BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (April 1986), page 81

[The 1st part of a series of articles creating a set of utility routines,
ending with the October 1986 issue]

It doesn't take long before the limitations of Basic cause us to give up or
progress into machine code. What I hope to do is give a series of machine code
routines which can be used by expert and novice alike to improve the 81's speed
and performance.

What I have is a loader program with a massive REM at the start, this Rem
contains a suite of programs which perform such essential tasks as a variety of
Inputs, Prints, Pauses, Scrolls and screen effects. By keeping careful notes of
register values, I then use those which apply to whatever program I am writing.

I hope to give you a similar utility which perhaps other readers may like to
contribute to, so building into a program which even QLers will envy!

As computers are supposed to make life easy, our first program might as well
create our REM for us.



BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (May 1986), page 81

[The 2nd part of a series of articles creating a set of utility routines,
started in the April 1986 issue and ending with the October1986 issue]

This is a program designed to extend a REM. To use it type in a 2 REM ...
followed by as many dots as you require to add to your existing line 1 REM.
Then RAND USR 16514. If you forget to add the 2 REM then your next line which
may be a program line will be added to your REM and could cause a little
confusion!

A little fun routine which simply turns everything on the screen to its
inverse. Useful for effects or creating a black screen very quickly, try using
in a loop such as:

   10 FOR I=1 TO 50
   20 RAND USR 16550
   30 NEXT I

This works by peeking at each screen position in the display file in turn,
adding 128 to it and poking it back onto the display file, ignoring end of line
markers of course.


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT



BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (June 1986), page 81

[The 3rd part of a series of articles creating a set of utility routines,
started in the April 1986 issue and ending with the October 1986 issue]

This month, as promised, I have got four scrolling routines to be added to your
REM collection.

Some may well ask why we need a routine to scroll up when there is already a
built in command SCROLL. Well, the ZX81 scroll is designed to operate in 1K
mode and can severely disrupt the display file. While the '81 can cope with it
without problems, if you try to use any of our other screen routines then the
machine will become totally confused and go away and sulk! The routine given
keeps the display file intact.


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT
USR 16575 = SCROLL DOWN
USR 16610 = SCROLL UP
USR 16640 = SCROLL LEFT
USR 16675 = SCROLL RIGHT




BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (July 1986), page 81

[The 4th part of a series of articles creating a set of utility routines,
started in the April 1986 issue and ending with the October 1986 issue]

I include a short but interesting routine which will draw a border around the
screen. You can change the border character by POKING the character value you
want to 16726.


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT
USR 16575 = SCROLL DOWN
USR 16610 = SCROLL UP
USR 16640 = SCROLL LEFT
USR 16675 = SCROLL RIGHT
USR 16725 = DRAW BORDER




BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (August 1986), page 81

[The 5th part of a series of articles creating a set of utility routines,
started in the April 1986 issue and ending with the October 1986 issue]

We have now reached the stage where we must move away from short relocatable
routines and begin to build a series of subroutines which further routines in
this series will make use of. It is therefore of the utmost importance that we
use consistent addresses so that future CALLS will function. I am going to set
these routines at 16900 onwards.

The block of code consists of five routines and a useful application.

KEYBOARD SCAN - 16900

The first routine is a general purpose keyboard scan and conversion to
character code. This is not checked for any limits and the resultant key press
is returned in register A which is pretty useless if called from BASIC. A=1 if
no key was pressed.

This routine is 15 bytes long and is used by all the following routines.

NO KEY PRESS - 16915

A routine which may appear to be pointless. It simply waits until NO keys are
being pressed before continuing. When you remember how fast machine code works
you will realise that if subsequent keyboard scans are required then unless the
computer waits until the previously pressed key is released a multiple input
will occur. Fine for real-time games but not much else!

KEY PRESSED - 16923

