'Wave' scroll effect in VRC7 without graphical glitches?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
'Wave' scroll effect in VRC7 without graphical glitches?
by on (#126650)
...Of course, I'm not gonna spend all those code waiting for the HBlank.
I'm trying to make the scroll look like a wave. Assume that the first page and the second page are exactly the same.
The following code is my code, and some graphical glitches appear at the right edge of the screen when running on FCEUX.

I_CW6_0:
;note that IRQControl is #$03

LDA IRQCount
BEQ I_CW6_0_1 ;First IRQ
CMP #$12
BEQ UsualIRQ ;Last IRQ
STA IRQAcknowledge
;IRQLatch or IRQControl doesn't need to be changed

INC IRQCount
LDA FrameCounter
LSR
LSR
CLC
ADC IRQCount
AND #$0F
TAY

LDA IRQScroll
CLC
ADC IRQWaveDif, Y

STA PPU_SCROLL_REG
STA PPU_SCROLL_REG
;LDA IRQPage
;ADC IRQWavePageDif, Y
;AND #$01
;ORA IRQPPU
;STA PPU_CTRL_REG1

RTS

IRQWaveDif:
.DB 0,$FE,$FC,$FB,$FA,$FB,$FC,$FE,0,2,4,5,6,5,4,2
IRQWavePageDif:
.DB 0,$FF,$FF,$FF,$FF,$FF,$FF,$FF,0,0,0,0,0,0,0,0


If the commented code are turned into actual code, there are more graphical glitches.