The &b09; Graphics Interface Module
The Graphics Interface module provides a simple and convenient
way to access the color graphics and joystick functions of the
Dragon Computer from &b09; programs. The module is a program
written in assembly language and stored in a file called "GFX". It
can be loaded into memory using the OS-9 "LOAD" command prior to or
after called &b09;, or it will be automatically called by &b09;
the first time it is referenced in a program if the "GFX" file is
located in the execution ("CMDS") directory.
"GFX" is called using the &b09; "RUN" statement. The first
parameter passed is the name of the graphics function desired.
Other parameters are used to pass coordinates, color modes, etc.
The are two basic graphics modes: 4-color having 128 by 192
pixel resolution, and 2-color having 256 by 192 pixel resolution.
The display is treated as a 256 by 192 point grid with coordinates
0,0 in the lower left-hand corner. X (horizontal) coordinates in
either mode must be in the range of 0 to 255. An X-coordinate
greater than 255 will cause a run-time error. Y coordinates
(vertical) must be in the range of 0 to 191. A number greater than
191 will be replaced by 191. Some of the graphics functions require
or optionally accept a color mode which controls the foreground
color and color set. The mode and color codes are given in the
table on the next page.
Color Graphics Modes and Color Codes
Color Code
Two Color Format
Four Color Format
Background
Foreground
Background
Foreground
Color Set 1
00
Black
Black
Green
Green
01
Black
Green
Green
Yellow
02
Green
Blue
03
Green
Red
Color Set 2
04
Black
Black
Buff
Buff
05
Black
Buff
Buff
Cyan
06
Buff
Magenta
07
Buff
Orange
Color Set 3*
08
Black
Black
09
Black
Dark Green
10
Black
Med. Green
11
Black
Light Green
Color Set 4*
12
Black
Black
13
Black
Green
14
Black
Red
15
Black
Buff
Color Sets 3 and 4 are not available on PAL video system
(U.K. and European) models.
MODE
RUN GFX("Mode",format,color)
MODE switches the screen from alphanumeric to graphics display mode,
and selects the screen mode and color mode. "Format" determines
between two-color (Format = 0), or four-color (Format = 1)
graphics modes. "Color" is the initial color code that specifies
the foreground color and color set.
This command must be given before aby other graphics command is
used. The first time MODE is called, it requests 6K bytres of memory
from OS-9 for use as the graphics display memory. MODE will return
an error if sufficient free memory is not available.
An example:
RUN GFX("Mode",1,3)
selects four-color mode graphics is used, and the initial
foreground color is red.
MOVE
RUN GFX("Move",x,y)
MOVE positions the (invisible) graphics cursor to the specified
location without changing the display. X and Y are the coordinates
of the new position.
Example:
RUN GFX("Move",0,0)
This example positions the cursor in the lower left-hand corner.
COLOR
RUN GFX("Color",color)
COLOR changes the current foreground color (and possibly the color
set). The current graphics mode and cursor position are not
changed. For example:
RUN GFX("Color",0)
changes the foreground color to green in four-color format (or
black in two-color format).
POINT
RUN GFX("Point",x,y) or
RUN GFX("Point",x,y,color)
POINT moves the graphics cursor to the specified X.Y coordinate and
sets the pixel at that coordinate to the current foreground color.
If the optional "Color" is specified, the current foreground color
is set to the given "Color". For example:
RUN GFX("Point",0,192,1)
Point moves the cursor to the upper left-hand corner and changes
the foreground color to green in two-color format, or it changes
the color to yellow in the four-color format.
CLEAR
RUN GFX("Clear") or
RUN GFX("Clear",color)
CLEAR resets all points on the screen to the background color, or
if the optional color is given presets the screen to that color.
The current graphics cursor is reset to (0,0).
LINE
RUN GFX("Line",x2,y2)
RUN GFX("Line",x2,y2,color)
RUN GFX("Line",x1,y1,x2,y2)
RUN GFX("Line",x1,y1,x2,y2,color)
LINE draw lines in various ways. If one coordinate is given, the
line will be drawn from the current graphics cursor position to the
coordinates specified. If two sets of coordinates are given, they
are used as the start and end points of the line. The line will be
drawn in the current foreground color unless a new color is given
as a parameter. After the line is drawn the graphics cursor will be
positioned at x2,y2. For example
RUN GFX("Line",0,0,0,192)
draws a line from (0,0) to (0,192).
RUN GFX("line",24,65,2)
draws a blue line (4-color mode) to point 24,65.
CIRCLE
RUN GFX("Circle",radius)
RUN GFX("Circle",radius,color)
RUN GFX("Circle",x,y,radius)
RUN GFX("Circle",x,y,radius,color)
CIRCLE draws a circle of the given radius. The current graphics
cursor position is assumed if no X,Y value is given. The current
foreground color is assumed if the Color parameter is not used.
The center of the circle must be on the screen.
ALPHA
RUN GFX("Alpha")
Alpha is a quick convenient way of getting the screen back to
alphanumeric mode. When graphics mode is entered again, the screen
will show the previous unchanged graphics display.
QUIT
RUN GFX("Quit")
QUIT switches the screen back to alpha mode and returns the 6K byte
graphics display memory to OS-9.
GLOC
RUN GFX("Gloc",vdisp)
GLOC returns the address of the video display RAM as an integer number.
This address may be used in subsequent PEEK and POKE
operations to access the video display directly. GLOC can be used
to create special functions that are not available in the Graphics
Module.
GCOLR
RUN GFX("Gcolr",color)
RUN GFX("Gcolr",x,y,color)
GCOLR is used to read the color of the pixel at the current
graphics cursor position, or from the coordinates X,Y. The
parameter "Color" may be an integer or a byte variable in which the
color code is returned.
JOYSTK
RUN GFX("Joystk",stick,fire,x,y)
JOYSTK returns the status of the specified joystick's Fire button,
and returns the X,Y position of the joystick. The Fire button may
be read as a BYTE, INTEGER, or a BOOLEAN value. Non-zero (TRUE)
means the button was pressed. The X,Y values returned may be BYTE
or INTEGER variables, and they will be in the range 0 to 63. The
Stick parameter may be BYTE or INTEGER, and should be 0 for
RIGHT, or 1 for LEFT, depending on whether the RIGHT or the LEFT
joystick is to be tested.
Example:
RUN GRX("Joystk",1,leftfire,leftx,lefty)
A Sample Graphics Program
The program on the next page illustrates how the GFX module is
called and used. It creates an analog clock on the graphics
display.
PROCEDURE clk
0000 (* Simple Clock Simulator *)
001C DIM time(4),last(4),xx(3),yy(3):INTEGER
0043 DIM x0,y0,radius,bkg:INTEGER
0056 DIM i,j,x1,y1,x2,y2:INTEGER
0071 DEG
0073 bkg=0
007A x0=128
0081 y0=96
0088 radius=95
008F RUN GFX("MODE",1,bkg+1)
00A5 RUN GFX("CLEAR")
00B2 RUN GFX("CIRCLE",x0,y0,radius)
00CF FOR i=0 to 89 STEP 6
00E4 x2=SIN(i)*radius
00F4 y2=COS(i)*radius
0104 x1=x2*.9
0115 y1=y2*.9
0126 j=MOD(i/30,3)+bkg+1
013B RUN GFX("LINE",x0+x1,y0+y1,x0+x2,y0+y2,j)
016C RUN GFX("LINE",x0-x1,y0-y1,x0-x2,y0-y2,j)
019D RUN GFX("LINE",x0+y1,y0-x1,x0+y2,y0-x2,j)
01CE RUN GFX("LINE",x0-y1,y0+x1,x0-y2,y0+x2,j)
01FF NEXT i
020A FOR i=1 TO 3
021A time(i)=0
0225 xx(i)=x0
0231 yy(i)=y0
023D NEXT i
0248 LOOP
024A time$=DATE$
0250 last=time
0258 time(3)=VAL(MID$(time$,16,2))*6
026E time(2)=VAL(MID$(time$(13,2))*6
0284 time(1)=MOD(VAL(MID$(time$,10,2))*30+time/2)/12,360)
02A9 j=last(3)
02B3 FOR i=3 TO 1 STEP -1
02C9 IF i=3 OR j=0 OR ABS(time(i)-last(i+1))<6 OR
ABS(time(i)-j)<6 THEN
0300 RUN GFX("LINE",x0,y0,xx(i),yy(i),bkg)
032B xx(i)=x0+SIN(time(i))*radius*(.3+i*.2)
035A yy(i)=y0+COS(time(i))*radius*(.3+i*.2)
0389 RUN GFX("LINE",x0,y0,xx(i),yy(i),bkg+i)
03B7 ENDIF
03B9 NEXT i
03C4 WHILE time$=DATE$ DO
03CF ENDWHILE
03D3 ENDLOOP