au ss UNDERSTANDIN

INTERNATIONAL

PERSONAL ORIC 1 (V1.0) and

COMPUTER ele) q ORIC ATMOS (V1.1)

IAN McLEAN

UNDERSTANDING

ORIC

DEDICATION

To Anne, for tea and sympathy

UNDERSTANDING

ORIC

lan McLean

Prentice /Hall

Englewood Cliffs, New Jersey London New Delhi Rio de Janeiro Singapore Sydney Tokyo Toronto Wellington

British Library Cataloguing in Publication Data

McLean, lan Understanding ORIC 1. ORIC-1 (Computer) |. Title 001.64’04 QA76.8.07

ISBN 0-13-477332-2 © 1984 by lan McLean

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the author.

PRENTICE-HALL INTERNATIONAL, INC., London PRENTICE-HALL OF AUSTRALIA PTY, LTD., Sydney PRENTICE-HALL CANADA, INC., Toronto

PRENTICE-HALL OF INDIA PRIVATE LIMITED, New Def/hi PRENTICE-HALL OF JAPAN, INC., Zokyo

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 LIMITED, Wellington, N.Z.

Printed in the United Kingdom by A. Wheaton & Co. Ltd, Exeter

0 9 86 7 6 5 43° 2 7

Contents

PREFACE Xx Beware the Evil ORIC

CHAPTER 1 1

The Performing ORIC

UNPACKING THE COMPUTER/CONNECTING UP/STARTING OFF/ THE NOISY ORIC/ALL THE COLOURS/CLEARING THE SCREEN/ REMOVING THE KEYCLICK/THE RESET SWITCH/SOME FANCY TRICKS/SOME PRETTY PICTURES.

CHAPTER 2 Zo

The Key to Success

THE KEYBOARD/SHIFTED KEYS/DELETE KEY/RETURN/ AUTOMATIC REPEAT/KEYBOARD BUFFER/LOWER CASE LETTERS/CONTROL CHARACTERS/ATTRIBUTES/BACKGROUND AND FOREGROUND/CTRL J/FLASHING AND STEADY/STANDARD AND ALTERNATE CHARACTERS/DOUBLE HEIGHT CHARACTERS / 60 HZ ATTRIBUTES.

CHAPTER 3 38

Enter the ORIC ENTERING PROGRAMS/LINE NUMBERS/ENTERING PROGRAMS/ EDITING/LINE NUMBERING/ DELETING A LINE/NEW/A DIVERSION/ BREAK.

vi Contents

CHAPTER 4 52

Loading and Saving Programs

CASSETTE RECORDER/CASSETTE TAPES/TECHNICAL TERMS/ CSAVE/CLOAD/CASSETTE RECORDER PROBLEMS/SLOW AND FAST/VERIFYING PROGRAMS/JOINING PROGRAMS/FINDING PROGRAMS/AUTOMATIC START/SAVING MEMORY BLOCKS/ SAVING LONG PROGRAMS/MORE DIVERSIONS.

CHAPTER 5 65 Exploring ORIC

GENERAL FEATURES/REM/COLON/STOP/CONT/GOTO/INFINITE LOOPS/SCROLLING/CLS/FOR ... NEXT/LET/WAIT/INK AND PAPER.

CHAPTER 6 75

The ORIC Display

PRINT/PRINTING NUMBERS/PRINTING CHARACTERS/STRINGS/ PRINT SEPARATORS/SEMICOLON/COMMA/SPC/PRINT @/ARITHMETIC.

CHAPTER 7 | 90

Some Odd Characters

CHR$/CONTROL CHARACTERS/ESCAPE/PLOT/LORES@/ PLOTTING ATTRIBUTES/ ATTRIBUTES WITH PRINT @/INPUT.

CHAPTER 8 103

It's Make Your Mind Up Time

DECISIONS /IF...THEN/AND, OR, NOT/IF... THEN...ELSE/MULTIPLE INSTRUCTION LINES/FOR...NEXT/STEP/REPEAT...UNTIL/ SUBROUTINES/ON...GOTO/ON...GOSUB/TRON AND TROFF.

CHAPTER 9 118

A Way With Words

STRINGS/CONCATENTION/FRE/STRING DECISIONS/COMPARING STRINGS/VAL/STR$/LEN/LEFT$/RIGHT$/MID$/KEY$/GET/ ASC/CHR$/VARIABLES/CLEAR.

Contents vii

CHAPTER 10 129

The Numbers Game

NUMBERS/SGN/ABS/INT/RND/MATHEMATICS/POWERS/SQR/ LOG/EXP AND LN/PI/SIN, COS, TAN, ATN/DEF FN/READ, DATA, RESTORE/ARRAYS/DIM/FUNNY NUMBERS/AND, OR.

CHAPTER 11 143

Sound It Out

PLAY/SOUND/ENVELOPE/MUSIC/MUSICAL THEORY/HARMONY/ PITCH/ DURATION/TIME/PROGRAMMING METHOD.

CHAPTER 12 164

ORIC The Artist

LOW RESOLUTION GRAPHICS/ALTERNATE CHARACTER SELECTION/LORES 1/USER DEFINED GRAPHICS/POKE AND PEEK/ CARTOON MOVEMENT/SCRN.

CHAPTER 13 178

More ORIC Artistry

HIRES/HIGH RESOLUTION SCREEN/CURSET/CURMOV/DRAW/ GLOBAL COLOUR IN HIRES MODE/CIRCLE/PATTERN/POINT/FILL/ HIGH RESOLUTION ATTRIBUTES/POKING ATTRIBUTES/CHAR/ USER DEFINED CHARACTERS/DRAWING CURVES.

CHAPTER 14 202 Bits ‘n Pieces DATA HANDLING/FILE HANDLING-STORE AND RECALL/GRAB/ RELEASE/SAVING SCREEN DISPLAYS/SAVING CHARACTER SETS/TRUE AND FALSE/POP/POS/PULL/ARRAY AND STRING

CORRUPTION/INPUT AND OUTPUT DEVICES/ALL ABOUT ATTRIBUTES.

CHAPTER 15 > a

Get Into Print

THE ORIC PRINTER/PEN POSITIONS/PRINT MODES/TEXT MODE/ CHARACTERS PER LINE/LLIST/LPRINT/CONTROL CODES/ GRAPHICS MODE/IMPLICIT COMMANDS/OTHER PRINTERS/PIN CONNECTIONS/THE TRS-80 COLOUR PRINTER/POS(1).

vill Contents

CHAPTER 16 230

Machine Code

MACHINE CODE/THE 6502 MICROPROCESSOR/ASSEMBLY LANGUAGE/CALL/RTS/PUTTING MACHINE CODE INTO MEMORY / HIMEM/DEEK AND DOKE/USER DEFINED INSTRUCTION(!)/USER DEFINED FUNCTIONS/LOADING AND SAVING MACHINE CODE.

CHAPTER 17 241 In Conclusion

APPENDIX A 243 ASCIll Codes APPENDIX B 246

Microcomputer Magazines

APPENDIX C 247 ORIC BASIC

APPENDIX D 257 Memory Maps

APPENDIX E 259 Pin Output Chart

APPENDIX F 260 Error Codes

APPENDIX G 262 6502 Assembly Language Instruction Set

INDEX 281 index

ACKNOWLEDGEMENT

The cartoons following the Preface and on Page 2 were adapted from drawings in 'Graphics Ad Lib No 3' by Tony Hinwood, published by Business Books

PREFACE Beware the Evil ORIC

"Dear Sir

We regret the several mistakes which have been made in dealing with your account. These, however, were not the fault of anyone in this organization as they were caused by our computer."

This is the genuine excerpt from a letter sent to a number of people by the accounts department of a well known international company. What is even more suprising is that most of the people to whom the letter was sent accepted the excuse as valid.

X

Preface xi

The computer has a very bad public image, which is not helped by reports in the popular press. The computer (it would seem) is a ferocious machine totally evil and much smarter than the poor people on whom it preys. Its main occupation is sending million-pound electricity bills to senior citizens. In its spare time it causes traffic snarl ups and is responsible for every ill which afflicts modern civilization from smog to (the mind boggles) overpopulation.

The only beings allowed into the monster's air conditioned den are a special elite of geniuses who have to have doctorates in at least four different subjects. Any lesser mortal daring to approach the computer much less touching the keyboard will be immediately vaporized. Any unauthorized keyboard entry will cause the computer to blow up the world.

Don't believe a word of it. The computer is just a machine like any other.

It will do only what you tell it to do. It is not very smart and will do exactly what it is told to do not what you think you told it to do. It will not do what it is not told to do even though it seems logical to you that that is what it ought to do. You will see what I mean once you start 'programming' the computer (telling it what to do).

YOU ARE IN CONTROL

This is the age of the personal computer. Your ORIC 1 is your own property. It is up to you to tell it what to do, and without your instructions it can do nothing.

So if you want to know what a key does press it.

If you want to know what will happen if you put an instruction into a program -— try it.

You cannot damage the machine by keyboard entries or program instructions, and sitting down and playing with the machine is fun. Enjoy yourself.

Please treat the programs you find later in the book as examples. They do not represent the only solutions and may not even be the best solutions. Change them in any way you wish. By doing so you will gain a deeper understanding of how the programs work and how the machine operates.

XII

® oO © eS ® 2

t

to know what a key does —press |

If you want

CHAPTER 1 The Performing ORIC

"Now he was master of the world he was not quite sure what to do next.

But he would think of something." Arthur C. Clarke 2001

Congratulations!

You now own an ORIC 1. Possibly the best value-for-money available in home computers at present.

Zo Chapter 1

You have sent the children to bed, told all your friends you are going to Outer Mongolia, and put the cat out to play with next door's Alsatian.

Now you are alone with your machine.

What's inna box Daddy? 'sit for me? Can I play wiv it?

'sit Chissimas - has Sanna brottit?

The Performing ORIC 3

UNPACKING THE COMPUTER

Carefully open the box and remove the protective packing. You should have the following:

1 Computer

c=. 1 User Manual

<j os

1 Power Supply 1 ‘Welcome’ Tape 1 Tape Recorder Lead

To get your computer working you will need a television set. The computer will work with either a black and white or a colour set, and all the programs in this book will run on whatever set you have. The colour programs will produce different shades of grey on a black and white set.

However, I rather hope you have a colour television set. Some spectacular displays can be generated by the ORIC 1.

For the remainder of the book I will be assuming that a colour set is being used.

4 Chapter 1

CONNECTING UP

If you look at the back of the computer you will see a number of sockets as shown:

Tape Cassette Expansion Bus

Right now we will be concerned only with the 'Power' and 'TV Output' sockets. We will come to the others later.

The jackplug output of the power supply should not be plugged into the power socket in the computer. Plug the power supply into a mains socket. If the mains socket has a switch then switch it on.

Unplug the aerial from your television and use the special cable provided to connect the 'TV Output’ socket on your ORIC 1 to the aerial socket on your television. If your television has both 'UHF' and 'VHF" sockets, use the socket marked 'UHF'.

If your television has an internal aerial you may find a switch next to the (normally unused) external aerial socket. This switches to external aerial and disconnects the internal aerial. If it exists, this switch should be operated.

The Performing ORIC 5

eee ee ee eeee eee eeese eee ee ee eee eee eee eee ee 8 6 eee ee eee eee ees * 0 @ 8 ee eee eee eee ee eee eee eee eee ee ee

Power Supply

Aerial Socket

* 0 0 6 6 6 6 6 6 6 6 eee eee FCCC O ee Oe ee ee eee ee ee ew oe CO ee ee eee eo 6668 Ow ee ewe eee wee oo oe SOO ee)

9V DC Power in

ecaetetetecerecetatececeretetesececetetatecetetete soteseteterereteteteterecerereteceseretateterecevatatecereretatececeteteteteratatacereretereceteteceretetererere® OR I HI I I HT I

Television

Switch on the television and plug the power supply into the computer. Turn the television volume control right down.

6 Chapter 1

If your television has channel select buttons (as in the diagram below) press a normally unused button.

JUJULUL

Unused Channel Select Button

Tuning Control

Tune the television by turning the tuning control knob until the message:

'ORIC EXTENDED BASIC V** ©1983 TANGERINE

#eEEX BYTES FREE

Ready'

appears in black print on a white screen. The numbers represented by the '*' symbol will vary depending on the memory size (16k or 48k) and

the machine 'version'. Currently there are two versions, V1.0 and V1.1.

The number of 'bytes free' is less than the total memory size. Some memory is used to control the screen display.

The Performing ORIC F

37631 BYTES FREE React, a

If instead of this message you find a rather odd black and white pattern on the screen, switch the computer back off and on again. Do this by unplugging and reconnecting the jack plug at the rear of the machine. This is hardened and will not wear. Switching power off and on again at the mains seldom works as the power then comes on too gradually to reset the machine correctly.

At the top right of the screen you should see the word 'CAPS'! in white letters on the black border. To the left of the screen, below the word 'Ready' you will find a flashing square. This is called the 'cursor'.

8 Chapter 1

STARTING OFF

Let's have a look at the keyboard.

: e * $ % A & * ( ) Cc + : | v4 i} a be 6 7 8 9 @ - = \

LI _ a_i o_O t_) Nes 8 RS ee ee ye ee "ok LO GMa CS eee SeSseeeeesee eee

CTRL RETURN

eee eee ee M < > ?

2S os oo oe

.

ee

If you have ever used a typewriter the ORIC keyboard should not hold too many terrors for you. The layout is the standard typewriter 'QWERTY' keyboard with a few keys added. There is plenty of space between the keys and the lettering is clear and uncluttered.

The Performing ORIC 9

Note the position of the two SHIFT keys, the CTRL (control) key, the ESC (Escape) key, the DEL (Delete) key, the Cursor control keys and the RETURN key.

E Pe oe 8 8 8 8G ee 8S EG Os

ee ee Del CRTL ee ee Return uaa ame Shift

shift eorcreenece orca

Cursor Control Keys

Here are some important points to note.

L I am going to ask you later in this chapter to press a SHIFT key (either of the SHIFT keys will do - they are both the same to the computer) and another key 'simultaneously'. What I really mean is that you should press SHIFT key first and hold it down while you press the other key; then release both keys. Many keyboard errors occur through not having the SHIFT key depressed first when a 'shifted' key is required.

Ze In exactly the same way I am going to ask you to press the CTRL key and another key 'simultaneously'. In this case the CTRL key is pressed first and held down while the other key is pressed, and then both are released.

>; From now on when I ask you to 'press' a key I will mean press and then release it. If I want you to hold a key down] will say so.

4. If you type in a wrong character press the key marked DEL (just above the large RETURN key at the right of the keyboard). This will delete the last character entered.

10 Chapter 1

Type in PAPER 1 and press RETURN.

If you are lucky the 'paper' i.e. the area inside the black border will have changed to red. More probably it will have changed to a shade of grey. If that is the case tune the television until you have a red paper area. This may require delicate tuning. If there is a switch marked 'AFT' beside the tuning controls on the television it may help to turn this to the 'OF F' position.

If instead of changing the colour of the paper area the computer prints the message '?SYNTAX ERROR' on the screen (in computer jargon we talk about it 'returning a syntax error') then you have not typed inPAPER 1 correctly. In this case please type it in again.

When you typed in the 'command' PAPER 1 you did not need to press the SHIFT key to get capitals. All alphabetic keys give capital letters when pressed. This is what 'CAPS' in the top right hand corner means. You won't be using lower case (small) letters for some time yet, so don't worry about them right now.

Let's have some fun with the computer. I shan't explain what I am asking you to do at this stage. Please follow my suggestions 'on trust’, All will be explained later.

The Performing ORIC 11

THE NOISY ORIC Type in ZAP and press the RETURN key. Some commands are not really all that difficult to understand! Now try PING again followed by the RETURN key. Type in: SHOOT : WAIT9: PING: WAIT9: ZAP: WAIT5:E XPLODE

(The colon (:) is SHIFT and the key to the right of key L_ pressed simultaneously.)

Be careful to use the letter O in 'SHOOT' and 'EXPLODE' and not the number # (zero). The number (zero) has a stroke through it on the keyboard so that you can tell the difference. A lot of syntax error messages are caused by confusing the two keys.

9 (zero)

O (letter)

Press RETURN. You should already have discovered one thing about the ORIC. It can generate a lot of noise not for ORIC users are the feeble chirps produced by some other microcomputers! One more burst and I hope you have thick walls or tolerant neighbours. Type in:

FOR N=1 TO 1f:ZAP:WAIT 5:NEXT

followed as usual by the RETURN key.

12 Chapter 1

ALL THE COLOURS Let's try something quieter. Type in FOR N= TO 7:PAPER N: WAIT 16§:NEXT and press RETURN

Nice colours aren't they!

CLEARING THE SCREEN

By now the screen is full of all sorts of rubbish. Let's see how to clear it.

Press CTRL and key L simultaneously.

c

H om * 8 = P ELS, Det oe ao

SSS eee Oe 2. os =. on

CTRLL Toclear Screen

Hey presto a nice clean screen!

The Performing ORIC 13

REMOVING THE KEYCLICK

You will have noticed that when you press a key you get a fairly loud click. This is to let you know the key has been pressed. If you like this idea good! If, like me, you find the positive feel of the keyboard more than adequate 'feedback', and the keyclick a noisy nuisance, then you will want to know how to get rid of it.

To stop the keyclick press CTRL and key F simultaneously.

Se yy P ° DEL = os

CTRL

Smee SSe eee 5 ao Seen nem Sm Se ee

CTRL F Toremove Keyclick

If you want to get the keyclick back press CTRL and key F simultaneously again.

14 Chapter 1

THE RESET SWITCH

Now let's explore the ORIC. Some very odd things are about to happen; so I had better tell you about the 'panic button’.

If you lift up the ORIC gently, so as not to pull the connections out of the back, you will see a small square hole. Inside this hole is a switch. This is the ORIC's reset switch. You will need a pencil or screwdriver to operate the switch. When you do so the screen clears and the 'ready' message is restored.

id Reset Key

The advantage of the reset switch is that it is a 'warm start’. This means that 'programs' (see chapter 2) are not lost, as they would be if you powered off and on. If you get lost and cannot get the machine back to sane and sensible operations it is comforting to know the reset switch is there but try not to use it too often.

The Performing ORIC 15

SOME FANCY TRICKS

Type in PAPER fkINK 3

and press RETURN

Press CTRL and L simultaneously.

You should have a black screen, blank except for the flashing cursor at top left.

Press RETURN to move the cursor down one line.

Press CTRL and D simultaneously.

Press ESC

Press key J.

So far nothing much has happened. However if you type in: HELLO BIG BOY

You may find the result rather surprising.

HELLO BIG BOY

16 Chapter 1

Press RETURN. Ignore the jumbled message which this _ pro- duces.

Press CTRL and L simultaneously to clear the screen and then press RETURN to bring the cursor down one line.

Press ESC followed by N. Type in:

YOU'RE REAL FLASHY Press ESC followed by A Type in: RED

How zat!

YOU'RE REAL FLASHY RED

The Performing ORIC 17

Press RETURN, ignoring the odd message this produces. Clear the screen by pressing CTRL and L simultaneously and then press RETURN to bring the cursor down one line.

Press ESC followed by J.

Press ESC followed by A and type in RED.

Press ESC followed by B and type in GREEN.

Press ESC followed by C and type in YELLOW.

Press ESC followed by D and type in BLUE.

Press ESC followed by E and type in MAGENTA.

Press ESC followed by F and type in CYAN.

RED GREEN YELLOR BLUE ARGERTA CTAK™

18 Chapter 1

Before we leave the large letters we will try one more demonstration. As before press RETURN and ignore the odd message. Press CTRL and L simultaneously to clear the screen, followed by RETURN to move the cursor one space downwards.

Press: ESC followed by W; ESC followed by @ (@ is SHIFT and 2 simultaneously); ESC followed by J;

and type in BLACK ON WHITE.

Move the cursor down two lines using the cursor control key with the downward pointing arrow to the left of the space bar.

Move the cursor to the far left of the screen using the cursor control key with the left pointing arrow.

Press: ESC followed by V; ESC followed by A; ESC followed by J;

and type in RED ON CYAN.

As before use the cursor control keys to move the cursor down to spaces and left to the start of the line.

Press: ESC followed by U; ESC followed by B; ESC followed by J;

and type in GREEN ON MAGENTA.

Use the cursor control keys again to position the cursor at the start of the next double line. You should be getting good at this by now.

Press: ESC followed by T; ESC followed by C; ESC followed by J;

and type in YELLOW ON BLUE. Finally press CTRL and Q@ together to hide the cursor. I hope you

will agree that this is a fairly dramatic display of the machine's keyboard entry facilities.

The Performing ORIC

20 Chapter 1

SOME PRETTY PICTURES Words are boring Let's see some pictures!

The first thing we will do is to get our cursor back. It is difficult to work without it.

Press CTRL and Q simultaneously.

Press RETURN and then press CTRL and L simultaneously; then press RETURN again.

