Recent

Author Topic: ZX02 implementation in Pascal  (Read 1623 times)

geraldholdsworth

  • Sr. Member
  • ****
  • Posts: 284
Re: ZX02 implementation in Pascal
« Reply #15 on: January 09, 2026, 08:58:39 pm »
Never knew about that one - thank you.
Everyday is a school day.

While I'm here, and I'm finding out lots of things - obviously, the project above is a console program, so the only way I know of running it is in Terminal (on my Mac)...i.e., not in debug mode. So, how does one debug such a program?
I'm more used to writing and debugging GUI applications, which I can just click on the Play button. Can't do that with this sort of project.

cdbc

  • Hero Member
  • *****
  • Posts: 2600
    • http://www.cdbc.dk
Re: ZX02 implementation in Pascal
« Reply #16 on: January 09, 2026, 09:31:37 pm »
Hi
In Laz menu click 'View' -> 'Debug Windows' -> 'Console In/Output' =^
...And remember if your app wants input, you should click on the 'Console Output Window' to give it focus, before you type...  ;D
Have fun mate and happy debugging
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

MathMan

  • Sr. Member
  • ****
  • Posts: 472
Re: ZX02 implementation in Pascal
« Reply #17 on: January 11, 2026, 12:10:23 am »
Hi
Quote
I made pointer a Cardinal so that it doesn't go below zero.
Warning: The above will only work on 32bit, NOT 64bit...!
A safer approach is to make it a 'PtrUInt' instead of a 'Cardinal', because a 'PtrUInt' is the Unsigned Integer of pointer/register-size of the current platform. The same goes for 'PtrInt' => pointer/register-sized Signed Integer
Regards Benny

While your point above is totally correct it does not apply in this case, as the 'pointer' above is a badly choosen variable name. The variable itself is an index into a dynamic array. Using Cardinal as type is save as it at max can generate a range check error. On the other hand it is oversized, as 6502 only has an address range of 64 kByte - Word would be sufficient.

MathMan

  • Sr. Member
  • ****
  • Posts: 472
Re: ZX02 implementation in Pascal
« Reply #18 on: January 11, 2026, 12:17:12 am »
Edit: Did a little reading inbetween. As guessed it is indeed a variant of the Lempel-Ziv-Welch family of compressors. It is based on LZSS with certain fine-tuning of parameters to accomodate 'low-end' CPU like Z80, 6502 etc. If you still want to understand how it is working look here for an explanation on LZSS

I think my main problem of understanding was that I couldn't relate the Elias codes in the given file to the description of how Elias encoding worked.

I can understand that, because the variant of Elias coding used is a very special one.

If I understand this correct, then the decoding of the Elias works as follows

 - the result in 'X' is stitched together from inverted Elias coded single
   bits of the input stream. That is '%10xxxxxx' in 'bitr' will shift in
   a '0' as low bit in 'X' - '%11xxxxxx' will shift in a '1' and '%0xxxxxxx'
   will terminate the process.
 - the bit-stream for the decoding is interleaved into the copy blocks
 - the bit-stream also contains the bits that define the state transitions!

New offsets do not fall under the Elias decoding, but are read as single (or double) bytes.

All this hoopla, just to make the decoder small & fast on an ancient architecture ...

Oh, forgot attached is my take on it - I have a tendency towards heavy commenting.
« Last Edit: January 11, 2026, 10:13:07 am by MathMan »

geraldholdsworth

  • Sr. Member
  • ****
  • Posts: 284
Re: ZX02 implementation in Pascal
« Reply #19 on: January 11, 2026, 04:16:20 pm »
Wow...thank you.

 

TinyPortal © 2005-2018