Displaying Text and Graphics
BASIC09 has three levels of graphics capabilities. The first and
third levels can include both graphics designs and text. The second level can display only graphics designs.
ASCII Codes
For low-resolution text screens and high-resolution text and
graphic screens, BASIC09 uses ASCII (American Standard Code
for Information Interchange) codes to represent the common
alphanumeric characters. ASCII is the same code that most
small computers use.
A table of the standard codes follows:
Table 9.1
BASIC09 ASCII Codes 0-127
Low- and High-Resolution Screens
Character Decimal Code Hexadecimal Code
BREAK
03 03
8 08
Q 9 09
Q 10 OA
CLEAR
1`Z OC
ENTER
13 OD
Space
32
20
! 33 21
" 34
22
# 35 23
$ 36
24
% 37
25
& 38
26
' 39
27
( 40 28
41 29
* 42 2A
+ 43
2B
44 2C
- 45 2D
46 2E
/ 47 2F
0 48 30
9-1
BASIC09 Reference
Character Decimal Code Hexadecimal Code
1 49 31 ~,
2 50 32
3 51 33
4 52 34
5 53 35
6 54 36
7 55 37
8 56 38
9 57 39
' 58 3A
' 59 3B
< 60 3C
= 61 3D
> 62 3E
63 3F
@ 64 40
A 65 41
B 66 42
C 67 43
D 68 44
E 69 45
F 70 46
G 71 47
H 72 48
I 73 49
74 4A
K 75 4B
L 76 4C
M 77 4D
N 78 4E
O 79 4F
P 80 50
Q 81 51
R 82 52
S 83 53
T 84 54
U 85 55
V 86 56
W 87 57
X 88 58
Y 89 59
Z 90 5A
C ( s
Hi~
0)
91 5B
9-2
Displaying Text and Graphics l 9
Character Decimal Code Hexadecimal Code
\ ( SHIFf CLEAR ) 92
5C
( sHm 0)
93 5D
94 5E
-~ ( sHm
CED
95 5F
96 60
a 97 61
b 98 62
c 99 63
d 100 64
e 101 65
f 102 66
g 103 67
h 104 68
i 105 69
j 106 6A
k 107 6B
1 108 6C
m 109 6D
n 110 6E
0
111 6F
p 112 70
q 113 71
r 114 72
s 115 73
t 116 74
u 117 75
v 118 76
w 119 77
x 120 78
y 121 79
z 122 7A
{ 123 7B
124 7C
} 125 7D
126 7E
127 7F
You can generate the characters in this chart by pressing the
appropriate key, or you can generate them from BASIC09 using
the CHR$ function.
9-3
BASIC09 Reference
Low-Resolution Graphic Characters
In addition to alphanumeric characters, low-resolution graphics
also offers graphic characters. Generate these characters by
pressing
ACT
at the same time you press a keyboard character.
The graphics character codes are in the range 128-255.
Pressing
ACT
while pressing another key, causes OS-9 to add
128 to the ASCII value of the second key. (For the technically
minded, OS-9 sets the high bit of the character code.) Therefore,
if you press
ACT
0,
you produce graphics character 193. You can
also generate graphics characters from BASIC09 using the
CHR$ function, and you can PRINT them in the same manner
as other characters.
Low-level graphics characters follow a pattern that repeats every
16 characters. Table 9.2 shows the first set of graphic characters,
128-143. Subsequent characters produce the same series of configurations but display in different colors, as shown in Table 9.3.
Table 9.2
Low-Resolution Graphic Character Set
Character Code Character Code Character Code Character Code
128 132 136 140
129
133
134
135
137
138
142
9-4
Displaying Text and Graphics l 9
Table 9.3
Low-Resolution Graphics Color Set
ASCII Code Graphics Block Color
128 - 143
Black and Green
144 - 159
Black and Yellow
160 - 175
Black and Blue
176 - 191
Black and Red
192 - 207
Black and Buff
208 - 223
Black and Light Blue
224 - 239
Black and Cyan
240 - 254
Black and Orange
255
Green
Within each color set, you can easily calculate the number for a
particular character. For instance, suppose you want to print a
character that has orange upper left and lower right corners. Picture the character divided into four sections, numbered as
follows:
d 11
To calculate a character that has orange at Sections
8
and 1, add
the section values to the first value in the orange group,
240,
like this:
240 + 8 + 1 = 249
Character
249
is what you want.
The following diagram shows how you might block out a large
letter O on the screen. The shaded portions of the characters are
colored. The unshaded portions are black. In this case we want
the colored portions to be green (the same color as the screen).
You can do this using the color set
1,28 - 143.
9-5
BASIC09 Commands Reference
8141181411814
2
R
. :a:
8 4
2
!.~'S,~' : ^ ~~./ y ',ids. .~!`,., .4:~.
8
a , M
:.M~4
2
.'y~ ' <oc6: , n
8 4
4
8
2 I 1 ll 2 I 1 II 2
Because Section 1 in the upper left character is to be colored,
add 1 to the initial character value of
128.
The first character
value is 129. Moving right, Sections 2 and 1 are colored in the
second character. Add 3 to
128
to get a second character value of
131. Calculate all 15 characters in this manner.
You could create a letter O in a BASIC09 procedure by
printing
each of the five rows of three characters. You could use DATA
lines to store the ASCII codes for each character, then use loops
to read and display the characters they represent.
Although low-level graphics is very rough, it can be useful, and
it lets you mix graphics with text.
The following procedure not only creates the letter O, it adds the
letter S and the number 9 to display the name of your operating
system.
9-6
Displaying Text and Graphics l 9
PROCEDURE os9prog
pDIM DAT:INTEGER
OPR I NT CHR $ C 1 2 )
OPR I NT
OPR I NT
OPRINT
OFOR Z=1 TO 5
OPRINT TAHC10);
OFOR T=1 TO 1 2
DREAD DAT
OPRINT CHR$CDAT);
ONEXT T
OPR I NT
ONEXT Z
DEN D
ODATA 129,131 ,130,143,129,131 ,131 ,143,129,131 ,130,
143
ODATA 133,143,138,143,133,143,143,143,132,140,136,
143
ODATA 133,143,138,143,132,140,140,143,131 ,131 ,130,
143
ODATA 133,143,138,143,131 ,131 ,130,143,143,143,138,
143
ODATA 132,140,136,143,140,140,136,143,143,143,138,
143
9-7
BASIC09 Reference
Special Characters in High-Resolution
High-resolution graphics does not have graphic characters but it
does have other international and special characters. These characters are represented by ASCII codes 128 through 159 as shown
in the following table:
Table 9.4
High-Resolution Special Characters
Hex Decimal Hex Decimal
Character Code Code Character Code Code
80 128 0 90 144
u
81 129
Be
91 145
e
82 130 AE 92 146
83 131 0 93 147
a
84 132 6 94 148
a
85 133 0 95 149
a
86 134
a
96 150
87 135
a
97 151
e
88 136 0 98 152
e
89 137 O 99 153
,, ,,
e
8A 138 0 9A 154
i 8B 139 § 9B 155
i 8C 140 £ 9C 156
13 8D 141 ± 9D 157
A 8E 142 9E 158
A
8F 143 f 9F 159
Medium-Resolution Graphics
For more sophisticated graphics operations, OS-9 has built-in
graphics interface modules that provide a convenient way to
access the graphics and joystick functions of the Color Computer
3. The required module for medium-resolution graphics is named
GFX. It must be in your execution directory or resident in memory when called by BASIC09.
You can either install GFX in memory using the LOAD command, or wait until BASIC09 calls it for a graphics function.
Once loaded, GFX resides in memory until you remove it using
the OS-9 UNLINK command or the BASIC09 KILL command.
9-8
Displaying Text and Graphics / 9
GFX has a number of functions that you pass to it as parameters with the RUN statement. For instance, the following statement clears the current graphics screen:
RUN GFXt"CLEAR")
Other tasks need such parameters as position, color, and size.
The following is a quick reference to all of the GFX functions.
Each is explained in detail later:
Function Purpose
Parameters
ALPHA
CIRCLE
CLEAR
COLOR
GC OLR
GLOC
Sets the screen to the
alphanumeric mode.
Draws a circle.
Clears the screen to a
color.
Changes the foreground
and background colors.
Reads a pixel's color.
Returns a video display
address.
JOYSTK Returns the joystick
button and X- and Ycoordinate status.
LINE
MODE
MOVE
None.
Radius, optional X- and
Y-coordinates, and color.
Optional color for screen.
Foreground and
background colors.
Names of variables in
which to store optional
X- and Y-coordinates.
None.
Names of variables in
which to return the
values.
Ending X- and Ycoordinates, optional
beginning coordinates,
optional color.
Draws a line.
Switches the screen
between alphanumeric
and graphics, sets the
graphics screen color.
Positions the invisible
graphics cursor.
Format, Color.
X- and Y-coordinates.
9-9
BASIC09 Reference
Function Purpose Parameters
POINT Moves graphics cursor X- and Y-coordinates
and sets a point. and optional pixel color.
QUIT Returns screen to None.
alphanumeric mode.
Deallocates graphics
memory.
Formats and Colors
In medium-resolution graphics, you have a choice of two formats.
Format 0 provides 256 horizontal points by 192 vertical points. In
this format, you can have only two colors on the screen at a time.
Format 1 provides a 128 by 192 point screen and a maximum of
four colors on the screen at a time. OS-9 medium-resolution
graphics treats the screen as if it were a grid, with coordinate
0,0 at the lower left corner as shown in the following illustration.
All points on the grid are positive.
Y-coordinate,0 - I
I I I I I I I I I I I I I I I I I
0, X-coordinate
BASIC09 defines colors with numbers or color codes. Many GFX
functions allow or require color codes as parameters. BASIC09
also divides the color codes into color sets. Specifying a color code
outside the current color set automatically initializes the new
set.
9-10
Displaying Text and Graphics / 9
Color
Set
1
2
3
4
Format 0
Color Back- Fore-
Code ground ground
00 Black Black
01 Black Green
02
03
04 Black Black
05 Black Buff
06
07
Format 1
Color Back- Fore-
Code ground ground
00 Green Green
01 Green Yellow
02 Green Blue
03 Green Red
04 Buff Buff
05 Buff Cyan
06 Buff Magenta
07 Buff Orange
08 Black Black
09 Black Dk Green
10 Black Md Green
11 Black Lt Green
12 Black Black
13 Black Green
14 Black Red
15 Black Buff
Table 9.5
Use the preceding charts to chose colors for those functions that
let you specify foreground or background colors. For instance, to
initialize a Format 1 graphics screen with a green background
and a red foreground, you type:
run gfxC"mode",1,3)
The following reference section describes all the medium-resolution graphics functions, and provides examples and sample programs. To understand the organization of the commands
reference, see "The Syntax Line" in Chapter 11.
9-11
BASIC09 Reference
The Draw Pointer
Medium-resolution graphics uses a draw pointer, or invisible
graphics cursor, to determine what area of the screen is affected
by graphics operations. When you establish a graphics screen,
the draw pointer is located at coordinates 0,0. Some graphic
functions automatically change the pointer location on the
screen. Fbr instance, the LINE function moves the draw pointer
from the beginning coordinates to the end coordinates.
Because some functions begin at the draw pointer, you need to
keep track of its location and make certain it is placed properly.
Use the MOVE function to set the draw pointer to new locations.
9-12
Displaying Text and Graphics / 9
ALPHA
Select alphanumeric screen
tax: RUN GFX("ALPHA")
Function:
Switches from the graphics screen to the alphanumeric (text) screen. The current graphics screen remains
intact.
Parameters:
None
RUN GFX("ALPHA")
Sample Program:
This procedure lets you choose to draw a circle or rectangle of
the size you select. Once you choose the shape and size, it uses
the MODE function to select a graphics screen. When the shape
is complete, you press
ENTER
to return to a text screen. The procedure uses the ALPHA function to return to the original menu.
PROCEDURE alpha
ODIM XCOR,YCOR,SIDE1,SIDE2,RADIUS,T,X,Y,Z:INTEGER
ODIM RESPONSE:STRINGL1J
10 REPEAT
OSHELL "DISPLAY 0C"
OPRINT "Do you want to draw"
OPRINT "1) A rectangle"
OPRINT "2) A circle"
OPRINT " -Press 1 or 2..."
OGET #O,RESPONSE
pPRINT
OI F RESPONSE="1 " THEN
OINPUT "Length of Side 1...",SIDE1
OINPUT "Length of Side 2...",SIDE2
ORUN GFX("MODE",0,0)
ORUN GFXC"CLEAR")
OXCOR-10
DYCOR=10
ORUN GFX("LINE",XCOR,YCOR,XCOR+SIDE1,YCOR,1)
9-13
BASIC09 Reference
pRUN GFXC"LINE",XCOR+SIDE1,YCOR,XCOR+SIDE1,YCOR+
SIDE2,1 )
ORUN GFXC"LINE",XCOR+SIDE1,YCOR+SIDE2,XCOR,YCOR+
SIDE2,1 )
ORUN GFXC"LINE",XCOR,YCOR+SIDE2,XCOR,YCOR,1)
DINPUT RESPONSE
pELSE
OIF RESPONSE="2" THEN
OINPUT "What radius?...",RADIUS
ORUN GF X C "MODE" , 0 , 1 )
ORUN GFXC"CLEAR")
ERUN GFXC"CIRCLE",128,90,RADIUS)
DINPUT RESPONSE
pEND I F
pENDIF
OUNTIL RESPONSE<>"1" AND RESPONSEc>"2"
pRUN GFXC"ALPHA")
OGOTO 1 0
OEND
9-14
Displaying Text and Graphics l 9
CIRCLE
Draw a circle
Syntax:
RUN GFX("CIRCLE"[,xcorycor],radius [,color])
Function:
Draws a circle of a given radius. If you do not specify a color, BASIC09 uses the current foreground color. If you
do not specify X- and Y-coordinates, CIRCLE uses the current
graphics cursor position as the circle's center.
Parameters:
radius The radius of the circle you want to draw.
color The code of the color you want the circle to be.
See the chart earlier in this section for color
information.
xcor,ycor The X- and Y-coordinates for the center of the
circle. Specifying coordinates outside the X
coordinate range of 0-255 or outside the Y
coordinate range of 0-191 causes an error.
Examples:
RUN GFX("CIRCLE",100)
RUN GFX("CIRCLE",100,3)
RUN GFX("CIRCLE",125,100,100)
RUN GFXC"CIRCLE", 1 25, 1 00, 1 00,2)
Sample Program:
This procedure uses CIRCLE to draw and erase a circle. The
location of the circle changes before each draw/erase operation,
causing the circle to move. When it hits the edge of the screen,
it reverses its direction at a random angle and
bounces.
PROCEDURE circles
ODIM RADIUS,XCOR,YCOR:INTEGER
ODIM XTEMP,YTEMP:INTEGER
ODIM PATH1,PATH2:INTEGER
ODIM FLAG:INTEGER
9-15
BASIC09 Reference
OFLAG=1
OXCOR=5
OYCOR=5
OPATH1 =RNDC1 5)+2
OPATH2=RNDC10)+2
OXTEMP-249
OYTEMP =185
ORUN GF X C "MODE" , 0 ,1 )
ORUN GFXC"CLEAR")
OFOR T=1 TO 200
OWHILE XCOR<250 AND XCOR>4 AND YCOR<186 AND YCOR>4
DO
ORUN GFXC"CIRCLE",XTEMP,YTEMP,3,0)
ORUN GFXC"CIRCLE",XCOR,YCOR,3,1)
OXTEMP=XCOR
OYTEMP=YCOR
OXCOR=XCOR+PATH1
OYCOR=YCOR+PATH2
OENDWHILE
pPATH1 =RNDC 1 5)+2
OPATH2=RNDC 1 0)+2
OIF XCOR>249 THEN
OXCOR=249
OEND I F
OIF XCOR<5 THEN
OXCOR=5
OEND I F
OI F YCOR> 185 THEN
EIYCOR-185
OENDIF
OIF YCOR<5 THEN
OYCOR=5
OEND I F
OFLAG=FLAG*-1
OIF FLAG<0 THEN
OPATH1 =PATH1 *-1
OPATH2=PATH2*-1
OENDI F
ONEXT T
OEND
9-16
Displaying Text and Graphics l 9
CLEAR
Clear the screen
Syntax: RUN GFX("CLEAR"[,color])
Function: Clears the current graphics screen. If you do not
specify a color, CLEAR sets the entire screen to the current
background color. CLEAR also sets the graphics cursor at
coordinates 0,0, the lower left corner of the screen.
Parameters:
color A code indicating the color to set the screen.
Examples:
RUN GFXC"CLEAR")
RUN GFXC"CLEAR",14)
9-17
BASIC09 Reference
COLOR
Change the foreground color
Syntax:
RUN GFX("COLOR", color)
Function:
Changes the foreground color (and possibly the color
set). COLOR does not change the graphics format or the cursor position.
Parameters:
color A code indicating the color you want for the
foreground. See the chart earlier in this chap
ter for color information.
Examples:
RUN GFX("COLOR",10)
Sample Program:
This procedure connects a series of differently colored circles to
produce a necklace effect.
PROCEDURE necklace
pDIM COLOR,T,U,J,R,FLAG,XCOR,YCOR:INTEGER
ORUN GFX("MODE",1,0)
pRUN GFX("CLEAR"
0COLOR=1
OX COR=1
OYCOR=1
OR=2
OFOR T=1 TO 6
pFOR J=1 TO 40
OXCOR=XCOR+1 _
OYCOR=YCOR+.8
OIF FLAG<O THEN
[]R=R-1
FlELSE
[]R=R+1
EIENDIF
0COLOR=COLOR+1
DIF COLOR>3 THEN COLOR=1
9-18
Displaying Text and Graphics / 9
OEND I F
ORUN GFXC"CIRCLE",XCOR,YCOR,R,COLOR)
ONEXT J
OFLAG=FLAG -1
ONEXT T
OFOR U=1 TO 10000
ONEXT U
REND
9-19
BASIC09 Reference
GLOC
Find the graphics screen location
Syntax: RUN GFX("GLOC",storage)
Function: Determines the location of the graphics screen in
memory and returns the address in the specified variable.
When you know the graphic screen address, you can use
PEEK and POKE to perform special functions not available in
the GFX module, such as filling a portion of the screen with a
color or saving a graphics screen to disk.
OS-9 Level Two maps display screens into a program's
address space before PEEK and POKE can operate on a display screen. This means that you must have at least eight
kilobytes of free memory in the user's address space. Program
and data memory requirements must not exceed 56 kilobytes.
Parameters:
storage An integer or byte type variable in which
GLOC stores the memory address of the
graphics screen.
Examples:
RUN GFX("GLOC",location)
Sample Program:
This procedure uses the GLOC function to locate the current
graphics screen, then uses POKE to paint a series of boxes on
the screen.
PROCEDURE boxin
ODIM LOCATION,PLACE,COLOR,HEGIN,QUIT,X,TERMINATE,
LINE,T,J:INTEGER
ORUN GF X ("MODE" , 1 , 0 )
ORUN GFX("CLEAR")
RUN GFX("GLOC",LOCATION)
pLOCATION=LOCATION+100 \ PLACE=LOCATION
CHEGIN=1
pQUIT=80
9-20
Displaying Text and Graphics l 9
oCOLOR=255
OTERM I NATE=1 0
OLINE=32
OFOR X=1 TO 4
OFOR Tml TO QUIT
OFOR J=BEGIN TO TERMINATE
OPOKE PLACE+J,COLOR
ONEXT J
OPLACE=PLACE+LINE
ONEXT T
OLOCATION=LOCATION+160
OBEGIN=BEGIN+1
OPLACE=LOCATION
OQUIT=QUIT-1 0
OTERMINATE=TERMINATE-1
OCOLOR=COLOR-85
ONEXT X
DI NPUT Z$
REND
9-21
BASIC09 Reference
JOYSTK
Get joystick status
Syntax:
RUN GFX ("JOYST K", stick,fire,xcor, ycor)
Function: Determines the status of the specified joystick fire
button and the X,Y position of the specified joystick handle.
Use this function only with a standard joystick or mouse, not
with the high-resolution mouse adapter.
Parameters:
stick The joystick (0 or 1) for which you want to
determine the status. 0 indicates the right joy
stick, 1 indicates the left joystick.
fire A
variable in which JOYSTK returns the sta
tus of the specified fire button.
Fire
can be
byte, integer, or Boolean type. A value other
than 0 or TRUE indicates the button is
pressed.
xcor,ycor Byte or integer type variables in which
JOYSTK stores the X- and Y-coordinates of
the joystick handle position. The coordinate
range is 0-63.
Examples:
RUN GFXC"JOYSTK",0,5hoot,x,y)
9-22
Displaying Text and Graphics / 9
Sample Program:
This procedure uses the JOYSTK function to draw on the screen
with the right joystick.
PROCEDURE joydraw
ODIM STICK,FIRE,XCOR,YCOR,XTEMP,YTEMP:INTEGER
RUN GF X C "MODE" , 0 ,1 )
ORUN GFXC"CLEAR")
OJOY=0 \XCOR=0 \YCOR=0
OREPEAT
OXTEMP=XCOR
OYTEMP=YCOR
ORUN GFXC"JOYSTK",O,FIRE,XCOR,YCOR)
OXCOR=XCOR*4
OYCOR=YCOR*4
ORUN GFXC"LINE",XTEMP,YTEMP,XCOR,YCOR)
OUNTIL FIRE<>0
REND
w
BASIC09 Reference
LINE
Draw a line
Syntax:
RUN GFX ("LINE"[,xcorl, ycorl],xcor2, ycor2
[,color] )
Function:
Draws a line in the current or specified foreground
color in one of the following ways:
· From the current draw position to the specified X,Ycoordinates.
· From the specified beginning X- and Y-coordinates to the
specified ending X,Y-coordinates.
Parameters:
xcorl,ycorl Are LINE's beginning X- and Y-coordinates.
xcor2,ycor2 Are LINE's ending X- and Y-coordinates.
color A code indicating the color you want the line
to be. See the chart earlier in this section for
color information.
Examples:
RUN GFXC"LINE",192,128)
RUN GFXC"LINE",0,0,192,128)
RUN GFXC"LINE",0,0,192,128,2)
9-24
Displaying Text and Graphics / 9
Sample Program:
This procedure draws a sine wave of vertical lines across the
screen.
PROCEDURE waves
ODIM A,H,C,D,X,Y,Z:INTEGER
pCALC=0 \ A=100
pRUN GFXC"mode", 0, 1 )
ORUN GFXC"CLEAR")
ORUN GFXC"COLOR",2)
OFOR X=0 TO 255 STEP 1
pCALC=CALC+.05
DY=A-SINCCALC)*15
pZ=Y+25
ORUN GFXC"LINE",X,Y,X,Z)
ONEXT X
SEND
9-25
BASIC09 Reference
MODE
Switch to graphics screen
Syntax:
RUN GFX("MODE",forma t, color)
Function:
Switches the screen from alphanumeric (text) to
graphics, selecting the screen format and color code. You must
run MODE before you can use any other graphics function.
When you do, BASIC09 allocates a six-kilobyte block of memory for graphics. If your system does not have this amount of
memory available, OS-9 returns an error message.
Parameters:
format Either 0 (a two-color 256 by 192 pixel screen)
or 1 (a four-color, 128 by 192 pixel screen).
color A code indicating the color to set the screen.
See the chart earlier in this chapter for infor
mation on color sets.
Examples:
RUN GFXC"MODE",1,2)
9-26