Press ESC followed by K and type in NSE£SESESE,WL */ ~ (* is key 6 and the SHIFT key pressed simultaneously)

Use the cursor control key to move the cursor down and left to the start of the first blank line (as you did in the last demonstration).

Press CTRL and D simultaneously, and then CTRL and T simultaneously. Press key O (that is the letter O, not zero).

Press the space bar three times.

Press key O and press the space bar 3 times.

Press O space O space O space O.

Press CTRL and Q simultaneously to hide the cursor.

The Performing ORIC

21

If pictures you want then pictures you got!

UO-C

22 Chapter 1

Press CTRL and T simultaneously, then CTRL and Q simultaneously. Press RETURN and clear the screen with CTRL andL. Type in HIRES and press RETURN.

The cursor should move down to the bottom of the screen. You should see the word 'Ready' in yellow letters close to the cursor.

Type in: CURSET 125,99,3:CIRCLE 99,1

and press RETURN.

A circle should appear on the screen.

Type in: CURSET 12,8,3:PATTERN 51:DRAW 227,199,1 and press RETURN.

Type in: CURSET 12,199,3:DRAW 227,-199,1

and press RETURN.

You should now have a circle and two crossed dotted lines.

The Performing ORIC

23

24 Chapter 1

Clever enough, you may think, for a very small computer, but ORIC has rather more than that up its sleeve.

What you do now depends on the version of the machine you have. If you have the 48K ORIC type in:

FOR N=#Af#6 TO #BFE6 STEP 49:POKE N, INT(RND (1)* 7#1):NEXT

and press RETURN. If you have the 16K ORIC type in

FOR N=#2606 TO #3FE@ STEP 49:POKE N, INT(RND(1)* 7+ 1):NEXT

and press RETURN.

Note press RETURN after NEXT in either case not after N,.

I hope these demonstrations have convinced you that you have a remarkable and versatile little machine. You may see some pattern in what we have been doing (if not don't worry) and may be interested in

what would happen if you changed the instructions about a bit.

Go ahead and try!

CHAPTER 2 The Key to Success

=

THE KEYBOARD

In the previous chapter you used the keyboard a fair amount and you should have the 'feel' of it by now. The spacing between the centres of the keys is the same as on a standard typewriter.

Press the reset key underneath the machine, or switch power off and on again. This gets the machine back to its initial state.

25

26 Chapter 2

SHIFTED KEYS

Some of the keys have two characters written above them. Pressing such a key causes the lower of these characters to appear on the screen. Pressing the same key and the SHIFT key (either SHIFT key will do) causes the upper character to appear.

For example pressing key 3 causes a 3 to be printed on the screen. Pressing key 3 and SHIFT simultaneously causes the symbol # to be printed on the screen (symbol # is 'shifted 3')

Practise using the shift keys type in:

1@#HS%* &*(NE+;{} /2"<>?

1ORSATERC DEt | 9: MX OF

The symbol * (shifted 6) is displayed as + onthe screen.

The Key to Success 27

DELETE KEY

The delete key DEL is used to delete keyboard entries if, for example, you press the wrong key or change your mind.

DEL moves the cursor one space to the left and deletes the last entered character to the left of the cursor as it does so. If the cursor is at the far left of a line then DEL will move it to the far right of the line above assuming that there is a character in that position which is part of the current entry. Otherwise DEL has no effect.

If you try to delete entries which have been 'terminated' (by pressing the RETURN key) you will get some odd effects.

RETURN

The RETURN key is used to 'terminate' entries. In the previous chapter you saw that the computer obeyed a command (did what you told it to do) only after RETURN was pressed. For example when you typed in 'ZAP' nothing happened until RETURN was pressed.

RETURN is also used when keying in computer 'programs' see later in this chapter.

AUTOMATIC REPEAT

Press a key say key @ and hold it down until you have a whole line of Q's. Holding a key down has the same effect as pressing it repeatedly. This is a useful feature if you wish to key in, for example, a lot of spaces. It also works with the DEL key so delete the line.

KEYBOARD BUFFER

Press an alphabetic or a numeric key and hold it down. The character chosen will appear on the screen repeatedly until eventually you will get a 'ping'. When you hear the ping release the key.

You are allowed to type in only a certain maximum number of characters before pressing a RETURN key. When you type in the characters they are put into a place called the keyboard buffer, where they are held until RETURN is pressed. The keyboard buffer can hold only so many characters. The ping is the ORIC method of warning you that its keyboard buffer is getting full.

28 Chapter 2

LOWER CASE LETTERS

The keyboard on the ORIC, as with most computer keyboards, is similar in operation to that of the standard typewriter. So far, however, it has worked like a keyboard with the 'capitals lock' set. The alphabetic keys have given capital letters when pressed and the SHIFT keys have not affected them.

To remove capitals lock press CTRL and T simultaneously.

The message CAPS, at the top right hand corner of the screen disappears and pressing an alphabetic key gives the lower case (small) letter; pressing the same key with SHIFT gives the upper case (capital) letter.

You would work with CAPITALS LOCK OFF if, for example, you were using the ORIC for typing a letter. Normally, however, you will be working with capitals lock on, as any instructions you give to the computer must be in capital letters.

To put capitals lock back on press CTRL and T simultaneously again.

CONTROL CHARACTERS

In the previous chapter, and above, we have used the CTRL key, pressed along with another key, to make the computer do various things such as clearing the screen, switching the key click on and off, switching capitals lock on and off and so on. Pressing CTRL with another key generates what is called a control character. We will look at control characters again in chapter 7.

In the remainder of this book I will indicate a simultaneous CTRL and other key depression in the form CTRL A, CTRL C etc. CTRL A means that keys CTRL and A are pressed simultaneously.

I shall start by listing the control characters with a brief explanation for reference. Where necessary I shall then give more details. Don't worry if you don't understand some of the explanations right now. We shall look at them again in later chapters.

The Key to Success

CTRL A -copies screen characters to keyboard buffer. CTRL C -—stops a program loop or scroll.

CTRL D - -—causes double print (on/off toggle).

CTRL F -—controls key-click (on/off toggle).

CTRL G = -causes a 'ping'

CTRL H -—moves cursor to left.

CTRL I moves cursor to right.

CTRL J = -— moves cursor down.

CTRL K -—moves cursor up.

CTRL lL -clears the screen.

CTRL M_= ~-acts like the RETURN key.

CTRL N= -—hides a line.

CTRL O -—hides any subsequent screen output (on/off toggle). CTRL P -—controls printer (on/off toggle).

CTRL Q = —hides cursor (on/off toggle).

CTRL S -—hides the screen output (like CTRL O). CTRL T -—controls capitals lock (on/off toggle).

CTRL X -—removes a line from program memory.

a ee affect background and foreground colours for Cini t the rest of the line.

CTRL J -—allows printing in the far left column.

30 Chapter 2

CTRLA

This control character is used _ in_ editing. That is changing the contents of the computer's 'memory'. We will look at its use in detail later in this chapter.

CTRL

This is the 'break' or 'stop' character for the ORIC. You will see it in use throughout this book.

CTRL D

This causes double print. To see this happening key in CTRL D and then type in any message. CTRL D is what is known as an 'on/off toggle’. This means that if double print is 'off' CTRL D puts it 'on' and if double print is 'on' CTRL D puts it 'off'.

We don't want double print right now; so key in CTRLD again to put it off.

CTRL F, CTRL G, CTRLL

You have used CTRLF and CTRLL _ in_ the © previous chapter and they should be familiar to you. CTRLF is an on/off toggle. The description of CTRL G is (I hope) self explanatory.

CTRL H, CTRL I, CTRL J, CTRL K, CTRL M

These control characters are seldom (if ever) used as direct keyboard entries. It is easier to use the cursor control keys, and RETURN which perform the same functions. The use of control characters not gener- ated by keyboard entries is dealt with in Chapter 7.

CTRL N

If you use this after you have typed in a command then that command will disappear from the screen. However the command will still be carried out if you press RETURN.

The Key to Success 31

CTRL O

This toggles information which would normally be displayed on the screen to the printer.

CTRL S

If you set CTRLS, characters entered from the keyboard are not displayed on the screen. A possible use is for 'secret' messages or for applications where entries might spoil a screen display. CTRL S is an on/off toggle.

CTRL Q

You used CTRL Q in chapter |. The flashing cursor can detract from screen displays and it is useful to be able to get rid of it. CTRL Q is an on/off toggle.

CTRL T

This has been already dealt with in this chapter. CTRLT is an on/off toggle.

CTRL X

This cancels the keyboard entries to its left. It can be useful when keying in 'programs' see later in this chapter.

CTRL Z, CTRL I

These can affect both background and foreground colours of print lines on the screen, and can have a range of other, rather odd, effects depending on which key is pressed after the control character has been keyed in. What these control characters are, in fact, doing is to prepare for some of the machine's 'attributes' which we will look at next. CTRL Z and CTRL are not particularly useful, but it is interesting to play with them and see the odd effects they can produce.

CTRL J

We will look at this character after we have discussed attributes.

32 Chapter 2

ATTRIBUTES

If some of the things we can do with the CTRL key seem weird and wonderful, they pale into insignificance beside the very odd effects we saw when we used the ESC key.

The effect the ESC key has is determined by which key is pressed directly following it. What the ESC key does is to prepare the computer to put something called an attribute into the next free charac- ter space on the screen. The key following the ESC key determines which attribute is placed in this space.

The space on the screen into which the attribute is put is left blank. The attribute determines a characteristic of all the characters printed to its right on the screen, until the end of the line or another attribute is reached, There are a number of methods of putting attributes on the screen (or to be more exact into that section of the computer's memory which controls the screen). Here, however, we are considering direct keyboard entries, and so we will look at ESC key entries.

The ESC key has no effect by itself. Its effect is determined by the key pressed next (compare the CTRL key which needs a_ key pressed with it), When I talk of ESC and a key (say for example ESC and A) below I mean the ESC key followed by the key mentioned.

I shall first summarise the effects of ESC key entries and shall expand on the summaries where necessary.

The Key to Success

ESC and @ black foreground (ink).

ESC and A - red foreground.

ESC and B green foreground.

ESC and C yellow foreground.

ESC and D blue foreground.

ESC and E magenta (purple) foreground.

ESC and F cyan (light blue) foreground.

ESC and G white foreground.

ESC and H - single height, steady, standard characters. ESC andI -— single height, steady, alternate characters. ESC and J double height, steady, standard characters. ESC and K double height, steady, alternate characters. ESC and L -— single height, flashing, standard characters ESC and M single height, flashing, alternate characters. ESC and N double height, flashing, standard characters. ESC and O double height, flashing, alternate characters. ESC and P black background (paper). ESC and Q red background.

ESC and R green background.

ESC and S yellow background.

ESC and T blue background.

ESC and U —- magenta (purple) background. ESC and V cyan (pale blue) background. ESC and W white background.

34 Chapter 2

BACKGROUND AND FOREGROUND

These terms are (I hope) self explanatory. You can use foreground and background attributes at the beginning of a row to set ink and paper colours and in the middle of the row to change these colours.

CTRL J

An attribute normally takes up a character position. Thus when we are entering text normally the first two characters of each line are reserved for attributes. If you wish to print in the two far left hand columns on the screen CTRL J allows you to do this. CTRL 1 is an on/off toggle.

FLASHING AND STEADY

If a line of text is preceded by a flashing attribute, it will flash ie change from background to foreground about three times per second. Text not preceded by a flashing attribute will remain steady in fore- ground colour. ESC followed by L, M, N and Q insert flashing attributes.

STANDARD AND ALTERNATE CHARACTERS

As well as the normal characters (A,B,C, ... 1,2,3, etc) ORIC has an alternate character set. These are a collection of shapes which can be used to form pictures, such as for example the train we typed in in Chapter 1. We will be looking at this character set in detail in Chapter 12.

ESC followed by I, K, M and O insert alternate character attributes.

The Key to Success 35

DOUBLE HEIGHT CHARACTERS

The effect of the double height attributes varies depending on the line on the screen in which they are used. If a double height attribute, for example, is put in the very top line (line zero) you will get the lower half of the double height character you type in.

For example if you type in 'A' you will get 'f}', if you type 'C' you will get 5

On the other hand if the double height attribute is on the next line down

(line 1) you will get the top half of the double height character you type in.

For example if you type in 'A' you will get '¢)'; if you type in 'C' you will get 'f"'.

CAPS

. LAPS PRIS LL EP ILS e

ADPNCCHUT 1 MRINDROCTH IVY STOR d FOO

This continues all the way down the screen. You will get bottom halves on lines @, 2, 4 etc and top halves on lines 1, 3, 5 etc.

36 Chapter 2

Thus to get a double height message you first type the message on an odd numbered line with a double height attribute, and then type the same message on the next line down, again with a double height attribute. The top half of the message on the upper line then joins up with the bottom half on the lower line to give a double height message.

Typing in a message twice, however, is a bit much like hard work. There must, you would think, be an easier way. There is! Remember the rather 'odd' effect of CTRL D. The message typed in with this control character set appears on two lines at once just what you want for double height print. Thus to get double height print, set CTRL D, then insert a double height attribute using ESC followed by J (static, standard characters) or K (static, alternate characters), or N (flashing, standard characters) or O (flashing, alternate characters). When the double height control character is set the attribute will control both lines. Double height attributes also force a black background; so make sure you set a foreground colour other than black. Otherwise you won't see the message.

Also make sure you start at an odd numbered line. Otherwise the effect can be most peculiar.

MU Fb LU Wie T OCC TAD

The Key to Success <6

60Hz ATTRIBUTES

Some attributes will upset your screen display, because they are designed to work with American 60Hz television sets. Avoid following ESC WIth MGV 5 E57 4152 or}.

CHAPTER 3 Enter the ORIC

@ 19 PRINT 1

°

ENTERING PROGRAMS

In Chapters 1 and 2 you 'keyed in' some 'commands'. In plain English this means you pressed a few keys and this made the computer do something.

Once the computer had done what you had told it to, however, it forgot the command. To get the computer to repeat the action you would have to type in the same keys all over again.

A command which the computer executes immediately and then forgets about is called an 'immediate' command.

38

Enter the ORIC 39

Let's try something different; first clear the screen using CTRL L, then type in:

16 PRINT 1

and press the RETURN key. You don't have to insert a space before and after PRINT, although it makes no difference if you do.

The screen should now look as follows:

Type in RUN and press the RETURN key the number '1' will appear on the screen. If instead you get the message 'SYNTAX ERROR' repeat the whole procedure (starting at the top of the page) again.

Now here's the trick type in RUN followed by the RETURN key again. And again you get the number 1. The computer has remembered the

instruction, and will continue to do so until either you delete or change it, or until power is switched off.

40 Chapter 3

By numbering the instruction you have caused the machine to store it in memory. The instruction is therefore no longer an ‘immediate’ com- mand, but is now a 'program' command. Programs consist of instructions with line numbers. The computer stores these instructions and 'executes' them (carries them out) each time the program is RUN.

You have just entered and run your first program.

LINE NUMBERS The numbers at the beginning of the program lines do not only define the instructions in these lines as program instructions. They are also one of the factors determining the order in the instructions are carried out. You already have the line: 1p PRINT 1 Type in: 5 PRINT 3 and press RETURN. Type in RUN followed by the RETURN key to run the program.

You will see that the screen now displays the results:

b ]

Line 5 is carried out before line 19, even though it was entered after it. Type in LIST, followed by the RETURN key.

The two lines you have entered will now appear on the screen:

5 PRINT 3 19 PRINT 1 Z “” This is what is know as a 'program listing'. You will see that not only is line 5 'executed' (carried out) before line 10, it is also listed before it

Enter the ORIC 41

ENTERING PROGRAMS

When you are typing in programs there are some points to note. You may have noticed that you did not need to put a space between the number at the start of the line (the 'line number') and the instruction which follows it. When you listed the program ORIC put the spaces in for you.

When you finished typing in a line you pressed the RETURN key. This 'terminates' (finishes) the line and 'enters' it into 'program memory! so that the machine remembers it and carries out the instructions when 'RUN!' is entered. Remember to press the RETURN key after typing in each program line throughout this book. If you make a mistake while typing in a line you can use the DEL key to delete it. If you get completely lost, however, press CTRL X to cancel the whole line and start again. EDITING LIST the program again. The screen should now read:

LIST

5 PRINT 3

PRINT 1 Suppose we want to change line 19 to:

19 PRINT 4 There are two methods of doing this: 1. Enter the whole line again.

2. Edit the line.

For a line as short and simple as line 19 the first method is the easier. Simply type in

19 PRINT 4 and press RETURN.

You will see that the previous line 19 has been replaced by the new line 1p.

42 Chapter 3

Suppose you want to change line 5 to: 5 PRINT 3+6

This time we will use the EDIT facility. To edit a line we must get the cursor to the start of that line. You could use the cursor control keys to move the cursor up to line 5. It is, however, rather too easy to get lost among all the print on the screen if you try to EDIT a line in place. It is much safer, at least until you have gained more practice in EDITing, to move the line you want down to a space below the other printing. To do this type in:

EDIT 5 followed by RETURN.

Press CTRL A and see how the cursor moves along the line. Remember that earlier I mentioned that keyboard entries go into a store called the keyboard buffer which holds them until the RETURN key is pressed. Well, moving the cursor over a character on the screen puts that character into the keyboard buffer just as if it had been entered via the keyboard.

Thus if you use CTRL A to move the cursor across line 5 until it is in the space to the right of the last character as below

5 PRINT 3

then the keyboard buffer will hold '5 PRINT 3' just as if you had typed it in.

Type in +6. This will appear at the end of the line so that it reads: 5 PRINT 3+6 9

The additional entries have also gone into the keyboard buffer. This buffer now holds all the required characters so press RETURN.

Enter the ORIC 43

To check that this has worked clear the screen and LIST the program. This should read:

SPRINT 3+6 19 PRINT 4

Suppose you want to edit a line so that part of it is missed out. You can do this by careful use of CTRL A and the cursor control keys.

Moving the cursor over a character on the screen with CTRL A copies that character into the keyboard buffer. Moving the cursor over a character with the cursor control key does not copy that character into the keyboard buffer.

For example, suppose you want to change line 5 to:

5 PRINT 6

that is taking out the characters '3+',

44 Chapter 3

Move the cursor to the left of the line. If you wish you can use EDIT 5 as before, or you can simply use the line 5 already on the screen.

Move the cursor across the line using CTRL A until it is over the character '3'. This means that the keyboard buffer contains the characters:

5 PRINT

Use the right cursor control to move the cursor until it is over the character '6'. Because moving the cursor with cursor control does not copy characters into the keyboard buffer, the contents of the keyboard buffer will not be changed.

Finally use CTRL A to move the cursor over the character '6'. This copies this character into the keyboard buffer, which holds:

5 PRINT 6 This is what we want; so press RETURN. Clear the screen and LIST the program. This should read:

5 PRINT 6 19 PRINT 4

Caution when you are changing something in the middle of a line it is very easy to forget to copy the rest of the line with CTRL A. Please watch out for this error.

Hang on to your hats we are coming to the hard bit!

Suppose you want to insert some characters in the middle of a line without removing any which are there already. At first sight this is not easy when you type in the new characters you obliterate other characters in the line. Again the secret is in the use of the cursor control keys as well as CTRL A.

This is best explained by an example. Suppose we want to change line 19 to:

IP PRINT 14344

When inserting characters into a line you need a bit of clear screen to work on— so use the EDIT facility.

Enter the ORIC 45

Type in EDIT 19 followed by RETURN. Line 19 should be: 19 PRINT 4

Move the cursor over the line with CTRL A until it is over the character 1A!

Move the cursor down one line with the cursor control key and type in:

1+ 3+ Because moving the cursor over screen characters with CTRL A and typing them in has the same effect that is to put them in the keyboard buffer the keyboard buffer will contain

1p PRINT 1+3+ Move the cursor up and to the left using the cursor control keys until it is again over character '4'. Use CTRL A to 'copy' this character into the

keyboard buffer, which now contains:

19 PRINT 14+3+4

46

Chapter 3

This is what we want so press RETURN.

Enter the ORIC 47

Clear the screen and LIST the program. This should now read

5 PRINT 6 IP PRINT 14+3+4

RUN the program (type in RUN and press RETURN) to get the output: 6 8

The use of CTRL A is a powerful method of EDITING. It means you can make up a program line by copying anything on the screen. It is, however, a fairly difficult method to get used to, especially as you cannot see what is in the keyboard buffer while you are EDITING.

Don't worry if you get lost at first a bit of practice and you will soon get the hang of it. Check your EDITING by clearing the screen and LISTING the program.

Caution if you get really lost while EDITING a line remember to use CTRL X to cancel your entry. If you press RETURN you will probably end up with a 'nonsense' line and be worse off than when you started.

If you change the line number when you EDIT a line then you will create a new line and will not alter the line you started with. This is a useful method of creating new lines whose content does not differ greatly from existing lines.

Again this is best seen from an example. Suppose we wish to add to our existing program the line:

