Aviator on the BBC Micro

# Graphics: VduPlot

```       Name: VduPlot                                                 [Show more]
Type: Subroutine
Category: Graphics
Summary: Perform a plot command using the standard VDU routines
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* VduMove calls VduPlot
* VduPoint calls VduPlot

Arguments:

A                    The type of plot command:

* 4 = Move cursor to coordinate

* 5 = Draw line from cursor to coordinate

* 69 = Draw point at coordinate

X                    The x-coordinate for the plot command (0-159)

Y                    The y-coordinate for the plot command (0-255)

.VduPlot

PHA                    \ Store the value of A on the stack, so we can retrieve
\ it after the call to OSWRCH

LDA #25                \ Start a VDU 25 command, which is the equivalent of a
JSR OSWRCH             \ PLOT command in BBC BASIC, and which has the following
\ format:
\
\   VDU 25, K, X; Y;
\
\ where K is the plotting mode (i.e. move or draw) and
\ X and Y are the relevant coordinates as 16-bit numbers

PLA                    \ Retrieve the value of A that we stored on the stack

JSR OSWRCH             \ Write the K parameter of the VDU command, i.e. the
\ type of plot command

LDA #0                 \ Set P = 0
STA P

TXA                    \ Set A = X, so now (P A) contains the x-coordinate as a
\ 16-bit number

ASL A                  \ Set (P A) = (P A) * 8
ROL P                  \           = x-coordinate * 8
ASL A                  \
ROL P                  \ This gives the screen location of the x-coordinate in
ASL A                  \ terms of VDU coordinates, where the screen is always
ROL P                  \ 1280 pixels wide, which is 8 times the number of
\ pixels in 160-pixel-wide mode 5 (i.e. 8 * 160 = 1280)

JSR OSWRCH             \ Write (P A), writing the low byte in A first

LDA P                  \ And then the high byte in P
JSR OSWRCH

LDA #0                 \ Set P = 0
STA P

TYA                    \ Set A = Y, so now (P A) contains the y-coordinate as a
\ 16-bit number

ASL A                  \ Set (P A) = (P A) * 4
ROL P                  \           = y-coordinate * 4
ASL A                  \
ROL P                  \ This gives the screen location of the y-coordinate in
\ terms of VDU coordinates, where the screen is always
\ 1024 pixels high, which is 4 times the number of
\ pixels in 256-pixel-high mode 5 (i.e. 4 * 256 = 1024)

JSR OSWRCH             \ Write (P A), writing the low byte in A first

LDA P                  \ And then the high byte in P
JSR OSWRCH

RTS                    \ Return from the subroutine
```