I came across the following PPU write sequence a while back in The Legend of Zelda:
It does this during every vblank after the function that handles PPU writes. It's also done after each series of writes in that PPU write function if the writes started in the $3F page:
I can't find any reason why it needs to be writing to this 4 times, nor have I found any mention of this on nesdev. I wondered if this was unique to Zelda, but found the same pattern in SMB1, SMB3, Ninja Gaiden 3, Battle City, Mega Man 1, and TMNT1, which covers a pretty wide range of companies (Nintendo, Tecmo, Namco, Capcom, Konami) and years (1985-1991). Available disassemblies for SMB1, SMB3, and Mega Man 1 have comments indicating they have no idea what this code is for, so I'm clearly not the only one confused by this.
Can anyone shed some light on this code?
Code:
Bank7_E4C4: A9 3F LDA #$3F
Bank7_E4C6: 8D 0620 STA PPU_ADDRESS
Bank7_E4C9: A9 00 LDA #$00
Bank7_E4CB: 8D 0620 STA PPU_ADDRESS
Bank7_E4CE: 8D 0620 STA PPU_ADDRESS
Bank7_E4D1: 8D 0620 STA PPU_ADDRESS
Bank7_E4C6: 8D 0620 STA PPU_ADDRESS
Bank7_E4C9: A9 00 LDA #$00
Bank7_E4CB: 8D 0620 STA PPU_ADDRESS
Bank7_E4CE: 8D 0620 STA PPU_ADDRESS
Bank7_E4D1: 8D 0620 STA PPU_ADDRESS
It does this during every vblank after the function that handles PPU writes. It's also done after each series of writes in that PPU write function if the writes started in the $3F page:
Code:
Bank6_A0DA: C9 3F CMP #$3F
Bank6_A0DC: D0 0C BNE $A0EA
Bank6_A0DE: 8D 0620 STA PPU_ADDRESS
Bank6_A0E1: 8E 0620 STX PPU_ADDRESS ; X == 0
Bank6_A0E4: 8E 0620 STX PPU_ADDRESS
Bank6_A0E7: 8E 0620 STX PPU_ADDRESS
Bank6_A0DC: D0 0C BNE $A0EA
Bank6_A0DE: 8D 0620 STA PPU_ADDRESS
Bank6_A0E1: 8E 0620 STX PPU_ADDRESS ; X == 0
Bank6_A0E4: 8E 0620 STX PPU_ADDRESS
Bank6_A0E7: 8E 0620 STX PPU_ADDRESS
I can't find any reason why it needs to be writing to this 4 times, nor have I found any mention of this on nesdev. I wondered if this was unique to Zelda, but found the same pattern in SMB1, SMB3, Ninja Gaiden 3, Battle City, Mega Man 1, and TMNT1, which covers a pretty wide range of companies (Nintendo, Tecmo, Namco, Capcom, Konami) and years (1985-1991). Available disassemblies for SMB1, SMB3, and Mega Man 1 have comments indicating they have no idea what this code is for, so I'm clearly not the only one confused by this.
Can anyone shed some light on this code?