                   Words on the Spectrum



    Now's the time to tackle that long-deferred oeuvre

  with Stuart Nicholl's fast machine-code word processor



This program for the 16K Spectrum started out as a

straightforward typewriter program in Basic with approxi-

mately 30 bytes of machine code to plot characters on to

the screen in such a way as to give 42 characters per line.

But the program was slow and used too much RAM, leaving

little free for data storage.

  The solution was to convert all the routines into machine

code and maintain a minimum of four pages of data with 42

characters per line, this being the equivalent of five and

a quarter pages of text if the normal 32 characters per

line were used.

  Up to this point I had been using the Spectrum character

set, but the upper-case letters were touching each other

and making the text illegible. I added a new character set

with all the characters redefined on a six-by-eight pixel

format. This created the option of using the Spectrum set

or the new typewriter-mode set.

  The program starts with the main Menu, which has six

options.

  The Start option takes you into the typewriter mode. It

begins by asking for the page required and printing the

selected page. This is done to avoid accidental overtyping

of an existing page of text. A cursor is placed in the

first character position at the top left of the screen, and

can be moved to any position by means of Caps Shift and

cursor controls: keys 5-8.

  The cursor always indicates the position of the next

character to be typed. If the cursor is moved over existing

typing the character will change to white Ink and show

through the cursor. If a character is overtyped, then it

will be printed on top of the existing character, but the

last character typed is held in the memory of the computer.

  All Spectrum characters are available, using Shift keys

as necessary, and all but the double-Shifted ones are

auto-repeat.

  Incorrect entries can be quickly erased by the use of

Caps Shift and Delete. This will erase the character behind

the cursor and backspace the cursor over the deleted

character. At the start of a line it will erase the last

character on the previous line and backspace on to that

line. This function is also auto-repeat.

  A Newline is obtained by pressing Enter, and this func-

tion will also auto-repeat. If the cursor is on line 22

then Enter will move the cursor to the end of line 22 where

it is split into two, bracketing the last line, to indicate

that the end of the page has been reached.

  This method is used to erase the last character on a

page, the cursor being in effect after the last character.

There are several options available in this mode and, as a

guide, these are indicated on line 24, with the keys

necessary for each option shown in inverse video. The next

options require both Shift keys to be pressed before the

option letter. First, n(ext) will scroll the page off the

screen and replace it with a copy of the next page. This

can be used after finishing typing a page or to read

through the pages. If you are on page 4 then the next page

will be page 1. Second, m(enu) will take you back to the

main Menu. Third, z is the copy keys and, as it suggests,

it will copy the page on the screen to the printer.

  A further facility is the Edit mode. This is accessed by

Caps Shift and Edit, and when selected will give you five

options. These will be printed on line 24 of the screen

with the key presses for each option shown in inverse.

  Insert - when selecting this option the cursor must be

over the first character in the block to be Shifted right.

You will be asked how many characters you require to be

inserted; this much be in the range 0-255. The decimal

numbers can be entered either with leading zeros like 032

or 006, in which case the Spectrum will automatically

accept the number without the need for Enter, or as a

"normal" number, that is, 32 or 6, in which case, if it is

less than 100, the use of Enter is required. Each key press

is checked, a buzz will sound if the entry is not valid and

three question marks will be printed. A zero entry will

skip this routine.

  The maximum number of characters that can be inserted is

one less than the number of characters from the cursor to

the end of the page if this is less than 255.

  Any character pushed off the page by this routine will be

lost. After a number has been accepted the page will scroll

off the screen and be replaced instantly with the modified

page and the cursor, still in its original position, so

that the required information can be typed in.

  Delete - this option is similar to Insert in that the

cursor is placed over the first character in the block to 

be deleted, and you will be asked how many characters you

require deleting before the page is scrolled off the screen

and reprinted with the correction made.

  The Erase option will erase part of a page reaching from

the end of the page to the line below the cursor. So the

