Program and Electronic Projects for the SSC, Electron and Spectrum Computers Macmillan ElectronicProjectsSeries Audio CircuitsandProjects (revisededition) Graham Bishop Programand ElectronicProjectsfor the BBC,ElectronandSpectrum Computers Graham Bishop Projectsfor the Carand Garage(revisededition) Graham Bishop Cost-effective ElectronicConstruction John Watson Program and Electronic Projects for the SSC, Electron and Spectrum Computers Graham Bishop M MACMILLAN ©Graham Bishop 1985 All rights reserved.No reproduction,copy or transmission ofthis publication may bemadewithoutwritten permission. No paragraph ofthis publication may bereproduced,copied or transmitted save with written permission or in accordance with the provisions ofthe Copyright Act 1956 (asamended). Any person who doesany unauthorised act in relation to this publication may be liable to criminal prosecution and civil claims for damaged. First published 1985 Published by MACMILLAN EDUCATION LTD Houndmills, Basingstoke, Hampshire RG21 2XS and London Companies and representatives throughout the world British Library Cataloguing in Publication Data Bishop, G. D. Program andelectronicprojectsfor the BBC, Electron and Spectrum computers.-(Electronic projects) 1.Microcomputers I. Title II.Series 001.64'04 QA76.5 ISBN978-0-333-38568-5 ISBN978-1-349-07759-5 (eBook) DOl 10.1007/978-1-349-07759-5 Accompanyingsoftwarecassette: ISBN 978-0-333-40553-6 Contents Preface vii Part2: Computer Programs 27 Part 1: The Micro Explained 1 7 Utility Programs 29 7.1 Pressto Continue 30 1 AMainframe,Minior Micro? 3 7.1.1 Menusandkey selection 30 1.1 What isaMicrocomputer? 3 7.2 Large(Spectrum) 34 7.3 Scrolling 35 7.4 Tellingthe Time 38 2 Bits, Bytes 5 7.5 Titling onthe BBC/Electron Machines 40 7.6 Graphics Building Blocks 41 3 Computer Applications 12 7.7 How Much Memory isLeft? 43 8 The Bishop Collection 46 4 Inside the Micro 13 8.1 Talkingto the Computer 46 4.1 The Microprocessor 13 8.2 Binary 48 4.2 The AddressBus 13 8.3 Mathematics 54 4.3 Hex andWords 13 8.4 3-D Graphics 54 4.4 The DataBus 13 8.5 HistogramsandGraphs 54 4.5 How the Computer's Memory isOrganised 15 8.6 Mathematical Equations, Quadratics 57 4.6 What isMeant by 32K? 17 8.7 Piecharts 58 8.8 PhysicsTopic Areas 60 8.9 Centre of Mass 60 5 UsingtheMicro 18 8.10 Series/Parallel Resistors 60 5.1 BASIC 18 8.11 Pictorial Demonstrations 60 5.2 MachineCode 18 8.12 Language Education UsingComputers 76 5.3 Assembly Language 18 8.13 Geography 78 8.14 Cookery and Home Economics 79 6 ExtendingtheMicro 24 8.15 History 82 vi ProgramandElectronicProjectsforthe BBC,ElectronandSpectrum Computers 8.16 A School, College,Factoryor Office NOTICEBOARD 83 12.3 Testingthe ADC 132 8.17 Programsthat TeachComputing 89 12.3.1 Suggested layoutforthe ADC board 132 12.4 ADC Applications 133 9 Sortingand Data Handling 97 12.4.1 Joysticks 133 9.1 Sort 97 12.4.2 Temperature 134 9.2 DataTabulation andProcessing 98 12.4.3 Light 135 9.3 A Word Processor 101 12.4.4 Voltage 135 12.4.5 Resistance 136 Part3: Computer InterfacingProjects 109 12.4.6 Presence 136 12.4.7 Sound 137 10 The Latch 111 12.5 Robotics 137 10.1 Latch Addressing 111 12.6 Recording andPlaying BackSound 139 10.2 The Latch Circuits 112 12.7 Other Application ideas 139 10.3 Construction 115 10.3.1 Suggested latch cardconstruction 115 Bibliography 141 10.4 The Latch in Operation 121 10.5 Latch OutputCircuits 121 AppendixI Z80InstructionSet 142 AppendixII 6502InstructionSet 145 11 A DigitaltoAnalogueConverter 124 AppendixIII Decimal-HexadecimalConversion Table 148 11.1 DAC CircuitandConstruction 124 AppendixIV A SelectionofAdditionalSpectrumPhysics 11.2 DAC Testing 124 Programs 150 11.3 Suggested DAC CardConstruction 126 Appendix V IntegratedCircuitPin Connections 156 12 An Analogue to DigitalConverter 127 Index 159 12.1 The ADC Circuit 127 12.2 Constructingthe ADC 129 Detailsofcassette 161 Preface One house in four in the U.K. hasa microcomputer, but what are and 6502 processorsand soenable easyconversion to bemadeinto they usedfor? Games... games... and even more games? There is other dialects of BASIC. The electronic projects can be easily far more to the microthan merely playingready-programmed games adapted for any micro with an edge connector to which are con and usingcommercial software packages. nected the addressanddata buses. This book sets out to explore many other 'useful' uses of the Students and teachers of Computer Science, Computer Studies home and businessmicro in the fieldsof and Electronics should find this book invaluable, at all levels,from primary to post-graduate degreelevel.The programs in chapter8can program writing beadapted toany subject areasfor school or college use. the useofutiIity programs The electronic projects of part 3should bewithin the capabilities writing instructional graphicsprograms of most readers, especially those who prefer working on practical connectingthe microto the outside world with electronics projects; the costs of each project are low, of the order of afew pounds foreachunit. andthe pure enjoymentof learning howamicro works. My sincere thanks go to Julie, my wife, andStella, my daughter, I had a problem with the title. The book contains over 60 pro for typing the manuscript and for tolerating a few weeks of pain grams and over 20 electronic projects and ideas, all of which are staking computing,electronicsandpreparation. suitablefor three popularcomputers A cassette tape isavailable with this book. One sideof the tape containstheSpectrumprograms,andthe othersidethe BBC/Electron the SinclairSpectrum programs, these being playable on either machine. This saves the the BBCModel B,and time-consuming job of typing the many long programs into the the Acorn Electron. computer. Titles could rangefrom 'Extending your Micro' to 'Spectrum, BBC 1985 GRAHAM BISHOP and Electron Projects in Programming and Electronics'. After much thought the present title wasselectedbecause,although somemight consider it long-winded, it doesgive an accurate summary of what the book isabout. The book should be of great interest to all those who own a micro, since the programs and projects can easily beadapted to suit all popular microcomputers. The programs and projects usethe Z80 Part 1 The Micro Explained 1 A Mainframe, Mini or Micro? Three kinds ofcomputerexist today: The mainframe computer - a very large machine filling one or (a) to perform calculations, likeacalculator; more rooms where large-scale computing operations, such asthe (b) to store many numbers, letters, words or, in general, 'data'; processingofbank accounts, arecarried out; (c) to processdata, such assorting into alphabetical order, sorting The minicomputer - a medium-sized machine, which occupies types, listing intocolumns; the corner of a room, with very large storage capacity and a (d) to play games,using colours, sound and fast-moving graphics; numberofprogramming languagesandfacilities; (e) to operate equipmentsuchasrobots, lights andmotors; The microcomputer (or micro for short) - a table-top machine (f) toteach in the classroom. with limited memory, say64K,andalimited numberofavailable 'add-ons'suchasprintersandcassetteor discmachines. Many microownersconfinetheir usesofthe microtofast-moving This book concentrates on the operation and applications ofthe games, and using the micro like a toy. This samecomputer can, basicmicro,usingthree ofthe more popular machineson the market, however, with littleor no modification,beprogrammed tocarry out namely the Sinclair Spectrum and the BBC Acorn and Electron. awhole rangeof applications. The complete system is illustrated in Thesemicros usethe Z80 (Sinclair) and 6502 (BBC) processorsand figure 1.1. sothe concepts developedcanbeextended to awide rangeofsimilar The basic packagecomprisesamicro,aTV receiverandacassette machines, most ofwhich useoneoftheseprocessors. recorder. Most micros generateaUHF TVsignal,usually on channel Part 1 describes the most common forms of computer jargon 36, for direct connection to a domestic colour TV receiver, the which should givethe readerabetterunderstandingofany computer sound being either contained within the micro itself using a small they possess,togetherwith the foundation on which canbebuiltthe internal loudspeaker, or (as with the Commodore micros) trans projects ofthe later chapters. mitted to the TV receiver in the normal way. Some micros,suchas the BBC Acorn and Electron, provide a video output for compiling directly to a colour monitor, and so give better picture definition. 1.1 What isaMicrocomputer? The cassetterecorder isnormally asimple audiocassettemachine, with the MIC and EAR input andoutputalong which the computer A microcomputer is a low-priced sophisticated piece of electronic sendsor receives its signals. Some machines, like the Commodore, equipmentwhich canbeprogrammed have their own special cassette recorder which turns itself on and