.GetTileViewEdges \ This routine may need clarifying, as the algorithm \ doesn't seem to make sense - it's possible that I've \ misinterpreted how GetTileViewAngles sets the bits in \ tileIsOnScreen, as that uses bufferMinYaw(Hi Lo) for \ the calculation and those values are not completely \ understood LDY xTileViewLeft \ Set Y to the tile column so we can pass it to the \ GetTileViewAngles routine JSR GetTileViewAngles \ Calculate the pitch and yaw angles for the tile corner \ at (Y, zTile), from the perspective of the viewer, and \ store them in the following tables in the relevant \ entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) BEQ edge5 \ If A = %00000000 then the tile is not on-screen and is \ past the left edge of the screen, so jump to edge5 to \ move right from this point, looking for a tile that's \ on-screen \ If we get here then our chosen starting tile is either \ on-screen or off the right edge of the screen CMP #%10000000 \ If A = %10000000 then the tile is on-screen, so jump BEQ edge4 \ to edge4 to update xTileViewRight to this position and \ start moving left, so we work through the portion to \ the left of the starting point \ If we get here then tileIsOnScreen = %10000001 and the \ tile is not on-screen and is past the right edge of \ the screen, so fall through into edge1 to start moving \ right .edge1 \ If we get here then we keep moving right, updating \ xTileViewLeft as we go \ \ We keep moving until: \ \ * We find a tile that's on-screen or reach the end \ of the tile row, in which case we jump to edge3 to \ set xTileViewRight and return from the subroutine \ \ * We find a tile that's off the left of the screen, \ in which case we fall through into edge2 LDA xTile \ Store the current column number in xTileViewLeft STA xTileViewLeft JSR GetTileEdgeToRight \ Move one tile to the right and calculate the pitch and \ yaw angles for the tile corner from the perspective of \ the viewer, and store them in the following tables in \ the relevant entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ \ The C flag is set if we have already reached the end \ of the row and can't move any further right BCS edge3 \ If we just moved off the right end of the row then the \ right end of the row is visible on-screen, so jump to \ edge3 to set xTileViewRight accordingly and return \ from the subroutine CMP #%10000001 \ If A = %10000001 then the tile is past the right edge BEQ edge1 \ of the screen, so loop back to move right by one more \ tile CMP #%10000000 \ If A = %10000000 then the tile is on-screen, so jump BEQ edge3 \ to edge3 to set xTileViewRight accordingly and return \ from the subroutine \ If we get here then A must be %00000000 and the tile \ is off the left edge of the screen, so fall through \ into edge2 to keep moving right .edge2 \ If we get here then we keep moving right until: \ \ * We find a tile that's on-screen or reach the end \ of the tile row, in which case we jump to edge3 to \ set xTileViewRight and return from the subroutine JSR GetTileEdgeToRight \ Move one tile to the right and calculate the pitch and \ yaw angles for the tile corner from the perspective of \ the viewer, and store them in the following tables in \ the relevant entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ \ The C flag is set if we have already reached the end \ of the row and can't move any further right BCS edge3 \ If we just moved off the right end of the row then the \ right end of the row is visible on-screen, so jump to \ edge3 to set xTileViewRight accordingly and return \ from the subroutine BEQ edge2 \ If A = %00000000 then the new tile is not visible, so \ loop back to edge2 to keep moving right \ Otherwise the tile is either visible or off the right \ edge, so fall through into edge3 to set xTileViewRight \ accordingly and return from the subroutine .edge3 LDA xTile \ Store the current column number in xTileViewRight STA xTileViewRight RTS \ Return from the subroutine .edge4 \ If we get here then we keep moving left, updating \ xTileViewRight as we go \ \ We keep moving until: \ \ * We reach the start of the tile row, in which case \ we jump to edge9 to set xTileViewLeft and return \ from the subroutine \ \ * We find a tile that's on-screen, in which case we \ jump to edge4 to update xTileViewRight and keep \ moving left \ \ * We find a tile that's off the right of the screen, \ in which case jump to edge9 to set xTileViewLeft \ and return from the subroutine \ \ * We find a tile that's off the left of the screen, \ in which case jump to edge7 to move left until we \ find a visible tile or run out of row LDA xTile \ Store the current column number in xTileViewRight STA xTileViewRight JSR GetTileEdgeToLeft \ Move one tile to the left and calculate the pitch and \ yaw angles for the tile corner from the perspective of \ the viewer, and store them in the following tables in \ the relevant entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ \ The C flag is set if we have already reached the start \ of the row and can't move any further left BCS edge9 \ If we just moved off the left end of the row then the \ left end of the row is visible on-screen, so jump to \ edge9 to set xTileViewLeft accordingly and return from \ the subroutine CMP #%10000000 \ If A = %10000000 then the tile is on-screen, so jump BEQ edge4 \ to edge4 to update xTileViewRight and keep moving left CMP #%00000000 \ If A = %10000001 then the tile is off the right edge JMP edge8 \ of the screen, so jump to edge8 to set xTileViewLeft \ accordingly and return from the subroutine \ \ If A = %00000000 then the tile is off the left edge of \ the screen, so jump to edge8 and on to edge7 to move \ left until we find a visible tile or run out of row .edge5 \ If we get here then we keep moving right until: \ \ * We find a tile that's on-screen or reach the end \ of the tile row, in which case we jump to edge6 to \ set xTileViewRight and start working left from \ xTileViewLeft until we find a visible tile or run \ out of row JSR GetTileEdgeToRight \ Move one tile to the right and calculate the pitch and \ yaw angles for the tile corner from the perspective of \ the viewer, and store them in the following tables in \ the relevant entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ \ The C flag is set if we have already reached the end \ of the row and can't move any further right BCS edge6 \ If we just moved off the right end of the row then the \ right end of the row is visible on-screen, so jump to \ edge3 to set xTileViewRight accordingly and start \ moving left from the current left edge value in \ xTileViewLeft BEQ edge5 \ If the new tile is not visible and off to the left of \ the screen then loop back to edge5 to keep moving \ right \ If we get here then we have now found a visible tile \ by moving right, so store that in xTileViewRight and \ start moving left .edge6 LDA xTile \ Store the current column number in xTileViewRight STA xTileViewRight LDA xTileViewLeft \ Set xTile to the value of xTileViewLeft so we can STA xTile \ start moving left from this point .edge7 \ If we get here then we keep moving left until: \ \ * We find a tile that's on-screen or reach the end \ of the tile row, in which case we set \ xTileViewLeft and return from the subroutine JSR GetTileEdgeToLeft \ Move one tile to the left and calculate the pitch and \ yaw angles for the tile corner from the perspective of \ the viewer, and store them in the following tables in \ the relevant entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ \ The C flag is set if we have already reached the start \ of the row and can't move any further left BCS edge9 \ If we just moved off the left end of the row then the \ left end of the row is visible on-screen, so jump to \ edge9 to set xTileViewLeft accordingly and return from \ the subroutine .edge8 BEQ edge7 \ If the new tile is not visible then loop back to edge7 \ to keep moving left .edge9 LDA xTile \ Store the current column number in xTileViewLeft STA xTileViewLeft RTS \ Return from the subroutineName: GetTileViewEdges [Show more] Type: Subroutine Category: Drawing the landscape Summary: For a given tile row, work out the edges of the visible portion of the row in the current player view, as left to right tile numbersContext: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawLandscapeView (Part 2 of 3) calls GetTileViewEdges
Arguments: xTileViewLeft The tile column of the tile we are analysing, from the perspective of the viewer, to be used as a starting point for working out the visible edges of the row zTile The tile row of the tile we are analysing, from the perspective of the viewer drawingTableOffset Defines where we store the results of the analysis in the tileViewData, tileViewYaw and tileViewPitch drawing data tables; each table contains two complete sets of tile data, with the first table at offset 0 and the second table at offset 32, so we store the results as follows: * 0 = store the results in the first table e.g. in the 32-byte table at tileViewData * 32 = store the results in the second table e.g. in the 32-byte table at tileViewData+32
Returns: xTileViewLeft The number of the tile column on this row that appears at the left edge of the screen xTileViewRight The number of the tile column on this row that appears at the right edge of the screen tileViewData Tile data for all the tile corners analysed while looking for the edges drawViewYaw(Hi Lo) The yaw angles for all the tile corners analysed while looking for the edges drawViewPitchHi High byte of the pitch angles for all the tile corners analysed while looking for the edges drawViewPitchLo Low byte of the pitch angles for all the tile corners analysed while looking for the edges tileIsOnScreen Information on whether a tile corner is on-screen for all the tile corners analysed while looking for the edges
[X]
Subroutine GetTileEdgeToLeft (category: Drawing the landscape)
Move one tile to the left along the tile row that we are analysing for view edges and tile angles
[X]
Subroutine GetTileEdgeToRight (category: Drawing the landscape)
Move one tile to the right along the tile row that we are analysing for view edges and tile angles
[X]
Subroutine GetTileViewAngles (Part 1 of 4) (category: Drawing the landscape)
Calculate the pitch and yaw angles for a tile corner, relative to a viewer object (e.g. the player), and whether it is on-screen
[X]
Label edge1 is local to this routine
[X]
Label edge2 is local to this routine
[X]
Label edge3 is local to this routine
[X]
Label edge4 is local to this routine
[X]
Label edge5 is local to this routine
[X]
Label edge6 is local to this routine
[X]
Label edge7 is local to this routine
[X]
Label edge8 is local to this routine
[X]
Label edge9 is local to this routine
[X]
Variable xTileViewLeft in workspace Zero page
The tile number at the left edge of the tile row we are currently processing when drawing the landscape
[X]
Variable xTileViewRight in workspace Zero page
The tile number at the right edge of the tile row we are currently processing when drawing the landscape