Customizing Your Word Processor

Author(s): John Lambert
Publication: LISTing Newsletter
Date: December 1993
Pages: 7-9

SINCLAIR USER – MAY 1986

Customising your word processor

John Lambert shows how to squeeze more from Tasword Two

TASWORD TWO has, justifiably, proved to be the most popular word processor program for the Spectrum. One of its attractive features is the ease with which you can modify it. The ideas which follow will allow you to customise Tasword in a number of ways and all will work on any version. They will also work if you have altered it to use Tasprint, the East London Robotics memory upgrade, microdrives and disc drives.

Throughout the article ‘direct mode’ denotes that commands can be entered directly from the keyboard and will give the OK report; ‘Basic’ is the Basic part of Tasword, reached by pressing STOP; and ‘Tasword’ denotes the code part of Tasword, reached by pressing Y from the STOP menu or RUN in direct mode. Sixty four mode denotes 64 characters per line and similarly 32 mode denotes 32 per line.

Changing the colours

As you might have discovered already, you can change the INK and PAPER colours used by Tasword simply by altering them in direct mode and running. That has disadvantages: the paper colour can only be 1, 3, 5 or 7 and the margins will be one less than that. To alter the colours in 64 mode enter, in direct mode

POKE 58512,54
POKE 58513,c
POKE 58521,54
POKE 58522,c

where c is 8 * paper + ink. For example, to get blue paper with white ink use c= (8*1+7) = 15. To change the margin colour enter

POKE 58508,54
POKE 58509,c

where c is calculated as above. To change the border colour enter

POKE 64516,b

where b is between 0 and 7. To change the 32 mode border use

POKE 60641,b

calculating b as above.

Those POKEs will not change the bottom two lines. To change those

POKE 64570,c

and for the second to the bottom line use

POKE 59993,c

calculating c as above. Note that on this line the top half is INK and the bottom PAPER. (To keep the same colours as above you should poke it 7*8+1=57.)

When returning to Basic the INK and PAPER colours are restored to those used before running Tasword but the Border is not. To remedy that add a BORDER command on line 20 before the CLS. As those POKEs are within Tasword they will be retained when the program is saved.

Lines, Characters, Words

When returning from Tasword, to the STOP menu, the program always goes to line 20. When going to Tasword from the Basic part of the program there are two routes, from line 10 – the usual one – and line 3060 – in the process of using search and replace. That can be employed to add a count either of lines or characters used. To count lines add

79 PRINT #0;AT 1,0;a/64;" Lines Used - "; (PEEK 64150+256*PEEK 64151+22)-a/64;" Lines Free"

and to count characters add

79 PRINT #0;AT 1,0;ch;" Characters Used-"; ((PEEK 64150 + 256 * PEEK 64151 + 22) * 64) - ch; " Free"

Alter the USR statements in lines 10 and 3060 to be LET ch=USR, followed by the rest of the line, and add LET a=ch in line 20 after the CLS.

The fastest way to count words is to add a short machine code program. Enter listing one, run it and save the code on tape. Load a copy of Tasword and add the program lines in listing two – you will also have to alter the CLEAR address in line 15 to 31940 and add another LOAD CODE””. To ensure the code is saved automatically add

705 SAVE "word" CODE 31941,59

Alternatively provided you are only using Tasword from cassette add

705 POKE 23736,181: SAVE "word" CODE 31941,59: POKE 23736,181

That will stop the ‘press any key’ message appearing and save the three parts but will cause odd results if used with microdrives or disc drives.

Once that is done LOAD the word code and then save TASWORD in the usual way.

The routine searches through the file, taking the length from Basic and the start of the file from locations within Tasword, and counts a word as being a non-space followed by a space. It includes words which start at the end of a line, making it a true count.

A space is taken to be a character with a code of 32 or a graphics character with a code of 128 or more. If you do not want to include those graphics then change the four DATA statements in line 110 to zero. If you use Tasprint the tilde character – code 126 – is used to change text styles and is treated by Tasword as a space. In that case change the second DATA item in line 110 (128) to 126.

The method of calling the routine may be new to you and relies on the way in which the Spectrum treats user-defined functions and stores numbers. When a function is called the system variable DEFADD holds the address of the definition of that function.

If a single letter is used the memory locations 3 to 7 on from that hold the five byte floating point form of the variable being used. If that value is an integer – between -32767 and 32767 – it can be found in locations 4 and 5. Unfortunately the Spectrum takes a relatively long time to delve into the ROM but the method is useful for routines which require one, or more, parameters to be passed.

