Compactor James Higgo steals space on the Spectrum. A few months ago, several routines which stored a screen in memory and then recalled it were published. This takes up much memory, and only three screens may be stored on a 48K Spectrum in this way. [Not quite true. The maximum is six, though there is then little room left over for a recalling program. Mr. Higgo's main point remains valid, of course.] This routine compacts the screen by not storing all the blank spaces, but by counting up how many of them there are. The resulting data is stored by a Basic program, and then recalled from any area of memory by the machine-code routine. The advantages of this technique are that it takes up about a tenth of the memory for a normal picture, is faster to draw, and several images may be superimposed. To store a picture, the Basic program must be run - use GO TO 10, as RUN will wipe the screen. The compacted data will be put into locations 50000 onwards, depending on the complexity of the picture. The length of the data will be indicated by the final value of the number at the bottom left-hand corner of the screen. The data may then be saved using SAVE "data" CODE 50000 and the length number. Once the data has been saved it may be reloaded into a new location using LOAD "data" CODE and the value of the desired location. To recall the picture, the machine-code routine must be loaded, and the values of the start and finish addresses of the data must be poked into the locations 65532 to 65535, by converting the number to hex and poking the high and low bytes as follows: 65532: end location high byte 65533: end location low byte 65532: start location high byte 65533: start location low byte For example, if the data is left at locations 50000 - not saved and reloaded - POKE 65532,200 end locations (ave. picture length) POKE 65533,180 POKE 65534,195 POKE 65535, 80 start locations Using these values for the end locations may chop off or add something to your picture if it is longer or shorter than the average. Once this had been done, to recall the picture, you need only type RANDOMIZE USR 60000 Listing 1 is the data for the machine-code routine. Listing 2 is a loader for listing 1. Listing 3 is the compacting program. Here's how to enter the program: 1. Type in machine-code loader and enter data by running it 2. Delete the loader line by line, and type in the compac- ter program 3. Draw a picture, then run the computer by typing GO TO 100. Commands for drawing the picture may be entered in lines 1-99, or a picture may be loaded from tape 4. Save the compacted code on tape by typing SAVE "data" CODE 50000 and the length of the data, which is given at the bottom left of the screen after compacting 5. Reload the data into the desired area, and poke the start and finish locations into stores 65532 to 65534, as described earlier. 6. Type RANDOMIZE USR 60000 If the start and end locations have not been calculated correctly, the screen will be filled with a portion of the picture, or garbage. The locations for finish are different for each screen, and are found by hexing the length of the data plus 50000, or whatever the start location is. [ As is evident from the description above, the compactor program printed with the article wrote over the top of the screen it was compacting. Not the most productive behaviour... The program called "Compactor" on the TZX is a slightly modified version which doesn't do this, but is the same otherwise - amongst others, it does still overwrite the screen _after_ it's done with that part. If, for some reason, you want the original, it is also on the TZX, as "CompctOrig". Neither version, by the way, autoruns - that would somewhat defeat the object of the exercise, as well. The code loader is not on the TZX - it was the simplest of affairs - but, of course, the machine code itself is, as "expand". Also on the TZX are two very simple sample screens. Note their sizes, particularly the second one! And this is for the pixel data alone - the routine never touches or even looks at the attributes. It seems that Mr. Higgo has overestimated the efficiency of his routine, or perhaps uses even simpler screens than these. In any case a com- pression factor of ten, as promised, is unlikely. Finally, there's also a demo program which loads the expander code and the two sample screens - demonstrating that the routine is relocatable - and then repeatedly pokes the requisite values and calls the routine on the screens in turn. This also proves that it doesn't just write successive zeroes, it skips them entirely, over- laying the compacted screen on the existing one. As the article explains, this can be used to superimpose one screen on another. Richard Bos, April 2012 ]