Authors
Charles Stelding
Publication
Pub Details
Volume: 4 Issue: 2
Date
Nov-Dec 1986
Pages
23-24
See all articles from SyncWare News v4 n2
When printing a text to the screen by using the PRINT statement, words at the end of the screen often will be cut off in the middle and continued on the next line. This makes the text difficult to read.
This utility will put the entire word at the beginning of the next line so that the word remains intact. You simply put the text you wish to print to the screen or a printer in a REM statement. A PRINT statement is not necessary. To illustrate how this works, type in the following BASIC listing and RUN it. Further explanation is given in the listing.
BASIC Listing
10 DATA "3E02CD30123E0DD72A5D"
11 DATA "5C2323E51120001953D5"
12 DATA "7EFE202015C1E17EFE0D"
13 DATA "C8D72310F83E0DD77EFE"
14 DATA "2020E22318F8C12B057E"
15 DATA "FE0D28E4FE2020F518DE"
16 RESTORE 10: LET addr=65000: FOR j=10 TO 15: READ a$: FOR k=1 to LEN a$ STEP 2: LET num=(CODE a$(k)-48-(7 and a$(k)>"9"))*16+(CODE a$(k+1)-48-(7 and a$(k_1)>"9")): POKE addr,num: LET addr=addr+1: NEXT k: NEXT j
100 LET wrap=65000
103 POKE (wrap+1),2: REM print to screen. Poke (wrap+1),3 will send text in the REM statement to printer. If you are using a printer other than the 2040, you must have your printer software loaded and initialized.
105 LET width=32: Poke (wrap+15),width
110 RANDOMIZE USR wrap: RAM The REM statement must immediately follow the "RANDOMIZE USR wrap" entry as this example illustrated. The letters following the REM token will be printed to the screen or printer and words which would normally be cut off in the middle at the end of the screen will be "wrapped around" to the next line to make them easier to read.
120 RANDOMIZE USR wrap: REM A quotation mark is simply entered as (") instead of two quotes ("") as in a PRINT statement.
130 RANDOMIZE USR wrap: REM The code is saved by SAVE "REM WRAP"CODE 65000,60 and is relocatable anywhere in useable memory. It will work on both the Spectrum and 2068 (also with the OS 64 cartridge). To relocate the code, simply define "addr" the value of the new location as "LET addr=32000" in line 16. Then define "wrap" as 32000 in line 100.
140 RANDOMIZE USR wrap: REM The column width is now set at 32 but can be changed to 64 for the OS 64 cartridge. To change the column width, type in any new width in line 105.
9998 STOP
9999 SAVE "REM WRAP" LINE 10
Machine Code Listing
FDE8 EQU 65000
FDE8 3E02 wrap LD A, 02 ;Put 02 in the
;accumulator
FDEA CD3012 CALL chop ;Set to print to
;screen
FDED 3E0D LD A, 0D ;Put 0D in the
;accumulator
FDEF D7 RST 10H ;Do a carriage
;return
FDF0 2A5D5C LD HL, (chad) ;Get addr. of REM
;statement
FDF3 23 INC HL ;Let HL=HL+1
FDF4 23 INC HL ;Let HL=HL+1
;(HL=beg. of text)
FDF5 E5 CHEK PUSH HL ;Save beg. of line
;on stack
FDF6 112000 LD DE, 0020 ;Put column width
; in DE
FDF9 19 ADD HL ,DE ;Add width to HL
FDFA 53 LD D,E ;Put width into D
FDFB 2A5D5C PUSH DE ;Save width on ;stack
FDFC 7E LD A, (HL) ;What's at beg. of
;next line?
FDFD FE20 CP 20 ;Is it a space?
FDFF 2015 JR NZ, LETR ;lf not, goto LETR
FE01 C1 PRNT POP BC ;Get B counter off
; stack
FE02 E1 PRN1 POP HL ;Get text location
;off stack
FE03 7E LOOP LD A, (HL) ;Put letter at HL
; in accum.
FE04 FEOD CP 0D ;Is it a carriage
; return?
FE06 C8 RET Z ;If yes, return to
;Basic
FE07 D7 RST 10H ;If not, print it
;to screen
FE08 23 INC HL ;Let HL=HL+1 (get
;next letter)
FE09 10F8 DJNZ, LOOP ;If B<>0, goto LOOP
FEOB 3E0D NEWL LD A,0D ;Load accum. with
;carriage ret.
FEOD D7 RST 10H ;Print it to screen
FEOE 7E NEW1 LD A, (HL) ;Put letter at HL
;in accum.
FEOF FE20 CP 20 ;Is it a space?
FE11 20E2 JR NZ,CHEK ;If not, goto CHEK
FE13 23 INC HL ;If yes, chk for
;another space
FE14 18F8 JR NEW1 ;Goto NEW1
FE16 C1 LETR POP BC ;Get B counter off
;stack
FE17 2B LTR1 DEC HL ;HL=HL-1 (find
;space)
FE18 05 DEC B ;B=B-1 (update
;counter)
FE19 7E LD A, (HL) ;Put letter at HL
;in accm.
FE1A FEOD CP 0D ;is it a carriage
;return?
FE1C 28E4 JR Z, PRN1 ;If yes, goto PRN1
FE1E FE20 CP 20 ;Is it a space?
FE20 20F5 JR NZ, LTR1 ;If not, goto LTR1
FE22 18DE END_ JR PRN1 ;If yes, goto PRN1