ZX81 SCREEN LASSO (16K ZX81)
by Mart Stenlake, Whitwick, Leicester
from Your Computer (April 1985), Pages 99-102

Yee-ha! Git those screen blocks movin'. Mart Stenlake cuts those
screen-handling problems down to size.

SCREEN is a machine-code program for the 16K ZX-81, enabling the creation,
editing, moving and storing of any rectangular block of the screen. The
following facilities are included.

- Any block size from one character to a full screen may be defined on the
screen.

- There is full on-screen editing, and all single characters - including
graphics and inverse - are available directly from the keyboard.

- The whole block is stored in a REM which is automatically adjusted in
size.

- Cursor movement may be selected as either automatic increment which is
useful for text input and character repeats, or cursor key dependent which
will assist in the creation of graphic designs.

- Once defined, the block may be moved on screen using the cursor keys. It
may be erased, printed in its last position, or the print position may be
altered to any part of the screen.

- Also included is a fast screen clear. Possible uses for SCREEN include
creating and storing graphics pictures, animation of games, saving and
printing text and data.

The program is 1,066 bytes long and is contained in two REM statements.

The program line following 2 REM cannot be removed at any time, but it may
be edited to a minimum length or used with this program, eg. 3 REM.

To enable the program to run, an existing REM statement must be specified.
The REM should initially contain no characters, and any line number, except
1 and 2 of course, may be used.

To specify the line number N, if N is less than 256, then enter:


    POKE 17055,N
    POKE 17056,0 (DEFAULT 0)

If N is greater than 255 then enter:

    POKE 17055,N-256*INT (N/256)
    POKE 17056,INT (N/256)

Call the program with RAND USR 17254. When a REM is used for the first
time, key 1 must be pressed next to enter the edit screen mode.
Subsequently, when a question mark appears in the bottom left-hand corner
one of the following 1 to 6 functions may be selected by pressing the
corresponding number key and 7 by pressing NEWLINE.

    1. Edit screen
    2. Erase and move block
    3. Move block without erase
    4. Erase block
    5. Erase screen
    6. Print block
    7. Return to Basic

Function 1 enables the editing of the whole screen, definition of the block
size and copying the block into a REM. The cursor position is shown by a
flashing character, a blank will Hash as a black square. This position may
be moved anywhere on the screen using the cursor control keys with shift.

Moving horizontally, on reaching the end of a line, the next position will
be at the opposite end of the next line vertically, depending on the
direction of travel. Initially, when a character is entered the cursor will
move to the next print position thus allowing faster input of text and data
and also resulting in character repeat at flash speed if the key is held
down.

By pressing shift and function together, this automatic increment is
cancelled and movement is by cursor control keys only. This will enable
easier construction of graphic figures etc. Pressing shift and function
again will return to automatic increment. The cursor will not move out of
the confines of the screen.

The mode letter will appear in the bottom left-hand corner of the screen.
Initially N, this indicates that the normal single-character face values of
all keys are available. Pressing SHIFT and graphics characters will have
those as face value.

SHIFT and RUBOUT will give an inverse I, indicating that all keys are now
the inverse of face value. SHIFT and EDIT will return mode to N. The mode
may be changed at any stage and in any sequence.

The definition of the print position and block size is achieved as follows.
To the right of the mode letter is a number, 1-3, which indicates the next
print position or block size value that is to be defined. A1 indicates the
top left-hand corner of the block. To define this, move the cursor to the
required position and press NEWLINE. A2 will now appear, indicating that
following this last procedure you may define the top right-hand corner of
the block. A2 then indicates that you may define the height or number of
lines in the block and only vertical movement is necessary for this.

Once the 3 has appeared, editing the screen can be carried out at any stage
up to NEWLINE, when the block is copied into the designated REM which is
adjusted in size to suit.

Once entered, the whole procedure must be completed. Any attempt to define
impossible positions in stages 2 and 3 will result in a return to stage 1,
but all data on screen will be retained. The block size may range from a
single character through any rectangular form to a full screen. After
NEWLINE on 3 there is a return to a choice of function.

On pressing the key, for function 2, "M.E." will appear in the bottom
left-hand corner and the top left-hand corner character of the block will
flash. Using SHIFT and the cursor keys the whole block is moved and the
previous position is erased.

The block will disappear off the right-hand edge of the screen until the
Hashing character is at the extreme right. The next move will result in the
whole block being printed one line down at the far left of the screen.

With left-hand movement the reverse will occur. Also the block will
disappear from the bottom of the screen, but only until the top line is on
the bottom line of the screen. The print position is automatically altered
so subsequent printing of the block will be in the last position. If the
block is only partly shown on screen, the whole block is retained.

NEWLINE will exit from the routine and return to the choice of function.

Function 5 is the same as function 2 except that the previous position is
not erased. An M will appear at the bottom left-hand corner. Function 4
erases only the specified block. Function 5 fast-erases the whole screen.
Function 6 prints the block at the specified position. Function 7 exits
from the routine and returns to BASIC control.

Several of the routines in the program may be used directly and therefore
be of assistance in programs. Their addresses are as follows:

    16554 Screen edit and block definition only
    16988 Prints block
    17057 Returns address of the first character in the designated REM
    17197 Clears screen
    17216 Erases block

The following are useful addresses:

    17254 Start of main program
    17055, 17056 Designate REM - low, high
    16775, 16786 Flash speed - off, on

The REM statements containing a block will have an extra four characters at
the beginning. The first two define the top left-hand corner of the block
and use the same values as a PRINT AT command. The third is the length of
the line, width, and the fourth is the number of lines, height.

These numbers may be altered directly and a routine is included to find the
address of the first number, therefore

    LET X = USR 17057

will give X that value and so POKE X,PEEK (X+1) will print the block one
step down the next time the print routine is called and POKE (X+1),PEEK
(X+1)+1 will print the block one step to the right. A blank line included
when the block is defined will provide trailing blanks to erase the
previous position. Out-of-range values will stop the program and give an
error N.

The flash speed may be altered to suit you. The byte address 16775 controls
the character off time and 16786 the on time. Initially both have the value
48 but may be Poked with any number between 1 and 255 - the larger, the
slower.

Controlled by timing

Other functions are controlled by this timing and so too fast a speed may
result in loss of program control. Although the program is essentially
crash-proof, beware of the following. When using a REM for the first time,
always use the EDIT screen mode, key 1 , first and do not use the program
while scroll is effective.

Cassette including a copy of SCREEN and a full RENUMBER program may be
obtained for 3 from E M Stenlake, 162 Brooks Lane, Whitwick, Leicester LE6
4DF. [Unlikely to still be available. PF]