26 PRINT 1+3+6 Use the cursor control keys to move the cursor to the start of line 19 and type in the character '2'. This will overwrite the 'l' and the

cursor will be over the character 'f.

Move the cursor along the line using CTRL A until it is over the final character '4'. Type in a'6'.

The keyboard buffer now holds the characters 20 PRINT 14+3+6

This is what we want so press RETURN.

48 Chapter 3

Note that line 19 is not altered. We used its display on the screen to create line 2 but this does not alter line 1f in program memory.

Line 19 would only be changed had we kept that line number unaltered while editing.

Clear the screen and LIST the program. This should read:

5 PRINT 6 19 PRINT 14+3+4 20 PRINT 14+3+6

RUN the program to get the output

6 8 1p

Note When you are editing a program line after using the EDIT command you may find the cursor is not at the start of the line. This happens when the line takes more than one row on the screen, especially with the V1.f@ machine. Use the cursor control keys to position the cursor before editing.

LINE NUMBERING

You will rembember that the very first line you entered had line number 19, rather than line number 1. Possibly you have already realised why this was done. It let you insert a line before line 19. Usually we number lines in steps of ten (19, 20, 30...), so that if additional lines are required they can easily be inserted.

DELETING A LINE

If you wish to delete a line in a program type in the line number followed by RETURN.

For example type in 5 and press RETURN. Clear the screen and LIST the program.

Check that line 5 has disappeared.

Enter the ORIC 49

As a double check, RUN the program to get the output:

8 1p

NEW

We have finished with the program; so we shall see how to get rid of it. We could delete it a line at a time, but there is an easier way.

Type in NEW and press RETURN. Clear the screen and LIST. The program has gone nothing is LISTED.

The NEW command is used to clear away any program in memory and give the programmer a 'clean slate’,

Take care when using this command. Make sure you really do want to clear all the program memory.

A DIVERSION

You have been working very hard with EDIT, and I hope you didn't get too bored. Before we go on we shall have a little fun. Type in this program. Remember to press the RETURN key after each line. Don't worry about understanding it at this stage.

19 PAPER $@:INK 3:CLS

20 REPEAT

34 PRINT: PRINT: PRINT: PRINT

4f INPUT"WHAT IS YOUR NAME"; A$

50 IF A$="ANNE" THEN A$="FATSO"

60 PRINT CHR$(12)

70 PRINT CHR$ (4);SPC (19); CHR$(27);"JHELLO ";A $ 84 PRINT CHR$(4)

99 UNTIL 9

Line 7 will take up two lines on the screen but this doesn't matter.

RUN the program. Type in your name when requested, followed by RETURN.

50 Chapter 3

HELLO GILES

WHAT IS YOUR NAME?

The result of typing in 'ANNE' (followed by RETURN) is interesting. This, as you may have quessed is my wife's name, but I am quite safe as she never reads my books! Try changing line 5f to suit your own circumstances.

I apologize to any of my readers called Anne. I don't mean you honest!

Enter the ORIC 51

BREAK

Once you have grown tired of the program you will want to stop it. You may remember that I mentioned CTRL C in the previous chapter and said you would use it throughout the book. This is the first example. Break from the program CTRL C when the computer

asks for your name. Don't delete the program just yet, as we will be using it in the next chapter.

= a P [‘ ° OEt = oo

CTRL

Sse ee ee os SS os

CTRLC To break from program

CHAPTER 4 Loading and Saving Programs

I have put this chapter near the beginning of the book quite deliberately. Why, you will probably ask, learn to save programs on tape before learning how to write them? There are two reasons:

1 Keying in even small programs all the time is tedious, and leads to error. You should get into the habit of saving anything you want to use later as soon as you have 'debugged' it (got it to work). Thus you don't have to debug it several times over. It is useful to save even faulty programs if you are interrupted in the middle of debugging them.

52

Loading and Saving Programs 53

2. There are a number of excellent commercial program tapes avail- able for the ORIC. You will soon be writing your own programs, but that should not prevent your purchase, use and enjoyment of professionally written software.

CASSETTE RECORDER

You will need a cassette tape recorder. You may decide to use one you already have, or you may purchase one especially for use with the ORIC.

You do not need an expensive recorder with stereo or tone control. If you have these facilities then adjust the balance to give single channel recording and the tone control to give maximum treble and minimum bass response.

You will find a tape counter extremely useful. In fact I would go so far as to say that if your present machine does not have this facility you should seriously consider purchasing a machine which does.

The cassette connector at the back of the ORIC consists of a round, seven hole socket known as a DIN socket. The connector on your tape cassette recorder could be one of the following:

1 a 3 hole DIN socket;

Z a 5 hole DIN socket;

as two jack sockets marked EAR and MIC;

4 any of these plus a motor control socket.

If your recorder has a three or five hole DIN socket then use the 3 pin to

3 pin DIN connector provided with your machine. Do not use a 5 pin connector.

If you have any other connector on your recorder, then obtain advice from your computer retailer. Motor control (automatic start and stop) is a useful feature and the ORIC provides switching for this. Be careful some tape recorder motors are too powerful for the ORIC to control. Again your computer retailer should be able to advise you.

U0O-E

04 Chapter 4

Cassette Recorder

N.B. If pins 4 & 5 are present, ensure they are not shorted together.

1. Tape out

2. Ground

3. Tape in

4,5. External Speaker 6, 7. Motor Control

ORIC

DIN Connectors CASSETTE TAPES

ORIC programs are saved on ordinary audio cassettes the same cassettes that you would use for recording music. I always pay that little extra for good quality low noise tapes, which, in my opinion, give a worthwhile increase in reliability. You may prefer to use the very short tapes (C1@ or C15) stocked by computer retailers. These can save time when it comes to finding programs on tape.

TECHNICAL TERMS

When I talk about Saving a program I mean recording the program, which is in the computer's program memory, on to cassette tape.

When I talk about Loading a program I mean 'reading' the program from the tape cassette and putting it into the computer's

Loading and Saving Programs BD

program memory. That is to say putting back into the computer's memory a program which has been saved onto cassette tape at some earlier time.

CSAVE

To save a program to tape cassette, ORIC uses the command CSAVE (which is short for Cassette Save).

We are going to save on to tape the program which we typed in in the previous chapter. If you switched the computer off between chapters, then I am afraid you will have to type the program in again.

Put a new cassette in the recorder and rewind to the start. Set the tape counter to zero.

Use the 'fast forward' control to feed on the tape until the counter is at about #75. This ensures that you do not try to record on the tape leader (the plastic bit at the start of the tape).

Make sure the lead. between the computer and the tape recorder is not near the power leads or the lead to the television. Otherwise it could pick up interference from these leads.

To save a program you have to give it a name. This name can be anything you wish provided it is not more than seventeen characters long (V1.8 machine) or sixteen characters long (V1.1 machine). Let's call our first program DEMO1.

Type in CSAVE "DEMO1", S

Start the tape recorder recording (if your recorder has an automatic start you may not need to do this) and press RETURN.

After a few seconds the message 'Saving DEMO1' (or 'Saving DEMO1 B') should appear at the top of the screen. When saving is complete the word 'Ready' appears on the screen. Stop the tape recorder.

CLOAD

Use the NEW command to clear the program memory. We are going to see how to get the program back from tape into the computer. To do this the ORIC uses the command CLOAD (short for Cassette Load).

56 Chapter 4

Wind the tape back until it is at a tape counter number just less that that at which you started to save (fff will do nicely in this case). Type in CLOAD"DEMO1",S taking care that the name DEMO1 is exactly the same as the name used when saving spaces do matter here.

Press RETURN and start the recorder playing. The message ‘Searching .. should appear at the top of the screen, followed by the message ‘Loading DEMO1' (or 'Loading DEMO] B') when the start of the program is detected. When loading is complete the word 'Ready' will appear on the screen. Switch off the tape recorder and RUN the program.

CASSETTE RECORDER PROBLEMS

If the word 'Ready' does not appear try CLOADing again at different volume settings on the tape recorder, remembering to rewind the tape before each attempt. You may need to press the reset switch under the computer to get the machine out of 'searching' mode. If your recorder has EAR and MIC sockets of the same size try changing the connections round.

You may get the error message 'FILE ERROR LOAD ABORTED' when you try to load. This at least indicates you have something on your tape.

If you still have no success, try saving a smaller program. Type in

1NPRINT 1

and press RETURN, then go through the saving procedure, clear program memory and try to reload.

If there is still no success try playing the recorder without the computer attached.

If there is nothing on the tape then there could be a fault in your connector or tape recorder. Test the recorder by recording something other than a computer program.

If you get a rather loud, unpleasant, high pitched noise then you have a program (or something very similar) on tape. The recording head of your tape recorder may be out of align- ment. Please refer to the maker's instructions for adjusting this.

Loading and Saving Programs 57

SLOW AND FAST

Let us, however, assume that nothing has gone wrong and you have recorded the program sucessfully. You probably wondered what the 'S' in the CLOAD and CSAVE commands is for.

When a computer saves information to or loads it from a tape it does it at a certain speed. This is nothing to do with the speed at which the tape moves, which remains constant; it is the speed at which information is sent down the line between the computer and the recorder. This is known as 'the baud rate’,

The ORIC has two baud rates. You have saved and loaded a program at 300 baud, which is a fairly slow rate. The 'S' in the command stood for 'slow'.

The ORIC can also save and load information at 2409 baud 8 times as fast. This saves you time, and also means that you get 8 times as much information on your tape.

The catch is that, because the information is packed so densely on tape, the slightest flaw in the tape or in the information on it can lead to a 'bad' program ie. one which will not load. 3% baud is much more reliable than 2409 baud. At the faster speed the alignment of the recording head and the volume setting of the recorder are much more critical.

To save the program at normal speed, wind your tape onto a fresh section (say tape counter number (#30) and follow exactly the same procedure, except that the command you use is:

CSAVE "DEMO1" followed as usual by RETURN. Test that your program has been saved by loading it back into memory. Again the procedure is the same as before, except that the command you use is:

CLOAD "DEMO1"

You may find you need several attempts to get the best volume setting before the program will load.

A program must be loaded back at the same speed (30% or 2469 baud) at which it was saved. Otherwise it will not load.

58 Chapter 4

VERIF YING PROGRAMS

It is convenient to be able to check that a program has been saved

correctly while that program is still held in program memory. The V1.1

provides the verify feature which allows ORIC to compare a program on

tape with one in memory without corrupting the program in memory.

A special form of CLOAD command is used to verify. This is: SOA eae

OF (CLR a oVgo

depending on whether the program you are verifying has been saved at 2400 or 349 baud.

This is best explained using an example. You should have DEMO] saved at slow speed at the start of your tape. You should also have DEMO] in program memory if not load it in. Wind the tape back to start. Type in:

CLOAD"DEMO1",V,S press RETURN and play the tape.

You should get the message 'Searching! as before, followed by 'Verifying DEMOI1 B'. When the message:

# Verify errors detected Ready

appears on the screen then stop the tape. You have verified that the program on tape is the same as that in program memory.

If your verification fails (i.e. you get a non zero count of verification errors) then adjust the volume on your cassette recorder and try again. If you still cannot verify make sure your machine is not version V1.0. Only version V1.1 has verify.

If you managed to save DEMO] at the faster speed, try verifying that save also. Use:

CLOAD"DEMO1",V

Loading and Saving Programs 59

The V1.1 machine will also accept

CLOAD YY V 55 and CLOAD"",V These commands check the content of program memory against the first program that they find on tape. JOINING PROGRAMS Large programs are often made up of a lot of small programs joined together. The V1.1 machine lets you join a program held on tape on to a program held in memory. Note this does not work on the V1.§ machine. Again this is best illustrated by an example. Clear program memory by typing in NEW and pressing RETURN. Wind the cassette tape on so that you are not overwriting anything you have saved. Key in the program:

199 PRINT"SEE HOW THEY RUN" RUN this program and get the message

SEE HOW THEY RUN on the screen. Save this to tape as DEMO1A. Verify that it has been saved correctly. Clear the program memory and enter the program:

1g CLS

20 PRINT

3@ PRINT

4f PRINT" THREE BLIND MICE"

50 PRINT RUN the program. You should get the message:

THREE BLIND MICE

on the screen.

60 Chapter 4

Wind the cassette tape back to just before the start of program DEMOIA. Key in:

CLOAD"DEMOIA", J or CLOAD"DEMOIA",J,S

depending on whether you saved DEMO1A at normal or slow speed. Play the tape.

When loading has fininished (Ready appears on the screen), LIST the resulting program.

You should get:

1g CLS

24 PRINT

39 PRINT

4g PRINT" THREE BLIND MICE" 50 PRINT

199 PRINT"SEE HOW THEY RUN"

RUN the program to get the message: THREE BLIND MICE SEE HOW THEY RUN DEMO1A has been joined on the the program in memory. Caution. When joining two programs together make sure that none of the lines in the second program has

the same line number as any of the lines in the first program. Otherwise the resulting program will not work correctly.

Loading and Saving Programs 61

FINDING PROGRAMS

When you save a program on to tape, always write down the name of the program, the tape counter reading at which it starts, and whether it was recorded at normal or slow speed. This information can be kept with the cassette. Most tape cassettes come with a card on which contents can be recorded.

If you do not know where a program is on a tape, but do know its name, then the CLOAD command with the name specified will cause the computer to ignore all other programs and only load the program of that name.

For example, suppose you know a program called HIDEANDSEEK is somewhere on a tape and that this program was recorded at 3ff baud. To find this program you would rewind the tape to the start, key in:

CLOAD"HIDE ANDSEEK",S

and press RETURN. If you then play the tape the computer will ignore all the programs until it comes to the one called HIDEANDSEEK, which it then loads into memory. The V1.1 machine will indicate at the top of the screen anything else (e.g. other programs) found on tape while it is searching for the named program.

If, on the other hand, you know where a program is, but have forgotten its name then the command

CLOAD" (or CLOAD!", S)

will cause the computer to load the first program it comes to on the tape into computer memory. Note there is no space between the inverted commas.

AUTOMATIC START

When you loaded DEMO1] into the computer, you had to type in RUN, followed by RETURN, to start the program. It could be convenient to have the program start as soon as it loaded. To do this we add

'AUTO! to the CSAVE command when saving the program.

If DEMO] is not in computer memory then load it in.

62 Chapter 4

Save it again, this time using the command: CSAVE"DEMO1",S, AUTO

if you are saving at 309 baud and CSAVE"DEMO1", AUTO

if you are saving at 2490 baud.

Reload the program in the normal way. It should now start as soon as it is loaded.

SAVING MEMORY BLOCKS

We have discussed saving programs held in what we have described as 'program memory'. The ORIC has different areas of memory which it uses to store various types of information. For example there are parts of the memory which control what the computer puts on to the screen, while other parts may be used for programs or data.

It is possible to save the information held in specified sections of memory on to tape and to load this information back into these sections later. We will look at this further in Chapter 14.

SAVING LONG PROGRAMS

There are few things more annoying than keying in a long program say from a magazine and losing it due to a power failure or because the computer will not save it. ORIC hasn't done this to me yet, but most other computers have! The way to avoid the horrible sinking feeling of seeing two hours' work disappearing into thin air, is to save the program every (say) twenty lines, so that if the mains supply 'hiccups' at line 2099, you have lines 19 to 1800 safely on tape.

Unless you have shares in the company which makes it, you won't want to use fresh tape each time you save the same program. Normally you would rewind the tape each time and use the same section of tape for each save.

If you are the cautious type you will probably have visions of the power supply ‘hiccup! occurring halfway through saving lines 19 to 2000, so that not only is the program lost but the previous save of lines 19 to 189% is also obliterated. To avoid this and it can and does happen we use the 'back up! principle.

Loading and Saving Programs 63

This involves saving lines 1 to 209 on one part of the tape, lines 19 to 409 on another, lines 19 to 69% on the first section (overwriting lines 19 to 209), lines 18 to 8% on the second (overwriting lines 19 to 409) and so on. In this way, even if a disaster does occur during a save operation, you never lose more than 29 lines of code.

MORE DIVERSIONS

You know how to use the keyboard and how to save and load programs. The best way to make sure you remember what you have learned is to get in a bit of practice. Here, therefore, are two programs for you to key in, save and RUN.

As before I shall ask you to take these on trust, and treat them just as a bit of fun.

DEMO2

This program demonstrates ORIC's colour capabilities. I suggest you name it DEMOQ2 when you are saving it.

RUN the program by typing in RUN followed by RETURN. Break with CTRL C. The program '‘hides' the cursor to improve the display. You can get it back with CTRL Q, after you have broken the program.

19 CLS:PAPERI

206 FOR N= TO 7

39 PLOT8,5+N,23-N

49 PLOT28,5+N,17

5d READ A$

60 PLOT19,5+N,A$

70 PLOT9,5+N,N

84 NEXT

99 PRINT CHR¢$ (17)

199 GOTO190

119 DATA BLACK ON WHITE 120 DATA RED ON CYAN

134 DATA GREEN ON MAGENTA 149 DATA YELLOW ON BLUE 156 DATA BLUE ON YELLOW 168 DATA MAGENTA ON GREEN 178 DATA CYAN ON RED

189 DATA WHITE ON BLACK

64 Chapter 4 DEMO3

I suggest you name the next program DEMO3. I find this program very useful as I have a six year old son who uses it as homework practice. Break from the program with CTRL C, get back to single print with CTRL D, and restore the cursor with CTRL Q.

When you are keying in the program you will find that lines 89, 109

119 and 12 take up two lines on the screen. This does not affect the program.

19 PRINT CHR$(17) 20 X%=RND(1)*11+4 16 30 Y%=RND(1)*94+1 4f PAPER @:INK 3 50 PRINT CHR$ (12) 60 FOR N=#TO7 70 PRINT:NEXT 84 PRINT CHR$ (4); CHR$(27)3"J"3 SPC (13); X%- Y%3"4 "3 V%s"= "3 99 INPUT A$ 199 IF VAL (A$)=X% THEN 119 ELSE EXPLODE: PRINT CHR$(4):GOTO 54 119 PRINT:PRINT:PRINT:PRINT CHR$ (27); "J"3SPC (18);"CORRECT" 126 FOR N=@ TO 9:ZAP: WAIT 5:NEXT:PRINT CHR$(4):RUN 24

CHAPTER 5 Exploring ORIC

TS = _ to Cy! ¢g

EERE eee eee ee = BERR eee eee ee sf eee eer rege és! EER Ree eee ee 2 ce VO

\

ea _ 0—

GENERAL FEATURES

In this chapter I am going to describe some of ORIC's features of Operation and some very useful instructions, which you will see in many computer programs. I shall keep my explanations brief at

this stage and shall give more details of some of these features and instructions at the appropriate stage.

65

66 Chapter 5

Type in NEW and press RETURN to clear program memory. If you wish you may leave the computer with its present background and foreground colours. If you prefer to work with black ink on a white background then type in INK#:PAPER 7 and press RETURN.

REM

The REM instruction causes the computer to ignore everything (even instructions) which follows it until the end of the line is reached.

You may wonder what possible use there could be for an instruction which the computer ignores. The answer is that it is not just computers which read programs people read them too! It may not astonish you to learn that not every program works first time. The programmer has to correct errors to get the programs to work at all, and will probably return to the program at a later date to improve it. Please believe me (and I speak from long and bitter experience), this is much easier if REM statements are used to indicate what each section of the program is for.

This is a rather extreme example. You do not need to type it into the computer unless you are really keen.

19 REM THIS ILLUSTRATES THE USE OF THE REM STATEMENT. I HAVE FOUND THAT I CAN TYPE IN COMMANDS LIKE ZAP, PING, EXPLODE, PRINT 1 AND SO ON AFTER REM BUT THE COMPUTER IGNORES THEM. IF I WANT AN EXPLOSION I HAVE TOGO TO LINE AND TYPE-

26 EXPLODE

The REM statement may be put in the middle of a line after an instruction provided it is preceded by a colon (:).

For example: 19 PING:REM THIS MAKES A NOISE