Machine code buffs might like to move the word count code to a REM statement for ease of loading and saving.

If you are familiar with the calculator routines in the ROM, you can make use of this method in your own programs; the INT-STORE routine in the ROM at 2D8Ch is particularly useful. For further discussion of the calculator see Helpline in Sinclair User, February.

Listing 1. word count data

  10 LET clr=31940: LET t=0: FOR n=1 TO 59: READ a: POKE (clr+n),a: LET t=t+a: NEXT n: IF t<>6405 THEN PRINT "ERROR": STOP
20 SAVE "word"CODE clr+1,59
97 REM ***********************
98 REM WORD DATA
99 REM ***********************
100 DATA 42,181,253,221,42,11,92,221,94,4,221,86,5,25,235,33,0,0,1,0,64,27,26,254,32,40,24
110 DATA 254,128,48,20
120 DATA 14,1,16,242,9,58,182,253,186,32,232,58,181,253,187,32,226,229,193,201,175,185,40,234,35,13,24,230

Listing 2. word count additional basic

   1 DEF FN w(x)=USR 31941
15 SEE TEXT
174 IF b=119 THEN GO TO 4500
705 SEE TEXT
4500 CLS : GO SUB 4000: PRINT AT 11,5;"Number of Words = ";: PRINT FN w(a)
4510 PRINT #0;" Press Any Key To Continue": PAUSE 1: PAUSE 0: GO TO 20

Listing 3. Assembly listing of Listing 1.

HL=Word Count
DE=Position in File
B=64 (Characters per Line)
C=Flag 0=Space 1=Non-Space

EA60 100 ORG 60000 ;Arbitary ORG
FDB5 110 FILEST EQU 64949 ;Address in Tasword
that stores the
start of the file
5C0B 120 DEFADD EQU 23563 ;System Variable
EA60 2AB5FD 130 INIT LD HL,(FILEST) ;Get start of file
EA63 DD2A0B5C 140 LD IX,(DEFADD) ;Pass the value of
EA67 DD5E04 150 LD E,(IX+4) ;a (file-length) to
EA6A DD5605 160 LD D,(IX+5) ;DE
EA6D 19 170 ADD HL,DE ;HL=start + length
EA6E EB 180 EX DE,HL ;Move it to DE
EA6F 210000 190 LD HL,0 ;HL=Word Count
EA72 010040 200 NXLINE LD BC,64*256+0 ;Load B,64 & C,0
EA75 1B 210 NXCHAR DEC DE ;Step through file
EA76 1A 220 LD A,(DE) ;
EA77 FE20 230 CP 32 ;if Space -
EA79 2818 240 JR Z,FNDSPC ;jump
EA7B FE80 250 CP 128 ;if Graphic -
EA7D 3014 260 JR NC,FNDSPC ;jump
EA7F 0E01 270 LD C,1 ;set flag
EA81 10F2 280 LINEND DJNZ NXCHAR ;if not end of line
get next char
EA83 09 290 ADD HL,BC ;flag holds state of
first char in line,
add to count
EA84 3AB6FD 300 LD A,(FILEST+1) ;find if address
EA87 BA 310 CP D ;counter (DE) has
EA88 20E8 320 JR NZ,NXLINE ;reached the
EA8A 3AB5FD 330 LD A,(FILEST) ;start of the
EA8D BB 340 CP E ;file - if so
EA8E 20E2 350 JR NZ,NXLINE ;then get next line
EA90 E5 360 PUSH HL ;move word count
EA91 C1 370 POP BC ;to BC
EA92 C9 380 RET ;and return
EA93 AF 390 FNDSPC XOR A ;clear A
EA94 B9 400 CP C ;is flag 0
EA95 28EA 410 JR Z,LINEND ;if so jump
EA97 23 420 INC HL ;increase word count
EA98 0D 430 DEC C ;zero flag
EA99 18E6 440 JR LINEND ;back to routine

Graphics and Pounds

If you are using a full-sized printer you can send control codes to it using the graphics characters. It is a good idea to add a space – 32 – to the sequence as otherwise the line, when printed, appears to have lost a character. That can be added before or after the sequence. As a matter of personal preference I tend to put it after, except for the underline codes. Code 140 should have it before and 131 after.

