Aviator on the BBC Micro

# Drawing lines: DrawVectorLine (Part 3 of 3)

```       Name: DrawVectorLine (Part 3 of 3)                            [Show more]
Type: Subroutine
Category: Drawing lines
Summary: Plot a pixel at (I, J)
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

.dvec11

\ When we first arrive here:
\
\   * QQ = 0, where we will tally up the fractional part
\          of the move along the shortest axis
\   * RR = pixel byte table
\   * VV = longest side of delta triangle
\   * PP = 0 (shallow horizontal)
\          VV (steep vertical)
\
\ so we now draw a line from (I, J), moving one pixel
\ at a time along the longest side of the delta triangle

LDA I                  \ Set X = I / 4
LSR A                  \
LSR A                  \ so X is the number of the character block containing
TAX                    \ pixel (I, J), as each character block is 4 pixels wide

LDA J                  \ Set Y = J / 8
LSR A                  \
LSR A                  \ so Y is the number of the character row containing
LSR A                  \ pixel (I, J), as each character row is 8 pixels high
TAY

LDA yLookupLo,Y        \ Set P = Y-th byte of yLookupLo
CLC                    \         + X-th byte of xLookupLo
STA P

LDA yLookupHi,Y        \ Set Q = Y-th byte of yLookupHi
ADC xLookupHi,X        \         + X-th byte of xLookupHi
STA Q                  \       = HI(screen address) + HI(X * 8)

\ So (Q P) is the screen address of the pixel row
\ containing pixel (I, J), out by 8 bytes for each row
\ above or below the top of the dashboard

LDA #159               \ Set Y = 159 - J
SEC                    \
SBC J                  \ so Y is the number of pixels that (I, J) is above
TAY                    \ (+ve) or below (-ve) the top of the dashboard, where a
\ value of 0 is the bottom pixel inside the canopy, and
\ a value of -1 is the white horizontal edge at the
\ bottom of the canopy

LDA I                  \ Set X = bits 0 and 1 of I
AND #%00000011         \       = I mod 4
TAX                    \       = pixel number within the 4-pixel byte

BIT N                  \ If bit 7 of N is set, jump to dvec12 to erase the line
BMI dvec12             \ with EOR logic instead of drawing it with OR logic

LDA RR,X               \ Fetch the X-th byte of RR, which is a pixel byte with
\ the X-th pixel set to white

ORA (P),Y              \ OR it with (Q P) + Y, which is the screen address of
\ the pixel row containing (I, J)
\
\ This will keep all pixels the same except the X-th
\ pixel, which is set to white, so this will plot a
\ pixel at (I, J) when stored in screen memory

\ instructions

.dvec12

LDA RR,X               \ Fetch the X-th byte of RR, which is a pixel byte with
\ the X-th pixel set to white

EOR #%11111111         \ Invert all the bits, so A is now a pixel byte that is
\ all white except for the X-th pixel, which is black

AND (P),Y              \ AND it with (Q P) + Y, which is the screen address of
\ pixel (I, J)
\
\ This will keep all pixels the same except the X-th
\ pixel, which is set to black, so this will erase the
\ pixel at (I, J) when stored in screen memory

.dvec13

STA (P),Y              \ Store the byte in A in screen memory at (Q P) + Y,
\ which sets all four pixels to the pixel pattern in A,
\ which either draws or erases the pixel at (I, J)

DEC VV                 \ Decrement VV to step one pixel along the longer axis

BNE dvec7              \ If VV is non-zero, jump up to dvec7 to calculate the
\ coordinate of the next pixel in the line

RTS                    \ Return from the subroutine
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.7867636,"math_prob":0.9808105,"size":3747,"snap":"2023-40-2023-50","text_gpt3_token_len":1048,"char_repetition_ratio":0.14560513,"word_repetition_ratio":0.21328224,"special_character_ratio":0.29516947,"punctuation_ratio":0.070876285,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99745774,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-04T12:38:42Z\",\"WARC-Record-ID\":\"<urn:uuid:b3c8c625-795d-4d83-80fd-37ee326de8db>\",\"Content-Length\":\"227167\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f61408b2-2f2b-4ce9-a6fc-6495d5397b9f>\",\"WARC-Concurrent-To\":\"<urn:uuid:f4f1c381-25b5-432c-88f9-5f011b16c183>\",\"WARC-IP-Address\":\"208.113.168.181\",\"WARC-Target-URI\":\"https://aviator.bbcelite.com/source/main/subroutine/drawvectorline_part_3_of_3.html\",\"WARC-Payload-Digest\":\"sha1:JV5RU7LIWZ6JI3HD7XQVS3AT3PBXPK6U\",\"WARC-Block-Digest\":\"sha1:2DATGTINWOJGRHVS6CRJFIPGDCU7BV27\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233511369.62_warc_CC-MAIN-20231004120203-20231004150203-00509.warc.gz\"}"}