Skip to navigation

Revs on the BBC Micro

Drawing objects: DrawObjectEdge (Part 5 of 5)

Name: DrawObjectEdge (Part 5 of 5) [Show more] Type: Subroutine Category: Drawing objects Summary: Fill the object if required and loop back for the next edge Deep dive: Creating objects from edges
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawEdge calls via draw29 * DrawObjectEdge (Part 2 of 5) calls via draw29 * DrawObjectEdge (Part 3 of 5) calls via draw29

Other entry points: draw29 Fill the inside of the object part from the previous block to the current one
.draw29 \ We have finished drawing the edge, so now we need to \ fill the inside of the object part, from the previous \ block to the current one LDA prevBlockNumber \ If prevBlockNumber < 40, then it is a valid block CMP #40 \ number in the range 0 to 39, so jump to draw30 to skip BCC draw30 \ the following instruction and fill the object from \ this block onwards \ If we get here then prevBlockNumber is off-screen, \ which means it must be off the left edge of the screen \ (as we are working from left to right), so we now need \ to fill from the left edge of the screen to the edge \ we just drew LDA #&FF \ Set prevBlockNumber = -1, so the following subtraction STA prevBlockNumber \ sets: \ \ A = blockNumber - prevBlockNumber - (1 - C) \ = blockNumber - -1 - 1 \ = blockNumber \ \ so the following fills this many blocks, which means \ it fills all the blocks from the left edge of the \ screen to the edge we just drew .draw30 LDA blockNumber \ Set A = blockNumber - prevBlockNumber - (1 - C) CLC \ = blockNumber - prevBlockNumber - 1 SBC prevBlockNumber BEQ draw31 \ If A <= 0, then: BMI draw31 \ \ blockNumber - prevBlockNumber - 1 <= 0 \ \ blockNumber - prevBlockNumber <= 1 \ \ so the current block and the previous block are either \ the same block or neighbours, in which case there is \ no gap to fill between the edges, so jump to draw31 to \ return from the subroutine as we are done drawing \ If we get here then A > 0, so from the above: \ \ blockNumber - prevBlockNumber > 1 \ \ so there is at least one full block between the \ current block and the previous block \ \ We therefore need to fill this gap with the relevant \ fill colour, with the number of blocks between the \ two edges given in A (without including the edges \ themselves) TAX \ Set X = A, so X contains the number of blocks we need \ to fill to the left of the edge we just drew JSR FillInsideObject \ Fill the inside of the object (i.e. all the blocks \ between the previous edge and the edge we just drew) .draw31 RTS \ Return from the subroutine .draw32 \ We jump here if the block number in blockNumber \ is >= 40, which means we the edge we are trying to \ draw is off the right of the screen, so now we need \ to work out whether we need to fill the object up to \ the edge of the screen LDY J \ If the edge type in J = 1, then we are drawing the CPY #1 \ left edge, so jump to draw31 to return from the BEQ draw31 \ subroutine as the whole object part is off-screen LDA prevBlockNumber \ If prevBlockNumber >= 40, then the dash data block CMP #40 \ number from the previous call to DrawObjectEdge is BCS draw31 \ also past the right edge of the screen, so jump to \ draw31 to return from the subroutine as the whole \ part between this edge and the previous edge is \ off-screen \ Otherwise we are drawing a right edge or an extra edge \ and the previous call to DrawObjectEdge was on-screen, \ so we need to fill between the previous edge and the \ right edge of the screen LDA #40 \ Set blockNumber = 40 to represent the block beyond the STA blockNumber \ right edge of the screen in the calculation at draw30, \ which works out whether to call FillInsideObject to \ fill from the previous edge to this block number BNE draw30 \ Jump to draw30 (this BNE is effectively a JMP as A is \ never zero)