The pound sign has caused many headaches. The problem is that, as far as the Spectrum is concerned, the pound has a code of 96 whereas most printers use a code of 35. To further complicate matters the printer also uses 35 to denote the hash character.

It does that by having a number of alternative character sets and you have to switch between them, either using software or by setting switches in the printer. The code of 96 will be printed as a backward apostrophe.

The ideal solution would be to check all the characters being sent to the printer and make the necessary changes. This can be done in software but as it will vary according to the printer and interface used it is difficult to give a general method.

Two methods can be used. The first is to set the printer to use the USA character set so that it will print a hash when sent a code of 35. In that way the hash in listings will be printed correctly.

If one of the graphics characters – say 143 – is set to give the English character set and 128 to give the USA set you can alternate between them at will. You must however remember whether the hash on screen will print as a pound or as a hash.

If you rarely use the hash character the other method will suffice. Set the printer to the English character set and alter the hash character so that it looks like a pound sign on screen. It will still have to be obtained by pressing Symbol Shift 3 but at least you can see what is happening. To do that enter, as a direct command

FOR n = 0 TO 7: POKE (61208 + n), PEEK (61696 + n): NEXT n

The pound sign on the keyboard will still give you a pound on screen so enter

FOR n = 0 to 7: POKE (61696 + n), 0: NEXT n: POKE 61697,4: POKE 61698,2

to change it to a backward apostrophe. Now you have only to remember to press the correct keys but at least what you see is what you get. If you want to use hash you will have to use the graphics characters to swop sets as before.

Help Pages

If you change the uses of the graphics characters you will need to alter the help pages accordingly. The easiest way is to move them into the text file to work on. Enter in direct mode

LET s = FN p(64949): FOR n = 0 TO 1407: POKE (s + n), PEEK (54784 + n): NEXT n

which will move it into the file. To return it to its correct place – provided you have not moved it from the start of the file – go into direct mode and enter

LET s = FN p(64949): FOR n = 0 TO 1407: POKE (54784 + n), PEEK (s + n): NEXT n

To work on the Extended mode page replace the 54784 in the above with 56320.

Keyboard

Tasword uses two of the system variables to time its reading of the keyboard. REPDEL at 23561 stores the length of time a key must be held down before it repeats and is normally set to 35. That can be usefully changed to around 20 for fast typists.

One useful modification is to alter the sound made when a key is pressed, as on a rattly keyboard the orginal sound is usually lost. The BEEPER routine in the ROM at 03B5h is used which needs, on entry, the DE register holding the frequency × time and HL holding the length of the timing loop.

Tasword sets D to zero and E to the value of PIP (23609), normally 5 but set to 2 by line 15. The value of HL is held in 59161 and 59162; POKEing 59161,50 gives a loud(ish) typewriter click.

Headers, footers . . .

Listing four is a routine which allows you to add headers, footers and page numbers to a printed text file, and print as many copies as you want. Delete lines 200 to 300 from your original copy of Tasword and type in the listing. Due to memory limitations, headers and footers should be included in the listing as shown.

Lines 200 to 240 should be self-explanatory as they ask for input from the user. Line 250 calculates which part of the text file is to be printed and tells you, on screen, what is happening. Lines 255 and 260 are more calculation. Line 270 puts your header here – remember to allow for the margin. Line 275 is part of the original Tasword Basic and takes into account different printer interfaces; you may find that causes a blank line to be output.

Line 280 calls Tasword to do the printing. Line 285 is similar to 275. Line 290 checks if you want to quit printing; the RUN ensures that all the additional variables created are CLEARed. Line 292 ensures that the page number is printed at the bottom of the page. Line 294 puts your footer here. Line 296 prints the page number; as most interfaces do not handle TAB correctly a number of spaces are LPRINTed. The number is positioned in the middle of the page. PEEK 60927 is the width of the margin.

The routine needs one memory location to store the number of text lines per page and I have used 31940 for that. You will have to alter the CLEAR in line 15 to 31939. Alternatively, you could use one of the unused locations in the system variables, 23681, 23728 or 23729, provided your printer interface does not use it.

The routine has been made as short as possible but if you use a microdrive or the Thurnall, Statacom or Watford disc systems you may find you get an ‘out of memory’ error. That is because those systems use memory when loading or saving. Using cassette, or the Technology Research disc system, does not.

