Skip to navigation


Graphics: FillCanopyRows

Name: FillCanopyRows [Show more] Type: Subroutine Category: Graphics Summary: Fill multiple screen rows with a particular colour, avoiding the canopy edges
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawGunSights calls FillCanopyRows * RemoveScore calls FillCanopyRows

Arguments: A The colour to fill the canopy with (Y X) The screen address to start filling from R The number of character rows to fill
.FillCanopyRows STY Q \ Set (Q P) = (Y X), so (Q P) is now the screen address STX P \ we want to start filling from STA S \ Store the value we want to store into S .fill1 LDY #0 \ Set a byte counter in Y LDA S \ Fetch the value of A that we stored in S above .fill2 STA (P),Y \ Set the Y-th byte of (Q P) to A, which sets 4 pixels \ to the pixel pattern in S DEY \ Decrement the byte counter BNE fill2 \ Loop back until we have set 256 bytes, starting at \ (Q P), to the value in A LDY #47 \ Set a byte counter in Y for 47 bytes INC Q \ Set (Q P) = (Q P) + 256 \ \ so it points to the next byte to fill after the 256 \ bytes we just did .fill3 STA (P),Y \ Set the Y-th byte of (Q P) to A, which sets 4 pixels \ to the pixel pattern in S DEY \ Decrement the byte counter BPL fill3 \ Loop back until we have set 47 bytes, starting at \ (Q P), to the value in A LDA P \ Set (Q P) = (Q P) + 64 CLC \ ADC #64 \ starting with the low bytes STA P BCC fill4 \ If the above addition didn't overflow, skip the next \ instruction INC Q \ The above addition overflowed, so increment the high \ byte of (Q P) to point to the next page in memory \ So now (Q P) is 320 greater than at the start, so it \ points to the next character row in screen memory .fill4 DEC R \ Decrement the row counter in R BNE fill1 \ Loop back until we have updated R rows RTS \ Return from the subroutine