/
C64PRG10_TXT.txt
23687 lines (16802 loc) · 933 KB
/
C64PRG10_TXT.txt
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
*********
Welcome to Project 64!
The goal of Project 64 is to preserve Commodore 64 related documents
in electronic text format that might otherwise cease to exist with the
rapid advancement of computer technology and declining interest in 8-
bit computers on the part of the general population. If you would like
to help by converting C64 related hardcopy documents to electronic
texts please contact the manager of Project 64, Cris Berneburg, at
<74171.2136@compuserve.com>.
Extensive efforts were made to preserve the contents of the original
document. However, certain portions, such as diagrams, program
listings, and indexes may have been either altered or sacrificed due
to the limitations of plain vanilla text. Diagrams may have been
eliminated where ASCII-art was not feasible. Program listings may be
missing display codes where substitutions were not possible. Tables
of contents and indexes may have been changed from page number
references to section number references. Please accept our apologies
for these limitations, alterations, and possible omissions.
The author(s) of the original document and members of Project 64 make
no representations about the accuracy or suitability of this material
for any purpose. This etext is provided "as-is". Please refer to the
warantee of the original document, if any, that may included in this
etext. No other warantees, express or implied, are made to you as to
the etext or any medium it may be on. Neither the author(s) nor the
members of Project 64 will assume liability for damages either from
the direct or indirect use of this etext or from the distribution of
or modification to this etext.
*********
The Project 64 etext of the Commodore 64 Programmer's Reference Guide,
first edition. Converted to etext by Ville Muikkula. Some errors in
the original document were corrected in this etext.
C64PRG10.TXT, June 1996, etext #46
*********
~
I would like to thank the following persons for their valuable help:
Jouko Valta for the memory maps on pages 310-334.
Marko Makela for the combined table of memory maps on pages 264-266.
Cris Berneburg for proof reading.
Kimmo Hamalainen for proof reading.
There was a lot of work, but finally, after five weeks of correcting
OCR-errors and formatting the text to readable format, it is ready. I
hope that this massive project shows to the C= community that it is in
a fact possible for one man to convert a 500 page book to ASCII text.
One just have to be dedicated, believe that it can be done and have
the PATIENCE for it... and lots of free time. So, who's going to etext
Inside Commodore DOS?
If you find errors in the text, please report them so that they can
be fixed. There should not be many, though...
There are some pictures missing on pages 132,157,162-163,195,364-365,
377-378,380-381,404,406-407,416-417,421,459,476-477 and 481. Also the
schematics of C-64 are not available. I apologize for the possible
inconvenience this might cause.
Ville Muikkula <vmuikku@yrttis.ratol.fi> or <vmuikku@raahenet.ratol.fi>.
*********
Note: To extract the ascii text basic programs all at once from this
etext use "tok64" by Cris Berneburg <74171.2136@compuserve.com>.
*********
Windows 95 MS-DOS Edit is the ideal program for reading this
etext. Just check that ANSI.SYS is loaded in CONFIG.SYS and issue
the command:
mode con lines=50
Now a whole page fits nicely on the screen and you can use Page Up/Page
Down keys to flip pages. Just be sure that the ~ characters are always
on the last line of the screen.
*********
~
COMMODORE 64
PROGRAMMER'S
REFERENCE GUIDE
Published by
Commodore Business Machines, Inc.
and
Howard W. Sams & Co., Inc.
i
~
FIRST EDITION
FOURTH PRINTING-1983
Copyright (C) 1982 by Commodore Business Machines, Inc.
All rights reserved.
This manual is copyrighted and contains proprietary information. No part
of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photo-
copying, recording, or otherwise, without the prior written permission
of COMMODORE BUSINESS MACHINES, Inc.
ii
~
TABLE OF CONTENTS
INTRODUCTION ....................................................... ix
o What's Included? .............................................. x
o How to Use This Reference Guide ............................... xi
o Commodore 64 Applications Guide ............................... xii
o Commodore Information Network ................................. xvii
1. BASIC PROGRAMMING RULES ......................................... 1
o Introduction .................................................. 2
o Screen Display Codes (BASIC Character Set) .................... 2
The Operating System (OS) ................................... 2
o Programming Numbers and Variables ............................. 4
Integer, Floating-Point and String Constants ................ 4
Integer, Floating-Point and String Variables ................ 7
Integer, Floating-Point and String Arrays ................... 8
o Expressions and Operators ..................................... 9
Arithmetic Expressions ...................................... 10
Arithmetic Operations ....................................... 10
Relational Operators ........................................ 12
Logical Operators ........................................... 13
Hierarchy of Operations ..................................... 15
String Operations ........................................... 16
String Expressions .......................................... 17
o Programming Techniques ........................................ 18
Data Conversions ............................................ 18
Using the INPUT Statement ................................... 18
Using the GET Statement ..................................... 22
How to Crunch BASIC Programs ................................ 24
2. BASIC LANGUAGE VOCABULARY ....................................... 29
o Introduction .................................................. 30
o BASIC Keywords, Abbreviations, and Function Types ............. 31
o Description of BASIC Keywords (Alphabetical) .................. 35
o The Commodore 64 Keyboard and Features ........................ 93
o Screen Editor ................................................. 94
iii
~
3. PROGRAMMING GRAPHICS ON THE
COMMODORE 64 .................................................... 99
o Graphics Overview ............................................. 100
Character Display Modes ..................................... 100
Bit Map Modes ............................................... 100
Sprites ..................................................... 100
o Graphics locations ............................................ 101
Video Bank Selection ........................................ 101
Screen Memory ............................................... 102
Color Memory ................................................ 103
Character Memory ............................................ 103
o Standard Character Mode ....................................... 107
Character Definitions ....................................... 107
o Programmable Characters ....................................... 108
o Multi-Color Mode Graphics ..................................... 115
Multi-Color Mode Bit ........................................ 115
o Extended Background Color Mode ................................ 120
o Bit Mapped Graphics ........................................... 121
Standard High-Resolution Bit Map Mode ....................... 122
How It Works ................................................ 122
o Multi-Color Bit Map Mode ...................................... 127
o Smooth Scrolling .............................................. 128
o Sprites ....................................................... 131
Defining a Sprite ........................................... 131
Sprite Pointers ............................................. 133
Turning Sprites On .......................................... 134
Turning Sprites Off ......................................... 135
Colors ...................................................... 135
Multi-Color Mode ............................................ 135
Setting a Sprite to Multi-Color Mode ........................ 136
Expanded Sprites ............................................ 136
Sprite Positioning .......................................... 137
Sprite Positioning Summary .................................. 143
Sprite Display Priorities ................................... 144
Collision Detects ........................................... 144
o Other Graphics Features ....................................... 150
Screen Blanking ............................................. 150
Raster Register ............................................. 150
Interrupt Status Register ................................... 151
Suggested Screen and Character Color Combinations ........... 152
iv
~
o Programming Sprites-Another Look .............................. 153
Making Sprites in BASIC-A Short Program ..................... 153
Crunching Your Sprite Programs .............................. 156
Positioning Sprites on the Screen ........................... 157
Sprite Priorities ........................................... 161
Drawing a Sprite ............................................ 162
Creating a Sprite ... Step by Step .......................... 163
Moving Your Sprite on the Screen ............................ 165
Vertical Scrolling .......................................... 166
The Dancing Mouse-A Sprite Program Example .................. 166
Easy Spritemaking Chart ..................................... 176
Spritemaking Notes .......................................... 177
4. PROGRAMMING SOUND AND MUSIC
ON YOUR COMMODORE 64 ............................................ 183
o Introduction .................................................. 184
Volume Control .............................................. 186
Frequencies of Sound Waves .................................. 186
o Using Multiple Voices ......................................... 187
Controlling Multiple Voices ................................. 191
o Changing Waveforms ............................................ 192
Understanding Waveforms ..................................... 194
o The Envelope Generator ........................................ 196
o Filtering ..................................................... 199
o Advanced Techniques ........................................... 202
o Synchronization and Ring Modulation ........................... 207
5. BASIC TO MACHINE LANGUAGE ....................................... 209
o What is Machine Language? ..................................... 210
What Does Machine Code Look Like? ........................... 211
Simple Memory Map of the Commodore 64 ....................... 212
The Registers Inside the 6510 Microprocessor ................ 213
o How Do You Write Machine Language Programs? ................... 214
64MON ....................................................... 215
o Hexadecimal Notation .......................................... 215
Your First Machine Language Instruction ..................... 218
Writing Your First Program .................................. 220
o Addressing Modes .............................................. 221
Zero Page ................................................... 221
The Stack ................................................... 222
v
~
o Indexing ...................................................... 223
Indirect Indexed ............................................ 223
Indexed Indirect ............................................ 224
Branches and Testing ........................................ 226
o Subroutines ................................................... 228
o Useful Tips for the Beginner .................................. 229
o Approaching a Large Task ...................................... 230
o MCS6510 Microprocessor Instruction Set-
Alphabetic Sequence ........................................... 232
Instruction Addressing Modes and
Related Execution Times ................................... 254
o Memory Management on the Commodore 64 ......................... 260
o The KERNAL .................................................... 268
o KERNAL Power-Up Activities .................................... 269
How to Use the KERNAL ....................................... 270
User Callable KERNAL Routines ............................... 272
Error Codes ................................................. 306
o Using Machine Language From BASIC ............................. 307
Where to Put Machine Language Routines ...................... 309
How to Enter Machine language ............................... 309
o Commodore 64 Memory Map ....................................... 310
Commodore 64 Input/Output Assignments ....................... 320
6. INPUT/OUTPUT GUIDE .............................................. 335
o Introduction .................................................. 336
o Output to the TV .............................................. 336
o Output to Other Devices ....................................... 337
Output to Printer ........................................... 338
Output to Modem ............................................. 339
Working With Cassette Tape .................................. 340
Data Storage on Floppy Diskettes ............................ 342
o The Game Ports ................................................ 343
Paddles ..................................................... 346
Light Pen ................................................... 348
o RS-232 Interface Description .................................. 348
General Outline .............................................. 348
Opening an RS-232 Channel .................................... 349
Getting Data From an RS-232 Channel .......................... 352
Sending Data to an RS-232 Channel ............................ 353
Closing an RS-232 Data Channel ............................... 354
Sample BASIC Programs ........................................ 356
vi
~
Receiver/Transmitter Buffer Base Location Pointers ........... 357
Zero-Page Memory Locations and Usage
for RS-232 System Interface ................................ 358
Nonzero-Page Memory Locations and Usage
for RS-232 System Interface ................................ 358
o The User Port ................................................. 359
Port Pin Description ........................................ 359
o The Serial Bus ................................................ 362
Serial Bus Pinouts .......................................... 363
o The Expansion Port ............................................ 366
o Z-80 Microprocessor Cartridge ................................. 368
Using Commodore CP/M (R) .................................... 369
Running Commodore CP/M (R) .................................. 369
APPENDICES ......................................................... 373
A. Abbreviations for BASIC Keywords ............................ 374
B. Screen Display Codes ........................................ 376
C. ASCII and CHR$ Codes ........................................ 379
D. Screen and Color Memory Maps ................................ 382
E. Music Note Values ........................................... 384
F. Bibliography ................................................ 388
G. VIC Chip Register Map ....................................... 391
H. Deriving Mathematical Functions ............................. 394
I. Pinouts for Input/Output Devices ............................ 395
J. Converting Standard BASIC Programs to
Commodore 64 BASIC ........................................ 398
K. Error Messages .............................................. 400
L. 6510 Microprocessor Chip Specifications ..................... 402
M. 6526 Complex Interface Adapter (CIA)
Chip Specifications ....................................... 419
N. 6566/6567 (VIC-II) Chip Specifications ...................... 436
0. 6581 Sound Interface Device (SID) Chip Specifications ....... 457
P. Glossary .................................................... 482
INDEX .............................................................. 483
COMMODORE 64 QUICK REFERENCE CARD .................................. 487
SCHEMATIC DIAGRAM OF THE COMMODORE 64 .............................. 491
vii
~~
INTRODUCTION
The COMMODORE 64 PROGRAMMER'S REFERENCE GUIDE has been developed as a
working tool and reference source for those of you who want to maximize
your use of the built-in capabilities of your COMMODORE 64. This manual
contains the information you need for your programs, from the simplest
example all the way to the most complex. The PROGRAMMER'S REFERENCE GUIDE
is designed so that everyone from the beginning BASIC programmer to the
professional experienced in 6502 machine language can get information to
develop his or her own creative programs. At the same time this book
shows you how clever your COMMODORE 64 really is.
This REFERENCE GUIDE is not designed to teach the BASIC programming
language or the 6502 machine language. There is, however, an extensive
glossary of terms and a "semi-tutorial" approach to many of the sections
in the book. If you don't already have a working knowledge of BASIC and
how to use it to program, we suggest that you study the COMMODORE 64
USER'S GUIDE that came with your computer. The USER'S GUIDE gives you an
easy to read introduction to the BASIC programming language. If you still
have difficulty understanding how to use BASIC then turn to the back of
this book (or Appendix N in the USER'S GUIDE) and check out the
Bibliography.
The COMMODORE 64 PROGRAMMER'S REFERENCE GUIDE is just that; a
reference. Like most reference books, your ability to apply the
information creatively really depends on how much knowledge you have
about the subject. In other words if you are a novice programmer you will
not be able to use all the facts and figures in this book until you
expand your current programming knowledge.
ix
~
What you can do with this book is to find a considerable amount of
valuable programming reference information written in easy to read,
plain English with the programmer's jargon explained. On the other hand
the programming professional will find all the information needed to use
the capabilities of the COMMODORE 64 effectively.
WHAT'S INCLUDED?
o Our complete "BASIC dictionary" includes Commodore BASIC language
commands, statements and functions listed in alphabetical order.
We've created a "quick list" which contains all the words and their
abbreviations. This is followed by a section containing a more
detailed definition of each word along with sample BASIC programs
to illustrate how they work.
o If you need an introduction to using machine language with BASIC
programs our layman's overview will get you started.
o A powerful feature of all Commodore computers is called the KERNAL.
It helps insure that the programs you write today can also be used
on your Commodore computer of tomorrow.
o The Input/Output Programming section gives you the opportunity to
use your computer to the limit. It describes how to hook-up and use
everything from lightpens and joysticks to disk drives, printers,
and telecommunication devices called modems.
o You can explore the world of SPRITES, programmable characters, and
high resolution graphics for the most detailed and advanced animated
pictures in the microcomputer industry.
o You can also enter the world of music synthesis and create your own
songs and sound effects with the best built-in synthesizer available
in any personal computer.
o If you're an experienced programmer, the soft load language section
gives you information about the COMMODORE 64's ability to run CP/M*
and high level languages. This is in addition to BASIC.
Think of your COMMODORE 64 PROGRAMMER'S REFERENCE GUIDE as a useful
tool to help you and you will enjoy the -hours of programming ahead
of you.
-----------
* CP/M is a registered trademark of Digital Research, Inc.
x INTRODUCTION
~
HOW TO USE THIS REFERENCE GUIDE
Throughout this manual certain conventional notations are used to de-
scribe the syntax (programming sentence structure) of BASIC commands or
statements and to show both the required and optional parts of each BASIC
keyword. The rules to use for interpreting statement syntax are as
follows:
1. BASIC keywords are shown in capital letters. They must appear where
shown in the statement, entered and spelled exactly as shown.
2. Items shown within quotation marks (" ") indicate variable data
which you must put in. Both the quotation marks and the data inside
the quotes must appear where shown in each statement.
3. Items inside the square brackets ([ ]) indicate an optional state-
ment parameter. A parameter is a limitation or additional qualifier
for your statements. If you use an optional parameter you must
supply the data for that optional parameter. In addition, ellipses
(...) show that an optional item can be repeated as many times as
a programming line allows.
4. If an item in the square brackets ([ ]) is UNDERLINED, that means
that you MUST use those certain characters in the optional para-
meters, and they also have to be spelled exactly as shown.
5. Items inside angle brackets (< >) indicate variable data which you
provide. While the slash (/) indicates that you must make a choice
between two mutually exclusive options.
EXAMPLE OF SYNTAX FORMAT:
OPEN <file-num>,<device>[,<address>],["<drive>:<filename>][,<mode>]"
EXAMPLES OF ACTUAL STATEMENTS:
10 OPEN 2,8,6,"0:STOCK FOLIO,S,W"
20 OPEN 1,1,2,"CHECKBOOK"
30 OPEN 3,4
When you actually apply the syntax conventions in a practical situa-
tion, the sequence of parameters in your statements might not be exactly
the same as the sequence shown in syntax examples. The examples are not
meant to show every possible sequence. They are intended to present all
required and optional parameters.
INTRODUCTION xi
~
Programming examples in this book are shown with blanks separating
words and operators for the sake of readability. Normally though, BASIC
doesn't require blanks between words unless leaving them out would give
you an ambiguous or incorrect syntax.
Shown below are some examples and descriptions of the symbols used for
various statement parameters in the following chapters. The list is not
meant to show every possibility, but to give you a better understanding
as to how syntax examples are presented.
SYMBOL EXAMPLE DESCRIPTION
<file-num> 50 A logical file number
<device> 4 A hardware device number
<address> 15 A serial bus secondary
device address number
<drive> 0 A physical disk drive number
<file-name> "TEST.DATA" The name of a data or program file
<constant> "ABCDEFG" Literal data supplied by
the programmer
<variable> X145 Any BASIC data variable name or
constant
<string> AB$ Use of a string type variable required
<number> 12345 Use of a numeric type variable
required
<line-number> 1000 An actual program line number
<numeric> 1.5E4 An integer or floating-point variable
COMMODORE 64 APPLICATIONS GUIDE
When you first thought about buying a computer you probably asked
yourself, "Now that I can afford to buy a computer, what can I do with
it once I get one?"
The great thing about your COMMODORE 64 is that you can make it do what
YOU want it to do! You can make it calculate and keep track of home and
business budget needs. You can use it for word processing. You can make
it play arcade-style action games. You can make it sing. You can even
create your own animated cartoons, and more. The best part of owning a
COMMODORE 64 is that even if it did only one of the things listed below
it would be well worth the price you paid for it. But the 64 is a
complete computer and it does do EVERYTHING listed and then some!
xii INTRODUCTION
~
By the way, in addition to everything here you can pick up a lot of
other creative and practical ideas by signing up with a local Commodore
Users' Club, subscribing to the COMMODORE and POWER/PLAY magazines, and
joining the COMMODORE INFORMATION NETWORK on CompuServe(TM)
APPLICATION COMMENTS/REQUIREMENTS
ACTION PACKED You can get real Bally Midway arcade games GAMES
like Omega Race, Gorf and Wizard of War, as well
as "play and learn" games like Math Teacher 1,
Home Babysitter and Commodore Artist.
ADVERTISING & Hook your COMMODORE 64 to a TV, put it in
MERCHANDISING a store window with a flashing, animated, and
musical message and you've got a great point of
purchase store display.
ANIMATION Commodore's Sprite Graphics allow you to create
real cartoons with 8 different levels so that
shapes can move in front of or behind each
other.
BABYSITTING The COMMODORE 64 HOME BABYSITTER cartridge can
keep your youngest child occupied for hours and
teach alphabet/ keyboard recognition at the same
time. It also teaches special learning concepts
and relationships.
BASIC PROGRAMMING Your COMMODORE 64 USER'S GUIDE and the TEACH
YOURSELF PROGRAMMING series of books and tapes
offer an excellent starting point.
BUSINESS The COMMODORE 64 offers the "Easy" series
SPREADSHEET of business aids including the most powerful
word processor and largest spreadsheet
available for any personal computer.
COMMUNICATION Enter the fascinating world of computer "net-
working." If you hook a VICMODEM to your
COMMODORE 64 you can communicate with other
computer owners all around the world.
INTRODUCTION xiii
~
Not only that, if you join the COMMODORE
INFORMATION NETWORK on CompuServe(TM) you can
get the latest news and updates on all Commodore
products, financial information, shop at home
services, you can even play games with the
friends you make through the information systems
you join.
COMPOSING SONGS The COMMODORE 64 is equipped with the most
sophisticated built-in music synthesizer
available on any computer. It has three com-
pletely programmable voices, nine full music
octaves, and four controllable waveforms.
Look for Commodore Music Cartridges and
Commodore Music books to help you create or
reproduce all kinds of music and sound effects.
CP/M* Commodore offers a CP/M* add-on and access to
software through an easy-to-load cartridge.
DEXTERITY TRAINING Hand/Eye coordination and manual dexterity
are aided by several Commodore games...
including "Jupiter lander" and night driving
simulation.
EDUCATION While working with a computer is an education in
itself, The COMMODORE Educational Resource Book
contains general information on the educational
uses of computers. We also have a variety of
learning cartridges designed to teach everything
from music to math and art to astronomy.
FOREIGN LANGUAGE The COMMODORE 64 programmable character set
lets you replace the standard character set
with user defined foreign language characters.
GRAPHICS AND ART In addition to the Sprite Graphics mentioned
above, the COMMODORE 64 offers high-resolution,
multi-color graphics plotting, programmable
-----------
* CP/M is a Registered trademark of Digital Research, Inc.
xiv INTRODUCTION
~
characters, and combinations of all the
different graphics and character display modes.
INSTRUMENT Your COMMODORE 64 has a serial port, RS-232 port
CONTROL and a user port for use with a variety of special
industrial applications. An IEEE/488 cartridge is
also available as an optional extra.
JOURNALS AND The COMMODORE 64 will soon offer an exceptional
CREATIVE WRITING wordprocessing system that matches or exceeds
the qualities and flexibilities of most "high-
priced" wordprocessors available. Of course you
can save the information on either a 1541 Disk
Drive or a Datassette TM recorder and have it
printed out using a VIC-PRINTER or PLOTTER.
LIGHTPEN CONTROL Applications requiring the use of a lightpen
can be performed by any lightpen that will fit
the COMMODORE 64 game port connector.
MACHINE CODE Your COMMODORE 64 PROGRAMMER'S REFERENCE GUIDE
PROGRAMMING includes a machine language section, as well as
a BASIC to machine code interface section.
There's even a bibliography available for more
in-depth study.
PAYROLL & FORMS The COMMODORE 64 can be programmed to handle
PRINTOUT a variety of entry-type business applications.
Upper/lower case letters combined with C64
"business form" graphics make it easy for you
to design forms which can then be printed on
your printer.
PRINTING The COMMODORE 64 interfaces with a variety of
dot matrix and letter quality printers as well
as plotters.
RECIPES You can store your favorite recipes on your
COMMODORE 64 and its disk or cassette storage
unit, and end the need for messy recipe cards
that often get lost when you need them most.
INTRODUCTION xv
~
SIMULATIONS Computer simulations let you conduct dangerous
or expensive experiments at minimum risk and
cost.
SPORTS DATA The Source (TM) and CompuServe (TM) both offer
sports information which you can get using
your COMMODORE 64 and a VICMODEM.
STOCK QUOTES With a VICMODEM and a subscription to any of the
appropriate network services, your COMMODORE 64
becomes your own private stock ticker.
These are just a few of the many applications for you and your
COMMODORE 64. As you can see, for work or play, at home, in school
or the office, your COMMODORE 64 gives you a practical solution for
just about any need.
Commodore wants you to know that our support for users only STARTS
with your purchase of a Commodore computer. That's why we've created
two publications with Commodore information from around the world, and
a "two-way" computer information network with valuable input for users
in the U.S. and Canada from coast to coast.
In addition, we wholeheartedly encourage and support the growth of
Commodore Users' Clubs around the world. They are an excellent source
of information for every Commodore computer owner from the beginner
to the most advanced. The magazines and network, which are more fully
described below, have the most up-to-date information about how to get
involved with the Users' Club in your area.
Finally, your local Commodore dealer is a useful source of Commodore
support and information.
POWER/PLAY
The Home Computer Magazine
When it comes to entertainment, learning at home and practical home
applications, POWER/PLAY is THE prime source of information for Com-
modore home users. Find out where your nearest user clubs are and
what they're doing, learn about software, games, programming techniques,
telecommunications, and new products. POWER/PLAY is your personal
connection to other Commodore users, outside software and hardware
developers, and to Commodore itself. Published quarterly. Only $10.00
for a year of home computing excitement.
xvi INTRODUCTION
~
COMMODORE
The Microcomputer Magazine
Widely read by educators, businessmen and students, as well as home
computerists, COMMODORE Magazine is our main vehicle for sharing
exclusive information on the more technical use of Commodore systems.
Regular departments cover business, science and education, programming
tips, "excerpts from a technical notebook," and many other features of
interest to anyone who uses or is thinking about purchasing Commodore
equipment for business, scientific or educational applications.
COMMODORE is the ideal complement to POWER/PLAY. Published bimonthly.
Subscription price: $15.00 per year.
AND FOR EVEN MORE INFORMATION...
...DIAL UP OUR PAPERLESS USER MAGAZINE
COMMODORE INFORMATION NETWORK
The magazine of the future is here. To supplement and enhance your
subscription to POWER/PLAY and COMMODORE magazines, the COMMODORE
INFORMATION NETWORK - our "paperless magazine" - is available now over
the telephone using your Commodore computer and modem.
Join our computer club, get help with a computing problem, "talk" to
other Commodore friends, or get up-to-the-minute information on new
products, software and educational resources. Soon you will even be
able to save yourself the trouble of typing in the program listings you
find in POWER/PLAY or COMMODORE by downloading direct from the
Information Network (a new user service planned for early 1983). The
best part is that most of the answers are there before you even ask the
questions. (How's that for service?)
To call our electronic magazine you need only a modem and a sub-
scription to CompuServe TM, one of the nation's largest telecommunica-
tions networks. (To make it easy for you Commodore includes a FREE year's
subscription to CompuServe TM in each VICMODEM package.) Just dial your
local number for the CompuServe (TM) data bank and connect your phone to
the modem. When the CompuServe (TM) video text appears on your screen
type G CBM on your computer keyboard. When the COMMODORE INFORMATION
NETWORK'S table of contents, or "menu," appears on your screen choose
from one of our sixteen departments, make yourself comfortable, and enjoy
the paperless magazine other magazines are writing about.
INTRODUCTION xvii
~
For more information, visit your Commodore dealer or contact Com-
puserve(TM) customer service at 800-848-8990 (in Ohio, 614-457-8600).
COMMODORE INFORMATION NETWORK
+-----------------------------------+-----------------------------------+
| Main Menu Description | Commodore Dealers |
| Direct Access Codes | Educational Resources |
| Special Commands | User Groups |
| User Questions | Descriptions |
| Public Bulletin Board | Questions and Answers |
| Magazines and Newsletters | Software Tips |
| Products Announced | Technical Tips |
| Commodore News Direct | Directory Descriptions |
+-----------------------------------+-----------------------------------+
xviii INTRODUCTION
~
CHAPTER 1
BASIC
PROGRAMMING
RULES
o Introduction
o Screen Display Codes (BASIC
Character Set)
o Programming Numbers and
variables
o Expressions and Operators
o Programming Techniques
1
~
INTRODUCTION
This chapter talks about how BASIC stores and manipulates data. The
topics include:
1) A brief mention of the operating system components and functions
as well as the character set used in the Commodore 64.
2) The formation of constants and variables. What types of variables
there are. And how constants and variables are stored in memory.
3) The rules for arithmetic calculations, relationship tests, string
handling, and logical operations. Also included are the rules for
forming expressions, and the data conversions necessary when you're
using BASIC with mixed data types.
SCREEN DISPLAY CODES (BASIC CHARACTER SET)
THE OPERATING SYSTEM (OS)
The Operating System is contained in the Read Only Memory (ROM) chips
and is a combination of three separate, but interrelated, program
modules.
1) The BASIC Interpreter
2) The KERNAL
3) The Screen Editor
1) The BASIC Interpreter is responsible for analysing BASIC statement
syntax and for performing the required calculations and/or data
manipulation. The BASIC Interpreter has a vocabulary of 65
"keywords" which have special meanings. The upper and lower case
alphabet and the digits 0-9 are used to make both keywords and
variable names. Certain punctuation characters and special symbols
also have meanings for the Interpreter. Table 1-1 lists the special
characters and their uses.
2) The KERNAL handles most of the interrupt level processing in the
system (for details on interrupt level processing, see Chapter 5).
The KERNAL also does the actual input and output of data.
3) The Screen Editor controls the output to the video screen (tele-
vision set) and the editing of BASIC program text. In addition, the
Screen Editor intercepts keyboard input so that it can decide
whether the characters put in should be acted upon immediately, or
passed on to the BASIC Interpreter.
2 BASIC PROGRAMMING RULES
~
Table 1 - 1. CBM BASIC Character Set
+-------------+---------------------------------------------------------+
| CHARACTER | NAME and DESCRIPTION |
+-------------+---------------------------------------------------------+
| | BLANK - separates keywords and variable names |
| ; | SEMI-COLON - used in variable lists to format output |
| = | EQUAL SIGN - value assignment and relationship testing |
| + | PLUS SIGN - arithmetic addition or string concatenation |
| | (concatenation: linking together in a chain) |
| - | MINUS SIGN - arithmetic subtraction, unary minus |
| * | ASTERISK - arithmetic multiplication |
| / | SLASH - arithmetic division |