.dlan4 LDA #31 \ We now iterate through all the tile rows, from back to STA zTile \ front towards the viewer, so set a row counter in \ zTile to iterate from 31 to 0 LDA xTileLeftPrevious \ Set xTileViewLeft = xTileLeftPrevious, so we start STA xTileViewLeft \ checking for the view edges, starting from the left \ edge from the previous calculation (or from tile zero \ if this is the first time) \ \ This makes the search for edges more efficient as the \ edges in neighbouring rows will be close together LDA #0 \ Set drawingTableOffset = 0 so the call to first call STA drawingTableOffset \ GetTileViewEdges (for tile row 31) will populate the \ tables at tileViewData+0, tileViewYaw+0 and \ tileViewPitch+0 with the angles of the tile being \ analysed JSR GetTileViewEdges \ For the row of tile corners at the very back of the \ landscape from the point of view of the viewer, work \ out the edges of the visible portion of the row in \ the current player view, as left to right tile \ numbers in xTileViewLeft and xTileViewRight \ \ We don't draw this row as it doesn't have any tiles \ anchored by the corners, but we generate the data so \ we can use it when drawing the tile rows below LDA xTileViewLeft \ Store the column number for the left edge of the STA xTileLeftPrevious \ visible portion of the row in xTileLeftPrevious, so \ we can refer to it above when we move on to the next \ row in front \ We now loop through each row of tile corners that has \ a row of tiles anchored, drawing each row in turn, \ from the back of the view to the front .dlan5 LDA drawingTableOffset \ Flip drawingTableOffset between 0 and 32, so each call EOR #32 \ to GetTileViewEdges and GetTileViewAngles alternates STA drawingTableOffset \ between storing the tile view data in: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ and storing it in: \ \ * (drawViewYawHi+32 drawViewYawLo+32) \ \ * (drawViewPitchHi+32 drawViewPitchLo+32) \ \ * tileViewData+32 \ \ This lets us store tile view data for both the current \ row that we are drawing and the previously drawn row LDA xTileViewLeft \ Set xTileViewLeftEdge to the tile number of the left STA xTileViewLeftEdge \ edge of the visible portion of the row we are \ analysing (i.e. zTile) so that we can generate results \ for other rows without losing this information LDA xTileViewRight \ Set xTileViewRightEdge to the tile number of the right STA xTileViewRightEdge \ edge of the visible portion of the row we are \ analysing (i.e. zTile) so that we can generate results \ for other rows without losing this information JSR ProcessSound \ Process any sounds or music that are being made in the \ background DEC zTile \ Decrement zTile to the z-coordinate of the next tile \ row forward, towards the viewer, so we can draw this \ new row BMI dlan6 \ If we have already drawn all the rows from 31 to 0, \ jump to dlan6 to return from the subroutine with the \ C flag clear LDY zTile \ If the new tile row is not the tile row that contains CPY zTileViewer \ the viewer, jump to dlan7 to draw it BNE dlan7 JMP dlan18 \ The new tile row contains the viewer, so jump to \ dlan18 to draw this row as a special case .dlan6 CLC \ Clear the C flag to indicate that we have drawn the \ whole landscape RTS \ Return from the subroutine .dlan7 \ We now check whether the new row, which we are about \ to draw, has the same visible portion as the \ previously drawn row, or if whether the new row's \ visible portion extends beyond the previous visible \ row or doesn't extend as far \ \ If the visible portions don't match, then we either \ need to extend the tile data for the current row to \ match, or we need to go back and extend the tile data \ on the previous row to match the current row \ \ This is so we can draw the tiles properly, as tiles \ are made up of tiles from both the current and \ previous rows of tile corners, so the calculate tile \ view data needs to match between the two rows JSR GetTileViewEdges \ For the new tile row, work out the edges of the \ visible portion of the row in the current player view, \ as left to right tile numbers in xTileViewLeft and \ xTileViewRight LDY xTileViewLeft \ If xTileViewLeft = xTileViewLeftEdge then the left CPY xTileViewLeftEdge \ edge of the visible row in this new row is at the same BEQ dlan11 \ place as in the previous row, so jump to dlan11 to \ do the same check on the right edge BCC dlan9 \ If xTileViewLeft < xTileViewLeftEdge then the left \ edge of the visible row in this new row is less than \ (i.e. to the left of) the edge in the previous row, so \ jump to dlan9 to go back to the previous row to fetch \ the tile data needed to make the datasets match \ Otherwise xTileViewLeft > xTileViewLeftEdge and the \ left edge of the visible row in this new row is \ greater (i.e. to the right of) the edge in the \ previous row, so we need to fetch more data on the \ left end of the current row to make the datasets match .dlan8 DEY \ Decrement Y to move left along the row by one tile 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) CPY xTileViewLeftEdge \ Loop back until we have moved left along the tile row BNE dlan8 \ all the way to the left edge in the previous row BEQ dlan11 \ Jump to dlan11 to move on to the checks on the right \ edge (this BEQ is effectively a JMP as we just passed \ through a BNE) .dlan9 \ If we get here then xTileViewLeft < xTileViewLeftEdge, \ so we need to go back to the previous row to fetch \ more tile data for the left end of the row, so we can \ use it to work out what to draw for the left end of \ the new row we are trying to draw \ \ This is because the visible part of the new row (the \ row in front) is extending left beyond the left edge \ of the visible part of the previous row (the one \ behind), so we won't have calculated the required \ tile data for the non-visible part of the previous \ row \ \ So we do that now by switching back to the previous \ row and calculating all the tile data for the tiles on \ the left of the previous row that have visible tiles \ in front of them in the new row LDA drawingTableOffset \ Flip drawingTableOffset between 0 and 32, so the calls EOR #32 \ to GetTileViewEdges and GetTileViewAngles store their STA drawingTableOffset \ data into the storage area that we used for the \ previous row, so we effectively extend the data to the \ left for the previous row INC zTile \ Increment xTile to the tile row number behind the one \ we are drawing, i.e. the previous row in this process LDY xTileViewLeftEdge \ Set Y to the left edge for the previous row .dlan10 DEY \ Decrement Y to move left along the row by one tile 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) CPY xTileViewLeft \ Loop back until we have moved left along the tile row BNE dlan10 \ all the way to the left edge in the new row in front STY xTileViewLeftEdge \ Update xTileViewLeftEdge to store the newly moved edge \ for the previous row DEC zTile \ Decrement zTile once again to move back to the row \ that we are drawing LDA drawingTableOffset \ Flip drawingTableOffset back again, so the calls EOR #32 \ to GetTileViewEdges and GetTileViewAngles once again STA drawingTableOffset \ store data in the new row's storage area .dlan11 \ By this point we have checked the left edges of the \ current and previous rows to fill in gaps in the tile \ data caused by the new row overlapping the previous \ row, and we now do the exact same thing for the right \ edges LDY xTileViewRight \ If xTileViewRight = xTileViewRightEdge then the right CPY xTileViewRightEdge \ edge of the visible row in this new row is at the same BEQ dlan15 \ place as in the previous row, so jump to dlan15 to \ draw the new row as we have all the tile information \ we need BCS dlan13 \ If xTileViewRight > xTileViewRightEdge then the right \ edge of the visible row in this new row is greater \ then (i.e. to the right of) the edge in the previous \ row, so jump to dlan13 to go back to the previous row \ to fetch the tile data needed to make the datasets \ match \ Otherwise xTileViewRight < xTileViewRightEdge and the \ right edge of the visible row in this new row is less \ than (i.e. to the left of) the edge in the previous \ row, so we need to fetch more data on the right end of \ the current row to make the datasets match .dlan12 INY \ Increment Y to move right along the row by one tile 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) CPY xTileViewRightEdge \ Loop back until we have moved right along the tile row BNE dlan12 \ all the way to the right edge in the previous row BEQ dlan15 \ Jump to dlan15 to draw the new row as we have all the \ tile information we need (this BEQ is effectively a \ JMP as we just passed through a BNE) .dlan13 \ If we get here, xTileViewRight > xTileViewRightEdge, \ so we need to go back to the previous row to fetch \ more tile data for the right end of the row, so we can \ use it to work out what to draw for the right end of \ the new row we are trying to draw \ \ This is because the visible part of the new row (the \ row in front) is extending right beyond the right edge \ of the visible part of the previous row (the one \ behind), so we won't have calculated the required \ tile data for the non-visible part of the previous \ row \ \ So we do that now by switching back to the previous \ row and calculating all the tile data for the tiles on \ the right of the previous row that have visible tiles \ in front of them in the new row LDA drawingTableOffset \ Flip drawingTableOffset between 0 and 32, so the calls EOR #32 \ to GetTileViewEdges and GetTileViewAngles store their STA drawingTableOffset \ data into the storage area that we used for the \ previous row, so we effectively extend the data to the \ left for the previous row INC zTile \ Increment xTile to the tile row number behind the one \ we are drawing, i.e. the previous row in this process LDY xTileViewRightEdge \ Set Y to the right edge for the previous row .dlan14 INY \ Increment Y to move right along the row by one tile 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) CPY xTileViewRight \ Loop back until we have moved right along the tile row BNE dlan14 \ all the way to the right edge in the new row in front STY xTileViewRightEdge \ Update xTileViewRightEdge to store the newly moved \ edge for the previous row DEC zTile \ Decrement zTile once again to move back to the row \ that we are drawing LDA drawingTableOffset \ Flip drawingTableOffset back again, so the calls EOR #32 \ to GetTileViewEdges and GetTileViewAngles once again STA drawingTableOffset \ store data in the new row's storage area .dlan15 \ By this point we have ensured that we have all the \ tile data that we need to draw the new row JSR DrawLandscapeRow \ Draw the tile row at z-coordinate zTile, between tiles \ xTileViewLeftEdge and xTileViewRightEdge, including \ any objects on any of the tiles BIT keepCheckingPanKey \ If bit 7 of keepCheckingPanKey is clear then we should BPL dlan16 \ keep drawing the landscape irrespective of whether the \ pan key is still being pressed, so jump to dlan16 to \ jump back to dlan5 to keep drawing the landscape \ If we get here then we need to check whether the same \ pan key is still being held down, and abort the \ drawing process if it isn't (this happens if the \ player initiates a pan, thus triggering this drawing \ process, but releases the key before the drawing has \ finished, in which case we don't need to finish off \ drawing the landscape) JSR CheckForSamePanKey \ Check to see whether the same pan key is being \ held down compared to the last time we checked BNE dlan17 \ If the same pan key is not being held down, jump to \ dlan17 to return from the subroutine with the C flag \ set to indicate that this is the case .dlan16 JMP dlan5 \ Loop back to dlan5 to analyse and draw the next tile \ row forward, towards the viewer .dlan17 SEC \ Set the C flag to indicate that we are aborting the \ drawing of the landscape as the panning key is no \ longer being held down RTS \ Return from the subroutineName: DrawLandscapeView (Part 2 of 3) [Show more] Type: Subroutine Category: Drawing the landscape Summary: Work through the landscape, drawing one row of tiles/objects at a time, from the back row to the front rowContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Subroutine CheckForSamePanKey (category: Keyboard)
Check to see whether the same pan key is being held down compared to the last time we checked
[X]
Subroutine DrawLandscapeRow (category: Drawing the landscape)
Draw a row of tiles between the left visible edge and the right visible, in two parts towards each side of the viewer
[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]
Subroutine GetTileViewEdges (category: Drawing the landscape)
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 numbers
[X]
Subroutine ProcessSound (category: Sound)
Process any sound effects that have been configured so they play in the background (this is called regularly throughout gameplay)
[X]
Label dlan10 is local to this routine
[X]
Label dlan11 is local to this routine
[X]
Label dlan12 is local to this routine
[X]
Label dlan13 is local to this routine
[X]
Label dlan14 is local to this routine
[X]
Label dlan15 is local to this routine
[X]
Label dlan16 is local to this routine
[X]
Label dlan17 is local to this routine
[X]
Label dlan18 in subroutine DrawLandscapeView (Part 3 of 3)
[X]
Label dlan5 is local to this routine
[X]
Label dlan6 is local to this routine
[X]
Label dlan7 is local to this routine
[X]
Label dlan8 is local to this routine
[X]
Label dlan9 is local to this routine
[X]
Variable drawingTableOffset in workspace Zero page
The offset to use within the various drawing data tables for the tile we are analysing
[X]
Variable keepCheckingPanKey in workspace Main variable workspace
Controls whether the DrawLandscapeView routine aborts drawing if the pan key is released before it has finished
[X]
Variable xTileLeftPrevious in workspace Main variable workspace
The previous value of xTileViewLeft
[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 xTileViewLeftEdge in workspace Zero page
The tile number at the left edge of the visible portion of the 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
[X]
Variable xTileViewRightEdge in workspace Zero page
The tile number at the right edge of the visible portion of the row we are currently processing when drawing the landscape
[X]
Variable zTileViewer in workspace Zero page
The tile z-coordinate of the viewer, but with the axes rotated to match the orientation of the viewer, so we can draw the landscape along the line of sight, towards the viewer's tile