Skip to navigation

Screen buffer: ShowBufferColumn

Name: ShowBufferColumn [Show more] Type: Subroutine Category: Screen buffer Summary: Update the player's scrolling landscape view by copying a 2-pixel wide column from the screen buffer into screen memory
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

Arguments: fromAddr(1 0) The source address from which we copy the character column toAddr(1 0) The destination address to which we copy the character column
.ShowBufferColumn LDX #24 \ The custom screen mode 5 used by the game contains 25 \ character rows, each of which is eight pixels high, so \ set a row counter in X to count the character rows in \ the screen buffer, which is one row less than the \ screen height, as the top row is the energy icon and \ scanner row .dcol1 JSR ShowBufferBlock \ Copy an eight-byte 8x2-pixel character block from the \ screen buffer at fromAddr(1 0) into screen memory at \ toAddr(1 0) LDA fromAddr \ Set (A fromAddr) = fromAddr(1 0) + &140 CLC \ = fromAddr(1 0) + 320 ADC #&40 \ STA fromAddr \ Each character row in screen mode 5 takes up 320 bytes LDA fromAddr+1 \ (40 character blocks of eight bytes each), so this ADC #&01 \ sets fromAddr(1 0) to the address of the next row down \ in the screen buffer CMP #&53 \ If the result of the addition is less than &5300, then BNE dcol2 \ we have not reached the end of row 15 in the screen \ buffer, so jump to dcol2 to skip the following \ At this point the screen buffer wraps around so the \ buffer entries continue at a lower address \ \ Specifically the last buffer before &5300 is \ screenBufferRow15, at address: \ \ &51C0 to &51FF for character row 15 \ \ and we now wrap around as follows: \ \ &3FA0 to &3FDF for character row 16 \ \ to take us to the buffer at screenBufferRow16 \ \ The address of screenBufferRow16 is &A0 more than the \ start of the screen buffer at screenBufferRow0, and \ the address of the latter is in screenBufferAddr(1 0), \ so we can calculate the new address like this: \ \ (A fromAddr) = screenBufferAddr(1 0) + &A0 \ \ So this wraps the address around so we can keep \ drawing content into the screen buffer \ \ See screenBufferRow0 for more information on the \ structure of the screen buffer LDA screenBufferAddr \ Calculate the following: CLC \ ADC #&A0 \ (A fromAddr) = screenBufferAddr(1 0) + &A0 STA fromAddr LDA screenBufferAddr+1 ADC #&00 .dcol2 STA fromAddr+1 \ Store the high byte of the result, so we now have: \ \ fromAddr(1 0) = fromAddr(1 0) + 320 \ \ with the address wrapped around as required LDA toAddr \ Set (A toAddr) = toAddr(1 0) + &140 CLC \ = toAddr(1 0) + 320 ADC #&40 STA toAddr LDA toAddr+1 ADC #&01 CMP #&80 \ If the high byte in A >= &80 then the new address is BCC dcol3 \ past the end of screen memory, so subtract &20 from SBC #&20 \ the high byte so the address wraps around within the \ range of screen memory between &6000 and &8000 .dcol3 STA toAddr+1 \ Store the high byte of the result, so we now have: \ \ toAddr(1 0) = toAddr(1 0) + 320 \ \ with the address wrapped around as required DEX \ Decrement the counter in X to move on to the next \ character row down BNE dcol1 \ Loop back until we have copied all 24 character blocks \ in the column from fromAddr(1 0) to toAddr(1 0) JMP drow3 \ Jump to drow3 to return from the subroutine, as drow3 \ contains an RTS