If you are using the REM statement in the middle of a line you can replace all of :REM by an apostrope (').

For example:

19 PING' THIS MAKES A NOISE

Exploring ORIC 67

You can use this abbreviation only in the middle of a line, after an instruction. You can't use it at the start. For example:

19 'THIS GENERATES AN ERROR does just that!

Take care remember that everything after REM is ignored until you reach the end of a line.

For example: 19 PING:REM A NOISE: ZAP:REM ANOTHER NOISE

will only 'ping'. It will not 'zap' because everything after the first REM is ignored.

COLON (:)

We saw the use of the COLON in the last example. It allows you to put more than one instruction on the same line. This is especially useful in IF....THEN decision statements, which we will look at in Chapter 8.

STOP

Clear the program memory with NEW and clear the screen. Type in this program:

19 REM A DEMONSTRATION PROGRAM 20 PRINT 1 39 PRINT 2 4h PRINT 3 50 PRINT 4

RUN the program. Once it is complete type in: 35 STOP and press the RETURN key. Clear the screen and RUN the program

again. Note that now only the first two numbers are printed. The STOP command stops the program.

68 | Chapter 5

CONT Type in CONT, and press RETURN. - The program will continue from line 49 on to the end.

CONT is used to restart the program after it has met a STOP command. The program will restart at the first instruction after the STOP command. CONT may be used only as an immediate command. Do not use it in any program.

GOTO

GOTO in a program, followed by a line number, makes the computer go to that line and do what it says there.

Add this line to the previous program (don't forget to press RETURN after you have typed in the line).

60 GOTO

Clear the screen and RUN the program. As before it will print the first two numbers and STOP. Enter CONT (ie type in CONT and press RETURN). The program will print the next two numbers. Then it will go back to the start and print the first two numbers again.

The effect of the GOTO statement is to take the program back to the beginning after line 5f has been executed (carried out), so that lines 26 and 39 are executed again.

GOTO can be used as an immediate command rather than an instruction. This can be useful if you wish to start a program part way through. In the demonstration program given, try the effect of GOTO 39, GOTO 4, or GOTO 5f instead of RUN.

Note You can also use RUN 34, RUN 49 or RUN 59 instead of GOTO 3 etc in this case.

Exploring ORIC 69

INFINITE LOOPS Delete line 35 by typing in 35 and pressing RETURN. Clear the screen and LIST the program. You should get:

19 REM A DEMONSTRATION PROGRAM 20 PRINT 1 39 PRINT 2 49 PRINT 3 50 PRINT 4 60 GOTO 24

Study this program carefully. You will see that every time it gets to line 6 it will 'loop back' to line 2@. Thus the program will execute the instructions in lines 20 to 6 repeatedly. This is known as an infinite loop.

RUN this program to see the effect of the _ infinite loop. Stop the program with CTRL C.

70 Chapter 5

SCROLLING

The infinite loop caused the screen display to 'scroll'. This means that when the bottom line of the screen is reached, the next print on the screen will cause all the previous printed lines to move up one space. The printing on the top line disappears from the screen as a result of this.

Another example of scrolling occurs when we list a program which is too long to fit on the screen all at once.

Clear program memory with NEW and clear the screen. Type in this program:

19 REM THIS IS A SILLY PROGRAM 20 REM IT DOES NOTHING AT ALL 36 REM 4 REM 50 REM 60 REM 78 REM 80 REM 94 REM

119 REM 120 REM 130 REM 149 REM 150 REM 160 REM 176 REM 180 REM 198 REM 200 REM 219 REM 220 REM 234 REM 249 REM 258 REM 260 REM 270 REM 28 REM 299 REM 309 REM

Exploring ORIC 71

You will see that as you are entering the final few lines of this program the lines at the start are ‘'lost' from the top of the screen. Don't worry, the machine still has them in memory. The reason that the top lines are lost from view is that the machine can display only 26 lines of print on the screen at any one time.

When you LIST the program it will again scroll up the screen and the tep lines will be lost. In fact in this case the situation is even worse. Because the computer prints a line space and then the word 'Ready' on the bottom two lines of the screen two more lines are lost from the top.

To stop the scrolling so that you can look at the program listing, press the space bar. To start the listing scrolling again press any key (except SHIFT or CTRL).

If you wish you can list a single line on the screen. For example clear the screen and enter:

LIST 59 Line 5 should be printed on the screen.

Possibly more useful is the ability to list a section of the program say from lines 2% to 69. To do this clear the screen and enter:

LIST 20 - 60

CLS

We saw how to clear the screen by CTRL L. There is also an instruction to do the same thing. Type in CLS and press RETURN. CLS stands for 'Clear Screen’. Unlike CTRL L, CLS can be used in programs.

72 Chapter 5

FOR...NEXT

The FOR...NEXT loop, which will be covered more _ fully in Chapter 8, lets us repeat a process any number of times, with a different value at each stage. It is a quick way of checking the effect of different values without having to rewrite the program each time. The two lines

1) FOR N=A TO 3 190 NEXT N

would automatically repeat four times the program lying between lines 18 and 16% setting the value of N to 9, 1, 2 and 3 successively at each point in the program where N is mentioned. 'NEXT N' in line 189 may be abbreviated to 'NEXT'.

LET

The LET instruction is used to set one thing equal to another. When you are writing programs you will sometimes be using what are called ‘variables’, As the name_ suggests’ these are quantities which vary during the program. These variables are usually represented by letters.

At the start of the program a variable has to set to its ‘initial value' that is, the number it starts at (if this is not zero). This is one of the uses of the LET instruction.

For example:

LEE xed LET AEIGr +6

LET can also be used to set up a counter or to add two variables together. For example:

LET B=B+]1 LET C=N+M

Variables will be dealt with more fully in Chapters 8 and 9; so don't worry if you find this a little puzzling at this stage.

'LET' can be missed out and normally is in the assignment statement, so that instead of typing in'LET A=6' we can type in 'A=6'.

Exploring ORIC 73

WAIT

Another useful instruction is WAIT, followed by a number. This holds up the action for a time 'proportional to' that number, with WAIT 19 giving a delay of about one second, WAIT 59 giving a delay of half a second and so on.

INK and PAPER

You have used these instructions previously and I hope they are fairly self explanatory. INK, followed by a whole number between # and 7 (inclusive) sets the foreground or '‘ink' colour of text on the screen. PAPER, followed by a whole number between @ and 7 (inclusive) sets the background or 'paper' colour.

The numbers corresponding to each colour, for both INK and PAPER, are:

Number Colour p black I red 2 green 3 yellow 4 blue 5 magenta (purple) 6 cyan (light blue) 7 white

INK and PAPER are 'global' commands. If you specify a new INK colour, the colour of all the text on the screen changes. If you specify a new PAPER colour the entire background changes to that colour.

Take care not to make INK and PAPER the same colour. If you do you won't see what is printed on the screen.

74 Chapter 5

Clear program memory with NEW and type in this program:

19 FOR N=@ TO 7

20 CLS

30 PAPER N

4h INK 7-N

50 PRINT"PAPER "N,"INK "7-N 60 WAIT 260

70 NEXT

You don't have to type in spaces in this program. PAPERN, WAIT 2@¢ and FORN=@#TO7 work just as well. The spaces (I hope) make the program easier to read and understand.

RUN the program. It demonstrates eight different combinations of INK and PAPER colours. More combinations are available. Experi- ment until you find one that you particularly like. The PRINT instruction in line 5f will be explained in the next chapter.

You can now use the keyboard, enter, edit, list, save and load programs, change ink and paper colour, use some of the more common machine instructions. These last were chosen to provide you with 'tools' to explore and understand the more advanced features of the machine.

CHAPTER 6 The ORIC Display

Ay

QHOWINA pt TONIGHT : \ <—a

IMPORTANCE OF BEING

RIC

PRINT

The PRINT instruction is used to 'print' characters (letters and

numbers) on the television screen and not (as you might logically expect) on to printer paper.

75

76 Chapter 6

On its own, PRINT starts the printing on the screen on the first free line. It can be used as a direct command or as an instruction in a program.

PRINTING NUMBERS Printing numbers is very straightforward. For example PRINT 5

does just that (provided we press RETURN). The number appears at the start of the first free line i.e. the first line from the top of the screen which does not already have print on it.

Now try 26 The number 6 should appear at the start of the next line.

The question mark (?) is used as an abbreviation for PRINT. As PRINT is used a great deal in programs this abbreviation should save you a lot of typing.

Here's an interesting feature clear program memory and enter: 19?5

LIST this program and you will get: 1g PRINTS

ORIC lets you use the abbreviation when you are typing in programs, but gives you the unabbreviated instruction when LISTing these programs a good example of 'user friendliness’.

I shall use PRINT rather than ? throughout this book for the sake of clarity.

You may also have noticed that I didn't put a space between PRINT and 5 in the last example, whereas I did in the one before it. The space is optional PRINT 5 does the same as PRINTS. Sometimes inserting spaces as in the first of these examples makes your program listings clearer.

The ORIC Display a7

What if we want to print a number somewhere in the middle of a line? Try

PRINT 6 that is, pressing the space key a number of times before the 6. After entering it you will find the 6 printed exactly where it would have been without the spaces! This is because the PRINT command is designed to look for the first number and ignores the spaces. We will see how to deal with this shortly. PRINTING CHARACTERS Characters are a different matter. For example if we enter

PRINT A The computer prints a f at the start of the first free line. This means that the computer is looking for a number and not a letter. It thinks the 'A' is a variable, and because it has not seen

it before, assumes it has value zero.

The trick is to put any characters we want printed inside quotes 1.€.3

PRINT "A"

The 'A' should appear, again at the start of the first empty line.

STRINGS

Characters or numbers within quotes are called STRINGS. We will learn more about them in Chapter 9.

Experiment with different messages inside the quotes. Clear the screen every so often to get rid of accumulated rubbish.

PRINT "A SCREEN MESSAGE"

PRINT " LOTS OF SPACES "

78 Chapter 6

By using spaces we can move a message to any point on a line. The message can include numbers but not as part of calculations. Try the effect of:

PRINT "5678"

5678 is placed on the screen in exactly the same place as if "ABCD" had been the message. To see the different effects clearly try

PRINT 5+6 and PRINT "5+6"

Without quotes the program works out and displays the result. With quotes it displays exactly what is inside the quotes, neither more nor less, What we do instinctively, ORIC has to be programmed to do. The quotes around anything, whether numbers or letters, tell the micro that they are just a message or label equivalent to a house number or name to be printed exactly ‘as is'. We can include as many spaces in such a message as we like: a space is treated in the same way as a letter or a number if inside quotes.

PRINT SEPARATORS

We can also use spaces within quotes to place the result of a calculation where we want it on the screen. We could try:

PRINT ® followed by PRINT 5+6

But the separate PRINT commands just put the spaces and the result on successive lines.

The ORIC Display 79

SEMICOLON Now try: PRINT" "55+6

The semicolon is one of the so called print separators and here it tells the micro that the two items are to follow each other directly. In general a semicolon indicates that we have more than one item following PRINT, and that the items are printed consecutively (one after the other).

To save you time and memory space, ORIC makes the use of the semicolon print separator optional. Where two items are on the same program line ORIC will assume a semicolon between them.

The exception to this is when one number follows another. ORIC then requires semicolons to indicate where one number stops and the next one starts.

For example, compare: PRINT 1;2;3

and PRINT 123

When numbers are printed on the screen a space is left after the number (before and after the number in the V1.1 machine). This is not, however, the case with strings.

For example try:

PRINT "1'™2"3"1;2533"123" PRINT "al";"together"

If you wish to put spaces between strings then you must include the spaces in the strings, or use separate strings containing the spaces.

If you have a number followed by a string then you don't have to put a space at the start of the string, as there will be a space following the number. If, on the other hand, you have a string followed by a number you will require a space at the end of the string in the V1.0 machine. The V1.1 machine puts spaces both before and after numbers.

80 Chapter 6

Try a few examples to get used to the idea:

PRINT “ORIC™s” "ed

PRINT 19"GREEN BOTTLES"

PRINT "Please leave "33; "pints"

(in V1.1 machine PRINT "Please leave";3;" pints") PRINT "5+6="5+6

You will see from the third example that ORIC accepts lower case (small) letters in strings, although it does not accept them as commands (or as variables). CTRL T removes the capitals lock and lets you type in lower case letters.

let us try a letter standing for a number. As we have seen, a letter (or group of letters) set equal to a number is called a 'variabie'. Try:

A=19:PRINT A"Green bottles" A=1f:PRINT "A Green bottles"

The first line should have the intended result 19 Green bottles

and the second will be the silly statement A Green bottles

This confirms that the 'A' in quotes is treated just as a letter to be printed and doesn't stand for a number.

The semicolon may also be used at the end of a PRINT statement. This inhibits the line feed so that the next character printed is at the first free space in the current line on the screen instead of the start of the next line down.

This sounds complicated, but an example should make it clearer. Clear the program memory and type in

19 CLS

26 PRINT: PRINT: PRINT: PRINT 34 PRINT"COUNTER READS "; 4g FOR N=1TO9

508 PRINT N;

60 WAIT 190

70 NEXT

The ORIC Display 81

RUN this program, with and without the semicolons at the end of lines 30 and 59. If you have the V1.1 machine you do not need a space as the last character of the string in line 30.

Line 2# in this program is of interest. The instruction PRINT all by itself does not print anything on the screen, but moves the start of whatever is printed next down one line. To demonstrate this try altering the number of PRINT instructions in line 2@ rembering to separate them with colons. Try the effect of deleting line 26.

COMMA

The comma (,) may be used as a print separator.

The effect of this print separator depends on the version of the machine you have.

In the V1.6 machine The comma inserts three spaces between the items printed.

Remember, however, that when a number is printed a space is inserted by the comma, this gives a total of four spaces printed between numbers separated by commas.

Strings don't have extra spaces inserted after them; so a comma puts three spaces between strings.

The number of spaces between items is not affected by the length of the item.

If several commas are used together, each additional comma adds another two spaces.

In the V1.1 machine

The comma divides the screen into columns, each eight characters wide. Characters are not normally printed in the first two horizontal positions (f and 1), so that the comma separator starts items at positions 2, 19, 18 etc.

Numbers have spaces in front of them. If you use the comma separator with numbers, then the leading space before each number is printed at the start of the corresponding column. Thus the numbers themselves start at positions 3, 11, 19 etc.

82 Chapter 6

The number of spaces between items is affected by the number of characters in the items, as each item will start at the first free column. If an item is more than eight characters wide (including leading and trailing spaces for numeric items) then it will take up two or more columns. If several commas are used together each additional comma causes a full column width of spaces.

Whatever version of machine you have, try these examples:

PRINT 1,2,3

PRINT wAN ; Nt ; ncn

PRINT "A",1,"B"

PRINT 1684,3,18 PRINT"HANDS","KNEES","AND","BOOMPSA","DAISY" PRINT 1,,2,,3

The comma, like the semicolon, may be placed at the end of a PRINT statement.

The ORIC Display 83

Clear program memory, type in and RUN:

1p CLS

26 FOR N=1 TO 199 30 PRINT N,

4h NEXT

wt

: CACA as G)tURINS IP SS Ee OU BUIGIPIRIN-H PENIS STMEN ahaha at sta ace ery

OOOO VIMO Bett:

ORCS GCh0L Gh Gh Re

6 1} 16 rai 26 wt 36: 4t $6: Se 61 os ri re SH Pe Ready |

The output obtained from this program on the V1.1 machine is shown. You can RUN the program on the V1.f machine but you will not obtain the neat 'tabulated' output.

While the comma separator in the V1.1 machine can be used to put items into columns it does not give us control of where these columns are placed on the machine. The TAB separator which works correctly only on V1.1 machines is rather more flexible.

84 Chapter 6

PRINT TAB ({n)..0.

causes the items following TAB(n), whether words or numbers, to start printing n spaces along the line. It is used to create tables of information in columns. We can use several TAB statements on one line provided each value of n is greater than the one before the program calculates how much farther it has to move to get to the next TAB value. As an example:

PRINT TAB(5)"FIRST"TAB(15)"SECOND"

will print the word FIRST starting at the Sth character position and SECOND at the 15th. Try changing the print positions to see the effects for example try to print the word SECOND starting at position 11 and then at position 19.

You will find that it will only print on the original line if the new TAB position is farther along than the last character printed, i.e. with five letters in the word FIRST the letter 'T' is printed at position 1%. To attempt to print another word (or number) starting at 19 would corrupt the original and so the word SECOND is printed instead at position 19 on the next line. Obviously we should do our TAB's in increasing order we cannot TAB backwards.

The ORIC Display 85

Clear program memory and type in this program. Compare the output obtained with that from the previous program. Don't worry about 'STEP' in line 20. We will come to this in Chapter 8.

19 CLS

20 FOR N=1TO 104 STEP 5

30 PRINT TAB(6)N; TAB (12)N+ 1; TAB (18)N+ 2 TAB (24)N+ 33; TAB (30)N+4

4h NEXT

ot ny

5 as |

GIGI Ot

“NTT SPIE IReheeehdeoae

gaBRANanenBaEeNE

SINAININSINSININ oe DUDS ALDI 8

1 © i 4 Sa) i sf 6 G £6 38 & i 36

86 Chapter 6

SPC SPC is a useful separator PRINT SPC (n) ... will insert n spaces before the item to be printed. n must be a positive whole number not greater than 255.

You can place a message anywhere on the screen using SPC. For example, try:

CLS:PRINT SPC (255) SPC (249)" MIDDLE OF SCREEN" This is not however a good technique. It is rather slow and any print already on the screen is obliterated, as CLS is required to get the

cursor to the top left hand corner.

SPC may be more usefully employed between two print items. Try, for example:

PRINT "TEN" SPC (19)"SPACES"

The ORIC Display 87

PRINT @

PRINT allows you to specify the position on the screen where a print message is to start in terms of the screen column (f to 39) and screen row (ff) to 25). It is implemented only on the V1.1 machine.

The format is:

PRINT @ X,Y3...

where X specifies column and Y specifies row as shown below.

88 Chapter 6

Thus:

PRINT @ 4,3;"ORIC" PRINT @ 5,531

would give

