Commodore 128 Book 2 Adva
Total Page:16
File Type:pdf, Size:1020Kb
COMMODORE C12S BOOK 2 ADVANCED PROGRAMMING COMMODORE el28 ADVANCED PROGRAMMING by Ian Sinclair Glentop Publishers Ltd MARCH 1986 All programs in this book have been written expressly to illustrate specific teaching points. They are not warranted as being suitable for any particular application. Every care has been taken in the writing and presentation of this book but no responsibility is assumed by the author or publishers for any errors or omissions contained herein. COPYRIGHT © Glentop Publishers Ltd 1986 World rights reserved No part of this pUblication may be copied, transmitted or stored in a retrieval system or reproduced in any way including but not limited to photography, photocopy, magnetic or other recording means, without prior permission from the publishers, with the exception of material entered and executed on a computer system for the reader's own use ISBN 1 85181 034 X Published by: Glentop Publishers Ltd Standfast House Bath Place High Street Barnet Herts ENS SXE Tel: 01-441-4130 Printed in Great Britain by The Eastern Press Ltd., London and Reading Contents PREFACE CHAPTER 1 Reminders roundup • Storage space • Machine code • Principles of programming. Other languages CHAPTER 2 Why use disks? • What is a disk system? • Tracks, sectors and density. Formatting disks. Storage space. The disk filing system • Loading and saving • More disk commands • Clearing, retitling and erasing. Backing up • Copying a named flle • Deleting flles • Wildcards and wiping. Protecting disks and programs. Renaming flles CHAPTER 3 Text display. Screen clear and print location. Print fielding. Formatting numbers • Standard form • Money amounts • Titles and centering. Windows. Hard copy CHAPTER 4 Working with numbers. Operators. Expressions. Translat ing formulae. Functions. Precision of numbers. Rounding • Number roundup CHAPTERS Complex data • Number arrays. Lists. Number sorting. String arrays. Sorting string lists. Matrix operations CHAPTER 6 Menus, subroutines and program design. Sectional program ming • A visual menu. Drive it yourself. Put it on paper. Foundation stones. Subroutine routine. Entry subroutine. The edit subroutine CHAPTER 7 BASIC filing techniques. What is a flle? • Knowing the names • Disk filing • Serial flles • Opening the flle • Printing to the flle • Getting your own back. Updating the file. Relative flles • Relative flle facts • Relative rules • Reading back. More complications CHAPTERS A database program - FILIT • First principles. The program in detail • The creation subroutine • Writing to the flle • Reading the flle • The entry subroutine. Reading v CHAPTER 9 Graphics and sound. Data display. Graphs. Elaborations. Function graphs. Bar charts • Pie diagrams. Sounding off CHAPTER 10 Printers. Printer types • Interfaces. The Centronics interface • The EPSON RX80 and LX80. TheJUKI 6100 daisywheel APPENDIX A Tuning a TV receiver APPENDIXB Standard form APPENDIXC Boolean actions APPENDIXD Suppliers INDEX vi Introduction The Commodore 128 is a machine of astonishing versatility, which can be used in a number of modes. This book is concerned with more advanced aspects of using and programming the machine in its 128 mode. As such, this book is a follow on to Sean Gray's book Starting BASIC for this machine. The main theme of this second level book will be business use, and in particular how to design and write programs of the database type for your own use. Many of the more advanced features of Commodore BASIC in the Commodore 128 are very well suited for use in database programs, and these features are fully explained and illustrated here. Since this is intended to be a second-level book, I shall assume that you already have a working knowledge of simple BASIC, as you might have obtained by programming a Commodore 64, or from the use of the Commodore 128 with the Levell book. Where a point might have been forgotten, I shall remind you of it, because I can't assume that every reader of this book will have had the same experience and background. The listings in this book have been printed out using 40 characters per line, so that if you are using the 40-character screen display, the listing should correspond to the screen display. Long listings have been numbered with line increments of 10 so that you can enter them using the AUTO command. I must thank many people at Commodore, particularly Chris Kaday, for arranging the loan of a Commodore 128 machine around which this book was written. I am also grateful, as always, to Mick Bignall whose excellent combination of hardware and software, Printlink 128, made it possible to print out the listings on my EPSON printer. Finally, my most fervent thanks must go to Dr. P. Holmes of Glentop Publishers, who commissioned this book, and to his team who made my printouts and disks into a real book. Ian Sinclair February 1986 vii Chapter 1 Reminders roundup The Commodore 128 provides for three sets of video output signals. These are the signals which are used by a monitor or a TV receiver to display characters, number, letter or graphical, on a screen so that you can see what the computer is doing. Throughout this book, the programming examples will be usable on any kind of display, but I shall assume that you are using either: 1. A TV receiver connected to the RF socket output of the Commodore 128 and correctly tuned (see Appendix A). or 2. A monitor with composite video input. Several manufacturers can now supply combined TV/Monitor units which are ideal for use with the Commodore 128 in its 128 mode. The 40/80 column switch should be in its 4O-column position. The 80-column position and the use of the RGB type of monitor should be reserved for the CP/M mode of the C128. The use of CP/M with the C128, and writing in CP/M is beyond the scope of this book. The types of video signals are not explained in the Commodore 128 manual, and it's important to know the differences, particularly if you want to use monitors that are not manufactured by Commodore. Video signals are electrical signals which will produce a picture on a cathode ray tube. The signals that the machine produces consist of a set of four: Red, Green, Blue and sync. The signals that are labelled with colour names control the colours on the screen and, when each of these signals can be fed separately to a monitor, the picture quality is as good as you can ever get with a colour monitor. The sync signal is used to ensure that the movement of the spot on the screen of the cathode ray tube, the spot that produces the picture, keeps in step with the colour signals. A monitor which has RGB inputs may not provide at all for any other type of signal input. For many purposes, it's preferable to combine the signals into one, called a composite video signal. This does not give such sharp, clear pictures, but it's certainly good enough for 4O-column work. Composite video signals are also used by video recorders, so that a monitor which uses these siJP.1als can also be used to obtain a better picture from your video recorder. Looking at it the other way round, if you have a monitor for your video recorder, it will accept the composite video signals from your Commodore 1281. The third method of connecting video signals is by modulation. This starts with a composite video signal, and uses a miniature TV transmitter circuit to convert the signal 1-1 into the form that a TV receiver can use. This gives the poorest results of all, because TV receivers are not intended to give the quality of picture that you can get from a monitor. The advantage, however, is that practically everyone has a TV receiver. In the course of writing this book, I used both a TV receiver and a monitor, and all the programs are usable on either. One of the advantages of working in 128 mode with database programs is that it doesn't really matter too much whether your display is colour or monochrome, since it's being used mainly for words and numbers. In any case, a lot of business programs use the screen only for reminders, and the main output of the computer is to a paper printer, producing what is called 'hard copy'. The use of printers of various types with the Commodore 128 is dealt with in Chapter 10. Storage space When you write a program for a computer, that program has to be stored in the memory of the computer, and it will usually need more memory when it runs. Whatever may appear on the screen when you switch your Commodore 128 on (122 365 bytes free), the amount of memory that can be used for a BASIC program is, at most, 58 109 bytes. You can check this for yourself by using P R I NT F R E ( 0 ). This corresponds to around 56K of free memory. Remember, however, that the C64 allowed only about 28K free for BASIC, and you'll appreciate that the Commodore 128 does allow much more space. This is why we can make use of the machine for so many serious purposes, unlike machines of the past. The figure of 122 365 bytes is obtained by adding in the number of bytes that are free for storing BASIC variables. This is obtained from P R I NT F R E ( 1 ) , and gives 64 256 when no program is in memory. By separating these two parts of memory, it's possible to run much longer programs than can be used on other machines which supposedly have 128K of memory.