In our first videotape on BBC Basic, we looked at the design of a programme, breaking it
down into procedures and we looked at the input statement to get numbers into our programme
and print to print them out again. And we also looked at some graphics, some very simple
line drawings. Now what we're going to go on and do during this videotape is to look
in a little more detail at some of the facilities you can use within your programmes. And we're
going to start by looking at the different types of variable a programme can contain.
Numeric variables and string variables. And you'll see the difference between them in
this programme. Now here we have a simple six line programme. Three input statements
and three print statements. And we appear to be using the variable A in all cases. But
there's an important difference. Here we have input and print for A by itself. Here input
and print for A percent. And here for A dollar. Now these are three different variables and
they're three different types of variable. And we'll be able to see the difference as
we try running this programme. There's my prompt from the first day of the programme.
First input statement asking me for a value of A. Let's use 100. A has been printed out
but instead of being printed right at the left hand side of the screen, it's been printed
out occupying a whole ten characters. Let's try A percent. Exactly the same thing has
happened. The number 100 has come back but it's been printed out in a ten character field.
A dollar. There's the first difference. When A dollar was printed out, it wasn't pushed
across towards the right. It was left at the left hand side of the screen. The first difference
between these variables is that A and A percent are both numeric variables and they'll hold
numbers. A dollar is a string variable and it doesn't hold a number at all but a string
of characters. So although we typed in the three digits 100 for each of these three variables,
when those digits went into A and A percent, they were treated as a number. But in A dollar,
they were treated as three separate characters. So our string A dollar has been printed out
without this extension to fill a field of size ten. Let's clear the screen and try it again
with some different values. We'll list the program again so that we can keep an eye on
which statement is being executed and we'll run it again. This time, we'll use the value
1.5. And we'll use 1.5 for each of our three variables. We'll use the value 1.5 for each
and there's the second difference that we notice. We put a value of 1.5 into A and when
we printed A, we got 1.5 back. Putting a value of 1.5 into A percent and printing A percent
gives us 1. The 0.5 has been lost. A dollar behaves as before. It doesn't treat 1.5 as
a number but as the three characters 1, 0.5. A percent is an integer variable. This means
that whatever value we try to put in it, it can only hold the integer part. It can't hold
any decimal places. A on the other hand is a real variable or you may see it referred
to as a floating point variable. This means that it can hold not only the integer part
of a number but also any decimal places it may have. If we tried running the program
again with a different set of numbers, let's use 1.12345.
Again, the difference between A and A percent, all those decimal places have been retained
in the variable A but were still left with only the integer part in A percent.
Now there are various things we need to look at with regard to the processing of numeric
variables. We'll start by looking at this business of having them printed out in a ten-character
field because often it's not convenient if we're trying to fill our screen with numbers
to have them all occupying ten characters. We have another small program here and we'll
use that to experiment with printing numbers in different formats. Now what we're doing
here is inputting a value for our variable A, assigning that value to a second variable
A percent and then printing them both out. The quotation mark I've put between A and
A percent in the print statement forces Basic to print them onto separate lines. So if we
run this coding and put in 1 as the value, then A and A percent have both been printed
in this ten-character field. Now we can change the size of this field by using a special
variable that Basic has. It's called at percent. Let's see the effect on this program of assigning
a value of 5 to at percent. If we run it again, again you can see the difference.
Again using the value 1, you can see the difference. Instead of the ones appearing
with a width of ten characters, our ones have appeared with a width of five characters.
So in the simplest way we can change at percent by giving it the value which is the number
of characters we want to have printed for numbers and then any print statements we execute
after that time will use that width. If we clear the screen, run the program again, let's
try it with some long numbers. Here I've got six digits to be printed and a decimal point.
There's the five because the integer value, A percent, can still get into a five-character
field. But because A has more than that many digits, Basic has decided that it can't print
it within the constraints of five characters and has gone ahead and printed the whole thing
anyway. Now we've only seen one very simple use of at percent, putting a simple number
into it to change the width with which a number can be printed on the screen. But if you look
in your user guide you'll find that at percent has several different parts and by adjusting
each of them you can change other things about the way the number is printed. Well we won't
discuss them on the videotape but when we record the program to show you these facilities
we'll include some examples of using at percent to give you different results and then you
can look through that program in conjunction with your user guide to see the sort of effects
that you can obtain. Now we've looked at real variables and integer variables and we haven't
really come up with a good reason why one should use integer variables at all because
they can't hold any decimal places. So why don't we use real variables for everything?
Well one reason for this is speed. Integer variables are quite a lot faster than real
ones and I can demonstrate that with this program. So let's look at some examples of
using integer variables. Now this coding has three repeat loops in it. Repeat until, repeat
until, repeat until. In this first loop we're going to time how long it takes to add one
to a variable a one hundred times. We start with a being zero and we repeat until a is
equal to one hundred a equals a plus one and so we'll loop around this a hundred times
with a getting bigger by one each time until we've reached a hundred. Now this statement
time equals zero sets the computer's clock back to zero. Time is a function in basic
which we can use to access the clock. Here we're using it like a stopwatch we're setting
it to zero at this point and then here in this print statement we're printing the value
of time. So having set time to zero before we do the loop and printing time afterwards
will give us an idea of how long this loop took. Time goes up each one hundredth of a
second so the number printed out here will be the number of one hundredth of a second
it took to do this loop. So the first loop uses the variable a. The second loop is exactly
the same coding but using the variable a a percent. The third loop does the same thing
with a percent. So a is going to be a real variable both a a percent and a percent are
going to be integer variables. When you see the times you'll see why I've included both
of these. The tabs in the three print statements have simply requested that the times be printed
on these lines so that we can see how they relate. Right let's run the program. Well
it didn't take very long and here are our three results. Remember these are hundredths
of a second. Our real variable a took twenty seven hundredths that's just over a quarter
of a second. Our integer variable a a percent took twenty one and a percent took sixteen.
So there's quite a big difference in speed between real and a percent. Now what's the
difference between a percent and a percent? They're both integer variables but a percent
is rather special. You'll remember that we can use any series of letters we like for
a variable name but any integer variable whose name consists only of a single letter followed
by a percent a percent b percent up to z percent is one of a set of variables called the resident
integer variables. Now they're special because they are faster and also because they're safe.
Even if your program is destroyed the values in those variables will be kept. I'm going
to press break now. Now you wouldn't normally do this when you're running a program. We'll
lose our blue screen but we'll be able to see which of our variables have kept their
values. Back to the initial BBC computer basic screen. Let's print a. No such variable. Let's
print a a percent. Again no such variable. If we print a percent we get a hundred. That's
the value that was left in a percent after we went round that loop adding one to it.
So real variables have the advantage that we can put any value into them whether or
not it has decimal places but integer variables have the advantage of speed. They're quite
a bit faster and if we use the resident integer variables that's the ones whose names consist
only of a letter and a percent sign then those values will remain safe even if we go from
one program to another. So they can be very useful when we have one program which wants
to pass values to another program that's going to be executed immediately. Now as we're
talking about processing numbers and processing numeric variables there are two more operations
we should look at. They're called div and mod and I have a little bit of coding here
which will show you how they work. What I've done here is to put values eight and five
into variables a and b both of them real variables and then these three print statements will
print out the results of a divided by b a div b and a mod b. Now divided by is the normal
division and it works in the way that we'd expect it to. Div is integer division. It
takes the integer value of a the integer value of b divides a by b and gives us the result
as an integer and related to that is mod which gives us the remainder when we divide the
integer value of a by that of b. Let's run the program and see what results we get. A
divided by b is eight divided by five which is one point six as we'd expect. A div b is
the integer result of dividing eight by five so it's effectively the integer value of one
point six in this case. A mod b gives us the remainder three which is the remainder when
we divide eight by five. Let's try that again but with a different pair of values. I've
changed this program slightly to use different values. I've used non integer values for a
and for b twelve point one and two point one. If we run this version of the program you'll
see something quite important that although a divided by b gives us a value of five point
several decimal places. A div b gives us six because both a and b are changed to integers
before the division is done so the point one is ignored in each case and a div b is effectively
twelve divided by two giving us six. Similarly a mod b the remainder gives us nothing because
that's working in the same way dividing twelve by two and giving no remainder. Well we've
looked at some different things we can do with numeric variables some of the different
operations and some of the advantages and disadvantages of each type. Now we're going
to have a break at this point and on the soundtrack of your video cassette you'll find a program
which demonstrates the things we've been talking about. When we come back at the end of that
program we'll move on to look at string data and the things we can do with that.
Thank you very much.
Now although we use computers a lot to process numbers we'll also find many times when we
need to process strings of characters as our data. They could be people's names or addresses
it could be the high score table in the game you're writing. So we need variables and we
need functions and different types of statements that will allow us to manipulate strings of
characters. Well I've got a very small program here which will start us off looking at some
of those functions. If we run it we'll get this an invitation to enter my name. Well
I'll use my name and it gives me back two numbers. Now the first of those numbers the
14 is the total number of characters that I typed. The second number the 6 is telling
me how far from the beginning of the string the first space was. So it's giving me information
which will allow me to work out how long the first name was and how long the second name.
Well if we clear the screen and look at the listing of the program we'll see the four
statements that did that. Statement 10 is an input statement inviting us to enter a
name giving a single quotation mark so that the value we type in will go on to the next
line and then accepting a value into the variable name dollar. And remember because
of the dollar sign at the end it's going to be a string variable. The second line 20 puts
a value into gap percent. The value that's going into gap percent is the value that this
function instra will give us. Now instra looks in one string to see if it can find another.
The two strings we've used are name dollar value we typed in and a string containing
just a single space. Quotation marks at either end with a single space in between them. So
instra will look along the value of name dollar searching for a space. As soon as it finds
one it'll stop looking and the value it gives us back will be the position of that space.
The next line 30 puts a value into L percent using a different function which is len to
give us the length of a string. The value len gives us back is the total number of characters
that are in name dollar. So that when we print out L percent the length and gap percent the
position of the first blank in the name will have those two pieces of information we saw
a moment ago. Let's run it again using a different name.
We'll try Joe Soap. We've typed in a total of eight characters. Remember that space counts
as a character. Three, one and another four gives us eight. The value of gap percent is
four because that space occurs in the fourth position in the string. Now having got those
two pieces of information we can then go ahead and calculate how long the first name is and
how long the second one. And I've got another version of this program which uses those two
pieces of information in just that way. Well we'll run the program first to see what it
does. The same prompt, enter your name.
And as you can see the program has managed to split that into its two halves giving us
the first name and the second name. Well I'll clear the screen and list the program for
you so that you can see the statements that do that. The first three statements here are
the same as the ones we saw before. These next two lines forty and fifty put values
into first dollar and last dollar. These are two new string variables that we're going
to be using. We've used two new functions here as well. Mid dollar and right dollar.
Notice that these functions have dollars as part of their names and this tells us that
the value they give back is a string value and not a number. Instra and Len both gave
us back numbers so their names did not contain dollar signs. Now mid dollar gives us the
value of a part of a string. The first value we've specified is name dollar, the name
we typed in. The second is a number and this tells us where within this string we want
to start. This number tells us how long we want the string to be. So we've said using
mid dollar take the value that's in name dollar, that's this variable here, starting in position
one and for length gap percent, gap percent remember was the position of the first space,
the position of the first space, take out a string from the middle and put that string
into first dollar. Line fifty uses the function right dollar and that's going to take characters
from the right hand end of name dollar. How many of them? Well that's what the second
value here specifies, L percent minus gap percent. Well L percent is the total number
of characters, gap percent is the position of that space character. So right dollar should
give us all the characters after the space and put them into last dollar. And finally
our two print statements print out first dollar and last dollar. We'll just run that program
with Joe Soap and see what numbers will have been involved. L percent will be eight, a
total of eight characters. Gap percent will be four, position of the first space. So into
first dollar we're putting the middle of the value of name dollar starting in position
one and of length gap percent of length four. So we'll take the first four characters and
this name, J O E and the space and put them into first dollar. Into last dollar we're
taking characters from the right of name dollar. How many characters? L percent is eight, gap
percent is four. That gives us a value of four characters from the right hand end of
name dollar. The last four characters of name dollar are soap. And so that's what we've
had printed out as our second name. Let me just clear the screen, list the program and
run it again using a slightly different name. Instead of Joe Space Soap I'm going to put
several spaces in between the two words. And there's the result. The first name still looks
alright but all those extra spaces or at least most of them have appeared as part of the
second name. That's because of the way this statement worked. Gap percent found the position
of the first space and so into last dollar we put all the characters following the first
space. Because we had several spaces in between the words our second name has spaces at the
beginning of it. And there's one other small problem with this program and that's to do
with the value of first dollar. Here into first dollar we've put four characters. J-O-E and
the space. Whereas in fact really we should only put three characters. That space isn't
part of the first name. So we're going to need a slightly more complicated version of
the program to do the job properly. If we run the program we can check to see if it
works. And I'll put several spaces in between the two names. And yes we seem to achieve
the correct result. Instead of all those spaces having been carried forward to the beginning
of the second name only the last non-space characters have been put into the second name.
Let's check that we've got the correct length for the first name. And I can do that by printing
the length of first dollar. Its value is five which is the correct number of characters
for the first name. Well I'll clear the screen and list that coding so that we can see how
we achieve that result. We've inserted an extra line of coding here, line sixty. It's
quite a complicated line so we'll have to go through it slowly. Line fifty puts into
last dollar all the characters from the right hand end of the name including maybe some
extra spaces. Now the first statement here in line sixty checks the first character of
the last name. If left dollar, last dollar, comma one is equal to a space. If left dollar,
last dollar, comma one is equal to a space. Left dollar is the opposite of right dollar.
It looks at characters on the left of the string. We've taken one character from the
left end of last dollar and we're asking if it's a space. If it is a space, then it's
a space. Then we have to remove that space and any others following. But if the answer
to that is no, but the last name does not begin with a space, then we can continue straight
down here and print out the first and the second names. So let's look at this coding
which is the work we do if we found a space. It's a repeat loop. Repeat until. Repeat until
left dollar, last dollar, one is not equal to a space. So that's the opposite comparison
to the one we made. Less than and greater than together mean not equal to in basic.
So we're going to execute this statement over and over again until there are no spaces at
the beginning of last dollar. So what does this statement do? It puts into last dollar
the value returned by mid-dollar. You remember we've already used mid-dollar to take a section
of a string. We're doing it again here, but we've only put two values in brackets after
it. Up here we used three separate values. We're going to take the middle of string last
dollar starting with the second character and because we haven't put a third value there,
it'll go all the way to the end of the string. So the effect of that statement is to put
into last dollar the value it had, but without the first character. So we're removing spaces
from the beginning of last dollar until there aren't any more spaces left at the beginning
of last dollar. If we run the program using Joe Soap with three spaces in between, then
gap percent will have been four, L percent will have been three plus three plus four
giving ten. First dollar will be the first three characters because we've made that correction.
We've reduced the length by one and last dollar will be all the characters in name dollar
starting at the right hand side of length ten minus four, six. So we'll have the four
letters for soap and the two spaces that are on the front of them. This will be true. The
first character of last dollar will be a space, so we remove the space from the beginning
of last dollar. This is not true because we do still have a space at the beginning of
last dollar, so we'll repeat again and remove another space from the beginning of last dollar.
Having removed two spaces, we'll now be down to soap, just the four characters. That will
be true. The first character of last dollar is not a space and so we can continue and
print out the two names. Now we've looked at some of the functions that BASIC provides
you with for handling strings and some of the ways in which you can use them, but there
are quite a lot of them and they do require careful attention. After you've watched this
session of our videotape, I would recommend strongly that you check all those functions
in your user guide. Look at all the rules for using them and the values they give you
back and experiment with them. Take the program that we've been working with and change it.
Make it work with several different names. Make it remove spaces at the front of the
first name if there are any. To help you do that, we've recorded that program onto the
soundtrack of this videocassette and that follows immediately. After that program, we'll
start looking at some graphics.
When we started using graphics, we used move and draw statements and all the positions
on the screen, positions to move to and positions to draw lines to, used absolute coordinates.
That is that they measured all distances from the origin, which is in the bottom left-hand
corner of the screen. So that if we were writing a procedure to draw a house, then the coding
would look something like this.
When we started using graphics, we used move and draw statements and all the positions
on the screen, positions to move to and positions to draw lines to, used absolute coordinates.
If we were writing a procedure to draw a house, then the coding would look something
like this.
I've written a procedure and I've called it PROC HOUSE and the purpose of this procedure
is to execute all the move and draw statements necessary to produce a little house. We start
by moving to 200 200, which is fairly close to the bottom left of the screen. All the
numbers I've used in the move and draw statements refer to absolute coordinates on the screen.
All the X coordinates are measured from the left-hand side. All the Y coordinates are
measured from the bottom.
I can get this house drawn simply by entering PROC HOUSE. And there you see it.
Very simple line drawing. Now that's all very well, but if I wanted a house in a different
place on the screen, then I'd have to go and change all of these numbers because these
are all absolute positions on the screen. If I want a more flexible technique for doing
drawings, which will allow me to change the position very simply, then I can use another
statement instead of move and draw, and that's the plot statement.
If we imagine that this is part of our graphics screen, then this bottom left-hand corner
is the origin and its coordinates are 0 0. And we can refer to any other point on the
screen by using as its coordinates the distance up and along measured from the origin. And
these are called the absolute coordinates. So in the X direction, this point would have
address 3, and in the Y direction, it would have a coordinate of 6. So if we were going
to draw a shape such as that using absolute coordinates, then we would have to find the
coordinates of every point on that shape that we were going to draw lines to.
And put those coordinates in our program. That's how we do it with move and draw. But
if we're going to use plot, we can use another technique. We can move to this point, and
then instead of working out the absolute coordinates of the next point and then of the next one,
we can say to get from this point to this point, we have to move no distance in the
X direction, but we have to move two points in the Y direction. Similarly, to get from
this one to this one, we're moving two points in the X direction and one in the Y direction.
So the coordinates of that point relative to that one are simply the distance one has
to move to get from one to the other. To get from here to here, although we have an X
coordinate of two relative, becoming down the screen. So we have a negative distance
in the Y direction. Now by using a plot statement, we can compose a shape that forms a house
or whatever else it is that we want to draw. We can then move to any point on the screen,
and that can then be plotted in that position on the screen using relative coordinates.
Let's look at the coding that does that. Now here's a second version of that procedure.
I've called it proc house two. And instead of move and draw, we've used nothing but plot
statements. Plot one and plot zero. You'll notice that the plot statement has three numbers
following it, compared with the two numbers we used for move and draw. This is because
the first number tells basic what sort of plot we want. Plot one is a drawing plot,
and plot zero is a move without drawing. But the difference between plot one and draw is
that these two numbers are relative coordinates. They're relative to the point where we are
now. Similarly, plot zero is a move relative to where we are now. So if we take this one
as an example, no matter where we were on the screen, if we then executed this plot
statement, which is a relative move without drawing, we'd move zero positions in the X
direction and 50 positions in the Y direction, so that we'd move straight up 50 graphics
units. Now don't worry too much about trying to remember all the numbers we've used here,
because we'll record this coding on the cassette a little later. Now the advantage of having
a relative move and draw instructions here is that we can go to any point on the screen
and then execute PROC HOUSE 2, and our house will appear. Let's suppose we want one around
here somewhere. Well, let's suppose that that was position 600 comma 500. We can start by
moving to that position. We can't see anything, because of course move doesn't change the
screen at all. But if we now say PROC HOUSE 2, we get a house. And it will have started
in position 600, 500. If we want another house in a different place, suppose we want one
somewhere up here on the screen, we can move to a different point and call the same procedure
again. Let's move to 800, 800. We can move to 800, 800, 800, 800, 800, 800, 800, 800,
800. Again, we can't see anything, because we simply executed a move. And now to save
myself some effort, I'll use the copy key and call the same procedure again. As you
can see, another house has appeared, but this time we started in position 800, 800. So relative
drawing and moving using PLOT 0 and PLOT 1 can be very useful if we want to move a shape
from one position in the screen to another position. Having done the work of defining
our shape, we can then use it as many times as we like on the screen, putting it in any
position that the computer can reach. Now if I didn't stop it, that program would continue
forever. So I'll press escape and break out of it. Let's have a look at the coding that
I used to call PROC HOUSE over and over again to draw houses in different places on the
screen. The first six lines of this program do the work, so let's have a look at them.
First statement, mode 1, but if you're using a 16K machine, then of course you could have
used mode 4. You've seen a VDU-19 statement before. In this case I wanted a blue background,
so VDU-19-0 for the background color to be changed to color number 4, which is blue.
I now have a repeat loop, repeat until false. False is a special value that Basic gives
us, which will never be true. So this loop would continue forever until I stopped it
some other way. I have a move statement and I'm using two occurrences of a function called
RND. This gives us a random number. I've said RND 1000, and so that's a random number between
1 and 1000. So the effect of this move statement is to move to a random position on the screen
with an X coordinate, which is a random number from 1 to 1000, and a Y coordinate, which
will be a different random number between 1 and 1000. Let's just leave this statement
for a moment. Just check, here we have PROC HOUSE 2, the statement which calls the procedure
to draw the house. So move and draw the house. Move to a different position, draw the house
again. So the house will be drawn starting in whatever position this move statement took
us to. This statement here, I equals INKY 15, is an easy way to slow the proceedings
down. This causes a delay of 15 hundredths of a second between the drawing of one house
and the drawing of the next one. What the INKY function actually does is to wait for
up to that many hundredths of a second for a key to be pressed. If I had pressed a key
in that time, the key number would have been put into I, and we'd have continued. As I
didn't touch any keys, it caused a delay of 15 hundredths of a second between the drawing
of one house and the drawing of the next. If I remove that statement, the INKY function
will be pressed, and repeat the program with just PROC HOUSE 2 in that position. You'll
see how much faster it goes. Now it's all very well to do simple line drawings in one
colour, but with a computer like the BBC machine, we ought to be able to do something a little
more adventurous, and of course we can. For a start, we can fill in solid shapes by making
those shapes out of a series of triangles, because one of the plot codes tells the computer
to draw and fill in a triangle, and of course we can change colour while we're doing the
drawing. Let's look at a different version of the program, which is doing basically the
same thing, but including both of those facilities, a colour change and a triangle fill. So here
we have not a white outline of a roof, but a solid red roof, which is a single triangle,
and if you look closely at the door, you'll see that that's a red rectangle, which in
fact we've constructed out of two red triangles drawn side by side. Well, let's stop that
and have a look at the coding that produced that. Here's the revised version of PROC HOUSE
2, and the first thing we notice is these two GCOL statements. GCOL stands for graphics
colour, and is the statement we use to change the colour in which graphics are drawn. It
doesn't affect the text at all, only the graphics. The 3 and the 1 in these positions say logical
colour 3 and logical colour 1. As I said, I'm using mode 1, so logical colour 3 is white,
logical colour 1 is red, although I could change those using my VDU-19 statement. If
you are using a 16K machine, you could get the same effect in mode 5. Now the other differences
come with these statements, the plot 81 statements. Plots can have various numbers for different
numbers, from 0 up to 87. 81 says plot a triangle using relative coordinates and fill it in.
This one does the roof, and these two together do the front door, two triangles side by side
which form a rectangle. Now when we use a plot 81 to draw a triangle, it uses the vertical
points that we specified in the plot statement, and the last two points we visited. So in
order to see exactly where this triangle would appear, we'd have to go back and work out
where that point was, and where that point was, because BASIC is going to join up these
three points together to decide what triangle to fill in. Similarly, for this plot 81, we
fill in a triangle defined by this point, this point, and this one, and then the final
plot 81, a triangle defined by these three points. Now we've only touched on a few of
the numbers that you can specify with plot, but when you read your user guide, you'll
find that there are a great range of plot codes going from 0 up to 87, all doing different
things. And for each one that you read about, you need to check to see whether it uses relative
or absolute coordinates, whether it's a move or a draw, whether it's drawing a line or
filling in a triangle, or doing any of the other things that plot codes can do. However,
it's worth experimenting with them. You can't do any harm, and you may very well produce
some interesting effects. Now we'll record this program, the one drawing the houses,
onto the soundtrack of this video cassette, so that you can look at it and use it as a
basis for your experimentation.
That's one way of producing shapes on the screen, using draw, move, and plot statements.
But there's another totally different way, which involves printing characters. Now we
could make shapes with the characters that are provided automatically by the machine,
but we are allowed the facility to define our own character shapes, and we can use
these to produce animals, men, whatever shape we want.
Now, the way that we can do this is by using the
characters displayed in modes 0 through to 6 on the machine are expressed in terms of
an 8 by 8 square of dots. So the first thing to do when you want to design a character
is to get yourself an empty chessboard. Now in order to design one of our own characters,
we have to imagine that each character occupies a square consisting of 64 spots, 64 points
of light, 8 across and 8 down. And we design a character by imagining whichever ones we
want filled in, in whatever color we're going to use. All the letters, except in mode 7,
for example an A, would be designed as certain of these points of light turned on and certain
turned off. Now there are a large number of possible configurations of on and off. I'll
give you an example of one I drew out a few moments ago. This would be a single character
on the screen as long as we can describe to BASIC exactly what points of light are switched
on in each of these rows across. The way we do this is by writing a list of 8 numbers.
Each of these numbers is a value for one of these rows of points. We have to think of
the points in this row as being worth 1 each. In this row, 2, 4, 8, 16, 32, 64 and 128.
And then for each point that we filled in, we have to add up the values for the whole
row. Now that sounds a little bit complicated when I describe it on a piece of paper. So
I've written a program which we'll record on the soundtrack to help you design your
own characters. So let's transfer this picture to the screen and see how it works. This area
represents one character and the program has drawn it as a large block so that we can easily
see what it's going to look like. This column of numbers down the side gives the value of
each of these rows of dots, 8 of them forming one character. At the moment, they're all
set to background so all these numbers are 0. These numbers here remind us of the value
of each position along the row from 1 on the right hand side up to 128 on the left. I've
used these two symbols to show which pixel, which point of light we're pointing to. Now
the program is written so that when I press the tab key, that block is changed in color.
Its value is added in to the appropriate figure on the right hand side. And then down at the
bottom here, we see how the character is progressing in three different colors. To turn a different
point on, I use the cursor keys. To move to the right, I press tab again. You can see
I've got another point of color here. My character now consists of two spots and the value for
this row is 136. 128 for this spot and 8 for this one. So 136 is the value of each of these
followed by seven zeros would describe a character looking like that, one with two spots. So
our next job is to transfer this picture of our little man onto this grid. Well, we'll
use the space bar to rub that one out because we don't need it and then start filling in
dots on the top row. Down to the next row, leave a space for his eyes and the next row.
That's the end of his left foot. Now you can see here that I've copied the shape of the
complete figure onto my grid. I now have my eight numbers down the right hand side which
I will use to describe this shape. And here I have my three little men in three colors
showing me what it will look like when it's printed as a single character on the screen.
If I now press return, these eight numbers will be incorporated into the grid. And then
integrated into a VDU statement which I can copy down and use in one of my programs. So
I'll press return. It's a VDU 23 statement. Check this in your user guide because this
is a statement used to define your own characters. There is the set of eight numbers which describe
that character. And where the program has printed three question marks is where we have
to insert a character number. We can use characters from 224 up to 255 for our own purposes. So
I'll use the editing keys and I'll copy that statement. Only I'll make it character number
240. I've now executed that VDU statement saying that character number 240 is going
to be defined by that series of numbers. And now I need to be able to print character 240.
Well there are two ways of doing that. One is to say print and then use the CAC code
VHR dollar function which stands for character with the number in brackets after it. That
says print the character whose number is 240. If I do that you see I get my little man.
The alternative is to use a VDU statement simply specifying the number VDU 240. And
we get the same result. We've described that character. It's now been stored in the machine's
memory and every time we print character number 240 we'll get this little man. Depending
of course on how many of him I want I could write a loop or write a program to print out
hundreds of them. As I said we'll record a copy of that program onto the soundtrack so
that you can then use it yourself to define your own programs. Well we've just about come
to the end of this tape. We've looked at different types of number processing. We've looked at
manipulation of strings. We've looked at using graphics and the plot statement and we've
done a little character definition. This should set you fairly well on the way to writing
quite complicated programs especially if you look at the coding we've provided and you
follow things through by reading the appropriate section in your user guide. So good luck with
your programs and I'll leave you with our little friend.
Thank you.