The space between PRINT and @ is optional, as is the space between (@ and the column number. The semicolon separating the row number and the first print item is compulsory. If you don't put it in you will get a syntax error.

You can use the PRINT (@ command to print on columns ) and 1 provided that you specify black paper and white ink. Any other paper/ink combination will give a very odd effect and could result in part of your message being lost. It is safer to restrict your printing to columns 2 to 39.

We shall see why when we look at attributes in the next chapter.

We can use several types of separator in the same print statement.

Try:

PRINT SPC (5)1,2;"BUCKLE MY SHOE" PRINT @ 6,7;"HELLO" TAB (29)"DOLLY"

(The second example will work on the V1.1 machine only.)

The ORIC Display 89

ARITHMETIC

The computer is used to process information we have been looking mainly at words, and where they are to be printed. We have also slipped in the occasional sum. For example:

PRINT 5+6 gave the answer 11.

We can do addition, subtraction, multiplication and division provided we get used to some unfamiliar symbols. The keyboard has the + and signs but no conventional x and +. Instead we use * and / so that 3 plus 4 multiplied by 5 divided by 6 is written

3+4*5/6.

The order of calculation is important. Multiplication and division are taken first, addition and subtraction second, so the above is worked out as

3+{(4*5)/6} We can use these calculations, as well as the many advanced functions

covered in Chapters 8 and 9, as part of almost any program line, including PRINT statements.

CHAPTER 7 Some Odd Characters

CHR$ Each character which you can type in from the keyboard and display on the screen has a number associated with it. These numbers are

known as ASCII codes, and are listed in Appendix A.

CHR $ converts anumber to the string containing the associated character. For example the ASCII code for A is 65. Thus:

PRINT CHR$(65) is the same as PRINT "A",

90

Some Odd Characters 91

CONTROL CHARACTERS

If you look at Appendix A you will see that the ASCII codes start at 32. Codes less than 32 do not correspond with any characters on the screen. Such codes generate characters known as _ control characters.

For example, try: PRINT CHR$(4)"DOUBLE"

This should give you double print in the same way as did CTRL D in Chapter 2.

Use CTRL D to get back to single print. You may have noticed that D is the fourth letter in the alphabet and that CRTL D did the same as PRINT CHR$(4). Could this just

be a coincidence? Let's find out.

You will recall that CTRL G caused a 'ping'. G is the seventh letter in the alphabet; so try

PRINT CHR$(7)

One more test for the sceptics. CTRL Q hides the cursor. Q is the seventeenth letter in the alphabet; so try

PRINT CHR$(17) Use either CTRL Q or PRINT CHR$(17) to get the cursor back, Here is a list of the control characters you may find useful in programs. Some peripheral devices (such as certain types of printer) use other

control codes, which will be listed in the booklets which accompany these devices.

92 Chapter 7

CHR$(1) Copies a character on the screen to the keyboard buffer

CHR$(4) Double print (on/off toggle)

CHR$(6) Keyclick (on/off toggle)

CHR$(7) Causes a ping

CHR$(8) Moves cursor one space to left CHR$(9) Moves cursor one space to right CHR$(10) Moves cursor down one line

CHR$(11) Moves cursor up one line

CHR$(12) Clears the screen

CHR$(13) Simulates a return key depression CHR$(17) Hides the cursor (on/off toggle) CHR$(19) Hides the screen output (on/off toggle) CHR$(20) Controls capitals lock (on/off toggle) CHR$(29) Allows printing in far left column (on/off toggle)

Control characters must be preceded by an instruction such as PRINT.

Some of the control characters are more useful than others. You will probably find that codes 4, 8 to 12 and 17 are the most common, but the others are available if you wish to use them.

ESCAPE

There is another control character which I have not put on the general list it is so important that it merits a section all to itself.

This is CHR$(27) which simulates an ESC key depression, and hence enables us to put attributes on the screen under program control.

We saw in Chapter 2 how attributes could be used to generate some unusual (and rather spectacular) screen displays. CHR$(27) lets us do the same things, but now we can use programs to generate these displays automatically, change them, and move them about.

The character following CHR$(27) is not printed but instead determines the attribute, which affects all the characters following it until either the end of the line is reached or a second attribute is encountered which cancels the effect of the first.

Some Odd Characters 93

When planning screen displays it is important to remember that attributes are printed as blank characters and each take up one character position on the screen.

Let's first list the effects of the various characters which could follow CHR$(27). We will then see some examples of these in action. PRINT CHR$(27)"@" black ink

is "A" —red ink

" "B" green ink

as. "Cc" yellow ink

" "DD" blue ink

"E" magenta ink

" "F" cyan ink

4 "G" -white ink

° "HH" single height, steady, standard

" "I" single height, steady, alternate

" "J" double height, steady, standard i "K" double height, steady, alternate " "L" single height, flashing, standard

" "M'"" single height, flashing, alternate "N" double height, flashing, standard 7 "QO" double height, flashing, alternate " "Pp" black paper

" "Q" red paper

" "R'" green paper

" "Ss" yellow paper

" "T" blue paper

" "UW" magenta paper

" "vy" cyan paper

"W"" white paper

First try a few examples to get used to the idea:

94 Chapter 7

PRINT CHR$(27)"A"CHR$(27)"T"SPC (12)"RED ON BLUE" PRINT CHR$(27)"E" CHR$ (27)"LTHIS IS A FLASHY EXAMPLE" PRINT CHR$(27)"C"CHR$(27)"ISOME VERY ODD CHARACTERS"

Make up a few more of these for yourself. Clear the screen occasionally so that you don't get lost.

A program, which can be repeated, is usually of more use than an immediate command. So try:

19 PAPER @:INK 3'BLACK PAPER YELLOW INK 20 PRINTCHR$ (12) CHR$ (4) CHR$ (17) 3@ REM CLEAR SCREEN, DOUBLE PRINT, HIDE CURSOR 49 PRINTSPC(9) CHR$(27)"JBIG YELLOW LETTERS" 50 PRINT:PRINT:PRINT 60 PRINTSPC(18) CHR$(27)"T" CHR$(27) "JON A BLUE LABEL "CHR¢$(27)"P" 70 PRINT:PRINT:PRINT 89 PRINTSPC (9) CHR$ (27)"A"CHR$ (27)"V" CHR$ (27) "JALSO RED ON CYAN "CHR$(27)"P" 99 GOTO 94

This program has a number of interesting points.

Firstly I have set the paper colour to black. If you do not specify a background colour when controlling a display with attributes, then your background for that line will go black by default. Setting the general background to black saves code and usually gives neater displays. Try changing line 19 to PAPER 7:INK 3, and you should see what I mean.

Because I have specified a ‘global’ ink colour of yellow all printing will be in yellow unless I change the ink colour on a specific line by using an attribute as I have done in line 89.

I have used PRINT CHR$(12) rather than CLS to clear the screen. This instruction not only clears the screen, but also moves the cursor down one line (from screen line zero to screen line 1). As we saw in chapter 2, we need to do this to get the double height print working correctly.

Program line 5f@ moves the cursor from screen line 1 to screen line 5 (skips lines 2,3 and 4). As line 5 is an odd numbered screen line double print will work correctly there. In general double size print lines must have double spaces (or multiples thereof) between them or, alterna- tively, no spaces at all. Try the effect of altering lines 5@ and 7 to each contain five PRINT instructions. Alter them again so that they each contain only one PRINT instruction.

Some Odd Characters 95

Finally line 99 puts the program in a continuous loop so that the word 'Ready' does not appear to spoil the display. Break from this loop with CTRL C. Don't forget to restore the cursor (CTRL Q) and cancel double print (CTRL D) after breaking from the program.

Play around with this program, or use it as a model to write similar ones for yourself.

Entering PAPER 7:INK @:CLS will clear the screen and get back to black ink on white paper.

Here is another program which you may find interesting. Try to work out exactly what is happening.

19 PAPER @:INK 2 20 PRINTCHR$(12)CHR$ (17) 396 FOR N=1T0 21 4f PRINTCHR$ (4)SPC (N) CHR$ (27)"KNSESESESE,WL * /* "CHR$ (19) 50 PRINTCHR$ (4)SPC (N+ 1)"o0"SPC (3)"0"SPC (3)"0 00 0" CHR$ (11) CHR$ (11) CHR$ (11) 60 WAIT 19 70 NEXT 84 PRINTCHR$ (17)

PLOT

You can position a message anywhere on the screen using SPC or TAB with PRINT. However this could take a bit of working out. What is required here is an instruction which prints on the screen starting at a specified number of spaces along from the left of the screen and a specified number of lines down from the top.

If you have the V1.1 machine you can do this with PRINT @. The PLOT instruction, however, works with both versions of the machine. The format is:

PLOTX,Y,"..."

where X is the number of spaces across the screen and Y is the number of lines down the screen.

96 Chapter 7

The line and column numbers are slightly different for each version:

Reserved Column (Not used)

26 V1.0 Machine

26 V1.1 Machine

For example PLOT 2,2"A" would print the letter A in the positions shown.

Some Odd Characters 97

PLOT is normally used only with strings. If you try: PLOT 6,6,65

you will find that, instead of the number 65, the letter A is printed in screen position 6,6.

PLOT 20,14,90 will print the letter Z.

The PLOT instruction interprets the number following it as an ASCII code. Refer to Appendix A and try a few examples for yourself.

In the examples given I have not used the two left hand columns. Let's find out what happens if you do. Clear the screen and enter:

PAPER 7:INK 4:PLOT 9,0,"TOP LEFT" (V1.9 machine) or PAPER 7:INK 4:PLOT 1,8,"TOP LEFT" (V1.1 machine)

Not very inspiring. Clear the screen again and enter

PAPER §:PLOT #,0,"TOP LEFT" (V1.9 machine) or PAPER $:PLOT 1,6,"TOP LEFT" (V1.1 machine)

TOP LEFT should now appear in white ink although you have set the INK colour to blue.

Try changing the message so that all the letters on the screen are blue. Enter

INK 4

The message turns blue but you have lost the first letter. It now reads OP LEFT. Messages placed on the screen by the PLOT command so that they start at column # appear in white ink. If you try to change the ink colour you lose the first letter of the message. This is because the second column from the left is then used to hold the attributes controlling the foreground (ink) colour of the screen display.

If you have the V1.1 machine you can also PLOT in the far left hand column. If you do this the entire row turns black and the message appears in white ink.

98 Chapter 7

LORES @

Up until now you have been using the 'TEXT', mode for displaying screen messages. The machine goes into TEXT mode automatically when you switch it on or when you press the reset switch. There is, however, another mode which allows you to use column # for your messages, by setting the 'default' colours of black paper and white ink so column @ is not required for attributes. This is Low Resolution Mode # or LORES 9 for short.

This mode is entered using the instruction LORES @ either in a program or as a direct command.

LORES fi is also the instruction which clears the screen in this mode. If you use CLS or CTRL L the machine goes back into TEXT MODE. If you use an INK instruction to change foreground colour you will lose all of the printing in column 9. Attempting to change the background colour with a PAPER instruction has an odd effect. Try it and see.

The screen cannot be scrolled in LORES f mode. If you try to print below line 26 the TEXT screen scrolls back into view.

The PRINT instructions are used in the normal way in LORES @ mode.

The instruction TEXT can be used to get back into text mode. This, however, does not clear the screen or restore normal paper colour. CLS does all of these.

PLOTTING ATTRIBUTES

We saw that attempting to PLOT a number on the machine resulted in that number being treated as an ASCII code. The smallest ASCII code number is 32 what happens if we PLOT smaller numbers?

The answer is that PLOTting numbers less than 32 is yet another method of putting attributes on to the screen and a very convenient method in that it is easy to specify the position where you wish the attribute to be placed.

Some Odd Characters 99

PLOT X,Y, black ink e ] red ink 7 Z green ink i 3 yellow ink 4 blue ink ? 5 magenta ink 6 cyan ink 2 ri white ink " 8 single height, steady, standard . a single height, steady, alternate 7 1f |= double height, steady, standard 1] double height, steady, alternate " 12 single height, flashing, standard ? 13 single height, flashing, alternate : 14 double height, flashing, standard " 15 double height, flashing, alternate ? 16 black paper " 17 red paper " 18 green paper " 19 yellow paper : 20 —blue paper is 21 magenta paper aH cyan paper i 23 white paper

24-31 may affect screen synchronization

I would advise against PLOTting numbers 24 to 3]. Some of the effects produced may not be very good for your television.

The next program shows how attributes PLOTted on to the screen can affect a display. See if you can work out what is happening. Break with CTRL C and restore the cursor with CTRL Q.

100 Chapter 7

19 PRINT CHR$(12)CHR¢$ (17)

24 PAPER 7:INK

36 PLOT5,11,"HERE'S YOUR NAME IN LIGHTS" 49 PLOTS,12,"HERE'S YOUR NAME IN LIGHTS" 59 WAIT 154

60 PLOT2,11,1@:PLOT2,12,1¢

70 WAIT 59

80 FOR N=1 TO 6

99 PLOT11,11,N:PLOT16,11,7-N:PLOT21,11, 1ff PLOT11,12,7-N:PLOT16,12,N:PLOT21,12,4 119 WAIT 54

128 NEXT

136 PLOT11,11,@:PLOT11,12,0

149 PLOT16,11,@:PLOT16,12,4

158 WAIT 59

169 FOR N=1 TO 6

174 PLOT11,11,16+N:PLOT16,11,23-N:PLOT21,11, 23 189 PLOT11,12,23-N:PLOT16,12,16+N:PLOT21,12,23 199 WAIT 59

200 NEXT

219 PLOT11,11,23:PLOT11,12,23

220 PLOT16,11,23:PLOT16,12,23

234 GOTO 79

ATTRIBUTES WITH PRINT @

If you have the VJ.l1 machine there is yet another method of putting attributes at selected positions on the screen. This is to use the PRINT @ instruction followed by CHR$ (27).

Try:

CLS:PRINT @9,12;CHR$(27)"A" CHR$ (27)"TRED ON BLUE"

INPUT

The INPUT instruction is used to get information from the keyboard, while the program is running.

Key in and RUN the following program: 19 INPUT" WHAT NUMBER";N

20 PRINT N,10*N 3f GOTO If

Some Odd Characters 101

Line 198 contains the INPUT instruction. This will print on the first free line on the screen whatever is in between the inverted commas. It will then wait for you to type in a number, followed by the RETURN key.

N may be positive or negative. It need not be a whole number. The INPUT instruction puts a space and a question mark after the message. The INPUT instruction works in the same way if you don't put a message after it. Then only the question mark 'prompt' appears on the screen. Try changing line 19 to:

19 INPUT N If you want to make sure that only whole numbers (integers) are entered, put a percent(%) sign after the variable. Any number keyed in will be rounded down to the nearest integer value.

Try changing lines 19 and 29 to:

19 INPUT N% 20 PRINT N%

If you enter letters when ORIC is expecting a number, ORIC will ask you to re-enter the correct information by giving the error message REDO FROM START. A second form of the INPUT instruction allows you to enter both letters and numbers. This form puts the inputted information between quotes and so turns it into a string (see earlier in this chapter). This happens whether the information entered is letters or numbers. To input string information the format is

INPUT "...."; A$ or simply INPUT A$ Note the $ sign. This denotes a string.

The next program demonstrates the use of this format:

1p INPUT "What is your name"; A$ 26 PRINT "Hello "A$

UO-H

102 Chapter 7

birt iS Your nanmetT Jan Heiio lan

Resets

Remember that for both forms of the INPUT instruction you must press the RETURN key after your entry.

If you have a message in your INPUT statement you must have semicolon separator between the message and your INPUT variable. If you have no message you don't need a semicolon.

CHAPTER 8 It's Make Your Mind Up Time

DECISIONS

Most of the programs we have seen so far have just run through from start to finish. This is unusual as a computer is a very good decision maker. We can get the computer to decide whether to execute a command or not, or get it to do lines in different order depending on what has gone before. Some examples are more useful than words,

103

104 Chapter 8

IF ... THEN

let us consider the IF ... THEN ... command. This is used as it is written. IF something is true THEN do something. Here is an example.

IF X=5 THEN PRINT “X=5" What comes after the THEN must be a command and what comes after the IF must be some sort of expression which is either true

or false.

The ORIC understands a number of symbols in the IF statement and these include:

equals

less than

<

> greater than

<= less than or equal to (or = <) >

= greater than or equal to (or => )

<> not equal to This program shows some of these in action.

19 INPUT" WHAT NUMBER";N

26 IF N=5 THEN PRINT" YOU TYPED 5"

30 IF N<f THEN PRINT" YOUR NUMBER IS NEGATIVE" 4h IF N <>8 THEN PRINT" THAT WASN'T 8"

50 IF N<=1 THEN GOTO If

60 IF N>1@ THEN STOP

7H GOTO 1p

Try this program and see if you understand what is going on. Notice that you don't have to use PRINT statements. You can have GOTO or STOP or anything else in "IF" commands.

For example consider this silly program.

19 INPUT" WHAT NUMBER";N 20 IF N>5 THEN N=32

39 PRINT "YOU TYPED IN "N 4f GOTO 1p

This program will give the 'correct' answer if your number is 5 or less.

It's Make Your Mind Up Time 105

AND, OR, NOT

Consider this program. It comments on ages less than 2, greater than 119 and between 13 and 19. Thus a number of decisions can be made all about the same variable.

1f INPUT "WHAT IS YOUR AGE";A 20 IF A<2 THEN PRINT "I DON'T BELIEVE YOU" 30 IF A>11f THEN PRINT "YOU MUST BE AN ALIEN" 4f IF A>12 AND A <2¢ THEN PRINT "YOU ARE IN YOUR TEENS" 5A GOTO 19

Notice in line 49 how I have used the word AND to make the decisions more complicated for ORIC. We can use other words to string IF statements together. These are OR and NOT. SoI could say:

IF X <19 AND A=5 OR Y=X THEN GOTO 29

This means GOTO line 2@ if both X is less than 19 and either A equals 5 or Y equals X. This is very complicated and is given as an example only. Using multiple decisions comes with practice and it is sufficient at this stage to know that they are there to be used.

NOT is also used in decisions:

IF NOT (ASB) TREN assesses is the same as

iA <> B TEN wisweces or in English

IF A IS NOT EQUAL TO B THEN .......

PF ass. DEN oes ELSE

The IF ... THEN ... ELSE construction is an extension of IF ... THEN, but gives more powerful and neater decisions. It tests if a condition or number of conditions are satisfied. If they are it performs a number of operations, otherwise it performs an alternate set of operations.

For example lines 49 and 5 in the last program could be put together into one line:

4h IF A>12 AND A<2@ THEN PRINT "YOU ARE IN YOUR TEENS" ELSE GOTO 19

106 Chapter 8

GOTO, when used after THEN or ELSE may be missed out, so that in this example we can have ELSE 1 instead of ELSE GOTO 1f.

BEWARE: Computers, like ORIC, are more logical than we are. They do things just as instructed. The IF statement is the source of many errors in computing.

ook at this program.

19 INPUT"WHAT NUMBER";N 20 IF N <5 THEN PRINT"N <5" 36 IF N>5 THEN PRINT"N>S5"

We have failed to tell ORIC what to do if N is equal to five. In this case it will do nothing but in longer programs this type of error can be disastrous.

The IF ... THEN ... ELSE ... structure is less prone to this type of error as ELSE covers all conditions not specified by IF. The program becomes

19 INPUT"WHAT NUMBER;3"N 20 IF N <5 THEN PRINT"N<5" ELSE PRINT "N2=5"

The OR expression is true when either or both conditions are satisfied:

19 INPUT"FIRST NUMBER" X 2h INPUT"SECOND NUMBER"; Y 39 IF X=5 OR Y=6 THEN PRINT "BINGO" ELSE 1

Note how even when X=5 and Y=6 the PRINT statement takes place.

If we wish we can use the IF statement in a program loop to execute a part of a program a certain number of times.

Suppose we want to print out the numbers 1 to 1f. We could do it like this.

19 X=1

20 PRINT X 30 X=2

4H PRINT X 50

etc

It's Make Your Mind Up Time 107

There is however, a method which uses fewer instructions. Let's try:

1g X=1

24 PRINTX

3h X=X+1

4f IF X <11 THEN 26

This program has two important points. First, line 3 seems to be mathematical nonsense. X cannot equal X+1. To a computer this means 'let the memory location called X take on the value of the old value of X with one added to it'. Put another way 'let X become X+1'. However we say it, the effect of line 34 is to add one on to X. In line 16 we set X to 1, and so the first time we do line 3f, X will become 2. The next time we do line 39, X will become 3 and so on.

Secondly line 4 has IF X <11 THEN .... The program stops when X=11 or is greater than 11. We wish the program to print up to ten and therefore we stop it when X has reached 1f+1 or 11. Another common error in computer programs is to do a loop once more than is required or once less than is required.

We can use a similar program to print out all the even numbers between one and ten inclusive.

1g X=2

20 PRINT X

39 X=X+2

4f IF X >1$ THEN STOP ELSE 29

It is important to look at line 49 again. If we had the statement IF X=l11 THEN STOP or some such then the program would never stop as X is never equal to 1]; it steps from 1 to 12. For safety's sake we could use the >= sign to stop a loop.

We can 'count down! to launch a rocket using the same sort of program.

1p X=19

20 PRINTX

39 X=X-]

4h IF X <=@ THEN PRINT "FIRE":STOP ELSE 29

MULTIPLE INSTRUCTION LINES Now I've done something else in line 49. Not only have I been over

cautious by using 'X <=' where 'X=9' would do, I've also used a ':' and a further command.

108 Chapter 8

Generally if the 'IF' statement is not true then the rest of the line is ignored until ELSE is encountered. If the 'IF' statement is true then the rest of the line preceding ELSE is executed.

FOR 655 NEAT

Program loops are so important that they have been given a special set of instructions. FOR NEXT loops do exactly what we have done just now but without the 'IF' statement. These loops have already been mentioned briefly in chapter 5.

19 FOR X=1 TO 1g 20 PRINT X 36 NEXT

This will print out the numbers from 1 to 1. In fact any lines between the FOR and the NEXT will be done 19 times.

STEP

We used the instruction X=X+2 to allow us to print out in steps of two. The FOR ... NEXT command also can be used for this by defining the STEP.

19 FOR X=2 TO 10 STEP 2 20 PRINT X 30 NEXT

We can "count down" by:

19 FOR X=19 TO 1 STEP -1 20 PRINT X

39 NEXT X

49 PRINT"FIRE"

If you don't use the STEP part of the FOR command then the computer assumes yOu mean +1.

It’s Make Your Mind Up Time 109

This can lead to a funny result. The FOR ... NEXT loop is always executed once even if it is not expected to. So:

19 FOR X=19 TO1 20 PRINT X 36 NEXT

will print out 19 then carry on. X will be 11 and as this is greater than 1] the computer thinks it has finished the loop.

We need not step in units. So:

19 FOR X=6.614 TO 9.131 STEP 9.917 26 PRINT X 39 NEXT

will also work, We can even use variables in the loop. Try:

19 INPUT"'HOW MANY'3Y % 20 FOR X=1 TO Y%

30 PRINT X

4g NEXT

While we are on the subjects of loops these are two things you should never do.

1. Do not reset the loop variable continually to a constant value within a loop.

19 FOR X=1 TO 39 20 X=5

34 PRINT X

4h NEXT

2. Do not jump into the middle of a loop.

1p GOTO 39

24 FOR X=1TO 19 30 PRINTX

49 NEXT

I'll leave you to work out why not. Just try the programs as they are if you don't understand and ORIC will tell you.

110 Chapter 8

It is possible to "nest" loops. This is not a command word but refers to a program 'structure' (a way of constructing programs).

19 FOR Y=# TO 19 20 FOR X= TO 19 30 PLOT: xX, ¥ 5's" 40 NEXT X 50 NEXT Y The X loop, lines 20, 38 and 4@ are "nested" inside lines 1$ and 59. So for each value of Y from # to 1f, X goes through its range. Diagram- matically this is shown: Y Loop (- X Loop Y Loop Lines 49 and 50 may be shortened to 4f NEXT X,Y The next program will NOT work. ara FOR X= TO 199 Y Loop ——24 FOR Y= TO 199

x Loop | 30 PLOTX, ¥, 3%" I rcseeiinclant antec

as the nesting is all mixed up.

We can have several levels of nesting if we wish. For example:

X Loop Y Loop Z Loop 4f PRINT X, Y, Z; | L___54 NEXT Z | 60 NEXT Y 706 NEXT X

Again lines 5f, 60 and 7 may be shortened to:

50 NEXT Z,Y,X

It's Make Your Mind Up Time 111

REPEAT ... UNTIL

Sometimes we do not know exactly how many times we wish to go round a loop. What we wish to do is repeat an action or number of actions until a condition is satisfied. If ORIC could make hay or recognise sunshine, it would rephrase an old proberb:

