                      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, depen-

ding on their shape. For example, ! is narrower than a W.

The routine can be adapted to give a set number of charac-

ters 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 - simi-

larly 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, use a

string as a "buffer". For example:

    LET a$=CHR$ n: PRINT #9;a$

instead of:

    PRINT #9;CHR$ n

[I haven't been able to replicate this bug, but that may

mean only that it is present only under some circumstances.

There is certainly a known bug in the STR$ ROM routine,

although I have never heard of a similar one for CHR$.]

  [There were instructions here for entering the code and

proportional character set. There are different versions

for the 48K and the 16K machines. These are on the TZX that

goes with this text file, as "PrintCde48"CODE 63744,1536

and "PrintCde16"CODE 30976,1536 respectively. Don't forget

to CLEAR <address-1> before loading!]



 Setting up channels



  There is a different method for setting up the channels

if you 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 there-

fore be used. Listing 2 [on the TZX as "if1 init"] 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 Micro-

drives, network etc. have been used. Also, if the shadow

systems 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 state-

ments - 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

half way 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 dia-

gram 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 firstbyte of each

character with 6 - listing 3 [on the TZX as "40 columns"].

Then Poke the "right-hand margin" addresses - are marked on

the hex listings - with 239 - this is 40*6-1. [I can't give

the entire hex listings nor underline any numbers in this

text file, but as a note underneath listing 3 made clear

anyway, there are two of these addresses; for the 16K, they

are 31367 and 31638; for the 48K, POKE 64135 and 64406. In

any case, the program itself will POKE those addresses for

you.] 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.