[MZF] MZ7: MZF file compressor using ZX7 algorithms

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

[MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Sun Sep 22, 2019 4:02 pm

Source: https://github.com/SHARPENTIERS/mz7

I heard about ZX7 compressor so I decided to check it.

I made a command line tool called mz7c which allows to convert a MZF binary into a MZ7 binary which embeds a ZX7 decompressor inside the header and contains the compressed data. It allows to compress EUGEA from 44 to 22KByte and this MZ7 can then be converted into a WAV to be played even with the genuine internal tape system of the MZ.

Knowing that my MZ-SD²CMT can load EUGEA in less than 19s, I should be able to load this compressed EUGEA in less than 10s - we are close to a QD speed!

As a fact, I could also put those MZ7 files inside my MZ700 ROM/DISK project to store more tools or files.

Not totally a waste I think.

Jo Even
Site Admin
Posts: 124
Joined: Wed Jan 17, 2018 9:28 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by Jo Even » Sun Sep 22, 2019 8:03 pm

This is very interesting! I will definitely test this with my current project.

Jo Even
Site Admin
Posts: 124
Joined: Wed Jan 17, 2018 9:28 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by Jo Even » Tue Sep 24, 2019 10:03 am

Tested this quickly today, it compressed my mzt-file to less than a third. Thanks a lot for this brilliant tool :)

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Tue Sep 24, 2019 1:53 pm

Glad to see it is useful indeed :).

S_U_C
Posts: 25
Joined: Sun Feb 17, 2019 6:41 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by S_U_C » Mon Oct 21, 2019 11:09 pm

Hi,
you can not use the comment area of the tape header to store the decoder as some programs already have their own machine code stored there.
A better place to store the decoder is the keyboard buffer at $11A4 ($11A3 set to $0D). Same place on the K, A, 700 and the 800 in 700 mode.

You will need to add a short prefix to your file to copy the decoder (compiled $11A4) to the buffer.
standard and turbo and the smart backwards routines (with the smart code removed) will fit and there is room left to load a compressed SP-5510 tape basic which loads at $11FD.

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Tue Oct 22, 2019 11:03 am

The keyboard buffer is an interesting place and I can certainly place the moving code in the existing prefix/suffix part of the MZ7 file.

Just a precision: the backward mode of mz7c (untested) is provided to address the delta issue with a program which resides up to the end of conventional RAM ($????-$CFFF) by shifting the delta before instead after the data block in forward mode.

What do you mean when saying "and there is room left to load a compressed SP-5510 tape basic which loads at $11FD"?

S_U_C
Posts: 25
Joined: Sun Feb 17, 2019 6:41 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by S_U_C » Tue Oct 22, 2019 1:12 pm

The standard, turbo and the smart RSC with the Spectrum video mapping removed will load at $11A4 and do not reach $11FD the load address of the MZ80A tape basic SP-5510, I have created a auto-run feature for SP-5510 basic which saves the basic and BTX file as a M/C file that loads and runs from the monitor. These are large files and can be 40KB but have to load at $11FD, they are ideal for compressing.
The prefix loader pushes the execute address onto the stack, pushes the $11A3 on the stack copies a $0D and the loader code (compiled to $11A4) to $11A3. It then works out the source and destination locations and returns to $11A3via a ret, which in turns ret to the execute address.
After the ret from loader, the loader code can be overwritten.
The only other thing that need calculating is the load address of the mzf file, to adjusted len of prefix, len of loader and delta and len of compredded data.

Note the end of usable ram on a MZ80K,A,700 and 800 in 700 mode is the end of V-ram not $CFFF, it may cause snow but is usable as the screen can not scroll while the decoder is running.

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Tue Oct 22, 2019 2:52 pm

S_U_C wrote:
Tue Oct 22, 2019 1:12 pm
Note the end of usable ram on a MZ80K,A,700 and 800 in 700 mode is the end of V-ram not $CFFF, it may cause snow but is usable as the screen can not scroll while the decoder is running.
You cannot use VRAM as a permanent area for a program but yeah it could contain the delta which is indeed a temporary data until all the data block is decompressed: that's a valid point if running the program doesn't rely upon preserving display as it was before loading.

I want to be sure to understand what you mean when you say "the standard, turbo and the smart RSC with the Spectrum video mapping removed will load at $11A4". If by turbo, you mean the one inside mzf2wav. It won't work as you may think. Turbo tries to load from $D400 because it is its load address in the header. But I guess, we could adapt it to make it uses $11A4 instead to load a compressed MZF files. The MZ7 compressor can also be adapted to load from $11A4 and will preserve the comment field (but it won't be necessary) by adding the loader move in the MZ7 loader part of the compressed file. A 2400 baud loading of a compressed file would allow to divide the load time by two at worst case.

I tried to compress MZ-700 BASIC 1Z-013B and it was not that great compared to most games. But TURBO x2/x3 + MZ7 may help to reduce the load time of the BASIC and the code to run and make it more acceptable.

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Tue Oct 22, 2019 2:58 pm

One thing is sure, I didn't happen to find some binaries using the comment field for something after they were loaded and run. Loading is direct, no move and less bytes in the data block. But I certainly understand it is not keeping the original comment and some non binary files may indeed use the comment field but the monitor cannot exploit them anyway.

hlide
Posts: 312
Joined: Thu Jan 25, 2018 9:31 pm

Re: [MZF] MZ7: MZF file compressor using ZX7 algorithms

Post by hlide » Tue Oct 22, 2019 3:12 pm

So next step for MZ7C:
- adding an option to use the keyboard buffer to host the decompressor code and preserving the comment field.

Possible next step for MZF2WAV:
- adding an option to use the keyboard buffer instead of $D400 to make it more compliant with all the SHARP MZ series K.

I don't know about the RCS stuff.

I need a code as an example to show how to build an autorunable BASIC program. It implies compressing both the BASIC and the program, to load them, run the basic and making it
run the program. Is that possible? (especially it may have different ways netween BASIC).

Post Reply