junglejourney

changeset 4:c3b5978024b1

Added proper walls for each room. Currently, the positions of the right and bottom walls do not correspond with those in the generated reference map.
author David Boddie <david@boddie.org.uk>
date Sun Jul 24 02:03:23 2011 +0200
parents e38ed805fcdc
children cbca25501227
files mapcode.oph
diffstat 1 files changed, 279 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/mapcode.oph	Sat Jul 23 01:32:29 2011 +0200
     1.2 +++ b/mapcode.oph	Sun Jul 24 02:03:23 2011 +0200
     1.3 @@ -11,10 +11,7 @@
     1.4      clc
     1.5      rts
     1.6  
     1.7 -next_value:
     1.8 -    jsr unlimited_values
     1.9 -    lda $7d
    1.10 -
    1.11 +div9:               ; A = value
    1.12  divide_loop:
    1.13      cmp #9
    1.14      bcc after_divide_loop   ; bmi should work here, I think, but it doesn't
    1.15 @@ -24,12 +21,250 @@
    1.16  
    1.17  after_divide_loop:
    1.18      clc
    1.19 +    rts             ; A % 9
    1.20 +
    1.21 +next_value:         ; no argument
    1.22 +    jsr unlimited_values
    1.23 +    lda $7d
    1.24 +    jsr div9
    1.25      and #3
    1.26      sta $7b
    1.27 +    rts             ; $7b = (next value % 9) & 3
    1.28 +
    1.29 +draw_top_line:
    1.30 +    ldx #9
    1.31 +    lda #1
    1.32 +draw_top_line_loop0:
    1.33 +    sta $57f6,x
    1.34 +    dex
    1.35 +    bpl draw_top_line_loop0
    1.36 +
    1.37 +    ldx #3
    1.38 +    lda $76
    1.39 +draw_top_line_loop1:
    1.40 +    sta $57f9,x
    1.41 +    dex
    1.42 +    bpl draw_top_line_loop1
    1.43 +    clc
    1.44 +    rts
    1.45 +
    1.46 +draw_left_line:
    1.47 +    ldx #99
    1.48 +draw_left_line_loop0:
    1.49 +    lda #1
    1.50 +    sta $579c,x
    1.51 +    txa
    1.52 +    sec
    1.53 +    sbc #10
    1.54 +    tax
    1.55 +    bpl draw_left_line_loop0
    1.56 +
    1.57 +    ldx #39
    1.58 +draw_left_line_loop1:
    1.59 +    lda $77
    1.60 +    sta $57ba,x
    1.61 +    txa
    1.62 +    sec
    1.63 +    sbc #10
    1.64 +    tax
    1.65 +    bpl draw_left_line_loop1
    1.66 +    clc
    1.67 +    rts
    1.68 +
    1.69 +draw_bottom_line:
    1.70 +    ldx #9
    1.71 +    lda #1
    1.72 +draw_bottom_line_loop0:
    1.73 +    sta $579c,x
    1.74 +    dex
    1.75 +    bpl draw_bottom_line_loop0
    1.76 +
    1.77 +    ldx #3
    1.78 +    lda $76
    1.79 +draw_bottom_line_loop1:
    1.80 +    sta $579f,x
    1.81 +    dex
    1.82 +    bpl draw_bottom_line_loop1
    1.83 +    clc
    1.84 +    rts
    1.85 +
    1.86 +draw_right_line:
    1.87 +    ldx #90
    1.88 +draw_right_line_loop0:
    1.89 +    lda #1
    1.90 +    sta $579c,x
    1.91 +    txa
    1.92 +    sec
    1.93 +    sbc #10
    1.94 +    tax
    1.95 +    bpl draw_right_line_loop0
    1.96 +
    1.97 +    ldx #30
    1.98 +draw_right_line_loop1:
    1.99 +    lda $77
   1.100 +    sta $57ba,x
   1.101 +    txa
   1.102 +    sec
   1.103 +    sbc #10
   1.104 +    tax
   1.105 +    bpl draw_right_line_loop1
   1.106 +    clc
   1.107 +    rts
   1.108 +
   1.109 +top_left_exits:     ; $70=test number
   1.110 +    lda $78
   1.111 +    adc $7f         ; i + second
   1.112 +    sta $7c
   1.113 +    clc
   1.114 +    lda $79
   1.115 +    adc $7e
   1.116 +    sta $7d         ; j + first
   1.117 +    clc
   1.118 +
   1.119 +    lda $70
   1.120 +    adc #4          ; 4 + test number
   1.121 +    clc
   1.122 +    tax
   1.123 +top_left_loop:
   1.124 +    jsr unlimited_values
   1.125 +    dex
   1.126 +    bne top_left_loop
   1.127 +
   1.128      rts
   1.129  
   1.130  make_room:          ; $78,$79=i,j
   1.131                      ; $7e,$7f=first,second
   1.132 +
   1.133 +    ; Determine if there is a top exit.
   1.134 +    lda #0
   1.135 +    sta $76
   1.136 +
   1.137 +    lda $78
   1.138 +    cmp #0
   1.139 +    bne not_top_screen
   1.140 +    lda #1
   1.141 +    sta $76
   1.142 +    jmp do_top_exit
   1.143 +not_top_screen:
   1.144 +    clc
   1.145 +
   1.146 +    lda $7e
   1.147 +    sta $70
   1.148 +    jsr top_left_exits
   1.149 +
   1.150 +    jsr div9
   1.151 +    sta $70         ; store the result temporarily
   1.152 +
   1.153 +    lda $7e
   1.154 +    jsr div9        ; second % 9
   1.155 +    cmp $70
   1.156 +    bne do_top_exit
   1.157 +    lda #1
   1.158 +    sta $76         ; top exit
   1.159 +
   1.160 +do_top_exit:
   1.161 +    clc
   1.162 +    jsr draw_top_line
   1.163 +
   1.164 +    ; Determine if there is a left exit.
   1.165 +    lda #0
   1.166 +    sta $77
   1.167 +
   1.168 +    lda $79
   1.169 +    cmp #0
   1.170 +    bne not_left_screen
   1.171 +    lda #1
   1.172 +    sta $77
   1.173 +    jmp do_left_exit
   1.174 +not_left_screen:
   1.175 +    clc
   1.176 +
   1.177 +    lda $7f
   1.178 +    sta $70
   1.179 +    jsr top_left_exits
   1.180 +
   1.181 +    jsr div9
   1.182 +    sta $70         ; store the result temporarily
   1.183 +
   1.184 +    lda $7f
   1.185 +    jsr div9        ; second % 9
   1.186 +    cmp $70
   1.187 +    bne do_left_exit
   1.188 +    lda #1
   1.189 +    sta $77         ; left exit
   1.190 +
   1.191 +do_left_exit:
   1.192 +    clc
   1.193 +    jsr draw_left_line
   1.194 +
   1.195 +    ; Determine if there is a right exit.
   1.196 +    lda #0
   1.197 +    sta $77
   1.198 +
   1.199 +    lda $79
   1.200 +    cmp #10
   1.201 +    bne not_right_screen
   1.202 +    lda #1
   1.203 +    sta $77
   1.204 +    jmp do_right_exit
   1.205 +not_right_screen:
   1.206 +    clc
   1.207 +
   1.208 +    inc $79
   1.209 +    lda $7f
   1.210 +    sta $70
   1.211 +    jsr top_left_exits
   1.212 +    dec $79
   1.213 +
   1.214 +    jsr div9
   1.215 +    sta $70         ; store the result temporarily
   1.216 +
   1.217 +    lda $7f
   1.218 +    jsr div9        ; second % 9
   1.219 +    cmp $70
   1.220 +    bne do_right_exit
   1.221 +    lda #1
   1.222 +    sta $77         ; right exit
   1.223 +
   1.224 +do_right_exit:
   1.225 +    clc
   1.226 +    jsr draw_right_line
   1.227 +
   1.228 +    ; Determine if there is a bottom exit.
   1.229 +    lda #0
   1.230 +    sta $76
   1.231 +
   1.232 +    lda $78
   1.233 +    cmp #10
   1.234 +    bne not_bottom_screen
   1.235 +    lda #1
   1.236 +    sta $76
   1.237 +    jmp do_bottom_exit
   1.238 +not_bottom_screen:
   1.239 +    clc
   1.240 +
   1.241 +    inc $78
   1.242 +    lda $7e
   1.243 +    sta $70
   1.244 +    jsr top_left_exits
   1.245 +    dec $78
   1.246 +
   1.247 +    jsr div9
   1.248 +    sta $70         ; store the result temporarily
   1.249 +
   1.250 +    lda $7e
   1.251 +    jsr div9        ; second % 9
   1.252 +    cmp $70
   1.253 +    bne do_bottom_exit
   1.254 +    lda #1
   1.255 +    sta $76         ; bottom exit
   1.256 +
   1.257 +do_bottom_exit:
   1.258 +    clc
   1.259 +    jsr draw_bottom_line
   1.260 +
   1.261 +    ; Fill in the room details.
   1.262 +
   1.263      lda $7f
   1.264      adc $79
   1.265      sta $7c
   1.266 @@ -46,6 +281,26 @@
   1.267      jsr unlimited_values
   1.268      dey
   1.269      bne make_room_loop0
   1.270 +    
   1.271 +                    ; Fill the room array with values.
   1.272 +    ldx #78
   1.273 +    ldy #63
   1.274 +make_room_loop1:
   1.275 +    jsr next_value
   1.276 +    sta $57a6,x
   1.277 +    dey
   1.278 +    tya
   1.279 +    and #7
   1.280 +    cmp #7
   1.281 +    bne next1
   1.282 +    dex
   1.283 +    dex
   1.284 +
   1.285 +next1:
   1.286 +    clc
   1.287 +    dex
   1.288 +    bpl make_room_loop1
   1.289 +    
   1.290      rts
   1.291  
   1.292  
   1.293 @@ -106,7 +361,7 @@
   1.294                      ; $7b=tile number
   1.295                      ; $72,$73=screen position 
   1.296  
   1.297 -                    ; Calculate the sprite address ($74,$75 + $76*0x60).
   1.298 +                    ; Calculate the sprite address ($74,$75 + $7b*0x60).
   1.299      lda $74
   1.300      sta $70
   1.301      lda $75
   1.302 @@ -136,9 +391,9 @@
   1.303      rts
   1.304  
   1.305  plot_room:          ; $78,$79 = i,j
   1.306 -    lda #$e0
   1.307 +    lda #$00
   1.308      sta $72
   1.309 -    lda #$5b
   1.310 +    lda #$58
   1.311      sta $73         ; $72,$73 = screen position
   1.312  
   1.313      lda #$00
   1.314 @@ -152,33 +407,41 @@
   1.315  
   1.316      jsr make_room
   1.317  
   1.318 +    lda #99
   1.319 +    sta $7a
   1.320  row_loop:
   1.321  
   1.322 -    lda #8
   1.323 -    sta $7a
   1.324 +    lda #9
   1.325 +    sta $76
   1.326  column_loop:
   1.327 -    clc
   1.328 -    jsr next_value
   1.329 +    lda $7a
   1.330 +    tax
   1.331 +    lda $579c,x
   1.332 +    sta $7b
   1.333      jsr plot_tile
   1.334  
   1.335 +    lda $7a
   1.336      sec
   1.337 -    lda $7a
   1.338      sbc #1
   1.339      sta $7a
   1.340 +    lda $76
   1.341 +    sec
   1.342 +    sbc #1
   1.343 +    sta $76
   1.344      clc
   1.345 +    cmp #0
   1.346 +    bpl column_loop
   1.347  
   1.348 -    cmp #0
   1.349 -    bne column_loop
   1.350      clc
   1.351  
   1.352      lda $72
   1.353 -    adc #$c0
   1.354 +    adc #$80
   1.355      sta $72
   1.356      lda $73
   1.357      adc #$02
   1.358      sta $73
   1.359      clc
   1.360 -    cmp #$79
   1.361 +    cmp #$7d
   1.362      beq end_rows
   1.363  
   1.364      jmp row_loop