Skip to navigation

Landscape: GetTileData

Name: GetTileData [Show more] Type: Subroutine Category: Landscape Summary: Get the tile data and tile data address for a specific tile
The tile data table at tileData is made up of sequences of 32 columns of tile corners going into the screen, where each column goes from z = 0 to 31 along the same x-coordinate, with the columns interleaved in steps of 4 like this: &0400-&041F = 32-corner column going into the screen at x = 0 &0420-&043F = 32-corner column going into the screen at x = 4 &0440-&045F = 32-corner column going into the screen at x = 8 &0460-&047F = 32-corner column going into the screen at x = 12 &0480-&049F = 32-corner column going into the screen at x = 16 &04A0-&04BF = 32-corner column going into the screen at x = 20 &04C0-&04DF = 32-corner column going into the screen at x = 24 &04E0-&04FF = 32-corner column going into the screen at x = 28 &0500-&051F = 32-corner column going into the screen at x = 1 &0520-&053F = 32-corner column going into the screen at x = 5 &0540-&055F = 32-corner column going into the screen at x = 9 &0560-&057F = 32-corner column going into the screen at x = 13 &0580-&059F = 32-corner column going into the screen at x = 17 &05A0-&05BF = 32-corner column going into the screen at x = 21 &05C0-&05DF = 32-corner column going into the screen at x = 25 &05E0-&05FF = 32-corner column going into the screen at x = 29 &0600-&061F = 32-corner column going into the screen at x = 2 &0620-&063F = 32-corner column going into the screen at x = 6 &0640-&065F = 32-corner column going into the screen at x = 10 &0660-&067F = 32-corner column going into the screen at x = 14 &0680-&069F = 32-corner column going into the screen at x = 18 &06A0-&06BF = 32-corner column going into the screen at x = 22 &06C0-&06DF = 32-corner column going into the screen at x = 26 &06E0-&06FF = 32-corner column going into the screen at x = 30 &0700-&071F = 32-corner column going into the screen at x = 3 &0720-&073F = 32-corner column going into the screen at x = 7 &0740-&075F = 32-corner column going into the screen at x = 11 &0760-&077F = 32-corner column going into the screen at x = 15 &0780-&079F = 32-corner column going into the screen at x = 19 &07A0-&07BF = 32-corner column going into the screen at x = 23 &07C0-&07DF = 32-corner column going into the screen at x = 27 &07E0-&07FF = 32-corner column going into the screen at x = 31
Arguments: xTile A tile corner x-coordinate (0 to 31) zTile A tile corner z-coordinate (0 to 31)
Returns: A The tile data for the tile anchored at (xTile, zTile): * If the tile does not contain an object, then: * The tile shape is in the low nibble (0 to 15) * The tile altitude is in the high nibble (1 to 11) * If the tile contains an object, then: * Bits 0 to 5 contain the object number of the object on the tile (0 to 63) * Bits 6 and 7 are both set tileDataPage(1 0) The address of the page containing the tile data Y The offset from tileDataPage(1 0) of the tile data C flag Determines whether the tile contains an object: * Set if this tile contains an object * Clear if this tile does not contain an object
.GetTileData LDA xTile \ Set Y = (xTile << 3 and %11100000) + zTile ASL A \ = (xTile >> 2 and %00000111) << 5 + zTile ASL A \ = (xTile div 4) * &20 + zTile ASL A AND #%11100000 ORA zTile TAY LDA xTile \ Set A = bits 0-1 of xTile AND #%00000011 \ = xTile mod 4 \ The low byte of tileDataPage(1 0) gets set to zero in \ ResetVariables and is never changed \ \ The low byte of tileData is also zero, as we know that \ tileData is &0400 \ \ So in the following, we are just adding the high bytes \ to get a result that is on a page boundary CLC \ Set the following: ADC #HI(tileData) \ STA tileDataPage+1 \ tileDataPage(1 0) = tileData + (A 0) \ = tileData + (xTile mod 4) * &100 \ So we now have the following: \ \ tileDataPage(1 0) = tileData + (xTile mod 4) * &100 \ \ Y = (xTile div 4) * &20 + zTile \ \ The address in tileDataPage(1 0) is the page within \ tileData for the tile anchored at (xTile, zTile), and \ is always one of &0400, &0500, &0600 or &0700 because \ (xTile mod 4) is one of 0, 1, 2 or 3 \ \ The value of Y is the offset within that page of the \ tile data for the tile anchored at (xTile, zTile) \ \ We can therefore fetch the tile data for the specified \ tile using Y as an index offset from tileDataPage(1 0) LDA (tileDataPage),Y \ Set A to the tile data for the tile anchored at \ (xTile, zTile) CMP #%11000000 \ Set the C flag if A >= %11000000, which will be the \ case if both bit 6 and bit 7 of A are set RTS \ Return from the subroutine