\ We now loop through the top seven rows in the \ character definition, using X as the row counter \ \ We draw the character from the bottom up on the \ landscape, so that's drawing the character rows on \ the landscape from front the back as we work through \ the character definition from bottom to top \ \ The row counter in X therefore iterates from 7 down \ to 0, with row 7 spawning the blocks for the \ penultimate row in the character definition, and row 0 \ spawning a blank row (as this moves the blank row in \ the character definition from the bottom to the top, \ as discussed in part 1) .spac3 ASL characterDef,X \ The leftmost column of each character definition is \ blank, so that characters are spaced out, so this \ shifts the character definition row to the left to \ move this blank column to the right side of the \ character definition, so the character's 3D blocks \ start at the correct tile coordinate LDA xTileCharacter \ Set xTile to the x-coordinate where we want to spawn STA xTile \ the character \ Each row in the character definition consists of eight \ bits (where each bit will be represented by a block on \ the landscape) \ \ In order to get tall characters on-screen, rather than \ the rather square characters in the operating system's \ font, we actually draw each character so that it's \ four tiles wide and eight tiles tall, so each tile \ contains a pair of blocks that represents a pair of \ bits in the character definition LDA #4 \ Set a loop counter in loopCounter to work through the STA loopCounter \ four pairs in the eight-block row .spac4 ASL characterDef,X \ Shift the character definition row to the left by two ROL A \ places and extract the top two bits into bits 0 and 1 ASL characterDef,X \ of A, so this is the leftmost block pair from this row ROL A AND #%00000011 \ Clear bits 2 to 7 of A and store the result in Y, so TAY \ Y contains the bit pattern for the two leftmost bits \ in the character row \ \ We can now use this as an index into the table that \ maps bit patterns to object numbers in objBlockNumber LDA objBlockNumber,Y \ Fetch the object number of the 3D text block object \ that matches the bit pair that we just extracted \ \ This actually fetches the object number + 32, though \ the 32 part is removed when the block is drawn in the \ DrawTileAndObjects, so this doesn't seem to have any \ effect PHA \ Store the object number on the stack, as follows: \ \ * 32 + 0 for no blocks in the pair \ \ * 32 + 7 for no block (left), block (right) \ \ * 32 + 8 for block (left), no block (right) \ \ * 32 + 9 for block (left), no block (right) \ \ This maps the pair to one of the three 3D text block \ objects JSR GetTileData \ Set A to the tile data for the tile anchored at \ (xTile, zTile), which we ignore, but this also sets \ the tile page in tileDataPage and the index in Y, so \ tileDataPage+Y now points to the tile data entry in \ the tileData table PLA \ Retrieve the object number for the 3D text block pair STA (tileDataPage),Y \ and store it in the tile data for the tile where we \ want to spawn this part of the character definition \ \ Note that the DrawTileAndObjects routine has separate \ logic when drawing 3D text, so this doesn't follow the \ normal tile data rules, and instead we just need the \ object number in the low nibble, which we fetched from \ the objBlockNumber above INC xTile \ Increment the x-coordinate to move on to the next tile \ to the right, for the next bit pair DEC loopCounter \ Decrement the loop counter to move onto the next bit \ pair in the character definition BNE spac4 \ Loop back to spawn the next bit pair's objects until \ we have done all four pairs in the character row INC zTile \ Increment the z-coordinate to move backwards to the \ tile row behind in the landscape DEX \ Decrement the character row counter in X BMI spac5 \ If we just spawned row 0 then X will now be negative, \ so jump to spac5 to finish off as we have spawned all \ eight character rows BNE spac3 \ Otherwise loop back until we have spawned rows 7 to 1 \ If we get here then we just spawned row 1, so now we \ need to spawn a blank for row 0 LDA #0 \ Zero the character definition row that we will use STA characterDef \ when X is 0, so we don't spawn any blocks for the top \ row of the 3D text block character BEQ spac3 \ Jump to spac3 to spawn row 0 (this BEQ is effectively \ a JMP as A is always zero) .spac5 LDA xTileCharacter \ We just spawned a character in the landscape, so add 4 CLC \ to xTileCharacter so the next character gets spawned ADC #4 \ to the right of the one we just spawned STA xTileCharacter PLA \ Pull A from the stack to reverse the push that we did \ at the start of the routine TAY \ Retrieve X and Y from the stack so they are preserved PLA TAX PLA RTS \ Return from the subroutineName: SpawnCharacter3D (Part 2 of 2) [Show more] Type: Subroutine Category: Title screen Summary: Spawn large 3D blocks for the extracted character definitionContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Subroutine GetTileData (category: Landscape)
Get the tile data and tile data address for a specific tile
[X]
Variable characterDef in workspace Main variable workspace
An OSWORD block for reading a character definition
[X]
Variable loopCounter in workspace Zero page
A general-purpose loop counter
[X]
Variable objBlockNumber (category: Title screen)
A lookup table to convert bit pairs into object numbers for spawning 3D text blocks on the landscape
[X]
Label spac3 is local to this routine
[X]
Label spac4 is local to this routine
[X]
Label spac5 is local to this routine
[X]
Variable tileDataPage in workspace Zero page
The address of the tileData page containing the current tile's data
[X]
Variable xTileCharacter in workspace Main variable workspace
The tile x-coordinate of the character being spawned in large 3D blocks on the landscape for the title screen