I ORIC-1: Z Basic I Programming 2 Manual
I ORIC-1: Z Basic I Programming 2 Manual
z Basic
i Programming
2 Manual
by John Scriven
1
c-
Edited and produced for Oric Products International Ltd. by Sunshine Publications
Ltd., London.
4
Cd 0 Sunshine Publications Ltd. 1983
4
Contents
CHAPTER 1
I;;ii
-- Introduction Page 5
CHAPTER 2
Setting the computer up Page 9
A guide to putting your Oric to work
4 CHAPTER 3
L -
4 3
L
0RIC Manual
CHAPTER 10
5
Sound Page 95 -
The Oric has four separate sound channels and &
four predefined sounds for games
c
CHAPTER 11
Saving programs on tape Page 103 *
A guide to the cassette operating system
5
CHAPTER 12
Better Basic Page 109 *
With a bit of practice and care you can improve
your Basic programs
CHAPTER. 13 s2
CHAPTER 14
Using a printer Page 131 b
-
CHAPTER 15
Oric Basic Page 135 k
A list of all Oric’s Basic commands
APPENDICES
b-
A Memory map Page 145 =
B Control characters Page 146 6
C Attributes Page 147 -
D ASCII chart Page 148 -‘;
E Binary/Hex/Decimal table Page 149 -”
F Pin output chart Page 151 6
G Derived functions Page 152 -
H Text screen map Page 154 6
I High resolution screen map Page 155 -’
J Error codes Page 156 fk
K The 6502 monitor Page 158 -
Index Page 165 G
-
4 I
-
CHAPTER 1
Introduction
=a
_-
;;i 1 Introduction
n
TV MAINS
LEAD
CENTRONICS
PRINTER
INTERFACE
EXPANSION
PORT
9V DC R G B MONITOR
POWER
IN
f-l
When you unpack your ORIC, you will notice that it has a key-
board, to enter information, and several sockets at the back. It needs
these to communicate with the outside world. First of all, connect the
power supply according to the instructions on the lead and push the
small plug into the socket at the back. ORIC only needs a low D.C.
voltage so never plug it directly into the mains.
The keyboard provides an input, but you will not see the results of
any key presses unless you plug it into a T.V. Using the connecting
lead, plug one end in the back of ORIC and the other end to the
U.H.F. aerial socket on your T.V. Most T.V.‘s purchased in the last
15 years will operate satisfactorily, although a black and white T.V.
will only give you shades of grey.
Now the moment you’ve been waiting for - switch on the mains,
and tune your T.V. to approximately Channel 36. If you have a
rotary tuner, this won’t be difficult: otherwise tune in a spare button.
When you are in the right place, you should see the following picture
on your T.V.
11
ORIC Manual
If you look at the back of ORIC you will see some other sockets.
The setting-up diagram shows you their particular function. Some of
them will be useful fairly soon, some will be used as you expand your
system.
The most important socket is for the cassette recorder. Almost any F
make will do - cheap portables are better than expensive hi-fi -
models. When you type in a program and want to save it, ORIC will
turn it into a sound signal that can be recorded. This can be reloaded
whenever you wish and you won’t need to type it again!
You need a lead with a three or seven pin DIN plug on one end, and
either a DIN plug or 3 Smm jack plugs on the other, according to the
sockets on your recorder.
Next to the cassette socket is the R.G.B. colour monitor socket.
The signal that comes out of ORIC, through the T.V. socket, has to
be coded into a U.H.F. signal for your television set, which then
decodes it. A monitor is like a T.V. set without the sound and tuning
section. If you use ORIC with a monitor you’ll get an even better
picture. The signal does not have to be encoded and decoded.
If you want to make a permanent record of what ORIC prints on r’
the screen, you can connect a printer via the next socket. To make it
easier, most manufacturers make printers that use standard plugs.
ORIC will connect to any printer that has a Centronics interface.
The last socket is the largest, and provides ways of connecting up
ORIC to many other pieces of equipment.
Some examples are: - extra memory, games cartridges, joysticks
and, of course, the modem. This device will allow ORIC to
download PRESTEL pages, or even programs, and to send and
receive electronic mail via the PRESTEL MAILBOX system.
Underneath ORIC is a little button that you may need a pencil to
12 4-
u
7!9
Chapter 2 Setting the Computer Up
?
operate. This is a RESET button and is an emergency device to get
you out of never ending loops. It does not switch off the power but
;;i only stops execution of a program. It could also be referred to as a
- warm start button, as it does not destroy the contents of the memory.
i
L
i
L
13
CHAPTER 3
Programming in Basic
3
3
-
-ii 3. Programming in BASIC
-
- First the bad news - ORIC doesn’t understand English. But now the
good news - you don’t have to learn a complicated electronic lan-
guage, because ORIC speaks a language called BASIC, (Beginners
All-purpose Symbolic Instruction Code). This language was inven-
ted in 1964 to help people to write computer programs easily. If your
machine is switched on, we’ll see how easy this is.
Type
PRINT “HELLO”
+
- 17
0 RIC Manual
18
Chapter 3 Programming in BASIC
words, somewhere between one and two hundred. There are several
different versions of BASIC around, just as there are several dif-
ferent versions of English.
For example, English spoken in London is not quite the same as
PA
-
that spoken in New York. If a Londoner talks about the pavement,
he means what an American would call the sidewalk. This is why we
>
1 have to speak correctly to ORIC, or else we will be given error mess-
-
ages.
1
- Type
PRINT “5”
I-r
C
1
-
19
ORIC Manual
PRINT 4 +3*2 will not give you 14, but 10 because * is more
important than + . Here is the order of priority, most important at
the top, least important at the bottom.
0
^ (“to the power of”)
*,/
+,-
Operators on the same line have the same priority. This is a way of
using ORIC as a calculator.
Enter these examples so you understand about priorities.
PRINT 2*3*4
PRINT 4 + 3*2
PRINT 4*3 + 2
PRINT 4/2 + 3
PRINT 2 + 3/4
PRINT 3 + 4^12
PRINT 3 - 4^2
PRINT 2 + 4^3*2
If you are uncertain then put the part of the argument (equation)
you want calculated first in brackets. e.g.
4+3*2=10
but
(4 + 3)*2 = 14
*********
20
Chapter 3 Programming in BASIC
Type
PRINT H
and see what happens You should get a 0. Of course it
can’t be a number - or can it? Type
-r
- LETH = 4
Now type
-r
-, PRINT H
This time ORIC knows that you’ve set H equal to 4 (just like in
algebra). H is called a variable. ORIC will remember this until you
either change the value of H, or type CLEAR, or switch off. Try this
with other letters, then type CLEAR and see if ORIC has forgotten
-r
-- them. You can use more than one letter, so AB could have a different
value to A or B. You can also have A5 or A6. ORIC will accept varia-
bles of more than two characters in length, but will only recognize
the first two.
3
C
Try:-
LET JOHN = 36
-r
- LET JOCELYN = 28
-i;
C
Now type
PRINT JOHN
PRINT JOCELYN
4
- You should get 28 each time, because ORIC has only remembered
a variable JO, which although originally set to 36, was reset to 28.
Enter
4 PRINT 4*JO
C
LET N $ = “BLAKE”
+
- Now type
PRINT N$
21
ORIC Manual
PRINT N$;FP$
It is possible to add strings together to make a new string.
Type
LET A$ = N$ + FP$
then PRINT A$. This is called concatenation. Try using CLEAR
again to check if it clears string variables too.
Note:- You don’t have to use LET to assign values to variables.
i.e. A=10 is the same as LET A= 10 to ORIC.
When we were talking about number variables, you probably
discovered that decimal fractions could be held in variables, as
well as whole numbers.
Try:
LET X = l/3
PRINT X
You should get 0.333333333
(ORIC can hold numbers between 2.93874x10 -39 up to
1.7O141x1O38). For further explanation see Chapter 6.
Simple letters should be called floating point variables. If the
letter, or pair of letters, is followed by a % then it is called an
integer or whole number variable e.g. A% = 4762. These can be
between - 32768 and + 32767. In general integer variables can be
handled faster than floating point variables.
So far, we’ve only used ORIC to give us results in a simple
way. This is called immediate execution or calculator mode. The
usual way to use computers is to get them to store a sequence of
instructions and to use this program when we require.
22
Chapter 3 Programming in BASIC
23
ORIC Manual
*********
DECISIONS
So far we’ve used the computers to work through all the num-
bers without making any decisions. Let’s use ORIC’s brain a little
more. Add these lines. (Feminists may wish to alter the wording of
lines 80 + 150!)
You will probably see that the program only tests for “Y” as a
reply. “OK” or “YEAH” or “JUST ABOUT” would be counted c-
7
Up till now all you’ve been printing has been in capitals. You’ve
probably discovered that SHIFT doesn’t seem to work.
If you press CTRL and T at the same time you’ll find ORIC’S
keyboard acts like a typewriter - lower case (small letters) nor-
mally and upper case (capitals) when you hold SHIFT down at the
same time. If you press control T (CTRL and T) ORIC will go -
c
-
24 2
-
Chapter 3 Programming in BASIC
a
7
LOOPS
7 ORIC has shown us so far that computers are capable of making
decisions according to whether conditions are true or false. They are
also capable of repeating an action for however many times you
require.
For instance, if you want ORIC to print all the numbers from 1 to
1000 and scroll them up the side of the screen, you could typei-
10 PRINT1
7 20 PRINT2
30 PRINT3
7 40 PRINT4
But you’d get rather fed up doing this 1000 times! Luckily there is
a BASIC command called the FOR. . . . TO/NEXT loop, that will
repeat an instruction whilst it counts to itself until the final number is
reached.
This is how it works:-
25
ORIC Manual
Line 10 sets the counter X to 1, then goes to line 20. There it prints
X, which is 1, and then goes to 30. This says NEXT X, so it shoots
back to the start of the loop at line 10 and increases it by the STEP
number (i.e. X is now 2). It prints X in line 20 then repeats as before
until X is 1000. This time it tries to make X = 1001, but it has
been told to only go up as far as 1000, so it jumps to the next line -
40, where it prints
“FINISHED”.
If you change the STEP number to 2, then it will print 1,3,5,7 etc.
You can leave it out, and ORIC will assume you want a STEP size of
1.
Try other STEP sizes yourself.
FOR/NEXT loops can count backwards, but you have to specify
the STEP number as a negative quantity.
10 FOR X = 1000 TO 1 STEP - 1
will count downwards.
If you make a mistake in the numbers, e.g.
FORX=4TO2STEP5
&RX=~TOF~~STEP -1
26
Chapter 3 Programming in BASIC
then the action in the loop will still be performed at least once,
because the test for whether the loop is completed is not made until
the loop has reached the NEXT statement and returned to the
start.
-4 Another use for FOR/NEXT loops is as a pause. You probably
- found that ORIC prints so fast that you couldn’t see the numbers.
-ii
To slow it down, we can put in
- 25 FOR PAUSE = 1 TO 100: NEXT PAUSE
This is like saying “Count up to 100 each time you print a
number, then continue’ ’ . Note the use of a colon to achieve two
-i
- statements in one line.
Be careful about using this facility if there is an IF. . THEN
-i branch in the line, as if the condition is true then ORIC will jump
to the new line and ignore any other statement in the original line.
C
I 27
ORIC Manual
28
Chapter 3 Programming in BASIC
REPEAT/UNTIL
If you wish to repeat a series of instructions a certain number of
times, then it is easy to use a FOR/NEXT loop. This will be repeated
the number of times that is set up in the first line, e.g.
FORN=lTO5
will loop five times. If you wish to loop until a certain condition 1s
true, it is difficult to know what value to put in the loop counter.
ii
C REPEAT allows you to loop any number of times, and tests at the
end of each loop to check if the condition is met in the UNTIL line.
+ii
29
ORIC Manual
50 END
60 REM THIS IS A RATHER SILLY PROGRAM
Use REM statements to label your subroutines. Note that you
can have have more than statement on a line, but each statement
must be separated by a colon - See line 20.
1000 REM SUBROUTINE TO WAIT FOR A SHORT TIME
1010 WAIT 100
1020 RETURN
You can use ’ instead of REM, but only as a comment at the end
of a line.
10 PRINT “HELLO” ‘THIS SAYS HELLO
is permissable.
10 ‘ COPYRIGHT ORIC LTD
is not permissable
Basic isn’t hard to learn, and this is only a brief guide. You will
become more proficient the more you use it.
*******
I hear and I forget
I see and I remember
I do and I understand
Old Chinese proverb.
30
CHAPTER 4
Colour and Graphics
4. Colour and Graphics
33
ORJC Manual
80 WAIT 100
1
90 NEXTP - -
100 NEXT I
210 INK 7 : PAPER 4 5
1
Of course, when the foreground an d back grouu nd colours are the =k
-
sa me, you won’t be able to read the words! 1
=+
1
k
1
k
1
k
1
”
:
10 LORES 0
_l
20 PLOT 16,12,“HELLO”
If you run this short program, HELLO will be printed in the centre
of the screen. You could use the program in Chapter 9 to define other
character’s using the standard character set. The PLOT command
would save you having to POKE into the screen memory.
34
4
.- - Chapter 4 Colour and Graphics
a
_ -
If you now type
10 LORES 1
1
_ - If line 20 is still intact, instead of HELLO appearing, a strange
1 set of blocks will be printed. These are characters from the alternate
- 4 set, and these particular ones are those that share the same ASCII t
a
codes as the letters in HELLO. This is the only difference between
_ _ LORES 0 and LORES 1.
G This program will print out the complete set of alternate cha-
racters.
1
L d 5 REM ** ALTERNATE CHARACTERS **
10 FOR N = 32 TO 128
4
c I 20 PRINT N,CHR$(27);“I”;CHR$(N)
30 PRINT
1 40 WAIT 25
50 NEXT N
;7 You can use this program to select characters to form your own
graphics shapes. This is one way in which it can be used.
Isi
m 1 REM *** MONSTER ***
Gi 2 REM *** LORES 0/l DEMO ***
5 LORES 1
Gi 6 D=0
c 9 REPEAT
10 A$ = “F9”:B$ = “6I”
4
20 FOR C=0 TO 35
ii 30 PLOT C,D,A$
35 PLOT C,D+l,B$
Isi 45 PLOT C,D,“ ”
50 PLOT C,D+ 1,“ ”
1 55 NEXT C
56 SHOOT
--4 6 0 D=D+2
70 UNTIL D=26
ii 75 EXPLODE
80 CLS
‘II The characters in A$ and B$ do not appear in their normal form,
- as LORES 1 has been selected. The rest of the program sends the
composite character along the rows successively until row 26 is
ii 35
r
0 RIC Manual
36
Chapter 4 Colour and Graphics
Type
PRINT SCRN (10,20)
The number 65 will be returned, as this is the ASCII code for
the letter A.
Here is a short program that REPEATS a loop until a falling missile
reaches a target. SCRN(X,Y) detects when the missile is one place
away from the target (the Ascii code for + is 43 - see line 220), and
the program finishes with an explosion. After you have RUN the pro-
gram, change the mode in which it operates, by adding line 115
LORES 0 or 115 LORES 1. This will show you the different effects
you get according to the mode you have selected.
100 :REM ** USE OF SCRN(X,Y) **
1 1 0 :CLS:INKl:PAPER4
120 :FOR N =20 TO 25
130 : PLOT N,26,” + ”
140 :NEXT N
150 :REPEAT
160 : A = INT(RND(1)*36 + 2)
170 : FOR P = 0 TO 24
180 : PLOT A,P,“V”
190 : WAIT 4
200 : PLOT A,P,” ”
210 : NEXT P
220 :UNTIL SCRN(A,P + 1) = 43
2 3 0 :EXPLODE
37
ORIC Manual
will move the cursor to the centre of the screen and print a pixel, or
small dot. The first parameter is how far across the screen
(O-239), the second is how far down the screen (0-199) and the
third is the FB number (FOREGROUND/BACKGROUND)
38
Chapter 4 Co/our and Graphics
39
0 RIC Manual
You can set the mask to any number from 0 to 255 to get different
effects. If you want equal sized dashes, you could type PATTERN
15.
15 is00001111 in binary
i.e. 8 + 4 + 2 + 1, so half the line is “on” and half is “off”. Try
drawing the square again, but this time reset the pattern mask to dif-
ferent numbers. There is nothing to stop you having two sides con-
tinuous, one dotted and one dashed. To help you understand how it
works, just add this line as a starter.
15 PATTERN 170
(170 is 10101010 in binary).
It should send you dotty!
*********
For a really exciting look at ORIC’S capabilities in HIRES mode,
try this short program which generates interference patterns by
drawing lines close to each other.
5 REM ** MOIRE **
10 HIRES
20 FORA = 0TO1
30 FOR B = 0 TO 239 STEP 6
40 CURSET 0,199*A,3
50 DRAW B,l99-398*A,l
60 CURSET 239,199*A,3
70 DRAW -B, 199-398*A,l
80 NEXT B: NEXT A
*********
CHAR
If you were to try to PRINT in HIRES mode, you would only get text
on the bottom 3 lines. There is a command however, that lets you
print anywhere you like on the high resolution screen. Type NEW to
clear the memory, then HIRES. Now set the cursor to the middle of
the screen by typing CURSET 120, 100, 3. Now type C H A R
65,0,1. You should have a capital A in the middle of the screen.
CHAR is the command, and is followed by three parameters.
CHAR X, S, FB.
X is the A.S.C.I.I. code (32- 127)
S is either 0 (standard character set) or 1 (alternate set)
FB is foreground/background value (0-3)
40
a
F -
Chapter 4 Colour and Graphics
5 REM ** SIDEPRINT **
10 H I R E S
2 0 CURSET 50,50,3
30 N$ = “HELLO I’M ORIC”
40 FOR A = 1 TO LEN (N$)
50 CHAR ASC (MID$(N$,A,l)),0,l
60 CURMOV 10,10,0
70 NEXT A
CURSET 120,100,3
a then
3 CIRCLE 50,l
POINTS
If you want to know if any particular pixel on the screen is in fore-
ground or background colour, e.g. if there is a space invader at the
centre of the screen, then POINT is the command you need. To see
how it works, try this in direct mode.
Type HIRES
Now type
CURSET 0,0,0 (cursor set at position 0,0 in background
colour).
Now type
TEXT
next
PRINT POINT (0,0)
As 0,0 is set to background, you will get 0 printed. Type HIRES.
This time type CURSET 0,0,1 (cursor set at position 0,0 in
foreground colour).
Now
TEXT,
then
PRINT POINT (0,0).
This time you should get - 1, as the pixel is set to foreground.
*********
42
Chapter 4 Colour and Graphics
FILL
This is a useful command that can fill an area of so many rows with
4 a value and so many character cells with a value, between 0 and 127.
There are 200 rows, 40 cells per row. The value produces colours
F
4
-- and patterns according to the attributes. (see appendix and chapter 7
for details).
-a
c
Here is a short program to show you the fine detail that ORIC can
achieve.
4
C
5 HIRES
10 FORN = 0tol99
1
c-
20 X = RND(l)*8 +16
30 FILLl,l,X
40 NEXTN
4
C
Line 20 chooses background colours at random from line 0
(top) to line 199 (bottom).
4 Experiment to find what the other attributes will achieve.
This program demonstrates mixing graphic patterns with colour
4
c
and flashing attributes.
Note that line 130 avoids using the control codes that disturb the
=a
- screen synchronization.
100 :REM **FILL DEMO **
1 1 0 :HIRES
1 2 0 :REPEAT
130 : A = RND(1)*128 + 1:IF A> 23 AND A< 32 THEN 130
4 140 : CURSET RND(1)*90 + 10,RND(l)*90 + 10,l
P
150 : FILL RND(1)*90 + l,l,A
160 :UNTIL KEY$< > ""
*********
43
0 RIC Manual
Anything you enter now will appear twice in consecutive rows. Try
it out. Help! How do we stop it?
As it’s a toggle action switch, typing PRINT CHR$(4) a second
time will turn this action off. The other control characters are
achieved in a similar manner. But. . . back to the double flashers!
The following program will give you the effect you desire.
10 PRINT CHR$(l2)
20 PRINT CHR$(4); CHR$(27);“N DOUBLE FLASH
CHARACTERS”
30 PRINT CHR$(4)
-1
c
45
-z
c
CHAPTER 5
-7
c -
,_
--
5. Editing Basic programs
-3
T--
4 When you write a program and wish to change a line, there are
c-
several methods of altering or deleting existing instructions.
-3 If the whole line is incorrect, then typing the line number
c-
followed by [RETURN] will delete the entire line.
10 PRINT “HELLO”
20 PRINT “OOPS!”
30 PRINT “GOODBYE”
Type:-
20 [RETURN]
4
C- Now type:-
;
LIST
L
You will see the program listing as before, but this time with line
20 missing
10 PRINT “HELLO”
4 30 PRINT “GOODBYE”
4 If you wish to delete all the lines in a program, then type NEW.
c
If you are typing a line in, and discover that you have made a
mistake, you can rub out the last character entered by pressing the
DEL key. Press DEL twice and the cursor will backspace (move to
the left) two positions.
To delete a complete line as you are entering it, hold down
CTRL and X. A backslash will appear at the end of the line, and
the cursor will jump down to the start of a new line.
3i
--
If you LIST a long program, you probably find that it flashes
up the screen too fast to read. To halt the listing, press the space
bar once. Pressing any key will continue the listing. To halt the
listing completely, hold down CTRL and C. Control C will also
si
t stop the execution of most Basic programs. They can be restarted
by typing CONT (for continue), unless you have changed any of
:
r .-
the program or its variables. Then you will have to use RUN or
GOTO.
c3 *********
4 49
--
ORIC Manual
COPYING
It would be very time-consuming to have to re-type whole lines, par-
ticularly if they contain complicated information. You are not all-
owed to have lines that are longer than 78 characters. Very long pro-
gram lines are difficult to read and spoil the lay-out of the listings.
ORIC will give out a PING if you try to exceed this number.
Should you need to change a line, ORIC has a COPY facility. To
see it in action, type this short program in.
If you decide that line 20 should read A = 25: B = 5, and that line
30 should read C = A + B, this is what you do. LIST the program
and it will appear on the screen. It is a good idea to press control L
(CTRL and L at the same time) to clear the screen each time before
you LIST the program.
You can now move the cursor up the screen using the arrow keys
next to the space bar. The cursor will move in the direction of the
arrow on the key. When the cursor is next to line 20, hold down the
CTRL key, and at the same time press A. The cursor will move to the
right and each character it passes over will be entered in the input
buffer (a temporary store).
When the cursor is over the 0 in 20, release CTRL and A, and
press 5. A 5 will appear instead of the 0. Continue to copy the line
using control A until the cursor is positioned over the 3 in 30. Rel-
ease control A and enter 5. The 5 will appear in place of the 3.
As you do not want the 0 in your new line, simply press r
[RETURN] and the edited line will be stored in the program
memory. The screen display will show A = 25: B =50, which may 64
make you think it is incorrect. Clear the screen as before and LIST 1
the program. Voila! - Line 20 now reads A = 25: B = 5. I
Because you did not copy the 0 at the end of the line, it was not 7
stored as part of the new line. To change line 30, move the cursor up
to the line and then copy as far as * using control A. Enter + then
copy B and press [RETURN].
--
50 a
1
Chapter 5 Editing Basic programs
51
0RIC Manual
52
CHAPTER 6
Number crunching
s;i
r-
-
RI
-
7
-
4
6. Number crunching
-
As you have already discovered, ORIC can handle very large num-
-i
- bers and also very small ones, both positive and negative. The larger
numbers grow, the more figures they require, so 10 needs two fig-
-3
- ures, 100 needs three, and so on. This can become untidy and diffi-
cult to read and write when the number gets very large. There is a way
*
- of writing numbers that is a lot more compact, called scientific or
1;;1,
exponent notation.
-
10 can be written 1 x 101 (10)
100 can be written 1 x lo* (10 x 10)
1000 can be written 1 x lo3 (10 x 10 x 10)
and so on
PRINT 999999999 * 1
-
-
F
then
PRINT 9999999999 *1
This shows you how scientific notation works, and also how the
number is rounded off.
Enter large numbers and see how Oric prints them. You can also
enter numbers such as 2.3E + 4 to see what their equivalent is. An
easy way to remember how to convert these numbers is to say
- 2.3E + 4 means
-
“Write down 2.3 Move the figures 4 places to the left. Fill any
spaces with zeros”.
2.3
23.0 +l place (or times 1 0)
1 230.0 +2 places (or times 1W
-
2300.0 -3 places (or times 1oW
w 23000.0 +4 places (or times loooo)
PC
55
0RIC Manual
-
rJ 10 FORN= -5TO5
-
20 PRINT N, SGN(N)
--
m 30 NEXTN
- *********
-
H
-
DATA
If you have a lot of numbers that will be used in a program
d
-
then it is possible to have them stored in the program as
DATA, rather than have to type them in each time. This short
example shows how to incorporate this information in your pro-
- grams: -
-
- 10 FORN= l T 0 5
rl
20 READ A
30 S=S+A
40 NEXTN
50 PRINT “SUM = “S
- 60 DATA 1,3,8,6,4
- Line 20 READS the DATA, one item at a time, and assigns
I
that value to the variable A. It is added to S (initially zero) each
C
57
0 RIC Manual
One reason for using arrays rather than simple variables is that
they can fit in FOR/NEXT loops easily.
10 FORN = lT05
20 A(N) = N*N
30 NEXTN
4 0 FORX=lTO5
50 PRINT X, A(X)
60 NEXTX
Lines 10 to 30 load the array A(N) with the squares of the loop
number (N). Lines 40 to 60 print the contents of the array on the
screen. Note that it is not necessary to fill every element in an array.
Any “empty” elements will contain zero.
An array like those we have just considered is similar to a column
of numbers, but it is also possible to have rows and columns - in
other words, a two-dimensional array. Multi- dimensional arrays
must be dimensioned before use.
10 DIM A(5,5)
2 0 FORN= l T 0 5
30 FORM= lTO5
40 A(N,M) = N*M
50 NEXT M,N
This will load numbers into 25 locations. You can probably see
from the program that they happen to be the answers to some simple
multiplication sums.
N
58
Chapter 6 Number crunching
m
-
-
C
LOGS
I have mentioned that numbers can be written using scientific
n
notation. e.g. 1.6E + 2 is the same as 160. More usually 1.6E +2
wouldbewritten 1.6x102 which means 1.6x 1OxlO or 1.6x100.The
n
small 2 in 102 means “write the large number down this number of
- times and multiply them together”. e.g. 10x10.
n
So 10 4 means 10 x 10 x 10 x 10 or 10000. The small number is called
the index or exponent. 10 4 is usually read as “10 raised to the power
n
of 4” or just “10 to the power of 4”.
- This gives us an introduction to logarithms, or logs for short,
because the log of a number is the power to which 10 must be raised
to produce that number. i.e. 4 is the log of 10,000.
z To find the log of a number between 1 and 10, we have to find the
- index that will produce that number. It must be between 0 + 1. If you
m type
-
-_
n
-
W
PRINT 10 T 0.698970004.
--
and see if you were right. (The sign T means “to the power of” and
is SHIFT 6 on the keyboard). Remember 10 log X = x.
59
0RIC Manual
60
d
-
have ten groups of ten, it forms a hundred, and ten hundreds form a
thousand and so on.
e.g. 3742 is made up of 3 thousands, 7 hundreds, 4 tens and 2
-
units. The largest figure you may have in any column is 9. One
W
-
more, and you have enough for one group of 10 in the next column.
e.g. 9
+l
10
Ir Just suppose that humans had 8 fingers and thumbs. They would
c-
have used these symbols: 0,1,2,3,4,5,6,7. 8 and 9 would not exist.
+
C
e.g. 7
c= +1
-
10
The largest figure you may now have in any column is 7. One
+ more makes a group of eight, so the answer is 10. This is not read as
C
“ten” but “one-zero” in “base eight”. To show that it is not a
-
m normal (or decimal or denary or base 10) number, then it is usual to
C
write it 10,.
Just as the column headings in base 10 numbers are in tens,
61
0 RIC Manual
62
Chapter 6 Number crunching
NOTE : You may fin d some books that identi fy hex numbers by use
c7
c of a $, but Oric will interpret this as a string sign.
-i
I If you need to convert between hexadecimal and base 10 num-
bers, you would use #. i.e.
‘7
I
PRINT #10
c?
CT
PRINT HEX$(l6)
‘7
v-
10 FORN=0TO255
20 PRINT N, HEX$(N)
30 NEXTN
-4
- *********
MATHS ROUTINES
Although it is important not to think of computers purely as
manipulators of numbers, there is no doubt that they make many
maths tasks that are usually boring and repetitive, comparatively
simple. Oric has many built in routines that assist “number-
-i
crunching”.
c-
63
0RIC Manual
If you needed to know all the square roots from 1 to 100, you
would have to spend a long time looking in tables or pressing calcu-
lator keys. Oric can achieve this much more simply. Type in this
program:-
1 0 CLS
2 0 FORN=lTOl00
30 PRINT N, SQR(N)
40 NEXT N
If you RUN it, the numbers from 1 to 100 will flash down the
left side of the screen, with their square roots next to them in the
centre of the screen. Oric calculates them so fast that you probably
found it difficult to read. Put in
35 WAIT 10
to slow the program down.
Oric can even calculate roots without using the SQR facility.
There is a method of finding roots called the Newton-Raphson
iterative method. Iteration means to keep on doing the same thing
again and again - an ideal use for a loop on Oric. Each time, the
guess is refined and gets closer to the correct answer. This short
program shows the guesses, and stops when the answer is correct.
(Line 80 jumps out of the loop if the guess is within
t 0.000001 of the right answer - just in case there is not an
exact answer).
5 REM *** ITERATIVE ROOTS ***
10 INPUT “THINK OF A NUMBER”;S
20 INPUT “GUESS THE ROOT”;G
30 PRINTG
40 X=S/G
50 G=(X+G)/2
60 R=G*G
70 IF R< (S + 0.000001) AND R>
(S - 0.000001) THEN GOT0 90
80 GOT0 30
90 PRINT“ROOT = “;G
There is another use for ORIC’s high-speed maths brain. The
17th Centu ry mathematics Leibnitz, who made calcul us possible,
64
-4 Chapter 6 Number crunching
-
A discovered a way of calculating TI.
- n is an irrational number; in other words, it can never be calculated to
-+ a finite number of decimal places.
- Leibnitz discovered that this sequence approached closer and
closer to the true value.
-
n 2 4(1-+++--f++. . . .)etc.
4
- You should be able to see a regular pattern in the fractions. ORIC
i loves patterns, as they can ble put in loops. I f you were to try to
- calcul ate the above form u l a with pencil and paper it would take
4 you a long time , even u P to - l/9. - all the worse wh.en you
- realize that the answer isn’t close enoug h until you’ ve looped
i several hundred times. Poor Leibnitz, but lucky you! Try this
c- program.
+
P 5 REM *** SLOW PI ***
10 CLS
li
Ic 20 DEF FNA(N) = (- l/N + l/(N + 2))
30 FOR X = 3 TO 10003 STEP 4
rzi
C 40 S = S + FNA(X)
50 APPROX = 4*(1+S)
--i
- 60 PRINT APPROX
70 NEXTX
--i
- Line 20 defines a function, A, containing a variable N. This
Ir? saves having a cumbersome line later. FNA actually calculates the
I series and is called at line 30. The loop goes up in steps of 4,
-i starting with 3, so X is 3,7,11,15 etc. This makes correct
- increments and the result is printed at line 50. If you RUN the
ri program, Oric will print a result for TI that gets closer and closer to
Lc the actual result. Compare it with 3.1416 and you will see that it’s
i- not the fastest way to calculate n, even with ORIC.
To find n rather more quickly, simply type
ri
- PRINT PI
eFi This will give you an accurate value of 71 to several places o f
-
decimals, as PI is stored as a constant by ORIC.
-i
- Remember that this means you cannot choose PI as a variable
name, or indeed any word beginning with PI, such as PIG = 8 or
ri
- PIPES = 78, because PI is a reserved word.
ii
c-
65
ORIC Manual
*********
RANDOM NUMBERS
There is a useful function on ORIC that is often used in games
programs. This is RND, which will return a pseudo-random
number. Due to the way computers generate random numbers, this
will not be truly random, and it would be possible to discover a pat-
tern in the series of numbers produced. This is not likely to be
obvious unless you perform a statistical analysis on the series, so
RND can for all normal purposes be considered truly random.
If you aren’t sure what random num bers are, then consider a die.
It has an equal chance of producing any numbers from 1 to 6. The
order in which the numbers are actually produced in a series of
throws is random. To simulate this on ORIC, try this program.
5 REM *** DICE THROWER ***
10 FORN=lTO10
20 PRINT“PRESS ANY KEY TO THROW DIE”
30 GET A$
40 A = INT(RND(l)*6) + 1
50 PRINT A
60 NEXT
Line 20 waits for any key to be pressed. Line 30 chooses a
random number between 0 + 1, multiplies it by 6, the INT function
loses any decimal fraction, and finally, 1 is added. This ensures that a
number from 1 to 6 will be produced.
RND(n) will produce a random number greater than or equal to 0
and less than 1, if n is a positive number. If n is a negative number,
then the random seed is set to a particular number, and subsequent
positive n’s will always produce the same sequence. If n is zero, the
last random number generated will be produced.
*********
To conclude this chapter, here is a program that utilizes many of
the functions mentioned in this chapter. It also uses some string
handling routines that you may not fully understand until you have
read the relevant chapter. If necessary come back to it later.
Calendars are difficult to construct due to the awkwardness of the
earth in not taking an exact number of days to pass round the sun. In
fact, it takes 365.242216 days to make an exact year.
66
i
7
67
CHAPTER 7
More mathematical functions
7. More mathematical functions
TRIGONOMETRY
ORIC has many functions that you will recognize if you have a sci-
entific calculator or if you remember your geometry lessons at
school. These are SIN (sines) COS (cosines), TAN (tangents). They
are ratios of lengths of sides of triangles for difference angles.
__ = opposite
AB
= tangent of angle x
BC adjacent
AB opposite
-= = sine of angle x
AC hypotenuse
adjacent
-BC - ________ = cosine of angle x
AC- hypotenuse
71
0RIC Manual
You can probably see how the ratios change in these three exam-
ple triangles: -
1.) When x is large
TAN (x) = opp + a large number that
adj tends towards infinity as
x approaches 90”
SIN (x) = opp + tends towards 1 as x
hyp approaches 90”
Opp*
+ COS (x) = adj tends towards 1 as x
adj hyp approaches 0”
You can obtain TAN, SIN & COS by simply typing PRINT TAN
(x), etc. The ony problem is that Oric, like most computers likes
angles in radians, not degrees. Luckily degrees can be turned into
radians, and vice versa very easily.
72
Chapter 7 More ma thema tical functions
How many times would the radius fit round the circumference?
More than 6 times - in fact 2 x TI times. If you were to cut out a slice
from the circle, so that the curved part equals the radius, r, then the
angle at the centre, is 1 radian. One complete circle
= 360’ so 1 radian = 3X6b” = 57.29578”
27-I
r
Here are some programs to show how ORIC can use trigonometric
functions to draw on the screen, as well as calculate for you.
73
ORIC Manual
74
Chapter 7 More ma thema tical functions
Ga
c-
d
I-
a
a
i
a
a
a
a
a
a
a 75
CHAPTER 8
Words
8. Words
ii
-
Earlier, we discovered that computers can manipulate any collection
rr
- of symbols, not just numbers. So that ORIC knows that the symbols
must be con.sidered as such, and does not mistake them for variables,
ri
- they have to be enclosed within quotes.
So,
PRINT A
ri
- will result in a zero being printed, as it is considered to be a variable.
PRINT “A”
will result in A being printed, as it is enclosed within quotes.
String variables are identified by a dollar sign at the end. e.g. A$ or
A3$. Remember that ORIC only reads the first two characters of a
variable name, so BIG$ is the same as BIKE$.
79
0RIC Manual
80
ii
-
Chapter 8 Words
Ii
Using the function ASC will return the code for any keyboard cha-
- racter. The function CHR$ works in the reverse direction, and con-
ci verts a number between 32 and 128 into the corresponding character.
To list them all, run this program.
;r
- 10 FOR N = 32 TO 128
20 PRINT “ASCII CODE” N “STANDS FOR”CHR$(N)
-i
- 30 WAIT 20
40 NEXTN
Ir
- Because all the characters have ASCII codes, they can be sorted
-i into order. As you can see, numerical order is the same as alphabe-
-
tical order, so Z, which has the value 90, is greater than A which has
the value 65.
You can use the greater than (> ) and the less than (< ) signs to
compare strings, as well as numbers. Care must be taken, however,
to avoid mixing upper and lower case, and all lower case letters have
Fi greater values than upper case, so although “apple” is less than
“zebra”, “apple” is greater than “Zebra”.
To assist you in manipulating strings, there are 3 more very useful
functions - RIGHT$, LEFT$ and MID$. RIGHT$ returns the
right hand portion of a string as follows:
A$= ‘ ‘ABCDEFGHIJ”
?
PRINT RIGHT$ (A$,2)
will print “IJ”. The number 2 is the quantity of characters to be
4 returned.
C
LEFT$ returns the left hand proportion of a string as follows:
?
C
A$= ‘ ‘ABCDEFGHIJ”
i PRINT LEFT$(A$,2)
will print “AB”
i
t
MID$ needs just a little more information.
4 A$= “ABCDEFGHIJ”
PRINT MID$(A$,5,2)
will print “EF”. The example means - return the 2 characters from
string A$, starting at position 5. The second number can be omitted,
81
0 RIC Manual
in which case all the characters to the right of, and including, the first
number are returned.
A$= “ABCDEFGHIJ”
PRINT MID$(A$,5)
will print ‘ ‘EFGHIJ”.
Here is a short program that demonstrates these functions.
10 PRINT “ENTER A STRING”
20 INPUT A$
30 IF LEN(A$)< 3 THEN PRINT “TOO SHORT”: GOT0
10
40 PRINT A$ “IS”;LEN(A$);“CHARACTERS LONG”
50 PRINT “IT STARTS WITH”;LEFT$(A$,l)
60 PRINT “AND ENDS WITH”;RIGHT$(A$,l)
70 PRINT “AND HAS”;MID$(A$,2,LEN(A$) - 2); “IN
THE MIDDLE”
Often it is easier to have information stored in a program. J ust as it
is possible to hold numbers in DATA statements, strings can be held
just in a similar manner.
1 0 FORX=0TO3
20 READ NAME$(X)
30 PRINT NAME$(X)
40 NEXT
50 DATA TOM, TERESA, DENIS, MARTIN
The DATA is READ one name at a time and stored in array,
NAME$. NAME$(0) is then TOM, NAME$(l) is TERESA,
NAME$(2) is DENIS, and NAME$(3) is MARTIN.
String arrays are similar to numerical arrays. ORIC reserves space
automatically for up to 11 elements (numbered 0 to 10). If you
want more, then you must put in a DIM statement for the number
you need e.g. DIM A$ (19) would create space for 20 elements.
There is one special thing to note about strings held in DATA
lines. If you insert leading spaces, they will be ignored by ORIC. e.g.
DATA AB, C,DE
will lose the space before the C. If you want the space included, you
must surround the whole item by quotes. e.g.
DATA AB,“ C”,DE
82
Chapter 8 Words
i-i When you RUN a program, the DATA pointer goes to the first
-
item in the first DATA line and READS from there. If you RUN the
ti name program, the data pointer will READ 4 items, then stay at the
-
end. If you then enter
GOT0 10
ii the pointer cannot find any more items, so the error message
-
I+
- OUT OF DATA IN 20
Because it is in the loop, the pointer will be reset each time, and
ii
Lt TOM will be loaded into all the elements of the array.
*********
SORTING
To complete this chapter, here is a program that demonstrates
r; some of the string handling techniques of ORIC, particularly the use
of string arrays and string comparison.
i
c
There are many kinds of sorting methods that computers can use.
All operate on the principle that words starting with letters that have
low ASCII codes will finish the routine at the beginning of an array,
those with high ASCII codes at the end, and the rest arranged in
u
numerical and therefore alphabetical order in between.
This sample program loads the words to be sorted into an array
LI
5 REM ***SORT***
10 INPUT “NO. OF WORDS”;N
15 DIM A$(N + 1)
20 FORX=0TON-1
30 INPUT A$(X)
40 NEXT
50 FORX=0TON-1
60 PRINT A$(X):NEXT
70 FORK=0TON-1
80 FORL=K+lTON
90 IF A$(L)> = A$(K) THEN 130
100 U$ = A$(L)
110 A$(L) = AS(K)
120 A $ ( K ) = U$
130 NEXT L
140 NEXT K
150 FORX=0TON
160 PRINT A$(X)
170 NEXT
84
r;T
r-+
rr-4
P-
I
* CHAPTER 9
Advanced Graphics
-4
C
-
“4
t
f4
.A
+I 9. Advanced graphics
i;: 8
c7 20
3 4
G
3 4
F;
_ 62
G 34
G
.. 34
G 0
87
ORIC Manual
88
Chapter 9 Advanced graphics
Type A now - you have been invaded by ORIC! Any A will now
appear in its new guise, as you have redefined how ORIC draws an
A.
It would take a long time to POKE numbers one at a time, so it is
better to write a short program to redefine characters.
Here is a frightening program that redefines the entire character
set. When you have entered it, LIST it, then RUN it, and watch the
screen. This is total alien domination! The only way to escape from
them is to press ORIC’s reset button, when you will return to the
standard character set.
5 REM *** ALIEN DOMINATION ***
10 FOR X = 46344 TO 47088 STEP8
20 FOR I=0 TO 7
30 READ M
40 POKE I+X,M
50 NEXT I
60 RESTORE
70 NEXT X
80 DATA 18,12,30,45,45,30,18,0
Here is a more useful program. You can use it to redefine any key-
board character, upper or lower case. A 2-dimensional array, Y, is
set up to store the new character in its large form. C$ is whichever key
is pressed. A is the start of the standard character set in memory, D is
the position of the first byte of the chosen character in the standard
character set. The subroutine at line 1000 PEEKS that byte of the
character and converts the decimal contents of that byte into a
binary number, i.e. 45 would be converted into 00101101, and
either zeros or ones loaded into the array Y.
The last section pokes either a solid block (128) if the cell is a 1, or a
blank (32) if the cell is a 0 into the screen display. This causes a large
version of the character to appear on the screen. The rest of the pro-
gram gives the user the opportunity to enter fresh data, one line at a
time, and to examine the result in actual or enlarged size.
5 REM *** CHARACTER GENERATOR ***
10 CLS
20 DIM X(8):DIM Y(8,8)
30 PRINT “PLEASE ENTER THE CHARACTER YOU
WISH”,“ TO REFEFINE”
89
0RIC Manual
40 GET C$
50 PRINT C$
60 C = ASC(C$)
70 A = 46080:D = C*8
80 GOSUB 1000
90 PRINT”ENTER THE DATA”
100 FORN=0TO7
110 PRINT“ROW “;N;
120 INPUT X(N)
130 IF X(N)> 63 OR X(N)< 0 THEN 120
140 POKE (A + D + N),X(N)
150 NEXT
160 GOSUB 1000
200 STOP
1000 REM *** CHARACTER GEN.SUBR. ***
1010 FORN=0TO7
1020 X(N) = PEEK(A + D + N)
1030 FORM=0TO7
1040 Y(N,M) = INT(X(N)/2T(7 -M))
1050 Z = ((X(N)/2T(7 -M)) - Y(N,M))*21(7 - M)
1060 X(N) = Z + 0.0001
1070 IF Y(N,M) = 0 THEN POKE 48220 + (N*40) + M,32
1080 IF Y(N,M) = 1 THEN POKE 48220 + (N*40) + M,128
1090 NEXT M
1100 NEXT N
1110 RETURN
*********
SERIAL ATTRIBUTES
To send information to the screen, ORIC uses serial attributes.
This means that a byte sent to the screen can be considered as a
graphic pattern or as an attribute controlling colour, flashing, etc.
The way the bits are set determines whether the byte is read as an
attribute or not. If bits 6+ 5 are both zero, then the remaining 5
bits are considered as an attribute - there are 32 of these. If bits
6 + 5 are not both zero, then bits 5 to 0 are read as a pattern.
In HIRES mode, bits 0 to 5 are the pattern bits. In TEXT and
LORES mode, bits 0 to 6 are the ASCII look up codes. Control
codes (bits 6 + 5 set to 0) become attributes. Bit 7 controls whether
the character is inverse or not, 1 is on, 0 is off.
90
Chapter 9 Advanced graphics
ottributc code
\
pattern bits
91
ORIC Manual
110 POKE48039+N+A+3,3
120 POKE 48040 + N + A + 3,64
130 SOUND l,N/2,0
140 PLAY 1,0,5,5
150 POKE 48040 + N + A, 32
160 POKE 48040 + N + A + 6,32
170 POKE 48040 + N + A + 3,32
180 NEXT N
190 EXPLODE
200 WAIT RND(1)*200 + 100
210 NEXT M
1000 REM *** CHARACTER DEFINITION ***
1010 FORN=0TO7
1020 READ X: POKE 46080 + (64*8) + N,X
1030 NEXT N
1040 DATA 18,12,30,45,45,30,18,0
1050 RETURN
You will see from this program that you can have all the fore-
ground colours on the screen at the same time, as well as changing
background colours. You do not have to POKE into the screen
display - PLOT will work as well.
Nomally the protected columns on the left of the screen control the
INK and PAPER colours for the whole screen. If you POKE an
attribute on to the screen, it occupies one character square and
effects all the character squares to its right unless you POKE another
colour attribute after it. As the INK attribute is separate to the
PAPER attribute, it is not necessary to cancel it unless other cha-
racters appear to its right. These would then take on the colour of the
closest attribute to their left.
In HIRES mode, it is possible to have a colour resolution of
200 lines by 40 character columns. Again, you have to POKE the
position just to the left of the position you wish to alter.
This program POKES background attributes into the centre of the
screen and foreground attributes to the far left. The circles that are
drawn take on the colour of the attributes according to their position
on the screen.
92
Chapter 9 Advanced graphics
93
CHAPTER 10
Sound
10. Sound
10 FORNN = lTO10
20 ZAP
30 WAIT 5
40 NEXTN
97
0 RIC Manual
5 REM ** MUSIC? **
2 + 1,7
20 MUSIC 1, RND(l)*6,RND(l)*l2
30 WAIT RND (1)*20+5
40 GOT0 5
5 REM ** KEYBOARD **
20 GET A$
30 A=VAL A$
40 I F A $ = “ - ” THEN A=11
50 IF A$=“=” THEN A=12
60 IF A $ = “/” THEN PLAY 0,0,0,0: STOP
70 IF A=0 THEN A=10
80 MUSIC 1,3,A,5
98
Chapter 10 Sound
90 GOT0 5
Line 20 waits for an input form the keyboard. Line 30 reads the
value into variable A. If you press a number then A will be the value
of that number, if another key, then A will equal 0. Lines 40 to 60
convert the remaining keys to the required values. Lie 70 stops A
from being 0. (This would result in an error message as the note
value in the MUSIC command cannot accept 0 as a valid
parameter).
Here are the details of the sound commands.
1. SOUND (Channel, Period, Volume)
All the parameters must be numeric. Out of range errors will be
zil detected.
Channel = 1,2 or 3 for tone channels
4,5 or 6 for noise channels
Note that there is only one noise channel, the 4,5 or 6 simply spe-
cify which tone channel it is mixed with.
Volume = 1 to 15 fixed volume levels
0 variable volume level controlled by PLAY
command
;;i
--
SOUND can be used to produce a wide variety of both musical and
non-musical sounds. Channels 1,2 and 3 produce pure tones, and 4,5
4
- and 6 add noise to each tone. The period value controls the pitch,
(the name refers to the period of vibration or frequency of the note
=a
c-
- do not mistake it for a note length parameter.) Unless you are
using an external amplifer, you will probably find that volumes of 6
?
c
or 7 are sufficiently loud!
2. MUSIC (Channel, Octave, Note, Volume)
4
- Channel = 1,2 or 3 - tone channels
Octave = 0 to 6 with 0 giving the lowest tone.
i Note = 1 = C Any other numbers will produce an error
message.
2=c#
3 =D
4 = D#
5 =E
6=F
7 = F#
8 =G
99
-
0RIC Manual L
9 = G#
10 = A
11 = A#
12 = B
MUSIC has been designed to offer you pure tones, and the pitch
has been set to make it easy to enter notes of a particular value, e.g.
from sheet music. There are three available channels, and notes,
octave (from 1 to 7), and volume are all selectable. .
2_1 4
DI i 2s XI,
Db Eb Gb Ab Bb
L D E F G A B
,ir\
3 5 b 8 10 ‘2
100
Chapter 10 Sound
4
-
This controls the way the sound is produced i.e. repeating or rise
and falling etc.
Envelope Period = 0 to 32767
Controls how long the sound or note takes to start and end.
When you use the sound facilities on ORIC, you may wish to turn
off the keyboard click by pressing CTRL and F once. If it is left on,
then key presses may affect the sound output.
This program illustrates one way in which note values, both in
Ir
-
terms of pitch and length, may be held in DATA statements and
called when required during the execution of the program. A chord
+
- effect is achieved by opening channels 1 and 2 in the PLAY
statement.
?
10 REM ** TUNE **
4 20 FOR N = 1TO11
- 30 READ A,B
1 40 MUSIC2,3,A,0
- 45 PLAY3,0,7,2000
50 WAIT B
60 PLAY 0,0,0,0
” 80 NEXT N
-- 100 DATA 5,30,5,30,7,30,8,75,5,75
I? 110 DATA 8,60,10,30,7,60,5,30,3,30,5,180
-
Although MUSIC and SOUND are fairly easy to imagine in terms
3
c- of the sounds they will produce, PLAY is more difficult.
This program allows you to enter the different channels, 1,2 and 3,
and also to alter the two envelope parameters, mode and period. In
this way, you will soon become familiar with all the sound
?
c- commands that ORIC has to offer.
?
C-
5 REM ** ENVELOPE TEST **
10 INPUT “ENTER THE TONE CHANNEL- 1,2 OR
3”;T
20 IF T< 1 OR T> 3 THEN 10
30 INPUT “ENTER THE ENVELOPE MODE, 0 TO
7”;M
40 IF M< 0 OR M> 7 THEN 30
50 INPUT “ENTER THE ENVELOPE PERIOD, 0 TO
32767”;P
101
=w
ORIC Manual 1
=-m
60 IF P< 0 OR P> 32767 THEN 50
70 CLS 1
k
80 PRINT “CHANNEL “T
90 PRINT “ENVELOPE MODE “M 1
LL
100 PRINT “ENVELOPE PERIOD “P
110 MUSIC T,3,4,0
120 PLAY T,0,M,P
130 PRINT “PRESS RETURN IF SOUND CONTINUES” L
2
.
2
,1
2
gj
2
2
2
2
51
2
2
2
2
;1
102
-4
P’
When you have spent some time typing in a long program, it’s nice to
know that you can store your program away somewhere and load it
into ORIC or another ORIC at a later stage.
You will need a cassette recorder and a connecting lead to do this.
As mentioned previously, the plugs depend on the type of recorder
-s
c you have. ORIC has a 7-pin socket at the back for cassette
input/output. If your recorder has a “remote” socket, it can be con-
nected to the extra pins. (If not, don’t worry - a 3 pin DIN plug
should fit, but you will have to remember to switch the machine on
and off yourself, or use the PAUSE button).
Do not attempt to use a 5 pin DIN plug, as the outer pairs of pins
are usually shorted together and will not function on ORIC.
To save a program, switch the recorder on to record and type
5;
CSAVE “XX”
(XX is the name you give to your program and may be up to 17 cha-
racters in length and include full stops, hyphens, etc.) When you
Y
c press [RETURN], the program will be converted into sound signals
and recorded on the tape.
r The message
Saving XX
will appear on the status line. When the program has been saved,
Ready will appear on the screen.
To load the program back in, make sure the recorder is connected
properly and type
CLOAD “XX”
ORIC will search through the tape until it reaches program “XX”
and will then load it into internal memory.
While it is searching, the message
Searching.. . .
will appear on the status line. When the required program has been
found, the message will change to
105
ORIC Manual
Loading XX
If you have forgotten the program name, o r simply wish to load in
the next program on the cassette, then type
CLOAD””
You can buy special computer data cassettes that are not very long
- Cl0 or Cl5 - or you can use good quality audio cassettes. Short
cassettes are preferable as it is easier to locate a program.
A final warning - don’t try and record on the plastic leader at the
start of the tape. Your ears may not mind missing half a note at the
start
. .
of some music, but ORIC will complain if even one byte is miss-
ing !
As well as saving programs normally, ORIC allows you to be far
more versatile in the use of your recorder. If you CSAVE programs as
above, they are recorded at the fast rate of 2400 baud (a measure
of data transfer). You should find that this speed is perfectly reliable
provided the record/replay head on the cassette recorder is clean and
well-aligned, and you are using good quality tapes.
If there is a fault in the tape, you may get the error message
FILE ERROR - LOAD ABORTED
If you wish to be absolutely sure that your masterpiece is CSAVEd
for posterity, then you may add the letter S to the CSAVE instruction
as follows, which will transfer data at the super reliable speed of
300 baud.
CSAVE “PROG l”,S
When you CLOAD slow programs, you must type CLOAD
“PROG l”,S or ORIC will expect a fast load.
If you wish your program to RUN automatically once it has been
loaded, add the instruction AUTO to the CSAVE instruction.
CSAVE “PROG l”,AUTO
There is no need to add anything to the instruction when an auto-
run program is CLOADed.
CLOAD “PROGl”
will RUN immediately after loading, as the AUTO message is
encoded with the program on the tape.
106
Chapter 7 7 Saving programs on tape
107
CHAPTER 12
Better Basic
12. Better Basic
Up until this point, you may have felt quite confident about using
ORIC. You will be copying programs from books and magazines
+
and probably starting to write your own original programs too.
- . This chapter is designed to help you improve your program
-il
writing and to make the most of the considerable facilities availa-
C
ble on ORIC.
4 The short example programs in this manual do not take up
c *
much memory. When you switch on, you are told how much
151 memory is available for you to fill with programs. Some of this
- will be used by the TEXT screen, and rather more if you are in
3 HIRES mode. Some more memory will be used to store variables,
C
etc. To find out the memory you have left, type
151
c
PRINT FRE (0)
The number of bytes left will be printed.
If you write longer programs, each time a string variable is
used, it is copied into an extra part of the memory. This is par-
ticularly noticeable in long FOR/NEXT loops, or in nested
Gi subroutines. If you start to run out of memory, it may be useful
C
to clear out all the extra copies - after all, only the most recent
one is needed. This is sometimes referred to as “house-keeping”
or as “garbage-collection”. Although a certain amount is
automatic, you can force garbage-collection by having a line such
as
Gi
w- 240 A = FRE (““)
in the necessary part of the program.
When you write small programs, they are easy to compose at
1 the keyboard. Any problems are fairly easy to sort out, and you
F-
can probably tell what the program does by glancing at the list-
ing.
With programs longer than about 20 lines or so, this gets pro-
gressively more difficult, and a week later you may wonder how
you got it to work in the first place, and to anyone else it may
i appear totally incomprehensible.
F
Gi
c
111
ORIC Manual
There are several ways in which you may make your program
clearer to yourself and to others. These are not hard and fast
rules, but they will undoubtedly improve your programming and
also make it easier if you decide to move on to other languages,
such as Pascal or Forth.
First of all, it is a good idea to write down your ideas for the
program on paper, rather than attempt to work them out at the
keyboard. This does not have to be in the form of a traditional
flowchart; indeed, flowcharts should not be necessary for well-
designed programs. Something simple to show the order of events
is all that is needed.
As an example, imagine that you have been asked to write a
program that will demonstrate how straight lines can appear as a
smooth curve. This effect is often called Curve Stitching.
This is the effect.
0 1 2 3 4 5 6
112
4 Chapter 12 Better Basic
F-
-ii
-
4 113
0RIC Manual
*********
THE MAIN MODULE.
When you reach the main section of the progam, then if it involves
graphics it is useful to sketch the finished display on paper and work
out which values will keep the lines within the screen boundaries.
How will the display be built up? It is possible to define each line
on the screen one at a time, but this is wasteful on memory and hardly
elegant. If you know the starting position of the lines and the step
size, it is better to use FOR/NEXT loops.
= 31 TO 3 STEP -2
FOR COUNT = 0 TO SIZE STEP INCR
DRAW ROUTINE
NEXT COUNT
114
Chapter 72 Better Basic
-
I make their structure clear. They will of course work with the semi-
7
colons and indenting removed.
- As has been previously mentioned, it is usual to space program
-
lines 10 apart to allow for additions at a later date.
To complete your program, it needs a title, as well as your name
and the date upon which you completed that particular version. This
4 makes it clear to you and anyone else what you intend the program to
-
do and it reminds you when you wrote it.
-G At a later date you may acquire a printer. Listings produced by this
--
means will look much neater, and your programs therefore easier to
4
-
decipher if they are neatly indented.
Deciding on a program and building it up in this manner is called
-
_ top-down programming. Building one up from program lines is
called, naturally enough, bottom-up.
Top-down programming produces a clearly-defined structure. It
also means that you rarely use GOT0 statements. Although they
appear initially to be the programmer’s friend, their unrestricted use
all over your programs will make them difficult to understand and
lead to that unpleasant syndrome, “spaghetti programming”.
-
w
10 PRINT “ENTER THE DATA”
20 INPUT A
30 IF A = 30 THEN GOT0 50
40 GOT0 10
50 GOT0 70
60 PRINT A;” WAS MORE THAN 100”:STOP
70 PRINT A;” WAS THE LAST NUMBER”
80 IF A> 100 THEN GOT0 60
90 END
This is rather an extreme example, but it does demonstrate how
ST confusing unstructured programs can be. Use of REPEAT/UNTIL,
t-
FOR/NEXT and IF/THEN . . . .ELSE will help you avoid falling
into a tub of spaghetti!
Here, then, is the completed curve stitching program. It is not
4
c
offered as the most wonderful program ever written, simply as an
example of how the use of loops, REMs and indenting can improve
the look of a program.
1000 :REM *** CURVE STITCHING **
1010 :REM
115
ORIC Manual
4120 :REM
5000 :REM ** MAIN PROGRAM **
116
Chapter 12 Better Basic
r 5010 :REM
7
5020 :REPEAT
i 5030 : FOR INCR = 31 TO 3 STEP - 2
7
5040 : HIRES
5050 .. PRINT “STEP” INCR
7-
-
5060 .. INK (INCR/6) + 1
5070 .. FOR COUNT = 0 TO SIZE STEP INCR
r
- ..
5080 CURSET 180-COUNT,l0,3
5090 .. DRAW COUNT,SIZE-COUNT,1
+
- 5100 .. CURSET 20,COUNT + 10,3
CI 5110 .. DRAW COUNT,SIZE-COUNT,1
-
5120 .. CURSET COUNT + 20,170,3
5130 .. DRAW SIZE-COUNT,-COUNT,1
5140 .. CURSET 20,COUNT + 10,3
5150 .. DRAW SIZE-COUNT,-COUNT,1
5160 .. NEXT COUNT
5170 .. WAIT 100
5180 : NEXT INCR
5190 :PRINT “PRESS ANY KEY TO STOP”:WAIT
500
5200 :UNTIL KEY$ < > “”
5210 :RETURN
-
7
c-
Advantages of a structured approach.
1. The flow of control is easy to follow.
2. The structures will fit into neat, separate modules.
3. The numbers of mistakes will be reduced, and those errors that
5i do creep in are easily eliminated.
4. The ideas inherent in this approach make learning other
languages and their application much easier.
I17
0RIC Manual
Disadvantages.
1. Structured programs may use more memory.
2. The speed of the program may be reduced.
3. The hardware of the computer may not be used in the most
economical manner.
4. It is harder to learn to write good structured programs than it is
to pick up sloppy habits!
Mug- trapping.
Writing structured programs may make you a better programmer,
but it is no guarantee that your program is as good as it could be.
When you test your pièce de résistance, then if it is designed to be
used by others it is important to consider all the silly things they may
decide to enter.
If you ask for a number to be input, what happens if a user enters
“two” instead of “2”? What happens if they press RETURN
without entering anything?
Luckily, ORIC is kind to errant users. In the first instance - a
string being entered instead of a number - REDO FROM START
will be printed until a figure is input. In the second case, ORIC will
wait until something is actually entered. If RETURN is constantly
pressed, then the question mark prompt will constantly re-appear.
You can make your requirements easier for the user to
understand. If you check the ASCII code of the input, or the value of
a number, then a message telling the user what to enter can be built
into your program.
1 0 INPUT “ENTER THE YEAR”;A$
20 IF VAL(A$) < 1900 OR VAL(A$) > 1985 T H E N
PRINT “BETWEEN 1900 & 1985,
PLEASE”:GOTO 100
30 PRINT “THANKS!”
If you draw a line or move a character, it is important not to go off
the edge of the screen or to print it in one of the protected columns.
You may realise this, but another user may not.
If A is the horizontal position and B the vertical position on the
HIRES screen, then something like this may help.
If A > 238 THEN A = 238
IFA< 1 THEN A = 1
IF B > 198 THEN B = 198
IFB< 1 THEN B =l
118
--ri
-
Chapter 72 Better Basic
119
I
f_
CHAPTER 13
Machine code programs
FA
4 13. Machine code programs
G
- 123
0RIC Manual
124
-4
- Chapter 13 Machine code programs
ADDRESSES
Perhaps you have wondered how ORIC can store numbers larger
than 255, particularly as there are 65536 different memory locations.
Addresses are stored as two byte numbers. e.g.
G
C
1st byte 2nd byte
G 128 is stored as 10000000 00000000
C
If the number is greater than 255, the second byte contains the
ii number of 256’s in the number.
F;
t 125
0 RIC Manual
126
Chapter 13 Machine code programs
;?
t- 127
0RIC Manual
128
Chapter 13 Machine code programs
It is useful to know which line the cursor is on if you need to use the
double height feature, so you do not end up with tops of letters under
their bottom halves.
A suitable line in a program to protect against this would be
500 IF & (0)/2< > INT(&(0)/2) THEN PRINT
This will move the cursor down to an even line.
Some of page 4 (locations # 0400 to # 0420) has been
reserved for your own machine code routines. Anywhere in memory
may be used for longer programs, but a Basic program may over-
write it if it occupies the USER PROGRAMS space in RAM.
To reserve memory for machine code programs, the top of the
user area can be lowered. To find its present position, enter
PRINT DEEK( # A6)
Work out how many bytes you require for your program, add on a
small number for safety (unless you are really pushed for memory),
and subtract the total from the number you previously found. Then
enter
HIMEM X
where X is the new top of user memory you have just calculated.
If you wish to learn more about using 6502 machine code, then
there are several books which cover the subject in great detail.
Some of the more useful ones are written by Rodnay Zaks
(published by Sybex) and Lance Leventhal (published by Osborne
McGraw-Hill). Other information and books can be obtained from
Rockwell International themselves.
129
14. Using a printer
-4 Oric may be used with any printer that has a Centronics interface.
r4
As well as the printer, you will need a connecting cable. The printer
connection is located at the back, next to the expansion port.
The printer should be connected before switching on. If all is well
the printing head should align itself at the starting position as soon
as power is supplied. In addition to the instruction booklet with the
printer, you may find the following information helpful.
On first connecting the printer, run the following program.
LLIST
This will list the program on the printer instead of on the screen.
If you do not get a listing, but merely Japanese or graphics cha-
racters, consult the printer handbook as to changing the character
set in the printer. When the listing is satisfactory run the program.
As you can see, it consists of a simple loop that will LPRINT
(print to the printer, rather than to the screen) the number followed
by the Ascii character that represents that code. This will show you
the character set available and, just as importantly, will show you
which numbers are read as control codes on the printer.
Although these are standardised to a certain extent, not all prin-
ters respond in the same manner. The control codes determine
actions such as line feed, carriage return, form feed, character size,
: etc.
c
For example, Microline printers will print standard, compressed
or expanded characters. If you were to type
LPRINT CHR$(31)
133
ORIC Manual
134
15. ORIC Basic
137
ORIC Manual
138
Chapter 15 ORIC Basic
139
ORIC Manual
140
Chapter 15 ORIC Basic
141
ORIC Manual
142
Chapter 15 ORIC Basic
143
Appendix B
146
Appendix G
Derived Functions
These functions are not directly available on Oric, but can be defined
using DEF FN. e.g:
DEF FN SC(X) = l/COS(X)
defines the secant.
Secant:
SEC(X) = l/COS(X)
Cosecant:
CSC(X) = l/SIN(X)
Cotangent:
COT(X) = l/TAN(X)
Inverse sine:
ARCSIN(X) = ATN(X/SQR( - X*X + 1))
Inverse cosine:
ARCCOS(X) = - ATN(X/SQR( - X*X + 1)) + 1.5708
Inverse secant:
ARCSEC(X) = ATN(SQR(X*X - 1)) + (SGN(X) - 1)*1.5708
Inverse cosecant:
ARCCSC(X) = ATN(l/SQR(X*X - 1)) + (SGN(X) - 1)*1.5708
Inverse cotangent:
ARCCOT(X) = - ATN(X) + 1.5708
Hyperbolic sine:
SINH(X) = (EXP(X) - EXP( - X))/2
Hyperbolic cosine:
COSH(X) = (EXP(X) + EXP( - X))/2
Hyperbolic tangent:
TANH(X) = - EXP( - X)/(EXP(X) + EXP( - X))*2 + 1
Hyperbolic secant:
SECH(X) = 2/(EXP(X) + EXP( - X))
152
Appendix G
Hyperbolic cosecant:
CSCH(X) = 2/(EXP(X) - EXP( - X))
Hyperbolic cotangent:
COTH(X) = EXP( - X)/(EXP(X) - EXP( - X))*2 + 1
Inverse hyperbolic sine:
ARGSINH(X) = LOG(X + SQR(X*X + 1))
Inverse hyperbolic cosine:
ARGCOSH(X) = LOG(X + SQR(X*X - 1))
Inverse hyperbolic tangent:
ARGTANH(X) = LOG((l+ X)/l - X))/2
Inverse hyperbolic secant:
ARGSECH(X) = LOG((SQR( - X*X + 1) + 1)/X
Inverse hyperbolic cosecant :
ARGCSCH(X) = LOG(SGN(X)*SQR(X*X + 1) + 1)/X
Inverse hyperbolic cotangent:
ARGCOTH(X) = LOG((X + 1)/(x - 1))/2
A Mod B:
MOD(A) = INT((A/B - INT(A/B))*B + 0.05)*SGN(A/B)
153
Appendix J
Error Codes
If ORIC cannot handle a command or some information, then an
error message will result. It will be followed by the line number where
the error occurred if it was in a program. These are the possible codes
and their meanings.
1.) CAN’T CONTINUE
Attempt to continue a program after a line has been added or
deleted.
2.) DISP TYPE MISMATCH
Attempt to DRAW in TEXT mode or similar problem.
3.) DIVISION BY ZERO
Difficult, even for ORIC!
4.) FORMULA TOO COMPLEX
More than two IF/THEN statements in the same line.
5.) ILLEGAL DIRECT
A statement such as DATA or INPUT has been used as a direct
command from the keyboard.
ILLEGAL QUANTITY
Out of range parameter, e.g. SQR( - 1)
NEXT WITHOUT FOR
Self-explanatory (one hopes!)
OUT OF DATA
Trying to READ past the end of the DATA list
OUT OF MEMORY
Self-explanatory, but might also be caused by more than 16 nested
FOR..NEXT/TO loops or sub-routines.
10.) OVERFLOW
38
A number larger than 1.70141* 10 has occurred during a
calculation.
11.) REDIM’D ARRAY
Attempt to redimension an array previously dimensioned.
12.) RETURN WITHOUT GOSUB
Self-explanatory.
156
Appendix J
157