-
Notifications
You must be signed in to change notification settings - Fork 7
/
using_screen_and_keyboard.tex
429 lines (343 loc) · 18.4 KB
/
using_screen_and_keyboard.tex
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
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
%----------------------------------------------------------------------------------------
% PART - Using the Screen and Keyboard
%----------------------------------------------------------------------------------------
\makeatletter\@openrightfalse
\part{Using the Screen and Keyboard}
\chaptertypein{
\keybackgroundcolor{gray}
\keytextcolor{black}
10 PRINT "\shiftkey\clrhomekey"\\
20 SLEEP 10\\
30 PRINT "your name"\\
40 SLEEP 10\\
50 GOTO 10
}
\newpage
\partheading{Using the Screen and Keyboard}
This chapter assumes that you've read and understand Chapter 1: {\emph Getting
to Know Your Commander X16}. If you not, go back and read it.\\
Now that you have written your first program in BASIC on the Commander X16,
it's time to look at the simplest thing you can make the X16 do: displaying
characters\footnote{A 'character' is any symbol that can be displayed on the
screen, such as letters, numbers, punctuation, and the graphic symbols that can
be typed} to the screen. As you've already seen, the {\ttfamily PRINT}
statement can be followed by a series of character surrounded by quotation
marks, causing the series of charcters to be displayed to the screen. This
series of characters is called a {\em string}. Let's write a program to print
a string to the screen.\\
It's nice to start a new program on an empty screen, so lets clear the screen
and place the cursor at the top by holding down the \shiftkey key and pressing
the \clrhomekey key. To tell the Commander X16 that you are writing a new
program, type \keybackgroundcolor{white}\key{n}\key{e}\key{w} and then press
the \returnkey key. Now you can begin to type the following program, paying
attention to line number and punctuation marks:\\
\key{1}\key{0} \spacebar \key{p}\key{r}\key{i}\key{n}\key{t} \spacebar
\key{"}\key{h}\key{e}\key{l}\key{l}\key{o}\key{,} \spacebar
\key{w}\key{o}\key{r}\key{l}\key{d}\key{!}\key{"} \returnkey
\note {
The \key{,} key is just the \doublekey{<\\,} key pressed {\em without}
holding the \shiftkey key, and the \key{!} key is just the \doublekey{!\\1}
key pressed {\em while} holding the \shiftkey key.
}
Now that your program is typed into the X16, run it by typing
\key{r}\key{u}\key{n} and pressing \returnkey.
You should see the following printed to the next line:
\codeblock {
HELLO, WORLD!\\
}
After your program finishes printing out the message, it should print a blank
line, a line with the {\ttfamily READY} prompt, and finally place your blinking
cursor on the following line. Your screen should look something like this:\\
\begin{center}
\screenbox{2.75in}{2in}{
NEW\\
READY.\\
10 PRINT "HELLO, WORLD"\\
RUN\\
HELLO, WORLD!\\
READY.\\
\cursor
}
\end{center}
When you typed {\ttfamily NEW} and hit \returnkey, the Commander X16 also left
a blank line followed by the {\ttfamily READY} prompt, just as it did when your
own program ran. You can think of BASIC commands like {\ttfamily NEW} as being
built-in programs, and they act much in the same way as the programs you will
write.\\
%----------------------------------------------------------------------------------------
% CHAPTER - The PRINT Statement
%----------------------------------------------------------------------------------------
\chapter*{The PRINT Statement}
\addcontentsline{toc}{chapter}{\protect\numberline{}The PRINT Statement}
Now that we've used the {\ttfamily PRINT} statement to display a string of
letters to the screen, let's look at how it can display numbers. You can
re-use your existing program by overwriting the statement at line 10. Do do
this, simply type {\ttfamily 10} followed by the BASIC statement you want to
replace line 10 with. In this case, let's replace it with a {\ttfamily PRINT}
statement that prints numbers instead of letters:\\
\codeblock {
10 PRINT "42"\\
}
Make sure you press \returnkey so that the Commander X16 accepts the new line,
and replaces the old one in your program. Now if you type {\ttfamily RUN} and
hit \returnkey, you should see:
\codeblock{
42\\
}
This example isn't much different than the last example, because we simply
printed a different string. The number {\ttfamily 42} is given to the
{\ttfamily PRINT} statement as a string, just as {\ttfamily HELLO, WORLD!} was
given as a string. To the {\ttfamily PRINT} statement, it doesn't matter which
characters are put inside the quotations marks; it always views them as just a
series of characters. However, the {\ttfamily PRINT} statement is able to
display a number to the screen while treating it as a number. For example,
replace line 10 with:\\
\codeblock {
10 PRINT 42\\
}
Notice that there are no quotation marks. When type {\ttfamily RUN}, you will
notice a slight difference:\\
\codeblock{
\hspace*{0.6em}42\\
}
Do you see it? There is an empty space before the number. This is because the
{\ttfamily PRINT} statement leaves a space for a sign indicator (positive or
negative) when it prints a number. For positive numbers nothing is displayed,
but if given a negative number, {\ttfamily PRINT} will fill that space with a
{\ttfamily -}. Try replacing {\ttfamily 42} with {\ttfamily -42} and running
the program again.\\
Now that you have the {\ttfamily PRINT} statement treating the value as a
number, you can try passing it a mathematical expression that the X16 will {\em
compute} into a number:\\
\codeblock {
10 PRINT 3+2\\
}
You should see:\\
\codeblock {
\hspace{0.6em}5\\
}
Now you can compare this result with what happens if we pass {\ttfamily 3+2} to
{\ttfamily PRINT} as a string:\\
\codeblock {
10 PRINT "3+2"\\
}
This time you should see:\\
\codeblock {
3+2\\
}
When you pass a value to {\ttfamily PRINT} inside of quotation marks, it treats
it as a series of characters, Specifically "3", "+", and "2". {\ttfamily
PRINT} is also smart enough to accept a mixture of strings and numeric
values:\\
\codeblock {
10 PRINT "THERE ARE" 5+3 "BITS IN A BYTE"\\
}
%----------------------------------------------------------------------------------------
% CHAPTER - Graphic Characters
%----------------------------------------------------------------------------------------
\chapter*{Graphic Chracters}
\addcontentsline{toc}{chapter}{\protect\numberline{}Graphic Chracters}
Sit down in front of the Commander X16 keyboard and look at the keys. If
you're familiar with regular computer or typewriter keyboard, you'll notice
that the X16 Keyboard's keys are different. Rather than just having letters,
numbers, and punctuation on them, you'll see that most keys also have one or
more "graphic characters" printed on them. While the regular characters can be
typed by simply pressing the keys, the graphics characters can be typed by
holding down either \shiftkey or \altkey and pressing one of the keys with
graphics characters. For example, try holding down the \shiftkey key and
pressing the \keybackgroundcolor{white}\key{s} key. Instead of an 'S', a heart
should appear on the screen. Now press and hold down the \altkey key and press
\key{s}. This time a right-angled graphic character should appear. Holding
the \shiftkey key causes the graphic character on the right to be typed, and
holding the \altkey key causes the graphic character on the left to be typed.\\
Graphic characters can be used to create larger shapes and images on the
screen. For example, the graphic characters that can be typed by holding
\altkey and typeing \key{a}, \key{s}, \key{z}, and \key{x} can be used to
create a square that is larger than a single character. If you include the
graphic characters that can be typed by holding \shiftkey and typing \key{c}
and \key{b}, you can draw a rectangle as large as the entire screen! If you
want your rectangle to have rounded corners, you can use the graphic characters
on the \key{u}, \key{i}, \key{j}, and \key{k}.\\
Spend some time experimenting with the other graphic characters to see what
kinds of shapes and designs you can draw. You can use the arrow keys to
position the cursor wherever you need to type.\\
% To start, sit down in front of the Commander X16 Keyboard and type the
% following:\\
%
% Hold down the \shiftkey key and press the \clrhomekey key. Then type
% \keybackgroundcolor{white}\key{N}\key{E}\key{W} and press the \returnkey key.\\
%
% This will clear any program currently programmed so that the X16 is ready to
% accept a new one.
%----------------------------------------------------------------------------------------
% CHAPTER - Colors
%----------------------------------------------------------------------------------------
\chapter*{Colors}
\addcontentsline{toc}{chapter}{\protect\numberline{}Colors}
The Commander X16 is also capable of displaying characters in different colors.
If you look at the number keys on the Commander X16 keyboard, you will see that
numbers 1-8 have colors listed next to the numbers. By holding down either
\altkey or \ctrlkey and pressing one of the numbers with colors listed on them,
you can change the color of the characters you type. Holding \ctrlkey while
you type the number will select the top color, and holding \altkey while you
type the number will select the bottom color. This allows for a total of 16
different colors that can be used to type characters:\\
\begin{tabular}{|c|c|c|}
\hline
Key & CTRL & ALT\\ \hline
1 & Black & Orange \\ \hline
2 & White & Brown \\ \hline
3 & Red & Light Red \\ \hline
4 & Cyan & Dark Gray\\ \hline
5 & Purple & Medium Gray\\ \hline
6 & Green & Light Green\\ \hline
7 & Blue & Light Blue\\ \hline
8 & Yellow & Light Gray\\ \hline
\end{tabular}
\vspace{16pt}
You may also noticed that \key{9} has "RVS ON" and \key{0} has "RVS OFF" where
the colors are listed on the other number keys. These are "reverse on" and
"reverse off", and can be typed by holding down \ctrlkey while pressing the
number. When "reverse on" is typed, it switches which color is used for the
chracter and which one is used for the background. For example, if you have
the character colors set to white and the background color set to blue, hitting
\ctrlkey + \key{9} will cause the characters you type next to be displayed in
blue with a white background. Because each character can be printed with the
colors reversed, it's like there are twice as many characters! This allows for
a lot of creativity in making drawings and designs with a combination of
graphic characters and colors. To turn off "reverse", just press \ctrlkey +
\key{0}.\\
\section{Setting Colors While PRINTing}
When you are typing the text of a print statement, you can use \ctrlkey and
\altkey with the number keys to change and reverse the colors. However, the
colors will not display on the screen in their new colors immediately.
Instead, a graphic character will be written to the text of your {\ttfamily
PRINT} statement. When the {\ttfamily PRINT} statement executes, this graphic
character will tell the Commander X16 to switch to that color as it is printing
the text. This also works with the "RVS ON" and "RVS OFF" functions. By using
this technique, you can change the color of the text multiple times (or even
reverse it) all from a single {\ttfamily PRINT} statement. If you don't want
your text to stay that way, remember to set it back to how you want it before
your program ends!\\
\section{The COLOR Statement}
The colors can also be set by running the {\ttfamily COLOR} statement. On a
new line, try typing {\ttfamily COLOR 2} and then pressing \returnkey. You
should see the "READY" prompt printed to the screen in red. Now anything you
type will also be in red. This is the same effect as holding \ctrlkey and
pressing \key{3}. The {\ttfamily COLOR} statement allows you to set the
foreground color to the first 16 colors of the Commander X16's
palette\footnote{A "palette" refers to a set of predefined colors that can be
used on the Commander X16. More information on palettes will be discussed in
the chapter on Graphics}. Because of the way computers work, you specify which
color by typing a number from 0-15 instead of 1-16.
The numbers that specify colors with the {\ttfamily COLOR} statement do not
correspond to the number keys pressed to change the color. This is because
there are only 8 number keys that contain colors, but there are 16 colors to
choose from. The order is the same, however, if you read all the top color
values of the number keys from left to right and then read all the bottom
values from left to right. If you start numbering with 0, you get the values
that you can use with the {\ttfamily COLOR} statement:\\
\begin{tabular}{|c|c|c|c|}
\hline
Number & Color & Number & Color\\ \hline
0 & Black & 8 & Orange \\ \hline
1 & White & 9 & Brown \\ \hline
2 & Red & 10 & Light Red \\ \hline
3 & Cyan & 11 & Dark Gray\\ \hline
4 & Purple & 12 & Medium Gray\\ \hline
5 & Green & 13 & Light Green\\ \hline
6 & Blue & 14 & Light Blue\\ \hline
7 & Yellow & 15 & Light Gray\\ \hline
\end{tabular}
\vspace{16pt}
The {\ttfamily COLOR} statement can also be used to set both the foreground
color and the background color. The first argument is the color to use for the
foreground and the second argument is the color to use for the background.
Separate the two arguments with a comma, like so:\\
\codeblock {
COLOR 13,0\\
}
The above call to the {\ttfamily COLOR} statement will set the foreground color
to light green and the background color to black. Just like the {\ttfamily
PRINT} statement, the {\ttfamily COLOR} statement can be used in a BASIC
program. When run in a program, it does not advance to the next line nor cause
the "READY" prompt to be printed. This means that the {\ttfamily COLOR}
statement can be used to change the foreground and background colors in between
calls to the {\ttfamily PRINT} statement without printing extra lines that you
don't want. It is also possible to call the {\ttfamily PRINT} statement in a
way where it does not advance the cursor to the next line, but instead leaves
it at the end of the characters that have just been printed. In order to use
{\ttfamily PRINT} without advancing to the next line, simply type a ';' at the
end of the statement:\\
\codeblock{
10 PRINT "X";\\
}
Now the next {\ttfamily PRINT} statement in the program will start printing
directly after the "X" that was written to the screen. If we use the
{\ttfamily COLOR} statement before the next {\ttfamily PRINT} statement, we can
change both the background and foreground colors of characters that are next to
each other on a line:\\
\codeblock{
10 PRINT "X";\\
20 COLOR 2,1\\
30 PRINT "X";\\
}
%----------------------------------------------------------------------------------------
%CHAPTER - Keyboard
%----------------------------------------------------------------------------------------
\chapter*{The X16 Keyboard}
\addcontentsline{toc}{chapter}{\protect\numberline{}The X16 Keyboard}
Molestiae ad dicta praesentium et. Placeat magnam nihil est animi vel eos. Sunt
consectetur nobis minima ut reiciendis hic non sed. Officiis sint voluptas non
quo eos architecto. Nulla et est laboriosam voluptatem. Iure sed et ducimus
nostrum est eveniet. Natus aut praesentium fugit. In quae tempora sunt autem
illum perspiciatis. Amet laborum numquam aut occaecati. Quia ad ab voluptas qui
autem. Qui voluptatum quibusdam est aliquam in. Quae ipsum aperiam aut saepe
molestiae natus sit. Totam autem veritatis deserunt. Hic ut excepturi porro. Et
ut vero voluptas iusto earum velit rerum. Assumenda enim voluptatum praesentium
quam. Rerum optio iste odit. Id quia ratione quasi. Doloremque et omnis autem
dolor. Vel minima numquam enim asperiores quae magni soluta a. Corrupti sint
sit sunt cum sunt asperiores animi rerum. Consectetur sunt itaque ducimus
soluta sed quod qui. Blanditiis alias rem ea. Doloremque nobis voluptas eius
occaecati mollitia temporibus enim ut. Quia consequuntur molestias quae modi
consequatur eveniet consequuntur.
%----------------------------------------------------------------------------------------
%CHAPTER - Screen Modes
%----------------------------------------------------------------------------------------
\chapter*{Screen Modes}
\addcontentsline{toc}{chapter}{\protect\numberline{}Screen Modes}
Minima ut quasi aliquid sapiente quo. Id veritatis ipsa vitae molestias velit
modi natus et. Quia incidunt totam laboriosam nostrum sed nihil. Assumenda
reiciendis molestiae quidem enim quis. Eius excepturi neque dolorem quia.
Nesciunt et consequuntur expedita enim soluta in recusandae. Reprehenderit
rerum ut facilis aut eius. Velit eveniet esse dolorem dolores tempore ratione
tempora. Iste sequi architecto dolores repellendus rem quia sequi. Voluptas
error maxime ipsam est sint saepe. Nulla similique eos dolorem esse nobis autem
nam a. Aut fugit quae reprehenderit qui. Minima dolorum nihil sapiente dolorem
porro minima id. Perspiciatis natus numquam voluptatum. Qui sint nemo
praesentium exercitationem voluptatem esse. Et perferendis praesentium
voluptatibus. Occaecati facere eligendi eos eum exercitationem. Nobis aperiam
inventore laudantium eius consequatur cupiditate. Tempora dolore culpa magni ut
eum sint voluptatibus. Quasi repudiandae necessitatibus repellendus cumque quia
dolorum. Illo et ut qui. Ut alias et quod repellat sit nobis. Officiis
doloremque quaerat vitae iste. Et nostrum pariatur dolorum iusto nulla quae ab.
Et voluptatem itaque quae perspiciatis quia.
%----------------------------------------------------------------------------------------
% CHAPTER - Editing Text
%----------------------------------------------------------------------------------------
\chapter*{Editing Text}
\addcontentsline{toc}{chapter}{\protect\numberline{}Editing Text}
Ea repudiandae laboriosam omnis consequatur omnis quam nesciunt est. Hic
voluptate explicabo sint pariatur mollitia. Omnis asperiores in praesentium
dolor quibusdam. Odit vitae possimus ut recusandae quia sapiente ipsum non.
Optio error velit eligendi. Facere itaque tenetur fugiat. Aspernatur magnam
tenetur nulla aspernatur architecto. Repellat repudiandae autem sunt qui.
Libero vel dolorem sed mollitia. Voluptatem eligendi minima voluptatum facere
aut magnam laborum vel. Quis rem officia aliquam nisi quisquam dolor quia.
Nobis magni non eos explicabo. Qui nisi in est voluptatem enim a repellendus.
Id quia incidunt enim sint impedit recusandae. Ut sit ut neque. Et sit delectus
id excepturi. Vero maiores libero minus. Ad accusantium sed ut vitae quia
earum. Iusto fugit repudiandae aut. Illum atque et dolores. Suscipit qui culpa
dolor. Voluptatibus consequuntur culpa ab vitae. Totam libero harum quia. Ipsa
aut minima labore eaque eos ipsam. Nulla quae eius tempore.
\@openrighttrue\makeatother