.InitialiseSights \ We start by calculating the screen address for the \ sights when they are in the middle of the screen, \ which is where we initialise them \ \ The base screen address has already been set up in \ viewScreenAddr(1 0), and we want to place the sights \ halfway down and halfway across the screen \ \ The custom screen mode 5 used by the game contains 25 \ character rows, each of which is eight pixels high \ \ The top character row is used for the energy icon and \ scanner, and viewScreenAddr(1 0) points to the start \ of screen memory just below this top row, so the \ player's view is 24 character rows high and row 12 is \ halfway down the screen \ \ Each character row in screen mode 5 takes up 320 bytes \ (40 character blocks of eight bytes each), so the \ offset within screen memory of the start of row 12 is \ 12 * 320, and we can move halfway along that row by \ adding a further 160, so that's an offset of: \ \ 12 * 320 + 160 = 4000 \ \ So the address of the sights in screen memory is: \ \ viewScreenAddr(1 0) + 4000 \ \ which is what we calculate now LDA viewScreenAddr \ Calculate the following: CLC \ ADC #&A0 \ (A sightsScreenAddr) = viewScreenAddr(1 0) + &0FA0 STA sightsScreenAddr \ = viewScreenAddr(1 0) + 4000 \ \ starting with the low bytes LDA viewScreenAddr+1 \ And then the high bytes ADC #&0F CMP #&80 \ If the high byte in A >= &80 then the new address is BCC sesi1 \ 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 .sesi1 STA sightsScreenAddr+1 \ Store the high byte of the result, so we now have: \ \ sightsScreenAddr(1 0) = viewScreenAddr(1 0) + 4000 LDA #80 \ Set the on-screen x-coordinate of the sights to 80, STA xSights \ which is in the middle of the 160-pixel wide screen LDA #95 \ Set the on-screen y-coordinate of the sights to 95, STA ySights \ which is in the middle of the 192-pixel high player's \ view (which is the whole screen apart from the energy \ icon and scanner row at the top) RTS \ Return from the subroutineName: InitialiseSights [Show more] Type: Subroutine Category: Sights Summary: Initialise the variables used to manage the sights, so the sights appear in the middle of the screenContext: See this subroutine in context in the source code References: This subroutine is called as follows: * CheckForKeyPresses calls InitialiseSights
[X]
Label sesi1 is local to this routine
[X]
Variable sightsScreenAddr in workspace Main variable workspace
The screen address of the sights
[X]
Variable viewScreenAddr in workspace Main variable workspace
The screen address of the player's scrolling landscape view, which is just below the icon and scanner row at the top of the screen
[X]
Variable xSights in workspace Main variable workspace
The pixel x-coordinate of the sights on-screen
[X]
Variable ySights in workspace Main variable workspace
The pixel y-coordinate of the sights on-screen