Try the routine using a file which you have safely saved. If you do get the ‘out of memory’ report you will have to shorten the Tasword Basic. Two methods can be used, both of which are used in the routine. The first is to change all the numbers to use VAL – that is 123 becomes VAL”123″ and so on – and that will save three bytes per number. It may not seem a great deal but in the routine 200 bytes are saved by this method.

The second method is to use variables in place of numbers. In the routine z is used for zero and u for one. If you add LET z=0: Let u=1 to line 10 and then change all occurences – omitting line 15 and the subroutine at 4000 – you can save a further three bytes every time.

Depending on your version of Tasword you can save up to 1.5K which is more than enough for this routine and any of your own. As long as you have 700-800 bytes free you should not have any problems – to check the amount of free memory enter

PRINT 65535-USR 7962

Listing 4. Print routine for headers, footers, page numbers and multiple copies

 200 CLS : GO SUB VAL "4000": PRINT AT VAL "4",VAL "8";"PRINT OPTIONS": PRINT "  just press ENTER for default    values given in brackets": LET z=VAL "0": LET u=VAL "1": LET gs=VAL "6000": LET i=VAL "8": LET j=z: LET j0=VAL "23": LET x=VAL "31940": LET a$="Text Lines per Page ": GO SUB VAL "850": LET i=VAL "10": PRINT AT i,z;"Line Spacing? (1)": GO SUB gs: IF a$="" THEN LET a$="1"
210 POKE VAL "62235",VAL a$: LET i=VAL "12": PRINT AT i,z;"Start at line? (1)": GO SUB gs: IF a$="" THEN LET a$="1"
220 LET c=VAL "64"*(INT VAL a$-u): LET st=c+FN p(VAL "62216"): LET i=VAL "14": PRINT AT i,z;"Finish at Line? (last)": GO SUB gs: IF a$="" THEN LET len=a-c: GO TO VAL "230"
225 LET len=VAL "64"*INT VAL a$-c
230 LET i=VAL "16": PRINT AT i,z;"First Page Number (1)": GO SUB gs: IF a$="" THEN LET a$="1"
240 LET pa=VAL a$-u: LET i=VAL "18": PRINT AT i,z;"Number of Copies (1)": GO SUB gs: IF a$="" THEN LET a$="1"
250 LET co=VAL a$: LET end=st+len: LET pl=INT (PEEK VAL "31940"/PEEK VAL "62235")*VAL "64": LET tp=INT ((len/pl)+u): FOR n=u TO co: LET fl=z: LET cp=pa: FOR f=st TO end-u STEP pl: LET b=f: LET x=VAL "60045": GO SUB VAL "950": LET cp=cp+u: RANDOMIZE USR VAL "59806": RANDOMIZE USR (FN p(VAL "62472")): CLS : PRINT AT VAL "10",z;"Press the q key to quit printing";AT VAL "14",z;"Printing Copy Number";n;AT VAL "18",z;"Page Number ";cp: IF end-f<pl THEN LET b=end-f: LET fl=u: GO TO 260
255 LET b=pl
260 LET x=VAL "60049": GO SUB VAL "950"
270 REM LPRINT "Header"
275 LET c=PEEK VAL "62470": IF c<>z THEN LPRINT CHR$ c
280 RANDOMIZE USR VAL "60038"
285 LET c=PEEK VAL "62471": IF c<>z THEN LPRINT CHR$ c
290 RANDOMIZE USR VAL "59806": IF INKEY$="q" THEN RUN
292 IF fl=u THEN FOR g=u TO (pl-b)*PEEK VAL "62235"/VAL "64": LPRINT : NEXT g
294 REM LPRINT "Footer"
296 FOR g=1 TO 25+PEEK 60927: LPRINT " ";: NEXT g: LPRINT "Page No ";cp;" of ";tp: LPRINT CHR$ 12: NEXT f: NEXT n: RUN

Variables used in Listing 4.

 st = start of file
len = length of the file
 pa = first page number
 co = number of copies
end = end of file
 pl = length of page (to be printed)
 tp = total number of pages
 fl = flag
 cp = current page

There is one problem, at least, to which I do not have the answer. The length of the text file (-22) is held in locations 64150 and 64151. Try POKEing 64150,122, RUN Tasword, clear the text file – E Mode X – and scroll through it. How do you get rid of line 357?

Finaily . . .

All the above will prove useful and enhance what is already an impressive program. If you have further ideas for improvements I would be pleased to hear from you c/o Sinclair User.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.