PRINTPROG
by Paul Rhodes
from Your Computer, Oct'84

CHARACTER PRINT 

Paul Rhodes shows you how to print characters
with proportional spacing on your screen.

THIS PROGRAM ALLOWS you to display text with proportional spacing of
characters on the screen or ZX Printer. It is called using the Print,
LPrint, List and LList commands, as for normal printing.

The characters are printed with differing widths, depending on their
shape. For example, ! is narrower than a W. The routine can be adapted
to give a set number of characters per line - for example 40, 64 etc.
- by setting all characters to be the same width. The program is
operated via the Print #9 command - similarly for LPrint #9, List #9
etc. The only restriction is that, especially if Interface 1 is
connected, functions such as CHR$ and STR$ may cause the computer to
crash. This appears to be due to the ROM, as the crash occurs before
the print routine is called. To avoid this problem, using a string as
a "buffer". For example:
	LET a$=CHR$ n : PRINT #9;a$
instead of:
	PRINT #9;CHR$ n

To enter the program, type in the hex- loader, enter F900 or 7900 -
for 48K and 16K Spectrums respectively - as the starting address, then
type in the relevant hex listing for your computer. Type in End, and
re-run the hexloader to enter the character set data. Replace the X in
the addresses with 7 or F, depending on your RAM size, and when all
the data has been entered, type in End as before. Save the code, with:
	SAVE "PrintCode" CODE 63744,1536
for the 48K version or:
	SAVE "PrintCode" CODE 30976,1536
for the 16K version. Then Verify it before proceeding to the next step.


Setting up channels

There is a different method for setting up the channels if your have
an Interface 1 connected, so if you have, skip the next paragraph and
enter listing 2. For those of you without the interface:
	RANDOMIZE USR 63744 (or 30976)
will set up the #9 channel.

If you have an Interface 1 connected, start reading again here! Due to
the way the Interface 1 affects the error routine, the above method is
very risky. You can use it, but if you do the system is liable to hang
up whenever there is an error, or when a Microdrive command is used -
CLS # and Clear # are OK, though. So far as I know, this problem is
unavoidable. An alternative method must therefore be used. Listing 2
is a subroutine which will set stream 9 to point to the Print Prog
channel Data.

However, the data is not stored in the channel area, so the routine
must be called again every time the Microdrives, network etc. have
been used. Also, if the shadow system's variables have not been
inserted when the routine is first called, it must be called again
after they have - that is, after any error, or any Interface 1 command.

You should now be able to print to the screen in the new layout using
Print #9. Apart from the problem with CHR$ etc. mentioned above, most
of the normal control characters can be used. The routine operates
with colour controls, Inverse, and position controllers. The number in
Tab statements - and the second number in an At statement - has a
range of 0-247 - 248-255 will continue on to the next line.


Text at pixel positions

This means that text can be printed at pixel positions across the
screen. Positions down the screen have the normal 0-21 range. CHR$ 6 -
the "Print comma" - puts the cursor at the beginning of the next print
zone - either halfway across the screen, or at the beginning of the
next line - as normal, and CHR$ 13 will move the print position to the
beginning of the next line.

When used with the printer, the buffer is copied whenever a new line
is started. As you can see, there are no major differences between
using this routine and using the normal Print command.

The character set is stored as it is in the ROM, except that the first
byte of data for each character stores the width. The remaining 7
bytes store the bit-pattern, which starts one bit from the left of the
character - see diagram 1. The top line of the character is therefore
always printed as a 0 (blank).

Diagram 1
	0 0 0 0 0 1 0 1	=5   <1st byte
	0 1 1 1 0 0 0 0 =112 <2nd byte
	0 1 0 0 1 0 0 0	=72  <3rd byte
	0 1 0 0 1 0 0 0	=72  <4th byte
	0 1 1 1 0 0 0 0 =112 <5th byte
	0 1 0 0 0 0 0 0	=64  <6th byte
	0 1 0 0 0 0 0 0	=64  <7th byte
	0 0 0 0 0 0 0 0	=0   <8th byte
	a b b b b c c c
The first byte determines how many columns (from the left) will be printed.
	a=one column blank for spacing between characters
	b=these columns make up the character
	c=these columns are ignored


Poke the first byte

To set 40-column printing, Poke the first byte of each character with
6 - listing 3. Then Poke the "right-hand margin" addresses - are
marked on the hex listings - with 239 - this is 40*6-l. You will
probably also want to redefine the character set, as the specially
designed "proportional spacing" character set can look very odd when
printed with regular spacing. Other column widths can be set similarly.

