.SendBarNamesToPPU SUBTRACT_CYCLES 2131 ; Subtract 2131 from the cycle count LDX iconBarRow ; Set X to the low byte of iconBarRow(1 0), to use in ; the following calculations STX dataForPPU ; Set dataForPPU(1 0) = nameBuffer0 + iconBarRow(1 0) LDA iconBarRow+1 ; CLC ; So dataForPPU(1 0) points to the entry in nametable ADC #HI(nameBuffer0) ; buffer 0 for the start of the icon bar (the addition STA dataForPPU+1 ; works because the low byte of nameBuffer0 is 0) LDA iconBarRow+1 ; Set (A X) = PPU_NAME_0 + iconBarRow(1 0) ADC #HI(PPU_NAME_0) ; ; The addition works because the low byte of PPU_NAME_0 ; is 0 STA PPU_ADDR ; Set PPU_ADDR = (A X) STX PPU_ADDR ; = PPU_NAME_0 + iconBarRow(1 0) ; ; So PPU_ADDR points to the tile entry in the PPU's ; nametable 0 for the start of the icon bar LDY #0 ; We now send the nametable entries for the icon bar to ; the PPU's nametable 0, so set a counter in Y .ibar1 LDA (dataForPPU),Y ; Send the Y-th nametable entry from dataForPPU(1 0) to STA PPU_DATA ; the PPU INY ; Increment the loop counter CPY #2*32 ; Loop back until we have sent 2 rows of 32 tiles BNE ibar1 LDA iconBarRow+1 ; Set (A X) = PPU_NAME_1 + iconBarRow(1 0) ADC #HI(PPU_NAME_1-1) ; ; The addition works because the low byte of PPU_NAME_1 ; is 0 and because the C flag is set (as we just passed ; through the BNE above) STA PPU_ADDR ; Set PPU_ADDR = (A X) STX PPU_ADDR ; = PPU_NAME_1 + iconBarRow(1 0) ; ; So PPU_ADDR points to the tile entry in the PPU's ; nametable 1 for the start of the icon bar LDY #0 ; We now send the nametable entries for the icon bar to ; the PPU's nametable 1, so set a counter in Y .ibar2 LDA (dataForPPU),Y ; Send the Y-th nametable entry from dataForPPU(1 0) to STA PPU_DATA ; the PPU INY ; Increment the loop counter CPY #2*32 ; Loop back until we have sent 2 rows of 32 tiles BNE ibar2 LDA skipBarPatternsPPU ; If bit 7 of skipBarPatternsPPU is set, we do not send BMI ibar3 ; the pattern data to the PPU, so jump to ibar3 to skip ; the following JMP SendBarPattsToPPU ; Bit 7 of skipBarPatternsPPU is clear, we do want to ; send the icon bar's pattern data to the PPU, so jump ; to SendBarPattsToPPU to do just that, returning from ; the subroutine using a tail call .ibar3 STA barPatternCounter ; Set barPatternCounter = 128 so the NMI handler does ; not send any more icon bar data to the PPU JMP ConsiderSendTiles ; Jump to ConsiderSendTiles to start sending tiles to ; the PPU, but only if there are enough free cyclesName: SendBarNamesToPPU [Show more] Type: Subroutine Category: PPU Summary: Send the nametable entries for the icon bar to the PPU Deep dive: Drawing vector graphics using NES tilesContext: See this subroutine in context in the source code References: This subroutine is called as follows: * SendBarNamesToPPUS calls SendBarNamesToPPU
Nametable data for the icon bar is sent to PPU nametables 0 and 1.
[X]
Subroutine ConsiderSendTiles (category: PPU)
If there are enough free cycles, move on to the next stage of sending patterns to the PPU
[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]
Configuration variable PPU_DATA = $2007
The PPU data register, which is used to send data to the PPU, to the address specified in PPU_ADDR
[X]
Configuration variable PPU_NAME_0 = $2000
The address of nametable 0 in the PPU
[X]
Configuration variable PPU_NAME_1 = $2400
The address of nametable 1 in the PPU
[X]
Macro SUBTRACT_CYCLES (category: Drawing the screen)
Subtract a specified number from the cycle count
[X]
Subroutine SendBarPattsToPPU (category: PPU)
Send pattern data for tiles 0-127 for the icon bar to the PPU, split across multiple calls to the NMI handler if required
[X]
Variable barPatternCounter in workspace ZP
The number of icon bar nametable and pattern entries that need to be sent to the PPU in the NMI handler
[X]
Variable dataForPPU in workspace ZP
An address pointing to data that we send to the PPU
[X]
Label ibar1 is local to this routine
[X]
Label ibar2 is local to this routine
[X]
Label ibar3 is local to this routine
[X]
Variable iconBarRow in workspace ZP
The row on which the icon bar appears
[X]
Variable nameBuffer0 in workspace Cartridge WRAM
The buffer for nametable 0 that gets sent to the PPU during VBlank
[X]
Variable skipBarPatternsPPU in workspace ZP
A flag to control whether to send the icon bar's patterns to the PPU, after sending the nametable entries (this only applies if barPatternCounter = 0)