REPEAT make hay UNTIL NOT weather = sunshine

More realistically we could use the REPEAT ... UNTIL loop to detect that a particular number is entered:

1p REPEAT

20 INPUT"WHAT'S MY AGE";A

39 UNTIL A=16

49 PRINT"THAT'S RIGHT, SWEET 16" 50 PRINT"AND NEVER BEEN KISSED"

A common use of REPEAT ... UNTIL is to allow data to be entered via the keyboard until an 'end of data’ input is received. Suppose for example that we wished to average an unknown number of values. We do know that none of these values will be 99, and so we can use 99 as a 'data terminator’ that is we enter 99 when we have entered all the values.

A program to illustrate this is:

19 REPEAT

26 T=T+V

39 N=N+1

49 INPUT"NEXT VALUE"; V

50 UNTIL V=99

60 PRINT"AVERAGE IS "T/(N-1)

(If you have the V1.1 machine you don't need the space after IS in line 69).

This program works provided at least one value is entered before the data is terminated by entering 99.

Note -—_ In programs similar to the above I shall put a space at the end of a string preceding a number. These spaces are necessary in the V1.0 machine. If you have the V1.1 machine you can leave them out.

Tz Chapter 8

REPEAT ... UNTIL loops can contain FOR ... NEXT loops nested within them, and vice versa. REPEAT ... UNTIL loops can be nested in the same way asFOR ... NEXT loops. For example, try:

16 REPEAT

20 : T=f:N=0

36 : REPEAT

4h: T=T+V

50 b4 N=N4+1]

60 : INPUT"NEXT VALUE"; V

76: UNTIL V=99

88 : PRINT"AVERAGE IS "T/(N-1)

99 UNTIL T/(N-1)=20

199 PRINT"THAT'S JUST WHAT WE WANT"

I have used a colon directly after the line numbers in lines 24 to 80. This allows spaces to be put in front of the instructions so that an indented listing is obtained. Where you have nested loops, indented listings can make your programs easier to understand.

If you wish to set up a continuous loop then REPEAT ... UNTIL # may be used.

It’s Make Your Mind Up Time 113

SUBROUTINES

Program loops are very useful when we want to do the same thing many times. There are times however when we wish to do something a number of times in a program but not as a loop.

Suppose, for example, we wanted to add a 25% mark up on the purchase cost of a number of items to obtain a selling price P, and print out the result. This could be done by:

199 INPUT "COST";C

118 D=6@.25*C

124 P = i + D

130 PRINT"SELLING PRICE = "P 146 PRINT"DISCOUNT = "D

In along program we might need to do this ten or twenty times. That is a bit like hard work; so ORIC allows us to treat this sort of program as a subprogram, or subroutine. We 'call' a subroutine by the instruction GOSUB followed by the line number where the subroutine starts.

The next program uses subroutines and has several other points of interest. It was developed by the gentle inhabitants of the tropical paradise Sco'lan. Although the cannibal tribe on the neighbouring island En-guland consider the Sco'ish people (or Haggizbashirz) to be primitive, this program shows that they have their priorities correct.

The program uses string variables which we saw with the INPUT instruction in the last chapter. It also uses integer variables so that all answers are whole numbers. This is because broken seashells are not negotiable currency.

114

190 119 200 219 220 236 240 250 260 270 280

Chapter 8

CLS A$ ="COCONUTS": B$ ="SEASHELLS PER DOZEN" GOSUB 2p

A$ ="GOATS": B$ ="SEASHELLS EACH"

GOSUB 2p

A$ ="HUSBANDS": B$ ="SEASHELLS PER DOZEN" GOSUB 2p

A$ ="POLITICIANS": B$="SEASHELLS PER GROSS" GOSUB 2p

STOP

REM #EdEAEAE AE AEE AE AE AEE AE AE AEE AE AEE AE AEE AE AE

REM SUBROUTINE

PRINT A$" IN "B$

INPUT C%

D%=9.25*C%

P%-C%+D%

PRINT"PRICE IS "P%B$

PRINT"MARK UP IS "D%B$

PRINT

RETURN

MAS Pee LA

PRICE IS 58 PER

SEASHELLS uP 12 16 SEASHELLS PER

GOATS IM SEASHELLS EACH

? 8S

PRICE 15 106 SEASHELLS EACH MARK UP IS 21 SEASHELLS EACH

PUSAN IN SEASHELLS PER DOZEN

a ICE IS 4@ SEASHEL1LS PER DOZEN BRK UP 15 8 sSEASHELLS PER DOZEN

PO, LFICIANS IN SEASHELLS PER GROSS

PRICE IS 18 SEASHELLS PER GROSS MARK UP IS 3 SEASHELLS PER GROSS

<M DOZEN

BREAK IN 166 Recchy

It’s Make Your Mind Up Time 115

Note the instruction RETURN in line 280. This tells ORIC to return from the subroutine to the next instruction following the GOSUB ‘call'. All such subroutines must end in a RETURN statement.

I have 'called' the subroutine in lines 3A, 508, 70 and 99; once it was executed the program returned to lines 49, 60, 84 and 199 respectively.

I had to be careful to ensure that the program did not accidently 'fall' into the subroutine without being called and I prevented this with the STOP at line 1f%. Otherwise the program would have gone a to line 119 after returning from the subroutine called at line 90.

If the STOP instruction was not there the program would fail when it reached the RETURN. Try it; remember you cannot break your computer by making program mistakes.

It is possible for one subroutine to call another. For example:

19 INPUT"NUMBER BETWEEN 1&5"3N

2 GOSUB 169

39 PRINT N:STOP

196 REM CHECK NUMBER

119 IF N<1 OR N>5 THEN GOSUB 2¢9¢

120 RETURN

208 REM WRONG NUMBER

219 PRINT"NUMBER OUTSIDE RANGE 1 TO 5"

220 PRINT"DEFAULT NUMBER 4 WILL BE USED":N=4 23 RETURN

A subroutine may even call itself. This is called recursion. For example:

19 PRINT"SELECT THE SERVICE YOU REQUIRE"

20 PRINT"1. BALANCE ENQUIRY"

30 PRINT"2. DEPOSIT"

4g PRINT"3, WITHDRAWAL"

50 GOSUB 190

60 IF N=1% THEN PRINT"YOU CAN'T AFFORD A BALANCE ENQUIRY"

70 IF N=2% THEN PRINT"GIMME THE MONEY"

80 IF N=3% THEN PRINT"YOU'VE GOT TO BE JOKING"

99 STOP

199 REM GET AND CHECK NUMBER

119 INPUT"WHAT IS YOUR CHOICE";N%

120 IF N% <1 OR N%>3 THEN PRINT"INVALID ENTRY": GOSUB 194

136 RETURN

116 Chapter 8

ON ... GOTO

There is a neater method of constructing a program to allow the user to make a choice from a list or menu on the screen. This is the ON ... GOTO instruction, which is of the form:

ON N GOTO 169, 200, 300

This will cause the program to jump to line 199 if N=1, to line 209 if N=2 and to line 309 if N=3. If N is not a whole number it is rounded down. If N is outside the specified range then the program will carry out the instruction directly following the ON ... GOTO instruction.

The next program does the same as the previous one but uses the ON ... GOTO instruction.

19 PRINT"SELECT THE SERVICE YOU REQUIRE"

20 PRINT"1. BALANCE ENQUIRY"

39 PRINT"2, DEPOSIT"

49 PRINT"3. WITHDRAWAL"

50 INPUT"WHAT IS YOUR CHOICE";N

60 ON N GOTO 199, 119, 120

70 PRINT "INVALID ENTRY": GOTO 59

199 PRINT"YOU CAN'T AFFORD A BALANCE ENQUIRY":STOP 119 PRINT"'GIMME THE MONEY": STOP

120 PRINT"YOU'VE GOT TO BE JOKING":STOP

ON ... GOSUB

On ... GOSUB works in a manner very similar to ON ... GOTO, but it is possibly rather more useful. Rather then merely jumping to the lines specified on the appropriate value of the variable it carries out subroutine jumps. For example:

19 REPEAT

20 INPUT"WHAT NUMBER";N

30 ON N GOSUB 169, 240, 300, 400

49 PRINT

5@ UNTIL F=1:END

199 PRINT"A PARTRIDGE IN A PEAR TREE": RETURN 200 PRINT"'TWO TURTLE DOVES": RETURN

300 PRINT" THREE FRENCH HENS": RETURN

406 PRINT"THAT'S ALL FOLKS": F = 1: RETURN

END in line 58 does much the same as STOP except that after END the program can't be restarted with CONT.

It’s Make Your Mind Up Time 117

TRON AND TROFF

One effect of having decisions in programs is that they no longer work in strict line order. For example the last program may go to any one of lines 199 to 40f before line 49.

When you are debugging such programs it is often useful to trace the exact order in which the lines are 'executed'. To do this you can put the instruction TRON (short for Trace On) in a program. Try the effect of adding the line:

5 TRON

to the last progam. As each line is executed that line number is printed on the screen in square brackets. Note that TRON may be used only in a program line. It cannot be an immediate command.

MUMBER? 1 . wR RiGee IN A PER TREE 7

m7 1 9+f3 Bag Eid zg 7

} Tg Rie COMES

H NUMBER? 3

E PRENCH HENS N

8

ry = ya T7 G4

arte Be

nninnwinnwurey

UMBER? 4 PALL. POKS

= a a:

re BSSSS

If you wish to look only at a part of a program, then the instruction TROFF switches the trace back off. Try the effect of inserting TROFF at various points in the program. The NEW command turns off the trace as well as clearing program memory.

uo-1

CHAPTER 9 A Way With Words

STRINGS

Words on the ORIC are called 'Strings' as they are strings of characters. So "ALAS POOR ORIC I KNEW HIM WELL" is a string which is 3M characters long. Remember a space is also a character. In fact anything you type in between the quotes, whether it is a number, a letter, a space, a symbol or whatever, is part of the string. To store this string in the computer we give it a name. This name is called a string variable. ORIC has some fairly strict rules about variables which we will look at later in this chapter. In the meantime we will take the easy way out and represent string variables by a single upper case (capital) letter followed by the symbol $ to represent a string.

118

A Way With Words 119

Try the following:

19 A$="THIS IS A STRING"

20 B$="So is this"

34 C$="Numbers like 1,2 and even 3*4/6" 4f PRINT A$

50 PRINT B$

60 PRINT C$

You will see that a string can contain both lower case and upper case letters. However a string variable must be upper case a$ ="wrong" is not acceptable to ORIC.

CONCATENATION We can add strings together. This is called concatenation. For example:

19 A$="Hello"

20 B$="I'm ORIC" 30 C$= A$ + BS

4g PRINT C$

will print Hellol'm ORIC. Because we didn't have a space between Hello and I'm, none has been added.

Any character created by CHR is itself a string and can be added to other strings. This is a particularly useful feature if we want to put a block of characters on two lines on the screen. This is best illustrated by an example.

19 A$ =CHR$ (27) +"I7K"

20 REM TWO ALTERNATE CHARACTERS

36 A$ =A$+CHR$ (19)+ CHR$(8)+ CHR$ (8) + CHR$ (8)

4f REM ONE SPACE DOWN AND THREE SPACE LEFT CHARACTERS 50 A$ =A$+CHR$ (27) + "IUZ"

60 REM TWO MORE ALTERNATE CHARACTERS

70 CLS: PRINT CHR$(17)'CURSOR OFF

89 PRINT: PRINT:PRINT SPC (17) A$

94 GOTO 94

1996 REM BREAK FROM PROGRAM WITH CTRL C

120 Chapter 9

FRE

Another interesting feature of this program was that the string variable A$ was used to hold increasingly longer strings by being set equal to its previous contents plus some new characters. This is a convenient method of building up long strings, but it has a serious disadvantage. It uses up a lot of memory space. This is because all the versions of A$, not just the current one, are held in memory. This does not matter in a small program, but it could cause you to run out of memory space in a large one.

The instruction FRE lets you know how much memory space you have left. For example:

PRINT FRE(Q)

used as an immediate command tells you the number of 'bytes' of memory remaining, and

169 IF FRE(f) <15f THEN PRINT"NO MORE ENTRIES" could be used in a data handling program.

Possibly even more useful is the form of the command: PREG")

If this is inserted in a program it will erase from the memory all versions of strings except the final versions.

STRING DECISIONS We can make decisions using strings:

1f INPUT"DO IT AGAIN Y/N"; Y$ 26 IF Y$="Y" THEN PRINT"IT IS DONE": GOTO 16 ELSE STOP

For strings to be equal they must contain exactly the same characters in the same order. Spaces do matter and upper case characters are not the same as lower case. If in the last example you entered 'YES' instead of 'Y' the program would stop, because "Y" does not equal "YES".

A Way With Words 121

COMPARING STRINGS

We can compare strings using the greater than (>) and less than (<) symbols. These do not refer to the length of strings, but instead to the ASCII values of the characters in the strings.

For example the ASCII value of A is 65, and of B is 66. So "A" is less than "B".

If the first characters of both strings are identical the second characters are compared, and so on until a difference is detected.

So "AA" is less than "AB"; "AAB" is greater than "AAA",

The next program lets you key in and compare any two strings. Use it until you are happy with the idea. Note that the comparisons are made on the string contents, not on the letters used to represent string variables.

19 REPEAT

24 INPUT"FIRST STRING"; A$

30 INPUT"SECOND STRING"; B$

40 IF A$ <B$ THEN PRINT A$" <"B$ 50 IF A$> BS THEN PRINT A$">"B$ 60 IF A$=B$ THEN PRINT A$" = "B$. 70 UNTIL B$="STOP": STOP

Stop the program by entering 'STOP' as the second string.

As alphabetical order of the characters A to Z corresponds with their ASCII code number order we can use comparisons to sort strings into alphabetical order. Be careful, however, to remember that the lower case numbers all have ASCII codes higher than any of the upper case numbers, so that "a" is greater than "Z".

If you prefer:

if A¢="EVIL" and B$="evil" then A$ is the lesser "evil"; if A$="Good" and B$="GOOD" then Ag is the greater "Good".

122 Chapter 9

VAL VAL changes a string of numerical data into a number. For example:

1p Ag="2" 26 PRINT A$,VAL (A$)

will print 2 2 . Not at first sight very inspiring. In the first place, however, the program printed a string and in the second place a number. You cannot mix strings and numbers; so you cannot write PRINT 2+ A$ in the same expression, but can write PRINT 2+ VAL (A$).

VAL can also act on mathematical symbols such as +, -, * and /. Thus:

1p A$="5+14-6* 3" 26 PRINT A$"="VAL (A$)

would print 5+ 14-6* 3=1 If VAL is used on an alphabetic string it gives the value zero even VAL (ORIC)= 6. STR$ STR§$ does the opposite to VAL it converts a number into a string. Thus STR$ (1234) ="1234". An advantage of changing a number into a string is that we then use the PLOT instruction to place it anywhere on the screen. For example PLOT 17,12,1234 gives an error, whereas PLOT 17,12,STR$ (1234) gives the desired effect. Note - = In the V1.9 machine STR$ used with positive numbers inserts an illegal character at the start of the string. To correct this use A$=STR$(....): A$ =RIGHT$(A$ , LEN (A$)- 1). LEN and

RIGHT$ are described overleaf. This fault has been cor- rected on the V1.1 machine.

A Way With Words 123

Another, and possibly even greater, advantage of changing a number into a string is that we may then use the powerful string manipulation instructions which ORIC makes available to us. Let's have a look at these.

LEN

First we can find out the length of a string using the LEN instruction.

19 INPUT"What is your name";N$ 26 PRINT"Your name has "LEN (N$)" letters"

Line 2@ uses LEN to count the number of letters in N$ and print this number out. LEFT$

LEFT$ allows us to obtain a specified number of characters from the start of a string. For example:

PRINT LEFT$("SILLY EXAMPLE", 5)

would print 'SILLY'.

Remember that spaces are characters and are counted, so that: A$="A BETTER EXAMPLE":PRINT left$ (A$, 5)

would print 'A BET'.

RIGHT $

RIGHT$ allows us to obtain a specified number of characters from the end of a string. For example:

PRINT RIGHT$("A BETTER MOUSETRAP", 4)

will print 'TRAP'.

124 Chapter 9

MID$

LEFT$ and RIGHT$ are special cases of the general string slicing instruction MID$. The general form of this expression is:

MID$(A$,A,B).

This will give B characters of string A$, starting at position A and moving to the right. This sounds complicated, but a few examples should clear it up. For example:

PRINT MIDS (" 12345", 3,2) A$="A STRING":PRINT MID$(A$,1,3) B$="I LIKE ORIC":PRINT MID$(B$,5,2)+MID$ (BS, 9, 2)

will print

34 AS KERI

respectively.

If you do not specify a second number, MID$ will give a string starting at the selected position and going to the end of the string being sliced. For example:

PRINT MID$("FRED", 2) will print 'RED'.

MID$(A$,1,N) is the same as LEFT$ (A$ ,N) MID$(A$,N,1) gives the Nth character in a string.

We can use MID§ to print a word backwards as in the next program.

19 INPUT" WHAT WORD"; W$

246 FOR N=LEN(W$) TO 1 STEP-1 | 34 PRINT MID$(W$,N,1)3

4g NEXT

54 PRINT

69 GOTO 19

A Way With Words 12

KEY$

Another method of entering a string from the keyboard is to use KEY$.

KEY$ used as part of an instruction (e.g. A$ =KEY$) scans the keyboard to see if a key is pressed. Unlike the INPUT instruction, however, it does not cause the program to wait until you have typed in something followed by RETURN. If a key is pressed, KEY$ takes the value of the string containing the keyed-in character. If no key is pressed, KEY$ records the 'empty string'.

For example:

If key P is pressed KEY$ ="P" If key 1 is pressed KEY$ ="1" If no key is pressed KEY$ =""(empty string)

Using KEY$ clears the keyboard buffer hence the form of the instruc- tion Af=KEY§$ which stores the entry more permanently in a string variable such as Af. If a key is held down KEY$ will not detect it again until the Repeat Key facility causes it to be re-entered into the keyboard buffer.

If two keys (not including SHIFT or CTRL) are held down at the same time KEY$ will not detect the second key pressed until the first is released.

To see the effect of KEY$ use the program: 1g A$=KEY$

24 PRINT A$ 30 GOTO 19

GET

GET causes the program to stop until any key other than SHIFT or CTRL is pressed. GET is followed by a variable, for example GETA$, GETB.

19 GET A$

20 PRINT A$ 34 WAIT 209 4h GOTO 19

with the previous program.

126 Chapter 9

You may have wondered why I put line 34 in this program. You will find out when you come to break from the program using CTRL C not easy is it?

You have to use CTRL C just after you have pressed another key. Line 39 gives you time to do this.

If you wish to make ORIC inactive use:

1p GET BS 246 GOTO 19

You can't get out of this with CTRL C as the GET instruction simply stores this entry and all others in string variable B$. To break from this loop you have to use the Reset key under the computer.

If a numeric entry is expected, GET may be followed by a numeric rather than a string variable. This has the disadvantage that a TYPE MISMATCH error will usually result from a non-numeric entry.

GET is often used simply to halt the program until any key is pressed. This is useful if, for example, you put a lot of text on the screen and ask the user to press any key to continue once he or she has read this. Here is another example which is popular with my children but not with my wife. It uses some instructions we haven't discussed yet, but you shouldn't find it difficult to work out what they do.

19 GET A$ 26 ZAP: WAIT 5:SHOOT: WAIT 18:PING: WAIT 5:EXPLODE 36 GOTO 14

ASC

The ASC instruction gives the ASCII value of the first character of the string to which it is applied.

For example, the ASCII value associated with 'A' is 65.

So ASC ("A")=65 ASC ("Another Example" )=65

ASC used with the null or empty string "" (no space between inverted commas) gives an ILLEGAL QUANTITY ERROR.

A Way with Words 127

CHR$

CHR$ is the opposite of ASC. It converts the code of a string character to that character.

Thus, taking the previous example, PRINT CHR$ (65) does the same as PRINT "A" We have already discussed CHR$ in some detail in Chapter 7.

VARIABLES

We already know that a number may be stored as a numeric variable and a string as a string variable. Until now we have used single upper case letters, followed by $ if the variable is a string variable.

This was done for the sake of simplicity, but it is not the best programming practice. It is clearer, for example, to use NAME$ as a variable to hold names, rather than just N$. The line:

190 SHIPS = LINERS + FERRIES

is rather more descriptive than:

198 S=L+F

We can use any number of characters (within the limits imposed by the keyboard buffer) for both string and numeric variables, provided we observe these rules.

i String variables must end with $, integer variables with %. 2. All letters must be upper case (capitals).

a Variables may contain numbers and spaces, but the first character ; must be a letter.

