NES Vertical Scrolling Screen Tear Issue
Moderator: Moderators
NES Vertical Scrolling Screen Tear Issue
Scenario:
I have a sprite in the center of the screen. The background x and y scroll is updated by the controller. I allow to scroll infinitely in any direction. The background continues to repeat (which is what I want.) I've experimented with 4 way mirroring and loading the same nametable into each of the 4 nametable addresses so the image always repeats.
Problem:
I notice that when I scroll horizontal the image repeats with no issue but when I continue to scroll vertical a set of artifacts appears on the top of the screen that appear to be generated by the PPU and not from any graphics in my .chr file. When y reaches between 240-255 the artifacts appear. I believe it has something to do with x being from 0-255 and the size of the nametable for y is 0-239.
Question:
How can I scroll in any direction for any length of distance and have a background continue to repeat without seeing the artifacts I mention above?
I have a sprite in the center of the screen. The background x and y scroll is updated by the controller. I allow to scroll infinitely in any direction. The background continues to repeat (which is what I want.) I've experimented with 4 way mirroring and loading the same nametable into each of the 4 nametable addresses so the image always repeats.
Problem:
I notice that when I scroll horizontal the image repeats with no issue but when I continue to scroll vertical a set of artifacts appears on the top of the screen that appear to be generated by the PPU and not from any graphics in my .chr file. When y reaches between 240-255 the artifacts appear. I believe it has something to do with x being from 0-255 and the size of the nametable for y is 0-239.
Question:
How can I scroll in any direction for any length of distance and have a background continue to repeat without seeing the artifacts I mention above?
Re: NES Vertical Scrolling Screen Tear Issue
TL;DR, don't do that. On the NES for Y scrolling, 256 comes after 239.nesdevwiki:PPU scrolling wrote:For this reason, a write [y] >= 240 to $2005 may appear as a "negative" scroll value, where 1 or 2 rows of attribute data will appear before the nametable's tile data is reached.
Re: NES Vertical Scrolling Screen Tear Issue
"Negative scrolling" is badly worded for what happens there. A more accurate description would be "scroll into the attribute table", where the AT data is displayed on the screen as NT data. I'm not saying this feaure doesn't have any applications, but so far I didn't find any so if there is any use to this it is in extremely weird/special cases.
For instance if you badly needed a 32x32 tile map and would be ready to sacrifice coulours for it, you could set all 4 BG palettes to the same values and use AT as NT, to get the required 32x32 map.
In typically scrolling case, you do not want to do that, and want to go from 239 to 0 directly.
For instance if you badly needed a 32x32 tile map and would be ready to sacrifice coulours for it, you could set all 4 BG palettes to the same values and use AT as NT, to get the required 32x32 map.
In typically scrolling case, you do not want to do that, and want to go from 239 to 0 directly.
- darryl.revok
- Posts: 520
- Joined: Sat Jul 25, 2015 1:22 pm
Re: NES Vertical Scrolling Screen Tear Issue
After incrementing the Y scroll, check if it's larger than 239. If so, add 16 to force a wrap to the next screen, skipping over the attribute tables. After decrementing it, check if it underflowed below 0, and subtract 16 if that's the case.
Re: NES Vertical Scrolling Screen Tear Issue
Thanks guys. I got it to work this way during my controller reads for up and down.
Code: Select all
player_up_update:
lda scrolly ; Load scrolly position
sec
sbc #$01 ; Subtract from A
stay scrolly ; Update scrolly position
cmp #$ef ; Compare scrolly to 239
bcs update_scrollyup ; If more than 239 update scrolly
jmp player_down_read ; Jump to player_down_read
update_scrollyup:
lda scrolly
sec
sbc #$10 ; Subtract 16 from scrolly position
sta scrolly
rts
player_down_update:
lda scrolly ; Load scrolly position
clc
adc #$01 ; Add from A
stay scrolly ; Update scrolly position
cmp #$ef ; Compare scrolly to 239
bcs update_scrollydown ; If more than 239 update scrolly
jmp player_left_read ; Jump to player_left_read
update_scrollydown:
lda scrolly
clc
adc #$10 ; Add 16 to scrolly position
sta scrolly
rts
Re: NES Vertical Scrolling Screen Tear Issue
Youre making it more complicated than needed. This is simpler :
Code: Select all
lda scrolly
clc
adc scrollyspeed
cmp #$f0
bcc +
sbc #$f0
+ sta scrolly
Re: NES Vertical Scrolling Screen Tear Issue
You can't use conditional branch instructions to branch to a subroutine like you're doing. Those instructions don't push a return address.Sl1pm0de wrote:Thanks guys. I got it to work this way during my controller reads for up and down.
Code: Select all
player_up_update: lda scrolly ; Load scrolly position sec sbc #$01 ; Subtract from A stay scrolly ; Update scrolly position cmp #$ef ; Compare scrolly to 239 bcs update_scrollyup ; If more than 239 update scrolly jmp player_down_read ; Jump to player_down_read update_scrollyup: lda scrolly sec sbc #$10 ; Subtract 16 from scrolly position sta scrolly rts player_down_update: lda scrolly ; Load scrolly position clc adc #$01 ; Add from A stay scrolly ; Update scrolly position cmp #$ef ; Compare scrolly to 239 bcs update_scrollydown ; If more than 239 update scrolly jmp player_left_read ; Jump to player_left_read update_scrollydown: lda scrolly clc adc #$10 ; Add 16 to scrolly position sta scrolly rts
Re: NES Vertical Scrolling Screen Tear Issue
Thanks. This ended up working. I use #$ef instead of #$f0 because you start to see the attribute table starting at #$f0 (240). I had seen the + method used before but didn't understand it. Now I do. It enabled me to jump the instruction (I'm pretty new at this).
I was adding 16 to 240 or subtracting 16 from an undersigned value (<0) to make it work before. This allowed me to skip the attribute table that was showing. Can someone help me understand why adding or subtracting (depending on the controller direction) 239 to 239 works?
Thanks
I was adding 16 to 240 or subtracting 16 from an undersigned value (<0) to make it work before. This allowed me to skip the attribute table that was showing. Can someone help me understand why adding or subtracting (depending on the controller direction) 239 to 239 works?
Thanks
Code: Select all
player_up_update:
lda scrolly ; Load scrolly position
sec
sbc scrollspeed ; Advance the scroll
cmp #$ef ; Compare scrolly to 239
bcc +
adc #$ef ; Add 239 to scrolly
+ sta scrolly ; Update scrolly position
jmp player_down_read ; Jump to player_down_read
player_down_update:
lda scrolly ; Load scrolly position
clc
adc scrollspeed ; Advance the scroll
cmp #$ef ; Compare scrolly to 239
bcc +
sbc #$ef ; Subtract 239 to scrolly
+ sta scrolly ; Update scrolly position
jmp player_left_read ; Jump to player_left_read
Re: NES Vertical Scrolling Screen Tear Issue
Adding 239 is the same as subtracting 17.