Skip to navigation

Drawing the landscape: DrawTileAndObjects

Name: DrawTileAndObjects [Show more] Type: Subroutine Category: Drawing the landscape Summary: Draw a tile and any objects stacked on it
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawLandscapeRow calls DrawTileAndObjects

Arguments: xTileToDraw The tile x-coordinate (i.e. the tile column) zTile The tile z-coordinate (i.e. the tile row)
.tobj1 \ If we get here then we need to draw a block in the \ title screen's 3D text \ \ We use object #63 for this purpose, and we set it to \ the object number for the 3D text block pair that the \ SpawnCharacter3D put into bits 0 to 3 of the tile data LDA tileViewData,X \ Set the object type for object #63 to the bottom AND #%00001111 \ nibble of the tile data, which contains the object STA objectTypes+63 \ number for the 3D text block pair for this part of the \ text: \ \ * 0 for no blocks in the pair \ \ * 7 for no block (left), block (right) \ \ * 8 for block (left), no block (right) \ \ * 9 for block (left), no block (right) BEQ buff1 \ If the object type is zero then jump to buff1 to \ return from the subroutine without drawing anything \ Otherwise we have set the type of object #63 to the \ correct 3D text block object, so now we set the tile \ coordinate and draw the object LDA xTileToDraw \ Set the x-coordinate for the block in object #63 to STA xObject+63 \ the tile column in xTileToDraw LDA zTile \ Set the z-coordinate for the block in object #63 to STA zObject+63 \ the tile row in zTile LDY #63 \ Set Y = 63 to pass to the DrawObject routine so we \ draw object #63 JMP DrawObject \ Jump to DrawObject to draw the 3D text block we've set \ up in object #63, returning from the subroutine using \ a tail call .DrawTileAndObjects JSR ProcessSound \ Process any sounds or music that are being made in the \ background LDA xTileToDraw \ Set X to the index of the tile data that we set up for ORA drawingTableOffset \ this tile in part 2 of the GetTileViewAngles routine CLC ADC quadrantOffset AND #%00111111 TAX BIT drawingTitleScreen \ If bit 7 of drawingTitleScreen is set then we are BMI tobj1 \ drawing a title screen, so jump up to tobj1 to draw \ this tile as a block in the title screen's 3D text LDA tileViewData,X \ Set A to the tile data for the current view, which we \ set in the GetTileViewAngles routine to the tile data \ for this tile, but zeroed if the tile is not visible \ (which will happen if the tile does not contain an \ object and is marked as not being visible from the \ player's point of view in the tileVisibility table) BEQ buff1 \ If A is zero then we marked this tile as being hidden \ in part 3 of the GetTileViewAngles routine, so jump to \ buff1 to return from the subroutine without drawing \ anything CMP #%11000000 \ If both bits 6 and 7 are set in the tile data then the BCC tobj2 \ tile we are analysing contains an object, in which \ case keep going, otherwise there is no object on the \ tile so jump to tobj2 \ If we get here then the tile we are drawing contains \ an object PHA \ Store the tile data on the stack JSR DrawFlatTile \ Draw the flat tile that's beneath the object PLA \ Retrieve the tile data from the stack JMP DrawObjectStack \ Draw the stack of objects on top of the tile, and \ return from the subroutine using a tail call .tobj2 \ If we get here then the tile we are drawing does not \ contain an object AND #%00001111 \ Set A to the tile shape for the tile, which is in the \ bottom nibble of the tile data BEQ DrawFlatTile \ If the tile shape is zero then the tile is flat, so \ jump to DrawFlatTile to draw the flat tile, returning \ from the subroutine using a tail call CMP #12 \ If the tile shape is 12 then we know the tile consists BEQ tobj3 \ of two faces, so jump to tobj3 CMP #4 \ If the tile shape is 4 then we know the tile consists BNE DrawSlopingTile \ of two faces, so keep going, otherwise we don't know \ how many faces it contains, so jump to DrawSlopingTile \ to work this out .tobj3 \ If we get here then the tile shape is 4 or 12, both of \ which we know consist of two triangular faces PHA \ Store the tile shape on the stack LDA viewingQuadrantOpp \ Set triangleStartPoint to bit 0 of viewingQuadrantOpp AND #1 \ to pass to the DrawTwoFaceTile routine STA triangleStartPoint PLA \ Retrieve the tile shape from the stack BNE DrawTwoFaceTile \ Jump to DrawTwoFaceTile to draw the tile, returning \ from the subroutine using a tail call (this BNE is \ effectively a JMP as we know the tile shape is \ non-zero)