4. Variables may not contain characters other than letters numbers and spaces (e.g. !,*='+) except for the $ and % following string and integer variables respectively.

a Variables may not contain at any place within them letters which form any instruction or function used by the computer. For example we can't use TOTAL because it starts with TO (which is used inFOR ... NEXT loops), we can't use FRED§$ because it starts with FRE, and we can't use PALLETS because it contains LET.

128 Chapter 9

Breaking any of these rules will cause a syntax error. There is, however, one more restriction. This does not cause syntax errors, but could cause your programs to give the wrong results. Only the first two characters of a variable are used by the computer.

Thus the line we looked at previously: 199 SHIP$ = LINERS +FERRIES is read by ORIC as 190 SH=LI+FE

It is good programming practice to give your variables full meaningful names, but this is for our benefit, not for the computer's.

SHIPS and SHELLFISH are completely different. things to us, but if used as variables they are both the same thing, SH, to ORIC.

For example:

19 SHIPS = 199 20 SHELLFISH = 1000 30 PRINT SHIPS

would print 1992, not 199. As far as ORIC is concerned the variable SH was set to 1A in line 1, changed to 1099 in line 20 and printed in line 34. Similarly:

19 INPUT"FIRST NAME";NAME1$

26 INPUT"SECOND NAME": NAME 2$

30 PRINT"HELLO "NAME1$" AND "NAME 2$

will have a result you may not expect. Try it and see.

CLEAR

When you start a program using the immediate command RUN, all the numeric variables are set to zero and all the string variables are set to the empty string. You may wish to do this in the middle of a program as well. If so the instruction to use is CLEAR. Try

19 N=6:A$="AB" 24 CLEAR 36 PRINT N+1;A$4+"A"

with and without line 2.

CLEAR also clears all array elements (see next chapter).

CHAPTER 10 The Numbers Game

NUMBERS

It is time we looked at some numbers. As many of you will not be mathematicians, I'll keep this as painless as I can.

SGN

SGN lets us look at the sign of a number. If a number is positive then SGN will be +1; if a number is negative SGN will be -1. If a number is zero SGN will be zero. For example:

129

130 Chapter 10

19 INPUT"WHAT NUMBER";N

20 IF SGN(N)=9 THEN PRINT'NUMBER = #"

30 IF SGN (N)=-1 THEN PRINT"THAT'S NEGATIVE" 4f IF SGN(N)=1 THEN PRINT"A POSITIVE INPUT"

ABS

The ABS function completely ignores the sign, and will always return the absolute, or positive, value of a number. So ABS (-5) = 5, ABS(6) = 6, ABS(-23.6) = 23.6, and so on.

INT

INT ignores the decimal point and numbers coming after it. For example:

INT(5.1)=5, INT(5.6) = 5, INT(5.0) =5 INT always rounds down. Thus INT(-5.1)=-6 (-6 is lower than -5.1).

If you wish to round to the nearest number then simply add §.5 to the number to be rounded. For example in the following program:

19 INPUT"WHAT NUMBER";N 20 N=INT(N+@.5) 39 PRINT N

N will always be printed rounded to the nearest number.

RND

RND gives a random number between @ and 1. This number can equal zero but cannot equal 1; although it can come very close to it. A statistician will tell you that the numbers are not quite truly random, but they certainly appear so to us ordinary mortals.

You must have a number in brackets after RND. This can be any number, but for all practical purposes we need use only RND(1), RND(f) and RND(-1)

RND(1) gives a random number between @ and 1. It gives a different random number each time when used normally. For example each time you RUN the program:

The Numbers Game 131

19 FOR N=1 TO 19 24 PRINT RND (1) 39 NEXT

you will get a different sequence of random numbers.

RND (-1) 'seeds' the random number generator. This means that it determines exactly where in the sequence of random numbers RND(1) will start. Add the line: oe

5 X=RND (-1)

to the program. The first time you RUN the program you will get a set of random numbers as before. When you RUN it again, however, you will get the same set of random numbers.

RND(f) gives a random number. It, however, gives the same random number each time the same RND(Q) in a program is executed. Delete line 5 and change line 28 so that the program is:

19 FORN=1 TO 19 24 PRINT RND (f) 39 NEXT

In the next program the computer uses RND(1) in a guessing game. As RND(1) cannot equal 1, INT (RND(1)* 1) gives a number between f and 9 (because INT rounds down).

19 CLS

26 PRINT'"GUESS A NUMBER BETWEEN 1 AND 16" 30 X=14+INT(RND (1)* 19)

4h: REPEAT

Sh: GET A$

70: IF Y>X THEN PRINT Y"IS TOO HIGH" 8H: IF Y<X THEN PRINT Y"IS TOO LOW" 949: ATTEMPTS=ATTEMPTS + 1

198 : UNTIL Y=X

119 PRINT"WELL DONE "Y"IS CORRECT"

126 PRINT"YOU TOOK "ATTEMPTS"ATTEMPTS"

MATHEMATICS

The next seven sections cover some 'heavy' maths. If this puts you off you can skip them and go on to 'READ, DATA, RESTORE’. If you do decide to do this, you will still have these sections to refer back to should you come across any of the functions they describe in programs.

132 Chapter 10

POWERS

The * sign is used to 'raise to the power' of a number, or ‘multiply a number by itself 'power' times'. So 2*2=2x2=4,or7°4=7x7x7x 7 = 2491. We can also have 2%(1/2) or 2*(@.5) = 1.4142136. Although entered as ~ from the keyboard this sign is displayed as + on the screen.

SQR

A number raised to the power one half is also known as the square root of that number. Square roots can also be found by using the expression SQR on the ORIC. So to print out the first ten numbers and their square roots we could write this:

19 FOR X=1 TO 19 2H PRINT X,SQR(X) 36 NEXT

LOG

LOG gives the logarithm of a number to the base 1f . This means that if 1p *X = Y then LOG(Y) = X. If you went to school before the days of the pocket calculator you probably learned about this logarithm.

EXP AND LN

EXP and LN are mathematical opposites. LN is a 'natural' logarithm. If (e)*X = Y then LN(Y) = X, where e is a number approximately equal to 2.718281828. If you understand this you may want to use the function in mathematical programs. If you don't don't worry. It doesn't have much use except in such programs.

EXP stands for exponential and describes the way many events in nature are controlled. For instance, radioactive decay and population explosions are exponential. If you wish to study these EXP will be useful. If X=LN(Y) then Y=EXP(X).

PI PI is also available on the ORIC. PI or tm is 3.1415927 approximately.

You can use it to find areas and circumferences of circles. The area of a circle is PI x radius x radius. The circumference is 2 x PI x radius.

The Numbers Game 133

19 INPUT"CIRCLE RADIUS";RAD 20 PRINT"AREA ="RAD 2*PI 36 PRINT"CIRCUMFERENCE ="2* PI*¥ RAD

SIN, COS, TAN, ATN

Speaking of PI and circles brings to mind some trigonometry. ORIC allows you to calculate sines (SIN), cosines (COS), and tangents (TAN). The inverse of TAN, Arctan (ATN), is also there. If you know what I mean by these I need not go on. If you are not familiar with these terms, never mind, they are not needed for many programs; except (possibly) for SIN which is quite useful for drawing curves. We will look at this in Chapter 12.

I have to add, for those who are familiar with trigonometry, that ORIC expects angles in radians not degrees. To convert radians to degrees divide by PI and multiply by 189, or, if you like, one degree is approximately 9.174533 radian.

DEF FN

We can define our own mathematical functions. The procedure is to have a line, before the first call to the function, of the form

DEF FN ... (the space is optional)

This means define function. The function name follows the same rules as those for variable names. You must also use brackets after the name. These should contain the variable (or one of the variables) used in the function. After this you put an equals sign and then what you want the function to do.

For example:

1g DEF FNA(X)=54+X

would give a result equal to 5 plus the number in brackets whenever called.

To call a function you simply name it. Thus 2H PRINT FNA(6) would print 11.

uo-J

134 Chapter 10

If you have a function with more than one variable you may still define it. What you do in this case is to define the function in terms of one of the variables and set the other variable or variables as required before calling the function.

For example:

19 DEF FNS(A)=A%2+B 20 B=6

3@ PRINT FNS(2)

44 PRINT FNS(3)

50 B=19

60 PRINT FNS(2)

would print:

19 15 14

Functions are used to do often repeated arithmetic operations. We could, for example, calculate areas and circumferences using functions.

19 DEF FNCIRCUM(RAD)=2*PI* RAD

20 DEF FNAREA(RAD)=PI* RAD*2

36 : REPEAT

49: INPUT"RADIUS";RAD

SO: PRINT"CIRCUMFERENCE ="FNCIRCUM(RAD) 60: PRINT"AREA ="FNAREA(RAD)

70: PRINT

84 : UNTIL RAD=6

94 END

Enter a zero radius to break from the program.

READ, DATA, RESTORE

There are three very useful commands which we have not looked at so far. These are the READ, DATA and RESTORE instructions.

The READ statement reads from a DATA statement, so

19 DATA 19,20,30,40, HELLO 26 READ X,Y,X,A,B$

would be the same as

The Numbers Game 135

1p X=19 20 Y=20 34 Z=30 4h A=49 50 BS ="HELLO"

The data can be anywhere in the program. If the computer encounters a DATA statement whilst executing a program then it just ignores it. You don't need inverted commas round a string in a DATA statement unless you wish to include leading or trailing spaces.

It can be useful to group data such as name and age so that you can see them in the program. Look at the following program.

19 DATA Joe Smith,23

20 DATA Fred Bloggs,48

34 DATA Alice Jones,27

4f DATA Sue Smith,15

1ff FOR K=1TO4

119 READ N$,A

124 PRINT "Name is "N$,"Age is "A 130 NEXT

If you try to READ more data than there are you will get an OUT OF DATA error. Every time you do a READ you get the next DATA item wherever it is in the program.

There are times when you want to start at the beginning again. To do this use the command RESTORE. If you try to read the same lot of data twice without using RESTORE you will again get an 'OUT OF DATA' error.

ARRAYS

A very useful way of handling things in the computer is by arrays. An array is a set of numbers all called by the same variable name but distinguished by a number in brackets.

DIM

To allow the ORIC to recognise an array we could start with DIM statement to 'dimension' it. DIM A(14) will reserve 15 locations called A(f) to A(14). If we don't dimension the array ORIC will reserve 11 locations (numbered from @ to 19) for it.

136 Chapter 10

We could then load the array ie:

19 DIM A(14) 24 A()=6 30 A(6)=43 49 A(14)=127

It is much better to load an array with either an INPUT or DATA statement. For example:

19 DIM A(14)

20 FOR K=6 TO 14

30 READ A (kK)

4f NEXT

50 DATA 1,2,3,5,1,2,2,4,9,15,6,43,8,20, 31

Note how easy it is to refer to a(K) as the Kth number stored in A. RUN this program and enter PRINT A(™) PRINT A(1), PRINT A(2) ete as direct commands.

Array names follow the same rules as do variable names. Thus we could store 25 prices, for example, in an array dimensioned by DIM PRICES (24).

We may also have arrays with more than one dimension. For example:

DIM B(2,2)

represents an array of nine locations, rather like a noughts and crosses grid.

B(9,0)B(0,1)B (0,2) B(1,8)B(1,1)B(1,2) B(2,0)B(2,1)B(2,2)

Each element can contain a number.

You can think of a two dimensional array as name (row, column). However, ORIC could use

DIM BIGARRAY (3,3,3,3,3,)

I don't know what you would want to use such an expression for, but when you do it's available.

The Numbers Game 137

You do not have to dimension multidimensional arrays provided that you don't require any of the dimension numbers to be larger than 19. It is, however, wise to do so.

If you did not dimension array B in the last example, ORIC would have assumed an 1] element square array and reserved space for 12] items instead of the 9 you actually needed. If you did not dimension BIGARRAY ORIC would have attempted to reserve space for 11x]1xllx 11x11 items and would have run out of memory. An array item takes up at least two bytes of memory.

Arrays can hold numbers of strings. Numeric arrays can be real or integer. Integer arrays can hold only whole numbers (integers). Real arrays can hold numbers with figures after the decimal point (e.g. 1.2, 0.34). Aninteger array has the symbol % after the array name. A string array has the symbol § after the array name.

String arrays can hold strings in exactly the same way as numeric displays hold numbers:

19 DIM NAME$ (15)

20 FOR K=9 TO 15

30 READ NAME$ (kK)

4h NEXT

5f DATA PETER ,SIMON,WALTER, TONY , LOUIE

6f DATA JOHN F.,JOHN G.,IAN, ARTHUR, JOHN K. 72 DATA HUGH, JACK,FRANK ,TOM,ERIC, PHIL

84 PRINT NAME$(7)" IS MAGIC"

97 REM LINE 84 IS RATHER SILLY

If we wished we could hold strings in multi dimensional arrays. Single dimensional string arrays however, tend to be the most common.

138 Chapter 10

FUNNY NUMBERS

This section looks like more boring maths. I would, however, ask you to give it some attention.

If you know how ORIC counts you will find a lot of things easier to understand.

let's take any number say 5831]

This may be written as

5x 1600 +8x 100 +3x19 +]

or 5xlfx10x19 +8x 1x10 +3x19 +1

in other words each digit position as we move to the left is multiplied by a higher 'power' of ten, or a number ten times larger than was the one to the right of it.

There is nothing 'magic' about the number 1f. We have grown used to working with powers of ten simply because most of us have ten fingers (eight fingers and two thumbs if you want to be pedantic).

Digital computers like ORIC, however, have only two 'fingers' or two things to count with. A signal may either be there or not there. A switch may be open or closed. A condition may be 'true' or 'false'. All this is represented by the digits 1 (on) or @ (off).

Ultimately ORIC sees everything in terms of an enormous number of ones and zeroes. These are all it can recognise.

We count in decimal, using ten counting symbols or numbers (@ to 9). ORIC counts in binary, using only two counting symbols (f and 1). So how can it count with only two symbols?

Well @ (decimal) = @ (binary) 1 (decimal) = 1 (binary)

The Numbers Game

139

But what does ORIC do when it reaches two? It has no more symbols to use, and so it must do what we do when we reach ten and run out symbols. It moves one space to the left.

So 2 (decimal) = 3 (decimal) =

ORIC has run out to the left.

4 (decimal) = 5 (decimal) = 6 (decimal) = 7 (decimal) =

Thus 111 (binary) is:

1x2x2 +1x2 +]

19 (binary) 11 (binary)

of symbols again; so it must move another space

109 (binary) 191 (binary) 119 (binary) 111 (binary)

which equals 7 (decimal)

I hope you see the pattern which is emerging

1111 (binary) is:

1x2x2x2 +1x2x2 +1x2 +]

which equals 15 (decimal).

Each column moved to the left is a power of two (instead of a power of ten) greater than the one to the right of it. Thus they go up 1,2,4,8,16,32

and so on.

A single binary digit (1 or @) is called a bit for short. One of ORIC's memory locations holds eight bits or one byte.

140 Chapter 10

Thus the maximum number one memory location can hold is: 11111111 (binary). This equals:

1xl +1x2 +1x4 +1x8 +1xl6 +1x32 +1x64 +1x128 (left hand column)

that is 255 (decimal). Thus a typical memory location could hold say the binary number 16160111. This equals 1+(1x2)+(1x4)+(Bx8)+(Ox16)+(1x32)+(8x64)+(1x128) = 1+2+4+32+128 = 167 (decimal). It is very inconvenient for us to write out numbers like 11911911; so we represent them with what are called hexadecimal numbers. Hexadecimal numbers are simply a shorthand way of writing binary numbers. They are

a convenience to us ORIC uses only binary.

To get a hexadecimal number we group the binary number into lots of four. Thus a single byte, which is 8 bits, is grouped in two lots of four.

i.e. 1911 611

Each of these groups will be represented by a_ separate character easy for values up to nine:

OndB=0 Opp1=1

19h1=9

For the binary numbers from 11@ to 1111 we use the symbols A to F respectively.

The Numbers Game 141

So 11 (decimal) = 1911 (binary) = B (hexadecimal) 16 (decimal) = 0001 A000 (binary) = 10 (hexadecimal)

ORIC can work with hexadecimal numbers up to FFFF. To indicate a number is hexadecimal put the symbol # in front of it.

Thus PRINT#FFFF would give 65535 PRINT#1A would give 26.

To convert from decimal to hexadecimal use HEX$. For example PRINT HE X$(26) gives #1A. As neither # nor A can be printed as numbers HEX$ generates a string. HEX$(f) generates the string "#" in the V1.0 machine and the string "#0" in the V1.1 machine.

AND, OR We saw AND and OR in Chapter 8, where they let us make decisions based on two or more conditions. AND and OR are also logical functions

which operate on binary numbers.

For example:

1 AND @ = 9 f AND 1 = @ f AND 6 = @ 1 AND 1 =1

Note that 1 AND 1 is not the same as 1 + 1! Also:

1OR1=1 fORI1=1 1OR # =1 fAORA=9

AND and OR operate a bit at a time. Thus: 1911 AND 1191 = 191 (all binary) If you don't understand this don't worry. You can write all your programs

without logical operators. They give, however, one more weapon in your armoury should you decide to employ them.

142 Chapter 10

For example:

19 INPUT"NUMBER BETWEEN @ AND 7";N% 20 N=7 ANDN%

will ensure N is a whole number between 1 and 7 whatever is entered. 16 FOR N=1 TO 29 26 PRINT 18+5%*(N AND 1) 30 NEXT

will print 19 when N is even and 15 when N is odd.

CHAPTER 11 Sound It Out

ORIC has four predefined sound commands. These (I hope) are self explanatory:

ZAP PING SHOOT EXPLODE

144 Chapter 11

One of the good features about ORIC sound is that you only need the instruction to start the sound going. While the sound is being generated the program can be doing something else. You can have a bullet going across the screen while SHOOT is sounding.

If you want a series of predefined sounds you need to put a delay after each, to give it time to finish.

Thus:

16 FOR N=1TO19 20 PING 36 NEXT

will give only one ping, while,

19 FOR N=1TO 16 26 PING: WAIT 14 36 NEXT

will give ten pings.

PLAY

The predefined sounds, useful though they may be, are only a very small part of ORIC'S sound repertoire. ORIC has three sound channels, which means it can play three different sounds at the same time. Each of these three sound channels can generate either pure (musical) tone or can be mixed with noise to give special effects.

Before experimenting with ORIC'S sound ensure the keyclick is off. CTRL F controls the keyclick. If you get a sound on continuously then CTRL F followed by any key (RETURN is usually best) will normally switch it off.

The PLAY command switches the three sound channels on and off and determines which channels can be combined with the noise generator.

PLAY does not by itself make any sound. It enables (switches on) channels which can then be used by the instructions SOUND and MUSIC. The PLAY instruction most commonly used is PLAY §,0,0,0. This switches off all sound.

When the machine is first switched on, channel 1] is enabled. No noise mixing is enabled on power up.

Sound It Out 145

The format of the PLAY command is: PLAY TE,NE,EM,EP where TE, NE, EM, EP are all numbers.

TE stands for tone enable and is a number between @ and 7.

The next table shows how TE values control the tone channels.

Te CHANNEL 3 CHANNEL 2 CHANNEL 1 off off off ] off off on 2 off on off 3 off on on 4 on off off 5 on of f on 6 on on of f 7 on on on

Thus, for example, when TE = 3 channels 1 and 2 are enabled; when TE = 7 all channels are enabled.

Compare the effect on the channels with the binary numbers in the previous chapters. Can you see a connection? Try representing 'off' by @ and 'on' by 1.

NE stands for noise enable and selects the channels which may have noise mixed in with the tone.

NE follows the same pattern as shown in the table for TE i.e. when NE = 3 (for example) noise may be mixed with tone in channels 1 and 2.

We will return to EM and EP shortly. Keep them at zero in the meantime.

SOUND

If a channel is enabled, the instruction SOUND causes a sound to be generated by that channel. The instruction is of the form:

SOUND C,P,V

where C, P and V are numbers representing Channel, Period and Volume. |

146 Chapter 11

C selects the channel on which the instruction operates.

When C is 1, Channel 1 is used for pure tone.

" WoW 2; " ? " " " "W "

W WoW bP ul 3 " " " " "

When C is 4, Channel 1 is used for tone and noise mixed.

" hh 5, W 2 " " "W " "W " "

" wo 6, W 3 " " " " " " "

V selects the volume. The normal range is from ] to 15. When V equals 1 the sound is fairly quiet; a value of 3 or 4 is good for experimentation; a value of 6 or 7 is loud enough for most purposes.

P selects how high or low the note is, but in a rather odd way. P stands for period and not (as you might expect) for pitch. This means that the smaller P is, the higher the sound that is generated. A value of 238 is about mid range on a piano key board. The lowest note is generated when P=4996. The highest I can hear is generated when P24,

The next program lets you try different values of P. Pressing any key stops the sound and lets you enter another value. A value of zero stops the program.

1p REPEAT

24 INPUT"PERIOD NUMBER"; P 3f IF P=@ THEN STOP

4f PLAY 1, @, 0, 2

54 SOUND 1, P, 4

60 GET A$

70 PLAY @, 0, 0, 0

89 UNTIL @

