ELECTRON
BASIC PROGRAMMING ON THE ACORN ELECTRON,
Neil Cryer and Andrew Cryer
(book and cassette)
BBC MICROCOMPUTER
BASIC PROGRAMMING ON THE BBC MICROCOMPUTER,
Neil Cryer and Pat Cryer
GRAPHICS ON THE BBC MICROCOMPUTER,
Neil Cryer, Pat Cryer and Andrew Cryer
(book and cassette)
BBC MICROCOMPUTER FOR BEGINNERS,
Seamus Dunn and Valerie Morgan
100 PROGRAMS FOR THE BBC MICROCOMPUTER,
John Gordon
(book and cassette)
THE BBC MICROCOMPUTER DISK COMPANION,
Tony Latham
100
PROGRAMS
FOR THE
ACORN ELECTRON
John Gordon
MEDC, Paisley College, Scotland
Prentice/Hall International
Englewood Cliffs, NJ London New Delhi Rio de Janeiro
Singapore Sydney Tokyo Toronto Wellington
British Library Cataloguing in Publication Data
Gordon, John
100 programs for the Acorn Electron
1. Electron (Computer) - Programming
I. Title
001 64'25 QA76.8.A
ISBN 0-13-634858-0
Electron and Acorn are trademarks of Acorn Computers Ltd
© 1984 by JOHN GORDON
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmited in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior permission of the author.
For permission within the United States contact Prentice-Hall Inc., Englewood Cliffs, NJ 07632.
ISBN 0-13-634858 0
ISBN 0-13-634866 1 {CASSETTE}
Prentice-Hall International, Inc., London
Prentice-Hall of Australia Pty Ltd, Sydney
Prentice-Hall Canada, Inc., Toronto
Prentice-Hall of India, Private Ltd, New Delhi
Prentice-Hall of Japan, Inc., Tokyo
Prentice-Hall of Southeast Asia Pte Ltd, Singapore
Prentice-Hall, Inc., Englewood Cliffs, New Jersey
Prentice-Hall do Brasil Ltda, Rio de Janeiro
Whitehall Books Ltd, Wellington, New Zealand
10 9 8 7 6 5 4 3 2
Printed in Great Britain by A. Wheaton & Co., Ltd., Exeter
To Teresa and Jayne for putting up with me.
SECTION 1 | |||
P1 | Nitemare | 6 | |
P2 | Musak | 8 | |
P3 | Tunes | 10 | |
P4 | Pattern | 12 | |
P5 | Graph Plotting | 14 | |
P6 | Bouncing Ball 1 | 17 | |
P7 | Bouncing Ball 2 | 18 | |
P8 | Jimmy | 19 | |
P9 | Clock | 21 | |
SECTION 2 | |||
P10 | Wheel of Fortune | 25 | |
P11 | Mastermind | 26 | |
P12 | Guess the Number | 28 | |
P13 | Reaction Test | 30 | |
P14 | Gobble | 31 | |
P15 | Tennis | 33 | |
P16 | Bombs | 35 | |
P17 | Bat'n'Moths | 38 | |
P18 | Monster Island | 41 | |
P19 | Battleships | 44 | |
SECTION 3 | |||
P20 | Loan Repayment Period | 48 | |
P21 | Depreciation | 50 | |
P22 | Four-weekly Moving Average | 52 | |
P23, P24, P25 | Stock Control | 55 | |
P23 Stock File Creation | |||
P24 Transaction File Creation | |||
P25 Stock File Update and Report | |||
P26 | VAT Calculator | 58 | |
P27 | True Rate of Interest | 59 | |
SECTION 4 | |||
P28 | Simple Tax Calculator | 60 | |
P29 | Loan Repayments | 62 | |
P30 | Monthly Accounts | 66 | |
P31 | Conversion | 66 | |
P32 | Birthday Lists | 68 | |
P33 | Diary | 70 | |
P34 | Calendar | 72 | |
P35 | Telephone List | 74 | |
P36 | Investments | 76 | |
SECTION 5 | |||
P37 | Quadratic Equations | 78 | |
P38 | Factorization | 80 | |
P39 | Factorial | 83 | |
P40 | Greatest Common Divisor | 85 | |
P41 | Secant Method | 86 | |
P42 | Method of Bisections | 88 | |
P43 | Trapezoidal Rule | 90 | |
P44 | Simpson's Rule | 92 | |
SECTION 6 | |||
P45 | Circles | 93 | |
P46 | Interference | 95 | |
P47 | Picture | 96 | |
P48 | Picture Editor | 97 | |
P49 | Zoom | 100 | |
P50 | Worm | 102 | |
P51 | Drawing | 104 | |
P52 | Writing Text At The Graphics Cursor | 105 | |
SECTION 7 | |||
P53 | Pie Chart | 107 | |
P54 | Bar Chart | 109 | |
P55 | Mean and Standard Deviation | 111 | |
P56 | Bubble Sort | 114 | |
P57 | Shell Sort | 116 | |
P58 | Merge | 118 | |
P59 | Binary Search | 120 | |
P60 | Permutations | 122 | |
P61 | Combinations | 123 | |
P62 | Least Squares | 124 | |
SECTION 8 | |||
P63 | Number of Days | 126 | |
P64 | Digital Clock | 127 | |
P65 | Kitchen Timer | 128 | |
P66 | Recipes | 129 | |
P67 | Encoder | 134 | |
P68 | Decoder | 136 | |
P69 | The Game of Life | 138 | |
P70 | Biorhythms | 141 | |
P71 | Dog Race | 143 | |
P72 | Magic Matrix | 145 | |
P73 | Dice | 147 | |
P74 | Pools Program | 148 | |
P75 | Shuffle | 149 | |
SECTION 9 | |||
P76 | Number Base Conversion | 151 | |
P77 | Colour Codes for Resistors | 154 | |
P78 | Volumes of Solids | 156 | |
P79 and P80 | Physics | 159 | |
P79 Moment of Intertia | |||
P80 Focal Length | |||
P81 | Resistors | 164 | |
P82 | Calculator | 165 | |
P83 | Coordinate Conversion | 166 | |
SECTION 10 | |||
P84 | Shading | 168 | |
P85 | Translation | 170 | |
P86 | Parallelogram | 172 | |
P87 | Drawing Circles | 174 | |
P88 | Shape Grabber | 177 | |
P89 | Rotation | 179 | |
P90 | Transformations | 182 | |
P91 | General Transformations | 185 | |
P92 | 3D-Rotation--1 | 187 | |
P93 | 3D-Rotation--2 | 190 | |
P94 | Perspective | 192 | |
P95 | Rotating House | 196 | |
SECTION 11 | |||
P96 | Arithmetic Tutor | 199 | |
P97 and P98 | French and German Tutorial | ||
P97 French Tutorial | |||
P98 German Tutorial | |||
P99 | Spelling | 204 | |
P100 | Counting | 207 |
I have, in my selection, attempted to answer the question "What do you use a microcomputer for?". You will find routines in this book which cover the use of micros at home, in business, in school and for pleasure.
It is intended that after you have entered any of these programs then you would wish to record them onto tape. To help you, here is a reminder as to the saving of programs.
To save a program:
Each program is laid out in the following format:
The ELECTRON dialect of BASIC is an attempt to overcome some of the limitations of "traditional" BASIC. It is possible to write fairly well laid out and well structured code in ELECTRON BASIC.
These programs represent an attempt to exploit these features of ELECTRON BASIC. However, the language does have its limitations. You will occasionally find some rather long IF statements, which can be difficult to read. This is due to a lack of a multi-line IF statement, as is given in other versions of BASIC such as COMAL.
It is possible to lay out programs using what is known as LISTO features, as used in the User Guide. I have not used this feature of the ELECTRON machine. I prefer to layout code in a manner that I find more natural.
When writing the programs, I first of all sketched out the program using a pseudo form of BASIC, which was fairly well structured. Thus when I come to code the programs, I already know the layout I required, so I did not use the layout features of the machine.
The routine is:
830 DEF FNchar(U,V)
840 PRINT TAB(U,V);
850 A%=135
860 =(USR(&FFF4) AND &FF00)/&100
Line 840 places the text cursor at position (u,v) on the screen. Line 850 places the value 135 (87 hex) into the accumulator. The routine called by USR(&FFF4) is one of the OSBYTE calls documented in the User Guide. ANDing the integer returned from the USR call with &FF00, masks off the least significant byte. Division by &100 leaves us with the ASCII code for that character.
Part of the fun in programming is the finding and correcting of bugs. Indeed, correcting bugs often contributes to the process of introducing bugs.
Bugs can be introduced in various ways. I might have left a few bugs in the code. Hopefully, through the efforts of Prentice-Hall in carrying out field tests, those will be at a minimum.
Bugs can be introduced when you are keing in your programs. To catch these bugs you have to go through each section of the program in turn and try to locate it bye eye and by testing the section. Using the page mode feature of the ELECTRON micro can be very helpful at this stage.
Common errors are:
One of the joys of programming is to take a simple routine and give it a professional user friendly appearance. I have not attempted to make any programs complete in this sense. This is left up to you.
Do not feel shy about using the programs as routines within others. Consider this book to be a software library.
However, if you do use a routine within work of your own, I would be pleased if you were to acknowledge the source.
GO ON ENJOY YOURSELF.