★ APPLICATIONS ★ DISQUE ★ SQUASH ★ |
Squash (Amstrad Computer User) | Applications Disque |
The problem of saving a screen dump on the CPC 464 is that it requires 16K of memory to save any type of display - either text, or mixed text and graphics. With a cassette the problem is one of the amount of time that it takes to load the screen dump back to memory - even though the cassette speed is quite reasonable when compared with other micros. Speed is no problem if you have a disc set-up, but at 16K a time, your disc will not take that long to fill up. SQUASH is a machine code program designed to reduce the amount of memory needed to hold all the information required to reproduce the original screen picture. This is accomplished in three ways:-
The three programs as shown in listings 1, 2 and 3 work as follows:- Listing 1 This is the program that does all the hard work of checking and compressing. MEMORY is set to &5000 in line 10. This is to allow enough room for the compressed data which is stored from &9000 downwards. The data may not reach anywhere near &5000 but it is necessary to set this figure just in case it should. The actual machine code program is located at &9030 onwards. The locations between &9000 and &9030 are used to hold the information for the Mode, Border and Ink colours. The machine code program is split up into 9 different sections which will make it easier for you to key in. Each section also has a checksum number to make sure that you get the data right. If you enter any data wrong then the Basic program will tell you which section the error is in. Section 1 clears all the various buffers that are used, to zero. Section 2 checks all 16000 screen locations to find out what numbers are being used on the screen. It does this by zeroing a block of256 memory locations and then using the number from the screen as the LSB address of the block. The screen number is then copied to this address in the block. At the end of the check, any numbers in the block that still remain at zero are therefore not being used on the screen. Section 3 then checks through this block to count how many 'free' numbers are available. The reason for all this is that the SQUASH program requires two numbers which it uses as 'markers'to signal lines that are the same, and sequences of characters that are the same. Obviously if all 266 possible 8 bit numbers are being used on the screen, then there are no numbers that can be used as markers. About the only time that this would happen is if you were to deliberately poke all 256 numbers to the screen memory. Even with the most complex of pictures there are usually several dozen free numbers available. If there are not two markers available, then the program will now return back to Basic, otherwise it will continue to section 4. Section 4 first sounds a BEEP to let you know that two markers are available. These are then placed at &9001/3. Section 5 then fetches the current values for the SCREEN OFFSET, MODE, BORDER and INK COLOURS, and these are stored from &9004 to &902C. Sections 6 and 7 create a couple of blocks'which contain data for helping with the checking of the lines. Section 8 then compares the 200 screen lines to see if any are the same. Lines that are the same will only use up two bytes - the marker number, followed by the number of the similar line. Section 9 will then check each individual line of 80 bytes (unless it starts with the 'same as'marker) and see if there is any repetition of numbers. If there are more than three consecutive numbers the same then these are represented as :- Marker (2) number The amount of numbers that are the same. The number itself. As this uses up three bytes then it is only worth doing if there are more than three numbers the same. For example, a complete line of 80 numbers all the same - let's say 99 — would be compressed to:- 128099Assuming that 12 represents the second marker number.This section also stores these numbers and markers from &9000, working its way towards low memory. The address of the final location used is stored at &9008/9 to enable the length of the squashed file to be calculated. As you may well gather, rather a lot of work has to be done by the program -one reason why it is in machine code. Listing 2 wish - or just clear the screen - and then type:- CALL &9200If all is well, your original picture should be displayed within one second. If the program does not work correctly then check all the data in the lists to see that you have entered it properly. Checksums are not foolproof -after all, you may enter two values the wrong way around. The checksum will still be the same but two values the wrong way around in the machine code program spell disaster. When the two programs are working, enter listing 3 and SAVE the compressed file to tape (or disc). If you are just creating and saving pictures onto tape then the program in listing 2 does not need to be in memory. Likewise, if you are reloading the files back into memory to be re-displayed, the program in listing 1 does not need to be in memory. They are both quite happy to work together or separately if required.Let's assume that you have a Basic program for creating some fancy pictures that you want to save in compressed form. This is what you need to do:- Firstly, load in listing 1 and RUN it to put the machine code program into memory. Load in your Basic program for creating the pictures and then MERGE the subroutine in listing 3 into your Basic program. Insert the following line into this subroutine:- 10005 CALL &9030When you have created your picture then GOSUB 10000, enter the file name that you wish to give to the picture, and the file will be saved to tape as a Binary file. Repeat this process if you require to save more pictures. To re-display the pictures then load the program in listing 2 and RUN it. If you had saved 5 pictures on tape then these could be displayed one after the other by using a program such as:- 10 FOR DISPLAY = 1 TO 5Each picture will then be loaded in and displayed. |
|
|