THINCHARS
by S.J. Patrick
from ZX Computing, August/September 1984

S J Patrick of Harrow presents this useful program that puts the
squeeze on your screen.


THINCHARS is a machine code routine written for the Spectrum which
displays 42 characters on each line of the screen, instead of the
usual 32. Each character is 6 pixels wide instead of 8, including a
blank column between letters. The shapes of the 96 characters (codes
32 to 127) are stored in a table at the end of the routine. Each
character takes 5 bytes, one per column, which are read from left to
right; the sixth column is always blank and is not stored in the
table.

The routine is relocatable, which means that it can be loaded at any
address in memory and will work without modification. This makes use
of the fact that when a "USR n" statement is executed in BASIC, the BC
register is loaded with n, the start address of the routine called.

THINCHARS takes the text to be printed from the 1-dimensional character
array s$, which must be set up by a DIM s$(...) statement at the start
of the program to ensure that it is the first variable in the variables
area. (An ordinary string variable would be moved to the end of the
variables area each time its value was altered.) If the first variable
is not array s$, the routine returns without doing any printing.

The first two characters of s$ are not printed, but their codes are
used as the x and y co-ordinates of where the printing is to begin;
the x co-ordinate is the same as that used for PLOTting, but the value
runs from 0 for the top row of the screen to 184 for the bottom row
(to allow printing on all 24 rows), and is rounded off if necessary to
a multiple of 8. The end of the string to be printed is signalled by a
character with code 128.

So a general statement to set up the string would be:
LET s$ = CHR$ x + CHR$ y + "text" + CHR$ 128
There is no limit to the length of s$; if the printing reaches the
foot of the screen, it continues at the top.

Any of the colour items (PAPER, INK, INVERSE, OVER, etc.) can be set
before THINCHARS is called. Two ROM routines are used: CALL 3405
copies the permanent screen attributes to the temporary ones; and CALL
3035 uses the screen address in the HL register to set the attributes
in the appropriate square. (This is done at the left-hand and right-
hand edges of each character, as they may be in different attribute
squares.) The routine will fill the screen with 1008 character in
about 1.4 seconds.


Loading the routine

The routine is 199 bytes long, followed by a character table of 480
bytes; suitable start addresses at 64600 for a 48K Spectrum and 31900
for a 16K Spectrum, but any address may be used, and when the routine
has been saved (SAVE "THINCHARS" CODE 64600,679) it may be reloaded to
a different address. Remember to enter CLEAR n, where n is less than
the chosen start address, before loading the routine.


Loading the character table

Figure 1 shows the 480 bytes of the character table, and the
characters which they represent. They are loaded into memory
immediately following the routine. Alternatively, the characters may
be generated by means of the program THIN.GEN. In this, you are given
a 5x8 grid in which to create a character, which is then stored in the
appropriate place; the program displays all the characters so far
loaded, and any of them may be returned to the grid for modification.


Description of program THIN.GEN

10        Ensures that s$ is the first variable.
130-160   Obtains start address of THINCHARS; check first character
          and halts if it is incorrect.
200-260   Sets up a copy of the character set in s$; the BEEP in line
          250 is to convince the user that something is happening.
270-290   Print box for character, character set and instructions.
300       Set cursor to top left-hand corner.
310       Print cursor.
320-330   Wait for a key; remove cursor.
340       Plot or unplot a square in the grid.
370-390   Move cursor.
400-496   Load grid with character i$. Line 460 tests if the bit read
          from the character table is the same colour as the relevant
          square on the grid and, if not, changes it. POINT was used
          instead of SCREEN$ as the latter treats both white and black
          squares as spaces.
500-595   Store grid in character table in place determined by i$, and
          re-print the character set.
600-620   Prints the character set (on YELLOW paper, so that the user
          can see how many empty spaces are left).


