The last part of this chapter will consist of some convenient and sometimes
even funny (sub)routines. Some programs will be explained in more detail,
so you will understand the functionality of the program and how to use
it best.

What is happening in this program probably looks familiar. In the well
known game PAC-MAN this routine is used, there, the main character is
chased by a ghost. In this program nothing is chased, but if the target
would move, this is exactly what would happen.

Very little can be said about this program. In lines 90 and 100 the
character is sent to its target. If the target would move, two lines
must be added in case the character is beneath or at the right of the
target. This is a nice exercise for the reader.

Everything in this program actually revolves around the CONSOLE instruction.
Before this instruction is discussed, you must know something. The screen
consists of 25 rows. The first row corresponds with the number 0 and
the last one with 24. This is where the CONSOLE command is based on.
The first number following the CONSOLE instruction denotes the first
row to which the instruction applies and the second number denotes to
the number of rows that will be affected. The CONSOLE command splits
off a certain number of rows on which a couple of instructions no longer
apply. The area outside the selection is only affected by a few instructions.

Here a a couple of examples:
CONSOLE 1,24 - Row 1 through 24 are affected by all instructions.
CONSOLE 5,10 - Row 5 through 14 are affected by all instructions etc.

For those who still do not fully understand this instruction: Look
inside the manual, a good explanation is given for all instructions;
as for the CONSOLE instruction.

Sorting data is commonly used in programs, that is why we discuss it
here. First a short explanation about the operation of the program is
in order.

Why only capitals, you might wonder. People who know the character
set of the SHARP will know that the capitals are neatly in alphabetical
order. This is not the case with the small letters, those are scattered
all over the place.

We sort the list according to the character set. The letter that occurs
first in the character set will come first. If the letter a
is further on in the character set than the letter e, then
e will precede a.

By using a small piece of machine code, we can change all this, but
we are not going to do that just yet.

Sorting data is used in all sorts of files and similar programs. These
programs usually do not sort only by name, but also by address, zip
code, place name and so on. Those programs will have a more difficult
sorting scheme than the one described above. With this program you can
get started, but if you want to sort a big file this program is not
suitable, you should experiment more with sorting before you can do
things like that.

This program writes 10 numbers to a tape. Writing to tape is
done with the instruction PRINT #2. This way you can write all sorts
of data to tape, even names and things like that. You can also write
to other devices, like QD, FD, RS232 and so on. The manual is very clear
on this subject.

WOPEN stands for WRITE OPEN, in other words, make sure we can write
data. This instruction ( always ) proceeds the PRINT instruction. At
the end of the program do not forget to close with CLOSE. Of course
you would like to know how to read the written data again. Here is the
code to do it:

Of course you first have to rewind your tape before running the
program.

As you see, this program has much in common with the previous program.
The main difference is that instead of WOPEN #2 it says ROPEN #2 and
it says INPUT instead of PRINT. ROPEN stands for READ OPEN, in other
words, make it possible to read data. INPUT normally stands for input
and PRINT for output, this is no exception. So it is all pretty logical.
Do not forget to close with CLOSE #2.

There are some more instructions that can be used like EOF and the
like, but these instructions are not really relevant at this point.
For the time being the two programs above should be more than sufficient.
The other instructions are almost never used.