Commodore 64 Omnibus.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
THE COMMODORE 64 OMNIBUS PETER LUPTON & FRAZER ROBINSON CENTURY COMMUNICATIONS LONDON Copyright c Peter Lupton and Frazer Robinson 1984 All rights reserved First published in Great Britain in 1985 by Century Communications Ltd, 12 - 13 Greek Street, London WI V 5LE ISBN 0 7126 06769 Printed in Great Britain in 1984 by Billing & Sons Limited, Worcester. Typeset by Spokesman, Bracknell NOTE: The programs in this book have been typeset directly from the Commodore 64. CONTENTS Acknowledgements Introduction PART 1 INTRODUCING COM MODORE 64 PROGRAMMING 1 Computers and Programs 1 2 Setting up your 64 3 3 First Steps 8 4 Programming 18 5 Program Control 34 6 Data and Programs 52 7 Pieces ofStrlngs 59 8 Functions 73 9 Logical Thinking 82 10 Memory Management 89 11 Sound and Music - Part 1 93 12 Character Graphics 119 13 High Resolution Graphics 146 14 Sprites 158 15 Permanent Storage 184 16 Advanced Techniques 204 PART 2 ADVANCED COM MODORE 64 PROGRAMMING 17 BASIC and how it works 211 18 Machine code on the 64 234 19 Bit-Mapped Graphics - Part 1 262 20 Bit-Mapped Graphics - Part 2 280 21 Display Interrupts 301 22 Programs and People 315 23 Sound and Music - Part 2 331 24 The 1541 Disk Drive 348 25 Advanced Disk Operations 364 26 The MPS801 Printer 403 APPENDICES 1 Abbreviations 419 2 BASIC Commands 420 3 BASIC Tokens and Abbreviations 431 4 Summary of DOS Commands 434 5 BASIC Error Messages 435 6 DOS Error Messages 441 7 Speeding Up Programs 446 8 Colour Codes 448 9 Musical Notation 449 10 N umbering Systems 453 11 Kernal Routines 458 12 The 6510 Instruction Set 464 13 SID Registers 472 14 VIC ITRegi sters 474 15 Screen Memory Maps 476 16 Character Codes 478 17 System Memory Map 483 18 Graphics Loader Programs 484 Index 497 ACKNOWLEDGEMENTS It is customary at this point to mention all those people without whose help this book would not have been possible. We would like to acknowledge the support and enthusiasm of Peter Rhodes without whom none of our books would have been possible. We haven't been able to say so until now - Thanks Peter! INTRODUCTION This book is an omnibus edi tion of our two books, The Commodore 64 Handbook The Advanced Commodore 64 Handbook We have taken the opportunity to correct one or two errors which crept into the first editions, and to clarify some obscurities noticed by our readers. The combined volumes form a complete guide to the Commodore 64. The firstsection of this book provides a complete introduction to BASIC and the fe atures of the 64, while the second introduces machine code (providing a set of routines to speed up graphics) and describes the use of disk drives and printers. With this book at your side you will be fully armed for the great adventure of64 programming! Peter Lupton and Frazer Robinson 1984 THE COMMODORE 64 OMNIBUS PART 1 INTRODUCING COMMODORE 64 PROGRAMMI NG CHAPTER 1 COMPUTERS AND PROGRAMS Despite everything you may have heard about computers being hyperintelligent machines which are on the point of taking over the world, a computer is not really intelligent at all. A computer is at heart little more than a high-speed adding machine, similar to an electronic calculator, but with more sophisticated display and memory facilities. The feature that gives computers their immense flexibility and potential is this: they can store lists of instructions which they can read through and obey at very high speed. These lists of instructions are called programs, and most of this book is concerned with how these programs are written. The computer instructions which form programs must fo llow certain rules, or the computer will not be able to understand them. The rules for wri ting programs resemble the rules of a spoken language, and so the set of instructions is often said to form a programming language. There are many different computer programming languages; the one that the Commodore 64 understands (in common with most other personal computers) is called BASIC. (The name BASIC is an acronym for Beginners' All-purpose Symbolic Instruction Code.) A programming language is much simpler than a human language because computers, for all their power, are not as good at understanding languages as people are. The BASIC language used by the 64 2 The Commodore 64 Omnibus - Pa rt 1 has less than 80 words. The rules fo r combining the words - the (grammar' of the language - are much more strict than for a language like English, again because it is difficultto make computers that can use languages in the relaxed sort of way in which we speak English. These may seem like limitations, but in fact as you will discover BASIC is still a powerful language, and it is possible to write programs to perform very complex tasks. Finally, remember this. Your computer will not do anything unless you tell it to, so whatever happens, you're the boss. The 64 won't take over the world unless you make it! CHAPTER 2 SETTING UP YOUR 64 Before you can use your Commodore 64 you must connect it to a power supply and to a television. To t I I I + " \ +\ I I I \ \ Cartridge Tuning TV Audio & Serial Cassette User Socket Screw Lead Monitor Interface Interface Port The Commodore 64 Connectors - Rear View �,.� , rL/ I , Joystick On/Off Power Sockets Switch Socket The Commodore 64 Connectors - Side View load and save programs you will also need to connect a cassette unit to the 64. Before connecting anything, make sure you know what should plug in where. The diagrams above show all the connector sockets of the 64. 4 Th e Commodore 64 Omnibus - Part 1 There are several sockets through which the 64 passes and receives information, and one through which it gets the electrical power it needs to operate. The sockets are not all labelled, so be sure �o refer to the diagram before plugging anything In. POWER The 64 needs a low voltage DC supply, and this is obtained from the power supply unit supplied with your computer. Plug this power supply into the mains, and plug the output lead into the computer. The socket for the power supply is at the right hand side of the machine. Do not switch on yet! DISPLAY The Commodore 64 uses a standard domestic TV to communicate with you, and for this almost any TV will do. To get the best results, use a modern, good quality colour TV. If you use a black and white set, the colour displays produced by the computer will appear as shades of grey. To connect the 64 to the TV, plug the supplied aerial lead into the aerial socket of the TV, and plug the other end into the socket at the back of the computer (check the diagram). The lead has a different type of plug at each end, so take care that you don't try to force in the wrong one. CASSETTE RECORDER The Commodore 64, like most other small computers, uses cassette tapes to save programs or information, so that you don't have to type them in every time you need them. You cannot use an ordinary cassette recorder with the 64: you must use the special Commodore Setting up your 64 5 cassette unit, which is available at extra cost. The cassette unit plugs into a socket at the rear of the computer. No separate power supply is needed for the cassette unit as this is provided by the computer. DISK DRIVE Programs can also be stored on floppy disks. A floppy disk drive is faster than a cassette unit and is more flexible in use. (It is also much more expensive). The disk drive connects to the round serial interface socket at the rear of the computer. The disk unit requires its own power supply and so must also be plugged into the mains. PRINTER If you have a printer, its lead plugs into the serial interface socket at the rear of the computer. If you are also using a disk drive you should plug the printer lead into the spare socket at the rear of the disk drive. The printer also has a separate mains lead. SWITCHING ON When you have connected everything together, you are ready to switch on. The equipment must be switched on in the right order, or there is a risk of damaging the computer. First switch on the TV. Second, switch on the disk drive and then the printer. (Remember that you should never switch a disk unit on or off withdisks inside it.) Last, switch on the computer itself. 6 Th e Commodore 64 Omnibus - Part 1 Switching offshould be carried out in the reverse order: first the computer, then the disk drive and printer, and last of all the TV. TUNING To get a display to appear on the TV screen, tune to channel 36, or, on a pushbutton set, use a spare channel and keep tuning until you see this appear on the screen: **** COMMODORE 64 BASIC V2 **** 64K RAM SYSTEM 38911 BASIC BYTES FREE READY. If you are unable to tune the television, perform the fo llowing checks: 1 Check that the aerial lead is connected. 2 Make sure the computer is connected to the mains and switched on. The red power indicator should be on. 3 Try tuning the TV again, and - if possible - try a different TV. Setting up your 64 7 With a little time and careful tuning, it is possible to get a clear and stable display on nearly all types of TV.