To try the effect of introducing noise, change line 49 and 5 to:

4 PLAY 1, 1, 0, 0 54 SOUND 4, P, 4

This program may be extended so that three period numbers can be entered and three channels (with or without noise) sounding at once. Experiment with this for yourself.

Sound It Out 147

ENVELOPE

You will recall that I promised to come back to the EM and EP parameters in the PLAY instruction. These are used when, instead of a sound at constant volume, we want a sound which varies in volume at different stages.

For example we may want a sound to build up gradually in volume and then die away quickly (slow attack, fast decay). Or we may want a sound which starts at maximum volume and dies away gradually (fast attack, slow decay).

EM can be used to select one of seven 'envelopes' with varying attacks and decays.

EP is the envelope period measured in milliseconds (thousandths of asecond). Do not confuse this timing with that of the WAIT command, which is in hundredths of a second.

The next diagram shows the seven envelopes available. The period length is also shown. Modes 1] and 2 stop the sound after half a period. Modes 3 to 7 are continuous.

kK Period —————*

Mode 1

| , MAT mm

| i |

148 Chapter 11

If you specify an envelope in your PLAY command then any subsequent sound will be controlled by that envelope. You may choose the volume of your sounds as you did previously, but if you wish you can specify a volume figure . This lets the PLAY command control your volume and tends to make the envelope more effective.

You can use the next program to select envelope modes, sound periods, and noise or pure tone. This is a useful program for investigating sound effects. You could also make the envelope period keyboard selectable. Pressing any key stops the sound and allows another choice. Selecting envelope mode zero stops the program.

1g REPEAT

26 INPUT"ENVELOPE MODE";E

39 INPUT"SOUND PERIOD"; P

4g INPUT"DO YOU WANT NOISE (Y/N)", Y$

50 IF Y$="Y" THEN C=4:N=1 ELSE C=1:N=9 6f PLAY 1,N,E, 500

76 SOUND C,P,4

80 GET A$

90 PLAY 6,0,0,0

199 UNTIL E=¢

The SOUND instruction is useful for noises and special effects. Here are a few to try:

19 REM CHOO-CHOO TRAIN

20 REPEAT

39 PLAY 1,1,2,50

4$ SOUND 4,19,0: WAIT 15

50 UNTIL KEY$¢ <>": REM EMPTY STRING

60 PLAY 6,0,0,0:REM PRESS ANY KEY TO END

19 REM RUNNER

20 REPEAT

34 PLAY 1,1,1,100 |

4g IF PR=8 THEN PR=14 ELSE PR=8

5@ SOUND 4,PR,0: WAIT 26

60 UNTIL KEY$ <>"":REM EMPTY STRING

70 PLAY 0,0,6:REM PRESS ANY KEY TO END

Sound It Out 149

19 REM DRUMS

29 REPEAT

34 : FORN=1TO8

4f : PLAY 1,1,1,35

54 : SOUND 4,35,0

60 : WAIT 5

70 : NEXT

8) WAIT 1p

98 : FORN=1TO2

190 : PLAY 1,1,1,300

119 : SOUND 4,340*N, @

126 : WAIT 64

130 : NEXT

149 UNTIL KEY$ <>"":REM EMPTY STRING 158 PLAY 9,0,0,0'PRESS ANY KEY TO END

MUSIC

The SOUND instruction is useful for sound effects like the ones we have just heard. It could be used for playing tunes, but ORIC has another instruction, MUSIC, which is provided for this purpose.

The MUSIC instruction takes the form:

MUSIC C,OC,N,V where C, OC, N and V are numbers. C is the channel select, and is a whole number between 1 and 6. This works in the same way as the channel select in the SOUND instruction. OC stands for octave and is a whole number between 9 and 6.

N stands for note and is a whole number between ] and 12.

V stands for volume and is a whole number between 9 and 15. This works in the same way as the volume select in the SOUND instruction.

For the MUSIC instruction to have any effect, the channels it uses must be switched on. This is done by the PLAY instruction. The length of the note may be determined by a WAIT instruction. The note may be switched off by using the PLAY instruction to switch off the relevant channel. PLAY 9,4,0,6 switches off all sound.

150 Chapter 11

Before we look at MUSIC in more detail, try this program. It lets you use ORIC as an organ. Please make sure the keyclick and capitals shift are switched off before you RUN the program. Pressing the SHIFT key with the alphabetic keys gives lower notes.

19 REPEAT

26 GET A$: A=ASC(A$)

36 A=ABS(A-32):IF A>83 THEN A =83

4h OCT%=A/12

SA NT=A-12*OCT%+1

60 PLAY 1,0,8,¢

76 MUSIC 1, OCT%,NT,5

8 WAIT 59

99 PLAY 6,0,0,0

199 UNTIL A=@'SPACE BAR STOPS PROGRAM

This is only the bare bones of a program to let you hear all the notes. Once you are happy with the MUSIC instruction you can expand the program so that the notes are played in the order that keys are placed on the keyboard, so that you can select volume and note length and so that all three channels may be selected at the same time.

To get a 'tremulo' effect replace lines 6f and 7 by

6H PLAY 1,9, 4, 100 7 MUSIC 1,OCT%,NT, #

Sound it Out 151

MUSICAL THEORY

If you are going to play tunes on ORIC you will need to know a little musical theory. If you know all about music you can skip over this section very quickly.

Even simple tunes can look daunting on sheet music. For a start there are usually two sets of five lines joined together.

P [y== 5) eC, a, | ST VN SN PY a ASE Fe A NT A Ca ee Ba |e ee a De ee a Re CN, i a dd SE A FE AS EN. A I OR A as SS en SP Ae of, ~_—

rac’ eT - TE WA OI LET IN arn eae he OO Fe ee a a ey a Ee OE GY

A ¢f | It[tg__ |g |

; 0 You will see that the top set of lines starts with the symbol (5 » while the bottom line starts with the symbol'®):. oy

é, is called the 'treble clef’;

* is called the 'bass clef’.

152 Chapter 11

HARMONY

As you probably know the symbols of the form ¢ stand for musical notes. However, you will see that most of the notes in this tune are of the form ,

A lot of the sheet music you come across will have this sort of multiple note. This is because the tunes are written so that they can be sung in 'harmony', i.e. two or more people sing and each sings different notes. You have probably heard harmony groups such as ‘barber shop' quartets. The multiple notes are a shorthand way of writing the music. You could write the tune as:

Voice 1

The tune has three 'voices'. ORIC has three channels to play them on.

Sound It Out 153

PITCH

The five lines on which sheet music is written are called the stave. Again you may know that notes written near the top of the stave are of a higher pitch than those written near the bottom. For convenience notes are given 'names' which determine their pitch. These names consist of the letters A to G. Thus the position of a note on the lines can be represented by a letter.

You will probably have heard of the musical scale: doh, re, me, fah, soh, la, te, doh

The eight notes of the scale are called an 'octave'. The scale of 'C major' is an octave which starts and ends with C. That is:

C= doh, D = re, E = me, F = fah, G = soh, A = la, B = te, C = doh,

Similarly a scale of A starts and ends with the note A.

154 Chapter 11

There is, however, a complication. Not all of the steps in frequency (changes in pitch) between the notes are the same. For example the change in pitch between the notes B and C is only half of the change in pitch between C and D.

To allow for this a scale or octave is split into twelve 'semitones'. These are:

A A#f or Bo B 2s C# or Db D D# or E> a F F # or G> G G# or A>

The symbol # means 'sharp' and » means 'flat'. So G# is a semitone higher than G and Ab is a semitone lower than A. G# is the same note as Ap .

I shall not go into scales in detail suffice it to say that the scale which sounds 'right' to most of us is the major scale. This goes up in semitone steps as follows:

doh (2 steps) re (2 steps) me (1 step) fah (2 steps) soh (2 steps) la (2 steps) te (1 step) doh

so that the scale of C major is C,D,E,F,G, A,B,C. And the scale of G Major is G, A,B, C,D, E, F#, G.

Work out other scales for yourself. You will see that only the key of C Major has no sharp or flat notes.

Sound It Out 155

In the tune we looked at earlier, you will see that the line repre- senting F has the 'sharp' symbol #. This means that notes written on this line should be played as F# rather thanF. You may be interested to know that the tune is written in the key of G Major, but this knowledge is not essential in order to convert the music into a computer program.

ORIC gives you seven full octaves numbered from (lowest) to 6 (highest). Each octave starts at note C (lowest) and ends at note B (highest). Each octave, as we know, contains twelve semitones. Thus the third parameter (N) of the MUSIC instruction is a number from 1 to 12, each number corresponding to a note:

Note N Parameter

B (highest) 12 Ad ll A 19 Git

G

F #

FE

E

D#

D

CH

C (lowest)

Bene FSF Hwa N WD

156 Chapter 11

The next diagram gives the ORIC numbers corresponding to positions on, above and below the staves. Where a sharp or flat is written on the line or the space at the start of the line, then all the notes on that line or space should have one added to their numbers (for sharp) or one subtracted (for flat).

Octave 12 i A 10 G 8 F 6 6 E 5 D 3 c B 12 A 10 G 8 F 6 E 5 D 3 B C 12 A 10 G 8 F 6 4 E 5 C 7 : 1 B 12 A 10 G 8 F 6 3 E 5 D 3 A 10 G 8 mes 6 2 E 5 D 3 C B 12 | A 10 G 8 F 6 1 E 5 D 3 B C 12 A 10 G 8 F 6 0 E D 3 5 C 1

Sound It Out 157

Middle C is so called because it is the note C near the middle of a piano keyboard.

Octave 2 Octave 3

bitueth aly

L Middle C

If there is a sharp or flat symbol affecting a note on the stave, then the corresponding note in other octaves will also be affected. For example in the tune shown F is set to F#. This means that F will be played as F#f, and will have note number 7 instead of 6, in all seven octaves,

In some tunes you will find sharp and flat symbols written in the middle of the line. You will also find the symbol:'4 which converts a note to its 'natural' value if it is normally sharp or flat. Symbols in the middle of the stave are called 'accidentals' and affect any notes on the line or space on which they occur up until next vertical line (that is until the end of the 'bar' in which they appear).

DURATION

We have looked at the pitch of the note. Now we will consider its duration.

It is normal to define a'single beat' note as E (this is called a crotchet).

A 'half beat' note is | (a quaver).

A ‘quarter beat' note is 5 (a semiquaver).

158 Chapter 11

Sometimes the tails of the notes are joined together, i.e.

J is two 'half beat' notes. J is two 'quarter beat’ notes.

A ‘double beat' note is written J (minim). A 'four beat' note is written o(semibreve). A dot after the note increases the duration of the note by half as much again for example

(" is 'one and a half beat' note.

P" is a 'three beat' note. Sometimes you will see notes linked by a curved line. If the notes are of the same pitch and next to each other they should be treated

as one single note. If they are different pitches, or if there are notes between them, they should be treated as two separate notes.

Finally we come to 'rests'. As the name implies these are pauses in the music. There are two of these:

{ pause for a single beat

7 pause for half a beat.

TIME

The figure after the clef at the start of the music gives the 'time', or the number of beats in a bar. Usually this is ; ; : ; : , or ; , although other values are possible. ; time is sometimes denoted by C or &. For the sake of simplicity take ; as being the same as : . There are

differences, but we are not delving too deeply into musical theory.

The number of beats in a bar should equal the top figure. Thus:

time has two beats to the bar;

time has three beats to the bar;

Fre FW Fh

time has four beats to the bar.

Sound It Out 159

All complete bars have the same number of beats. This is a useful check to make sure you have not forgotten a note or used an incorrect note length when programming a tune.

PROGRAMMING METHOD

The first thing I do when changing sheet music into a computer program is to find the shortest note in the music. This could be a quaver or a semiquaver. I then set a variable TIME equal to the time, in hundredths of a second, that I wish the shortest note to last. All the other notes will last for a multiple of this value.

For example if the shortest note were a semiquaver and I set TIME equal to 1, then a full beat would take 4 x 1 = 4 hundredths or

0.4 of a second. If the tune were in : time a bar would play in 1.2

seconds.

The advantage of this is that by varying the value of TIME, which is set at the beginning of the program, I can speed the tune up or slow it down until I get the speed I want.

Let's look at the tune we started with. We shall take this up to the end of the first full bar. Once you have seen how to change musical notation into program instructions you use the same technique for a whole tune.

160 Chapter 11

Let's make the two treble voices channels 1 and 2 and the bass voice channel 3. The shortest note in this example is a quaver; so we will make time = 17, giving a time of about one second for a bar.

Thus the first line is: 19 TIME =17

Split the music up into periods each equal to the shortest note.

aco >

2 ie ae,

i wt wl i

—s

In the first of these periods voices 1 and 2 are both playing the note G above middle C, which is octave 3 note 8. Voice 3 is silent.

Thus the next instructions turn on channels 1 and 2 and play the selected notes,

20 PLAY 3,0,0,0 3 MUSIC 1,3,8,5 4 MUSIC 2,3,8,5

This is going to remain the same for two periods.

Sound It Out 161

Thus the next line is: 50 WAIT TIME*2

Where the next note is the same as the last one, but we want to hear them as two separate notes, we have to turn the appropriate channel off and on again for a short time. Where the next note is different we don't have to do this. Thus in the next period we don't have to switch on channels 1 and 2. We do, however, have to switch on channel 3. Thus the next lines are:

6f PLAY 7,0,0,0

76 MUSIC 1,3,12,5 89 MUSIC 2,3,3,5 99 MUSIC 3,2,8,5 199 WAIT TIME*2

Next we have to switch channels 1] and 2 off for a short time and back on again to get distinct notes. Channel 3 remains on. Thus:

119 PLAY 4,0,0,0: WAIT 2 126 PLAY 7,0,0,0

13@ MUSIC 1,3,12,5

149 MUSIC 1,3,3,5

15@ MUSIC 3,2,8,5

160 WAIT TIME*2-2

In line 169 we adjust the length of note to allow for the small delay in line 119.

The next two TIME periods are the same again. Thus:

170 PLAY 4,0,0,0: WAIT 2 184 PLAY 7,0,0,0

19H MUSIC 1,3,12,5

204 MUSIC 2,3,3,5

21 MUSIC 3,2,8,5

224 WAIT TIME*2-2

Finally we have to switch all sound off:

234 PLAY 9,0,0,0

162 Chapter 11

You could go through an_— entire tune’ in_ this fashion, but this would be rather tedious. Let's see if we can avoid repeating all these MUSIC and PLAY instructions.

If a channel is switched off we can set a MUSIC command to play a note on it. The command has no effect. This means that we could have three MUSIC commands at every stage even though not all the channels are played.

Thus the program could use a standard pattern of PLAY, MUSIC and WAIT instructions, and read all the instruction parameters from DATA statements. Thus this program does the same as the last:

19 TIME =17

20 RESTORE

36 READ A'TOTAL NUMBER OF NOTES

4h FOR K=1 TOA

56 READ Cl,S1,€1,P1

60 READ £1, T1,NI1,Vi-L2, 72,N2,V2,L3,.13,N3, V3 70 READ PERIODS

84 READ C2,S2,N2,P2

99 WAIT TIME*R -2

199 PLAY S,T,U,V:WAIT 2

11p IF KEY$ <>"" THEN PLAY $,0,0,8:STOP

120 NEXT

134 DATA 4,3,0,0,0,1,3,8,5,2,3,8,5,0,1,0,2,3,0,0,0 1aO-DATA: 7, 0.0505 351255 255555 5 28s 254505050 150 DATA: 7.0005) 5 Sy 255s 25.0 59 5 GD 160 DATA 7,0,0,0,1,3,12,5,2,3,3,5,4,2,8,5,2,0,0,0,0

This program does not look much shorter than the one before, although it is probably a little quicker to key in. If, however, we were playing 499 notes instead of 4, the advantages of the second method would be rather more obvious. Each note added requires only one extra line of data, plus an alteration in the first data item.

The number of data items could be reduced by putting quantities which remain constant (envelope mode, envelope period, volume, channel select) into lines 5f to 1ff. As it stands, however, the program is more versatile. It allows us to vary the volume of parts of the tune for all channels or for each channel; it allows us to change the envelope mode, possibly to introduce tremulo; it allows us to switch noise onto any channel for special effects.

Sound It Out 163

Line 119 lets us stop the program by pressing any key.

Adapt this program to write tunes of your choice. Experiment with different effects.

CHAPTER 12 ORIC The Artist

LOW RESOLUTION GRAPHICS

We have already seen that the ESC key followed by I, K, M or O, or CHR$(27) followed by "I", "K", "M" or "O", create the alternate character set. These alternate characters can be used to draw low resolution, or 'chunky' characters on the screen. We saw alternate characters used to print a shape on the screen in Chapters 1,7, and 9.

164

ORIC The Artist 165

ALTERNATE CHARACTER SELECTION

If you are building up a picture using chunky graphics, you can select the characters you require for each part of the picture by referring to Appendix A.

It is, however, often easier to work out what a character should be than to try and find it on a list. Fortunately the procedure to do this is fairly straighforward.

To generate alternate characters, ORIC divides a character position into six. The divisions are not quite equal.

V1.0 Machine V1.1 Machine

166 Chapter 12

The alternate characters are created by inking in selected areas and leaving others at paper colour. Let's take an example:

V1.0 Machine V1.1 Machine

I have numbered the areas 1, 2, 4, 8, 16, 32. Can you work out the significance of these numbers? Look at binary notation in Chapter 10 and work out the binary equivalents if you need a clue.

Just follow this simple procedure to generate whatever character you want:

Ls Draw the character position, divide it up and number the areas as | have done.

2. Select the areas you want to be inked in.

ae Add up the numbers in the selected areas. In the example I have given, 1+ 8+ 16= 25

4. Add 32 to this number (ASCII codes of normal characters start at 32). In the example given the result would be 25 + 32 = 57.

The number you end up with will be equal to the ASCII code for the alternate character you want.

ORIC The Artist 167

To print the chosen shape on the screen we could either use the ASCII code directly:

PRINT CHR$ (27)"I" CHR$ (57)

or we could look up Appendix A to find the character which corresponds to that ASCII code. In the example chosen the character '9' has ASCII code 57. Thus we could use:

PRINT CHRg$ (27)"I9"

Practise using this procedure. You will find it becomes routine fairly quickly.

When you are printing a number of characters merged together to form a picture you will usually find that it is more convenient to define a string containing all these characters. You may remember we did this in Chapter 9.

LORES 1

It is awkward in the V1.@ machine to place a character in a selected position on the screen using PRINT. It is much easier to use PLOT.

It would also be more convenient if we did not need to use CHR$(27)"1....." to generate alternate characters.

ORIC allows us to use PLOT and to miss out CHR$'27)"I" by providing a screen display mode known as LORES 1. In LORES 1 all characters are normally printed as alternate characters and do not have to be specified as such.

We looked at LORES @ in Chapter 7. LORES 1 is similar in many ways, but rather more useful (in my opinion).

To put ORIC into LORES 1 mode, use the instruction LORES 1 either as an immediate command or in a program. This instruction clears the screen and sets the default colours of black paper and white ink.

If you use CLS or CTRL L in LORES 1 the machine goes back into TEXT mode. Clear the screen with the instruction LORES 1.

As with LORES §, you can use column @ in LORES 1 provided you do not wish to change the ink colour.

168 Chapter 12

The next program generates a shape on the screen which could (with a bit of imagination or the wrong pair of spectacles) be taken for a flying saucer. You can move the saucer round the screen using the cursor control keys. Pressing the space bar stops the program.

To move a shape on a screen we print spaces over the shape delete it and then print it again in a position just next to where it was before.

19 LORES 1:PRINT CHR$(17)

20 SAUCER$ = CHR¢$ (7f)+ CHR$ (87) + CHR$ (36) 39 X=18:Y=13

4f: REPEAT

50: PLOT X,Y,SAUCER$

60: GET A$

70: IF ASC (A$)=8 AND X>1 THEN DX=-1 88: IF ASC (A$)=9 AND X<36 THEN DX=1 99: IF ASC (A$)1l1 AND Y>@ THEN DY=-1 104 : IF ASC (A$)=18 AND Y<25 THEN DY=1 119 : PLOT X,Y," ": REM THREE SPACES 126: X=X+DX:Y=Y+DY:DX=f:DY=9

130 : UNTIL ASC (A$) = 32

149 CLS:PRINT CHR¢$(17)

Note this program will work with both V1.1 and V1.9 machines, but as a result does not use the full screen of either. If you have the V1.1 machine you can, if you wish, use PRINT {fa instead of PLOT.

In Chapter 7 we saw that we can use PLOT commands to put colour attributes on the screen. We could make the saucer turn red when it enters the right hand side of the screen by adding the line:

125: IF X>18 THEN PLOT X-1,Y,1

You can print normal characters in LORES @ if you wish to mix text and graphics. Attribute 8 will switch to the standard set and attribute 9 will switch back to the alternate set. Try:

19 LORES 1

24 PLOT 4,13,8:PLOT 5,13,"STANDARD":PLOT 13,13,9