The opposite to the last routine and it waits until a key is pressed before
continuing. Both these routines are used by other routines and can be used from
BASIC as long as there is no need to know which key was pressed (i.e. a "press
any key to continue" prompt).

GET A NUMBER - 16931

Does the some as the last routine but this time only accepts a number from 0-9.
Note that the A register contains the CODE of the number NOT its value, you
will have to SUB 1Ch from the returned number to get the value.

GET A LETTER - 16945

Does the some as the last routine but this time only accepts a letter from A-Z.
Note that the A register contains the CODE of the letter.

PRESS A KEY - 16959

A routine to demonstrate how the inputs can be used. From 16959 to 16974 is a
piece of code to print the message held at the end of the routine.

16975 calls the 'no key pressed' routine to ensure no carry over from the last
key held.

16978 calls the 'key pressed' routine and returns.

16982 to 16992 holds the message.

Used from BASIC or machine code whenever a "PRESS ANY KEY" message is required,
the text being printed centrally at position 21,11.


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT
USR 16575 = SCROLL DOWN
USR 16610 = SCROLL UP
USR 16640 = SCROLL LEFT
USR 16675 = SCROLL RIGHT
USR 16725 = DRAW BORDER
USR 16900 = KEYBOARD SCAN
USR 16915 = WAIT UNTIL NO KEY PRESS
USR 16923 = WAIT FOR KEY PRESS
USR 16931 = WAIT FOR ALPHABETICAL KEY
USR 16945 = WAIT FOR NUMERICAL KEY
USR 16959 = DISPLAY "PRESS A KEY" MESSAGE




BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (September 1986), page 81

[The 6th part of a series of articles creating a set of utility routines,
started in the April 1986 issue and ending with the October 1986 issue]

The "Get a Letter" and "Get a Number" routines are both very useful for
programs which use either a menu of option system of working but it is still
very limiting when you want a series of characters to be input, as in entering
a name or commands for adventure games.

So this month I have provided a routine to accept a string of multiple
character entry.

The first thing to do is to set up a buffer to store the sequence of
characters, I have used from 17000 to 17049 which allows for 50 characters.
Note that the buffer address is absolute and you will have to modify the code
if you want to put it elsewhere.

Next month I'll give a routine to print out the contents of the buffer, experts
may like to write their own as a kind of exercise.


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT
USR 16575 = SCROLL DOWN
USR 16610 = SCROLL UP
USR 16640 = SCROLL LEFT
USR 16675 = SCROLL RIGHT
USR 16725 = DRAW BORDER
USR 16900 = KEYBOARD SCAN
USR 16915 = WAIT UNTIL NO KEY PRESS
USR 16923 = WAIT FOR KEY PRESS
USR 16931 = WAIT FOR ALPHABETICAL KEY
USR 16945 = WAIT FOR NUMERICAL KEY
USR 16959 = DISPLAY "PRESS A KEY" MESSAGE
USR 17051 = STRING INPUT




BIG REM PROJECT (16K ZX-81)
by Ray Elder
from ZX Computing (October 1986), page 81

[The 7th (& final) part of a series of articles creating a set of utility
routines, started in the April 1986 issue and ending with the October 1986 issue]

This month I am giving some code to print out the characters entered by last
month's input routine and then to develop an all purpose text storage routine
that can be used with it.

The code to print a stored set of characters is easy:

1. Load register pair HL with the start address where the text resides.
2. PEEK it into register A.
3. Compare it with 118, the NEWLINE character.
4. if it is 118 end and return from the routine.
5. Print it at the next character position.
6. Increment the HL address by one.
7. Go and do it all again by jumping to step 2.

As given it leaves the print position at the space immediately following the
last character printed. If you move step 5 to between steps 2 and 3 then the
print position will be placed at the beginning of the next line.

So far so good. Its easy to call it from BASIC by using PRINT AT y,x; first,
but setting the x and y position from machine code needs a little program
itself. One such is as follows, all it does is set register H to the x or
column position and L to the y pos or line number and store it in the VARS
16441.

In Mnemonics: LD H,col : LD L,line : LD (16441),HL
Or in HEX, 26002E15225764


Routines:
USR 16514 = REM EXPANDER
USR 16550 = SCREEN INVERT
USR 16575 = SCROLL DOWN
USR 16610 = SCROLL UP
USR 16640 = SCROLL LEFT
USR 16675 = SCROLL RIGHT
USR 16725 = DRAW BORDER
USR 16900 = KEYBOARD SCAN
USR 16915 = WAIT UNTIL NO KEY PRESS
USR 16923 = WAIT FOR KEY PRESS
USR 16931 = WAIT FOR ALPHABETICAL KEY
USR 16945 = WAIT FOR NUMERICAL KEY
USR 16959 = DISPLAY "PRESS A KEY" MESSAGE
USR 17051 = STRING INPUT
USR 17100 = DISPLAY INPUT STRING


TEXT STORAGE (16K ZX-81)
by Ray Elder
from ZX Computing (October 1986), page 81

While this is fine for printing text entered from our input routine it can also
be used to print longer previously stored text for instructions, messages,
adventure games etc, and so I offer this program as a means of storing larger
text easily.

To use it decide where in your REM you wish to store it and enter that address
at the start [to store in 2 REM set the address to 16531]. Several sets of text
can be stored immediately after each other and the start addresses are given at
each stage. Make careful note of these addresses for later use in loading the
HL registers when you wish to use them.

There are many variations which we could use, for instance by including the
code 21000D097EFE76C8D723l8F8 at the start of each text item all that would be
required to print it would be a simple CALL to its address, but this is merely
a suggestion for advanced users to play with.
