forked from MEGA65/mega65-user-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappendix-basic10-condensed.tex
7595 lines (6432 loc) · 223 KB
/
appendix-basic10-condensed.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{BASIC 65 Command Condensed Reference}
For the full-length version of the BASIC 65 reference,
please refer to either the MEGA65 Book or the MEGA65 BASIC 65
Reference Guide.
\section{Format of Commands, Functions and Operators}
This appendix describes each of the commands, functions and other
callable elements of BASIC 65.
Some of these can take one or more arguments, that is, pieces of input
that you provide as part of the command or function call.
Some also require that you use special keywords.
Here is an example of how commands, functions and operators will be
described in this appendix:
{\bf KEY <numeric expression>,<string expression> }
In this case, KEY is what we call a \textbf{keyword}. That just means
a special word that BASIC understands.
Keywords are always written in CAPITALS, so that you can easily
recognise them.
The {\bf <} and {\bf >} signs mean that whatever is between them must
be there for the command, function or operator to work.
In this case, it tells us that we need to have a
{\bf numeric expression} in one place, and a {\bf string expression}
in another place.
We'll explain what there are a bit more in a few moments.
You might also see square brackets around something, for example,
{\bf [,numeric expression]}.
This means that whatever appears between the square brackets is
optional, that is, you can include it if you need to, but
that the command, function or operator will work just fine without it.
For example, the \screentext{CIRCLE} command has
an optional numeric argument to indicate if the circle should be filled
when being drawn.
The comma, and some other symbols and punctuation marks just represent themselves.
In this case, it means that there must be a comma between the
{\bf numeric expression} and the {\bf string expression}.
This is what we call syntax: If you miss something out, or put the
wrong thing in the wrong place, it is called a
syntax error, and the computer will tell you if you have a syntax error
by giving a \screentext{?SYNTAX ERROR} message.
There is nothing to worry about getting an error from the computer.
Instead, it is just the computer's way of telling you that something
isn't quite right, so that you can more easily
find and fix the problem.
Error messages like this can't hurt the computer or damage your program,
so there is nothing to worry about.
For example, if we accidentally left the comma out, or replaced it with
a full-stop, the computer will respond with
a syntax error, like this:
\newpage
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
KEY 8"FISH"
?SYNTAX ERROR
KEY 8."FISH"
?SYNTAX ERROR
\end{verbatim}
\end{tcolorbox}
It is very common for commands, functions and operators to use one or
more {\bf``expression''}.
An expression is just a fancy name for something that has a value.
This could be a string, such as \screentext{"HELLO"}, or a number, like
\screentext{23.7}, or it could be a calculation, that might include
one or more functions or operators, such as \screentext{LEN("HELLO") * (3 XOR 7)}.
Generally speaking, expressions can result in either a string or numeric result.
In this case we call the expressions either string expressions or numeric expressions.
For example, \screentext{"HELLO"} is a {\bf string expression}, while
\screentext{23.7} is a {\bf numeric expression}.
It is important to use the correct type of expression when writing your programs.
If you accidentally use the wrong type, the computer will give you a
\screentext{?TYPE MISMATCH ERROR}, to say that the type
of expression you gave doesn't match what it expected, that is, there
is a mismatch between the type of expression
it expected, and the one you gave. For example, we will get a
\screentext{?TYPE MISMATCH ERROR} if we type the following command,
because \screentext{"POTATO"} is a string expression instead of a numeric expression:
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
KEY "POTATO","SOUP"
\end{verbatim}
\end{tcolorbox}
You can try typing this into the computer yourself now, if you like.
\section{Commands, Functions and Operators}
Commands are statements that you can use directly from the {\bf READY.}
prompt, or from within a program, for example:
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
PRINT "HELLO"
HELLO
10 PRINT "HELLO"
RUN
HELLO
\end{verbatim}
\end{tcolorbox}
% =======================================
% Start of the BASIC 65 command reference
% =======================================
\titleformat*{\subsection}{\normalfont\huge\bfseries\color{blue}}
% ***
% ABS
% ***
\subsection{ABS}
\index{ABS}
\index{BASIC 65 Functions!ABS}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$B6
\item [Format:] {\bf ABS(x)}
\item [Usage:] The numeric function {\bf ABS(x)} returns
the absolute value of the numeric
argument {\bf x}. \\
{\bf x} = numeric argument (integer or real expression).
\item [Remarks:] The result is of real type.
\item [Example:] Using {\bf ABS}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
PRINT ABS(-123)
123
PRINT ABS(4.5)
4.5
PRINT ABS(-4.5)
4.5
\end{verbatim}
\end{tcolorbox}
\end{description}
% ***
% AND
% ***
\subsection{AND}
\index{AND}
\index{BASIC 65 Operators!AND}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$AF
\item [Format:] operand {\bf AND} operand
\item [Usage:] The Boolean {\bf AND} operator performs a bit-wise
logical AND operation on two 16-bit values.
Integer operands are used as they are.
Real operands are converted to a signed 16 bit integer.
Logical operands are converted to 16 bit integer
using \$FFFF, decimal -1 for TRUE
and \$0000, decimal 0, for FALSE.
\begin{verbatim}
0 AND 0 -> 0
0 AND 1 -> 0
1 AND 0 -> 0
1 AND 1 -> 1
\end{verbatim}
\item [Remarks:] The result is of integer type.
If the result is used in a logical context,
the value of 0 is regarded as FALSE,
all other, nonzero values are regarded as TRUE.
\item [Example:] Using {\bf AND}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
PRINT 1 AND 3
1
PRINT 128 AND 64
0
\end{verbatim}
\end{tcolorbox}
In most cases {\bf AND} is used in {\bf IF} statements.
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
IF (C >= 0 AND C < 256) THEN PRINT "BYTE VALUE"
\end{verbatim}
\end{tcolorbox}
\end{description}
% ******
% APPEND
% ******
\subsection{APPEND}
\index{APPEND}
\index{BASIC 65 Commands!APPEND}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$0E
\item [Format:]
{\bf APPEND\# lfn, filename [,D drive] [,U unit] }
\item [Usage:]
Opens an existing sequential file of type
SEQ or USR for writing and positions the write pointer
at the end of the file.
{\bf lfn} = {\bf l}ogical {\bf f}ile {\bf n}umber \\
1 <= lfn <= 127: line terminator is CR \\
128 <= lfn <= 255: line terminator is CR LF
\filenamedefinition
\drivedefinition
\unitdefinition
\item [Remarks:]
\screentext{APPEND\#} functions similar to the \screentext{DOPEN\#}
command, except that if the file already
exists, the existing content of the file will be retained, and any
\screentext{PRINT\#} commands made to the
open file will cause the file to grow longer.
\item [Example:] Open file in append mode:
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
APPEND#5,"DATA",U9
APPEND#130,(DD$),U(UN%)
APPEND#3,"USER FILE,U"
APPEND#2,"DATA BASE"
\end{verbatim}
\end{tcolorbox}
\end{description}
% ***
% ASC
% ***
\subsection{ASC}
\index{ASC}
\index{BASIC 65 Functions!ASC}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$C6
\item [Format:] {\bf ASC(string)}
\item [Usage:] Takes the first character of
the string argument and returns its numeric code value.
The name is apparently chosen to be a mnemonic to ASCII,
but the returned value is in fact the so called PETSCII code.
\item [Remarks:]
{\bf ASC} returns a zero for an empty string, which behaviour
is different to BASIC 2, where ASC("") gave an error.
The inverse function to {\bf ASC} is {\bf CHR\$}.
\item [Example:] Using {\bf ASC}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
PRINT ASC("MEGA")
77
PRINT ASC("")
0
\end{verbatim}
\end{tcolorbox}
\end{description}
% ***
% ATN
% ***
\subsection{ATN}
\index{ATN}
\index{BASIC 65 Functions!ATN}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$C1
\item [Format:] {\bf ATN(numeric expression)}
\item [Usage:] Returns the arc tangent of the argument.
The result is in the range ($-\pi/2$ to $\pi/2$)
\item [Remarks:]
A multiplication of the result with $180/\pi$
converts the value to the unit "degrees".
{\bf ATN} is the inverse function to {\bf TAN}.
\item [Example:] Using {\bf ATN}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
PRINT ATN(0.5)
.463647609
PRINT ATN(0.5) * 180 / ~
26.5650512
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% AUTO
% ****
\subsection{AUTO}
\index{AUTO}
\index{BASIC 65 Commands!AUTO}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$DC
\item [Format:]
{\bf AUTO [step]}
\item [Usage:] Enables faster typing of BASIC programs.
After submitting a new program line to the BASIC editor with
the RETURN key, the AUTO function generates a new BASIC line
number for the entry of the next line. The new number is
computed by adding {\bf step} to the current line number.
{\bf step} = line number increment
Typing {\bf AUTO} with no argument switches this function off.
\item [Example:] Using {\bf AUTO}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
AUTO 10 : USE AUTO WITH INCREMENT 10
AUTO : SWITCH AUTO OFF
\end{verbatim}
\end{tcolorbox}
\end{description}
% **********
% BACKGROUND
% **********
\subsection{BACKGROUND}
\index{BACKGROUND}
\index{BASIC 65 Commands!BACKGROUND}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$3B
\item [Format:] {\bf BACKGROUND colour}
\item [Usage:] Sets the background colour
of the screen to the argument, which must be in the
range 1 to 16. (See colour table).
\item [Colours:] {\bf Index and RGB values of colour palette}
\ttfamily
{\setlength{\tabcolsep}{1mm}
\begin{tabular}{*{4}{|R{1.2cm}}|l|}
\hline
index & red & green & blue & colour \\
\hline
1 & 0 & 0 & 0 & black \\
2 & 15 & 15 & 15 & white \\
3 & 15 & 0 & 0 & red \\
4 & 0 & 15 & 15 & cyan \\
5 & 15 & 0 & 15 & magenta\\
6 & 0 & 15 & 0 & green \\
7 & 0 & 0 & 15 & blue \\
8 & 15 & 15 & 0 & yellow\\
9 & 15 & 6 & 0 & orange\\
10 & 10 & 4 & 0 & brown \\
11 & 15 & 7 & 7 & pink \\
12 & 5 & 5 & 5 & dark grey\\
13 & 8 & 8 & 8 & medium grey\\
14 & 9 & 15 & 9 & light green \\
15 & 9 & 9 & 15 & light blue\\
16 & 11 & 11 & 11 & light grey\\
\hline
\end{tabular}
}
\item [Example:] Using {\bf BACKGROUND}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BACKGROUND 4 : REM SELECT BACKGROUND COLOUR CYAN
\end{verbatim}
\end{tcolorbox}
\end{description}
% ******
% BACKUP
% ******
\subsection{BACKUP}
\index{BACKUP}
\index{BASIC 65 Commands!BACKUP}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$F6
\item [Format:] {\bf BACKUP D source TO D target [,U unit]}
\item [Usage:] Used on dual drive
disk units only (e.g. 4040, 8050, 8250).
The backup is done by the disk unit internally.
{\bf source} = drive \# of source disk (0 or 1). \\
{\bf target} = drive \# of target disk (0 or 1).
\item [Remarks:] The target disk is formatted and
a identical copy of the source disk is written. \\
This command cannot be used for unit to unit copies.
\item [Example:] Using {\bf BACKUP}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BACKUP D0 TO D1 : REM COPY DISK DRIVE 0 -> DRIVE 1 UNIT 8
BACKUP D1 TO D0, U9: REM COPY DISK DRIVE 0 -> DRIVE 1 UNIT 9
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% BANK
% ****
\subsection{BANK}
\index{BANK}
\index{BASIC 65 Commands!BANK}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$02
\item [Format:] {\bf BANK bank-number}
\item [Usage:] Selects the memory configuration
for BASIC commands, that use 16-bit addresses.
These are LOAD, SAVE, PEEK, POKE, WAIT and SYS.
See system memory map in \bookvref{cha:memory-map} for details.
\item [Remarks:] A value > 127 selects memory mapped I/O.
The default value for the bank number is 128.
This configuration has RAM from \$0000 to \$1FFF
and BASIC ROM's, KERNAL ROM's and I/O from \$2000 to \$FFFF.
\item [Example:] Using {\bf BANK}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BANK 1 :REM SELECT MEMORY CONFIGURATION 1
\end{verbatim}
\end{tcolorbox}
\end{description}
% *****
% BEGIN
% *****
\subsection{BEGIN}
\index{BEGIN}
\index{BASIC 65 Commands!BEGIN}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$18
\item [Format:] {\bf BEGIN} ... {\bf BEND}
\item [Usage:] The {\bf BEGIN} and {\bf BEND} keywords act like
a pair of brackets around a compound statement
to be executed after a {\bf THEN} or {\bf ELSE} keyword.
This overcomes the single line limitation of the
standard {\bf IF} ... {\bf THEN} ... {\bf ELSE} clause.
\item [Remarks:] Do not jump with {\bf GOTO} or {\bf GOSUB} into a
compound statement. It may lead to unexpected
results.
\item [Example:] Using {\bf BEGIN} and {\bf BEND}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
10 GET A$
20 IF A$>="A" AND A$<="Z" THEN BEGIN
30 PW$=PW$+A$
40 IF LEN(PW$)>7 THEN 90
50 BEND :REM IGNORE ALL EXCEPT (A-Z)
60 IF A$<>CHR$(13) GOTO 10
90 PRINT "PW=";PW$
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% BEND
% ****
\subsection{BEND}
\index{BEND}
\index{BASIC 65 Commands!BEND}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$19
\item [Format:] {\bf BEGIN} ... {\bf BEND}
\item [Usage:] The {\bf BEGIN} and {\bf BEND} keywords act like
a pair of brackets around a compound statement
to be executed after a {\bf THEN} or {\bf ELSE} keyword.
This overcomes the single line limitation of the
standard {\bf IF} ... {\bf THEN} ... {\bf ELSE} clause.
\item [Remarks:] The example below shows a quirk in the implementation
of the compound statement.
If the condition evaluates to {\bf FALSE}, execution
does not resume right after {\bf BEND} as it should,
but at the beginning of next line.
Test this behaviour with the following program:
\item [Example:] Using {\bf BEGIN} and {\bf BEND}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
10 IF Z > 1 THEN BEGIN:A$="ONE"
20 B$="TWO"
30 PRINT A$;" ";B$;:BEND:PRINT " QUIRK"
40 REM EXECUTION RESUMES HERE FOR Z <= 1
\end{verbatim}
\end{tcolorbox}
\end{description}
% *****
% BLOAD
% *****
\subsection{BLOAD}
\index{BLOAD}
\index{BASIC 65 Commands!BLOAD}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$11
\item [Format:] {\bf BLOAD filename [,B bank]
[,P address] [,D drive] [,U unit] }
\item [Usage:]
"Binary LOAD" loads a file of type
PRG into RAM at address P and bank B.
\filenamedefinition
{\bf bank} specifies the RAM bank to be used.
If not specified the current bank, as set with the last
{\bf BANK} statement, will be used.
{\bf address} can be used to overrule the load address,
that is stored in the first two bytes of the PRG file.
\drivedefinition
\unitdefinition
\item [Remarks:]
If the loading process tries to load beyond the address \$FFFF,
an 'OUT OF MEMORY' error occurs.
\item [Example:] Using {\bf BLOAD}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BLOAD "ML DATA", B0, U9
BLOAD "SPRITES"
BLOAD "ML ROUTINES", B1, P32768
BLOAD (FN$), B(BA%), P(PA), U(UN%)
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% BOOT
% ****
\subsection{BOOT}
\index{BOOT}
\index{BASIC 65 Commands!BOOT}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$1B
\item [Format:] {\bf BOOT filename [,B bank]
[,P address] [,D drive] [,U unit] } \\
{\bf BOOT SYS} \\
{\bf BOOT}
\item [Usage:]
{\bf BOOT filename} loads a file of type
PRG into RAM at address P and bank B and starts executing
the code at the load address.
{\bf BOOT SYS} loads the boot sector from sector 0,
track 1 and unit 8 to address \$0400 on bank 0 and
performs a JSR \$0400 afterwards (Jump To Subroutine).
The {\bf BOOT} command with no parameter tries to load
and execute a file named AUTOBOOT.C65 from the default unit 8.
It's short for {\bf RUN "AUTOBOOT.C65"}.
\filenamedefinition
{\bf bank} specifies the RAM bank to be used.
If not specified the current bank, as set with the last
{\bf BANK} statement, will be used.
{\bf address} can be used to overrule the load address,
that is stored in the first two bytes of the PRG file.
\drivedefinition
\unitdefinition
\item [Remarks:]
{\bf BOOT SYS} copies the contents of one physical sector
(two logical sectors) = 512 bytes from disc to RAM,
filling RAM from \$0400 to \$05ff.
\item [Example:] Using {\bf BOOT}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BOOT SYS
BOOT (FN$), B(BA%), P(PA), U(UN%)
BOOT
\end{verbatim}
\end{tcolorbox}
\end{description}
% ******
% BORDER
% ******
\subsection{BORDER}
\index{BORDER}
\index{BASIC 65 Commands!BORDER}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$3C
\item [Format:] {\bf BORDER colour}
\item [Usage:] Sets the border colour
of the screen to the argument, which must be in the
range 1 to 16. (See colour table).
\item [Colours:] {\bf Index and RGB values of colour palette}
\ttfamily
{\setlength{\tabcolsep}{1mm}
\begin{tabular}{*{4}{|R{1.2cm}}|l|}
\hline
index & red & green & blue & colour \\
\hline
1 & 0 & 0 & 0 & black \\
2 & 15 & 15 & 15 & white \\
3 & 15 & 0 & 0 & red \\
4 & 0 & 15 & 15 & cyan \\
5 & 15 & 0 & 15 & magenta\\
6 & 0 & 15 & 0 & green \\
7 & 0 & 0 & 15 & blue \\
8 & 15 & 15 & 0 & yellow\\
9 & 15 & 6 & 0 & orange\\
10 & 10 & 4 & 0 & brown \\
11 & 15 & 7 & 7 & pink \\
12 & 5 & 5 & 5 & dark grey\\
13 & 8 & 8 & 8 & medium grey\\
14 & 9 & 15 & 9 & light green \\
15 & 9 & 9 & 15 & light blue\\
16 & 11 & 11 & 11 & light grey\\
\hline
\end{tabular}
}
\item [Example:] Using {\bf BORDER}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
10 BORDER 5 : REM SELECT BACKGROUND COLOUR MAGENTA
\end{verbatim}
\end{tcolorbox}
\end{description}
% ***
% BOX
% ***
\subsection{BOX}
\index{BOX}
\index{BASIC 65 Commands!BOX}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$E1
\item [Format:] {\bf BOX X0,Y0, X1,Y1, X2,Y2, X3,Y3, SOLID}
\item [Usage:] Draws a quadrangle by connecting the
coordinate pairs 0 -> 1 -> 2 -> 3 -> 0.
The quadrangle is drawn using the current drawing context
set with SCREEN, PALETTE and PEN.
The quadrangle is filled, if the parameter SOLID is 1.
\item [Remarks:] A quadrangle is a geometric figure with four sides
and four angles. A box is a special form of a
quadrangle, with all four angles at 90 degrees.
Rhomboids, kites and parallelograms are special
forms too.
So the name of this command is misleading, because
it can be used to draw all kind of quadrangles,
not only boxes. \\
It is possible to draw bow-tie shapes.
\item [Example:] Using {\bf BOX}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BOX 0,0, 160,0, 160,80, 0,80
\end{verbatim}
\end{tcolorbox}
\begin{tikzpicture}[thick]
\draw (3cm,0cm) -- (6cm,0cm) -- (6cm,1.5cm) -- (3cm,1.5cm) -- (3cm,0cm);
\end{tikzpicture}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BOX 0,0, 160,80, 160,0, 0,80
\end{verbatim}
\end{tcolorbox}
\begin{tikzpicture}[thick]
\draw (3cm,0cm) -- (6cm,1.5cm) -- (6cm,0cm) -- (3cm,1.5cm) -- (3cm,0cm);
\end{tikzpicture}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BOX 0,0, 160,0, 140,80, 20,80
\end{verbatim}
\end{tcolorbox}
\begin{tikzpicture}[thick]
\draw (3cm,0cm) -- (6cm,0cm) -- (5.3cm,1.5cm) -- (3.7cm,1.5cm) -- (3cm,0cm);
\end{tikzpicture}
\end{description}
% *****
% BSAVE
% *****
\subsection{BSAVE}
\index{BSAVE}
\index{BASIC 65 Commands!BSAVE}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$10
\item [Format:] {\bf BSAVE filename ,P start TO P end
[,B bank] [,D drive] [,U unit] }
\item [Usage:]
"Binary SAVE" saves a memory range to
a file of type PRG.
\filenamedefinition
If the first character of the filename is an at-sign '@' it
is interpreted as a "save and replace" operation. It is dangerous
to use this replace option on drives 1541 and 1571, because they
contain the notorious "save and replace bug" in their DOS.
{\bf bank} specifies the RAM bank to be used.
If not specified the current bank, as set with the last
{\bf BANK} statement, will be used.
{\bf start} is the first address, where the saving begins.
It becomes also the load address,
that is stored in the first two bytes of the PRG file.
{\bf end} Is the address, where the saving stops.
{\bf end-1} is the last address to be used for saving.
\drivedefinition
\unitdefinition
\item [Remarks:]
The length of the file is {\bf end - start + 2}.
\item [Example:] Using {\bf BSAVE}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BSAVE "ML DATA", P32768 TO P33792, B0, U9
BSAVE "SPRITES", P1536 TO P2058
BSAVE "ML ROUTINES", B1, P(DEC("9000")) TO P(DEC("A000"))
BSAVE (FN$), B(BA%), P(PA) TO P(PE), U(UN%)
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% BUMP
% ****
\subsection{BUMP}
\index{BUMP}
\index{BASIC 65 Commands!BUMP}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$CE \$03
\item [Format:] {\bf b = BUMP(type)}
\item [Usage:] Used to detect
sprite-sprite (type=1) or sprite-data (type=2) collisions.
the return value {\bf b} is a 8-bit mask with
one bit per sprite. The bit position corresponds with the
sprite number.
Each bit set in the return value indicates, that the
sprite for this position was involved in a collision
since the last call of {\bf BUMP}.
Calling {\bf BUMP} resets the collision mask, so you
get always a summary of collisions encountered since
the last call of {\bf BUMP}.
\item [Remarks:] It's possible to detect multiple collisions,
but you need to evaluate sprite coordinates then
to detect which sprite collided with which one.
\item [Example:] Using {\bf BUMP}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
10 S% = BUMP(1) : REM SPRITE-SPRITE COLLISION
20 IF (S% AND 6) = 6) THEN PRINT "SPRITE 1 & 2 COLLISION"
30 REM ---
40 S% = BUMP(2) : REM SPRITE-DATA COLLISION
50 IF (S% <> 0) THEN PRINT "SOME SPRITE HIT DATA REGION"
\end{verbatim}
\end{tcolorbox}
\ttfamily
{\setlength{\tabcolsep}{1mm}
\begin{tabular}{|R{12mm}|R{12mm}|l|}
\hline
sprite & return & mask \\
\hline
0 & 1 & 0000 0001 \\
1 & 2 & 0000 0010 \\
2 & 4 & 0000 0100 \\
3 & 8 & 0000 1000 \\
4 & 16 & 0001 0000 \\
5 & 32 & 0010 0000 \\
6 & 64 & 0100 0000 \\
7 & 128 & 1000 0000 \\
\hline
\end{tabular}
}
\end{description}
% *******
% BVERIFY
% *******
\subsection{BVERIFY}
\index{BVERIFY}
\index{BASIC 65 Commands!BVERIFY}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$28
\item [Format:] {\bf BVERIFY filename [,P address]
[,B bank] [,D drive] [,U unit] }
\item [Usage:]
"Binary VERIFY" compares a memory range to
a file of type PRG.
\filenamedefinition
{\bf bank} specifies the RAM bank to be used.
If not specified the current bank, as set with the last
{\bf BANK} statement, will be used.
{\bf address} is the address, where the comparison begins.
If the parameter P is omitted, it is the load address,
that is stored in the first two bytes of the PRG file.
\drivedefinition
\unitdefinition
\item [Remarks:]
{\bf BVERIFY} can only test for equality. It gives no information
about the number or position of different valued bytes.
In direct mode the command exits either with the message {\bf OK}
or with {\bf VERIFY ERROR}. In program mode a {\bf VERIFY ERROR}
either stops execution or enters the {\bf TRAP} error handler,
if active.
\item [Example:] Using {\bf BVERIFY}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
BVERIFY "ML DATA", P 32768, B0, U9
BVERIFY "SPRITES", P 1536
BVERIFY "ML ROUTINES", B1, P(DEC("9000"))
BVERIFY (FN$), B(BA%), P(PA), U(UN%)
\end{verbatim}
\end{tcolorbox}
\end{description}
% *******
% CATALOG
% *******
\subsection{CATALOG}
\index{CATALOG}
\index{BASIC 65 Commands!CATALOG}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$0C
\item [Format:] {\bf CATALOG [filepattern] [,R] [,D drive] [,U unit] }
\item [Usage:] Prints a file catalog/directory of the specified disk.
The {\bf R} (Recoverable) parameter includes files in the
directory, which are flagged as deleted but are still
recoverable.
{\bf filepattern} is either a quoted string, for example: {\bf "da*"} or
a string expression in parentheses, e.g. {\bf (DI\$)}
\drivedefinition
\unitdefinition
\item [Remarks:]
The command {\bf CATALOG} is a synonym for {\bf DIRECTORY}
or {\bf DIR} and produces the same listing.
The {\bf filepattern} can be used to filter the listing.
The wildcard characters {\bf *} and {\bf ?} may be used.
Adding a {\bf ,T=} to the pattern string, with {\bf T} specifying
a filetype of {\bf P}, {\bf S}, {\bf U} or {\bf R}
(for {\bf P}RG, {\bf S}EQ, {\bf U}SR, {\bf R}EL) filters the
output to that filetype.
\item [Example:] Using {\bf CATALOG}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
CATALOG
\end{verbatim}
\selectfont{\codefont 0}
\begin{tcolorbox}[colback=white,coltext=black,arc=0mm,boxrule=0mm,
left*=0.5mm,right*=0mm,top=0mm,bottom=0mm,nobeforeafter,
left skip=0.5mm,
width=28mm,height=3mm,valign=center]
\begin{verbatim}
"BLACK SMURF " BS 2A
\end{verbatim}
\end{tcolorbox}
\begin{verbatim}
508 "STORY PHOBOS" SEQ
27 "C8096" PRG
25 "C128" PRG
104 BLOCKS FREE.
\end{verbatim}
\end{tcolorbox}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
CATALOG "*,T=S"
\end{verbatim}
\selectfont{\codefont 0}
\begin{tcolorbox}[colback=white,coltext=black,arc=0mm,boxrule=0mm,
left*=0.5mm,right*=0mm,top=0mm,bottom=0mm,nobeforeafter,
left skip=0.5mm,
width=28mm,height=3mm,valign=center]
\begin{verbatim}
"BLACK SMURF " BS 2A
\end{verbatim}
\end{tcolorbox}
\begin{verbatim}
508 "STORY PHOBOS" SEQ
104 BLOCKS FREE.
\end{verbatim}
\end{tcolorbox}
\end{description}
% ******
% CHANGE
% ******
\subsection{CHANGE}
\index{CHANGE}
\index{BASIC 65 Commands!CHANGE}
\begin{description}[leftmargin=2cm,style=nextline]
\item [Token:] \$FE \$2C
\item [Format:] {\bf CHANGE "find" TO "replace" [,from-to]}
\item [Usage:] Used
in direct mode only. It searches the line range
if specified or the whole BASIC program else.
At each occurrence of the "find string" the line is
listed and the user prompted for an action: \\
'Y' <RETURN> do the change and find next string \\
'N' <RETURN> do {\bf not} change and find next string \\
'*' <RETURN> change this and all following matches \\
<RETURN> exit command, don't change.
\item [Remarks:] Instead of the quote (\screentext{"})
each other character may be used
as delimiter for the findstring and replacestring.
Using the quote as delimiter finds text strings, that are
not tokenised and therefore not part of a keyword. \\
\screentext{CHANGE "LOOP" TO "OOPS"} will not find
the BASIC keyword \screentext{LOOP}, because the
keyword is stored as token and not as text.
However \screentext{CHANGE \&LOOP\& TO \&OOPS\&} will
find and replace it (probably spoiling the program).
\item [Example:] Using {\bf CHANGE}
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
CHANGE "XX$" TO "UU$", 2000-2700
CHANGE &IN& TO &OUT&
\end{verbatim}
\end{tcolorbox}
\end{description}
% ****
% CHAR
% ****
\subsection{CHAR}
\index{CHAR}