                     Screen Compactor



        R. Swailes presents a memory saving program

        for the Spectrum which is designed to help

   adventure writers to draw pictures more efficiently.



The original purpose of this compactor program was to

enable adventure game writers to draw pictures quickly

without wasting too much memory. Some adventure games draw

pictures for each location but take a long time about it.

This program is a compromise between slow pictures and

minimum waste of memory and instant pictures but with con-

siderable waste of memory.

  The average saving of memory is about 40 per cent, though

for simple line drawings it will be much higher. For very

detailed pictures completely filling the screen there will

be a minimal saving.



 Begins at pixel one



  The Spectrum screen $ save begins at pixel one and saves

its value - 1=On 0=Off. The first eight pixels, for example

0,0,1,1,1,1,0,0 are represented by binary 00111100 or 60

decimal. At the first screen location in memory (16384), if

Peeked, would be seen the value 60. The save continues

through all locations saving the pixel values in blocks of

eight. There are 49152 pixels - 49152/8 = 6144 bytes or 6K

of memory.

  The compactor program relies on the fact that most pic-

tures have more background than picture. Where background =

eight pixels off Bin 00000000 = decimal 0.

  Even if saving a page of alpha numerics economies can be

made because the top line of any 8 by 8 character is always

blank, and since the screen scan does the top row of the

first eight lines together - chapter 24 display file -

these can be compressed. The bottom lines of each character

are usually also blank - except lower case letters with

tails - and similar savings can be made here.

  The machine code save "picture to code" looks at the

first screen location (16384) to see if any of the eight

pixels are on - giving a value greater than zero. If so it

saves the value as normal. Should it be zero - after sto-

ring the 0 - it checks the next location to see if that is

also zero and continues until a lit pixel is found. The

program then saves the number of consecutive zeros. For

example.

Screen$ Code:

64, 2, 0 0 0 0 0 0 0 0 0 12, 19 = 13 bytes

Compacted Data:

64, 2, _0,_9,_0_, 12, 19 = 7 bytes

  0 indicates start of a loop of zeros.

  9,0 Length of loop (low order byte first)

0x256 + 9 = 9 Loop=9)

Thus 0, 0, 24  24x256 + 0 = 6144 bytes = 6K

is a screen full of zeros in 3 bytes. To convert the code

back to a picture the reverse applies.

  Type in listing 1 and Run, then type in Data 1. If all

goes well then save to tape the machine code for picture

saving.

  Amend listing 1 with listing 2 and Run, then type in

Data 2. This will also save to tape if it is correct. This

is the machine code for picture printing.



 Clear the machine



  Clear the machine and type in the Demonstration Program

and Run. It will load up the Data 1 and Data 2 Code from

tape. It then expects a Screen $ to load in.

* If you haven't a Screen $ handy on tape then delete line

90 and insert 90 List 120. Following the program and your

Screen $ - or listing - will be saved in code - in memory.

The length of the code and saving can be seen. Press any

key and the Screen $ instantly reappears.

  A list of Pokes - table 1 - is supplied in case you don't

want to save a whole screen. Just amend the started data in

listings 1 and 2 and this will enable you to save either

the Top 1/2, Top 2/3, the whole screen or the whole and

Attribute File.

  You can draw and save several pictures one after the

other; just Poke 23728-9 as lines 50, 60, 70 in the main

program - with the position in memory where the picture

code is to be stored. Save the picture with Rand USR 25000

and then Peek 23728-9 - line 120 in the main program - to

find the length of the picture code in memory and work out

the next picture code start position and repeat.



 For all Spectrums



  To recall any picture Poke 23728-9 - lines 150,160 in the

main program - where V=start position of picture code in

memory then Rand USR 25130.

  The program was written for all Spectrums, and the

machine code is fully relocatable. For 48K machines instead

of typing in numbers 25 etc. type in 35xxx or 45xxx.

  Your picture code can be saved to tape once stored in

memory. See chapter 20, Spectrum manual.