Somewhere I need to add 10 to temp16Lo so that the correct address is written to $2006, but I can't figure out where it goes.
Here's the source code.
Code: Select all
DrawMetatiles:
txa
pha
tya
pha
ldx #0
ldy #0
lda #0
sta looptemp
sta looptemp2
sta temp16Lo
lda #$20
sta temp16Hi
DrawMetatiles_loop:
lda looptemp
tax
lda MetatilesToDraw, x
asl a
asl a
tay
lda $2002
lda temp16Hi
sta $2006
lda temp16Lo
sta $2006
;Draw top 2 pieces of metatile
lda metatiles,y
sta $2007
iny
lda metatiles,y
sta $2007
iny
;move to next row
lda temp16Lo
clc
adc #$20
sta pointerLo ;use a different pointer since we want to go back to the first row for the next metatile
lda temp16Hi
adc #00
sta pointerHi ;if temp16Lo wrapped around, add 1 to temp16Hi, otherwise leave it unchanged.
lda $2002
lda pointerHi
sta $2006
lda pointerLo
sta $2006
;draw bottom two pieces of metatile
lda metatiles,y
sta $2007
iny
lda metatiles,y
sta $2007
iny ; after this, y should be pointing at the top left of the next metatile.
inc temp16Lo
inc temp16Lo
bcc dontIncrementHi
lda temp16Hi
adc #$00
inc temp16Hi
sta temp16Hi
dontIncrementHi:
inc looptemp
lda looptemp
cmp #64
beq exitloop
jmp DrawMetatiles_loop
exitloop:
pla
tay
pla
tax
rts
metatiles:
.db $45, $45, $47, $47 ; tile 0, bricks
.db $53, $54, $55, $56 ; tile 1, question blocks
.db $c6, $c7, $c8, $c9 ; tile 2, bullet bill cannon
.db $b4, $b5, $b6, $b7 ; tile 3, ground tile
.db $ab, $ad, $ac, $ae ; tile 4, hard block
MetatilesToDraw:
.db $00, $01, $02, $03, $04, $00, $01, $02
.db $03, $04, $00, $01, $02, $03, $04, $00
.db $01, $02, $03, $04, $00, $01, $02, $03
.db $04, $00, $01, $02, $03, $04, $00, $01
.db $02, $03, $04, $00, $01, $02, $03, $04
.db $00, $01, $02, $03, $04, $00, $01, $02
.db $03, $04, $00, $01, $02, $03, $04, $00
.db $01, $02, $03, $04, $00, $01, $02, $03