pdf - TRS-80 Color Computer Archive

Add to My manuals
258 Pages

advertisement

pdf - TRS-80 Color Computer Archive | Manualzz
COLOR COMPUTER GRAPHICS
by
William Barden, Jr.
Radio Shack
A Division of Tandy Corp .
761 02
Ft. Worth, Texas
Color Computer Graphics:
©
1982 Tandy Corporation, Fort Worth, Texas 76102
U.S.A. All Rights Reserved.
Reproduction or use of any portion of this manual without the express written per­
mission of Tandy Corporation is prohibited. While reasonable efforts have been
taken in the preparation of this manual to insure its accuracy, Tandy CO!poration
assumes no liability resulting from any errors or omissions in this manual or from
the use of the information obtained herein.
TRS-80 Color Computer System Software:
©
1982 Tandy Co1poration and
Microsoft. All Rights Reserved.
The system software in the Color Computer microcomputer is retained in a read­
only memory (ROM) format. All portions of this system software, whether in the
R O M format or other source code form, and the R OM circuitry are copyrighted and
are the proprietary and trade secret information of Tandy Corporation and
M i crosoft . Use, reproduction, or publication of any portion of this material without
the prior written authorization of Tandy Corporation is strictly prohibited .
Design and Production by Ellen Klempner.
Editorial Supervision by Tom McMillan.
I l lustrations by Jack Wittry.
Typeset b y LeWay Composing Service.
10
9
8
7
6
5
4
3
Foreword
We've known Wil liam Barden , Jr. for several months now . A bunch of
the guys and I were watching the Dodgers on the color television in my
coffee shop, the B YTE TO EAT, when suddenly in walked a guy
carrying what appeared to be a gray box with keys on it. He said , "You
guys aren't watching this, are you?" and switched off the TY,
disconnected its antenna, and hooked up the gray box . The next thing we
knew, "OK" appeared on the screen in place of the ninth inning .
Wel l , to make a long story short, every day since then, Barden has
come in and connected his gray box to our large television . For hours on
end , he ' l l sit there watching really weird patterns that appear on the
screen - circles , boxes, tiny little figures that jump up and down .
We' re really glad he was able to finish the book, despite what he
says in the Preface . Now , maybe next season we can watch the Dodgers
again.
Max and the Guys
v
Preface
Want to use your Color Computer to draw a "pie chart " ? How about
constructing a chessboard with all chess pieces represented in four
colors? Interested in doing a precise plot of a mathematical function?
How about animating figures in your Space War game?
The Color Computer can easily do all of these things with its built-in
graphics capability . The Color Computer has hardware to provide up to
eight colors on your display, and it can plot 49 , 1 52 points on the screen !
Hardware is nothing without software, and the Color Computer has
plenty of that contained in read-only memory (ROM). Much of the Color
B ASIC and Extended Color BASIC is devoted to making use of the
powerful graphics capabilities of the hardware . Commands are available
to draw circles, rectangles, arcs, angled lines, to rotate figures, to scale
figures up and down , and many, many more .
In this book w e ' ll show you how to use the Color BASIC and
Extended Color BASIC commands to do all kinds of graphics. We'll also
describe some graphics capabilities that are hidden in the Color
Computer.
Color Computer Graphics consists of two sections: a tutorial section
in the first eight chapters and a collection of graphics techniques in the
last half of the book.
The first section, " Using Color Computer Graphics Modes and
Commands , " discusses the built-in graphics modes and all of the
graphics commands available in both Color BASIC and Extended Color
BASIC .
Chapter I describes the memory mapping of the Color Computer, or
how the display memory and the memory available for user programs is
divided up among random-access memory (RAM). The chapter also
discusses the graphics modes that allow you to display text data and what
the Color Computer calls semigraphics modes, graphics that occupy text
character positions.
Chapter 2 discusses the remaining graphics modes of the Color
Computer. These are the modes that allow you to plot up to 256 by 1 92
points on the display in as many as four colors . Graphics pages, or RAM
areas set aside to hold graphics display data, are also discussed .
For those of you that have only Color BASIC , Chapter 3 describes
how to use the Color BASIC commands .
VI
Chapters 4 through 8 describe all of the commands for Extended
Color BASIC in detai l , with many examples.
The second section of this book, "Programming Techniques for
Color Computer Graphics , " is a collection of graphics techniques and
applications for both Color BASIC and Extended Color BASIC. There
are dozens of separate descriptions, each one discussing a separate
technique.
Some of the techniques described are moving dots, PAINTing, bar
graphs , drawing shades of grey , hidden lines , filled-in circles, animation ,
and many more !
This section duplicates some of the material found in the first section
of the book but is meant more as a quick reference to a desired graphic
effect . The description of the technique, the sequence to follow with the
proper BASIC format, a practical example, and notes on the technique
are provided for each technique.
The graphics capabilities of the Color Computer are excellent. It's
really just a matter of learning them then getting some practice in
application. Color Computer Graphics should help you to do both . Now
you can see your computer dreams in technicolor!
To Max and the guys at the BYTE TO EAT, none of whom gave a shred
of encouragement on this book.
To Steve Mussatti .
VII
Table of Contents
SECTION I:
USING COLOR COMPUTER GRAPHICS MODES
AND COMMANDS
1:
2:
3:
4:
5:
6:
7:
8:
Color Computer Memory Mapping and Semigraphics
1
Modes
True Graphics Modes
31
Color BASIC Graphics Capabilities
Extended Color BASIC: Initialization
53
73
Extended Color BASIC: PSET, PRESET, PPOINT, and
85
PLOTTING
Extended Color BASIC: Drawing Lines, Rectangles, Filled
Rectangles, Circles, and Arcs with LINE and CIRCLE
Extended Color BASIC: Using the DRAW Command
99
119
Extended Color BASIC: Using the PAINT and GET/PUT
Commands
139
SECTION II:
PROGRAMMING TECHNIQ UES FOR COLOR COMPUTER
157
GRAPHICS
APPENDICES
Appendix I:
Appendix II:
Decimal/Binary Conversion Table
205
Color BASIC Commands and Actions
209
Appendix III:
Extended Color BASIC Graphics Commands and
Appendix IV:
Color Computer Graphics Modes
Actions
Index
235
211
215
COLOR COMPUTER GRAPHICS
SECTION I
Using Color Computer Graphics
Modes and Commands
Color Computer Memory Mapping and Semigraphics Modes
CHAPTER 1
Color Computer Memory Mapping and
Semigraphics Modes
To get a clear picture of Color Computer graphics, we must discuss two
topics: the memory mapping of the Color Computer and the graphics
modes that are available. These concepts are essential to a complete
understanding of Color Computer graphics. If some of this material
seems difficult, don 't hesitate to read ahead in other chapters and come
back to the first two chapters later. The chapters get easier as they go on!
Memory mapping refers to the way the memory space in the Color
Computer is divided - what portion is read-only memory (ROM) , what
portion is random-access memory (RAM), and what portion is dedicated
to other functions . The memory mapping is tied into the way the Color
Computer was engineered and designed.
The graphics modes are also built into the hardware of the Color
Computer. A special graphics generator chip controls the memory
modes. It 's not necessary to understand how the graphics generator chip
functions, so we won't be giving you a course in computer design . ( For
those who are interested in computer design , read the sequel to this book,
The Color Computer Meets the Mad Computer Scientist . )
M EMORY MAPPING
The 6809 microprocessor in the Color Computer can normally use
up to 65 ,536 bytes of memory. That address space is divided up by the
system designer into ROM , RAM , and input-output as shown in Figure
1.1.
1
2
ADDRESS
DECIMAL
HEX
65,535
65,280
65,279
FFFF
FFOO
FEFF
49,152
cooo
3 2 , 768
8000
16,3 8 4
4000
INPUT/OUTPUT
ADDRESSES
CARTRI
DGE ROMMEMORY)
( R EAD-ONLY
ROMCOLOR
(READ-ONLY
BASICMEMORY)
ROMEXTENDED
BASIC COLOR
OR RAM
(UNUSED
RMEMORY)
ANDOM-ACCESS
6 5 , 53 6
BYTES
RAM(MEMORY)
RANDOM-ACCESS
0
0000
Figure 1 . 1 :
Color Computer address space.
Bits, Bytes, and Memory
Each of the 65 ,536 bytes of memory is made up of eight bits, as
shown in Figure 1 . 2 . B it is a contraction of binary digit . A binary digit
can hold an on or off condition, represented by a I or 0.
Each byte of memory can hold binary values of 00000000 through
1 1 1 1 1 1 1 1 , which represent decimal values of 0 through 255 . You won 't
have to become proficient in manipulating binary data to do Color
Computer graphics , but you should understand the relationship of bits ,
bytes , and memory. We ' ve included Appendix I to help in converting
decimal and binary values .
Color Computer Memory Mapping and Semigraphics Modes
7
6
5
4
3
3
0
DECI MBIALNARY=
1 0 1 1 1 010
186
8 BI TS= I BYTE
Figure 1 . 2 :
B i t s in memory.
ROM Memory
ROM is used to hold the BASIC interpreter program. The BASIC
interpreter is put into ROM because the contents of ROM are never
destroyed when power is turned off on the system. Since BASIC
programs are most often run in the Color Computer, it's a logical choice
for the firmware .
Another portion of the memory space is used to hold cartridge
ROM . Cartridge ROM is similar to the BASIC interpreter ROM , except
that it holds precanned applications programs such as games ,
programmed instructions, or business packages.
RAM Memory
RAM is used for holding user BASIC programs and user
machine-language programs, for storage of variables used by the BASIC
interpreter, and for video memory. RAM is volatile and its contents are
completely destroyed whenever power is turned off, so RAM must be
reloaded with programs or data by reading in cassette or disk files.
Input-Output Addresses
Certain portions of the 65 ,535 bytes of addressing space are
dedicated to input-output addresses . These addresses look like memory
locations. They are decoded by the Color Computer hardware as a means
to communicate with Color Computer ports such as serial (RS-232)
input-output, joysticks, and sound generation .
VIDEO M EMORY
Contrary to reports , video memory is not total recall of every plot of
"I Love Lucy." Video memory is the portion of normal RAM used for
screen display .
The area from memory location 1 024 up is devoted to video
4
memory . The minimum size of this area for a single screen's worth of
data is 5 1 2 bytes; the maximum size of this area is 6, 1 44 bytes .
Naturally, the more video memory required , the less area that will be
available for user programs .
RESOLUTION
The minimum video memory area occurs when a low-resolution
display mode is used . In a low-resolution mode, the display is made up
of a small number of blocks of data. The lowest resolution mode displays
64 blocks horizontally by 32 blocks vertically, for a total of 32 x 64 or
2048 blocks. These 2048 blocks can each be represented by two bits .
Since four groups of two bits can be squeezed into each byte, the total
number of video memory bytes required is 2048/4 , or 5 1 2 bytes .
The maximum video memory area occurs when a high-resolution
display mode is used. In a high-resolution mode , the display is made up
of many smaller blocks of data. The highest resolution mode displays 256
blocks horizontally by 1 92 blocks vertically for a total of 49, 1 52 blocks .
These 49, 1 52 blocks can each be represented by one bit . Since we can
squeeze eight bits into one byte, the total number of video memory bytes
required is 49, 1 52/8 or 6 1 44 bytes .
How different grades of resolution affect a display is shown in
Figure 1 . 3 , which illustrates the same scene for coarse to fine resolution.
LEAST
RESOLUTION
Color Computer Memory Mapping and Semigraphics Modes
5
MID
RESOLUTION
G REATEST
RESOLUTION
Figure 1.3:
Resolut ion in graphics.
TRADEOFFS IN RESOLUTION
When should low resolution be used and when should high
resolution be used? In general , low resolution requires less memory while
high resolution requires greater memory. Since video memory shares the
same RAM space as BASIC and other programs , the more resolution
required, the less RAM memory that is available for B ASIC programs .
Another thing to consider is the amount of color required.
Generall y , the lower the resolution, the greater the number of colors
6
permitted . This is because there is only so much RAM memory to go
around . We can ' t specify 49 , 1 52 blocks of display and permit eight
colors for each block . To do so would require 1 6 , 384 bytes of RAM !
Another factor is speed. It takes eight times as long to process
1 6 , 3 84 blocks of display data as it does to process 2,048 blocks of
display data! If you are displaying animation on the video, it might be
better to use lower resolution and get more frames per second.
There are tradeoffs in considering the resolution to use. We ' l l
explain more of these i n detail a s w e go through the book .
Blocks vs. Pixels
We've been referring to blocks of data on the display . The common
term for such a block is a picture element, shortened to pixel. l n the rest
of this book we'll use the term pixel in place of block, but there ' s nothing
mysterious or esoteric about it. The number of pixels in a display may be
anywhere from 2048 (64 horizontal by 32 vertical) to 49 , 1 5 2 (256
horizontal by 1 92 vertical ) .
G RAPHICS MODE
We're now ready to tackle the various graphics modes that are
available on the Color Computer. There are 1 6 of these modes, ranging
from display of alphanumeric characters to high-resolution graphics
displays of 256 by 1 92 pixels. Why so many modes? The chief reason is
that the Color Computer uses a special-purpose semiconductor integrated
circuit called the video display generator, or VDG . This chip is a
general-purpose display device, and we get all of these modes for free!
Some of them are more useful than others . We 'll describe all of them and
allow your experience to determine which will be the most useful.
There are three basic display modes: alphanumeric, alpha
semigraphic, and graphic . Alphanumeric mode allows display of text
characters . The character set is defined by an internal character generator
in the VDG chip which produces 5-by-7 dot-matrix characters as shown
in Table 1 . 1 .
@
A
B
c
D
E
It> blank
#
$
%
Color Computer Memory Mapping and Semigraphics Modes
F
G
H
I
J
K
L
M
N
0
p
Q
R
s
T
u
v
w
x
y
z
[
\
]
t
Table I.I:
&
+
0
1
2
3
4
5
6
7
8
9
<
>
?
Character Set of VDG
The alpha semigraphic mode is a low-resolution mode that is related
to the alphanumeric mode. The graphic mode is a full graphic mode that
generally permits higher resolution.
All of the modes can be selected under program control . Most of
them can be selected very easily under Extended Color BASIC . We'll
start with the simplest mode and work upwards , showing you the BASIC
commands which set the mode, the appearance of the mode , and the
video memory affected.
ALPHAN U M ERIC MODE (INVERTED)
This is the normal mode of the Color Computer system which is set
on power on or reset, or upon return to the BASIC interpreter after
execution of a BASIC program .
This mode is shown in Figure 1.4. The border is always black.
There are 32 characters per line and 1 6 lines per screen, making for a
total of 512 character positions .
7
8
VIDEO DISPLAY
MEMORY (RAM)
ONE BYTE
"T"
1025
"H"
1026
"E "
1027
" R"
1024
1
I
'"
1056
'
ulu
105 7
"I"
1058
"N"
1059
"E"
1060
"2"
1061
l
r
1533
:;
"A"
1534
"s"
1535
" T"
Figure 1.4:
Alphanumeric mode screen format.
Each character position is made up of 8 by 1 2 pixels. Since a
character generated by the VDG character generator is 5 by 7 pixels,
there is a buffer area of 2 pixels on top, 3 pixels on the bottom, 2 pixels
on the right, and l pixel on the left, as shown in Figure 1 . 5 .
BUFFER AREA
,---...,
BUFFER AREA
,----..
}
BUFFER AREA
CHAR ACTER="X"
Figure 1 .5:
Character position pixels.
Color Computer Memory Mapping and Semigraphics Modes
9
The character in each character position is defined by one byte in the
video display memory. There is a one-for-one relationship between a
video display memory byte and a character position on the screen, as
shown in Figure 1 . 4 . The code in each video display memory byte is the
code shown in Table 1 . 2 . The code is a modification of the American
Standard Code for Information Interchange (ASCII), which is a standard
computer code for alphabetic, numeric, and special characters .
Character
@
A
8
c
0
E
F
G
H
I
J
K
L
M
N
0
p
Q
R
s
T
u
v
w
x
y
z
[
\
]
t
Table 1 .2:
Decimal
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Hex
Character
40
41
42
43
44
45
46
47
48
49
4A
48
4C
40
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
58
5C
50
5E
5F
Character Codes in Color Computer .
lfJ
#
$
%
&
+
I
0
1
2
3
4
5
6
7
8
9
<
>
?
Decimal
96
97
98
99
1 00
1 01
1 02
1 03
1 04
1 05
1 06
1 07
1 08
1 09
110
111
112
113
114
115
116
117
118
119
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
Hex
60
61
62
63
64
65
66
67
68
69
6A
68
6C
60
6E
6F
70
71
72
73
74
75
76
77
78
79
7A
78
7C
70
7E
7F
10
Figure 1 . 6 shows a typical display o f alphanumeric data o n the video
screen and the corresponding characters in video memory . Note that all
values in video memory are less than 1 2 8 . Values that are less than 1 2 8
have b i t 7 , the most significant bit, set t o a zero .
I'1024 0 l 0 l 0 l 0 0
H s I s L I N E (DISPLAY LINE 1
BINARY
1025
11027026
10281029
10301031
10321033
10341035
10371036
DECIMAL
CHARACTER
8472
7383
9673
8396
7673
7869
96113
TH
s
s
L
NE
000 lll 000 00l l0l 000 00l 0l
00 11 01 00 0l 00 00 0l
000 111 001 00l 001 00l 001 001
00 ll 00 00 1l 0l 01 01
000 lll 00l 00l 000 00l 000 011
BI7Ti 6 5 4 3 2 1 0
l
Figure 1.6:
Alphanumeric data display.
Whenever bit 7 of any byte in video display memory is set to zero,
the YDG will display an alphanumeric character in the corresponding
character position on the screen .
To see how this mode works, run the following Extended Color
B ASIC program to fill all of video display memory with an ''A ''
character. You'll see the screen fill up with the "A" character.
1 00
1 10
1 20
130
1 40
R E M F I L L SC R E E N W I T H "Au
F O R l.J M = 1 0 2 4
T O 1 0 2 4+5 1 1
P O K E I.J M 1 6 5
N D: T I.J M
GOTO 1 40
CHARACTERS
Color Computer Memory Mapping and Semigraphics Modes
11
The 65 here is the ASCII code for " A " . The 1 024 is the starting
address of video memory from Figure 1 . 1 . Normally you would not have
to know this starting address to do graphics work, but, on the other hand,
it won ' t hurt you either!
ALPHAN UMERIC MODE (NON-I NVERTED)
This alphanumeric mode is related to the alphanumeric mode
inverted. In the alphanumeric inverted mode, the character is black on
green. In the non-inverted alphanumeric mode, the character is green on
black. Table 1 . 3 shows the character codes for this mode. Note that there
are 64 fewer character codes than for the inverted mode, indicating that
bit 6 (binary weight of 64) is reset.
Character
@
A
B
c
D
E
F
G
H
I
J
K
L
M
N
0
p
Q
R
s
T
u
v
w
x
y
z
[
\
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Hex
00
01
02
03
04
05
06
07
08
09
OA
OB
oc
OD
OE
OF
10
11
12
13
14
15
16
17
18
19
1A
18
1C
Character
l!J
#
$
%
&
+
I
0
1
2
3
4
5
6
7
8
9
<
Decimal
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Hex
20
21
22
23
24
25
26
27
28
29
2A
28
2C
20
2E
2F
30
31
32
33
34
35
36
37
38
39
3A
38
3C
12
J
29
30
31
t
Table 1 .3:
1D
1E
1F
>
?
30
3E
3F
61
62
63
Non-Inverted Character Codes
The VDG automatically performs this reverse-field operation for any
character which has bit 6 reset, as shown in Figure 1 . 7. Those readers
with Extended Color BASIC can run the following program to show how
video memory bytes can be intermixed with both inverted and normal
characters .
1 0 0 R E M F I L L S C R E E N W I T H I N t.J E R T E D A N D N O N I N t.i C H A R A C T E R S
1 1 0 F O R t.J M = 1 0 2 4 T D 1 0 2 4 + 5 1 1 S T E P
1 2 0 P O K E \.JM ' 1
1 3 0 P O K E 1.J M + l 1 8 5
1 4 0 N E )< T I.J M
1 50 GOTO 1 50
,..,.:..
NON-INVERTED
('REVERSE FI E LD') )
m
[Al
I N VERTED)
Figure I. 7:
BI T
B I T RESET
BI T
7 6 54 3 2 1 0
l o l1 l o l o l o l o l o l1I
"-- BI T 6 SET
7 6 543 2 1 0
l o l o l o l ol o l o l o l1I
\___ 6
Reverse field display.
The B ASIC interpreter (Color or Extended Color) normally enters a
non-inverted character code in the proper video memory location. If the
(SHIFT) and (ID keys are held down simultaneously, then the BASIC
interpreter switches from the current mode, inverted or non-inverted, to
the other mode. Try entering some simple text on the screen and use the
(SHIFT) and (ID key to see this effect. Figure 1 . 8 shows the result in
memory.
Color Computer Memory Mapping and Semigraphics Modes
L I
DI S PLAY LI N E
BI N ARY
1024
0
1
0
0
1
1
0
0
1025
0
1
0
0
1
0
0
1
1026
0
0
0
0
1
1
1
0
1027
0
1
0
0
0
1
0
1
1028
0
1
1
0
0
0
0
0
1 029
0
0
1
1
0
0
0
1
Figure 1.8:
13
1
DECI M AL CHARACTER
L
NE (NON-INVERTED)
(NON-I N VERTED)
76
73
14
69
96
49
1
Inverted and non-inverted displays.
SEMIGRAPHICS MODES
There are four semigraphics modes in the Color Computer. I'd like
to tel l you that the semigraphics modes were named after that English
computer scientist, Alfred E. Semigraphics . However, this confusing
term really comes from the fact that all semigraphics modes use the same
character position as the alphanumerics mode , a block of 8 by 12 pixels.
It is possible to intermix text and graphics in some of the
semigraphics modes , unlike the true graphics modes.
Depending upon the mode , the semigraphics modes divide the block
up into 4, 6, 8, 12, or 24 elements as shown in Figure l . 9 . The
semigraphics modes are called semigraphic 4, semigraphic 6 ,
semigraphic 8 , semigraphic 12, and semigraphic 24 , each name reflecting
the number of elements. Each mode divides the block into 2 columns 4
pixels wide .
14
L
N
E
DISPLAY LINE
�
0
0
0
oo
0 0 0
0
00
O
o
0
0
0
0
12
6
PIXELS
PIXELS
SEMIGRAPHIC
(4 ELEMENTS)
6
PIXELS
4 PIXELS
( 6
6
SEMIGRAPHIC
4
ELEMENTS)
PIXELS
4 PIXELS
PIXELS
SEMIGRAPHIC
(8
ELEMENTS)
8
Pl XE LS
PIXELS
PIXELS
2
(12
SEMIGRAPHIC
2
2
12
2
ELEMENTS)
2
2
PIXELS
PIXELS
PIXELS
PIXELS
PIXELS
PIXELS
PIXEL
I 24
SEMIGRAPHIC
I
24
(J2 Tl MES)
ELEMENTS)
'---..----'
8 PIXELS
Figure 1 .9:
Semigraphics format.
j
I
Color Computer Memory Mapping and Semigraphics Modes
15
Semigraphic 4 Mode
This mode divides up a character position into 4 elements . Each
character position of the 32 character positions per each of the 1 6 lines is
represented by 1 byte in video memory . A total of 512 bytes are required
in video memory . The mapping for this scheme is shown in Figure I . I 0 .
Each element in the character position is either o n o r off. The color
for off elements is black. The color for on elements is one of the eight
standard colors in the YDG: green, yellow , blue, red , buff, cyan ,
magenta, or orange .
Each byte in video memory holds a number of fields , as shown in
Figure I. 1 1 . The first bit is a I , indicating the semigraphics mode. The
next field indicates the color; it holds binary values from 000 through
1 1 1 , or 0 through 7 . The next 4 bits represent the on/off state of each of
the four elements - a zero is off (black) while a one is on (color) .
r
N
(
A � C D DI SPLAY LI N E 1
L
1024
10251026
N
E
10271028
10291030
A� (SEMIG RAPHIC DATA)
10311032
cD
1033
1034
512 BYTES TOTAL
4
,....
Figure 1 . 10:
Semigraphic
+
-'-
4 mapping.
7I 1 lc62lc51 Jc40IL33JL221L1ijL0ol (SEMIGRAPHIC BYTE)
GREEN 000001
COLOR
YELLOW
FI ELD ELEMENT
ON/OFF
STATUS BLUERED 011010
BUFF
100101
CYAN
MAGENTA
ORANGE 110111
4
'-----...,----' '--....----'
Figure I.II:
Fields in semigraphic
4 mode.
16
Note that in this mode all four elements have the same color; there
cannot be four separate colors in each of the four elements.
This mode is the Color BASIC high-resolution mode of 64 pixels
horizontally by 32 pixels vertically. It is used in the SET,·RESET, and
POINT commands. In these commands, an X value of 0 through 63
specifies the horizontal position , while a Y value of 0 through 3 1
specifies the vertical position. The following BASIC code uses the SET
command to set the screen to this mode with alternating colors from 0
through 7 (green through orange) .
1 00
1 10
1 20
1 30
1 40
1 50
1 60
170
1 80
1 80
R E M S E M I G R A P H I CS 4 M O D E
C= l
FOR Y = 0 TD 3 1 STEP 2
F O R }( = 0 T D 6 3 S T E P 2
S E T ( ){ 1 Y 1 C )
S E T ( ){ + 1 1 Y 1 C l
S E T 0( 1 Y + l 1 Cl : S E T 0( + 1 1 Y + l 1 C l
C = C + l : I F C = 8 THEN C = l
N E >( T }-(
N E >( T y
GOTO 1 80
Color BASIC converts the C value in the SET command to a value
of 0 through 7 by subtracting one. It then stores this value in the color
field. The X and Y values from the set turn on one of the four elements in
the character position block. As the color value must be the same for all
four elements of the block, the program above uses the same color value
for all four elements . Typical values in video memory for a small number
of points are shown in Figure l . 1 2 .
I n addition to setting the most significant bit i n the video memory
byte associated with the character position, the BASIC interpreter sets the
VDG to the semigraphics mode . This is done prior to any display work.
The entire screen is either in the alphanumeric/semigraphic mode or in
the graphic mode . The location associated with setting the mode is
location 653 1 4 . The following code will set the semigraphic 4 mode .
1 00 A = PEEK C 653 1 4 l
1 1 0 P O K E 6 5 47 6 1 0
P O K E 6 5 472 1 0
: P O K E 6 5 3 1 4 1 C A A ND 7 )
P O K E 6 5 474 1 0 :
Note that if you are using BASIC, the BASIC interpreter will
automatically set the alphanumeric/semigraphic mode whenever a return
is made to the BASIC interpreter. You do not have to be concerned about
any POKEs to the locations above.
Color Computer Memory Mapping and Semigraphics Modes
_J _
1 I1
ONEGRAPHI
COLUMNSOFCS64
17
--1 I--
ONE CHARACTER POSI T I O N
123456
DIS PLAY LI N E 1
110250 24 7 61 500 400 03 02 01 00 CHARACTER POSITION 2
0 00 01 00 0
3
10271026
0
4
1028 1 00 00 0 1 01
56
1029
1030 /
BUFF
� ELEMENT
COLOR
ON/OFF
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
,l.-
,
Figure 1.12:
I
Semigraphic
4 data storage example .
Semigraphic 6 Mode
Semigraphic 6 and the remaining semigraphics modes (semigraphics
8 and semigraphics 1 2) are the forgotten semigraphic modes. (Years ago,
these modes were implemented in the VDG. Paperwork defining the
modes was shuffled and lost, however, and neither the Color BASIC
interpreter nor the Extended Color BASIC interpreter contain commands
to set the modes . ) If the modes are used, they must be set by POKEs to
address 653 1 4 and the addresses in the range 65472 through 65477 .
In addition , the video memory area must be set to the proper byte
configurations. This is not difficult in the semigraphic 6 mode, where one
byte is used for each character position. But it's somewhat more involved
in semigraphics 8 and semigraphics 1 2 modes. We'll discuss each of the
modes in detail , but remember that you may never want to use any
semigraphic mode other than semigraphic 4, and you may want to do that
automatically through the BASIC interpreter.
Semigraphic 6 mode divides up a character position into six
elements . Each of the 32 character positions per line in each of the 1 6
l ines is represented by one byte in video memory. A total of 5 1 2 bytes
are required in video memory. The mapping for this scheme is shown in
Figure 1 . 1 3 .
18
r
I
NE
1024
1025
11002627
1028
10291030
10311032
11003433
Figure 1 . 13:
A � C D DIS PLAY LINE I
L
NE
s
A (SEMIGRAPHIC 6 DATA)
D
�
c
,._
,-
512 BYTES TOTAL
Semigraphic 6 mapping.
This mode makes two sets of two colors available. The border color
is always black, as it is for all semigraphics modes. One set of colors that
can be chosen is green , yellow , blue, and red. A second set is buff, cyan,
magenta, and orange. As in the semigraphic 4 mode, all on elements
have the same color, while all off elements are black .
Each byte in video memory holds a number of fields , as shown in
Figure 1 . 1 4 . The first field is made up of two bits that determine the
color as shown in the figure . The next six bits determine the on/off state
of each of the six elements in the character position; a one is on while a
zero is off.
.....____., '--....-----'
ELEON/OFF
MTUENST
COLOR
FI
E
LD
ST
A
GREEN 0001
YELLOW
BLUERED 11I 0
Figure 1 . 14:
Fields in semigraphic 6 mode.
Color Computer Memory Mapping and Semigraphics Modes
19
The selection o f the color set i s made b y setting o r resetting bit 4 of
address 653 1 4 . A zero in bit 4 generates magenta or orange, depending
upon the color bit in the video memory byte . A one in bit 4 generates
blue or red, depending upon the color bit in the video memory byte .
To utilize this mode in BASIC, set or reset the 653 1 4 address bit,
change the 65472-65477 addresses, and then fill the 5 1 2 bytes of video
memory with the graphics you want displayed. The following program
uses an on color of blue and sets a checkerboard pattern on the video
display .
1 0 0 R E M S E M I G R A P H I C S 6 M OD E
1 1 0 A = P E E K ( 6 5 3 1 4 ) : P O K E 6 5 3 1 4 1 C A A ND
7 ) + 8+ 1 6 ' U S E 1 6 D R 0
1 2 0 P O K E 6 5 47 6 1 0 : P O K E 6 5 474 1 0
P O K E 6 5 47 2 1 0
1 3 0 F O R V M = 1 0 2 4 T D 1 0 2 4+ 5 1 1
1 4 0 I F I V M A ND 3 2 1 = 0 T H E N P O K E V M 1 l 6 6
ELSE POKE VM 1 1 53
1 5 0 N E> : T I.J M
1 60 GOTO 1 60
The appearance of the display is shown in Figure 1 . 1 5 .
BLACK
BORDER
------6 4 COLUMNS--------+
.- -.- -.- - - - - - - - - - - - - - - -i
••
( BELEMENT
LUE
BLACK
SPACE
BLUE
�
\__
�
!
j1j oi1! 0 ! 0 !1!1 l o l
51 31 0
Figure l . 15:
Semigraphic 6 example.
20
Semigraphics 8, 1 2, and 24 Memory Requirements
·
·
Two preceding semigraphic modes used 1 byte in memory for all
graphics elements and required 5 1 2 bytes of memory. The semigraphics
8, 1 2 , and 24 modes require 4, 6, and 1 2 bytes of memory respectively
for each set of graphics elements . This increases the video memory
requirements to 2048 , 3072, and 6 1 44 respectively.
There is 1 byte of memory for each of the rows in the graphic
character position for these three modes. The memory mapping of each
character position is somewhat involved. The byte for each row is
displaced 32 bytes from the last row rather than being adjacent in
memory. We'll give you examples in the discussions fol lowing.
Semigraphics 8 Modes
This mode divides the character position into 8 elements, each
element being 4 by 3 pixels , as shown in Figure 1 . 1 6 . Each character
position of 8 elements is represented by 4 bytes in video display memory,
making a total of 4 x 5 1 2 bytes, or 2048 bytes of video memory .
----- 64 GRAPHI C S -------­
COLUMNS PER LINE
-----3 2 CHARACTER -------­
POSITIONS PER LINE
LINE 1
64
GRAPHICS
ROWS PER
S C REEN
16
LINES
64 x 64
I
�·
1 ST ROW
2NO ROW
3RO ROW
4TH ROW
1024
1025
1026
1027
TOP ROW OF
L--
LINE l,
�
-- _;,__c P_2...J ®
CP3 ©
�------_
· , __c P_4--I@
--
·
1055
TOP ROW OF LINE
1056
2ND ROW OF LINE
1057
CPI
• ,
l,
�
CP32
· CPI
@
�-----''-'CC.P..:2--1@
2048 BYTES TOTAL
Figure 1 . 16:
ONE C HARACTER
POSITION
Semigraphic 8 mapping.
L
CP 1
CP2
CP3
rlNE
�INE
32 BYTES DIFFEREN C E
BETWEEN ROWS I N
THE SAME C HARACTER
POSITION
Color Computer Memory Mapping and Semigraphics Modes
21
The relationship between the video memory bytes and the elements
of the character position is shown in Figure 1 . 1 7 . There is a memory byte
for each row . Each byte of the 4 memory bytes has bit 7, the most
significant bit, set. The next 3 bits of each byte are the color for the row .
The remainder of the bytes hold the on/off state for each of the 8
elements , 2 elements being specified per byte.
ROW 21
4
ROW 1 BYTE
ROW 2 BYTE
3
L]L 5 � LL64 } ONECHARACTER
LL I LL 2o POSITION
3
X=DON'T
(0 OR I)CARE
ROW 4 BYTE I C 2 C 1 C o x x L 1 L o +96
COLOR
FI E LD ELEMENT
ON/OFF
STATUS
Figure
'---...--' �
1.17:
Semigraphic 8 format.
Eight colors can be specified for each row . It is possible to have
green in row 0, red in row 1 , orange in row 2, and buff in row 3 , for
example. As in the other semigraphics mode, the border is always black .
As we mentioned earlier, this mode is not implemented in either
Color B ASIC or Extended Color BASIC. It must be invoked by setting
up the proper data in memory and issuing a POKE to address 653 1 4 and
POKEs to addresses 65472-65477.
The program below shows how the mode is used . A POKE to 653 1 4
o f 0 and a POKE 6547 5 , 1 sets the mode. We ' ve chosen to store a
checkboard pattern of 64 elements by 64 elements . Each new on element
will be set to a different color. There will be off (black) elements
between each on element. The appearance and layout is shown in Figure
1 .18.
22
1 0 0 R E M S E M I G R A P H I CS 8 M O D E
11 0 A = P E E K ( 8 5 31 4 ) : P O K E 8 5 31 4 t <A A N D 7>
1 2 0 P O K E 8 5 47 8 1 0 : P O K E 8 5 47 5 1 1 : P O K E
8 5 47 2 1 0
130 C = 0 : D T =1 2 8 + 0 + 8 : N = B
140 F O R L N = 0 TO 8 3
150 F O R C P = 0 T D 8 2 STE P 2
180 P O K E 1024+LN*32+ C P / 2 1 D T
170 N E >( T C P
1 8 0 C = C +1 8 : I F C = 1 2 8 T H E N C = 0
180 N = N / 2 : IF N<1 THEN N=B
200 D T =128+C+N
210 N E ){ T L N
220 GOTO 220
BLACK BORDER
BLACK
SPACE
--- ---
ROWS64
I
I
I
+
GREEN
YELLOW
BLUE
REDBUFF
CYAN
MAGENTA
ORANGE
Figure
1.18:
11
11
11
11
00 00 01
00 11 01
11 00 01
1I 11 0I
COLOR
(REPEATS)
10
00
10
00
01 00 00
00 01 01
01 00 00
00 01 0I
BIT
(RONEPEATS)
� �-��-�
Semigraphic 8 example.
Color Computer Memory Mapping and Semigraphics Modes
23
The program above uses two loops . The outer loop (FOR LN = 0 TO
64) increments the row number LN from 0 through 63 . The inner loop
(FOR CP = O TO 3 1 ) increments the column number CP from 0 through
63 . A total of 64 x 32 or 2048 passes are made through the loops,
representing 2048 POKEs for the 2048 bytes of video memory.
For each byte of video memory , a POKE of DT is done. OT is the
byte for the current row and 2 columns. It is equal to 1 28 (most
significant bit is always a one) + C (the current color value) + N (the
current bit to be set) . The color value C changes by one for each new
row , cycling through 0 through 7. The bit value changes to produce the
checkerboard pattern .
Prior t o the POKEs , the semigraphics 8 mode i s set b y POKEs to
653 1 4 and 65472-65477.
Sem igraphics 12 Mode
This is the fourth semigraphics mode. It divides the character
position into 1 2 elements as shown in Figure I . 1 9 . Each element is 4 by
2 pixel s , as shown in the figure . Each character position of 12 elements is
represented by 6 bytes in video display memory, making a total of
6 x 5 1 2 bytes or 3072 bytes of video memory.
---64 GRAPHICS ------­
COLUMNS PER LINE
--- 32 CHARACTER
-----­
POSITIONS PER LINE
l
LINE l
96
G R APHICS
ROWS PER
f'"
ONE CHARACTER
POSITION
!ST ROW
2ND
3RD
4TH
5TH
6TH
1024
1025
1026
1027
TOP ROW OF LINE l, CPI
"-------'-· ' '' "--<
- ©
•
•
•
•
• I CP4
©
1055
TOP ROW OF LINE 1, CP32
1056
2ND ROW OF LINE l, CPl
1057
1058
�
·"'-,_
, , 2_, ®
'-------
L._____0;_
' c_ n
@
_, @
"------0'-' c_P-<
J @
L
3072 BYTES TOTAL
Figure 1 . 19:
Semigraphic 12 mapping.
�:1 :
c
(!!
2
c
�
J
cC1
LINE
LINE
��� �;� ��! �
32 BYTES DIFFER E N C E
w
R
E
R CTER
POSITION
24
As Figure l . 20 shows, there is a memory byte for each row, similar
to the mapping of semigraphics 8 mode. Each of the 6 bytes has bit 7, the
most significant bit set. The next 3 bits of each byte are the color for the
row . The remainder of the bytes hold the on/off state for each of the 1 2
elements , 2 elements being specified per byte.
l
ROW 2
34
6
'"�'"}
LL1g
LL 3
L1
LLe6 CHARAC
LL 42 ONEPOSI TIOTERN
Lo
COLOR
FI E LD ON/OFFELEMENTSTATUS
C 2 C 1 C o Lu L lO
C 2 C 1 C o Lg Le
C 2 c l co L 7 L 6
C 2 C l co
L3 L 2
C 2 C 1 Co
L 1 Lo
C2 C 1 Co
5
,------...
ROW l BYTE
ROW 2 BYTE
ROW 3 BYTE
ROW 4 BYTE
ROW BYTE
ROW 6 BYTE
Figure
5
1.20:
�
x
x
x
x
x
x
x
x
x
x
x
x
L5
L4
+o
+32
+64
+96 X=DON'T CARE
+ 128 (0 OR 1l
+160
Semigraphic 12 format.
Eight colors can be specified for each row . The border is always
black. Again, this mode is not implemented in either Color BASIC or
Extended Color BASIC but must be set up by storing the proper data in
memory and issuing 2 POKEs.
The program below shows how the mode is used. POKEs to 653 1 4
and 65472-65477 set the mode. We'll perform a similar program to the
one for semigraphics 8 and store a checkerboard pattern of 64 by 96
elements. Each new on element will be a different color. There will be
off elements between each element. The appearance and layout is shown
in Figure l. 2 1 .
Color Computer Memory Mapping and Semigraphics Modes
25
1 0 0 R E M S E M I G R A P H I CS 1 2
1 1 0 A = P E E K ( 6 5 3 1 4 ) : P O K E 6 5 3 1 l'.1 1 ( A A N D 7 )
1 2 0 P O K E 6 5 477 1 1 : P O K E 6 5 47 4 1 0 : P O K E
6 5 47 2 1 0
1 3 0 C = 0 : D T = 1 2 8+ 0 + 1 0
N= 10
1 40 FOR L N = 0 T O 95
1 50 FOR C P = 0 TD 32
1 6 0 P O K E 1 0 2 4+ L N * 3 2+ C P 1 D T
1 7 0 N E >( T C P
1 8 0 C = C+ 1 6 : I F C = 1 2 8 T H E N C = 0
1 9 0 I F N = 1 0 T H E N N = 5 E LS E N = 1 0
2 0 0 D T = 1 2 8+ C+ N
2 1 0 N E >< T L N
220 GOTO 220
BLACK BORDER
GREEN
YELLOW
BLUE
REDBUFF
CYAN
MAGENTA
ORANGE
GREEN
YELLOW
BLUE
RED
96ROWS1
I
I
I
i
Figure
1.21:
-
-
-
l
0
0
0
l
0
l
l
0
0
l
0
l
0
l
l
0
l
0
l
0
l
0
0
l
0
l
l
0
l
0
l
l
l
0
0
l
0
l
0
l
l
0
l
0
l
0
l
l
l
l
0
l
0
l
0
l
l
l
l
0
l
0
l
l
0
0
0
l
0
l
0
l
0
0
l
0
l
0
l
l
0
l
0
l
0
l
0
l
0
l
l
0
l
0
l
� �������
T
(RCOLOR
EPEATS) ( 2 BI(RTONEPEATS)
S IBIGNORED)
Semigraphic 1 2 example.
This program is very similar to the program for semigraphics 8 .
(What the heck, i t saves wasted energy i n being creative . . . ) I t operates
from rows 0 through 9 5 , however, reflecting the fact that there are 96
vertical row s . The color variable C and bit on value N change as before,
except that N is flipped back and forth between a 1 0 1 0 and 0 1 0 1
configuration. (Only 2 o f the on bits are used i n each 1 0 1 0 or 0 1 0 1
value . )
26
Semigraphics 24 Mode
This is the super semigraphics mode . It divides the character
position into 24 elements , each element being 2 by 1 pixels as shown in
Figure 1 . 22. Each character position of 24 elements is represented by 1 2
bytes i n video display memory , making a total of 1 2 x 5 1 2 bytes , or 6 1 44
bytes of video memory.
----- 64 G R A P H I C S -------­
C OL U M N S P E R L I N E
----- 3 2 C H A R AC T E R -------­
PO S I T I O N S P E R L I N E
L I NE l
2
192
GRA P H I C S
ROWS P E R
S CR E E N
64 x 1 9 2
16
L I N ES
3
4
ONE C HARACTER
POS I T I O N
1024
TOP ROW OF L I N E l, C P I
1 0 25
, CP2
1026
, CP3
1027
, CP4
1055
TOP R O W O F L I N E I , C P 3 2
1056
2 N D ROW OF LINE I, C P l
1057
, CP2
10 58
, CP3
6 1 44
Figure 1.22:
Semigraphic
24
B Y T ES TOTA L
mapping.
A
CPI
®
©
®
@
@
®
CP2
CP3
LINE 2
L
3 2 BYT E S D I F F E R E N C E
BE TWE E N R O W S I N
T H E SA M E C H A R A C T E R
P OS I T I O N
Color Computer Memory Mapping and Semigraphics Modes
27
Each row with 2 columns i s represented b y 1 memory byte a s in the
preceding two semigraphics modes, as shown in Figure 1 . 23. Each row
may be one of eight colors, as in the other modes . Again, the format for
each byte is virtually identical to the other modes, as shown in the figure .
The border is black as before . Again, this is a forgotten mode as far as
the B ASIC interpreters .
L2220
161814
1210 ONEPOSI TCHARACTER
86 I ON
42
0
ROW l2 L2321
435 191715
67 1311
89 97
1011 53
12
ROW 2 BYTE 11 CC2 cCl CC o L2123 2220 xx xx +O+ 32
ll cC22 cCll cCoo 1917 1618 xx xx ++9664
34
11 CC22 Ccll CCoo 1513 1214 xx xx ++ 160128
56
+ 192 NOTTHESECONTBYTESI GUOUSARE
11 CC22 CCl1 CCoo xx xx 119 108 +224
78
910 11 CC22 Cc l1 CCoo xx xx 57 64 ++ 288256
1112 1 CC22 ccll CCoo xx xx 31 02 ++ 320352
2lo
ELEMENT
X • DON' T CARE
OFF
FlCOLOR
ELD ONSTATUS
!
1
I
Figure l .23:
Semigraphic 24 format.
28
The program below is almost identical to the semigraphics 1 2 mode.
(Writers are lazy by nature. ) In this case, however, the number of rows
goes from 0 through 1 9 1 . As in the other examples, the mode is set by
POKEs to 65475 and 65472-65477 .
1 0 0 R E M S E M I G R A P H I CS 2 4
1 1 0 A = P E E K < 6 5 3 1 4 ) : P O K E 6 5 3 1 4 1 <A A N O 7 )
1 20 POKE 65477 , 1 : POKE 65475 , 1 : POKE
65472 1 0
1 30 C = 0 : DT = 1 28+0+ 1 0
1 40 FOR LN=0 T D 1 8 1
1 50 FOR C P = 0 T D 32
1 60 POK E 1 024+LN*32+C P 1 DT
1 7 0 N E )< T C P
1 80 C = C+ 1 6 : I F C = 1 28 THEN C = 0
1 8 0 I F N = 1 0 T H E N N = 5 E LSE N = 1 0
200 DT = 1 28+C+N
2 1 0 NEXT LN
220 GOTO 220
USING THE SEMIG RAPHICS MODES
The semigraphics 8, 1 2, and 24 modes are somewhat cumbersome
to use because there are no BASIC functions that implement them. As
we'll see in the next chapter, however, they do offer one advantage over
the true graphics modes - they provide eight colors with a maximum
resolution of 64 by 192, which is a fairly fine resolution. Keep them in
mind for possible use in BASIC or assembly-language programs if the
graphics modes do not provide enough colors for your application.
Let's emphasize again that the semigraphics 6, 8, 12, and 24 modes
are much harder to use than the graphics modes handled automatically in
the BASIC interpreters. You may not want to bother with POKEing into
the address locations. This information is presented for your amazement
and amusement only!
In the next chapter we'll look at the remaining graphics modes, the
true graphics modes. These are implemented in Extended BASIC and can
be used much more easily than the semigraphics modes covered in this
chapter.
Color Computer Memory Mapping and Semigraphics Modes
N OTES
29
True Graphics Modes
31
CHAPTER 2
True Graphics Modes
In this chapter we 'll look at the true graphics modes of the Color
Computer. Many of the modes are supported by the Extended Color
BASIC but can be used with Color BASIC if you have enough
random-access memory (RAM) for the video memory area and are
willing to set up the data in video memory in your own BASIC code .
There are 8 different graphics modes in the Color Computer, ranging
from a four-color 64 by 64 mode, which requires 1 024 bytes of video
memory, to a two-color 256 by 1 92 mode , which requires 6, 1 44 bytes of
video memory . Generally, the higher the resolution, the fewer colors and
the greater the amount of video memory required. The number of colors
is limited to either two or four, plus a border color. The available
graphics modes are shown in Figure 2 . 1 .
As you can see from the figure , Extended Color BASIC supports the
5 highest resolution modes. We'll discuss each of the modes in detail ,
showing you how to use them in Extended BASIC and in your own code.
B efore we get into the detailed discussion , however, let's look at some of
the characteristics of these modes .
32
MOOE
SCREEN
....f.-
64-- 1024
64 X 64 F 64 FOUR
COLORS BYTES
128- 1024BYTES
128X64T 64i TWOCOLORS
VIDEO
MEMOR Y
I
f
-f-
REQUIRED
-
-
1------1
-
-f-
l
2048
BYTES
1BYTES
536
�
2048
BYTES
�
3012BYTES
I
�
'-
I
I
I
I
I
)
2048
BYTES
2048
BYTES
6144
BYTES
-t-
12s- 6144
(128Xl
PMODE92F3) 19i2 COLORS
FOUR
BYTES
6144
256BYTES
256X192
T
192
(PMODE4) i TWOCOLORS
4
Figure
2.1:
Graphics modes.
::�:,
�
-f-
-t-
I
I
-f-
12s128 X 64 F 64i COLORS
FOUR
128(P128X96T
MODE 0) 96i COLORS
TWO
128(128P MODEX961F 96i FOUR
COLORS
128(128PMODEX 1922)T 19i2 COLORS
TWO
} 1536BYTES
I
)
True Graphics Modes
33
BORDER AND COLOR SET FOR GRAPHICS MODES
The border in the alphanumeric and semigraphics modes was always
black, no matter what colors were used on the image area of the screen.
In the graphics modes we have a choice of either a green or a buff color
for the border. By border, of course, we mean the space surrounding the
area in which we can actually store graphics characters or text (see Figure
2 . 2) . The choice of border is hardwired by the video display generator
(VDG) chip and can't be changed.
GREEN OR BUFF BORDER
GRAPHI C S OR TEXT
Figure
2.2:
Border area.
The color set in the graphics modes is also predefined, as shown in
Table 2 . 1 . The color sets in the four-color mode are green, yellow , blue,
and red with a green border, or buff, cyan, magenta, and orange , with a
buff border. Note that the border color for each set is always the first
color of the set . The color sets in the two-color mode are black and green
with a green border or black and buff with a buff-colored border. Here
the border is the last color of the set.
The color set , including border, is selected in Extended BASIC by
the SCREEN command, which has the format
S C R E E N type 1 color set
In the command above , type is 0 for text screen or 1 for graphics
screen , and color set is 0 or l for the two-color sets .
34
Two-Color
Four-Color
Color
HW BASIC
HW BASIC
Color
Color
Set o
*Green
Yellow
Blue
Red
0
1
2
3
1
2
3
4
Black
*Green
0
1
0
1
Color
Set 1
*Buff
Cyan
Magenta
Orange
0
1
2
3
5
6
7
8
Black
*Buff
0
1
0
1
HW
Table 2 . 1 :
=
hardware code
BASIC = BASIC code
*
=
border color
Graphics Modes Color Sets .
The SCREEN command selects the color set by outputting a color
set select (CSS) signal to the VDG . This signal is either a 0 or 1 ,
selecting one o f the two color sets available. There are never more than 2
color sets available in any VDG mode, be it alphanumeric, semigraphics ,
or graphics.
The type parameter switches from a text screen to graphics screen .
In fact, this simply involves setting the alphanumeric/semigraphic mode
or the graphics mode. The SCREEN command can be used to switch
color sets in the text screen mode, resulting in red on black or black on
green . In the graphics mode it switches colors in a similar fashion.
VIDEO MEMORY MAPPING IN THE GRAPHICS MODES
In the semigraphics modes of the last chapter, the video memory
mapping was somewhat less than straightforward . (This chapter was
simplified from an earlier version which put a Color Computer user in a
trauma ward in Des Moines . ) The memory mapping in the graphics mode
is much easier to understand , and while such an understanding is not
essential to successful use of this mode , it will enable you to solve
problems more easily and create more sophisticated applications .
In all of the graphics modes the data for display is in video memory
as a string of 1 - or 2-bit fields . The upper left element of the display is
represented by the first field, the next element to the right by the second
field , and so forth down to the field for the lower right element. Each
True Graphics Modes
35
TWO-COLOR
GRAPHI
DISPLAYCS
VIMEMORY
D EO
BYTE
LDS"
DEFI N8E"FI8 EELEMENTS
FOUR-COLOR
DIGRAPHI
SPLAYCS
VIMEMORY
D EO
BYTE
Figure
2.3:
LDS"
DEFIN4E"FI4 EELEMENTS
Fields in the graphics modes .
field is 1 bit for a two-color mode or 2 bits for a four-color mode, as
shown in Figure 2. 3 .
The total amount of video memory in bytes required is 1 x H x V/8
or 2 x V x H18 , where H is the number of horizontal elements and V is the
number of vertical elements . The product is divided by 8 to find the
number of 8-bit bytes required. As an example of this, suppose that we
have a graphics mode of 1 28 by 1 92 . In this mode we have only two
colors . The total number of bits is I x H x V = I x 1 28 x 1 92 = 24 ,576,
and the total number of bytes required is 24 ,576/8 = 3 ,072 .
Each memory byte represents 4 or 8 elements, depending upon
whether a four- or two-color mode is in force. For example, the upper
row of a 1 28 horizontal element mode with two colors is represented by
1 28/8 or 1 6 bytes. These bytes would occupy consecutive memory
locations starting at video memory location 1 536 and ending in video
memory location 307 1 .
As in the other video modes, video memory is a part of RAM and
continues upward, as shown in Figure 2 . 4 .
36
,
,,..
l EOO
7680
6144 1800
4608 1200
3072
1536 0 600
1024 0400
0 0000
ocoo
Figure 2.4:
GRAPHIFOURCSMOREPAGES
l
GRAPHICS PAGE 4
RAM
GRAPHICS PAGE 3
GRAPHICS PAGE 2
GRAPHICS PAGE
TEXT SCREEN
SYSTEM USAGE
1
Video memory in graphics.
PMODE COMMAND
The PMODE command in extended BASIC selects one of 5 higher
resolution graphics modes . The format of the PMODE command is
P M 0 0 E mode 1 start-page
The mode value in PMODE may be 0 through 4 . The mode values
correspond to the resolutions and colors shown in Table 2 . 2 . The
start-page selects a video memory page from 1 to 8 . We' ll discuss pages
a little later in this chapter, but for now assume that we're talking about
the first page, starting at video memory location 1 536.
As you can see from the table, there are three modes not supported
by the PMODE command. These three modes are the 64 x 64 F mode,
the 1 28 x 64 F mode, and the 1 28 x 64 T mode. The first number is
True Graphics Modes
P MODE
Resolution (H x V)
Bytes
Pages
0
1
2
3
4
1 28 x 96
1 28 x 96
1 28 x 1 92
1 28 x 1 92
256 x 1 92
1 536
3072
3072
61 44
61 44
1
2
2
3
4
37
Colors
Blk/Grn or Blk/Buff
GYBR or BCMO
Blk/Grn or Blk/Buff
GYBR or BCMO
Blk/Grn or Blk/Buff
GYBR is green, yellow, blue, red
BCMO is buff, cyan, magenta, orange
Table 2.2:
PM ODE Values vs. Resolution .
the horizontal resolution, the second is the vertical resolution, the "F" is
four-color, and the "T" is two-color. This is how we ' ll refer to these
modes in the following discussion . We ' ll use the PMODE designators for
the other five modes .
The 64
x
64 F Mode
This mode is not supported by BASIC . It is a four-color mode that
displays graphics in a 64 by 64 matrix. As this is a total of 8 1 92 bits , it
requires 1 024 bytes of video memory. The mapping for this mode is
shown in Figure 2 . 5 .
This mode can b e set b y POKEs, providing that the video memory is
properly set up. The following BASIC program shows how to utilize this
mode . The program draws alternating blue and red vertical stripes and
then switches to the alternate color set for magenta and orange stripes .
1 00
1 10
1 2 Q)
1 3 Q)
1 4 Q)
1 50
1 60
1 70
1 80
1 80
200
210
220
R E M 6 4 >: 6 4 F G R A P H I C S
P O K E 6 5 47 3 ' 1
P O K E 6 5 47 4 , Ql
P O K E 6 5 47 6 , Ql
A = < P E E K <6 5 3 1 4 ) A N D 7 ) + 1 2 8
POKE 653 1 4 ,A
F O R I.J M = 1 0 2 4 T D 1 0 2 4+ 1 6 * 3 1 + 1 5
P O K E t.J M , 1 87
N E >< T t.J M
F D R I = l T D 6 0 0 : N E >< T I
A = < P E E K < 6 5 3 1 4 l A N D 7 ) + 1 2 8+ 8
POKE 653 1 4 tA
GOTO 220
38
ROW 1
ROW 2
I
64
+
BYTE 1
ROW 6 4
C 1C o C 1Co C 1 C o C 1 C o
F I RS T 4 E L E M E N T S OF ROW 1
2
NEXT 4
3
NEXT 4
4
16
17
1024
�
�
C 1 C o C 1 C o C 1 C o C 1 Co
COLOR SET 0
* GREEN
YELLOW
BLUE
RED
L A S T 4 ELE M E N T S OF ROW
1
F I R S T 4 E L E M E N T S OF ROW 2
LAST 4 E L E M E N T S OF R OW 6 4
COLOR SE T 1
* BUFF
CYAN
M A G E N TA
ORANGE
* = BORDER COLOR
Figure 2.5:
6 4 X 6 4 F mode mapping.
The first 3 POKEs set the VDG to the 64 by 64 mode. The next
PEEK statement sets the graphics mode . The four statements must be
used exactly as they appear. The FOR . . . TO loop stores a value of 1 87
into the start of video memory through the halfway point. There are 1 6
bytes per row, and the last location to be stored is
1 024 + 1 6 x 3 1 + 1 5 .
After a short timing loop, a second POKE to 653 1 4 is done to
change the color set select.
The data value of 1 87 stored in each byte is 1 0 1 1 1 0 1 1 in binary.
There are 2 bits for each element, so this represents alternating 1 0s artd
l l s , or blues and reds (color set 0) .
The figure drawn is shown in Figure 2 . 6 . There will be "garbage "
in the bottom of the screen . A full screen in this mode is 1 024 bytes . As
only one half of the screen was written , extraneous characters are present
in the bottom half of the screen .
True Graphics Modes
39
G R E E N OR B U F F B O R D E R
BL U E / R E D OR
M A G E N TA /O R A N G E
STRIPES
GARBAGE
Figure 2.6:
The 1 28
64 x 64 F mode example.
x
64 T Mode
This is the second mode not supported b y BASIC . I t is a two-color
mode that displays graphics in a 1 28 by 64 matrix . It requires the same
amount of memory as the 64 x 64 F mode
1 024 bytes . The
horizontal resolution has been doubled at the expense of halving the
number of colors available. The mapping for this mode is shown in
Figure 2 . 7 .
-
This mode can again be set b y POKEs i n a manner very simi lar to
the 64 x 64 F mode . The following program is almost identical to the
64 x 64 F program except that it initializes the VDG to the 1 28 x 64 T
mode and stores a value of I 0 1 0 I 0 1 0 ( 1 70 decimal) . These represent
alternating black and green stripes in the first color set and alternating
black and buff in the second color set. Note that one of the colors used in
each case is the border color, so the edges merge into the border.
1 00
1 10
1 20
1 30
1 40
1 50
1 80
1 70
REM 1 2BX84T GRAPH I CS
POKE 85473 , 1
POKE 85474 t0
P O K E 85478 t 0
A = ( PEEK ( 853 1 4 l A N D 7 l + 1 28+ 1 8
POKE 853 1 4 , A
FOR VM= 1 024 T D 1 024+ 1 8•3 1 + 1 5
P O K E t,J M , 1 7 0
40
1 80
1 80
200
210
220
N D < T t.J M
FDR I = l TD 600
A = PEEK ( G53 1 4 ) +8
POKE G53 1 4 1 A
GOTO 220
:
NEXT
I
I n this mode, there i s also garbage i n the bottom half of the screen,
as only 5 1 2 bytes were written.
BYTE 2l
3
ROWROW 2l
+12a64
l
ROWj 64
FIRST 88 ELEMENTS OF ROW
NEXT
NEXT 8
LAST
FI R ST 88 ELEMENTS
ELEMENTS OFOF ROWROW 2
LAST 8 ELEMENTS OF ROW 64
BLACK 0l *BUFF
BLACK
*GREEN
*=BORDER COLOR
l
1716
1024
l
C
COLOR SE T 0
Figure 2.7:
The 1 28
COLOR SET
1
128 x 64 T mode mapping.
x
64 F Mode
This mode is the third mode not supported by BASIC . It is a
four-color mode that displays graphics in a 1 2 8 by 64 matrix . As the
number of colors has been doubled over the 1 28 x 64 T, twice as much
memory is required
2048 bytes . The mapping for this mode is shown
in Figure 2 . 8 .
This mode, again set b y POKEs, i s very similar to the previous two
modes. The following program is almost identical to the previous
programs except that it initializes the VDG to the 1 28 x 64 F mode and
-
+12s64!
2
BYTE l
ROW
ROW
True Graphics Modes
I2
j 64
ROW
C 1 C o C 1C o C 1 C o C 1C o
F I R ST
4
NEXT 4
ELEMENTS OF ROW
N E XT 4
3
32
L A ST
33
F I R ST
COLOR
SET 0
* GR E E N
Y E LL O W
BLUE
RED
41
0001
10
C1 Co
11
44
I
E LE M E N T S O F R O W I
EL EMENTS O F ROW
COLOR
SE T
2
1
* BU F F
CYAN
M AG E NTA
ORANGE
* = B O R D E R C O L OR
Figure 2.8:
1 28 x 64 F mode mapping.
stores a value of 1 0 1 1 1 0 1 1 ( 1 87 decimal ) . This value represents
alternating blue and red (color set 0) or magenta and orange (color set 1 )
stripes as in the 64 x 64 F program .
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 80
200
210
220
REM 1 2BX64F GRAPH I CS
POKE 65472 10
POKE 65475 1 1
POKE 65476 1 1
A = < PEEK < 653 1 4 l AND 7 l + 1 28+32
POKE 653 1 4 1 A
F O R VM= 1 024 TD 1 024+32•3 1 +3 1
P O K E t.J M 1 1 8 7
N E> ( T I.J M
FOR I = l TD 600
A = PEEK < 653 1 4 l +8
POKE 653 1 4 1 A
GOTO 220
42
Here, 2048 bytes are required, but only I 024 bytes (32 x 3 1 + 3 1 )
are stored, leaving garbage in the bottom half of the screen as before.
Graphics Modes in Extended Color BASIC
The next graphics modes are all supported in Extended Color
BASIC , much to the relief of the VDG chip designers . If you plan to use
the 64 x 64 F, the 1 28 x 64 T, or the 1 28 x 64 F, be sure to follow
the POKE sequences above in setting the proper modes. At the end of the
PMODE graphics we 'll investigate which addresses and bit
configurations set all modes so that you may utilize the forgotten modes
in your BASIC or assembly-language programming.
Also realize that in the examples above, the area used for graphics
started at RAM location 1 024 , the text screen. In the Extended Color
BASIC implementation of the following modes , the text screen is left
intact, and the graphics screens (pages) start at location 1 536.
PMODE 0
-
1 28
x
96 T
This mode is a two-color mode that displays graphics in a 1 28 by 96
matrix. The number of bits required is 1 28 by 96 by 1 (two colors) or
1 2 ,288, which is 1 536 bytes. The mapping for this mode is shown in
Figure 2 . 9 .
ROW 1
ROW
j
2
R O W 96
FIRST
BYTE 1
2
NEXT
3
NEXT
16
LAST
17
F IRST
1536
LAST
COLOR SET 0
BLACK
* GR E E N
C
0
1
PMODE 0 mapping.
E L E M E N T S OF R O W 1
E L E M E N T S OF ROW 1
ELEMENTS O F ROW 2
E L E M E N T S OF R O W 9 6
COLOR SET J
B L AC K
* BU F F
* = BO R D E R C O L O R
Figure 2.9:
888
88
8
True Graphics Modes
43
" PMODE O,start-page" sets this mode. After this command has
been executed in a BASIC program , all graphics will be referenced to a
1 28 by 96 matrix . Standard colors of black and green (green border) and
black and buff (buff border) are used and selected by the color set
parameter in the SCREEN command.
PMODE 1 - 1 28
x
96 F
This mode is a four-color mode that displays graphics in a 1 28 by 96
matrix. The number of bits required is 1 28 by 96 by 2 (four colors) or
24 ,576, which is 3072 bytes . The mapping for this mode is shown in
Figure 2. 1 0 .
ROWROW 12
+ 12a-!
ROWj
FIRST ELEMENTS OF ROW
BYTE 1 C 1Co C1Co C1Co C1Co NEXT
NEXT 4
3
LAST
4 ELEMENTS
OFOF ROWROW 12
FI
R
ST
ELEMENTS
3332 I
I
3072 C 1Co c1co C1Co C1Co LAST ELEMENTS OF ROW
*GREEN
0001 *BUFF
CYAN
YELLOW
10
BLUE
ORANGE
RED * =BORDER11 COLORMAGENTA
96
96
4
1
4
4
4
COLOR SET 0
Figure 2 . 10:
PMODE
I
C1 Co
COLOR
96
SET
1
mapping.
" PMODE 1 ,start-page" sets this mode . After this command has
been executed in a BASIC program , all graphics will be referenced to a
1 28 by 96 matri x . Standard colors of green , yellow , blue, and red (green
border) and buff, cyan, magenta, and orange (buff border) are used and
selected by the color set parameter in the SCREEN command .
44
PMODE 2 - 1 28
x
1 92 T
This is a two-color mode that displays graphics in a 1 28 by 1 92
matrix . The number of bits required is 1 28 by 1 92 by 1 (two colors) or
24 ,576, which is 3072 bytes. The mapping for this mode is shown in
Figure 2 . 1 1 .
2
ROW l
ROW
+12s 192
j 192
i
ROW
1'1' 1'1'1'1'1'1'1
1617 I 1 1 1 1 1 1 1 I
23
BYTE l
3072 tc Jc Jc jc j cj cjc Jcf
COLOR
C
SET 0
0
BLACK
* GREEN
F I R S T 8 ELEMENTS OF ROW
NEXT 8
1
NEXT 8
2
192
L A ST 8 E L E M E N TS OF R O W l
F I R S T 8 E L E M E N T S OF
ROW
L A S T 8 E L E M E N T S OF R OW
COL OR SET 1
l
BLACK
* BUFF
* : BO R D E R COLOR
Figure 2 . 1 1 :
PMODE 2 mapping.
" PMODE 2 ,start-page" sets this mode . After this command has
been executed in a BASIC program, all graphics will be referenced to a
1 2 8 by 1 92 matrix. Standard colors of black and green (green border) and
black and buff (buff border) are used and selected by the color set
parameter in the SCREEN command.
PMODE 3 - 1 28
x
1 92 F
This mode is a four-color mode that displays graphics in a 1 28 by
1 92 matrix. The number of bits required is 1 28 by 1 92 by 2 (four colors)
or 49 , 1 52 , which is 6 1 44 bytes. The mapping for this mode is shown in
Figure 2 . 1 2 .
True Graphics Modes
+
45
ROWROW 1
2
ROWj
BYTE C 1 Co CjCQ C1 Co C1Co NEXT
FIRST ELEMENTS OF ROW 1
NEXT
LAST
FIRST ELEMENTS
ELEMENTS OFOF ROWROW1
C1 Co C1Co C1Co C1Co LAST ELEMENTS OF ROW
*GREEN
0001 *BUFF
YELLOW
BLUE
MAGENTA
RED * =BORDER1110 COLORCYAN
ORANGE
1 2 8 -+
1 92
�
192
1
2
3
4
4
4
32
33
4
4
2
614 4
4
192
COLOR SET
Figure 2.12:
0
C1 Co
COLOR SET 1
PMODE 3 mapping.
" PMODE 3 ,start-page" sets this mode. After this command has
been executed in a BASIC program , all graphics will be referenced to a
1 28 by 1 92 matrix. Standard colors of green , yellow, blue , and red
(green border) and buff, cyan , magenta, and orange (buff border) are
used and selected by the color set parameter in the SCREEN command .
PMODE 4 - 256
x
1 92 T
This is the highest resolution mode, horizontally. (The semigraphics
24 mode has the same vertical resolution of 1 92 elements , but allows
only 64 elements horizontally . )
This mode i s a two-color mode that displays graphics i n a 256 by
1 92 matrix . The number of bits required is 256 by 1 92 by I (four colors)
or 49 1 52 , which is 6, 1 44 bytes . The mapping for this mode is shown in
Figure 2 . 1 3 .
" PMODE 4 ,start-page" sets this mode . After this command has
been executed in a BASIC program , all graphics will be referenced to a
256 by 1 92 matrix. Standard colors of black and green (green border) and
black and buff (buff border) are used and selected by the color set
parameter in the SCREEN command.
46
+256
192
l
BYTE
1
::
lTITITITl
]1I I I I I II
6144
12
ROW
192
F I R ST
8
N E XT
8
NEXT
8
E L E M E N T S OF R OW
1
L AS T 8
E L E M E NTS OF ROW
F I RST 8
E L E M E N TS OF ROW
12
8
E L E M E N T S OF R O W
LAST
COL O R S E T 0
BLACK
* GR E E N
Figure 2.13:
ROW
ROW
c
0
*
COLOR SE T 1
192
BLAC K
* BUFF
' B ORDER
C O LOR
PMODE 4 mapping.
USING THE PMODE GRAPHICS MODES
Because the five modes above are supported in Extended Color
BASIC by the PMODE command , and because its graphics capabilities
are excellent, you will probably want them utilized by the standard
Extended Color BASIC graphics commands. All of the modes, however,
are selectable by POKEs, providing that the video memory area has been
set up with the correct data for display.
The following BASIC program illustrates how POKEs can be used
to set up the resolutions for PMODES 0 through 4. A single line is drawn
across the center of the screen for each of the modes . The screen starts at
location 1 024 instead of the normal location 1 536 for graphics.
True Graphics Modes
1
1
1
1
1
00
10
20
30
40
1 50
1 60
1 70
1 80
1 90
200
210
220
230
240
250
260
270
47
REM P R O G R A M TD SET ALL P M O D E S
P C L E A R LI
I N PUT PM
I F P M < 0 O R P M > ll G O T O 1 2 0
I F ( PM = 0 OR P M = 2 l THEN BR= 1 6 ELSE
BR=32
I F P M > l T H E N M R = 9 6 E L S E M R = ll 8
D I = MR*BR
I F ( PM AND 1 l =0 THEN VA=0 ELSE V A = 255
P I = ( PM+3 l * 1 6+ 1 28
V D = P M + 3 : I F P M = ll T H E N V D = V D - 1
I F ( V D A N D ll l = ll T H E N P O K E & H F F C 5 1 1
E L S E P O K E & H F F C Ll 1 0
I F ( VD AND 2 l =2 THEN POKE &HFFC3 1 1
ELSE POKE &HFFC2 1 0
I F ( I.J D A N D 1 ) = 1 T H E N P O K E &: H F F C 1 , 1
ELSE POKE &HFFC0 1 0
A = ( PEEK ( &HFF22 l A N D 7 )
POKE &HFF22 1 P I +A
F O R V M = 1 0 2 ll T O 1 0 2 ll + M R * B R * 2 - 1
I F V A = 0 THEN P O K E VM 1 2 55 E L S E P O K E
1.J M 1 0
N E :< T 1.J M
2 8 0 F O R V M = 1 0 2 ll + D I
2 9 0 P 0 K E 1.J M , 1.J A
3 0 0 N E :< T I.J M
3 1 0 GOTO 3 1 0
TO
1 0 2 ll + D I + B R = 1
The first active statement clears 4 screen pages of 1 536 bytes each.
The next statement INPUTs a PM ODE value of 0 through 4. A check is
then made of the PM ODE value; if it is other than 0 through 4, the
INPUT statement is executed again.
Variable BR is the number of bytes per row. The number per row is
1 6 for a 1 28 horizontal two-color mode ( 128 X I / 1 6) and 32 for a 1 28
horizontal four-color mode ( 1 28 X 2/ 8) or a 256 horizontal two-color
mode (256 X I / 8).
If PM is greater than I, the number of the middle row (variable MR )
is 96; otherwise it is 48. The displacement in bytes from the start of the
video memory is in variable DI and is equal to BR X M R.
Even-numbered P M ODEs in PM will cause ( PM A N D I ) to be
equal to zero. Even-numbered PMODEs are two-color modes. The value
stored in all two-color modes will be 0, which creates black on a border
of green. The value of four-color modes will be 255 representing
1 1 1 1 1 1 1 1 for red codes per byte; the display here will be red on a green
48
border. The v alue to be stored is held in VA.
VD is the value to be sent to the VDG in address
&HFFC5-&HFFCO (65472-65476) . Pl is the value to be sent to address
&HFF22 (653 1 4 ) . The coding for these values is shown in Figure 2 . 1 4 .
PM
MOOE INPUT
PM
MOOE INPUT
BR
B Y TES/ROW
MR
MIOOL E ROW
01
MR OISPL
16
•8
768
32
'8
153 6
16
96
1 53 6
32
96
3072
32
96
3072
VA
VA L UE
Pl
fM00£i
0
176
I
0
I
I
255
192
I
I
0
0
208
I
I
0
22•
I
I
I
2'0
I
I
I
I
255
0
0
0
I
0
0
0
0
0
0
0
0
0
0
0
0
0
�
DE T E R M I N E S
MODE
VO
fMOOCI
8HFFCI, 1
8HFFCO , 0
S HF F C J ,
1
1
8 HF F C 2 , 0
8 HF F CS,
8 H F FC 4 , 0
Figure 2.14:
POK E i ng graphics mu<lcs example.
The VDG value is output in statements 200 through 220. The Pl
value is merged into address &HFF22 in statements 230 and 240 .
The first FOR VM = loop clears the video memory to be used to the
border color, green. The end of the video memory is given by
1024 + MR x BR X 2- 1 . The second FOR VM = loop outputs the value
to the middle row; the length of this row is BR.
VIDEO M EMORY PAGES
We saw from the last chapter and this chapter that the minimum
amount of video memory used is 5 1 2 bytes. This minimum allocation
occurs in the alphanumeric and some semigraphics modes. The maximum
video memory used in one display is 6 1 44 bytes . This occurs in the
high-resolution semigraphics and graphics modes .
Color BASIC allocates 5 1 2 bytes for video memory. This area is the
normal text screen. Extended Color BASIC automatically allocates 6 1 44
bytes above the text screen starting at location 1 536. Whenever you are
working in high-resolution graphics you must be certain that you have
0
0
0
0
0
True Graphics Modes
49
allocated enough memory. This is done in Extended Color BASIC by the
PCLEAR command, which has the format
PCLEAR
n
where n is the number of graphics pages to be reserved .
A graphics page is equal to 1 536 bytes, the number of bytes required
for the PMODE 0, the lowest resolution graphics mode. Up to 8 graphics
pages can be reserved , a total of 1 2 ,288 bytes . Note that a graphics page
is not related to a normal memory page for the 6809 microprocessor,
which is 256 bytes . The graphics page is somewhat arbitrarily set at the
PMODE 0 video memory requirement.
More than one display ' s worth of video memory is allocated because
the start of the display area may be changed from the normal location of
1 536 to any of the other 8 video pages . The normal method for doing this
is Extended BASIC ' s PMODE command , in which the start-page
parameter defines the starting point for the video display .
P M 0 0 E mode t start-page
Table 2 . 3 shows the starting addresses for the different values of
start-page in Extended Color BASIC . The ending address depends upon
the current PMODE setting, which may be as much as 6 1 44 bytes beyond
the start.
In fact, it' s possible to change the start of video memory to any
location of the 65 ,536 locations in RAM/ROM memory. You would
Start-Page
1
2
3
4
5
6
7
8
Table 2.3:
Start-Page Values .
Starting Location
(Hex.)
(Dec.)
1 536
3072
4608
6 1 44
7680
921 6
1 0,752
1 2,288
0600
ocoo
1 200
1 800
1 EOO
2400
2AOO
3000
50
normally not want to do this while working within the confines of
Extended Color BASIC , but you may want to do it in assembly-language
programs or advanced BASIC applications.
The method for doing this is to address the VDG by a series of
POKEs. Seven POKES are done to set 7 bits in the VDG . Seven bits
represents 0 through 1 28 (0000000 through 1 1 1 1 1 1 1 ) . Each i ncrement
represents an area of 5 1 2 bytes . For example, specifying 0 1 00000 for the
7 bits would set the start of video memory to 32 x 5 1 2 or 1 6 , 384. This
scheme is shown in Figure 2 . 1 5 .
Bl T
F F D3
FFD2
POKE
POKE
OR 0 S E T S B I T 6
OR 0 R ES E T S B I T 6
FFDl
F FD 0
POKE
POKE
OR 0 S E T S B I T 5
OR 0 R E S E T S B I T 5
F FC F
FFCE
POKE
POKE
OR 0 S E T S B I T 4
OR 0 R E S E T S B I T 4
F FCD
FFCC
POKE
P O KE
OR 0 S E T S B I T 3
OR 0 R E S E T S B I T 3
FFCB
FFCA
P O KE
POKE
OR 0 S E T S B I T 2
OR 0 R E S E T S B I T 2
FFC9
F FC B
P OKE
POKE
OR 0 SETS B I T l
OR 0 R E S E T S B I T l
F FC 7
F F C6
POKE
POKE
OR 0 SE T S B I T 0
OR 0 R E SETS B I T 0
x
x
x
x
6
5
4
3
0
0
0
0
0
0
0
0 * 51 2 • 0
0
0
0
0
0
0
l
1 * 512 • 51 2
0
0
0
0
0
0
0
0
0
0
0
2 * 512 • 1 024
3 * 5 1 2 • 1 536
I
x
0
S T A R T O F D I S P LAY
I
I
0
0
l
l
l
l
0
•
1 2 6 * 51 2 • 64. 512
1 2 7 * 5 1 2 ' 6 5,024
T H I S V A L U E * 5 1 2 ' ST A R T
O F D IS P LAY A R E A I N M E M ORY
F F D 3 ' 65 , 4 9 1
F F C C ' 65 , 484
D2 ' 65, 490
CB , 65, 483
D l ' 65, 4 8 9
CA ' 6 5, 4 8 2
DO , 65, 488
C 9 ' 65 , 4 8 1
C F ' 65,487
ca , 65, 4 a o
C E ' 65, 486
C 7 • 65, 4 7 9
CD , 65, 485
C 6 , 65, 4 7 8
Figure 2 . 1 5 :
Modifying the video memory start.
True Graphics Modes
51
T o set the 7-bit value, address the V D G locations shown in Figure
2 . 1 5 . Seven total locations must be addressed by a POKE XXXX, 1 or
POKE XXXX ,O. We ' ve used a POKE XXXX , 1 to set a bit, and a POKE
XXXX ,O to reset a bit so that it would be more apparent whether a set or
reset was being performed. To set the start of video memory at location
0, the start of RAM, execute
1 00 POKE
1 1 0 POKE
1 20 P O K E
1 30 POKE
140 GOTO
B: H F F D 2
B: H F F C E
B: H F F C A
B: H F F C G
140
10
10
10
10
P O K E B: H F F D 0 1 0
P O K E B: H F F C C 1 0
P O K E B: H F F C B 1 0
This example is shown in Figure 2 . 1 6 .
8HFFD2, 0
- o
BIT 6
POKE
5
POKE
4
POKE
8 HFFCE, 0 - o
3
POKE
S H F FC O, 0 - o
2
POKE
l
POKE
0
POKE
Figure 2 . 16:
S H FFDO, 0 - o
S H F FC A , 0
8 HFFC8, 0
-
o
0 0 0 0 0 0 0 , 0 * 51 2 • 0 , START OF
D I S P L AY
IN M E M O R Y
- o
8 H FF C 6 , 0 - o
Modifying video memory start example.
If you do this, you will see the working storage of the BASIC
interpreter. Because the values are a mix of alphanumerics and
semigraphics, you will see some characters and some graphics. If you set
this value and then run a BASIC program, you will see variables
changing dynamically during execution of the program .
THE MYSTIFYING G RAPHICS ORACLE
We' ve covered a lot of ground in these two chapters. To help
present a synopsis of everything we' ve learned, Appendix IV shows all
of the graphics modes , their video and memory formats, color sets,
B ASIC support, and POKE sequences . In the following chapters we ' ll be
exploring the B ASIC and Extended BASIC commands and occasionally
referring to the material presented in this chapter. Don ' t feel obligated to
memorize the information already presented, but use it as a guide when
you get confused in the following material .
c>
<!£1)_:
.
0
=
v�
0
.·.
Color BASIC Graphics Capabilities
53
CHAPTER 3
Color BASIC Graphics Capabilities
This chapter is for those users who have not upgraded to Extended Color
BASIC . The built-in graphics commands for Extended Color BASIC are
excellent - using them you can draw straight lines , circles, ellipses,
rectangles, and odd-shaped figures , not to mention painting areas with
colors and other graphics-oriented operations . Reproducing the same
capabilities for Color B ASIC would require an assembly-language
program of moderate size and complexity. A BASIC program driver
might conceivably add some of the features but would be very slow in
comparison to Extended Color BASIC.
Our best advice to a user seriously interested in color graphics is to
add Extended Color BASIC . (Let ' s see, 1 0 percent of every Extended
Color BASIC upgrade kit purchased is . . . ) In the meantime, we'll
describe the graphics available in the Color BASIC and show you how to
implement some color graphics capabilities .
COLOR BASIC COLOR CAPABILITY
There are 4 Color BASIC commands related to graphics: CLS , SET,
RESET, and POINT. CLS clears the screen to one of eight colors . SET
and RESET operate on a graphics point. The POINT command returns
the value of a graphics point.
The graphics mode used for all commands is the semigraphics 4
mode described in the first chapter. If you will be using these commands
and haven't read the first chapter, you may want to read the chapter now
54
and pay particular attention to this semigraphics mode. We 'll provide a
refresher course in the following, though.
The semigraphics 4 mode operates on a display of 64 horizontal
elements by 32 vertical elements, as shown in Figure 3 . 1 . The basic
screen is 256 pixels (picture elements) wide and 1 92 pixels high . This
means that every element in this mode is 4 pixels wide by 6 pixels high,
as shown in the figure. As every pixel is roughly square, we're
displaying an element that is a rectangle higher than it is wide.
------ 256
32
P I X E L S ------
192
I
VERT ICAL
PIXELS
ELEMENTS
---/- 6 4
Figure 3 . 1 :
H O R I Z O N TA L
E L E M E N T S ----
Color BASIC graphic screen format.
The semigraphics 4 mode uses 5 1 2 bytes o f video memory for each
display of 64 elements by 32 elements. The mapping for the display is
shown in Figure 3 . 2 . The normal location of video memory is in RAM
location 1 024 and continues through memory location 1 53 5 .
Each byte of memory controls four elements o n the screen , as shown
in Figure 3 . 2 . The four elements are subdivisions of an alphabetic
character position. If text is on the screen a single alphabetic character
will be displayed in the character position.
Color BASIC Graphics Capabilities
N
A
�
C
D
(
55
D I S P L AY L I N E I
L
1024
1025
1026
N
1 02 7
E
1028
1029
1030
A
1031
�
1032
1033
1034
+
.....
(SE M I G R A P H I C 4 DATA)
c
D
5 1 2 B Y T E S TOTAL
Figure 3.2:
Color BASIC graphic mapping.
A byte has 8 bits (binary digits) , each of which is a one or a zero.
An on condition is represented by a one , while an off condition is
represented by a zero.
If the first bit of any byte in video memory is a zero, the byte
represents an alphabetic character. The next bit of an alphabetic character
defines whether the character is inverted , i . e . , black on a green
background or red on an orange background. The remaining 6 bits of the
character are the code for the character. Codes for Color Computer
characters are shown in Tables l . 2 and l . 3 .
I f the first bit o f any byte in video memory is not a zero , but a one ,
the byte represents a graphics character. In this case , the format for the
byte is as shown in Figure 3 . 3 .
The next 3 bits after the first bit define the color. The bits may be
000 , 00 1 , 0 1 0, 0 1 1 , 100, 1 0 1 , 1 1 0 , or 1 1 1 , representing colors of green ,
yellow, blue, red , buff, cyan, magenta, or orange . This will be the color
of each of the 4 elements in the character position, providing each is
turned on . The background or border color for this mode is always black .
If an element is turned off, black will appear.
The next 4 bits define the on/off state of each of the 4 elements . A
one is on , while a zero is off. Note that the four elements must have the
same color, defined by the 3 color bits .
56
7 6 5 4 3 2 1 0
i 1 ic2lc 1 lc olL3 IL 2IL 1 !Loi {SEMIGRAPHIC 4 BYTE)
..._____,
COLOR
FIELD
GREEN 000
YELLOW 001
BLUE 010
RED 0 1 1
BUFF 100
CYAN 101
MAGENTA 1 1 0
ORANGE 1 1 1
Figure 3.3:
ELEMENT
ON/OFF
STATUS
Graphic character format .
CLS COMMAND
The format for the CLS (clear screen) command is
CLS
(cl
where c is a color code of 0 through 8, representing the colors shown in
Table 3 . 1 .
CLS (c)
(c)
0
1
2
3
4
5
6
7
8
Color
Black
*Green
Yellow
Blue
Red
Buff
Cyan
Magenta
Orange
*Default if (c) omitted
Table 3 . 1 :
CLS Colors .
Color BASIC Graphics Capabilities
57
The CLS command simply clears the 5 1 2 bytes of video memory to
the specified color by setting the 3 color bits (it subtracts one from the c
value) , and turning on the 4 on/off bits . The exception for this is a c
value of black, which simply turns off all on/off bits . To see how this
works , run the following program . It will display the value of all video
memory bits in the center of the screen, preceded by the video memory
location .
1 00 REM D I S PLAY CLS FUNCT I ON ACT I ON
1 1 0 I NPUT A
1 20 C LS ( A l
1 30 FOR I = 1 024 TO 1 024+5 1 1
1 40 PR I NT @ 256+ 1 0 , I ; PEEK ( I l ;
1 5 0 N E >( T I
A CLS value of 4 produces the display shown in Figure 3 . 4 , with
the indicated breakdown of the value .
VI D EO MEMORY LOCATI O N
Figure 3.4:
CLS example.
The color to which the screen has been cleared remains in force even
when a return is made to the Color BASIC interpreter. As more text is
entered, however, the screen is reset to the alphanumeric black on green
for the character positions. Pressing the (CLEAR) key or executing a C L S
without any argument will also reset the screen to a standard green
58
background. This background is not the semigraphics mode background
but rather the alphanumerics mode; each byte in video memory has a 96
code for a space rather than a 143 code for a green color with all
elements on.
The CLS takes approximately 1 / 1 00 second, making it very fast
indeed, much faster than any BASIC FOR . . . NEXT loop could be .
SET, RESET COMMANDS
The formats of the SET and RESET commands are
SET ( h 1v 1c)
RESET (h 1v)
The h is a value specifying the horizontal element number from 0
through 63 . The v is a value specifying the vertical element number from
0 through 3 1 . The c is a color code that is the same as the CLS
command .
The SET , of course, sets the element specified to the color specified;
the RESET resets the element to the background color, or black. This
produces some unexpected results . Look at Figure 3 . 5 . The screen is first
cleared to blue by a CLS(3). Next, the approximate center dot is set to
red by S ET(3 1 , 1 6 ,4) . What should the result be? A red dot in the center
of a blue screen? Wrong ! The CLS turns on all four of the elements. The
SET changes the color of one element. In doing so, it puts the red color
code in the video memory byte for 3 1 , 1 6 . However, this is also the video
memory byte for 30, 1 6; 30, 1 7 ; and 3 1 , 1 7 . Since these elements are on by
the action of the CLS , changing the color for the SET changes the color
for all four elements !
A following RESET turns off the 3 1 , 1 6 element by resetting the bit
for that element to 0. A black element results !
Because of this implementation, you must work with a color on a
black background if you are using SET/RESET and if you want the
maximum resolution of 64 by 32 elements. If you work with one color on
another color background, you will be working with a resolution of 32 by
1 6 elements . An alternative to this is working with a higher resolution
semigraphics mode; we'll discuss this option shortly.
Color BASIC Graphics Capabilities
I
I
I
BLUE
I
I
BLUE
I
I
I
I
I
BLUE
I1
I
I
I
BLUE
R O W 30, C O L U M N 16
BLUE
BLUE
BLUE
BLUE
R O W 3 0 , COLUM N
ROW 3 1 , C O L U M N 1 6
BLUE
B L UE
B LU E
B L UE
ROW 31, C O L U M N
I
I
B LUE
I
BLUE
I
I
I
I
BLUE
I
I
I
I
1
0
0
17
17
BLUE
I
I
I I I I I I1I I I
1
59
1
1
1
BYTE A F T E R C L S
�
(3 l
ALL 4
E L E M E NTS
ON
BLUE
-- B LU E _.
i
RED
BLUE
i
T H I S E LE ME N TT U R N E D ON
T H E S E E L E M E N T S WERE O N
I N I T I A L LY, NOW A R E RED
t
-:
BLUE
ED
!
- B L U E -+
I1I I I I I I I
0
Figure
3.5:
1
1
1
1
1
1
BYTE AFTER SET
(31,
16,
4)
SET/RESET example.
Speed of SET/RESET
The SET/RESET commands execute at about 4 . 2 milliseconds
(4 . 2/ 1 000 second) per point. It takes about 8 seconds to SET 2048 points ,
not counting the overhead of a loop.
POINT COMMAND
The format of the POINT command is
PO I NT
C h tv)
60
The h value is the horizontal element number of 0 through 63; the
is the vertical element number of 0 through 3 1 . The POINT command
tests the element specified . One of three conditions may be present:
v
• The character position may be in the text, or alphanumeric
mode. In this case, POINT returns a - 1 .
• The element may be set to a color. In this case, POINT returns
the color code of 1 through 8 .
• The element may be reset (black) . I n this case, POINT
returns a 0.
To see how this works, look at the following example.
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
REM SAMPLE USE OF P O I NT
CLS ( 1 l
P R I N T @ 2 5 6 1 " T E >( T " i
SET ( 0 t 1 8 1 3 l
RESET ( 1 1 1 8 l
A = PO I NT ( 0 1 1 6 )
B = P O I NT ( 0 1 1 8 l
C = P O I NT ( 1 t 1 8 l
PR I NT @ 320 1 A i B i C i
This first clears the screen to a green background . The " ( 1 ) " in the
CLS statement isn't strictly necessary , as this is the default color. Next , a
PRINT @ 256 of "TEXT" is done. This sets the 256th , 257th , 258th,
and 259th bytes of the video memory (locations 1 536 through 1 539) to
the alphanumeric characters "TEXT" . Next, a SET (0 , 1 8 ,3) is done to
SET the next element below the ' 'T ' ' to blue . This is followed by a
RESET of ( l , 1 8) . The situation in video memory is now as shown in
Figure 3 . 6.
The POINT command is then used to test (0,32), (0, 34), and ( 1 , 34) .
The element at (0,32) is the part of the alphanumeric character ' 'T' ' . The
entire byte for this text character is in the text format, and a - 1 is returned
as variable A . The element at (0,34) is the upper left element of the
character position below the "T" . It has been SET to 3 , or blue , and this
value is returned in variable B. The element at ( 1 ,34) is the upper right
element of the character position below the ' 'T' ' . It has been RESET to
black, and a 0 is returned as variable C .
I s the POINT command useful? Not very . (Oh , o h . I expect
thousands of letters here , informing me of a myriad of applications for
POINT . . . ) It is one of those BASIC commands included in the BASIC
lexicon which can occasionally be used but will probably never appear in
Color BASIC Graphics Capabilities
CHARACTER
POS I T I O N
0
1
2
3
61
4
COLUMN
LINE
ROW 1 4
I
till
�
15
16
8
17
18
9
19
.,
.
256
I
0
0
I
0
I
0
BLACK
BLUE
GREEN
T"
0
"
"E"
257
0
I
0
0
0
I
0
I
2 58
0
I
0
I
0
0
0
2 59
0
I
0
I
I
0
I
0
0
"
260
I
0
0
0
I
I
I
GREEN
2 88
I
0
I
0
I
0
1
1
B LU E / BL A C K
289
1
0
0
0
1
1
1
Figure 3 . 6 :
I
I1
I
"x"
T"
G RE E N
POINT example.
most BASIC programs. It could be used to test the on/off status of an
element prior to RESETting a point, example. This would avoid having
to store a table of values that have been SET and must be RESET before
new graphics are displayed .
The POINT command takes the same amount of time to execute as
the SET, about 4 . 2 milliseconds .
TYPICAL USES OF SET/RESET
Because of the low resolution, SET/RESET is useful for such things
as bar graphs using several colors, plots that use a black background, or
crude figures with possible animation .
The program below plots a bar graph of up to eight values, as shown
in Figure 3 . 7. The background of the graph is green, the axes of the
graph are blac k , and the bars on the graph are alternating colors .
62
1 00 REM BAR GRAPH PLOT
1 1 0 CLS
1 20 I = 0 : A ( 8 ) = - 1
1 3 0 P R I N T 11 I N P U T 8 t.J A L U E S F R O M 0 T D
E N D I N G W I T H - 1 11
1 40
1 50
1 60
1 70
1 80
1 80
200
210
220
230
240
250
260
270
280
280
300
310
320
330
340
350
360
370
380
380
400
410
420
430
I N PUT A < I >
I F A < I ) = - 1 GOTO 1 80
I = I + l : I F I = 8 GOTO 1 8 0
GOTO 1 40
CLS < 1 )
J = 1 00
F O R I = 6 4 T D 64+32* 1 0 S T E P 32
PR I NT @ I 1 J i
J=J-10
N E )< T I
PR I NT @ 422 '
1 2 3 4 5 6 7 8
F D R Y = 4 TD 2 5
II
1 00
II
RESET < 10 , y )
N D( T Y
F O R }( = 1 1 T D 4 5
R E S E T < }( 1 2 5 )
N D( T }(
C=2
F O R I =0 TD 8
B=A < I )
I F B = - 1 THEN GOTO 430
I F B < 0 THEN 5 = 0
I F 5 > 1 00 THEN 5 = 1 00
B = B / 5 : I F 5 = 0 GOTO 420
FOR Y = 24 TD 2 4 - B STEP - 2
SET < I *4+ 1 2 1Y 1C )
N E >( T Y
C = C + l : I F C = 8 THEN C = 2
N E >( T I
GOTO 430
This program can be divided into several parts, as shown i n Figure
3 . 8 . The statements from 1 00 through 1 70 input 8 values into a
nine-element array , A . The last element of this array always holds a - 1 as
a terminating value. Entering a - 1 at any time terminates the input. At
that point the A array may be filled with 0 to 8 values .
Color BASIC Graphics Capabilities
JOO
0
UJ
a:
90
80
LL
LL
::J
CD
70
60
50
3
40
30
z
<t
>u
UJ
::J
_J
CD
3
0
_J
_J
<t UJ UJ
f- <.'.) >z z
<t
a:
0
GREEN
BORDER
20
10
0
2
3
4
5
6
7
8
1 00 REM BAR GRAPH PLOT
1 1 0 CLS
1 20 ! = 0 : A 1 8 1 = - 1
1 3 0 P R I N T " I N P U T 8 <.• A L U E S F R O M
0 TD 1 00 END I NG W I T H - 1 "
1 a 0 I N PUT A I I I
1 5 0 I F A I I I = - t GOTO 1 80
1 60 I = I + 1 : I F ! = 8 GOTO 1 8 0
1 70 GOTO 1 a 0
1 80 CLS I t I
1 80 J = 1 0 0
2 0 0 F O R ! = G a T O G ll + 3 2 * 1 0 S T E P 3 2
2 1 0 PRINT @ I ,J I
220 J = J - 1 0
230 NEXT I
P R I NT
@
Ll 2 2
1 11
1 2 3 a 5 G 7 8"
250 FOR Y=a TO 2 5
260 RESET 1 1 0 , y I
270 NEXT y
2 8 0 F O R ) ( = t 1 TO a s
2 9 0 R E S E T ( )-{ 1 2 5 )
300 NEXT x
3 1 0 C=2
320 F O R ! = 0 TD 8
330 B=A I I I
3a0 I F B = - 1 THEN GOTO a30
350 I F 6 < 0 THEN B = 0
360 I F B > 1 0 0 THEN B = 1 00
370 B = B / 5 : I F B = 0 THEN GOTO az0
3 8 0 F O R Y = Z ll T O 2 a - B S T E P - 2
3 9 0 S E T < l * ll + 1 2 , y , C )
a00 NEXT y
a 1 0 C = C + l : I F C = 8 THEN C = 2
a z 0 N E >: T I
a30 GOTO a30
Figure 3.8:
AXES
Bar graph example.
Figure 3.7:
2a0
- B L AC K
Bar graph program structure.
Input
0-8
values
to
l
l
}
}
A( )
Display
""1 00,90 ...
1 0.0··
Print
X
coordinate
values
Plot
Y axis
Plot
X axis
Display
bars
63
64
The statements from 1 80 through 230 display the Y coordinate
values of ' ' 1 00 , 90 , . . . , I 0, O' ' . The X coordinate values are simply
PRINTed with the statement at 240.
The Y axis is plotted by statements 250 through 270. The CLS( l ) in
statement 1 80 cleared the screen by storing semigraphics characters .
RESETting the points will tum off the left-hand elements in each
character position, producing a black color. The X axis is plotted in
statements 280 through 300, also producing a black background.
Statements 3 1 0 through 420 display the values as bars on the graph.
The color codes for the SET are held in variable C . Colors from 2
through 8 will be displayed. ( 1 is green , and this will not show up . ) For
each of eight values , the value is obtained from the array (330), checked
for validity and changed to a limit value if necessary (340 through 360) ,
and then scaled .
Since there are 1 0 character positions or 20 vertical elements
involved, each element represents a unit of five: 0, 5 , 1 0 , . . . , 1 00 . The
value is divided by five to give the number of elements involved. This
number may be a fractional value, but the SET/RESET command looks
only at the integer value and discards the fraction. The bar is drawn by
plotting from Y 24 (bottom) to (25-value/5) in steps of -2 . This means
that the bar will be drawn from top to bottom .
The SET sets the current Y value. In doing so, it actually sets four
values as it changes the color code in the byte from green to another
color. STEPping in units of -2 avoids duplicating the SET for the next
higher element and the problems of blacking out an element discussed
earlier. Although the numeric resolution is within 5 units, the graphics
resolution is within 1 0 units, or one character position, because of the
black out problem.
For each value, the X coordinate is I x 4 + 1 2 , producing columns
at 1 2 , 1 6, 20 , and so forth. These correspond to the label placement
under the X axi s .
Each time a bar i s drawn, the color code i s changed (4 1 0) to a code
of 2 through 8 . The plotting stops when the next value from the array is
- 1 , or when 8 values have been processed.
=
INTERMIXING ALPHANUMERICS AND GRAPHICS
The above plot shows how easy it is to mix alphanumerics and
graphics characters . Simply be aware of the fact that there are four
semigraphics elements in each alphanumeric character position and avoid
overwriting of text.
Color BASIC Graphics Capabilities
65
TREATING G RAPHICS AS CHARACTER STRINGS
The semigraphics 4 mode in SET/RESET may be used to advantage
in character string display . Each of the four elements for a graphics
character position is held in I byte in the semigraphics 4 mode. One byte
is used to hold one character's worth of data. We can exploit this fact and
treat a block of four graphics elements as a string character.
The reason for using character strings to generate graphics is that it
is fast ! To give you an idea how this method works and to show you how
speedy it can be, look at the following program:
1 00 REM GRA PH I CS CHARACTER STR I NG EXAMPLE
1 1 0 A $ = CHR$ ( 1 28 ) +CHR$ ( 1 28 ) +CHR$ ( 1 28 ) +
CHR$ ( 1 28 >
1 20 B $ = A$+A$+A$+A$+A$+A$+A$+A$
1 30 FOR I = 0 TO 1 5
l l'.1 0 P R I N T B $ i
1 5 0 N E >: T I
This program uses the CHR$ function. CHR$ creates a
one-character string with the value of the argument. It is used for those
arguments that are not valid ASCII character codes, but still legitimate
codes in the computer. Many of these codes cannot be generated from the
keyboard (there are no keys for them), and CHR$ is a way of handling
them in strings.
An A$ = CHR$( 1 28) generates a one-character string that is treated
like any other string. In place of an ASCII character, such as decimal 65
for " A " , however, is the code 1 2 8 .
Now in this case the code 1 28 represents a binary 1 0000000 . We
know from study of semigraphics that any character in video memory
with the first bit set is a semigraphics character. So it is with CHR$( 1 28) .
It is a semigraphics character with a color code of 000 (green) with the 4
bits for the elements off (black).
Statement 1 1 0 uses the concatenation (from Middle Latin
" concatena , " a stringed instrument - no, just kidding) feature of strings
to form a long string of four of these codes . Statement 1 20 concatenates
eight of these, making the total string of B$ equal to 32 codes of 1 28 .
The B$ string i s now PRINTed i n the next loop, just a s any other
text string would be. The result is that for each line, 32 bytes of l 28s are
stored in video memory (which is synonymous with being displayed),
just as 32 bytes of another text string would be stored and displayed .
The effect is to clear the screen with a black background . (The
display scrolls up as the last character of the last line is output . ) The
entire clear takes only about 112 second. (We know that CLS(O) can do it
66
much more rapidly, but this is just to give you an idea of the relative
speed of strings over SET/RESET. )
The program below utilizes graphics strings i n animation . The figure
drawn is a cylinder and piston of a two-stroke engine. It fires with a red
explosion and the piston moves up and down. Figure 3 . 9 shows the
display.
1 00
1 10
1 20
1 30
1 40
1 50
1 80
1 70
1 80
1 80
200
210
220
230
240
250
280
270
280
280
300
310
320
330
340
350
380
370
380
380
REM AN I MAT I ON US I NG CHR$ STR I NGS
CLS ( 1 )
A $ = CHR$ ( 1 75 )
5$= CHR$ ( 1 28 )
C $ = A$+A$+A$+A$+A$+A$
0 $ = A $ + 5 $ +5$+5$+5$+A$
E $ = C H R $ ( 2 23 )
F $ = E$+E$+E$+E$
G$= 5$+5$+5$+5$
H$ = CHR$ ( 1 8 1 )
I $ = H$+H$+H$+H$
PR I NT @ 205 1 C$ i
PR I NT @ 237 1 C$ i
F O R I = 28 8 T D 454 STEP 32
PR I NT @ I ' 0$
N E :n I
P R I NT @ 302 1 F$ i
PR I NT @ 270 d $ ;
F O R I = 0 T D 2 0 : N E :n I
FOR I = 302 T O 388 STEP 32
PR I NT @ I - 32 1G$ i
PR I NT @ I +32 1F$ i
FOR J = 0 TD 75 : NEXT J
N E :n I
FOR I = 388 TD 334 STEP -32
P R I NT @ I - 32 1 F $ i
P R I NT @ I +32 1 G$ i
FDR J = 0 TD 75 : NEXT J
NEXT I
GOTO 270
To see how these strings are set up, look at Figure 3 . 1 0 . The
cylinder shell is blue . The inside of the cylinder is black. The piston is
cyan . The explosion is red .
A blue color is represented by a semigraphics byte of 1 75 , a black
color by a byte of 1 2 8 , a cyan color by 223 , and a red color by 1 9 1 .
Color BASIC Graphics Capabilities
67
5
BLUE
BLUE
BLUE
BLACK
BLACK
CYAN
CYAN
BLACK
BLACK
RED
CYAN
BLACK
2
SEQ U E N C E : l,
BLU E
BLUE
BLACK
BLACK
2, 3, 4, 3, 2,
l.. ..
CYAN
BLACK
Figure 3.9:
CYAN
Animation example.
These are one-character strings A $ , B $ , E$ , and H$ , respectively.
The top 2 rows of the cyl inder are 6 bytes of 1 75 , held in C$. The
cylinder shell is a blue byte, 4 black bytes, and a blue byte, held in string
D$ .
Each piston row is 4 bytes of 223 , held by string E$. A row of black
is held in string G$. The explosion will occur over l row , and is held in
string 1 $ , which is 4 bytes of red.
The basic outline is set up by statements 2 J O through 250.
Statements 2 J O and 220 display the upper 2 rows , while statements 230
through 250 display the 6 rows for the cylinder shell .
Statement 260 displays the first row for the piston and statement 270
fires the cylinder by PRINTing 1$. Statements 270 through 390 are the
main loop for the program.
Each time through the loop the piston moves downward in 4 steps
for statements 290 through 330. As each step is made, the previous upper
row is erased by PRINTing a row of black. When the piston reaches the
last position, statements 340 through 380 move it upward in 4 steps ,
erasing the previous bottom row of the piston for each step. At the top of
the travel , statement 270 fires the cylinder again.
Timing loops at 320 and 370 create a delay for the animation effect.
68
tB
BLUE
BLUE
�
A$ . I 1 I 0 I 1 I 0 I 1 I 1 I 1 I 1 I ( CHR$ (175))
I
BLACK
B $ = I 1 I 0 I 0 I 0 I 0 I 0 I 0 I 0 I ( CHR$ ( 1 2 8) )
ALL OFF
C $ A$ + A$ + A$ + A$ + A$ + A$
�
•
1111111111111
BLUE
D $ = A$ + B$ + B$ + B$ + B$ + A$
II
II
CYAN
�
tB
II
II
CYAN
E$ • l 1 l 1 l o l 1 l 1 l 1 l 1 l 1 I < CHR $ < 22 3 l l
F$• E$ + E$ + E$ + E$
G
111111111
$ B$ + B$ + B$ + B$
-
CYAN
=
RED
�
BLACK
rn RED
rn
I $ • H$ + H$ + H$ + H$
111111111
Figure 3. 10:
RED
Animation example. strings.
Color BASIC Graphics Capabilities
69
OTHER M ETHODS FOR IMPLEMENTING
COLOR BASIC G RAPHICS
Besides the string method, there are two alternatives to
SET/RESET. These are the POKE method to change video display
memory/semigraphics modes and assembly language.
POKE Method
In the first two chapters, we discussed all of the graphics modes that
are available in the Color Computer. There are many more semigraphics
modes than the ones used in Color BASIC , and some of these permit 8
colors at resolutions of up to 64 horizontal by 1 92 vertical . In addition,
all of the true graphics modes are available, and these will permit high
resolutions of up to 1 28 by 1 92 . The only catch is that none of these are
implemented in Color B ASIC .
All of the modes, however, are available by setting the proper mode
via POKE statements as shown in Appendix IV. In addition, you must
POKE the proper data into video memory, and in some of the modes this
is quite involved .
Another problem is that some of the modes will be incompatible
with Color B AS IC as far as video memory mapping. Color BASIC
assumes a 5 1 2-byte video memory area, and many of the other modes
require a much larger memory area than this. One solution to this is to
change the location of the display memory, as described in the previous
chapter.
If the display area is changed to a high memory location (dependent
upon your RAM size and video memory required for the mode) and that
area protected by a CLEAR high memory parameter, then you can alter
this memory area with impunity.
It will still be a formidable job to POKE the proper data into video
memory, however. Even such a seemingly simple task as drawing a line
from point A to point B is not a trivial matter. Here again we must stress
that Extended Color B ASIC does all of this for you without the agony. (If
you like agony, perhaps I could persuade you to help me on the next
Color Computer book . )
Assembly Language
If you want high-speed graphics with Color BASIC and are clever at
programming, then perhaps 6809 assembly language is your best bet. Try
your hand with Radio Shack's Editor Assembler for the Color Computer.
Assembly language will certainly give you the speed for rapid
manipulation of graphics. The complexity is still there , however, in
spades , as assembly-language programming is another order of
magnitude more difficult than BASIC .
70
It is possible to combine the features of BASIC and machine
language by calling high-speed graphics subroutines using the USR cal l .
If you have a limited number o f graphics applications , perhaps you might
code the graphics routines in machine language (the output of assembly
language) and call them by USR calls.
In the next several chapters we'll describe the Extended BASIC
graphics commands, and perhaps we'll convince you that the power of
Extended BASIC is worth the cost.
NOTES
Color BASIC Graphics Capabilities
71
Extended Color BASIC: Initialization
73
CHAPTER 4
Extended Color BASIC : Initialization
In this chapter we ' l l talk about six of the twelve Extended Color BASIC
commands , in addition to discussing the general mapping of the Extended
Color BASIC graphics. The six commands are used to either initialize the
color graphics or as commands to change colors, screen location , or
graphics resolution. The six commands are
•
•
•
•
•
•
SCREEN
PCLEAR
PMODE
COLOR
PCLS
PCOPY
Select graphics or text screen
Reserve graphics pages
Set graphics resolution and page
Select foreground, background color
Clear graphics screen
Copy one graphics page to another
G RAPHICS MODES
We discussed the graphics modes in detail in Chapter 2. We ' l l give
a recap of that material here , for those who didn't want the detailed
explanations of Chapter 2 . (Always taking the easy way out , eh? You' d
make a good writer. )
There are 1 5 total alphanumerics, semigraphics, and graphics modes
built into the Color Computer by the video display generator (VDG) chip.
The VDG is a general-purpose semiconductor chip meant to provide
many types of color graphics. Some of its modes are more useful than
others.
74
Of the 1 5 modes , two provide a display of alphanumeric or text data
on the screen, five provide a display of semigraphics , and eight provide a
display of graphics .
The two alphanumeric modes are supported by the Color BASlC and
Extended Color BASIC .
One of the five semigraphics modes is supported in Color BASIC
and Extended Color BASIC - the semigraphics 4 mode that provides a
64-by-32 color display of eight colors on a black background. The
remaining semigraphics modes are available only by special
programming, either in BASIC or assembly language.
The eight graphics modes generally provide high-resolution graphics
at the expense of the number of colors available. The modes provide
either four or two colors, with resolutions from 64 by 64 to 256 by 1 92 .
The higher the resolution and greater the number o f colors , the more
video memory required . Five of the eight modes are supported by
Extended Color BASIC . Those modes are:
•
PMODE 0 : 1 28 horizontal
1 536 bytes of video memory
• PMODE 1 : 1 28 horizontal
3072 bytes of video memory
• PMODE 2 : 1 28 horizontal
3072 bytes of video memory
• PMODE 3 : 1 28 horizontal
6 1 44 bytes of video memory
• PMODE 4 : 256 horizontal
6 1 44 bytes of video memory
by 96 vertical in two colors and
by 96 vertical in four colors and
by 1 92 vertical in two colors and
by 1 92 vertical in four colors and
by 1 92 vertical in two colors and
COLOR SETS
Up to eight colors are available in the VDG - green , yellow , blue,
red, buff, cyan, magenta, and orange . In addition, black, the absence of
any color on the screen, is used.
In the graphics modes (PMODEs 0 through 4) , two or four colors
are available, depending upon the mode .
In the two-color mode (PMODE 0, 2 , or 4) the two colors are either
black and green on a green background, or black and buff on a buff
background. The choice of color set is selectable by the SCREEN
command.
If in the four-color mode (PMODE 1 or 3) the four colors are either
green, yellow, blue, and red on a green background, or buff, cyan,
magenta, and orange on a buff background. The choice of color set is
selectable by the SCREEN command.
The colors available for the 5 PMODEs are shown in Table 4 . 1 .
Extended Color BASIC: Initializa tion
75
Colors (Color Set O or Color Set 1 )
PMODE
black/green or black/buff
green, yellow, blue, red or buff, cyan, magenta, orange
black/green or black/buff
green, yellow, blue, red or buff, cyan, magenta, orange
black/green or black/buff
0
1
2
3
4
Table 4. 1 :
PMODE Colors .
M EMORY MAPPING FOR PMODES
The memory mapping for a Color Computer with Extended Color
BASIC is shown in Figure 4 . 1 . RAM occupies the first 1 6 , 384 bytes of
memory space from location 0 through 1 6 ,383 (or 32 ,767 on 32K
systems). RAM is used for storage of BASIC variables (working
storage), storage of the text screens , storage of the graphics pages, user
BASIC programs, BASIC program variables, string storage , stack , and a
possible reserved area for machine-language programs or other uses , as
shown in Figure 4 . 2 .
DECIMAL
HEX
65.535
FFFF
O E D I CAT E D I 10
CARTRIDGE
RO M
4 9 , 1 52
c ooo
40,960
AOOO
3 2 ' 768
32, 767
8000
7FFF
COLOR
BASIC
EXTENDED
COLOR
BASIC
BYTES
OF MEMORY
ANO I 10
65, 536
UNUSED
OR
RAM
16, 384
16,383
4 000
3FFF
RAM
0
0000
Figure 4 . 1 :
Memory mapping fo r Extended Color BASIC.
76
DECIMA L
HEX
32, 76716,383OR 7FFF3FFFOR RESERVED
FOR
MACHI NSTACK
E LANGUAGE
STRISTORAGENG
USER
BASIC
OR
PROGRAMS
32,1OF6, 768384RAMBYTES
13,824 3600 BASIVARICABLES
GRAPHI
CS
PAGES
0400 WORKITEXTNGSCREEN
102415360 0600
STORAGE
0000
L.,__ - - - - - - - -
1-- - - - - - - '--- - - - - -
--
1--- - - - - - - -
Figure 4.2:
RAM storage.
Text Screen
The area from RAM location 1 024 through 1 535 is dedicated to the
text screen (see Figure 4 . 3 ) . This is the normal display of text that you
see when you are entering BASIC statements. It is used any time that the
Extended Color BASIC interpreter is reentered.
GRAPHICS
PAGES
15361535 05FF
0600
1024 0400
Figure 4.3:
TEXT
SCREEN
1------1
Text screen.
} PER(32162CHARACTERS
RLIYNESES AT
LI NE·l
�� � J
Extended Color BASIC: Initializa tion
77
G raphics Screen
The area from 1 536 upwards is divided into graphics pages (see
Figure 4.4). The minimum size graphics area required is 1 5 36 bytes
(PMODE 0). The 1 5 36 figure is used as a standard screen size in
Extended Color BASIC . PMODEs 0, 1 , 2, 3 , and 4 use 1 53 6 , 3072,
3072, 6 1 44 , and 6 1 44 bytes respectively. In terms of graphics pages ,
then, these modes use 1 , 2 , 2, 4, and 4 pages respectively.
DECIMA L
HEX
1 3 , 824
3600
12, 288
3000
JO, 752
2AOO
9216
2400
7680
lEOO
6 14 4
1800
4608
1 2 00
G R A P H I C PA G E
8
7
"
EXTRA " PAGES
FOR AN I M A T I O N
O R OT H E R U S E S
6
5
4
3
3072
ocoo
1536
0600
2
1
Figure 4.4:
}
REQ U I R E D
FOR P M O D E
4
REQUIRED
FOR PMODE 0
Graphics pages.
Up to 8 graphics pages can be allocated by the PCLEAR command.
While only 4 pages are required in the highest resolution graphics mode
(PMODE 4, 256 by 1 92 , two colors), Extended Color BASIC has the
ability to switch rapidly from one page to the other by the PMODE
command and to copy one page to another by the PCOPY command . lt
might be convenient, for example, to rapidly display 8 pages at 1/a second
intervals in the PMODE 0 mode to provide an animation effect .
The Extended BASIC user doesn't have to b e aware o f the actual
memory location of the graphics pages; all references to them are done by
a page number from 1 through 8 .
78
THE SCREEN COMMAND
The format of the SCREEN command is
S C R E E N type
t
color set
where type is 0 for text screen or l for graphics screen and color set is 0
or l .
The SCREEN command is used to switch from a display of the
5 1 2-byte text screen to the display of the current graphics page. The color
set selects one of two color sets, as described above . The SCREEN
command may be used at any time in an Extended BASIC program . The
color set select may be used for the text screen in addition to selecting a
set of graphics colors . The standard text display is black on green, but
executing
SCREEN 0 t 1
will display red on orange for the text. Pressing (BREAK) always resets the
text display to black on green.
The short program
1 00
1 10
1 20
1 30
1 ll 0
1 50
SCREEN 0 t 1
FOR 1 = 0 TD
SCREEN 1 ,0
FOR 1 = 0 TO
SCREEN 1 t 1
FOR 1 = 0 TD
1 0 00
N D( T
1 0 00
N E )< T
1 0 00
N E )< T
l
illustrates how the screen may be switched from text to graphics and how
the color set may be changed.
When the screen is changed from text to graphics, the graphics
displays the current page and the current graphics resolution selected by
the last PMODE statement. If there is garbage in the graphics screen
area, the graphics display may be somewhat strange (expect to see lemon
rinds, old balogna skins , and so forth) . Normally, the graphics screen
would contain meaningful data put in by the Extended Color BASIC
graphics statements.
Extended Color BASIC: Initialization
79
THE PCLEAR COMMAND
The PCLEAR command is used to reserve 1 to 8 graphics pages .
Extended Color B ASIC automatically reserves 4 graphics pages on
initialization , enough for every graphics mode. If no PCLEAR is done,
this number of pages will remain in force throughout the BASIC program
execution .
The format of the PCLEAR is
P C L E A Rn
where n is 1 through 8 .
The PCLEAR is normally issued at the beginning of a BASIC
program . If it is issued dynamically in the middle of a graphics program
after display processing has been done, the PCLEAR may cause
unexpected results. When the Extended Color BASIC interpreter executes
the PCLEAR, it reserves the appropriate amount of storage after the text
screen . The area immediately after the graphics page area is used for the
BASIC program . The pointer to this area is adjusted to point to the next
location after the last byte of the graphics pages.
The PCLEAR may be used to reduce the default value of 4 graphics
pages to l to 3, making more RAM available for BASIC program
storage, or to make certain that enough video memory is available for
programs that do a lot of graphics processing. Use as required.
THE PMODE COMMAND
The PMODE command is used to set one of the graphics modes (0
through 4) and to select the starting page number ( I through 8) for
display . The format of PMODE is
P M O D E mode 1 start-page
The default value for PMODE is PM ODE 2, 1 , a resolution of 1 28
by 1 92 (two-color) with a start-page number of one.
PMODE may be used at any time to change the resolution of the
graphics mode . Don 't forget that the actual command that causes the
graphics page to be displayed is SCREEN . SCREEN uses the last
PMODE mode and start-page values (or the default values) to display the
graphics page.
PMODE may be used to switch from one graphics page to the next
while keeping the same resolution. For example: If we were in the lowest
80
resolution of 1 28 by 96, two-color (PMODE 0), each page would be
1 536 bytes . We could rapidly display all 8 graphics pages by
1 00 FOR S P = 1 TO 8
1 1 0 PMODE 0 1S P
1 2 0 N E >( T S P
In this case , the PCLEAR command must have previously allocated 8
graphics pages, and, of course, the pages would have been fil led with
some meaningful data.
THE PCOPY COMMAND
The PCOPY command is used to copy the contents of one graphic
page to another. The format is
PCOPY
n
TO m
where n and m are graphics page numbers of I through 8 , previously
allocated by a PCLEAR command.
The PCOPY command is a convenient way to move display data
from one graphics page to another without having to do a series of
cumbersome PEEK and POKEs or some other scheme. Dependent upon
the mode, don ' t forget that a screen ful l of data may take more than a
single graphics page and that it may be necessary to do several PCOPYs
for a screen ' s worth of data.
THE PCLS COMMAND
The PCLS command is the Extended Color BASIC equivalent of the
CLS command. It clears the current graphics screen with a specified
color. The format of PCLS is
P C L S color
where color is a value of I through 8 , corresponding to the standard
graphics colors. If no color is specified , the current background color is
used.
The PCLS clears the entire screen; this means that more than I
graphics page will be used if you are in a PMODE that requires more
than 1 graphics page (PMODE 2 through 4) .
" Ah there' s the rub, " as the Bard says in A Merchant of Fort
Worth . As you know from the discussion earlier in this chapter, only four
Extended Color BASIC: Initialization
81
o r two colors are available a t any given time , depending upon the
PMODE. How can PCLS clear the current graphics screen with all
colors? The answer is that it doesn' t . Only the available colors are used
and only in the current color set as specified by the last SCREEN
command. Table 4 . 2 shows the proper codes for various PMODES, color
sets, and PCLS colors.
The PCLS command may be used even if a graphics screen is not
being displayed (SCREEN O,X). The PCLS simply clears the current
graphics page and the current display status is not a consideration .
PM ODE
Color Set
0
0
0
.
2
0
3
0
4
0
= border
Table 4.2:
PCLS Actions .
PCLS Color
black
*green
black
*buff
*green
yellow
blue
red
*buff
cyan
magenta
orange
black
*green
black
*buff
*green
yellow
blue
red
*buff
cyan
magenta
orange
black
*green
black
*buff
PCLS Code
0
1
0
5
1
2
3
4
5
6
7
8
0
1
0
5
1
2
3
4
5
6
7
8
0
1
0
1
82
THE COLOR COMMAND
The COLOR command is used to set the foreground and background
colors . The format of the COLOR command is
C 0 L 0 R foreground ' background
where foreground is a value from l to 8 and background is a value from l
to 8 .
Let's talk about what w e mean by foreground , background , and
border, since these are confusing terms.
The border for the alphanumeric and semigraphics modes is always
black, as shown in Figure 4 . 5 . The border for the graphics modes is
either green or buff, depending upon whether we have selected color set
0 (green) or color set I (buff) . In both the alphanumerics/semigraphics
modes and the graphics modes , we can set the background color to the
same color as the border, making the background disappear beyond the
edge of the screen. We can also set the background to another color,
creating a distinct border. The background , therefore , is the field upon
which graphics figures will be drawn, by the various Extended Color
BASIC commands. The foreground is the color used to draw the figures .
As with the PCLS command , there may be a limited number of
colors available for either background or foreground. If we are in the
two-color mode (PMODE 0, 2, or 4), the background can be green or
black for color set 0 or buff or black for color set l . The foreground can
be the same two colors . Obviously , we want the foreground to show up,
so we are left with green/black or buff/black for the two screen colors
whether they are specified as foreground or background.
If we are in a four-color mode (PMODE I or 3 ) , the background and
foreground colors can be green, yellow, blue, or red , for color set 0 or
buff, cyan , magenta, and orange , for color set 1 . Here again, we want
the colors to show up, so we have the following options for foreground
and background colors: green/yellow , green/blue , green/red , yellow/blue,
yel low/red, and blue/red, buff/cyan, buff/magenta, buff/orange,
cyan/magenta, cyan/orange, and magenta/orange.
The COLOR command may be used at any time; if it is used in the
four-color mode to change the foreground color, three separate colors
may be displayed upon a one-color background. If that background color
is the same as the border color, no border will appear.
As an example of the use of COLOR, look at the fol lowing
program . It paints three rectangles upon a buff background using the
LINE command discussed in the next chapter. The display is shown in
Figure 4 . 5 .
Extended Color BASIC: Initialization
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 80
220
83
REM USE OF COLOR COMMAND
PMODE 1 1 1
SCREEN 1 1 1
PCLS 5
COLOR 6 15
L I N E ( l1 8 1 2 6 l - ( 8 l1 1 5 ll l 1 P S E T 1 B F
COLOR 7 15
L I N E ( 1 2 0 1 8 2 l - ( 1 5 6 t l l ll l 1 P S E T 1 B F
COLOR 8 1 5
L I N E ( 1 8 2 t l ll 2 l - ( 2 2 8 t 1 7 0 l 1 P S E T 1 B F
GOTO 200
COLOR 6 , 5
B
B U F F BOR D E R ,
BAC K G R O U N D
7,
I I
COLOR
5
M A G E N TA
I I
C O L O R 8,
5
ORA N G E
Figure 4.5:
COLOR use example.
USING THE COMMANDS IN THIS CHAPTER
The commands discussed in this chapter were really the trivial
commands in Extended Color BASIC; they do very little as far as
producing graphics on the screen . Understanding SCREEN , PCLEAR,
PMODE, COLOR, and PCLS , and PCOPY , however, is essential to
working with the remaining graphics commands . In the rest of this book,
we ' ll be discussing the graphics commands that can be used to draw
plots , lines, boxes , filled-in boxes , circles, ellipses , arcs, irregular
figures, etc . , and we' II be using the material in this chapter as a base .
PSET, PRESET, PPOINT, and Plotting
85
CHAPTER 5
Extended Color BAS I C : PSET, PRESET,
PPOINT, and Plotting
We've covered the elementary commands of Extended Color BASIC in
previous chapters. In this chapter we ' l l discuss three of the Extended
Color B ASIC commands that are used to plot points . These commands
are very similar to the Color BASIC commands of SET, RESET, and
POINT, which let us set , reset, or test any graphics point; they are PSET,
PRESET, and PPOINT.
THE G RAPHICS MATRIX
As we' ve seen from the previous chapters , the graphics modes use
different resolutions, ranging from 1 28 horizontal elements by 96 vertical
elements to 256 by 1 92 . To simplify switching from one resolution to
another, all graphics commands in the remainder of the book use the
highest resolution graphics mode of 256 horizontal by 1 92 vertical in
specifying coordinates (See Figure 5 . 1 ) .
We can see how this works by previewing the LINE command,
which draws a line between any two screen points . The program below
displays the line in the upper left quadrant , as shown in Figure 5 . 2 , for
the 5 graphics modes. Notice in running the program that the line
becomes finer and finer as the graphics modes go to higher resolution.
(It's a fine line between the proper use of PMODE 0 and PMODE 4 ! )
86
(
ELEMENT
ELEMENT
r255.
o
0, 0
I
256 HORIZ ONTAL
ELEMENTS
2 CAL
VERTI
ELEMENTS
I
19
�
ELEMENT
0, 1 9 1
Figure 5. 1 :
ELEMENT
128,CENTER96 TO
!CLOSE
l
L 255,
ELEMENT
191
Graphics matrix.
1 0 0 R E M D E M O N S T R A T I O N OF G R A P H I C S
ADDRESS I NG
1 1 0 F O R P = 0 T O LI
1 20 PMODE P 1 1
1 30 SCREEN 1 1 0
1 40 PCLS
1 50 L I NE ( 0 1 0 ) - ( 1 27 185 ) 1 PSET
1 6 0 F O R I = 0 TO 1 0 00 : NEXT I
1 7 0 N E :n P
1 80 GOTO 1 80
USING PSET, PRESET, and PPOINT
The PSET, PRESET, and PPOINT are PMODE SETs, RESETs,
and POINTs, hence the prefix "P" . They do essentially the same
thing as the Color BASIC SET, RESET, and POINT - they set,
reset, or test one point on the screen. All coordinates for the com­
- - 1 92 coordinate system of graphics.
mands use the 256 by
PSET, PRESET, PPOIN T, and Plotting
Figure 5 . 2 :
87
Resolution example.
PSET
The format for PSET is
PSET
(h
1v 1c)
where h is a horizontal element number o f 0 through 255 , v i s a vertical
element number of 0 through 1 92 , and c is a color value of 0 through 8 .
I f the c parameter i s omitted , the current foreground color i s used .
PSET will set one element located at h, v. The size of the element
that is set will be one element of whatever PMODE is in force . The
actual physical size will be finer for higher resolution graphics modes.
The size of the element in PMODE 4 is 1 unit, for example, but the size
of the element in PMODE 0 is 4 units , due to the lower resolution.
This program sets one vertical line in the middle of the screen .
1 00
110
1 20
1 30
1 ll 0
1 50
1 60
1 70
R E M S E T O N E t.J E R T I C A L L I N E
PMODE 0 t 1
SCREEN 1 '0
PCLS
F O R l.l = 0 T O 1 9 2
P S E T ( 1 2 7 , t.J )
N E> : T l.J
GOTO 1 70
88
The PSET command uses the current foreground color to set the
points. In the program above, the background color defaulted to black
and the foreground color defaulted to green , as PMODE 0 is a two-color
mode.
In the program below , the same line is drawn, but PM ODE 1 is used
with the alternate color set (SCREEN 1 , 1 ) . The PSET here specifies
color 7, and the result turns out to be a blue line on a buff background .
1 00
110
1 20
1 30
1 ll 0
1 50
1 60
1 70
R E M S E T O N E l,J E R T I C A L L I N E
PMODE 1 t 1
SCREEN 1 t 1
PCLS
F O R l,! = 0 T D 1 9 2
P S E T ( 1 2 7 , l,J t 7 )
N E )< T l,J
GOTO 1 70
PRESET
The PRESET command works exactly the same as PSET in reverse .
The PRESET resets an element. Since the reset is always assumed to be
in the background color, no color value is specified in the format
PRESET
<H tV l
The program below sets a vertical line, delays for a display , and
then resets the same line.
1 00
110
1 20
1 30
1 ll 0
1 50
1 60
1 70
1 80
190
200
210
R E M S E T O N E l,J E R T I C A L L I N E
PMODE 1 t 1
SCREEN 1 t 1
PCLS
F O R l.1 = 0 T D 1 9 2
P S E T ( 1 2 7 , l.J t 7 )
N E :n l,J
N E )< T I
FOR ! = 0 TD 1 000
F D R l,! = 0 T D 1 9 2
P R E S E T ( 1 2 7 , i,J )
N E )< T l,J
GOTO 2 1 0
PSET, PRESET. PPOINT, and Plotting
89
PPOINT
PPOINT is used in similar fashion to POINT. It tests the color of a
specified graphics point. The format of PPOINT is
P PO I NT
<h 1v)
PSET and PRESET will be used a lot less frequently than the more
powerful Extended Color commands such as LINE and CIRCLE;
PPOINT will be used even less frequently . Sti ll, it is nice to have a
command that can test the color of an element. As an example of the use
of PPOINT, consider the program below , which clears the screen , sets
one random element to magenta, and then scans for the element returning
the location as shown in Figure 5 . 3 .
1 00
1 10
1 20
1 3 Q)
1 LI 0
1 5 Q)
1 G Ql
1 7 Q)
1 8 Q)
1 9 Q)
2 Q) Q)
2 1 Q)
R E M E >: A M P L E O F P P O I N T
PMODE 1 d
SCREEN 1 d
PCLS
PSET < RND < 255 ) 1 RND < 1 9 1 ) , 7 )
F O R )-( = 0 T D 2 5 5
F D R y = Q) T D 1 9 2
I F P P O I N T O( 1 Y ) = 7 G O T O 2 0 0
N E >( T y
N E )< T }-(
S C R E E N Q) ' Q)
P R I N T " P O I N T F O U N D A T " ' t\ ,
• \/
I
• \I
The program above first sets the PMODE to a four-color mode,
PMODE 1 . The screen is set to graphics with color set 1 by SCREEN
1 , 1 . Next, the screen is cleared to the background color (buff) by PCLS .
One random point is then set by PSET. The color for the PSET is 7 , or
blue.
A scan of all of the 3 ,072 points is then made by the X, Y loops. For
each point, a test is made of the color by the PPOINT statement. If any
point is color 7 , the screen is reset to text and the location of the point is
printed .
The maximum (worst-case) time for the scan here is 400 seconds , so
be patient !
In thinking about it, PPOINT is about as useful as POINT. See
earlier comments .
90
B U F F BACKG R O U N D
M A G E N TA P O I N T ,
S E T R A N DOM L Y - I
S TA R T
P PO I N T S C A N
ON S C R E E N
END
Figure 5.3:
PPOINT use example.
TIME FOR PSET/PRESET
The scan above indicates a disadvantage of PSET/PRESET and
PPOINT. All of these commands have fairly large overhead compared to
the more powerful commands such as LINE and CIRCLE. It is much
faster to draw a line with LINE, for example, than with a loop using
PSET. The PSET/PRESET commands should be used only when you
can ' t accomplish the same things with other Extended Color BASIC
commands. One of the best uses for PSET/PRESET is in plotting data,
which we'll discuss right now .
PLOTTING USING PSET/PRESET
In a plotting application, you can use the PSET/PRESET commands
to plot the results of graphs . To do this , we must give some thought
PSET, PRESET, PPO/NT, and Plotting
91
about the coordinates o f the graphics screen and the coordinates o f the
application . (We may be putting Descartes before de horse , but here
goes . . . )
Most plotting is done in Cartesian coordinates as shown in Figure
5 .4 . In this system, there are X and Y axes.
The X axis is the horizontal axis. X values increase in a positive
sense to the right, and decrease in a negative sense to the left. The Y axis
is the vertical axis. Y values increase in a positive sense in the up
direction , and decrease in a negative sense in the down direction. The
intersection of the X and Y axes defines the origin of the graph, where X
and Y are both zero.
AXI S
Y
POI N T AT \
(X , Y l • - 2 . 2
t-- - - - 2
I
!
0
0,
N
I
G
I
rOR
-t -+-- -+--i --+- +-_,1---+--!-- -+- +-+ X AXI S
-
-
-4
-3
-
-2
-
-
-I
I
I
-I
-2
_ _ _ _ _ _
-3
-4
Figure 5.4:
-
4
Cartesian coordinates.
_.
\_POIAT NT
(X , Y l • 3 , -2
92
, - - - - - - --- - - - - - ,I
y
I
I
I
I
I
I
I
CARTESIAN I�:
I
---����������----- ,
I
I
I
I
I
I
I
I
I
I
I
L_ _ _ _ _ _ _
_ _ _ _ _ __ _
J
ORIIS NOWG( 0IN, AATN
ATCARTESI
Ol
H
COLOR
COMPUTER
191
Figure 5.5:
v
./!
I
I
I
I
I
I
I
________________ _
_J
Conversion to Color Computer coordinates.
To convert from the X, Y coordinate system to the graphics of the
Color Computer screen is a fairly easy task. It involves changing the X , Y
coordinates to horizontal and vertical coordinates , as shown i n Figure
5.5.
First o f all , determine where the origin i s to be on the screen . You
might want a center origin for the display of a map, where the X, Y
coordinates are referenced to the center of a state, as shown in Figure
5 . 6 . For mathematical functions, you might also want a center origin
where both positive and negative values are represented, as shown in the
same figure . If you are displaying the elevation of a jogging course, you
might want the origin to start in the left-hand corner, as shown in the
figure . If you are displaying undersea mountain ranges , the origin might
start at the midpoint of the top screen row.
PSET, PRESET, PPOINT, and Plotting
GENCY
PPO I N T
CORN RS
�
CON FUSION
%!
O R I G I N FOR
MAP D I SPLAY
READINESS
SHOCK
z
0
1<I
>
w
-'1500
/ H E AR T B R E A K
w
1000
500
\_
D I ST A N C E
OR I G I N FOR J O GG I N G
COU R S E D I S P L AY
OR I G I N FOR
M AT H E M A T I C A L
P L OT T I N G
/"
Figure 5.6:
HILL
Determining the origin of a graph.
O R I G I N FOR
U N D E R S E A PLOT
93
94
Next, determine the limits of the X and Y data you want displayed.
The map coordinates might involve an area 400 miles by 200 miles. A
mathematical graph might involve horizontal values of 720 units and
vertical units of + 1 to - 1 . The jogging course display might cover 26
miles , 385 yards and elevations from 0 to 500 feet .
T o translate from X , Y coordinates to Color Computer screen
coordinates , do the following:
1 . Write down the maximum number of X units. Include both
negative and positive ranges . If an X, Y plot goes from -50 to + 50, for
example, the maximum number of units is 1 00 . Call this XR , for X range .
2 . Divide 254 by XR for a new value XS (X scale factor) . This is
the number of X units for every horizontal unit on the screen minus one .
3 . Write down the maximum number of Y units . Include both
negative and positive ranges . If an X, Y plot goes from - 1 0 to + 1 0 , for
example, the maximum number of units is 20. Call this YR , for Y range .
4 . Divide 1 9 1 by YR for a new value of YS , Y scale factor. This is
the number of Y units for every vertical unit on the screen minus one.
5 . Locate the origin that you want on the screen. Express it in h, v
units . The origin will have a horizontal location of 0 through 255 and a
vertical location of 0 through 1 9 1 . Call these coordinates H and V.
6 . Plot the values by
PSET
<H ,y 1C>
where H = H + X x XR , V = V Y x YR , and C is the PSET color
value . Note that the equation for V has a minus sign .
As an example of this method , let's plot a sine graph . The sine
waveform for 0 through 360 degrees is shown in Figure 5 . 7. It varies
between 0 and + 1 and 0 and -1 , vertically. The X range, or XR , is in
this case 360 degrees . The XS, or X scale factor is 254/360. The Y range,
or YR , is 2 units . The YS, or Y scale factor, is 1 9 1 /2 .
-
2( Y
U N I TS
RANGE )
3 6 0 DEGREES
X RANG E )
Figure 5.7:
(
Sine wave example.
PSET, PRESET, PPOINT, and Plotting
95
In this case there are no negative values of X (0 through 360
degrees) , but there are both positive and negative values of Y ( 1 through
1 ) . We ' ll locate our origin at the midpoint of the left side of the screen,
which is H 0 and V 96. H is therefore 0 and V is 96.
We are going to vary X from 0 through 360 and we should get
values of Y from 0 to 1 back to 0 and down to -1 and then back to 0. The
values of Y will be given by Y
SIN(X). A minor complication here,
however. . . X is in radians, a unit of angular measurement which is equal
to the number of degrees divided by 57. 2957 (or 2 x PV360) . When we
use this conversion , we have
-
=
=
=
Y = S I N I X / 57 . 2957 1
For our major loop in the program, then, it appears we have
something like
1 70
1 80
1 90
200
210
F D R }{ = 0 T D 3 8 0
H = H + )< * >: S
t.J = t.J _ Y * Y S
P S E T I H , 1.1 t 7 l
N E )< T }{
Using the scale factor and origin values , we have
1 70 FOR X = 0 TD 380
1 80 H = 0+X*254/ 380
1 90 V = 9 8 - Y * l 1 92 / 2 l
2 0 0 P S E T I H t l.l t 7 l
2 1 0 N E )< T ){
We also have to relate Y to X by the function
Y = SIN(X/5 7 . 29578):
1 7 0 F O R X = 0 TD 3 8 0
1 80 H = 0+X*254/ 380
1 90 V = 9 8 - S I N I X / 57 . 29578 l * l 1 92/ 2 l
2 0 0 P S E T I H , t.1 , 7 1
2 1 0 N E )< T ){
96
When we integrate this with the graphics commands, the program
looks like this:
1 00
1 10
1 20
1 30
1 70
1 80
1 90
200
210
220
REM PLOT S I NE WAVE
P M O D E ll 1 l
SCREEN 1 10
PCLS
FOR X = 0 TD 380
H = 0 + X * 2 5 ll / 3 8 0
V = 9 G - S I N I X / 57 . 29578 1 * 1 1 9 1 / 2 1
P S E T < H , t.1 I
N E ){ T }(
GOTO 220
The resulting display is shown in Figure 5 . 8 .
I
I
;�'\.
\.
I
\�
'
Figure 5.8:
/
180 DEGREES
\
0 DEGREES
\.
/
\
\
\'
"-/
I
360
DEGREES
/
/
I
Sine wave ploc.
In this program we took the approach of looping through the
external range of Xs - the range of degrees from 0 through 360 . Another
approach is to loop through the number of H or V points. In other words,
instead of plotting 360 increments, why not plot 255 increments , one per
horizontal unit? Depending upon the function that is being plotted, this
can sometimes eliminate multiple PSETs of the same point. This
approach is used in the program below , which plots multiple sine waves
PSET, PRESET, PPOINT, and Plotting
97
over a user-specified number of degrees and a starting angular
displacement (starting number of degrees) .
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 80
200
210
220
REM PLOT MULT I PLE S I NE WAVES
P M O D E ll 1 1
PCLS
I NPUT
NUMBER OF DEGREES ; ND
I N PUT " START I NG DEGREE S " ; so
ND=ND-SD
SCREEN 1 10
F O R X = 0 TD 255
R D = I I I X / 255 l •ND l +SD l / 57 . 28578
PSET I X 1 8 6 - S I N I RD l •85 l
N D( T :<
SCREEN 0 10
GOTO 1 30
II
I I
In this program X is the number of the horizontal point and varies
from 0 through 255 . The range of X is variable and is an input parameter.
It is set equal to ND , number of degrees . The starting number of degrees
is input variable ND .
Initiall y , the PMODE is set equal to 4 , the 255 by 1 92 two-color
resolution. The graphics screen is then cleared . Note that this can be done
even without displaying the screen . Statements 1 30 through 220
constitute the program loop. Each time through, the number of degrees to
be displayed is input as ND , along with the starting point, SD . The
SCREEN command then sets the graphic mode and the sine function is
plotted. At the end of the plot, the screen is set back to text mode , and
another pass is made . Note that the screen is only cleared at the
beginning , and that subsequent passes plot the new plot over the old.
-
-
Drawing Lines, Rectangles, Circles, and A rcs
99
CHAPTER 6
Extended Color BAS I C : Drawing Lines,
Rectangles, Filled Rectangles, Circles, and
Arcs with L I N E and C I RCLE
Up to this point in Color Computer Graphics, we ' ve discussed some
of the more mundane commands. In this chapter and the next, we ' ll be
discussing LINE , CIRCLE, ORAW , PAINT, and GET/PUT, the most
powerful Extended Color BASIC commands that will enable you to draw
a variety of lines , shapes , and figures and to color them easily .
This chapter discusses the LINE and CIRCLE commands which
enable you to:
•
•
•
•
•
•
Draw
Draw
Draw
Draw
Draw
Draw
a straight line between any two points on the screen
a box of any size anywhere on the screen
a filled-in box of any size anywhere on the screen
a circle of any size anywhere on the screen
an arc of any size anywhere on the screen
an ellipse of any size anywhere on the screen
USING THE LINE COMMAND TO DRAW LINES
The LINE command allows you to draw a line between any two
points on the screen . The format of the LINE for line drawing is
L I NE
( x1 t y1 ) - ( X2 t Y2 ) I A
100
The XI , YI and X2 , Y2 parameters define two points on the screen.
These points may be in any relationship to each other. In other words ,
point 2 may be to the left or right of point l and above or below point l .
(About the only stipulation is that the points must be on the screen ! ) The
points are defined by the standard H, V coordinates that we used in PSET,
PRESET, and PPOINT
X is a value from 0 through 255 that specifies
the horizontal coordinate; Y is a value from 0 through 1 92 that specifies
the vertical coordinate. The coordinates reflect the screen matrix in the
highest resolution mode, but, of course, are valid for any PMODE from 0
through 4 .
The A coordinate is either PSET o r PRESET. If PSET i s used, then
the current foreground color is used in drawing the line. If PRESET is
used, then the current background color is used to draw the line . In other
words, this command is really a PSET LINE or PRESET LINE , a
command that draws or erases the line , depending upon whether the
PSET or PRESET option is used.
That ' s all there is to drawing a line , any line ! Those of you who are
not impressed have probably never tried to implement a line-drawing
routine in BASIC or assembly language. It is quite involved when the
direction of the line, the limit conditions of the end points , and the
increments are considered. LINE will do all of this automatically , leaving
you free to do graphics applications .
T o draw a line between a point at 23,23 and a point at 1 00, 100,
then , we'd have
-
L I NE
( 23 1 23 ) - ( 1 00 1 1 00 ) 1 PSET
The result would be as shown in Figure 6 . 1 .
�3)
� (100,100)
Figure
6.1:
LINE example.
Drawing Lines, Rectangles, Circles, and A rcs
101
To show you that LINE does indeed work with any set of two
points , run the following program. The program selects any two points at
random and then uses LINE to connect them, using a random color.
PMODE 3 ( l 28 by 1 92 resolution) is used.
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 90
200
210
REM L I NE DEMONSTRA T I ON
PMODE 3 1 1
SCREEN 1 10
PCLS
X 1 = RND l 256 l - 1
Y 1 = R ND l 1 92 l - 1
X 2 = RND l 256 1 - 1
Y2=RND C 1 92 l - 1
C = RND l 5 l - 1 : I F C = l THEN GOTO
COLOR C d
L I N E 0( 1 1 Y 1 l I )<2 1 Y 2 l 1 P S E T
GOTO 1 40
1 80
-
Speed of LINE
How fast does LINE draw a line? To the eye it seems instantaneous.
This is an interesting question, for with a great deal of graphics
processing, execution speed may be a critical factor. We can easily find
out by running this program
1
1
1
1
1
1
1
00
10
20
30
40
50
60
REM L I NE T I MER
PMDDE 4 1 1
SCREEN 1 I 0
PCLS
FDR Y 1 = 0 TD 1 92
L I NE 1 0 1 Y 1 l - 1 255 1 Y l l 1 PSET
N E )< T Y l
The program action is shown in Figure 6 . 2 .
1 02
I
I CLEAR SCREEN
I
I
I
I
Figure
6.2:
FROM
BOTTOMTOP TO
LINE timing display.
When this program is run and timed , we get about 8 . 3 seconds to
clear the screen using LINE. If the statement in 1 50 is replaced by 1 50
REM AAAAAA, the time is about 1 . 3 seconds. The total time for LINE
processing in this simple case is therefore about 7 seconds , or about 36
milliseconds (36/ 1 000 second) per line. A similar test for LINE in
PMODE 4 yields 5 1 9 random-length, random-direction lines in 50
seconds, or about one "average" line per 96 milliseconds. The worst
case is probably about double this, or about 1 92 milliseconds . This is at
least 20 times faster than the fastest BASIC line drawer!
Background and Foreground Colors in LINE
The PSET option uses the current foreground color to draw the line.
This means that the foreground color must be changed by means of a
COLOR statement to draw a line in a color other than the current PSET
color. Using PRESET simply uses the current background color, which
has the effect of erasing the line as this program illustrates:
1 00
1 10
1 20
130
l t'.1 0
1 50
1 60
1 70
REM L I NE PRESET EXAMPLE
PMDDE 3 1 1
SCREEN 1 1 0
PCLS
L I N E ( 23 1 23 l - ( 1 00 d 00 l 1 PSET
FOR 1 = 0 TD 1 000 : NEXT I
L I NE < 23 1 23 ) - ( 1 00 ' 1 00 ) 1 PRESET
GOTO 1 70
Dra wing Lines, Rectangles, Circles, and A rcs
103
USING LINE TO DRAW BOXES AND FILLED-IN BOXES
LINE Should really have been called LINEBOX (or maybe
LINEBOXFILLEDINBOX), because it generates not only lines on the
screen but also boxes (rectangles) and filled-in boxes . In this option, the
two points of LINE define the opposing comers of a box as shown in
Figure 6 . 3 .
� - - - - - -,
I
I
L
TWO NPOINTS
DEFI
I N G BOX
I
I
I
I
_
_
_ _ _
I
I
_.
TWO
DEFINIPOIN GN TSBOX
Figure 6.3:
-----LIEXTENDED
NBASIESC DRAW
BY
COLOR
I N TERPRETER
Using LINE to draw boxes .
The format of line for box generation is
L I NE
( X 1 1 Y1 l - ( X2 1 Y2 l 1 P S E T 1 B
or
L I NE
( X 1 , Y1 >
-
( X2 , Y2 l
1
PSET 1 BF
where B generates a box outline, and B F generates a box filled in with
the current foreground color. The PRESET option can be used in place of
PSET to reset the box to the background color.
1 04
Let' s use the previous random line generator to generate boxes and
filled-in boxes:
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
1 80
1 90
200
REM BOX DEMONSTRAT I O N
PMODE 3 1 1
SCREEN 1 10
PCLS
X 1 = RND C 256 l - 1
Y l = RN D < 1 82 l - 1
}( 2 = ( 2 5 6 ) - 1
Y 2 = RND C 1 82 l - 1
C = R ND C 5 l - 1 : I F C = l THEN GOTO 1 80
COLOR C 1 l
I F RND C 2 l = 2 THEN L I NE
O ( l 1 Y l l - r n2 1 Y2 l 1 PSET 1 B ELSE L I NE
OD 1 Y l l - ( ){ 2 1 Y 2 l 1 P S E T 1 B F
2 1 0 GOTO 1 40
This program continually generates boxes and filled-in boxes of
every size at every location (see Figure 6.4; as usual , this is a program of
dubious practical value . ) The overhead of generating a filled-in box is
much greater than that of generating a line or outline of a box . Because
of thi s , you can see that there is a definite direction to the fil l , either up
or down. Furthermore , the time in generating a filled-in box may go over
one second for larger boxes.
I
Figure
6.4:
BOX example.
Dra wing Lines, Rec tangles, Circles, a n d A rcs
105
Direction of LINE
Some experimentation with LINE uncovers the fact that LINE
operates just as you would expect. It draws a line from the beginning to
end point and also generates a box from the horizontal line defined by the
start point (Xl , Yl ) to the horizontal line defined by the end point
(X2 , Y2 ) , as shown in Figure 6 . 5 .
BOX O R F I LLED-IN BOX
D R AWN IN I N DICATED
·� '"'"'"
1;:,
I t�
: IJJ'l'
.... , ,
DICATED
D I R E CT I O N
S
S
'
E
LJ
S = START P O I N T
E= END POINT
Figure
6.5:
Direction of LINE.
Speed of LINE,BF
A test case program for LINE, B F generated 1 05 filled-in boxes in
50 seconds. The average filled-in box generation is therefore about 1/2
second , a significant time for a microcomputer action, but far less than it
would take for the equivalent user code to perform such an action.
USING CIRCLE TO DRAW CIRCLES
The next Extended Color BASIC command that we'll discuss is
CIRCLE. Circle can be used to draw not only circles, but also ellipses
and arcs (CIRCLEELLIPSEARC, really) .
The format of CIRCLE to draw a circle is
C I RCLE
e x t Y),R . c
1 06
where X and Y are the horizontal and vertical coordinates of PMODE 4,
the 256 horizontal by 1 92 vertical mode. X can therefore be 0 through
255 and Y can be 0 through 1 92. This coordinate defines the center of the
circle, as shown in Figure 6 . 6 .
C I RCLE ( X , Y ) , R , C
C I R C L E ( 70, 9 0 ) , 46
�
G
CENTER D E F I N E D
BY ( 70 , 90 )
"-.:_j___ R A DIUS
Figure
6.6:
DEFINED
BY 4 6
M A X I MUM
R A D I U S • 1 28
CIRCLE format.
The R parameter is the circle's radius, or distance from the center to
any point on the circumference, as shown in the figure . The maximum
radius for a display of a circle will be 1 27 for a center of 1 28 ,92. The
radius may vary from 0 to 1 27 or above, although larger radii may result
in border segments (discussed later in this chapter) .
The C parameter is the color code for the foreground color. If this is
omitted, the current foreground color is used. A color code that is the
same as the background effectively causes a circle reset which erases a
previously drawn circle.
To gain some familiarity with the CIRCLE, run the following
program . It draws circles from the screen center with increasing radii ,
similar to what is shown in Figure 6. 7.
1 00
1 10
1 20
1 30
1 40
REM C I RCLE DRAWER
PMODE 4 t 1
SCREEN 1 ,0
PCLS 1
FOR R = 0 T O 200
Drawing Lines, Rectangles, Circles, and A rcs
107
1 50 C I RCLE ( 1 28 1 96 ) 1 R 1 0
1 60 F O R 1 = 0 T D 1 000 : NEXT
1 70 C I RCLE
1 8 0 N E >( T R
( 1 28 1 96 ) 1 R t l
APPROXIMATE
SCREEN
CENTER
figure 6.7:
CIRCLE e x ample .
There' s one interesting thing about the circles created by this
program . We specified a radius of up to 200; for the larger radii , the
circles flattened out and finally occupied the border area of the screen , as
shown in Figure 6 . 8 .
BORDER FROM LARGE
RADIUS
figure
6.8:
CIRCLE border case.
108
Height : Width Ratio
The normal aspect ratio of a television picture is 4 : 3 , as shown in
Figure 6 . 9 . This figure means that the width of the picture is 4 units and
that the height is 3 units . The VDG chip in the Color Computer divides
the screen up into 256 by 1 92 pixels, which is also an aspect ratio of
4 : 3 . A correctly adjusted television should show a perfectly round circle
when the program above is run. Inexpensive televisions may produce an
elongated circle which may have to be corrected by some adjustments to
the controls on the back of the TV - vertical height and centering.
4 (256
U N ITS
rn
..J
w
x
""'
"'
�
�
rn
!::
z
::>
"'
1
Figure 6.9:
P I X E L S.)
0
(128,96),40
C I R C LE G E N E RATED BY C I RC L E
OR S I M I L A R SHOULD
BE PERFECTLY ROUND
Aspect ratio
The height : width ratio for the circle is variable within the CIRCLE
command, however. The format for a CIRCLE command with
height : width ratio is
C I RCLE
( X 1 Y l R 1 C 1HW
where HW is the height : width ratio, expressed as a figure from 0 to
255 . The default HW ratio is 1 .
The HW ratio is just what the name says - the ratio of graphic
height to width . A HW ratio of 1 says that the height of the circle will be
1 unit and the width of the circle will be 1 unit. Height divided by width
is Il l and the HW ratio is 1 .
Dra wing Lines, Rec tangles, Circles, and A rcs
109
Suppose that the height was 40 units and the width was 80 units . In
this case the HW ratio would be 40/80, or . 5 , and the circle would appear
as shown in Figure 6 . 1 0 , a flattened circle, really an ellipse .
Figure 6. 10:
HW ratio example I
If the height was 80 and the width was 40, the circle would be
squashed from the sides . The HW ratio would be 80/40, or 2, and the
circle would appear as shown in Figure 6 . 1 1 .
/
Figure 6. 1 1 :
H W ratio e x ample 2 .
HW = _fill =
40
2
1 10
Cases from O through 3 are shown in Figure 6. 1 2 . These cases are
generated by the program below .
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
Figure
6. 12:
REM HW RAT I O FOR C I RCLES
P M O D E LI t 1
SCREEN 1 10
PCLS
F O R H W = 0 TO 3 S T E P . 25
C I RCLE < 1 28 186 ) 1 50 1 1 1HW
N D( T H W
GOTO 1 70
HW
=
1
HW
=
0
HW ratio program example.
You can see from the figure that an HW ratio of 0 produces a circle
of no height - a horizontal line - and that an HW ratio greater than 2 or
3 draws a very elongated ellipse. An HW of 255 would with a small
radius be close to a vertical line.
It's important to note that when the HW ratio is other than 1 , the
width of the circle is equal to the radius times 2 and the height of the
circle is equal to the radius times 2 and the HW ratio. It may well have
been the other way around, but one standard or the other had to be
chosen.
When the circle produced by such an extreme HW ratio is drawn,
any points that fall outside the border of the screen are drawn as being on
the border. Which brings us to our next topic.
Dra wing Lines, Recta ngles, Circles, and A rcs
111
Borders for Oversized Circles
As you can see from Figure 6 . 8 , any circle that falls outside of the
border is drawn as the border itself. The center of the circle must appear
within the screen display area, however, as there is no way to specify a
center outside of screen limits !
Filling in Circles
Is there a way to fill in circles similar to the way we filled in
rectangles? (Sorry, watercolors on the television are not allowed . ) The
PAINT command enables us to do this, but let's try another approach for
the time being . We ' l l start with a circle of small diameter and increase an
increment at a time to see the result.
1 00
1 10
120
1 30
140
150
1 60
REM F I LLED- I N C I RCLE
PMDDE 4 t 1
SCREEN 1 t 0
PCLS 1
FOR R 0 T D 200
C I RCLE ( 1 28 1 8 6 ) 1 R 1 0
N E >� T R
DRAWER
=
The circle appeared as shown in Figure 6 . 1 3 . It grew in size until it
occupied the screen boundaries . As it grew, however, there were points
that were not filled-in . Why is this? Because the increment of the radius
I , 2 , 3, and so forth . However, it takes
can only be an integer value
less than a one-unit increment to guarantee a fill of every pixel . So we
can fill in circles by using this method, but we will have to live with
some gaps in the result.
-
Figure 6 . 1 3:
Filled-in c i rcle example.
1 12
USING CIRCLE TO DRAW ARCS
CIRCLE can do more than draw circles, ellipses, or partial circles
with boundary edges; it can also be used to draw arcs. Arcs are partial
circumferences of circles, as shown in Figure 6 . 14.
CIRCLE DEFINED
BY
( 128,
96), 50
THIS PORTION .-- NOT DRAWN � /
I
I
I
\
\.
'
END OF ARC___...'
Figure
6. 14:
/ START OF ARC
THIS
PORTION
DRAWN
( ARC)
Drawing arcs.
The format o f CIRCLE for drawing an arc is
C I RCLE
< X 1 Y l 1 R 1 C 1 HW 1 START 1 END
In this format, START and END specify the start and end of the arc , as
shown in Figure 6 . 1 5 . The circle is marked off in values from 0 through
1 . The 0 point is at "three o'clock" (90 degrees geographic, 0 degrees
trigonometric) , the .25 point is six o'clock ( 1 80, -90) , the .5 point is
nine o'clock (270, - 1 80) , the .75 point is twelve o'clock (360 , -270) ,
and the I point is back to the start. When the circle is drawn, it is drawn
clockwise from the starting point.
You know from using CIRCLE in previous examples that when the
START and END are not specified, a complete circle or ellipse is drawn.
To specify any segment (arc) of a circle or ellipse, put in the proper
START and END and execute the circle command .
To convert from geographic degrees (compass coordinates from a
map) to CIRCLE START and END values, take the number of degrees ,
Dra wing Lines, Rectangles, Circles, a n d A rcs
ANY POIF IORENDTEND,ASMAY BE
SPECI
START
SUCH AS .6
.
5
POI
N
T
! 210°. - 180°1
Figure
6.15:
DEGREES
•
.
7
77
23....2801360
777-.
2
5
'.
5
5277 277
I.
COLOR COMPUTER
VA L UES
6.16:
-
.75 POI N T ( 360°,- 270°)
0 POINT (0°90°TRIGEOGRAPHI
GONOMETRIC, C )
CIRCLE arc fonnat.
GEOGRAPHIC
Figure
1 13
0
'.
1
25
23...45/360
125-.
2
5•
-.
17525
-.
1
25+1
'.
8
90
I.
180
.75
.25
Converting from geographic t o CIRCLE coordinates.
divide by 3 60 , then subtract .25 . If the result is negative, add I . A
compass heading of 1 80 degrees (due south), for example, would be
1 80/360 - . 2 5 , or . 5 - . 25 = . 2 5 . A compass heading of 45 degrees
(northeast) would be 45/360 - . 2 5 = . 1 25 - . 2 5 = -. 1 25 ; the result is
negative, so adding one gives us .75 . Figure 6. 1 6 shows the process.
1 14
In trigonometric representation, a circle starts at 0 degrees in the
three o'clock position and proceeds counterclockwise through 90 degrees
(twelve o'clock), 1 80 degrees (nine o'clock) , 270 degrees (six o'clock) ,
and back to 360 degrees or 0. The angular displacement may also
proceed clockwise from 0 degrees in a negative sense : -90 degrees (six
o'clock ) , - 1 80 degrees (nine o'clock), -270 degrees (twelve o'clock) ,
and back to -360 or 0 degrees . In many cases it may keep on going
through greater and greater angular displacements - 720 degrees , 1 080
degrees, and so forth. Figure 6 . 1 7 shows the scheme.
90°
4 5°
1�.......
180.
--0(360DEGREES
DEGREES}
270°
---- oF' ANGULAR
360° 360°DISPLACEMENT
go•. 10°
+
Figure
6.17:
+
s
Trigonometric representation.
To convert from positive trigonometric degrees (less than or equal to ·
360) to START and END representation, take the trigonometric degrees
and divide by 360 . Make this number negative . Add one to it. A
trigonometric value of + 90 degrees, for example, is -(90/360) + I =
-.25 + I
. 75. A trigonometric value of + 270 degrees is -(270/360)
+ I
-.75 + I = .25 . To convert from negative trigonometric
degrees (less than or equal to 360), change to the equivalent positive
=
=
Dra wing Lines, Rec tangles, Circles, and A rcs
90°
TRIGONOME TRIC
OEGREES
1 15
+45" 2.3.I. 45/360•.
MAKE
-.112525 V+l•.E -.812575
ADD NEGATI
�0
180°
-135" --- ���
I.2. -135"
270°
ALENT
V
EQUI
TO
CONVERT
+
225
+VALUE:
225/360'NEGATI.625V E: -.625
3.4. MAKE
.75 875
"'/ ·5
0
\.325.25
Figure
I:
'-""-....._
'
'" '• __ . , , . ,
6.18:
'
CIRCLE
COOROINA TES
Converting from trigonometric to CIRCLE coordinates.
+ 1 80;
+ 270; -1 80
value and then convert as above (-90
-270 = + 90; -360 = + 360). To convert from large angular
displacements (greater than 360) , subtract 360 until the result is less than
or equal to 360, and then convert as above . Figure 6 . 1 8 shows the
conversion method.
=
=
Now that we know how to convert into START and END values ,
let's plot some arcs. We 'll use one-quarter arcs of a circle stepping from
0 (three o'clock) to . 75 (twelve o' clock) , as shown in Figure 6 . 1 9 .
1 00
1 10
1 20
1 30
1 ll 0
1 50
1 80
1 70
1 80
1 90
REM PLOT ARCS
PMODE 3 , 1
SCREEN 1 t 0
PCLS
ST=0
F O R X = 35 TD 2 1 5 STEP 8 0
C I R C L E ( )< t 9 8 l t 2 0 t ll t 1 , S T t S T + , 2 5
ST=ST+ , 25
N E )<T :<
GOTO 1 90
1 16
5 5
0 .50 .5r(
7 �1.0
7
0
25� �25
Figure
6.19:
Arc example.
The CIRCLE statement above can be broken down as follows: The
centers for the four circles are at X,96, or 35 ,96; 95 ,96; 1 55 ,96; and
2 1 5 ,96. The radius is fixed at 20. The color is red (background is green
from the PCLS) , the HW ratio is 1 (perfect circle). The STARTs are 0,
. 25 , .5, and .75. The ENDs are . 25 , .5, . 7 5 , and 1 .
Arcs can also be drawn for ellipses. In this case the HW ratio would
define the eccentricity of the ellipse. The program below draws a series
of arcs from the six o'clock point to the nine o'clock point for HW values
of .25 through 3 in steps of .25. The result is shown in Figure 6 . 20 .
1 00
110
1 20
1 30
l ll 0
1 50
1 60
1 70
REM ARCS W I TH VARY I NG HW RAT I OS
P M D D E ll t 1
SCREEN 1 1 0
PCLS
FOR HW= . 25 TD 3 STEP . 25
C I RCLE < 1 28 1 86 ) 150 t 1 1 HW 1 . 25 1 . 5
N E >( T H W
GOTO 1 70
SEMIGRAPHIC 4 MODE
A n exam p l e o f t h e Color
B A S I C mode of 64 p i xe l s
horizonta l ly by 32 p i xe l s ver­
t i c a l l y , t h i s photograph
s hows ava i l a b l e colors.
(Chapter 1 )
2
BAR G RAPH PLOT
H e re we are u s i n g
S ET/RESET t o have u p to
e i g h t c o l ors o n a
backgro u n d , w i t h text as
we l l . (Chapter 3)
3
A N I MATI O N U S I N G
C H R $ ST R I N GS
T h i s program u t i l izes
g r a p h i c s s t r i n g s i n a n i ma­
tion. The f i g u re s h o w n i s a
c y l i nder a n d p i ston of a two­
stroke e n g i n e . I t f i res w i t h a
red explosion and t h e p i ston
moves up a n d d o w n .
(Chapter 3)
4
USE OF T H E COLOR
COM MAN D
T h i s exa m p l e of t h e COLOR
com ma n d p a i n t s t h ree rect­
a n g les o n a b u f f
backgro u n d . (Chapter 4)
5
PLOT A S I N E WAVE
U s i n g P S ET to p l o t a s i n e
wave, we a r e a l so convert i n g
from Cartesian coord i n ates
to Color Computer coor­
d i nates. (Chapter 5)
6
L I N E D E M O N STRATI ON
Her e we s e l e c t a n y two
poi nts at ra ndom a n d use
t h e L I N E c o mma n d to con­
nect t he m , u s i n g a ra ndom
color. (C h a pter 6)
7a
BOX D E M O N STRATI O N
T h e L I N E c o mma n d c a n a l so
be used to g e n erate boxes
and f i l l e d -i n boxes.
(Chapter 6)
7b
BOX D E M O N STRAT I O N
continued
This shows t h e BOX pro­
g ram at a later stage.
(Chapter 6)
8
H E I G HT: W I DTH RATIO
FO R C I R C L ES
Vary i n g t h e h e i g h t to w i d t h
rat io i n t h e C I R C L E com­
mand res u l t s in e l l i pses.
(Chapter 6)
9
F I L L E D-I N C I R C L E
DRAW E R
H ere w e f i l l i n a c i rc l e
without using the PAI NT
c o m m a n d . (Chapter 6)
10
ROTATE PROGRAM
U s i n g t he D RAW c o mma n d s ,
i n c l u d i n g t h e A n g le c o m­
m a n d , we c a n d raw a f i g u re,
th e n rotate and draw i t
aga i n . (Chapter 7)
11
DRAW T H E TAN DY
TOW E R
T h i s i s an exam ple of u s i n g
stri n g s a nd s u bs t r i n g s w i t h
the DRAW commands to
copy a repet i t ive s h ape.
(Chapter 7)
Drawing Lines, Rectangles, Circles, and A rcs
Figure 6.20:
117
Arcs for e l l ipses example.
CIRCLE Defaults
As we've discussed , the format of the CIRCLE command varies
from a simple CIRCLE (X, Y) ,R to CIRCLE (X, Y) ,R ,C,HW,START,END .
The default parameters for various formats are shown below:
C I RCLE
e x , n tR
C I RCLE
e x , y i tR t C
c
e x , y ) t R , c t HW
e x , y ) t R , c t HW t START
c
I RCLE
I RCLE
C = foreground,
HW= 1 , START = O,
END = l
HW = I , START = O ,
END = I
START= 0 , END = 1
END = 1
If a comma is used in place of specifying a parameter, the default
parameter is assumed . The statement
C I RCLE
0( , Y l t R , t H W t S T A R T , E N D
for example , would generate a circle with the foreground color. The HW
ratio must be specified for START and END .
Using the DRA W Command
1 19
CHAPTER 7
Extended Col or BASIC : Using the D RAW
Command
The DRAW command is somewhat related to the LINE command. It
draws a line from point 1 to point 2. The line may be drawn in an up
direction, at 45 degrees , to the right, at 1 35 degrees , down, at 225
degrees , or left, at 3 1 5 degrees , as shown in Figure 7 . I .
The length of the line may be any number of units , from 0 to
hundreds .
The DRAW command also includes the capability to move to a
designated spot on the screen , specified in X, Y coordinates or in relative
coordinates.
DRAW also has the provision of drawing a blank line ( !) or
changing the color.
The DRAW command uses a string of commands to indicate how
the line should be drawn . A typical line might be defined as DRAW "up
25 units , " " right 20 units , " and so forth . Within the commands, DRAW
may reference a substring of commands, a powerful feature that enables
the user to build little modules of commands.
Another powerful DRAW feature is the ability to scale DRAW
commands. This means that with a single command, DRAW may
produce displays that are l /4 scale , 1 12 scale , on up to 62/4 scale .
The DRAW command is really an order of magnitude more
powerful than LINE, which was an order of magnitude more powerful
than PSET ! (Which was an order of magnitude more powerful than SET ,
which was . . . ) We' l l discuss a l l o f the ramifications o f DRAW i n this
chapter.
120
UP
315°
45°
STARTING POI NT
2 25°
Figure
7.1:
135°
DOWN
D RAW directions.
DRAW FORMAT
The format of DRAW is
DR AW
11 string 11
or
DRAW A$
In the first case, " string" represents a string of DRAW commands;
the string may be any number from one to dozens . A typical DRAW
string might be
DRAW
" D20 ;
R25 ;
U23"
where the string represents a line drawn from the current screen position,
Down 20, Right 25 , and then Up 23 positions. Note that the individual
commands are separated by semicolons and that the entire line of
command is a string with double quotation marks enclosing the line.
In the second case, A$ represents a general string variable , which
might be A$, B$, CC$, YY$, or some other legitimate name. This string
variable in tum would define a string of valid DRAW commands.
Using the DRA W Command
121
DRAW COM MANDS
DRAW commands are shown in Table 7 . 1 . They include motion
commands which result in a line segment being generated, mode
commands which change the color, angle, or scaling, and two options,
" no update" and " blank . "
Motion
M
U
D
L
R
E
F
G
H
X
Move the cursor
Move Up
Move Down
Move Left
Move Right
Move 45 degrees
Move 1 35 degrees
Move 225 degrees
Move 31 5 degrees
EXecute a substring
Mode
C = Change Color
A = Change Angle (rotate)
S = Change Scale
Options
N
B
Table 7. 1:
=
No Update after draw action
Draw Blank line (move, do not display)
DRAW Commands .
M Command
The M command moves the imaginary cursor for the DRAW to a
specified spot on the screen . Initially, this is done with the " B " (or
B lank) option so that wherever the cursor is to start off, no line is
generated in the move . Thereafter, an M command can be used with the
B prefix or without.
To draw a line starting from 1 28 ,96 to 0,0 and then to 255 , 2 , for
example, the l ine is first positioned by B M 1 28 ,96 and then MO,O and
M25 5 , 2 are done to draw the lines. (See Figure 7 . 2) .
122
1 00
110
1 20
1 30
1 40
1 50
REM DRAW EXAMPLE
PMODE 3 t 1
SCREEN 1 t 0
PCLS
DRAW " BM 1 28 t 86 ; M0 t0 ; M255 t 2 "
GOTO 1 50
1 4 0 D R AW " B M 1 2 8 , 9 6 ; MO, O; M 2 5 5 , 2 "
• ( 128, 96 )
B M 1 2 8 , 96 POS I T I O N S
I M AG I N A R Y C U R S O R
( 128, 96 )
MO, 0 D R AWS T H E
LINE FROM CURRENT
C U R S O R POS I T I O N TO
(0, 0 )
Using the DRA W Command
123
(2 55, 2 )
( 128,
96 )
M255, 2 DRAWS THE
LINE FROM CURRENT
CURSOR POSITION TO
(255, 2)
Figure
7.2:
M command using absolute motion.
The M command, therefore , is used to position the cursor or to draw
a line between any two specified screen points (just as the LINE
command was used) . M will generate any angled line and draw the line
in any direction depending upon the relationship of the start point to the
ending point . Note that the screen points are explicitly identified in the
format (B)MX , Y , where (B) indicates a Blank option.
Another form of the M command uses relative rather than absolute
values for X and Y. After the first M command is executed, the graphics
cursor is in a known position . A Move may be done with a displacement
from that known position to any other position. The displacement may be
either negative or positive . The program above may be rewritten as
1
1
1
1
1
1
00
10
20
30
40
50
REM DRAW EXAMPLE
PMODE 3 1 1
SCREEN 1 t 0
PCLS
DRAW " BM 1 28 t 8 6 i M - 1 28 1 - 86 i M+255 t + 2 "
GOTO 1 50
This is a relative move . (Please, no jokes about the proximity of
mothers-in-law . ) The format for this type of relative move is
(B)M + -XD , + -YD , where XD is the number of units to move in the X
direction and YD is the number of units to move in the Y direction. The
sign indicates the direction
' ' + is right for X and down for Y and
-
' '
1 24
"-" is left for X and up for Y. The displacement value will be added to
the current cursor position, and the result will define the new point. The
Y positive sign is optional in the above format; it's probably best,
however, to always use a plus or negative sign when working in this
format to avoid confusion.
In the above program , BM 1 28 ,96 moved to 1 28 ,96 without writing
a line. The next Move was M - 1 28 ,-96 which gave the new value
1 28 - 1 28 , 96 - 96, or 0, 0. The next Move was M + 255 , + 2 which
gave the new value 0 + 255 , 0 + 2, or 255 , 2. You can look at the
relative displacements, then, as either being added to the current cursor
position, or moving in a " + " direction or "-" direction for X or Y.
Figure 7. 3 shows the movements.
1 4 0 D R A W " BM 12 8 , 9 6 ; M - 1 2 8 , - 9 6 ; M + 2 5 5 , + 2 "
• ( 1 2 8 , 96 )
B M 1 2 8 , 9 6 POSITIONS
I M A G I NARY C U R SO R
9 6 - 96 = 0 = Y
_....
_
_
_
_
_
_
_
128 - 1 2 8 = 0 = X
( 1 2 8 , 96 )
M - 1 2 8 , - 9 6 DR AWS T H E L I N E FROM
T H E C U R R E N T CURSOR POSITION AT ( 1 2 8 , 9 6 )
T O ( 1 2 8 - 12 8 , 9 6 - 9 6 ) O R ( 0, 0 )
Using the DRA W Command
-
1 25
( 2 55, 2 )
( 128, 9 6 )
M + 2 5 5 , + 2 D R AW S T H E L I N E F R O M
T H E C U R R E N T C U R S O R POS I T I O N A T ( 0 , 0 )
TO ( 0 + 2 5 5 , 0 + 2 ) O R ( 2 5 5 , 2 )
Figure
7.3:
M command using relative motion.
Other Motion Commands
The other motion commands are all relative commands that specify a
relative displacement from the current cursor position. (Remember that
the cursor is imaginary - it doesn't show up and we ' re using it only for
convenience . ) Up, Down, Right, and Left are easy to remember, as the
first letter of each direction is used as an abbreviation for the command.
E, F, G, and H fill in the gaps between these directions as shown in
Figure 7 .4 .
These commands allows u s to easily specify movement i n eight
directions. Since much graphics will involve drawing lines in this
fashion, they are much more convenient to use than specifying a new
Move command for each line segment. Suppose , for example, that we
wanted to draw a large letter " M " in the center of the screen, as shown
in Figure 7 . 5 . We could draw it very easily by using the DRAW motion
commands:
1 00
1 10
1 20
1 30
1 40
REM DRAW EXAMPLE 3
MODE 3 1 1
SCREEN 1 1 0
PCLS
DRAW " BM 1 28 1 96 i E 1 5 i R 1 0 i D30 i L 1 2 i
U 1 8 i G 1 3 i H 1 3 i D l B i L 1 2 i U30 i R 1 0 i
F15"
1 50 GOTO 1 50
1 26
U(Pl
------
L ( EFT l
R ( IGHT
�STARTI
N
G
POINT
O(OWNl
E (45°)
POINT
+--
H (315°)
F( !35°l
G(225°l
Figure
7.4:
RIO
Other motion commands.
RIO
Fl5
U30
Hl3 Gl3
Ul8
Ll2
Figure
l
7.5:
Ll2
Using the motion commands.
AT 128, 96
Using the DRA W Command
127
About the only difficulty in using the DRAW motion commands is
that the commands that specify motion in acute angles are referenced to
the number of pixel units displaced horizontally or vertically . Remember
that the number of units of length for a line drawn at a 45 degree angle is
approximately 1 . 42 times the length of a vertical or horizontal line with
the same displacement along the Y or X direction . See Figure 7 . 6 .
The M command can easily b e used to connect to any horizontal or
vertical line, since you need only to know the horizontal or vertical
displacement rather than the actual length of the angled line.
" D RAW
-
-
-
-
E5 ; "
-
- - - -
�---
ACTUA L L E N G T H
OF L I N E I S
1 .4 2 * 5 • 7.07 U N I T S
Z}
5
------Figure 7.6:
5 UNITS
------
Acute angle displacements .
The Blank Command
We saw the use of the Blank command used as a prefix for the
Move command to effect a move without drawing a line . The " B " prefix
may also be used before any motion command to blank out a line . Simply
tack it on before the command as in " B H 1 5 ; " in the above program . The
line will still be drawn, but it will be blank . (Some of you will be able to
relate this to the philosophical question about a tree falling in the woods
with no one around . If a line is DRAWn with a B lank prefi x , is it really
drawn?)
128
An alternative way to use the B lank command is to use the B
command separately, without prefixing another command. An example
from above is
1 40 DRAW " B M 1 28 1 88 i E 1 5 i R 1 0 i D30 i L 1 2 i
U 1 8 i G 1 3 i B i H 1 3 i D 1 B i L 1 2 i U30 i R 1 0 i
F15"
The Color Command
The C command is used at any time in the DRAW string to change
the color of the following line. The format of C is
Cx
where x is a standard color code from 0 through 8. The Cx command is
embedded in the string just as the other commands are, with a semicolon
following the Cx.
Using the M program from above, you can alternate colors on the
l ine segments quite easily. As with all graphics , you have only the four
colors of the color set to play with in PMODE I or PMODE 3 .
1
1
1
1
1
00 REM DRAW EXAMPLE 3
1 0 PMODE 3 1 1
20 SCREEN 1 1 0
30 P CL S
40 DRAW " BM 1 28 18G i C2 i E 1 5 i R 1 0 i C 1 i
D30 i L 1 2 i C2 i U 1 8 i G 1 3 i C3 i H 1 3 i D 1 8 i
C4 i L 1 2 i U30 i C2 i R 1 0 i F 1 5 "
1 50 GOTO 1 50
The colors for the M are as shown in Figure 7 . 7 .
C2 •YELLOW
C2
c.,,
z
w
w
a:
to
u
..,
"
c:;
N
u
FigC4•RED
ure
7.7:
Using the color command.
Cl
Using the DRA W Command
129
Once a color is specified by the C command, it will remain in force
until the C command is encountered .
The No Update Command
The N, or No Update command, is another optional command that
may be used similarly to the B command, either as a prefix to a motion
command or as a separate command delimited by a semicolon.
The N command allows the next motion command to be executed
but prevents it from updating the cursor position. In other words, the next
line is drawn , but the cursor remains at the beginning of the line after the
line is drawn , as shown in Figure 7 . 8 .
DRAW "U40;
"ND20·
130120110 DRAW
DRAW
"R30;"°R30""
BEFORE
' CURSOR"DRAW ND20;'
e
n,,
,
U40
I
U40
Figure
7.8:
AFTER "DRAW ND20; "
R30 R30
D20
AFTER "DRAW R30;"
Using the N command.
We can see how the N command works in displaying a giant asterisk
in the center of the screen, as shown in Figure 7 . 9 . Both forms of the N
command, the prefix and separate command, are used.
130
1 00 R E M D R A W EXAMPLE 3
1 1 0 PMODE 3 d
1 20 SCREEN 1 1 0
1 30 PCLS
1 4 0 D R A W " B M 1 2 8 1 8 B i N U ll 0 i N R 2 B i N R ll 0 i
N F 2 8 i N D ll 0 i N G 2 8 i N l ll 0 i N H 2 8 "
1 50 GOTO 1 5 0
Figure
7.9:
N command example.
The Angle Command
The A, or Angle command, is somewhat of a misnomer. It is really
a rotate command. The format of the command is
Ax
where x is 0, 1 , 2 , or 3 , specifying rotations of 0 degrees , 90 degrees ,
1 80 degrees , or 270 degrees. When the command is invoked, all
subsequent lines will be rotated to the new position.
To see how this works , look at the program below . The figure in the
normal position is shown in Figure 7 . 1 0 . It is drawn by "BM 1 28 ,96;
U70; R20; D20; L20" . The program draws four versions of the figure by
using four A commands . The first A command, "AO" , displays the
Using the DRA W Command
131
figure in the 0 degree position. The ' ' A 1 ' rotates the figure 9 0 degrees
clockwise and displays it. The "A2" rotates the figure 1 80 degrees and
displays it. The ' A 3 ' ' command rotates the figure 270 degrees and
displays it. The final display is shown in Figure 7 1 1
'
'
.
Figure
Figure
7. IO:
Angle command example 1 .
7. 1 1 :
Angle command example 2 .
.
132
1 00 REM ROTATE PROGRAM
1 1 0 PMODE 3 1 1
1 20 S C R E EN 1 1 0
1 30 PCLS
1 40 A$= B M 1 28 1 8 6 j U70 i R 20 ; o20 j L20 "
1 50 DRAW " A0 " +A $
1 60 GOSUB 1 000
1 70 DRAW " A 1 " +A$
1 80 GOSUB 1 000
1 80 DRAW " A2 " +A$
200 GOSUB 1 000
2 1 0 DRAW " A3 " +A$
220 GOSUB 1 000
230 GOTO 230
1 000 FOR I = 0 TD 1 000 : NEXT I
1 0 1 0 RETURN
II
The subroutine in 1 000 causes a slight delay between each rotation .
Each DRAW command is a combination of a fixed string A$ defining the
figure and an A command in a string. The two strings are concatenated to
form one string that is executed by each DRAW command .
The last angle used in the A command is in force until the next A
command is executed. An AO will reset the display to its normal 0 degree
orientation .
STRINGS AND SU BSTRINGS
Before we discuss the next command, the X command, let ' s review
what we know about strings and their use. A string is nothing more than
a collection of bytes . Many times these bytes represent text characters in
ASCII format as in the string ' ' THIS IS A STRING' ' . In other cases, the
string may represent non-ASCII codes by using the CHR$ command , as
in A$ = 'C HR$( 23) + CHR$(25 ) , which sets string A$ equal to two bytes
made up of 23 and 25 . We won 't be using the second format of strings in
the ORA W commands, where all of the data will be character data
representing the ORA W commands found in Table 7. I .
A string defined by a statement such as
1 00 A$= " TH I S
I S A STR I NG "
is a constant string. Any time A$ is referenced, it will contain the same
data.
Using the DRA W Command
133
Strings can be concatenated , which is a fancy term for appending
one string to the end of another string. When this is done, a new string is
created . This new string may become a constant string or may simply be
temporarily stored. C$ below is a constant string of ' 'THESE ARE THE
PROGRAMS THAT TRY MEN ' S SOULS " , while the temporary string
of ' ' FIFfY FOUR FORTY OR FIGHT' ' disappears after it is displayed .
1
1
1
1
1
1
00
10
20
30
40
50
A$ = " THESE ARE THE PROGRAMS
B $ = " THAT TRY MEN ' S SOULS "
C$=A$+B$
D $ = " F I FTY - FOUR FORTY
E $ = " 0R F I GHT "
PR I NT C$ , D$+E$
"
II
A substring in reference to the DRAW commands (a DRAW
string?) means any constant string that has been defined previously and
can be denoted by a string label, such as A$, 8$, or Z l $ . A substring for
DRAW may move to a new position, draw a series of lines , or change
the color, j ust as we have seen in the above examples .
A substring may be cal led from within a DRAW string by means of
the X command , execute substring. This means that one string can
reference another string which can reference another string which can
reference another string, and so on. When these strings define graphics
figures, a whole series of modules may be made up to perform various
graphics functions . We ' l l show you what we mean in the next program .
The program below draws a modest skyscraper, shown in Figure
7 . 1 2 . It uses several substrings to perform the graphics . String A$ defines
a " window draw " of right 8 , down 20, left 8 , and up 20, as shown in the
figure . String 8$ executes the window draw by "XA$" and then moves
the cursor over to the right 1 4 positions in preparation for the next
window . String C$ executes string 8$ by "X8$" three times, so it draws
three windows and then moves over left 24 positions and down 24
positions in preparation for the next floor. String D$ executes string C$
to draw a floor of windows five times to draw the entire five floors of
windows .
1
1
1
1
1
1
1
00
10
20
30
40
50
60
REM DRAW THE TANDY TOWER
P MODE 3 1 1
SCREEN 1 10
PCLS
A $ = " R8 i D20 i LB i U20 "
B $ = " >< A $ i B R 1 4 "
C $ = " )< B $ i )<B $ i >< B $ i B L 4 2 i B D 2 4 "
134
1 70
180
1 80
200
210
D $ = " ){ C $ i }( C $ i ){ C $ i }( C $ i X C $ i "
D R A W " B M 8 ll 1 3 G i R 5 0 i D 1 2 4 i L 5 0 i U 1 2 4 "
D R A W " B M 1 0 0 1 4 0 i }( D $ i "
D R A W " B M 8 ll 1 3 G i B R 2 5 i U G 0 i F 8 i G 8 i
GOTO 2 1 0
II
p
DOD
DOD
ODD
DOD
ODD
Figure
7 . 12:
) 0$
(4
C$
DRAWS )
D D D = c$
�
�
Using strings and substrings.
The actual drawing starts with line 1 70, which draws the building
outline. Line 1 80 moves the cursor to 1 00,40 and then executes string
XD$ to draw all of the windows. Line I 90 adds a flag to the top of the
building .
There were five levels of graphics here ! This simple example
doesn't do the X command justice. Graphics can be shortened drastically
whenever repetitive designs have to be drawn; they can be defined by a
substring and executed at any time. Submodules of designs can easily be
defined and used as building blocks to draw composite pictures . A very
powerful command!
SCALING UP AND DOWN
We're leaving the best commands until last. Scaling is another very
powerful feature of the DRAW command . It's implemented by the S
option . The format of S is (another complicated one)
Sx
Using the DRA W Command
135
where x is a value from l to 62 indicating the scale factor as shown in
Figure 7. 1 3 .
1/4 SIZE
��ORMAL"
SIZE
,/
Figure
7 . 1 3:
4
fil_ SIZE
Scale factor.
As you can see from the figure , scale factors from 1 /4 to 62/4 are
possible. Scale factors under 4/4 result in displays that are less than the
dimensions as defined in the ORA W; scale factors greater than 4/4 result
in enlarged displays.
To see how this works, look at the program below . It generates an
oddly shaped figure (see Figure 7 . 1 4) vaguely reminiscent of a Space
Shuttle in need of maintenance . The figure is defined by the A$ string,
which assumes a starting point in the midpoint of the figure . The actual
DRAW command is in line 1 60, which uses a blue color ( " C 3 " ) and
starts at 1 28 , 1 36 . The figure is drawn by executing the B$ string
followed by XA$.
00 R E M AN I MA T I ON BY S COMMAND
1 0 PMODE 3 d
20 SCREEN 1 '0
30 PCLS
LI 0 A $ = 11 B L B i R 1 6 i 0 1 ; L 1 6 i U l ; B R 6 i
R 2 i u a ; O Li i R 2 i D L! 11
1 50 FDR S = l T D 62
1 6 0 B $ = 11 S 11 + S T R $ ( S )
C 3 ; B M 1 2 8 ' 1 3 6 ; ){ 5 $ ; )< A $ ;
1 70 DRAW
1
1
1
1
1
II
II
ua ;
136
1 80
1 90
200
210
F O R I = 1 TO 9 9 / S : N E X T I
DRAW " C 1 ; BM 1 28 ' 1 36 ; XB$ ;
N E )< T S
GOTO 2 1 0
)-(A $ ;
II
H EA D - O N V I E W
O F SPACE SHUTTLE
( US E YOUR I M A G I NATION ! )
=1L
)
STA R T I N G POINT
Figure
7 . 14:
Scale factor example.
The B$ string is a constant string made up of ' ' S ' ' and the
equivalent string value of the numeric variable S. The STR$ function is
used to convert the numeric variable S to a string which is then
concatenated with " S " to form "S 1
"S 2 " , and so forth .
The B$ string sets the scale factor which ranges from l to 62 in the
loop from line 1 40 through 1 90 .
After the figure is drawn i n statement 1 60 , a short time delay that
decreases with larger scale factors is done in line 1 70 . Larger scale
factors generate larger figures that take longer times to generate . After
the time delay, the figure is erased by a second DRAW line that uses the
background color ( ' ' C l ' ' ) . The effect is of a figure getting larger and
larger on the screen.
The S command can be used any time that a figure must be reduced
or expanded - animation is just one use .
"
,
Using the DRA W Command
N OTES
137
[
Using the PAINT and GET/PU T Commands
139
CHAPTER 8
Extended Color BASIC : Using the PAINT and
G ET/PUT Commands
In this chapter we' II discuss the last three Extended Color BASIC
graphics commands: PAINT, GET, and PUT.
PAINT is used to fill in areas with a specific color very similar to a
paint-by-numbers technique. PAINT will color an area with any color in
the current color set (two or four colors) up to a boundary of another
specified color.
GET/PUT are two associated commands. They must be used
together. GET moves any screen area from the screen memory into an
array . A fter the move, the array holds the graphics data from the screen
area for as long as the user desires . The graphics screen may now be used
for other displays.
At some later time, the PUT is used to move the array data back
onto the screen at any user-specified area. As the areas may be different ,
GET/PUT can be used for animation and other graphics techniques .
T H E PAINT COMMAND
The PAINT command format is
PA I NT
( X 1 Y l 1 C 1B
where (X, Y) is a standard graphics coordinate with X = 0 through 255 and
Y = O through 1 9 1 . C is the color to be painted; B is the boundary color
for the PAINT.
140
The operation of PAINT is shown in Figure 8 . I , where a figure has
been drawn in PMODE 3 with one color. The graphics in this case were
generated with a series of DRAW commands, but similar figures could
have been generated with LINE, CIRCLE, or other commands. All of
these commands , with the exception of LINE BF, produce an outline of a
figure , but not a filled-in color. PAINT can be used to fill in any area.
The area to be filled in is first defined by means of the (X, Y)
coordinate . This coordinate can be anywhere within the confines o f the
area to be PAINTed. The C value specifies the color for the PAINT. This
�� � �
E I NBEASC��ROUN D
-------
R40
,BFlO
' R20
( 120,1TO00)BEIS
AREATNHITEDNTOI NIBENERS 3,PAIBOX.ORN TED.BLUE.COLOR
U40 U20
D20 WIPAIBOUNDARY
COLOR IS 4, OR RED.
D40
L20
L40
100,80'
e
GREEN
GREEN
GREEN
GREEN
GREEN
Figure
RED LI N ES
8.1:
PAINT example.
Using the PAINT and GET/PU T Commands
141
color can b e any one in the current color set. I n the four-color mode this
will be one set of four colors; in the other PMODES , this will be one set
of two colors . As with other graphics commands , a color out of the color
set can be specified, but the color value will be converted to a color in
the current set.
The B value is the boundary color. Here again, this must be a color
in the current color set. It may be the same as the color value to be
PAINTed.
The program below PAINTs one area in the figure .
1 0 0 R E M P A I N T E >( A M P L E
1 1 0 PMODE 3 t 1
1 20 SCREEN 1 10
1 30 PCLS
1 4 0 D R A W " B M 1 0 0 1 8 0 i R ll 0 ;
B F 1 0 i R20 i 020 ; L20 i
1 5 0 P A I N T ( 1 2 0 ' 1 0 0 ) 1 3 1 ll
1 60 GOTO 1 60
040 ;
U20 i
L ll 0 ;
U ll 0 ;
In the example above, the foreground color default was red on a
green background and the two concentric boxes were drawn with a red
color. The boundary color chosen in the PAINT command was also red
(4) . The color to be painted was blue ( 3 ) . As the area to be painted was
smal l , the PAINT seemed almost instantaneous.
Suppose that a PAINT was done with a gap in the boundary , as
shown in Figure 8. 2. Here, the paint leaks out of the boundary, first into
the outer box area and then into the area beyond the outer box . Finally,
the entire screen is PAINTed ! The point here is that the boundary area
must be well defined with no gaps or discontinuities or this type of
problem will occur. (Best to check the insides of your TV if you see this
occurring - video paint can be extremely corrosive . )
PAINT will leak in from outside a boundary also . If the PAINT start
point were specified out of both boxes in Figure 8 . 2 , say at 1 , 1 , the result
would have been the same .
Another thing about the PAINT of Figure 8 . 2 is that it takes a much
greater time than other Extended BASIC commands due to the filling-in
nature of the command. The time required to PAINT an area of one-half
the screen is about 4 seconds , a considerable time for any processing
operation .
Note also in Figure 8 . 2 that a PAINT proceeds in segments . In this
case the PAINT was done in about six or seven segments, each with an
unpredictable direction . (Actually, with a very predictable direction in
terms of a computer algorithm, but not very predictable in terms of using
the PAINT command . )
142
GAP !
�::�,�·:;,� ""'°
� ''"''''' ' ' ' '
..----_-_-_-_-_-_��
�-1 I
I -�
.. , , ,
"" "'"· ' · .
( PA I N T B L U E U N T I L R E D
'
Figure
8.2:
''"
''
'
'
Leaking PAINT.
As with all Extended Color BASIC commands , PAINT works only
with the colors in the current color set. If other color codes are specified ,
they are converted to a code in the current set. Specifying an 8 for the
PAINT color in the programs above would have had the same result as
specifying a 4 .
Another condition t o watch for i n PAINT i s that the start point is i n
the proper area t o be PAINTed. Suppose that we have the same figure as
Figure 8 . 1 but that we had specified an inside boundary color of yellow
(C2). The PAINT would proceed from the inside of the inner box out and
paint over the yellow boundary, as shown in Figure 8 . 3 . Ofcourse, if
this is planned, it's fine , but if not, the PAINT will obliterate all areas
except the one beyond the designated boundary .
Using the PAINT and GET/P U T Commands
Lq"
.--- -/i
�/
--., I i
GREEN
Y E L LO W
LINES
RED LI N E S
- PA I N T
GREEN
143
( 120, 100
),
3, 4
•
GREEN
GREEN
GRE E N
Figure
8.3:
PAINT boundaries.
THE G ET AND P UT COMMANDS
The last two commands are probably the most powerful (and most
complicated) in the Extended Color BASIC set. GET and PUT must be
used together. GET defines an area of the graphics screen and stores it in
an array while PUT retrieves the data from the array and puts in onto a
designated area of the screen.
The GET/PUT action works in the simplest case as shown in Figure
8 . 4 . The screen data in the GET rectangle is stored in array Z. During the
execution of the PUT statement, the data is taken from array Z and
displayed in the PUT area.
GET and PUT can be used to replicate figures in different places on
the screen or to produce animation effects. Before we get into the details
144
of GET/PUT, let ' s run a simple example.
The program below replicates (reproduces) the upper left-hand
figure at three other screen areas by one GET and three PUT statements ,
as shown in Figure 8 . 5 .
R E CTA N G L E D E F I N E D
BY GET STAT E M E N T
A R R AY Z
TWO - D I M EN S I ON A L A R R AY
D E F I N E D BY D I M A N D
R E F E R EN C E D BY G E T , PUT
STATE M E N T S
'"'""' ""'" I I
BY
Figure
8.4:
PUT STAT E M E N T
GET/PUT action.
�
4,/,1
Using the PAINT and GET/PU T Commands
1 00
1 10
1 20
1 30
1 LI 0
1 50
1 80
1 70
1 80
1 90
200
REM S I M PLE USE OF GET/ PUT
D I M A ( 1 9 t 39 l
PMODE 3 t 1
SCREEN 1 t 0
PCLS
DRAW
B M 8 LI t 4 0 ; E 1 0 ; F 1 0 ; D 2 9 ;
U29 "
G E T ( 8 Li t 3 0 l - ( 8 3 t 8 9 l t A
PUT ( 1 98 t 30 l - ( 2 1 5 t 89 l t A
P U T ( 8 Ll t 1 2 2 l - < 8 3 t 1 8 1 l t A
PUT < 1 98 t 1 22 l - ( 2 1 5 t 1 8 1 l t A
GOTO 200
II
�" G E T "
/
D
"PUT "
0
Figure
8.5:
'\
145
L20 ;
T H IS RECTA N G L E
UT "
0
11 PUT 11
0
GET/PUT example.
The GET command defines a rectangle in the same fashion as LINE .
The upper left-hand comer is (64 ,30) and the lower right-hand comer is
(83 , 69). The GET command stores the contents of the rectangle in
two-dimensional array A , previously defined by the DIM A( l 9 , 39) array .
The three PUTs read the array into the three rectangles defined .
Arrays
To understand the GET/PUT statements , we need to know a little
more about arrays . Arrays are structures to hold data. Data within the
array is referenced by an element number within the array . A
one-dimensional array holds each piece of data one after another in list
146
r
NAME OF A R R AY IS " z z "
1 00 D I M Z Z ( 1 0 0 )
\.._ DEFI NE S
A R R AY
OF 1 0 1 E L E M E N T S
5
ZZ ! O l
ZZ
I Jl
J22
zz ( 2 )
J3
zz 1 3 )
-JO
zz
(4 )
8
ZZ 1 5 l
556
ZZ ( 6 )
JO, 0 0 0
zz (7)
17
zz (8 )
2
A • ZZ ( 5 ) S E T S
VAR IA B L E A TO
CONTENTS OF 6th
E L E M E N T OF AR RAY
ZZ, OR 5 5 6 .
..
" "" � '""'" r
ZZ 19 9 )
J
ZZ (JOOl
-J
�
Figure
"ASCEND I NG " ELEMENT
N UMBERS FROM 0 TO JOO
8.6:
One-dimensional array.
form . An element within the array is referenced by one element number,
as shown in Figure 8 . 6.
A two-dimensional array is arranged in two directions, as in a chess
board . Elements within the array are referenced by two element numbers,
as shown in Figure 8. 7. Arrays of three or more dimensions are possible.
Arrays are set up by a DIMension statement. The DIM statement
simply allocates storage for the array - it sets aside a block of RAM
memory locations based upon the dimensions of the array .
Nothing is put into the elements of the array after the execution of
the DIM statement - the BASIC interpreter simply knows where to find
the array when references are made to it. The form of the DIM statement
for a two-dimensional array is
D I M X < N 1M )
where N is one less than the ' ' X ' ' dimension of the array , and M is one
less than the " Y " dimension of the array . "X" is the name of the array ,
Using the PAINT and G E T/PU T Commands
r
147
NA ME OF ARRAY IS " z z "
\_
1 00 D I M ZZ ( 4, 9 )
Z Z ( O, O l
�
DEF I N E S " X " D I M E N S I O N A S
0 - 4 , 0 R 5, A N D Y D I M E N S I ON
AS 0- 9 , O R 1 0
0
-1
18
10,000
5
17
-- z z <4. 0 l
l
-5
3
32,000
-18,000
16
..- Z Z ( 4 , l l
2
13
5
5
5
-- z z < 4. 9 l
2
3
10
E L E ME NTS
"
y"
4
5
6
8
9
z z ( 0 , 9)
�
0
3
4
�-----�----------'
5 E L E M E N T S " x"
A • ZZ ( 0 , 9l S E T S VAR I A B L E A
TO THE C O N T E N T S OF ( 0, 9 l
E L E M E N T O F A R R AY Z Z , O R 2.
Figure
8.7:
Two-dimensional array.
a one- or two-character name identical to a BASIC variable-name format .
An array that represents a graphics screen rectangle of width 1 5 by
height 1 0 could be set up by
D I M AA ( 1 4 18 )
Arrays are referenced by element number or numbers , depending
upon the number of dimensions . To store a 55 in the first element of the
AA array , we could do
AA ( 0 1 0 ) =55
Note that the index numbers for the array start with 0 and run
through to the last dimension number. In the case above we'd have
element numbers from 0 through 1 4 for X and 0 through 9 for Y . To put
numeric values of 0 into the entire array, we'd have
148
1 00
1 10
1 20
1 30
1 ll 0
1 50
1 80
REM SETUP AND CLEAR ARRAY
D I M A A < 1 ll 1 8 )
F O R ){ = 0 T D 1 ll
FOR Y = 0 TD 8
A A ( ){ 1 Y l = 0
N E )< T y
N E )< T )-(
One of the reasons arrays are used is to be able to represent one-,
two-, or three-dimensional arrangements of data that occur in the
real-world in computer form. Two-dimensional arrays are almost ideal
for processing the X and Y coordinates of the graphics screen . One
element number of the array represents the X coordinate , while the other
represents the Y coordinate .
We say almost ideal because Color Computer BASIC arrays have
one fault in regard to storing graphics data. Each element in an array
takes 5 bytes of storage space in RAM . An array of 1 5 by I O elements ,
then, has 1 5 x 1 0 , or 1 50 total elements, each one occupying 5 bytes .
The total number of bytes is 1 50 x 5 or 750 bytes, all to store 1 50
graphics elements .
On the other hand , utilizing an array in this fashion can be done
rapidly. We're really sacrificing storage for speed , and graphics speed is
probably most important.
You can see how much storage is allocated by an array or other
variable types by using the MEM command. The MEM command returns
the number of free RAM bytes available at any time. After SYSTEM
initialization and before any BASIC program is entered, for example, the
MEM command can be used like so
DK
PR I NT MEM
B ll 8 7
The MEM command returned the number of free RAM bytes for a
1 6K-RAM system with Extended Color BASIC . After adding some
BASIC code we get something like the following:
DK
1 00 REM TEST AVA I LABLE RAM
1 1 0 D I M A A < l ll 1 8 )
PR I NT MEM
B ll ll 7
Using the PAINT and G E T/PU T Commands
149
The difference between the two values of available RAM is
8487-8447, or 40 bytes. This difference is equal to the storage required
for statements 1 00 and 1 1 0. The statements are stored in a compressed
form for BASIC commands with most of the text data intact. Some space
is required for line numbers and pointers. Note that at this point we
haven't executed any BASIC statements yet and that the DIM statement
for array AA hasn't been processed . At this point the BASIC interpreter
is unaware of the array requirements. Now we'll execute the two
statements:
1 00 REM TEST AVA I LABLE RAM
1 1 0 D I M A A C l Ll 1 9 l
RUN
OK
PR I NT MEM
7888
OK
What we' ve done at this point is to execute the REM and DIM
statements . The REM statement had no effect on available RAM . The
DIM allocated space for array AA. The difference between 8447 and
7688 is the space allocated, plus a few bytes for array variable name and
pointers. The difference is 759 bytes , 750 bytes of space for the array
proper and 9 bytes for name and pointer.
The absolute maximum RAM space we have available in a I 6K
system with four graphics pages (default value for PCLEAR) is 8487
bytes . (PCLEAR I to 3 will provide additional RAM space . ) This
represents array storage of 8487/5 or 1 699 elements . With the proper
array allocation, up to 64 ,000 points can be stored in an array during
GET and PUT.
THE GET STATEMENT
The format of the GET statement is
GET
< XI 1 Yl l
-
C X2 1 Y2 l 1A 1 G
The first two sets o f parameters define a rectangle in a manner
similar to the LINE command. The upper left comer is specified by
(Xi , YI ) and the lower right comer is specified by (X2 , Y2 ) . The A
parameter is the name of the array into which the graphics data is to be
150
stored . This array must have previously been specified with a DIM
statement. The G parameter specifies full graphic detail and is optional .
When the GET is executed, the graphics data in the display
rectangle is moved into the array named in the GET. It remains there
forever, unless the array is changed in the program (which should not be
done) . The graphics data is stored in compressed form. There are either
4, 8, or 1 6 graphic elements in each byte of the array . We used an array
with the same dimensions as the graphic block in an earlier example, but,
in fact, we could have cut down on the array requirements considerably .
To make the most efficient use of array storage for GET, allocate an
array using a DIM statement of
D I M A < 0 1X )
where A is the array name and X is a number based on the number of
graphic elements, PMODE, and "G" option . To find X,
I
Find the number of elements in the graphic GET statement. If
the statement is GET (20 ,40)-(40,60) , for example, the number of
graphic elements is 2 1 x 2 1 or 442.
2. If you have specified the "G" option, divide this number by 8
if in PMODE 3 or 4, by 1 6 if in PMODE 1 or 2, or by 32 if in PMODE
0. The result, rounded to the next higher integer, is the number of bytes
required . If you aren 't using "G" , divide by 1 6 if in PMODE 3 or 4, 8 if
in PMODE 1 or 2, or 32 if in PMODE 0. The result, rounded to the next
higher integer, is the number of bytes required . If we had been in
PMODE 3 with a "G" option for GET (20,40)-(40 ,60) , for example,
we'd have 442/8 = 52 6/8 . This number rounded to the next higher
integer is 5 3 . A total of 53 bytes is required.
3. Now take the number of bytes required and divide by 5. This
number, rounded up to the next higher integer, is the X to put in the DIM
statement. In the example we've been working with we ' d have
53/5
1 0 3/5 , rounded up is 1 1 . The DIM statement would therefore be
DIM A(O, 1 1 ) . That ' s quite reasonable in terms of storage compared to
DIM A(20, 20), which would take up 1 2 1 0 bytes!
.
=
Of course , you can leave the DIM statement at the size of the
graphics area, but why waste space? The steps in figuring out the value
for the DIM statement are shown in Figure 8 . 8 . It's worth the trouble.
The array allocated is a two-dimensional array that really looks like a
one-dimensional array (say , what?) , as the X width is 1 (0 + I ) .
Using the PAINT and GET/PU T Commands
151
P M O D E 3, 1
G E T ( 42 , 4 2 ) - ( 10 6 , 106 ) , A , G
D
�
Z Z (O , 1 )
z z co. 106)
Figure
F I N D E L E M E NT S I N G E T
G E T ( 4 2 , 4 2 ) - ( 10 6 , 106 )
( 1 0 6 - 4 2 + 1 ) * ( 10 6 - 4 2 + l ) •
6 5 * 6 5 · 4225
2 .-
F I N D D I V I SOR :
I F "G " USE 8 I F PMODE
3 OR 4 ; 1 6 IF PMODE
1 O R 2 ; 32 IF P M O D E 0
I F NOT " G " U S E 1 6 I F PMODE
3 OR
8 IF PMODE
1 OR 2 ; 32 IF PMODE 0
422 5 / 8 • 52 8 1 1 8
5 2 8 1 / 8 ROU N D E D U P
IS 529
D I M Z Z ( 0, 106 )
ZZ (0,0)
STEPJ.STEP
t-------;
t-------;
STEP
4;
3.-
F I N D D I M VA L U E :
5 2 9 / 5 • 105 415 ,
R O U N D E D UP I S
106
I>------<J
8.8:
Calculation of minimum array for GET/PUT.
THE PUT STATEMENT
The PUT statement format is somewhat similar t o the GET
statement
PUT
< Xi t Yi l
-
< X2 t Y2 ) tA t A C T I O N
where Xi , Yi is the upper left comer of the destination rectangle and
X2 , Y2 is the lower right comer of the destination rectangle. A is the name
of the array used in the GET statement. ' ' ACTION ' ' is an optional action
to be taken if the " G " option has been used in the GET statement. We'll
discuss the ACTION operations in a moment.
The PUT accesses the array used in the GET (there may be more
than one GET, each with a different array) and stores the graphics data
152
found there in the area specified by the PUT. There must be enough roorr
in the PUT area to store all of the elements from the GET. In general , the
PUT should specify the same size rectangle as GET, although it' s
possible to play some games here and get partial data.
ACTION Items
If you 've used a "G" option in the GET, then you must use one of
the ACTION items in the PUT; otherwise you may have garbage on the
screen .
The PSET (sound familiar?) action items transfers the rectangle
defined in the GET with all colors and points set in the same way . An
example is shown in Figure 8 . 9 ; the program below duplicates the block
in the figure .
1 00
1 10
1 20
1 30
1 40
1 50
1 80
1 70
1 80
1 80
Figure
8.9:
R E M PSET A C T I ON I TEM
D I M AA ( 0 188 )
'51*51 18/5
P M O D E LI 1 1
SCREEN 1 1 1
PCLS
L I NE ( 0 1 0 ) - ( 40 1 40 ) 1 PSET 1BF
L I NE ( 0 1 0 ) - ( 1 0 ' 1 0 ) 1 PRESET 1BF
GET ( 0 1 0 ) - ( 50 1 50 ) 1AA 1 G
P U T ( 2 0 5 t 1 li 1 ) - ( 2 5 5 t 1 8 1 ) 1 A A 1 P S E T
GOTO 1 80
PSET with GET/PUT.
Using the PAINT and G E T/PUT Commands
153
The PRESET option transfer the data but resets the points that were
set in the GET statement area. Adding statement 1 65 PUT
(205 , 1 4 1 ) - (255 , 1 9 1 ) , PRESET resets the PUT area directly after the
PSET, as shown in Figure 8 . 1 0 . The PRESET can be used to erase areas
on the screen.
Figure
8. 10:
PRESET with GET/PUT.
The AND option performs an AND operation on the points of the
original rectangle and the points in the destination area. If both the
original and destination points are set, the result will be set; if either point
is reset, the result will be reset.
The AND can be used to mask out certain areas of graphics .
The OR option performs an OR operation on the points of the
original rectangle and the points in the destination area. If one or the
other of the points is set, the result will be set. If neither is set the result
will be reset.
The OR can be used to guarantee that certain areas of graphics are
set to the foreground color.
The NOT option reverses the state of each point in the destination
rectangle; the contents of the array do not affect the operation but only
define the area of the destination rectangle to be processed .
Using the G ET/PUT Commands
Any number of GET commands, up to the limits of memory, may
be used by defining new arrays to hold the GET data. PUT commands
154
may reference any of the arrays in any area of the screen desired,
provided that the destination areas do not go across screen boundaries .
The PMODEs for the GETs and PUTs must correspond, otherwise
garbage may appear on the screen .
NOTES
Using the PAINT and GET/PUT Commands
N OTES
155
"'
Q
.
SECTION II
157
SECTION II
Programming Techniques for
Color Computer Graphics
The material in this section is designed as an applications
workbook. It is a compendium of graphics techniques for the
Color Computer and includes applications techniques for
both Color Computer BASIC and Color Computer Extended
BASIC. It includes short notes on such things as drawing
lines, squares, rectangles, triangles, filled-in figures, gray
shades, circles, ellipses, arcs, animation, and others.
The code in the applications should be used as a guide for
your o wn applications. It is not always "idiot-proof" and may
not work with invalid arguments. In many cases the speed of
the code may be increased by combining statements in a
single BASIC line; single statements lines are used here for
clarity.
The applications are presented in alphabetical order for easy
reference. The application notes are meant to be used as a
quick guide on how to implement a graphics problem, but
they are not a replacement for the more comprehensive
material in earlier sections.
SECTION II
List of Applications
Alphanumeric Characters in Graphics Modes
Arc, Drawing
Border Outline, Drawing
Circle, Drawing
Ellipse, Drawing
Intermixing Text and Graphics
Line, Any Angle, Drawing (Method 1 )
Lines, Horizontal , Vertical, or Diagonal , Drawing
Mode of G raphics, Changing
Moving Figures by G ET/PUT
Moving Figures by I ndexing
Octagon, Drawing
Other Colors in PMODE 4
Rectangle, Filled-In, Color BASIC
Rectangle, Fil led- In, Drawing (Method 1 )
Rectangle, Fil led- In, Drawing (Method 2)
Rectangle, Outline, Drawing (Method 1 )
Rectangle, Outline, Drawing, (Method 2)
Rotations of Figures
Semigraphics 8, Set/Reset
Semigraphics 1 2, Set/Reset
Semigraphics 24, Set/Reset
Square, D rawing
Start of Video Memory, Changing
Triangle, Drawing
159
SECTION II
161
1
Alphanumeric Characters in Graphics Modes
Description
Although Extended Color BASIC graphics modes do not permit
internally generated text characters , it is relatively easy to define and
generate character sets . One popular way of defining alphabetic,
numeric , and special characters is by a 5-by-7 dot matri x , shown in
Figure 9 . ALP. l . Characters are defined by dots of the matrix.
5
,,_,,..-..,-,--,,.E1
I
"
U S E B U F F E R ZON E "
T O S E PA R A T E C H A RA C T E R S
5
5
•
•x"
Figure
9.ALP.1:
•
7.
• ! u
Five-by-seven characters.
This concept can be used with the DRAW command to create text
fonts that may be displayed along with graphics patterns in Extended
Color B AS IC graphics modes. Any number of character sets may be
created , with any patterns , such as Japanese Kata-Kana characters or
other foreign or special characters .
When 5-by-7 dot-matrix characters are used , up to 42 characters
may be displayed horizontally (5 dots plus a buffer of one "off" dot) and
24 characters vertically. Larger matrices , such as 6 by 8 , will allow a
reasonable number of characters with better resolution.
When the characters are defined properly by a DRAW string, they
may be executed at any spot on the screen and may be increased or
diminished in size at w il l .
1 62
Sequence
Draw the character to be represented as a dot matrix. Now define the
character as a series of DRAW commands. Assume some constant
starting position , such as the upper left-hand corner position. Use the
smallest number of dots that will be displayed (e . g . , 5-by-7 dots) . The
DRAW string can now be executed by a DRAW command.
Example
Define and draw an "X" using a 5-by-7 dot matrix . The "X" is
shown in Figure 9 . ALP . 1 . It is defined by
:a = 11 0 1 ; F a ; o 1 r n L LI ; u 1 ; E a ; u 1 ; 11
The X$ string can now be used in a DRAW command, together with
such commands as Execute, Color, and Scale .
1 00
1 10
1 20
1 30
1 40
1 50
P M O D E LI , 1
SCREEN 1 1 0
)-( $ = 11 0 1 i F Ll i 0 1 i B L l! i U 1 i E l! i U 1 i 11
PCLS 1
DRAW
C 0 ; S L! ; II + )-( $
GOTO 1 50
II
Notes
1 . Use PMODE 4 unless you are working in large scale characters .
2 . B l ack o n green i s a good foreground/background color. Other
colors cause convergence problems and characters show up in multiple
colors.
SECTION II
1 63
2
Arc, Drawing
Description
This application draws an arc between any two points by using the
CIRCLE command of Extended Color BASIC. The arc drawn will
represent a hemisphere between the two points as shown in Figure
9 . ARC. l . The arc can be specified "concave up/concave left" or
" concave down/concave right" .
t)
" CON CAVE
UP"
"
CONCAVE
LEFT "
l
::
-)
( 16 0 , 72 )
" CONCAVE
R I G HT "
c-
S PE C I F I E
POINTS
( 101, 1 4 9 )
Figure
9.ARC . l :
1
,,.,....
-C I RC U L A R
ARC
DRAWN
"
C O N C AVE
DOWN "
ARC action.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Set C to the color to be used. Set
XI , YI and X2 , Y2 to the coordinates of the two points. Set D to 0 for
concave up/left or to 1 for concave down/right.
Use these commands:
1 00 X N = ABS C X2 - X l l / 2 : YN=ABS C Y2 - Y l l / 2
1 1 0 I F X 2 - X 1 < 0 THEN X M = XN+X2 ELSE XM = XN+X 1
1 64
1 20 I F Y 2 - Y 1 < 0 THEN Y M = Y N+Y2 ELSE Y M = Y N + Y l
1 30 X X = 0 : I F X2 = X 1 THEN X X = 90 : GOTO 1 50
lll0 JC< = A T N ( ( Y 1 - Y 2 l / ( )< 2 - >( 1 > ) * 5 7 . 2 9 5 8
1 5 0 JC< = 1 - JOU 3 6 0
1 60 I F xx+ . 5 } 1 THEN X Y = XX - . 5 ELSE X Y = XX+ . 5
1 70 I F 0 = 0 THEN C I RCLE
( J< M 1 Y M l 1 S Q R ( )< M * )< M + Y M * Y M l 1 C t 1 1 )0( 1 J< Y E L S E
C I R C L E ( )< M 1 Y M l , S Q R O( M * >( M + Y M * Y M l 1 C t 1 1 >( Y 1
1 80 GOTO
180
Example
Draw an arc between the points 50, 1 00 and 1 00,50.
80 P M O O E 3 1 1
82 SCREEN 1 10
84 PCLS
8 6 X 1 =50 : Y 1 = 1 00
X2= 1 00 : Y2=50
1 00 X N = ABS ( X2 - X 1 l / 2 : Y N = A BS ( Y 2 - Y 1 l / 2
1 1 0 I F X 2 - X 1 < 0 THEN XM= XN+X2 ELSE XM= XN+X 1
1 20 I F Y2 - Y 1 < 0 THEN YM= YN+Y2 ELSE YM=YN+Y 1
1 30 X X = 0 : I F X2 = X 1 THEN X X = 80 : GOTO 1 50
1 40 X X = ATN C C Y 1 - Y2 l / C X2 - X 1 l l *57 . 2858
1 5 0 ){ ){ = 1 - }( }( / 3 6 0
1 60 IF xx+ . 5 } 1 THEN XY=XX- . 5 ELSE XY = XX+ . 5
1 70 I F 0 = 0 THEN C I RCLE
( ){ M 1 Y M l 1 S Q R O ( M * }( M + Y M * Y M l 1 C t 1 1 )0: 1 ){ Y E L S E
C I R C L E O( M 1 Y M l 1 S Q R ( ){ M * l{ M + Y M * Y M l 1 C t 1 ,
1 80 GOTO
1 80
Notes
I
An error will occur if the center of the circle falls outside of the
screen limits . That is, if a full circle with the given points could not be
drawn, then the arc can not be drawn either.
2. The arc will be flattened if the center of the circle defining the
arc is within the screen limits, but a portion of the arc is out of the screen
l i mits .
.
SECTION II
1 65
3
Border Outli ne, Drawing
Description
This application draws a border outline by using the CIRCLE
command of Extended Color BASIC . The border is drawn in the
foreground color. It is assumed that the background color is green (color
set 0) or buff (color set l) so that the border outline is visible.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. PCLS the screen to a green or buff
color by PCLS l or PCLS 5 .
Use this CIRCLE command:
C I RCLE
< 1 28 1 8 6 ) 1 2 0 0 1C
The color used i s the color specified i n C .
Example
Draw a border in color set 0 with green background and red outline.
1
1
1
1
1
00 PMOOE 3 t 1
1 0 SCREEN 1 1 0
20 PCLS
3 0 C I R C L E ( 1 2 8 1 8 6 ) 1 2 0 0 i ll
Ll 0 G O T O 1 l'.1 0
1 66
4
Circle, Drawing
Description
This application draws a circle by using the CIRCLE command of
Extended Color B ASIC . The center of the circle, the radius , and color
code are defined in the command. The circle will be a complete circle
and not an arc .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use this CIRCLE command:
C I RCLE
( X 1 Y l 1R 1 C
The circle will be drawn with center at X,Y, a radius o f R , and a
color of C .
Example
Draw a circle of radius 20 at the center of the screen .
1 00 PMOOE 3 1 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 C I RCLE ( 1 28 1 88 ) 1 20 14
1 40 GOTO 1 40
SECTION ti
167
5
Ellipse, Drawing
Description
This application draws an ellipse by using the CIRCLE command of
Extended Color BASIC . The center of the circle, the radius, and color
code are defined in the command. The radius will determine the width of
the ellipse; the height will be determined by the height:width ratio.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use this CIRCLE command:
C I RCLE
< X 1 Y > 1 R 1 C 1HW
The ellipse will be drawn with center at X , Y, a color of C , a width
of 2 x R , and a height of 2 x R x HW.
Example
Draw an ellipse of width 1 00 and height of 50 at the center of the
screen .
1
1
1
1
1
00
10
20
30
40
PMODE 3 d
SCREEN 1 '0
PCLS
C I RCLE < 1 28 1 88 ) , 50 , 4 , , 5
GOTO 1 40
1 68
6
Intermixing Text and Graphics
Description
Alphanumerics and text can be intermixed only while in the normal
text display mode of Color BASIC or Extended Color BASIC . The
graphics display mode uses a separate graphics page that will not allow
internal generation of text characters . The text display mode allows both
internally generated text characters and limited graphics (64 elements
horizontally by 32 elements vertically) .
Because the four graphics elements of a character position are
contained in 1 byte in the text display mode , four graphics elements may
be defined by a single 8-bit value. This value may be treated as a single
character in a character string, or a series of these graphics characters
may be joined together in a longer string.
Alternativel y , the values defining the four elements of graphics may
be POKEd into the text display area from 1 024 through 1 53 5 .
Sequence
For each four graphics elements in a character position, do the
following:
1 . Determine the color for the elements . All elements in one
character position must be the same color, or black.
2 . Compute the value for the character position by
l,J
= 1 2 8 + ( C - 1 ) * 1 G +L3+L2+LI +LO
where C is the color code of 1 through 8 (green through orange) and L3 ,
L2 , LI , and LO correspond to the graphics element position as shown in
Figure 9 . INT . 1 . If L3 is to be on, L3 = 8; if off, 0. If L2 is to be on,
L2 = 4; if off, 0. If LI is to be on, LI = 2; if off, 0 . If LO is to be on,
LO = l; if off, 0 . If a black color (0) is to be used, all elements are off
and V = 1 28 .
3 . POKE the value V into the proper byte of the text display
buffer. The address for the POKE will be
SECTION II
V
L3
(8)
Ll
(2)
L2
(4)
•
1 2 8 + ( C - 1 ) * 1 6 + L 3 + L 2 + L l + LO
c • 0
1
2
3
4
5
6
LO
(J)
7
8
Figure 9.INT. l :
1 69
BLACK
GREEN
Y L LO
BLUE
RED
BUFF
CYAN
M A G E N TA
ORANGE
E
W
Graphics elements coding.
1 0 2 ll +L * 3 2 + CP 1
where L is the line number of 0 through 1 5 , and CP is the character
position of 0 through 3 1 .
4 . Alternatively , set a one-character string equal to CHR$(V) . The
resulting string can then be PRINTed @ or used in any other way a string
is used .
Example
Display " TEXT" bracketed on the left by a bar of blue and on the
right by a bar of red, as shown in figure 9 . INT. 2 .
z
�
f-­
U)
0
a..
"'
w
f-­
u
<I
� /\
B L U E BAR
B LA C K
[l rl E lxl rl
) (___�
B U F F BAR
Figure 9.INT.2:
Intermix of text and graphics example.
1 70
The graphics character position on the left is
l.I
1 = 1 28+2* 1 8+8+2
The graphics character position on the right is
t.1 2 = 1 2 8 + 4 * 1 8 + 4 + 1
The 6 characters can now be PRINTed by
1 00
P R I N T C H R $ < t.i 1 l + " T D( T " + C H R $ < t.1 2 l
or displayed by
P R I N T @ 2 5 8 + 1 8 1 " T E >( T " ;
POKE 1 024+258+ 1 5 1 V l : POKE
2 5 8 + 2 0 ' t.1 2
1 20 GOTO 1 20
1 00
1 10
1 024+
SECTION II
1 71
7
Line, Any Angle, Drawing (Method 1 )
Description
In this method of drawing a line using the LINE command of
Extended Color B ASIC , a start and end point for the line are determined .
The X and Y coordinates of the line are based upon the maximum graphic
resolution of 255 horizontal by 1 92 vertical elements . The two points
must be within the screen boundaries .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use the LINE command in the
following format:
L I NE
( X1 , Y 1 ) - ( X2 , Y2 ) , P S E T
This draws a line between points XI , Yl and X2 , Y2 . The start and
end points are included in the line. The color used is the current
foreground color.
Example
Draw a line between 24 ,30 and 1 28 , 5 5 .
1 0 0 P M O O E ll , 1
1 1 0 SCREEN 1 ,0
1 20 PCLS
1 3 0 L I N E ( Z l! , 3 0 ) - ( 1 2 8 , 5 5 ) t P S E T
1 ll 0 G O T O 1 ll 0
Notes
l . This method is best for lines which may have any angle.
Consider DRAW for angles of O , 45 , 90, 1 3 5 , 1 80 , 225 , 270, and 3 1 5
degrees.
1 72
8
Lines, Horizontal, Vertical, or Diagonal, Drawing
Description
This method of drawing a line uses the DRAW command of
Extended Color BASIC. A starting point, direction , and length for the
line are determined . The X and Y coordinates of the starting point are
based upon the maximum graphic resolution of 255 horizontal by 1 92
vertical elements. The starting point must be within the screen
boundaries.
The length of the line is expressed in high-resolution units. Diagonal
lines are expressed in the number of units moved in a horizontal or
vertical position.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Set Xl , Yl to the starting point for
the line. Use the DRAW command in the following format:
DRAW
" B MXJ 1 Yl ;
#L "
The " # " sign represents the DRAW command as follows: U = up,
D = down, R = right, L = left, E = 45 degrees , F = 1 35 degrees , G = 225
degrees , H 3 1 5 degrees . The L parameter is the length of the line to be
drawn . The color used is the current foreground color. Any color in the
current PMODE may be used by using the format
=
DRAW
II
B MXJ , yj ;
C& ;
#L "
where & is the color code from 1 to 8 .
Example
Draw a diagonal red line from 1 28 ,92 to 148 ,72 .
SECTION II
1 00 PMODE 3 t 1
1 1 0 SCREEN 1 10
1 20 P C L S
1 30 DRAW " BM 1 28 192 ;
1 40 GOTO 1 40
ca ;
1 73
E20"
Notes
1 . This method is best for lines with angles of O , 45, 90, 1 3 5 , 1 80 ,
225 , 270, and 3 1 5 degrees .
2 . The LINE command may be used instead of DRAW. In LINE,
however, the color cannot be specified as in DRAW.
1 74
9
Mode of Graphics, Changing
Description
This BASIC program provides an easy way to change the graphics
mode to one not implemented in either Color BASIC or Extended Color
BASIC . Changing the mode can be used as an initialization to doing
graphics work in the video display generator (VDG) modes that are not
implemented in the BASIC interpreters .
Sequence
Set variable P to the mode to be used. Set variable C to the color
set , 0 or 1 .
For P : Values of 0 through 4 correspond to PMODE 0 through 4
(even if Extended BASIC is not installed). Values of -6, -8 , - 1 2 , and
-24 correspond to the semigraphics modes 6, 8 , 1 2 , and 24 respectively.
Values of 5 through 7 correspond to the 64 x 64 four-color mode, the
1 28 x 64 two-color mode , and the 1 28 x 64 four-color mode
respectively .
Use these statements:
1 000
1010
1 020
1 030
1 040
1 050
1 060
1 070
1 080
I F P > 7 THEN GOTO 1 5 00
ELSE I F P = - 6 THEN GOTO 1 1 00
ELSE I F P = - 8 THEN GOTO 1 1 00
ELSE I F P = - 1 2 THEN GOTO 1 1 00
ELSE I F P = -24 THEN GOTO 1 1 00
ELSE I F P < 0 THEN GOTO 1 500
I F P >4 THEN T = P+3 ELSE T = P+ 1 1
A = < PEEK C 653 1 4 l AND 7 l : POK E
653 1 4 1A+T*1 6+C*8
I F P = 5 THEN P = 6
I F P >4 THEN P = P - 5 ELSE P = P+3
I F P = 7 THEN P = 6
I F ( p A N D 4 ) = 4 T H E N P O K E &: H F F C 5 , 1
E L S E P O K E &: H F F C 4 1 0
I F ( p A N D 2 ) = 2 T H E N P O K E &: H F F C 3 , 1
E L S E P O K E &: H F F C 2 1 0
I F ( p A N D 1 ) = 1 T H E N P O K E &: H F F C 1 , 1
E L S E P O K E &: H F F C 0 1 0
SECTION II
1 75
1 090 GOTO 1 500
1 1 00 IF P = - 6 THEN P = 0
E L S E I F P = - 8 THEN P = 2
E L S E I F P = - 1 2 THEN P = 4
ELSE I F P = - 24 THEN P = 6
1 1 1 0 A = < PEEK ( 65 3 1 4 l AND 7 l :
I F P = 0 THEN POKE 653 1 4 t A+ 1 6+C*B
ELSE POKE 653 1 4 t A
1 1 2 0 G O T O ·1 0 6 0
1 500 RETURN
Example
To set PMODE 4 and color set 1 in a Color BASIC machine, do the
following:
1 00 P = 4 : C = 1
1 1 0 GOSUB 1 000
1 20
1 30
1 40 GOTO 1 40
1 000 ( s u b r o u t i n e
•
•
ab o v e )
Notes
The area displayed will be from the current starting address
1 024
if in Color B ASIC or Extended Color BASIC text display, or a graphics
page start if in Extended Color BASIC graphics display . Change the
starting address as described in "Start of Video Memory, Changing" if
desired.
-
1 76
10
Moving Figures, by GET,PUT
Description
This application shows how figures can be moved on the screen to
produce animation or other effects . The technique used here is by the use
of the Extended Color BASIC GET/PUT commands. The figure is drawn
at a given starting point by a standard Extended Color BASIC command
or commands. The figure is then moved into an array by the GET
command and redrawn at a new screen position by the PUT command .
The process is repeated as often as required. Indexing (see "Moving
Figures by Indexing" ) can be used to facilitate the PUTs.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Clear the screen by PCLS , or leave
the current screen contents in place.
Establish a two-dimensional array for the GET. The array should be
large enough to hold the area of the screen to be stored. In the simplest
case, the dimensions of the array should match the area dimensions .
However, a great deal of memory may be saved and the speed will be
increased by using the techniques of Chapter 8 .
Draw the figure to b e moved by normal commands . Perform a GET
on the screen area to move the entire area into the array . Initiate a
FOR . . . TO . . . SET loop from 0 to an end index value. Draw the figure by
performing a PUT to the next screen area, using the index value to
determine the location . Continue through the end of the loop.
Example
Move a circle centered at 20,20 with a radius of 3 , diagonally down
to 1 70 , 1 70 .
1 00
1 10
1 20
1 30
1 ll 0
1 50
P M O D E ll t 1
SCREEN 1 ,0
PCLS
D I M l.l ( 1 0 t 1 0 )
C I RCLE ( 20 120 ) 13
G E T ( 1 5 t 1 5 l - ( 2 5 1 2 5 ) 1 IJ 1 G
SECTION II
1 80
1 70
1 80
1 90
200
1 77
FOR
1 = 0 TD 1 50
P U T ( 1 5 + 1 t 1 5 + 1 ) - ( 2 5 + 1 1 2 5 + 1 ) , t.1 , p s E T
FOR J = 0 TD 20 : NEXT J
N D( T I
GOTO 200
This example produces a succession of circles, as shown in
9 . MFG . I . Each is drawn with a center at 20 + 1 , 20 + I and then erased.
The overhead of the PUT command allows the figure to remain long
enough to create an animation effect.
rDEFINED
r.:J-AREA
L:'.r
IN GET ( I = O )
( 1 5 , 15 )
c2:��" '
� INTERMEDIATE
POSITION ( ! = 6 0 )
0"
'
"'
"'
" "-.
( 16 5 16 5 )
.
Figure 9 . MFG . l :
FINAL
f POSITION
-@]- ( 1 7 5 , 175 )
'
Moving figures b y GET/PUT example.
Notes
l . This example moves a circle along the diagonal in about 1 3
second s .
2 . Delete the FOR J = 0 . . loop for a faster move (6 seconds) .
3 . The PUTs effect an automatic erase as the array block is
rewritten . More elaborate figures may leave garbage unless a proper erase
(by a PUT with PRESET or other means) is done .
4. Replicating the block will cut a swath along the path and
possibly overwrite other figures that fall into the block area .
5 . U s e a larger STEP size fo r slower moves.
.
1 78
1 1
Moving Figures, by Indexing
Description
This application shows how figures can be moved on the screen to
produce animation or other effects . The technique used here is indexing .
The figure is drawn at a given starting point by a standard Extended
Color B ASIC command. The figure is then erased by using a PCLS or by
overwriting the figure with the background color. The figure is then
redrawn at a new screen position and the process is repeated. The process
continues until the end of the path is reached .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Clear the screen by PCLS , or leave
the current screen contents in place. Initiate a FOR . . . TO . . . STEP loop
from 0 to an end index value.
Draw the figure at the screen start plus the index value . Erase the
figure by a PCLS or by redrawing the figure with the background color.
Continue until the last index is reached .
Example
Move a circle centered at 20 ,20 with a radius of 3 , diagonally down
to 1 70 , 1 70 .
1 00
1 10
1 20
1 30
1 40
1 50
1 60
1 70
P M O D E Ll 1 1
SCREEN 1 1 0
PCLS
FOR I = 0 TD 1 50
C I RCLE ( 20+ I 120+ I ) 1 3
C I RCLE ( 20 + I 1 20+ I ) 13 1 0
N E )< T I
GOTO 1 70
This example produces a succession of circles as shown in 9 . MFI . l .
Each is drawn with a center at 20 + 1,20 + I and then erased. The
overhead of the CIRCLE command allows the figure to remain long
enough to create an animation effect .
SECTION II
OR I G I N AL
0,---- P O S I T I O N
"-
"
( CE N T E R AT
20, 20)
"
",
,...--- I N T E R M E D I AT E
POS I T I O N
'{ C E N T E R AT B O ,
"-
0
"
FINAL
PO S I T I O N
{ C E N T E R AT
Figure 9.MFl . l :
"-
"
80)
"
".
"
1 7 0 , 170 ) �a
Moving figures b y indexing example.
Notes
1 . This example moves a circle along the diagonal in about 3 1
seconds .
2 . Use a l arger STEP size for a faster move.
3 . Substitute a PCLS for the second move i f desired. The speed
will be about the same.
4 . Vary X and/or Y with the index variable to move vertically ,
horizontally, or diagonall y .
5 . U s e t w o index variables for other angles , although this will
slow down the move considerably .
1 79
180
12
Octagon, Drawing
Description
This application draws an octagon, as shown in Figure 9 . 0CT. l .
The octagon is drawn with the midpoint at any given X , Y location. It may
be any of 3 '.2 sizes - width of 3 , 6, 9, 1 2 , 1 5 , etc . , up to a base of 96.
The entire octagon must be within the screen boundaries or an imperfect
octagon will result.
-f
I
I
I
���:ER AT
< 128, 1 1 2 1
S•32
!
Figure
9.0CT. l :
Octagon action.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Set X, Y to the midpoint of the
octagon. Set S, scale factor, to a value of 1 through 32. The width of the
octagon will be 3 times S .
Use the following BASIC line to draw the octagon:
1 0 0 D R A W 11 B M 11 + S T R $ C X ) + 11 1 11 + S T R $ ( Y ) + 11 S 11 +
S T R $ ( s ) + II ; II + II B M +0 ' - 6 ; R 2 ; F ll ; D ll ; G ll ; L ll ;
H ll i U ll l E ll i R 2 i B M + 0 1 + 6 11
SECTION II
Example
Draw an octagon centered at 1 28 , 96 with a width of 3 3 .
1
1
1
1
1
00 PMOOE 3 t 1
1 0 SCREEN 1 10
20 PCLS
30 X = 1 28 : Y = 8G : S = l l
4 0 O R A W 11 B M 11 + S T R $ ( ){ ) + 11 1 " + S T R $ ( Y ) + " S " +
S T R $ ( S ) + " ; " + " 5 M + 0 1 - G i R 2 i F ll i D ll i G ll i l l! ;
H ll i U ll i E ll i R 2 i B M + 0 1 + 6 11
1 50 GOTO
1 50
Notes
1 . The cursor is centered at the midpoint of the octagon after the
line has been executed. Further DRA Ws will occur from this point.
2. If the octagon will not fit on the screen, the DRAW will still
draw a figure, but one or more sides will be the wrong lengths.
181
182
13
Other Colors in PMODE 4
Description
This application provides a gray color in addition to green and black
in color set 0, or a blue color in addition to buff and black in color set 1 .
It uses the PSET command to alternate black and green stripes in a
rectangular area. The same technique can be used in a non-rectangular
area with some modification .
Sequence
Set PMODE to 4 and page number. Set SCREEN to graphics and
color set 0 or l . Reverse the foreground/background colors by COLOR
0, 1 . PCLS the screen to a green or bu ff color by PCLS .
Define the rectangle to be colored gray or blue by setting Xl ,Y J to
the upper left-hand corner and X2 Y2 to the lower right-hand corner.
Perform the fol lowing loop:
,
1 30 FDR X = X l TO X2 STEP 2
1 40 FOR Y = Y l TO Y2
1 5 0 P S E T ( ){ 1 Y l
1 60 NEXT Y : NEXT X
Example
Color the rectangle defined by 20,20 to 1 00, 1 00 gray.
90 PMODE 4 1 1
1 00 SCREEN 1 ' 0
1 1 0 COLOR 0 d
1 2 0 P C L S : >: 1 = 2 0 : Y 1 = 2 0
}( 2 = 1 0 0
1 3 0 F O R }-{ = ){ 1 T D ){ 2 S T E P 2
1 40 FOR Y = Y l TD Y2
1 5 0 P S E T ( )- ( , y )
1 6 0 N E :n y : N E :n )-(
1 70 GOTO 1 70
Y2= 1 00
Notes
Other STEP sizes in color set l produce additional effects , including
rainbow striping.
SECTION II
1 83
14
Rectangle, Fi l led-in, Color BASIC
Description
POKE graphics may be used for Color BASIC to draw filled-in
rectangles . This method is fast, allows eight colors , but works only with
the 64-by-64 resolution of Color BASIC .
The rectangles may be any size in multiples of character positions .
Normal graphics in Color B ASIC has a resolution of 64 by 32 with each
character position defining four graphics elements. The character position
is 4 pixels wide by 6 pixels high. The smallest rectangle that can be
defined in this mode is one character position (4 by 6, or two X units by
two Y units) . Other rectangles will be drawn to the next smallest
character position. For example, if a 1 2-wide by 1 5 -high rectangle was
called for, the rectangle would be 1 2/2 = 6 character positions wide by
1 5/2 = 7 character positions high. The rectangle is specified in Color
BASIC graphic coordinates where X = 0 to 63 and Y = 0 to 3 1 .
Sequence
Set C to the color to be used , 0 through 9 . Set (Xi , Yi ) to the
coordinates of one comer of the rectangle. Set (X2 , Y2 ) to the coordinates
of the opposite corner of the rectangle .
Use these statements to draw the rectangle:
1 0 0 I F )< 2 < )-( 1 T H E N }{ L = }( 2 E L S E }( L = i< l
1 1 0 I F )< 2 < )< 1 T H E N )< R = )<1 E L S E )-( R = i< 2
1 20 I F Y2< Y 1 THEN YT=Y2 ELSE Y T = Y l
1 30 I F Y2< Y 1 THEN YB= Y l ELSE YB=Y2
l< R = I N T < l< R / 2 )
1 4 0 l< L = I N T ( )-( L / 2 )
l<D = )< R - l< L + l
YB= I NT < YB / 2 )
1 50 Y T = I NT < YT / 2 )
YD=YB-YT+ l
1 60 I F C = 0 THEN L = 0 ELSE L = 1 5
1 7 0 I F C< >0 THEN C=C- 1
1 80 P K = 1 2B+C* 1 G+L
1 80 FOR I = l TO YD
200 FOR J = l TO XO
2 1 0 POKE 1 024+XL+J - 1 +YT*32+ ( l - 1 l *32 1 PK
220 NEYT J
2 3 0 N E l< T
I
184
The sequence above first finds the "left" X, XL , the "right" X, XR ,
the "top" Y, YT, and the "bottom" Y, YB .
It then finds the coordinates in character positions by dividing the X
coordinates by 2 and the Y coordinates by 2 . The X and Y distances are
then computed - XD and YD .
If the color is black, all elements will be off and variable L set to O;
otherwise L is set to all on ( 1 1 1 1 binary or 1 5 decimal ) . The color code
for POKEs is then found by subtracting 1 from variable C. The proper
code to be POKEd for each character position is 1 2 8 + C x 1 6 + L .
Next, two loops are performed . The innermost " J " loop draws a
row of colors. The outermost " I " loop increments over YD rows. Each
POKE stores one character position of the rectangle.
Example
Draw a blue rectangle with an upper left comer at 32, 1 6 (center of
screen) and a lower right corner at 48,24 .
80 C = 3 : X 1 = 3 2 : Y 1 = 1 G : X 2 = 4 8 : Y 2 = 2 4
1 0 0 I F }< 2 < >( 1 T H E N }{ L = >( 2 E L S E )-( L = )< l
1 1 0 I F }{ 2 < }( 1 T H E N )-( R = }( l E L S E }< R = >( 2
1 20 I F Y2< Y 1 THEN Y T = Y2 ELSE Y T = Y l
1 30 I F Y2< Y 1 THEN YB = Y l ELSE Y B = Y2
1 4 0 ){ L = I N T ( )-( L / 2 )
)< R = I N T ( }( R / 2 )
)< D = >< R - }( L + 1
1 50 YT = I NT < YT/2 )
YB= INT < YB/2 )
YD=YB -YT+ l
1 60 I F C = 0 THEN L = 0 ELSE L = 1 5
1 70 I F C< >0 THEN C = C - 1
1 80 P K = 1 28+C* 1 B+L
1 80 FOR I = l TO YD
200 FOR J = l TO XD
2 1 0 P O K E 1 0 2 4 + }( L + J - 1 + Y T * 3 2 + < I - 1 l * 3 2 1 P K
2 2 0 N E> : T J
2 3 0 N E )< T I
240 GOTO 240
Notes
This code is not " idiot-proof. " Using invalid X and Y coordinates or
colors will yield improper results !
SECTION II
185
15
Rectangle, Fil led-in, Drawing (Method 1 )
Description
In this method of drawing a filled-in rectangle using the LINE
command of Extended BASIC, a diagonal of the rectangle defines the
size and position . The X and Y coordinates of the diagonal are based upon
the maximum graphic resolution of 255 horizontal by 1 92 vertical
elements . The two points must be within the screen boundaries.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set . Use the LINE command in the
following format:
L I NE
( X 1 1 Y1 ) - ( X2 1 Y2 ) 1 P S E T 1 B F
This draws a rectangle outline. The upper left corner of the rectangle
is defined by XI , Yl . The lower right corner of the rectangle is defined by
X2 , Y2 . The start and end points are included in the outl ine. The color
used is the current foreground color.
Example
Draw a rectangle whose upper left corner is at I , I and whose lower
right corner is at 1 27 , 9 1 .
1 00 P M O O E 3 1 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 L I NE ( 1 t 1 ) - < 1 27 1 8 1 ) 1 PSET 1BF
1 40 GOTO 1 40
Notes
The method is faster than creating a filled-in rectangle with DRAW
and PAINT. Compare the example with " Drawing a Filled-in Rectangle
(Method 2 ) . ' '
1 86
16
Rectangle, Filled-in, Drawing (Method 2)
Description
This method of drawing a rectangle uses the ORAW and PAINT
commands of Extended BASIC . In this method , a ORAW string defines
the sides of the rectangle and the starting point. This method has some
advantages over LINE with the B option. A color other than the
foreground color may be specified and the rectangle may be scaled up or
rotated. The increments for the ORAW are based upon the maximum
graphic resolution of 255 horizontal by 1 92 vertical elements. The
rectangle may not go beyond the boundaries .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use the ORA W command in the
following format:
DRAW
II B MXJ 1 Yl ; B ;
Rll ;
Dl2 ;
Lll ;
Ul2 II
In this format X1 and Y1 are the starting coordinates of the rectangle
where XI = 0 to 255 and Y1 = 0 to 1 9 1 . ll is the width of the rectangle
minus 1 , ( 1 - 255) and l2 is the height of the rectangle minus 1 , ( 1 1 9 1 ) . B is the border color for the rectangle .
PAINT the rectangle by
P A I NT
( XJ + l 1 Yl + l l 1 C 1B
where C is the color for painting and B is the border color used in the
ORA W command. B and C may be equal if the rectangle is to be one
solid color. If B and C are not equal , there will be a narrow outline
around the rectangle.
Example
Draw a rectangle whose upper left comer is at 1 , 1 and whose lower
right comer is at 1 27 , 9 1 . The width is therefore 1 27 and the height 9 1 .
Color the rectangle blue.
SECTION fl
1 00 PMODE 3 , 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 3 0 D R A W II B M 1 ' 1 ; C 3 ;
1 40 PA I NT ( 2 1 2 ) ,3 ,3
1 50 GOTO 1 50
R 1 26 ;
080 ;
L 1 26 ;
187
U 8 0 II
Notes
The cursor for the draw is positioned back at 1 , 1 after the ORA W .
188
17
Rectangle Outline, Drawing (Method 1 )
Description
In this method of drawing a rectangle using the LINE command of
Extended BASIC, a diagonal of the rectangle defines the size and
position. The X and Y coordinates of the diagonal are based upon the
maximum graphic resolution of 255 horizontal by 1 92 vertical elements.
The two points must be within the screen boundaries .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use the LINE command in the
following format:
L I NE
( XJ 1 Yl > - ( X2 1 Y2 > , P S E T ,
B
This draws a rectangle outline. The upper left comer of the rectangle
is defined by Xl , Yl . The lower right comer of the rectangle is defined by
X2 , Y2 . The start and end points are included in the outl ine . The color
used is the current foreground color.
Example
Draw a rectangle whose upper left comer is at 1 , I and whose lower
right comer is at 1 27 , 9 1 .
1 00 PMODE 3 t 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 L I NE ( 1 t 1 > - ( 1 27 1 9 1 l 1 PSET 1 B
1 ll 0 G O T O 1 ll 0
Notes
The method is faster than a rectangle drawn with the DRAW
command. Compare the example with "Rectangle Outline, Drawing
(Method 2) . "
SECTION II
189
18
Rectangle Outline, Drawing (Method 2)
Description
In this method of drawing a rectangle using the DRAW command of
Extended B ASIC, a DRAW string defines the sides of the rectangle and
the starting point. This method has some advantages over LINE with the
B option. The color of the sides may be changed easily and the rectangle
may be scaled up or rotated. The increments for the DRAW are based
upon the maximum graphic resolution of 255 horizontal by 1 92 vertical
elements . The rectangle may not go beyond the boundaries.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Use the DRAW command in the
following format:
DRAW
" B MXJ 1 Yl ;
RLJ ;
DL2 ;
LLJ ;
UL2 1 1
In this format X J and Y1 are the starting coordinates of the rectangle
where Xl = 0 to 255 and Y1 = 0 to 1 9 1 . Ll is the width of the rectangle
minus l ( 1 255) , and L2 is the height of the rectangle minus 1 ( l
1 9 1 ) . The color used is the current foreground color.
-
-
Example
Draw a rectangle whose upper left corner is at I , 1 and whose lower
right corner is at 1 27 , 9 1 . The width is therefore 1 27 and the height 9 1 .
1 00 P MODE 3 , 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 DRAW
BM 1 ' 1 ;
1 40 GOTO 1 40
II
R 126 ;
D90 ;
L 1 26 ;
U90
II
Notes
1 . The cursor for the draw is positioned back at 1 , l after the
DRAW.
2. The C command can be used at any time to change the color of
a side . Example: " R l 26 ; C2; D90; . .
.
"
1 90
19
Rotations, of Figures
Description
The best way to rotate figure outlines is with the Angle option of the
DRAW command. Angle lets you displace any line drawn by 0, 90, 1 80,
or 270 degrees , in effect a rotation . The format of Angle is
" AX "
where X is 0, 1 ,2 , or 3 , corresponding to 0 degrees , 90 degrees , 1 80
degrees , or 270 degrees .
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Define your figure by a ORAW
string.
Define the angle command as a separate string , such as A$ . This
string can be concatenated onto the ORA W string for the figure . Draw
the figure by performing a ORAW A$ +
(draw string) , " where A$ is
the Angle option.
"
Example
Rotate the pentomino (figure made up of five squares) defined by
" R4;D4;R4;D4;L4;D4;L8 ;U4;R4;U8" (see Figure 9 . ROT. l ) through 0,
90 , 1 80, 270 , and 0 degrees .
1 00
1 10
1 20
1 30
1 40
1 50
1 80
1 70
1 80
1 80
PMODE 3 1 1
SCREEN 1 1 0
PCLS
5 $ = " R ll m a ; R a m a ; L a m a ; L B ; u a m a ; u s ; "
DRAW " A0 " +5$
G O S U 5 1 000
DRAW " A l " +5$
GOSU5 1 000
DRAW " A2 " +5 $
GOSU5 1 000
SECTION II
200 DRAW " A3 " +B$
2 1 0 GDSUB 1 000
220 DRAW " A0 " +B$
230 GOTO 230
1 000 FOR ! = 0 TO 1 000
1 0 1 0 PCLS
1 020 RETURN
N E >( T
I
4
4
8
4
1-- - - - I
I
I
I
4
-
4
-
I
- -
-
I
I
I
I
I
4
I
I
8
Figure 9 .ROT. 1 :
Pentomino .
Notes
l . The default Angle value is 0.
2 . Once a n Angle option is executed, i t stays i n force for all
subsequent DRAW s .
191
1 92
20
Semigraphics 8, SET/RESET
Description
This application allows a set or reset of one graphic element in the
semigraphics 8 mode while in either a Color BASIC or Extended Color
BASIC machine. The semigraphics 8 mode is not supported in either
BASIC version . It allows 8 colors in a 64-by-64 matrix with a black
border.
Sequence
Prior to the set or reset, semigraphics 8 mode must be set by the
instructions in "Mode of Graphics, Changing . " Also, the start of the
display area must have been defined by the procedures in "Start of Video
Memory, Changing . ' '
Set variable X to the horizontal coordinate, 0 through 63 . Set
variable Y to the vertical coordinate, 0 through 63 . Set C to the color, 1
through 8 . 0 (black) is not a valid color. Set SR to 0 if the element is to
be set, or to 1 if the element is to be reset . Variable ST should be set to
the start of the display area (this may be done only once, after setting the
start).
Use the following statements:
1 00
1 10
1 20
1 30
1 40
I F S R = 0 THEN M = 1 28+ ( C - l l * 1 B
I F < X AND l l = 0 THEN M = M+ 1 0 ELSE M = M+5
IF SR= 1 THEN M= 1 28+ ( C - 1 l * 1 B :
I F < X AND 1 l = 0 THEN N = 5 ELSE N = 1 0
AD=ST+Y*32+ I NT < X l2 l
I F S R = 0 THEN A = < PEEK < AD l AND 1 5 ) :
A = A D R M : P O K E AD 1 A
I F SR= 1 THEN A = < PEEK < AD l AND N l :
A = A D R M : P O K E AD 1 A
Example
Set element 63 ,63 (lower right-hand comer) to blue.
90 C = 3 : X = G3 :
1 00 ( s t a t e m e n t s
1 50 GOTO 1 50
Y = G3 :
above )
SR=0
:
ST = 1 4000
SECTION II
1 93
Notes
1 . When working in graphics modes that require more buffer than
is allocated (more than 5 1 2 in Color BASIC), set the display start to high
memory and protect this area with a CLEAR.
2. Before processing graphics in this mode, reset all 4096 elements
(2048 bytes ) . This can be done by the statements described here or by
2048 POKEs of 1 28 + (C- 1 )* 1 6 .
1 94
21
Semigraphics 1 2, SET/RESET
Description
This application allows a set or reset of one graphic element in the
semigraphics 1 2 mode, while in either a Color BASIC or Extended Color
B ASIC machine. The semigraphics 1 2 mode is not supported in either
B ASIC version . The semigraphics 1 2 mode allows 8 colors in a 64-by-96
matrix with a black border.
Sequence
Prior to the set or reset, semigraphics 1 2 mode must be set by the
instructions in "Mode of Graphics , Changing . " Also , the start of the
display area must have been defined by the procedures in ' ' Start of
Memory , Changing . ' '
Set variable X to the horizontal coordinate, 0 through 63 . Set
variable Y to the vertical coordinate, 0 through 95. Set C to the color, 1
through 8 . Black (0) is not a valid color. Set SR to 0 if the element is to
be set or to 1 if the element is to be reset. Variable ST should be set to
the start of the display area (this may be done only once, after setting the
start) .
Use the following statements:
1 00
1 10
1 20
1 30
140
I F SR=0 THEN M = 1 2B+ e C - 1 l • 1 G : I F e x
AND 1 1 = 0 THEN M = M+ 1 0 ELSE M = M+5
I F SR= l THEN M = 1 2B+ e C - 1 l • 1 G : I F e x
AND 1 1 = 0 THEN N = 5 ELSE N = 1 0
AD= ST+Y•32+ I NT e X / 2 l
I F S R = 0 THEN A = C PEEK e AD l AND 1 5 1
A = A D R M : P O K E AD 1 A
IF SR = l THEN A= C PEEK C AD l AND N l : A=A
D R M : P O K E AD 1 A
Example
Set element 63 ,95 (lower right-hand comer) to red.
90 C = 4 : X = G3 :
1 00 ( s t at emen t s
1 50 GOTO 1 50
Y=95 :
above )
SR = 0 :
ST= 1 4000
SECTION II
1 95
Notes
1 . When working in graphics modes that require more buffer than
is allocated (more than 5 1 2 in Color BASIC) , set the display start to high
memory and protect this area with a CLEAR.
2. Before processing graphics in this mode, reset all 6 1 44 elements
(3072 bytes) . This can be done by the statements described here or by
3072 POKEs of 1 28 + (C- 1 )* 1 6 .
1 96
22
Semigraphics 24, SET/RESET
Description
This application allows a set or reset of one graphic element in the
semigraphics 24 mode while in either a Color BASIC or Extended Color
B ASIC machine. The semigraphics 24 mode is not supported in either
BASIC version . The semigraphics 24 mode allows 8 colors in a
64-by- 1 92 matrix with a black border.
Sequence
Prior to the set or reset, semigraphics 24 mode must be set by the
instructions in ' 'Mode of Graphics, Changing . ' ' Also, the start of the
display area must have been defined by the procedures in "Start of Video
Memory, Changing . ' '
Set variable X to the horizontal coordinate , 0 through 63 . Set
variable Y to the vertical coordinate , 0 through 1 9 1 . Set C to the color, 1
through 8 . B l ack (0) is not a valid color. Set SR to 0 if the element is to
be set or to 1 if the element is to be reset. Variable ST should be set to
the start of the display area (this may be done only once, after setting the
start) .
Use the following statements:
1 00
1 10
120
130
1 1'.1 0
I F S R = 0 THEN M = 1 28+ 1 C - 1 1 * 1 G : I F I X
A N D 1 1 = 0 THEN M = M+ 1 0 ELSE M = M+5
I F SR= l THEN M = 1 28+ 1 C - 1 1 * 1 G : I F I X
AND 1 1 = 0 THEN N = S ELSE N = 1 0
AD= ST+Y*32+ I NT I X / 2 1
I F SR=0 THEN A= I PEEK I AD I AND 1 5 1
A = A D R M : POKE AD 1A
I F S R = l THEN A = I PEEK I AD I A N D N I : A = A
D R M : P O K E AD 1 A
Example
Set element 63 , 1 9 1 (lower right-hand comer) to yellow.
SECTION II
90 C = 2 : X = G3 :
1 00 ( s t a t e M e n t s
1 50 G O T O 1 50
Y= 191 :
above )
SR=0
197
S T = 1 ll 0 0 0
Notes
1 . When working in graphics modes that require more buffer than
is allocated (more than 5 1 2 in Color BASIC), set the display start to high
memory and protect this area with a CLEAR.
2. Before processing graphics in this mode, reset all 6 1 44 elements
(3072 bytes ) . This can be done by the statements described here or by
3072 POKEs of 1 28 + (C- 1 )* 1 6 .
1 98
23
Square, Drawing
Description
This application draws a square of any of 32 sizes, as shown in
Figure 9 . SQU . 1 . The square is drawn with the midpoint at any given
X , Y location. The square may be any of 32 sizes - sides of 4, 8, 1 2 ,
1 6 , 20, etc . , u p t o sides o f 1 2 8 . The entire square must b e within the
screen boundaries or an imperfect square will result.
' '"" '.'.r
..'..'.__ " .
S M A L LE S T S Q U A R E
- �;;"'"
'-..._ L A R G E ST
SQUARE
( S I DES OF 1 2 8 )
Figure 9.SQU . l :
Square action.
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Set X , Y to the midpoint of the square .
Set S, scale factor, to a value of 1 through 32. The size of the square ' s
sides w i l l be 4 times S .
Use the following BASIC line to draw the square:
1 0 0 D R A W " B M " + S T R $ ( ){ ) + " t " + S T R $ ( Y l +
" S " +STR$ ( S l + " ; " + " BM - 8 t - B ; R 1 G i D 1 G ;
L 1 6 i U 1 6 i BM+B t + B "
SECTION II
Example
Draw a square centered at 1 28 ,96 with sides of 8 .
1 00 PMODE 3 , 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 X = 1 28 : Y=8G : 8 = 32
1 4 0 D R A W " " B M " + S T R $ ( )-( ) + " 1 " + S T R $ ( Y ) +
" S " +STR$ ( S ) + " i " + " BM - 8 1 - B i R 1 G i D 1 G i L 1 G i
U l G i BM+B ,+8 "
1 50 GOTO 1 50
Notes
1 . The cursor is centered at the midpoint of the square after the
line has been executed. Further DRA Ws will occur from this point .
2 . If the square will not fit on the screen , the DRAW will draw a
figure , but one or more sides will be the wrong lengths .
199
200
24
Start of Video Memory, Changing
Description
This B ASIC program provides an easy method of changing the start
of video memory in the hardware to any 5 1 2-byte boundary . The
program can be used in both Color BASIC and Extended Color B ASIC .
Changing the start of video memory can be used to graphically display
the BASIC interpreter or as initialization to doing graphics work in the
VDG modes that are not implemented in the BASIC interpreters .
Sequence
Set variable S to the address to be used. The lower 9 bits of this
address will be ignored if the address is other than a multiple of 5 1 2 - 0,
5 1 2 , 1 024, 1 536, etc. The program will set the VDG start to the given
address.
Use these statements:
1 000
1010
1 020
1 030
1 040
1 050
S = I NT ( S / 5 1 2 l
FOR I = &HFFCG TO &HFFD2 STEP 2
R = S - I NT ( S /2 l *2 : S = I NT ( S / 2 l
POKE I +R 1 0
N E :n I
RETURN
Example
To set the VDG to display the area starting at location 2048:
1 00 5 = 2048
1 1 0 GOSUB 1 0 00
1 20
1 30
1 40 GOTO 1 40
1 000 ( s u b r o u t i n e
•
•
ab o v e )
Notes
The mode of display will be the one that is currently in force . lf in
Color BASIC or the text display of Extended Color BASIC , the mode
will be alphanumeric and the area on the screen will be the start specified
through start + 5 1 1 . If in an Extended Color BASIC graphics mode, the
mode will be the current PMODE and will display the number of bytes
normally displayed in that PMODE.
SECTION II
20 1
25
Triangle, Drawing
Description
Thi s application draws a triangle with the base down , as shown in
Figure 9 . TRI . I . The triangle is an isosceles triangle with a right angle at
the apex. The triangle is drawn with the midpoint at any given X,Y
location. The triangle may be any of 32 sizes - base of 4 , 8, 12, 16, 20 ,
etc . , up to a base of 1 28 . The entire triangle must be within the screen
boundaries or an i mperfect triangle will result.
/
APEX
�
'
I
80
I
I
M I DPOINT AT
= (72, 108)
= 20
X, Y
s
f+- B A S E O F �
Figure 9.TRl . I :
Triangle action.
Sequence
Set PMODE to proper graphics mode and page number. Set
SCREEN to graphics and color set. Set X,Y to the midpoint of the
triangle . Set S, scale factor, to a value of 1 through 32. The size of the
triangle ' s base will be 4 times S .
U s e the following BASIC line t o draw the triangle:
202
1 0 0 D R A W " B M " + S T R $ ( ){ ) + " 1 " + S T R $ ( Y ) +
" S " + S T R $ ( S ) + " ; " + " B M + 0 1 - ll i F B i L 1 G i E B ;
B M + 0 1 + ll 11
Example
Draw a triangle centered at 1 29 ,96 with a base of 32.
1 00 PMODE 3 1 1
1 1 0 SCREEN 1 10
1 20 PCLS
1 30 X = 1 28 : Y = 8G : S = B
1 4 0 D R A W " B M " + S T R $ ( )-( ) + " 1 11 + S T R $ ( Y l +
" S " + S T R $ ( S ) + " ; " + " B M + 0 1 - ll i F B i l 1 G i E B ;
B M + 0 1 + ll 11
150 GOTO
1 50
Notes
1 . The cursor is centered at the midpoint of the triangle after the
line has been executed. Further DRAWs will occur from this point.
2. If the triangle will not fit on the screen , the DRAW will draw a
figure , but one or more legs will be the wrong lengths .
Append ices
APPENDICES
205
APPEN DICES
Appendix 1.
DEC
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Decimal/Binary Conversion Chart
BINARY
00000000
00000001
000000 1 0
000000 1 1
00000 1 00
00000 1 0 1
00000 1 1 0
000001 1 1
00001 000
0000 1 001
0000 1 0 1 0
0000 1 0 1 1
0000 1 1 00
0000 1 1 0 1
00001 1 1 0
00001 1 1 1
0001 0000
0001 000 1
000 1 00 1 0
000 1 001 1
000 1 0 1 00
000 1 0 1 0 1
0001 0 1 1 0
0001 0 1 1 1
000 1 1 000
0001 1 00 1
0001 1 0 1 0
0001 1 01 1
0001 1 1 00
0001 1 1 0 1
0001 1 1 1 0
0001 1 1 1 1
001 00000
001 00001
001 000 1 0
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
001 0001 1
001 001 00
00 1 00 1 01
001 001 1 0
001 001 1 1
001 01 000
00 1 0 1 001
001 01 01 0
001 01 01 1
001 0 1 1 00
001 0 1 1 0 1
00 1 0 1 1 1 0
00 1 0 1 1 1 1
001 1 0000
001 1 0001
001 1 001 0
001 1 001 1
001 1 01 00
001 1 01 0 1
001 1 01 1 0
001 1 01 1 1
001 1 1 000
001 1 1 00 1
001 1 1 01 0
001 1 1 0 1 1
001 1 1 1 00
001 1 1 1 01
00 1 1 1 1 1 0
00 1 1 1 1 1 1
01 000000
01 000001
01 00001 0
01 0000 1 1
01 000 1 00
0 1 0001 01
01 0001 1 0
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
1 00
1 01
1 02
1 03
1 04
1 05
1 06
0 1 000 1 1 1
0 1 001 000
01 001 001
0 1 001 0 1 0
0 1 001 0 1 1
0 1 001 1 00
01 001 1 0 1
0 1 001 1 1 0
01 001 1 1 1
0 1 01 0000
0 1 0 1 0001
0 1 0 1 00 1 0
01 0 1 00 1 1
0 1 0 1 01 00
01 01 01 01
01 01 01 1 0
01 0 1 0 1 1 1
01 0 1 1 000
01 01 1 00 1
0 1 01 1 0 1 0
0 1 01 1 0 1 1
0 1 0 1 1 1 00
01 01 1 1 01
01 0 1 1 1 1 0
01 0 1 1 1 1 1
0 1 1 00000
0 1 1 0000 1
0 1 1 0001 0
01 1 0001 1
0 1 1 00 1 00
0 1 1 00 1 01
0 1 1 00 1 1 0
0 1 1 001 1 1
0 1 1 0 1 000
01 1 0 1 001
01 1 01 0 1 0
206
1 07
1 08
1 09
1 10
111
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
0 1 1 0 1 01 1
0 1 1 0 1 1 00
01 1 0 1 1 0 1
01 1 0 1 1 1 0
01 1 0 1 1 1 1
01 1 1 0000
0 1 1 1 0001
0 1 1 1 001 0
01 1 1 00 1 1
01 1 1 01 00
01 1 1 0 1 0 1
01 1 1 01 1 0
01 1 1 01 1 1
0 1 1 1 1 000
01 1 1 1 001
0 1 1 1 1 01 0
01 1 1 1 01 1
01 1 1 1 1 00
01 1 1 1 1 0 1
01 1 1 1 1 1 0
01 1 1 1 1 1 1
1 0000000
1 0000001
1 00000 1 0
1 00000 1 1
1 0000 1 00
1 0000 1 01
1 00001 1 0
1 0000 1 1 1
1 0001 000
1 0001 001
1 0001 0 1 0
1 000 1 0 1 1
1 000 1 1 00
1 000 1 1 0 1
1 0001 1 1 0
1 0001 1 1 1
1 001 0000
1 001 000 1
1 001 001 0
1 001 001 1
1 001 0 1 00
1 001 01 0 1
1 001 01 1 0
1 51 1 001 01 1 1
1 52 1 00 1 1 000
1 53 1 00 1 1 001
1 54 1 001 1 0 1 0
1 55 1 001 1 01 1
1 56 1 001 1 1 00
1 57 1 001 1 1 0 1
1 58 1 001 1 1 1 0
1 59 1 00 1 1 1 1 1
1 60 1 0 1 00000
1 61 1 0 1 00001
1 62 1 0 1 000 1 0
1 63 1 01 0001 1
1 64 1 01 001 00
1 65 1 01 001 01
1 66 1 0 1 00 1 1 0
1 67 1 0 1 001 1 1
1 68 1 0 1 01 000
1 69 1 0 1 01 001
1 70 1 0 1 0 1 0 1 0
1 71 1 01 0 1 0 1 1
1 72 1 01 0 1 1 00
1 73 1 0 1 0 1 1 0 1
1 74 1 01 0 1 1 1 0
1 75 1 0 1 0 1 1 1 1
1 76 1 0 1 1 0000
1 77 1 0 1 1 0001
1 78 1 0 1 1 00 1 0
1 79 1 0 1 1 00 1 1
1 80 1 01 1 0 1 00
1 81 1 0 1 1 0 1 0 1
1 82 1 0 1 1 0 1 1 0
1 83 1 0 1 1 01 1 1
1 84 1 0 1 1 1 000
1 85 1 01 1 1 00 1
1 86 1 0 1 1 1 0 1 0
1 87 1 0 1 1 1 0 1 1
1 88 1 01 1 1 1 00
1 89 1 0 1 1 1 1 0 1
1 90 1 0 1 1 1 1 1 0
1 91 1 0 1 1 1 1 1 1
1 92 1 1 000000
1 93 1 1 000001
1 94 1 1 00001 0
1 95
1 96
1 97
1 98
1 99
200
201
202
203
204
205
206
207
208
209
21 0
21 1
21 2
213
214
21 5
21 6
21 7
21 8
21 9
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
1 1 0000 1 1
1 1 0001 00
1 1 000 1 0 1
1 1 0001 1 0
1 1 0001 1 1
1 1 001 000
1 1 00 1 001
1 1 001 01 0
1 1 001 01 1
1 1 00 1 1 00
1 1 001 1 0 1
1 1 001 1 1 0
1 1 001 1 1 1
1 1 01 0000
1 1 01 0001
1 1 0 1 00 1 0
1 1 01 001 1
1 1 0 1 0 1 00
1 1 01 01 01
1 1 01 01 1 0
1 1 01 01 1 1
1 1 0 1 1 000
1 1 01 1 001
1 1 01 1 01 0
1 1 01 1 0 1 1
1 1 0 1 1 1 00
1 1 01 1 1 0 1
1 1 01 1 1 1 0
1 1 01 1 1 1 1
1 1 1 00000
1 1 1 0000 1
1 1 1 000 1 0
1 1 1 0001 1
1 1 1 00 1 00
1 1 1 001 01
1 1 1 001 1 0
1 1 1 001 1 1
1 1 1 0 1 000
1 1 1 0 1 00 1
1 1 1 0 1 01 0
1 1 1 0 1 01 1
1 1 1 0 1 1 00
1 1 1 0 1 1 01
1 1 1 01 1 1 0
APPENDICES
239
240
24 1
242
243
244
245
246
247
248
249
250
251
252
253
254
255
1 1 1 01 1 1 1
1 1 1 1 0000
1 1 1 1 0001
1 1 1 1 001 0
1 1 1 1 001 1
1 1 1 1 0 1 00
1 1 1 1 01 01
1 1 1 1 01 1 0
1 1 1 1 01 1 1
1 1 1 1 1 000
1 1 1 1 1 001
1 1 1 1 1010
1 1 1 1 1 01 1
1 1 1 1 1 1 00
1 1 1 1 1 1 01
1 1 1 1 1 110
11111111
207
APPENDICES
Appendix 11.
209
Color BASIC Graphics Commands
and Actions
CLS (c)
c is a color code of 0-8 . Clears all 5 1 2 bytes (64 by 32 pixels) of
text screen to specified color.
1 00 CLS U I l
'clear
sc reen
to
red
POINT (h,v)
h is the horizontal element number from 0 through 63 . v is the
vertical element number from 0 through 3 1 . Returns an argument for the
specified pixel at h , v . If the character position containing the pixel is in
the alphanumeric (text) mode , returns - 1 . If the character position
containing the pixel is in the graphics mode and the pixel is on, returns
the color code (c) of 1 through 8. If the character position is in the
graphics mode and the pixel is off (black) , returns a 0 .
1 00
I F P O I NT ( 32 t 1 5 l = - 1 THEN PR I NT
GRAPH I CS !
ELSE PR I NT " OK
II
" NOT
II
RESET (h,v)
h is the horizontal element number from 0 through 63 . v is the
vertical element number from 0 through 3 1 . The pixel at h, v is turned
off. A black color results.
1 0 0 R E S E T (Q) , 0 ) : R E S E T ( 6 3 , 3 1 l
' re s e t c o rn e r P i x e l s
SET (h,v,c)
h is the horizontal element number from 0 through 63 . v is the
vertical element number from 0 through 3 1 . c is the color code (see
CLS ) . Sets the pixel at h , v . If background color is other than black,
changes three adjacent pixels to the specified color. If background is
black, only the specified pixel is set to the color.
210
1 00 SET ( 63 1 0 ) : SET ( 0 13 1 )
' s e t c o rn e r P i x e l s
Color Codes (c)
O = black
1 = green
2 = yellow
3 = blue
4 = red
5 = buff
6 = cyan
7 = magenta
8 = orange
APPENDICES
Appendix 111.
21 1
Extended Color BASI C Graphics
Commands and Actions
CIRCLE (X,Y) ,R,C,HW,S,E
(X, Y) are the coordinates of the center of the circle or ellipse or arc .
R is the radius of the circle or ellipse or arc to be drawn . C is the color to
be used in drawing the outline and is optional . If not specified, the
current foreground color is used. HW is the ratio of height to width, from
0 to infinity . If not specified , 1 (circle) is used. S is the starting point for
an arc and E is the ending point for an arc . S and E may be 0 to 1 and are
optional . If not specified , a complete circle or ellipse is drawn .
1 00 C I RCLE ( 1 28 1 86 ) 120
' d raw c i rc l e of rad i us
1 10
20
in
c en t e r
C I RCLE < 1 28 186 ) 120 1 6
' d raw c Y an c i rc l e
1 20 C I RCLE ( 1 28 186 l 1 40 1 1 . 5
' d r a r,r e l l i p s e
(
1 30
C I RCLE
1 28 186 ) 140 1 12
1 40
C I RCLE ( 1 28 1 86 ) 1 40 1 1 1 0 1 . 5
' d r aw c i r c u l a r a r c
1 50 C I RCLE ( 1 28 1 86 ) 1 40 1 1 2 1 0 1 . 5
' d raw e l l i P t i c a l a rc
COLOR F,B
F is the foreground color from 0 to 8. B is background color from 0
to 8 . Foreground and background colors are set accordingly . Colors must
be in the current color set as defined by SCREEN .
212
1 00 COLOR 1 1 4
' s e t f o r e g r o un d
to red
to
g reen 1
b a c k g r o un d
DRAW "string"
The string is string of ORAW commands. See Chapter 7 .
GET (Xl,Yl)-(X2,Y2),A,G
(XI , YI ) is one comer of the screen area to be processed. (X2 , Y2) is
the opposite comer of the screen area to be processed. A is the name of
the array to be used to store graphics data from the GET. A must be
previously defined by a DIM statement. G is optional. When used ,
complete graphics detail will be stored in the array . GET stores graphics
data from the defined screen area into an array for later use by PUT.
1 00
C 50 1 50 ) - ( 60 1 6 0 l 1 Z Z 1 G
• get g raPh ics data
LINE (Xl,Yl)-(X2,Y2) ,PSET or PRESET,B or BF
(XI , YI ) is one end point of line on screen . (X2 , Y2) is the opposing
end point. If PSET is used, the line , box, or filled-in box will be the
current foreground color. If PRESET is used, the line, box , or filled-in
box will be the current background color. B or BF are optional . If neither
is used, a line will be drawn between XI , YI and X2 , Y2 . If B is used, a
box will be drawn with XI , YI and X2 , Y2 treated as opposite comers. If
BF is used, a filled-in box will be drawn with the color defined by PSET
or PRESET.
1 00 L I NE ( 50 1 5 0 ) - ( 80 1 8 0 ) 1 PSET
' d r a 1A1 l i n e
1 1 0 L I NE ( 50 1 50 ) - ( 80 1 8 0 ) 1 PRESET
'e rase l ine
1 20 L I NE < 50 1 50 ) - ( 80 1 8 0 ) 1 PSET 1 B
' d r aw b o x o u t l i n e
1 30 L I NE < 50 1 50 ) - ( 80 180 ) 1 PRESET 1 B
' e rase box o ut l ine
1 40 L I NE ( 50 1 50 ) - ( 80 1 8 0 ) 1 PSET 1 B F
' d r aw f i l l e d - i n b o x
APPENDICES
2 13
PAINT (X,Y),CP,CB
{X, Y) defines the point at which the color is to be started. CP is 0 to
8 and is the color for the PAINT. CB is 0 to 8 and is the border color at
which the painting is to stop. PAINTing with color proceeds until the
border color is encountered . The border must completely surround the
area in which PAINTing is to occur.
1 00
P A I NT
< 1 28 186 ) 1 7 1 8
' Paint
Marenta
un t i l
o r an re
b o rde r
PCLEAR N
This reserves N graphics pages of 1 536 bytes each. N is l to 8 . If
this command is never specified , the default number of pages reserved is
4 . No data is stored in the pages. (The pages are not cleared . )
1 00
P CLEAR
5
'clear 5
Pares
PCLS C
This clears the current graphics screen with specified color C. C is 1
through 8 . C must be in the current color set.
1 00
P C L S LI
'clear
sc reen
with
buff
PCOPY N TO M
This copies the contents of graphics page N to graphics page M . N
and M are I to 8 . The contents of N are not affected.
1 00
PCOPY
1
TO 5
' C O PY
Pare
1
to
5
PMODE M,P
M is 0 to 4 and specifies the graphic mode to be selected. P is 1 to 8
and specifies the graphics page to be displayed . If PMODE is never
specified, mode 0 and page I are used .
1 00
PMODE
3 12
'set
PMODE 3
and
Pare
2
PPOINT (X, Y)
This tests the point at {X,Y) and returns the color code of the point.
The color code w i l l be in the current color set.
214
1 00
'test
A = P PO I NT C 1 28 186 )
cente r
po int
PRESET (X, Y)
This resets the point at (X,Y) . The current background color is used
in the reset.
1 00
PRESET
< 1 28 1 86 >
' reset
c ente r
Point
PSET (X,Y)
This sets the point at (X,Y). The current foreground color is used in
the set.
1 00
PSET
( 1 28 1 86 )
'set
the
c ente r
Po int
PUT (XI, Yl)-(X2, Y2),A,(options)
(XI , YI) defines one corner of a screen area. (X2 , Y2) defines the
opposite corner. A defines an array previously used by a GET. See
Chapter 8 for options . Graphics data previously stored in array A is PUT
into defined screen area. Contents of array A are not affected.
1 00
PUT ( 80 1 80 ) - ( 80 180 ) 1 Z Z
' d i s P l aY g raph i c s d a t a
SCREEN T,S
This selects the text or graphics screen and color set . T is 0 if text
screen to be displayed or 1 if graphics screen is to be displayed. S is color
set, 0 or 1 .
1 00 SCREEN 1 1 1
' se l e c t g raph i c s
an d
color
set
0
Notes
1 . X (or XI or X2 ) is 0 to 255 .
2. Y (or Yl or Y2) is O to l 9 1 .
3 . C is 0 t o 8 , representing black, green , yellow, blue, red , buff,
cyan, magenta, or orange , respectively .
Appendices
215
Appendix 1 v . Color Computer Graph ics M odes
MODE
1
BASIC MODE
ALPHAN U M E R I C
NORMAL TEXT
DISPLAY FORMAT
ELEMENT FORMAT
ABCDEFGH
01234567
t-" '"'"""
•
•
POSITIONS
16
LINES
•
•
0
j
1 C H A R ACTER
POSITION
1•
•
•
•
•
•
•
12
P I X E LS
•
•
8 P I X E LS
BYTE MAPPING
MEMORY MAPPING
+o
LINE 1, CP 1
+l
LINE 1, CP 2
+32
LINE 2 , CP 1
+33
LINE 2, CP 2
�
+ 5 10
L I N E 16, C P 3 1
+511
L I N E 1 6 , C P 32
-
N O R M A L START
= 1 0 2 4 10
t-.
) 512
��
7
2:
s
0
II I I II I II
0
r�
BYTES
T H I S B I T IS S E T I F I N V E R T E D ,
R E S E T I F N O T I NV E R T E D
COLORS
BORDER
BLACK
CHARACTEWBACKGROUND
I F C S S = 0 AND I N V
=
0, G R E E N ON
=
1 , BLACK ON
BLACK
IF CSS = 0 AND I N V
GREEN
I F C S S = 1 AND I N V
BLACK
IF CSS = 1 AND I N V
ORANGE
=
=
0, O R A N G E ON
1 , BLACK ON
USE
Color BASIC and Extended Color BASIC both reset to green on black.
216
Appendices
MODE 2
BASIC MODE
SEM I G RAPHIC 4
USED BY S ET/RESET IN COLOR
BASI C A N D EXTEN D E D COLOR
BAS IC.
DISPLAY FORMAT
ELEMENT FORMAT
�
I
64 H O R I ZONTAL E L E M E N T S
" " " """' '°"".'"
"'I'"",
32
VE RTICAL
E L E MENTS
_
12
� ---+----+I
1 C H A RACTER
P O S I T I ON
·�
8
BYTE MAPPING
MEMORY MAPPING
+o
L I N E l , CP 1
+l
L I N E 1 , CP 2
��
+32
L I N E 2 , CP 1
+33
L I N E 2 , CP 2
+ 510
+511
<�
J 1 Jc J c Jc J�J�JI J5J
N O R M A L START
= 1 0 2 4 10
7
--t--_
�
> 5 1 2 BYTES
0
'---....--J ..._____,
COLOR
<<
L I N E 1 6 , CP 3 1
I F B I TS = O ,
E L EM E N T I S OFF,
I F = 1, O N
LINE 16, CP 3 2
COLORS
BORDER
CHARACTER/BACKGROUND
BLACK
CCC
000
001
010
01 1
1 00
1 01
1 10
111
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
USE
SET/RESET when in text display uses this mode in both Color BASIC and Extended
Color BASIC. Alphanumeric mode above and this mode can be used together
by storing proper bytes in text buffer. Graphics bytes will have bit 7 set.
Appendices
217
MODE 3
BASIC MODE
S E M I G RA P H I C 6
NOT I M P L E M E NTED. MUST B E SET
AS D E S C R I B E D U N D E R "USE."
DISPLAY FORMAT
ELEMENT FORMAT
�1
'"
' " ' "" " " " " " "
6 4 H O R I Z O N TA L E L E M E N TS
4
--
48
VERTICAL
E L E M ENTS
( 16 L I N E S )
j
1 C H A R AC T E R
POS I T I O N
�J
8
MEMORY MAPPING
+O
L I N E 1, C P 1
+l
L I N E I , CP 2
;�
+32
LINE 2 , CP 1
+33
L I N E 2 , CP 2
+ 510
+ 51 1
'�
BYTE MAPPING
r--_
SET START
AS R E Q U I R E D
0
7
i c ic ! � 1� 1 � 1 � 1 \ l 6 I
��
'--_,-/ '--����--'
> 5 1 2 BYTES
COLOR
«
L I N E 16, CP 3 1
IF B I TS = O ,
E L E M EN T IS O F F ,
I F = 1 , ON
L I N E 1 6 , CP 3 2
COLORS
BORDER
USE
4
CHARACTER/BACKGROUND
BLACK
cc
00
01
10
11
00
01
10
11
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
)
)
css
css
=
=
0
1
1 . A = P EEK (6531 4) : POKE 653 1 4, (A AND 7) + B + X where X = 0 for CSS
0 OR 1 6 for CSS 1 .
2. POKE 65476, 0 = POKE 65474, 0 : POKE 65472, 0.
3. Set START by POKEs to 65,478-65,491 . See Chapter 2.
4. Store bytes in 51 2-byte video display area as required.
218
Appendices
MODE 4
BASIC MODE
S EM I G RA P H I C 8
NOT IM PLEM ENTED. MUST BE S ET
AS DESCRIBED U N D ER "USE."
ELEMENT FORMAT
DISPLAY FORMAT
_--+_
ZONTAL ELEMENTS
64( 32HORICHARACTER
POSITIONS)
64 CAL
VERTI
ELEMENTS
(16 LI N ES) I CHARACTER
POSITION
MEMORY MAPPING
+o+I ROWROW A,A, LILINNEE II,, CPICP 2
+2 ROW A, LI N E I, CP 3
+32+33+31 ROWROWROW B,B,A, LILILINNNEEE I,II,, CP2CPCPI32
+128 ROWROW A,A, LILINNEE 2,2, CPICP2
+!29
+2046
+2047 ROWROW D,D, LILINENE 1166,, CPCP3132
�
;
ROW A
B
12
BYTE MAPPING
�
�
SET START
ASREQUI
RED
2048
BYTES
·r:1·1·1·1�111 ·1:f.
'I I I I I I I I }"
'I I I I I I I I �I...
I' I COLORI I I ION/OFFI I �I·"
0
'
•
•
•
� �
•
'
•
•
•
•
•
\
•
•
•
•
•
\
•
� '------....,,--
X
ELEMENT
�DON'STATE
T CARE
Appendices
Semlgraphlc 8 continued
COLORS
BORDER
CHARACTER/BACKGROUND
BLACK
CCC
000
001
010
01 1
1 00
1 01
110
111
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
USE
1.
2.
3.
4.
A = PEEK (6531 4) : POKE 653 1 4, (A AND 7) .
POKE 65475, 0 : POKE 65475, 1 : POKE 65472, 0.
Set START by POKEs to 65,478-65,491 . See Chapter 2.
Store bytes in 2048-byte video display area as required.
219
220
Appendices
MOOE 5
BASIC MODE
S EM I G RA P H I C 1 2
NOT I M PLEMENTED. MUST BE SET
AS DESCRIBED U N D ER "USE."
DISPLAY FORMAT
ELEMENT FORMAT
t+--+--
ZONTAL POSIELEMENTS
(6432 HORICHARACTER
TIONS!
96ELEMENTS
VERTI
C
AL
(16 LINES! I CHARACTER
POSI T I O N
12
�
BYTE MAPPING
MEMORY MAPPING
+O+
+2
+32+3+33I
+192
+193
+3070
+307
I
:
:!:.
I
ROWROW A,A, LILINNEE I, CPIGP 2
ROW A, LINE I, CP3
ROWROW A, LILINNEE I, CP32
ROW B, LINE CPICP2
ROWROW A,A, LILINNEE 2,2, GPCP2
ROWROW F,F, LILINNEE 1166,, CP31
CP32
I,
8,
I,
I,
I
:
8
SETREQUI
AS START
RED
3072
BYTES
ON /OFF
COLOR ELEMENT
STATE
•DON'T CARE
X
Appendices
Semlgraphlc 1 2 continued
CHARACTER/BACKGROUND
COLORS
BORDER
BLACK
CCC
000
001
01 0
01 1
1 00
101
110
111
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
USE
1.
2.
3.
4.
A = PEEK (6531 4) : POKE 6531 4, (A AND 7).
POKE 65477, 1 : POKE 65474, 0 : POKE 65472, 0.
Set START by POKEs to 65,478-65,491 . See Chapter 2.
Store bytes in 3072-byte video display area as required.
221
222
Appendices
MODE 6
BASIC MODE
S E M I G RAPHIC 24
NOT IM PLEM ENTE D. MUST BE S ET
AS DESCRIBED U N D E R "USE."
DISPLAY FORMAT
ELEMENT FORMAT
�
ROW
64 H O R I Z O N TA L E L E M E N T S ( 32 C H A R A C T E R POS I T I O N S )
192
VER T I C A L
E L E M ENTS
( 16 L I N E S )
12
m
1 CHARACTER
POSITION
K �_.c...<...'-477-.,.,..-;,..,j
L L---=c:-----":.L.<..::....:.L..LJ
MEMORY MAPPING
+O
ROW A, L I N E 1, C P l
+1
R O W A, L I N E 1 , C P 2
+2
ROW A , L I N E 1, C P 3
�
+31
ROW A, L I N E 1 , C P 3 2
+32
R O W B , LI N E 1, C P l
+33
+384
��
+ 3 85
+ 6 1 42
+ 6143
:
ROW B , L I N E 1 , C P 2
R OW A , L I NE 2 , C P l
R O W A , L I N E 2, C P 2
R O W L , L I N E 16, C P 3 1
R O W L, L I N E 1 6 , C P32
BYTE MAPPING
SET START
AS
R E Q U I RED
�
�
�
6144
BYTES
0
I
c
c
c
L
23
x
x
+O
B
1
c
c
c
L
21
L
20
x
x
+32
c
I
c
c
c
L
19
L
18
x
x
+64
D
I
c
c
c
L
17
L
16
x
x
+ 96
E
I
c
c
c
L
15
L
14
x
x
+ 128
F
I
c
c
c
L
13
L
12
x
x
+ 1 60
G
I
c
c
c
x
x
L
11
L
JO
+ 1 92
H
1
c
c
c
x
x
L
9
L
8
+224
I
c
c
c
x
x
L
7
L
6
+ 2 56
I
c
c
c
x
x
L
5
L
4
+ 2 88
I
c
c
c
x
x
L
3
+320
I
L
2
c
c
c
x
x
I
L
0
+352
A
K
L
L
22
L
'--...,---J �
COLOR
ON / O F F
ELEMENT
STATE
'
X • D O N T CARE
Appendices
Semlgraphlc 24 continued
COLORS
BORDER
CHARACTE�BACKG ROUND
BLACK
CCC
000
001
010
01 1
1 00
1 01
110
111
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
USE
1.
2.
3.
4.
A
PEEK (653 1 4) : POKE 6531 4, (A AND 7) .
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0.
Set START by POKEs to 65,478-65,491 . See Chapter 2.
Store bytes in 61 44-byte video display area as required.
=
223
224
Appendices
MODE 7
BASIC MODE
G RAPHICS 64
x
64 F
NOT I M PLEMENTED. M UST B E S ET
AS DESCR I B E D U N D E R "USE."
ELEMENT FORMAT
DISPLAY FORMAT
64 C O L U M N S
,
4
4
4
4
FOUR
COLORS
64
ROWS
64
64
123
BYTE MAPPING
MEMORY MAPPING
+o
R O W 1 , COL 1 - 4
+1
ROW 1, COL 5 -8
+2
:
ROW 1 , C O L 9 - 1 2
+15
ROW l , C O L 6 1 - 6 4
+16
R O W 2 , COL 1 - 4
+ 1 0 22
+ 1023
R O W 6 4 , COL 5 7 - 6 0
,
0
SET START
AS R E Q U I R ­
ED OR U S E
CURRENT
GRAPHICS
PAGE
,
cc
cc
c c
cc
COL
N+3
1024
BY T E S
COL
ROW 64, COL 6 1 - 6 4
N+2
�--- C O L N + l
'----- C O L N
COLORS
CHARACTER/BACKGROUND
BORDER
G R E E N I F CSS
css
1
=
=
0, BUFF IF
cc
00
01
10
11
00
01
10
11
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
}
}
css - o
css - 1
Appendices
Graphics 64
x
225
64 F contin ued
USE
1 . A = PEEK (653 1 4) : POKE 653 1 4, (A AND 7) + 1 28 + C where C = 1 28
for CSS
1 or 0 for CSS
0.
2. POKE 65473, 1 : POKE 65474, 0 : POKE 65476, 0.
3. Set START by POK Es to 65,478-65,491 (see Chapter 2) or use current graphics
page (Extended Color BASIC).
4. Store bytes in 1 024-byte video display area as required.
=
=
Appendices
226
MODE 8
BASIC MODE
G RAPHICS 1 28
x
64 T
NOT I M PLEMENTED. M U ST B E SET
AS DESCRIBED U N D E R "USE."
ELEMENT FORMAT
DISPLAY FORMAT
�� &a tfil �:
1 2 8 COLUMNS
64
R O WS
2
2
2
2
2
2
2
TWO
COLO R S
64
128
123
BYTE MAPPING
MEMORY MAPPING
+o
R OW l , C O L l - 8
+ l
R O W 1 , COL 9 - 1 6
+2
R O W 1, COL 1 7 - 2 4
+15
ROW 1 , COL 1 2 0 -1 2 8
+ 16
R O W 2, C O L 1 - 8
+1022
+1023
�
'
ROW 6 4 , C O L 1 1 2 - 1 19
'
S E T START
A S REQU I R ­
E D OR USE
CURRENT
GRAPHICS
PAGE
COL N + 7
1'
COL N+6
1024
BYTES
'---- COL N +5
�--- COL N+4
'----- COL N +3
ROW 6 4 , COL 1 2 0 - 1 2 8
1'
�------ COL N +2
'----- COL N + l
'------ COL N
COLORS
CHARACTER/BACKGROUND
BORDER
G R E E N IF CSS = 0 , BUFF IF
css = 1
c
0
1
0
1
BLACK
GREEN
BLACK
BUFF
css
=
0
css
=
1
USE
1 . A = PEEK (653 1 4) : POKE 653 1 4, (A AND 7) + 1 28 + 1 6 + C where
C
8 for CSS = 1 or 0 for CSS
0.
2. POKE 65473, 1 : POKE 65474, 0 : POKE 65476, 0.
3. Set START by POKE to 65,478-65,491 (see Chapter 2) or use current graphics
page (Extended Color BASIC).
4. Store bytes in 1 024-byte video display area as required.
=
=
Appendices
9
MODE
G RA P H I CS 1 28
x
64 F
NOT I M PLEMENTED. M UST BE SET
AS DESCR I B E D U N D E R "USE."
DISPLAY FORMAT
ELEMENT FORMAT
1
2
3
128 C O L U M N S
64
R OWS
FOUR
COLORS
64
128
123
MEMORY MAPPING
+O
R O W 1 , COL 1 - 4
+1
ROW 1 , COL 5 - 8
+ 2
R O W 1, COL 9- 1 2
�
+31
ROW 1 , C O L 6 1 - 6 4
+ 32
ROW 2, COL 1 - 4
'
+ 20 4 6
ROW 6 4 , C O L 57-60
+2047
ROW 64, COL 6 1 - 6 4
.
BYTE MAPPING
SET START
AS R E Q U I R ­
E D OR USE
C U R RENT
GRAPHICS
PAGE
�
0
cc
cc
cc
cc
2048
BYTES
."
COLORS
CHARACTER/BACKGROUND
BORDER
G R E E N IF CSS
css
=
1
227
BASIC MODE
0 , BUFF I F
cc
00
01
10
11
00
01
10
11
GREEN
YELLOW
BLUE
RED
BUFF
CYAN
MAGENTA
ORANGE
}
}
css
=
0
css
=
1
228
Appendices
Graphics 128
x
64 F continued
USE
1 . A = PEEK (6531 4) : POKE 6531 4, (A AND 7) + 1 28 + 32 + C where
C = 8 FOR CSS = 1 or 0 for CSS
0.
2. POKE 65472, 0 : POKE 65475, 0 : POKE 65476, 1 .
3. Set START by POKEs to 65,478-65,491 (see Chapter 2) or use current graphics
page (Extended Color BASIC).
4. Store bytes in 1 024-byte video display area as required.
=
Appendices
MODE
10
BASIC MODE
G RA P H I C S 1 28
x
96 T
P M O D E 0 ( Ext) OR "USE."
DISPLAY FORMAT
1 2 8 C OL U M N S
TWO COLORS
BY 96
ELEMENT FORMAT
ROWS,
2
2
M EMORY MAPPING
BYTE MAPPING
1536 BYTES. EACH BYTE HOLDS 8
C OL U M N S . S E T START OR USE PAGE.
lcl cl c l cl c l clc l
0
7
COLORS
BORDER
CHARACTER/BACKGROUND
G R E E N OR B U F F
0
0
=
=
BLK 1
BLK 1
=
=
G A N I F CSS = 0
B U F F IF CSS
1
USE
A
PEEK (6531 4) : POKE 6531 4, (A AND 7) + 1 28 + 32 + 1 6 + C
POKE 65476, 0 : POKE 65475, 1
POKE 65473, 1
=
=
=
229
230
Appendices
MODE 1 1
G RAPH ICS 1 28
BASIC MODE
x
96 F
DISPLAY FORMAT
1 2 8 C O LU M N S BY 96 R OWS,
FOUR C O L O R S
MEMORY MAPPING
3072 BYT E S. EACH BYTE HOLDS 4
C O L U M N S . S E T STA R T OR U S E PAGE.
PMODE 1 ( Ext) OR "USE."
ELEMENT FORMAT
Same as M ode 1 0
BYTE MAPPING
I
cc
cc
cc
cc
0
I
COLORS
BORDER
G R E E N OR B U FF
}
}
CHARACTER/BACKGROUND
00
GREEN
01 = YELLOW
1 0 = BLUE
11
RED
00 = BUFF
01
CYAN
1 0 = MAGEN TA
1 1 = ORANGE
=
=
=
(CSS OJ
(CSS 1 )
USE
PEEK (653 1 4) : POKE 6531 4, (A AND 7) + 1 28 + 64 + C
A
POKE 65477, 1 : POKE 65474, 0 : POKE 65472, O
=
Appendices
MODE
12
G RAPH ICS 1 28
BASIC MODE
x
1 92 T
DISPLAY FORMAT
PMODE 2 ( Ext) OR "USE."
ELEMENT FORMAT
128 C O L U M N S BY 192 R O W S ,
TWO C O L O R S
M EMORY MAPPING
BYTE MAPPING
3 0 7 2 B Y T E S . E AC H B Y T E H O L D S 8
COLU M N S . S E T STA R T OR USE P A G E .
COLORS
BORDER
CHARACTE�BACKGROUND
G R E E N OR B U FF
SAME AS 1 28
x 96
T
USE
A
PEEK (6531 4) : POKE 653 1 4 , (A AND 7) + 1 28 + 64 + 1 6 + C
POKE 65477, 1 : POKE 65474, 0 : POKE 65473, 1
=
231
232
Appendices
MODE 1 3
G RAPH ICS 1 28
BASIC MODE
x
1 92 F
DISPLAY FORMAT
1 2 8 C O L U M N S BY 1 9 2 ROWS,
FOUR C O L O R S.
MEMORY MAPPING
6 1 4 4 B Y T E S. E A C H BYTE HOLDS 4
C O L U M NS. S E T START OR USE PAGE.
P M O D E 3 ( Ext) OR "USE."
ELEMENT FORMAT
Same as M ode 1 2
BYTE MAPPING
I
cc
cc
cc
cc
0
I
COLORS
BORDER
G R E E N OR BUFF
CHARACTER/BACKGROUND
SAME AS 1 28
x
96
F
USE
A
PEEK (6531 4) : POKE 653 1 4, (A AND 7) + 1 28 + 64 + 32 + C
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0
=
Appendices
MODE
14
G RAPH ICS 256
BASIC MODE
x
1 92 T
DISPLAY FORMAT
PMODE 4 ( Ext) OR "USE."
ELEMENT FORMAT
256 C O L U M N S BY 192 ROWS,
T W O C O LO R S .
MEMORY MAPPING
BYTE MAPPING
6 1 4 4 BYT ES. E A C H BYTE H O L D S 8
COLU M N S. S E T STA R T OR U S E PA G E .
COLORS
BORDER
CHARACTE�BACKGROUND
G R E EN OR B U FF
SAME A S 1 28
x
96
T
USE
PEEK (653 1 4) : POKE 6531 4, (A AND 7) + 1 28 + 64 + 32 + 1 6 + C
A
POKE 65477, 1 : POKE 65475, 1 : POKE 65472, 0
=
233
Index
235
I n d ex
ACTION items, 1 52
A N D, 1 53
N OT, 1 53
OR, 1 53
PRES ET, 1 53
PSET, 1 52
Address s pace, 1
American Standard Code for
I n format ion I nterchange
(ASCI I), 9, 1 32
A N D , 1 53
A l p h a n u meric characters i n
graphics modes, 1 6 1
A l p h a n u meric mode, 6
inve rted, 7
non-i nverted, 1 1
A l pha sem i g ra p h i c mode, 7
A n i mation, 66, 1 39, 1 43, 1 78
A n g l e command (A), 1 30, 1 90
Arcs , d raw i ng , 1 1 3, 1 63
A rrays, 1 45, 1 76
RAM s pace for, 1 49
two-d i mension a l , 1 76
A s pect rati o, 1 08
Assembly l an g u age, 69
Automat i c erase, 1 77
Bar graphs, 61
BAS I C i nterpreter, 3, 12
Bit, 2
most s i g n i ficant, 1 0, 24
B l a n k command (B), 1 27
B l a n k l i ne, d raw i ng, 1 1 9
Border out l i ne, d raw ing, 1 65
Boxes:
d raw i n g , 1 03
d raw i n g f i l l ed- i n , 1 04
Byte, 2
C I RCLE command, 99, 1 05, 1 63,
1 67
defau lt va l u e of, 1 1 7
CI RCLE coord i nates, convert i ng to,
1 13
C i rcles:
d rawi ng, 1 05, 1 66
f i l l i ng i n , 1 1 1
C LS command, 53
format for, 56
Color BAS I C, 53, 69
Color code, 56
COLOR command, 73, 82
Color command (C), 1 28
Color set, 74
Color set select (CCS) s i g n a l , 34
Colors:
background, 82
border, 82
chan g i n g , 73
foreground, 82
Concatenat ion, 65, 1 32
Coord i nates, 91
Cartes ian, 91
convert i n g , 92
D I M statement, 1 46
values for, 1 50
Dot-mat rix characters, 6, 1 6 1
DRAW command, 99, 1 6 1 , 1 72, 1 86,
1 89, 1 90
format for, 1 20
motion, 1 21
mode, 1 2 1
sca l i n g , 1 34
S option, 1 34
E l l i pse, 1 09
draw i ng, 1 67
Eng i ne, an imation of, 66
Extended Color BASIC, 42, 73, 85
i n itial izat ion of, 73
236
Index
G ET/PUT command, 99, 1 39, 1 43,
1 76
format for, 1 49, 1 51
Graphics generator chip, 1
G raphics matrix, 85
G raph ics modes, 1 , 6, 7, 73
alphanu meric characters i n , 1 6 1
border and color set for, 33
chang i ng , 1 74
memory req u i rements for, 31 , 35
resoluti ons of, 85
video memory mapping i n , 34
64 x 64 F, 37
1 28 x 64 T, 39
1 28 x 64 F, 40
G raphics pages, 49
memory location of, 77
Height : w i dth ratio, 1 08, 1 67
H i gh-reso l ution mode, 4
I ndex ing, 1 76
mov i ng f i g u res by, 1 78
I n p ut-output addresses, 3
L I N E command , 99, 1 0 1 , 1 7 1 , 1 85,
1 88
col ors i n , 1 02
d i rection of, 1 05
speed of, 1 0 1 , 1 05
Li nes, d rawi n g , 1 00, 1 1 9, 1 7 1 , 1 72
Low-resolution mode, 4
M EM command, 1 48
Memory mapping, 1 , 75
M i x i n g a l p h a n u merics and
g raphics, 64, 1 68
M ost s i g n i ficant bit, 1 0, 24
M oves:
absol ute, 1 23
f i g u re, 1 76, 1 78
rel at ive, 1 23
N o n-ASC I I codes, 1 32
NOT, 1 53
No Upd ate com mand (N), 1 29
Octagon, d raw ing, 1 80
OR, 1 53
PAINT command, 99, 1 39, 1 86
format for, 1 39
leaking, 1 4 1
s peed of, 1 41
PCLEAR com m and, 49, 73, 79
defau lt value of, 79
PCLS command, 73, 80, 1 78
PCOPY command, 73, 80
Pento m i no, 1 90
Pixel (pi ctu re e lement), 6
Plott ing, 90
s i ne g raph, 94
PMODE command, 36, 73, 79
default val u e of, 79
format for, 36
PMODE 0, 42, 74
PMODE 1 , 43, 74
PMODE 2, 44, 74
PMODE 3, 44, 74
PMODE 4, 45, 74
other colors i n , 1 82
POI N T command, 53
format for, 53
PPO I NT command, 85
format for, 89
speed of, 89
PRESET command, 85
format for, 88
speed of, 90
PSET command, 85, 1 82
format for, 87
speed of, 90
Rad ians, 95
Random-access memory
(RAM), 1 , 3, 75
Rectang les:
d raw i n g f i l led- i n , 1 83, 1 85
d ra wing outl i ne of, 1 88, 1 89
Read-on ly memory (ROM), 1 , 3
cartridge, 3
RESET com mand, 53
format for, 58
speed of, 59
typical uses of, 61
Resol utions, 4
chang i n g , 73
speeds i n , 6
tradeoffs i n , 5
Rotat ion, f i g u re, 1 90
Scale d rawi ng , 1 1 9
SCRE EN command, 73, 74, 78
format for, 33
Screen location, chang ing, 73
Sem igraphics modes, 1 3
Index
Sem i g raph ic 4 mode, 1 3, 1 5, 53
col ors i n , 1 5
Sem i g raph ic 6 mode, 1 3, 1 7
colors i n , 1 8
mapp i n g for, 1 7
Semigraphic 8 mode, 1 3, 20
colors i n , 21
memory req u i rements of, 20
S ET/RESET, 1 92
Semigraphic 1 2 mode, 1 3, 23
colors i n , 24
memory req u i rements of, 23
SET/RESET, 1 94
Semigraphic 24 mode, 1 3, 26
SET/RESET, 1 96
SET com mand, 53
format for, 58
speed of, 59
typ ical u ses of, 6 1
Spec i a l characters, 1 6 1
Squ are, d raw i n g , 1 98
Strings, 1 32
character, 65
command, 1 1 9
concatenated, 1 33
constant, 1 32
tem porary, 1 33
Stri pes, 1 82
Subst r i n g s , 1 32, 1 33
command, 1 1 9
Text screen , 76
Tria n g l e , d raw i ng , 201
Trigonometric representat i o n , 1 1 4
USR ca l l , 70
V ideo d i s p l ay generator (VDG), 6,
1 6, 33, 73
Video memory, 3
cha ng i ng start of, 200
X (execute) command, 1 33
23 7

advertisement

Related manuals

advertisement