I've been working at learning NES coding for several months now, and the incredible amount of information here and at NintendoAge have helped me out a lot. I'm stuck on this one though, so I decided to finally make a post and see if people can point me in the right direction.
I've been trying to put together a short demo for scrolling combined with collision detection, and while I've gotten everything to work well enough going right, I run into issues when I go left. It seems as if the collision map isn't being updated properly when I scroll to the right, as my character suddenly is colliding with invisible walls, falling through the floor, and all manner of other odd behaviors.
I tried to take a break from this for a bit and go back to it, but nothing I've done seems to be fixing it.
Anyway, I've included some relevant snippets of my (probably really sloppy and messy) code. Hopefully someone knowledgeable can look at it and point me in the direction of what I'm doing wrong and how I can fix this.
I have a feeling that the stuff I'm doing in @left here might be the cause of my problems.
I hope I'm providing enough information. If not, I'll be happy to clarify anything.
I've been trying to put together a short demo for scrolling combined with collision detection, and while I've gotten everything to work well enough going right, I run into issues when I go left. It seems as if the collision map isn't being updated properly when I scroll to the right, as my character suddenly is colliding with invisible walls, falling through the floor, and all manner of other odd behaviors.
I tried to take a break from this for a bit and go back to it, but nothing I've done seems to be fixing it.
Anyway, I've included some relevant snippets of my (probably really sloppy and messy) code. Hopefully someone knowledgeable can look at it and point me in the direction of what I'm doing wrong and how I can fix this.
I have a feeling that the stuff I'm doing in @left here might be the cause of my problems.
Code:
Column:
lda xscroll+1
and #%00001111 ;check bottom 4 bits to see if we need to draw a new column
bne @done2
lda drawn ;check the 'drawn' value to see if we've already drawn this value
bne @done2
lda #$01 ;if we haven't drawn, set drawn value to #$01 and continue
sta drawn
lda xscroll+1
and #%11110000
lsr
lsr
lsr
lsr
sta ColRam_Index ;check upper bits of xscroll, shift, store in ColRam_Index
lda render_direction
bne @left ;check which direction we're rendering in. If non zero, jump to @left
jsr findcolumnR
jsr Loadcolumn ;find right hand column and buffer it.
jmp @done2
@left
lda ColRam_Index
sec
sbc #$01
sta ColRam_Index ;subtract $#01 from ColRam_Index
lda ColRam_Index
bpl @. ;if the result is negative, we load $#0F and store that in ColRam_Index
lda #$0F
sta ColRam_Index
@.
jsr findcolumnL ;find left hand column and buffer it
jsr Loadcolumn
@done2
lda xscroll+1
and #%00001111 ;check lower bits of xscroll+1, if zero, go to @rts
beq @rts
lda #$00 ;reset "drawn" to #$00
sta drawn
@rts
JSR Movement
JSR Collision
JSR UpdateSprites
rts
lda xscroll+1
and #%00001111 ;check bottom 4 bits to see if we need to draw a new column
bne @done2
lda drawn ;check the 'drawn' value to see if we've already drawn this value
bne @done2
lda #$01 ;if we haven't drawn, set drawn value to #$01 and continue
sta drawn
lda xscroll+1
and #%11110000
lsr
lsr
lsr
lsr
sta ColRam_Index ;check upper bits of xscroll, shift, store in ColRam_Index
lda render_direction
bne @left ;check which direction we're rendering in. If non zero, jump to @left
jsr findcolumnR
jsr Loadcolumn ;find right hand column and buffer it.
jmp @done2
@left
lda ColRam_Index
sec
sbc #$01
sta ColRam_Index ;subtract $#01 from ColRam_Index
lda ColRam_Index
bpl @. ;if the result is negative, we load $#0F and store that in ColRam_Index
lda #$0F
sta ColRam_Index
@.
jsr findcolumnL ;find left hand column and buffer it
jsr Loadcolumn
@done2
lda xscroll+1
and #%00001111 ;check lower bits of xscroll+1, if zero, go to @rts
beq @rts
lda #$00 ;reset "drawn" to #$00
sta drawn
@rts
JSR Movement
JSR Collision
JSR UpdateSprites
rts
I hope I'm providing enough information. If not, I'll be happy to clarify anything.