# Drawing objects: DrawObjectEdge (Part 2 of 5)

```       Name: DrawObjectEdge (Part 2 of 5)                            [Show more]
Type: Subroutine
Category: Drawing objects
Summary: Calculate the screen address for the edge we want to draw
Deep dive: Creating objects from edges
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

.draw7

LDA blockNumber        \ Set A to the dash data block number for the edge to
\ draw, which we stored in blockNumber in part 1

CMP #20                \ If blockNumber >= 20, set bit 0 of T, otherwise clear
ROL T                  \ it, so bit 0 of T is clear if the edge is in the left
\ half of the screen, and set if the edge is in the
\ right half

LSR A                  \ Set (A P) = (A P) >> 1
ROR P                  \           = (blockNumber 0) >> 1
\           = blockNumber * 128
\           = blockNumber * &80

CLC                    \ Set (Q P) = (A P) + dashData
STA Q                  \ This addition works because the low byte of dashData
\ is zero

\ So we now have:
\
\   (Q P) = dashData + blockNumber * &80
\
\ which is the start address of the dash data block,
\ because the dash data blocks occur every &80 bytes
\ from dashData

IF _ACORNSOFT OR _4TRACKS

STA draw27+2           \ Modify the following instruction at draw27:
LDA P                  \
STA draw27+1           \   LDX &3000,Y -> LDX #(Q P),Y
\
\ This is pseudo-code, but it means we have modified the
\ instruction to load the Y-th byte from the dash data
\ byte of the dash data block for the edge to draw

ENDIF

LDX blockNumber        \ Set X to the dash data block number for the edge to
\ draw

CPX #40                \ If blockNumber < 40 then blockNumber is a valid dash
BCC draw8              \ data block number in the range 0 to 39, so jump to
\ draw8 to keep going

JMP draw32             \ Otherwise blockNumber is not a valid dash data block
\ number and is off the right edge of the screen, so
\ jump to draw32 to work out whether we need to fill
\ the object all the way to the right edge of the screen

.draw8

LDA bottomTrackLine    \ Set A = bottomTrackLine, which is the number of the
\ track line at the bottom of the object, and which is
\ the same as the offset into the dash data block for
\ the bottom edge

CMP dashDataOffset,X   \ If A >= the dash data offset for our dash data block,
BCS draw9              \ then A is pointing to dash data, so jump to draw9 to
\ skip the following instruction

LDA dashDataOffset,X   \ Set A to the dash data offset for our dash data block,
\ so it points to the first byte of the block's dash
\ data (i.e. the lowest byte of the dash data block
\ on-screen)

.draw9

STA blockOffset        \ Set blockOffset = A, so blockOffset contains the dash
\ data block offset for the bottom track line of the
\ edge we want to draw

CMP topTrackLine       \ If A < topTrackLine, then the track lines are the
BCC draw11             \ right way around, so jump to draw11 to keep going in
\ part 3

CPY #1                 \ If Y <> 1, then we are drawing either a right edge or
BNE draw10             \ an extra edge, so jump to draw29 via draw10 to check
\ whether we need to fill to the left of this edge, and
\ then move on to the next edge

\ If we get here then A >= topTrackLine and Y = 1, so
\ we are drawing the left edge and the bottom track line
\ is higher than the top track line, which means there
\ is nothing to draw, so we return from the subroutine

RTS                    \ Return from the subroutine

.draw10

JMP draw29             \ Jump to draw29 to check whether we need to fill to the
\ left of this edge, and then move on to the next edge
```