Skip to navigation

Sights: SetSightsAddress

Name: SetSightsAddress [Show more] Type: Subroutine Category: Sights Summary: Update the address variables for the sights when they move into a new character block or row
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveSightsSideways calls SetSightsAddress * MoveSightsUpDown calls SetSightsAddress * MoveSightsUpDown calls via sadr3

Arguments: X Describes how the sights have moved when they move into a new character block or row in screen memory: * 0 if the sights moved right into the next character block * 1 if the sights moved left into the previous character block * 2 if the sights moved up within the same row * 3 if the sights moved down within the same row * 4 if the sights moved up into the row above * 5 if the sights moved down into the row below
Other entry points: sadr3 Contains an RTS
.SetSightsAddress \ We calculate the new screen address for the sights \ after the movement type described in X, by adding the \ relevant address change from entry X in the tables at \ sightsMoveAddr(Hi Lo) LDA sightsScreenAddr \ Add the address change for the movement type in X to CLC \ the sights screen address in sightsScreenAddr(1 0) ADC sightsMoveAddrLo,X \ STA sightsScreenAddr \ We start by calculating this: LDA sightsScreenAddr+1 \ ADC sightsMoveAddrHi,X \ (A sightsScreenAddr) = viewScreenAddr(1 0) \ + (sightsMoveAddrHi+X sightsMoveAddrLo+X) CMP #&80 \ If the high byte in A >= &80 then the new address is BCC sadr1 \ 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 \ \ If the high byte is in range, jump to sadr1 to check \ the high byte against the start of screen memory JMP sadr2 \ Jump to sadr2 to skip the next check, as we know it \ doesn't apply .sadr1 CMP #&60 \ If the high byte in A < &60 then the new address is BCS sadr2 \ before the start of screen memory, so add &20 to the ADC #&20 \ high byte so the address wraps around within the range \ of screen memory between &6000 and &8000 .sadr2 STA sightsScreenAddr+1 \ Store the high byte of the result, so we now have: \ \ sightsScreenAddr(1 0) = viewScreenAddr(1 0) \ + (sightsMoveAddrHi+X sightsMoveAddrLo+X) \ \ with the address wrapped around as required .sadr3 RTS \ Return from the subroutine