cursor must be placed on the last line of typing that you

wish to keep before this option is called. The erased part

of the page will scroll up and off the screen; the retained

part stays in position.

  Justify - there are two Justify options, with both you

have a further choice of justifying the whole page or the

cursor line only. So if only the cursor line is required,

be sure to place the cursor anywhere on the required line

before this mode is selected. Justify left will scroll the

page off the screen and reprint it with the line or page

shifted to the left-hand margin. Justify left/right will

scroll the page off the screen and reprint it with the line

or page shifted left and the space between words padded out

so that the last letter of the last word in each line is at

the right-hand margin.

  These last options can be skipped if the Edit mode is

accidentally selected by pressing any other key. The Edit

mode cannot be selected with the cursor at the end of the

page.

  The Stop command stops the program with the usual report

and a message that "Continue will restart at Menu". If the

program is broken then Goto 9000 will also restart at the

menu. If Run is used then all existing typing will be

erased.

  The Erase-a-page option will ask which page is to be

deleted. Any choice other than 1-4 will take you back to

the menu. The page selected will be instantly erased.

  Pages can be Loaded and Saved on tape with appropriate

options. You will be asked to name the pages when Loading

and Saving; the usual rule of 10 characters maximum

applies.

  The Change-typeface option will give you three options:

Normal, New and Redefine.

  Normal gives typing with the Spectrum characters, but

because of the squashed look of the eight-by-eight pixel

format, certain characters will look odd.

  New: because of the problems outlined above, a new key-

board has been defined to give a six-by-eight character

set. When this mode is selected, all typing on the Spectrum

will use the new characters, the program listing may be

shown in the new characters, but instructions and menus

will still use the Spectrum set.

  Redefine: any character in the new set can be redefined

with this option. The Spectrum will require the character

to be redefined and the decimal number of lines 1-8 of the

new character. A display will be given showing the Spectrum

character selected with the new character beside it; above

this will be a grid with lines 1 to 8 and columns a to f

indicated. As each decimal number is entered the character

will be shown magnified on this grid and the actual size

character will alter its shape accordingly.

  The character grid is in two colours, yellow and green;

the yellow area indicates six columns a to f, and any

redefined character should stay within this area as it is

only this part of the character that is plotted on the

screen.

  With this routine the whole keyboard could be redefined

to suit your needs. If you want to retain your redefined

keyboard then the word processor program will need to be

reSaved with the command Goto 9900.

  The Spectrum will either buzz if an incorrect option is

chosen, or repeat the prompt, or skip the routine being

called. A squeak will sound each time a menu option is

chosen and valid entry made. In the Typewriter mode a key

tap will sound with each key press.

  [Program entry instructions have been omitted at this

point, until:] I have purposely kept some of the program in

Basic so that you may follow it more easily. It would be a

simple task to convert all of option 1 and option 6 to

machine code.

  The routine starting at 29666 shows how to clear the

Input lines 23 and 24 and which channel to open so that

printing can be displayed on these lines. The Basic input

Inkey$ can be replaced by a call to the ROM routine to

clear the input lines, and the Basic

        PRINT # x;"********"

can be replaced by Open Channel and Print String ROM calls.

The rest of option 1 is then a straightforward case of

checking which keys are being pressed by Peeking the vari-

able Last Key at address 23560 and making the necessary

jumps, and calls. For example, line 230L



      LD A, (23560)

      CP "n"

      JR NZ,NEXT

      CALL 31038

      JR LINE 50

NEXT  CP "m"

      RET Z

      JR LINE 60



The only time a Ret to Basic would be made is when the Menu

option is chosen, so line 1000 would become;

1000 RANDOMIZE USR 'START ADDRESS' : GO TO m

and lines 50 to 780 and 8000 to 8040 could then be deleted.

This would also have the benefit of making the Break key

inoperable in the typewriter mode which can be annoying if

Caps Shift and Space are pressed by mistake.