.spat21 LDA patternCounter ; Set (addr A) = patternCounter LDX #0 STX addr STX dataForPPU ; Zero the low byte of dataForPPU(1 0) ; ; We set the high byte in part 1, so dataForPPU(1 0) now ; contains the address of the pattern buffer for this ; bitplane ASL A ; Set (addr X) = (addr A) << 4 ROL addr ; = patternCounter * 16 ASL A ROL addr ASL A ROL addr ASL A TAX LDA addr ; Set (A X) = (ppuPatternTableHi 0) + (addr X) ROL A ; = (ppuPatternTableHi 0) + patternCounter * 16 ADC ppuPatternTableHi ; ; ppuPatternTableHi contains the high byte of the ; address of the PPU pattern table to which we send ; patterns; it contains HI(PPU_PATT_1), so (A X) now ; contains the address in PPU pattern table 1 for ; pattern number patternCounter (as there are 16 bytes ; in the pattern table for each pattern) ; We now set both PPU_ADDR and addr(1 0) to the ; following: ; ; * (A X) when nmiBitplane is 0 ; ; * (A X) + 8 when nmiBitplane is 1 ; ; We add 8 in the second example to point the address to ; bitplane 1, as the PPU interleaves each pattern as ; 8 bytes of one bitplane followed by 8 bytes of the ; other bitplane, so bitplane 1's data always appears 8 ; bytes after the corresponding bitplane 0 data STA PPU_ADDR ; Set the high byte of PPU_ADDR to A STA addr+1 ; Set the high byte of addr to A TXA ; Set A = X + nmiBitplane8 ADC nmiBitplane8 ; = X + nmiBitplane * 8 ; ; So we add 8 to the low byte when we are writing to ; bit plane 1, otherwise we leave the low byte alone STA PPU_ADDR ; Set the low byte of PPU_ADDR to A STA addr ; Set the high byte of addr to A ; So PPU_ADDR and addr(1 0) both contain the PPU ; address to which we should send our pattern data for ; this bitplane JMP spat23 ; Jump into part 5 to send pattern data to the PPUName: SendPatternsToPPU (Part 4 of 6) [Show more] Type: Subroutine Category: PPU Summary: Configure variables for sending data to the PPU until we run out of cycles Deep dive: Drawing vector graphics using NES tilesContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Configuration variable PPU_ADDR = $2006
The PPU address register, which is used to set the destination address within the PPU when sending data to the PPU
[X]
Variable dataForPPU in workspace ZP
An address pointing to data that we send to the PPU
[X]
Variable nmiBitplane8 in workspace ZP
Used when sending patterns to the PPU to calculate the address offset of bitplanes 0 and 1
[X]
Variable patternCounter in workspace ZP
Counts patterns as they are written to the PPU pattern table in the NMI handler
[X]
Variable ppuPatternTableHi in workspace ZP
High byte of the address of the PPU pattern table to which we send patterns
[X]
Label spat23 in subroutine SendPatternsToPPU (Part 5 of 6)