.GetTileShape JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile) AND #%00001111 \ Extract the tile altitude from the low nibble and STA S \ store it in S INC xTile \ Move along the x-axis to fetch the next tile to the \ right JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile) AND #%00001111 \ Extract the tile altitude from the low nibble and STA V \ store it in V INC zTile \ Move along the x-axis to fetch the next tile into the \ screen JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile) AND #%00001111 \ Extract the tile altitude from the low nibble and STA U \ store it in U DEC xTile \ Move back along the x-axis to fetch the next tile to \ the left JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile) AND #%00001111 \ Extract the tile altitude from the low nibble and STA T \ store it in T DEC zTile \ Move out of the screen, back along the z-axis to take \ us back to the tile we are processing \ So at this point we have the altitudes of four tile \ corners, as follows, with the view from above: \ \ ^ [T] [U] \ | \ | [S] [V] \ z-axis \ into \ screen x-axis from left to right ---> \ \ S is the altitude of the tile corner that anchors the \ tile for which we are calculating the shape, and T, U \ and V are the altitudes of the tile's other three \ corners, so now we can analyse the shape of the tile LDA S \ If S = V then jump to shap10 CMP V BEQ shap10 CMP T \ If S = T then jump to shap4 BEQ shap4 LDA U \ If U = V then jump to shap2 CMP V BEQ shap2 .shap1 \ If we get here then we either fell through from above: \ \ * S <> V \ * S <> T \ * U <> V \ \ or we jumped here from shap10 and: \ \ * S == V \ * S <> T \ * U <> T \ * U <> V LDX #12 \ Return a shape value of 12 in X RTS \ Return from the subroutine .shap2 \ If we get here then then: \ \ * S <> V \ * S <> T \ * U == V \ \ and A is set to U CMP T \ If U <> T then jump to shap5 BNE shap5 \ If we get here then: \ \ * S <> V \ * S <> T \ * U == V \ * U == T \ \ and A is set to U LDX #2 \ Set X = 2 to return as the shape if U >= S CMP S \ If U >= S then jump to shap3 to return a shape value BCS shap3 \ of 2 LDX #11 \ U < S so return a shape value of 11 in X .shap3 RTS \ Return from the subroutine .shap4 \ If we get here then: \ \ * S <> V \ * S == T LDA U \ If U = V then jump to shap8 CMP V BEQ shap8 \ If we get here then: \ \ * S <> V \ * S == T \ * U <> V \ \ and A is set to U CMP T \ If U = T then jump to shap6 BEQ shap6 .shap5 \ If we get here then either we jumped from shap2: \ \ * S <> V \ * S <> T \ * U == V \ * U <> T \ \ or we fell through from above: \ \ * S <> V \ * S == T \ * U <> V \ * U <> T LDX #4 \ Return a shape value of 4 in X RTS \ Return from the subroutine .shap6 \ If we get here then: \ \ * S <> V \ * S == T \ * U <> V \ * U == T \ \ and A is set to U LDX #14 \ Set X = 14 to return as the shape if U < V CMP V \ If U < V then jump to shap7 to return a shape value BCC shap7 \ of 14 LDX #7 \ U >= V so return a shape value of 7 in X .shap7 RTS \ Return from the subroutine .shap8 \ If we get here then: \ \ * S <> V \ * S == T \ * U == V \ \ and A is set to U LDX #5 \ Set X = 5 to return as the shape if U < T CMP T \ If U < T then jump to shap7 to return a shape value BCC shap9 \ of 5 LDX #13 \ U >= T so return a shape value of 13 in X .shap9 RTS \ Return from the subroutine .shap10 \ If we get here then: \ \ * S == V \ \ and A is set to S CMP T \ If S = T then jump to shap14 BEQ shap14 LDA U \ If U = T then jump to shap12 CMP T BEQ shap12 \ If we get here then: \ \ * S == V \ * S <> T \ * U <> T \ \ and A is set to U CMP V \ If U <> V then jump to shap1 BNE shap1 \ If we get here then: \ \ * S == V \ * S <> T \ * U <> T \ * U == V \ \ and A is set to U LDX #6 \ Set X = 6 to return as the shape if U < T CMP T \ If U < T then jump to shap11 to return a shape value BCC shap11 \ of 6 LDX #15 \ U >= T so return a shape value of 15 in X .shap11 RTS \ Return from the subroutine .shap12 \ If we get here then: \ \ * S == V \ * S <> T \ * U == T \ \ and A is set to U LDX #1 \ Set X = 1 to return as the shape if U < V CMP V \ If U < V then jump to shap11 to return a shape value BCC shap13 \ of 1 LDX #9 \ U >= V so return a shape value of 9 in X .shap13 RTS \ Return from the subroutine .shap14 \ If we get here then: \ \ * S == V \ * S == T \ \ and A is set to S CMP U \ If S = U then jump to shap16 BEQ shap16 LDX #10 \ Set X = 10 to return as the shape if S < U BCC shap15 \ If S < U then jump to shap15 to return a shape value \ of 10 LDX #3 \ S > U so return a shape value of 93 in X .shap15 RTS \ Return from the subroutine .shap16 \ If we get here then: \ \ * S == V \ * S == T \ * S == U LDX #0 \ Return a shape value of 0 in X RTS \ Return from the subroutineName: GetTileShape [Show more] Type: Subroutine Category: Landscape Summary: Calculate the shape of the tile anchored at (xTile, zTile)Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GenerateLandscape calls GetTileShape
Given a tile at altitude S, with neighbouring altitudes T, U and V: ^ [T] [U] | | [S] [V] z-axis into screen x-axis from left to right ---> The shape is calculated as follows, where: * 0 and 1 represent arbitrary altitudes that are in that order, with 1 being higher than 0 * a, b represent arbitrary altitudes where a <> b <> 1 These are all the different types of shape (note there is no shape 8, and shapes 4 and 12 can have multiple layouts): Shape S vs V S vs T S vs U U vs V U vs T Layout ----- ------ ------ ------ ------ ------ ------ 0 S == V S == T S == U 1 1 1 1 1 S == V S <> T U < V U == T 0 0 1 1 2 S <> V S <> T S <= U U == V U == T 1 1 0 1 3 S == V S == T S > U 1 0 1 1 4a S <> V S <> T U == V U <> T a 1 b 1 4b S <> V S == T U <> V U <> T 1 a 1 b 5 S <> V S == T U == V U < T 1 0 1 0 6 S == V S <> T U == V U < T 1 0 0 0 7 S <> V S == T U >= V U == T 1 1 1 0 9 S == V S <> T U >= V U == T 1 1 0 0 10 S == V S == T S < U 0 1 0 0 11 S <> V S <> T S > U U == V U == T 0 0 1 0 12a S <> V S <> T U <> V 1 1 a b 12b S == V S <> T U <> V U <> T a b 1 1 13 S <> V S == T U == V U >= T 0 1 0 1 14 S <> V S == T U < V U == T 0 0 0 1 15 S == V S <> T U == V U >= T 0 1 1 1 Note that for shape 12a, the top-right corner could in theory be a different altitude to a, b and 1, and the comparisons would still fit. However, the way the landscape gets smoothed ensures that every tile has at least one horizontal edge, so this means the top-right corner must be at altitude 1. It is worth noting that: * Shape 0 has four horizontal edges * Shapes 4 and 12 have one horizontal edge and three sloping edges * Shape 8 is unused * All other shapes (1, 2, 3, 5, 6, 7, 9, 10, 11, 14 and 15) have two horizontal edges and two sloping edges
Returns: X The shape of the tile anchored at (xTile, zTile)
[X]
Subroutine GetTileData (category: Landscape)
Get the tile data and tile data address for a specific tile
[X]
Label shap1 is local to this routine
[X]
Label shap10 is local to this routine
[X]
Label shap11 is local to this routine
[X]
Label shap12 is local to this routine
[X]
Label shap13 is local to this routine
[X]
Label shap14 is local to this routine
[X]
Label shap15 is local to this routine
[X]
Label shap16 is local to this routine
[X]
Label shap2 is local to this routine
[X]
Label shap3 is local to this routine
[X]
Label shap4 is local to this routine
[X]
Label shap5 is local to this routine
[X]
Label shap6 is local to this routine
[X]
Label shap7 is local to this routine
[X]
Label shap8 is local to this routine
[X]
Label shap9 is local to this routine