ZX1 decompressor

ZX1 I/O stream decompressor. (last update: 20/07/22)

CODE: xxl
ENTRY: destination adress store in ZX1_OUTPUT, ( no stream? source in ZX1_INPUT )

ZX1_OUTPUT      equ ZP
copysrc         equ ZP+2

                mwa #packed_data ZX1_INPUT
                mwa #destination ZX1_OUTPUT
                jsr unZX1
unzx1
              ldy   #$ff
              sty   offsetL
              sty   offsetH
              iny          ; 0
              sty   lenL
              sty   lenH
              lda   #$80
dzx1_literals jsr   dzx1_elias
              pha
cop0          jsr   GET_BYTE
              ldy   #$00
              sta   (ZX1_OUTPUT),y
              inw   ZX1_OUTPUT
              lda   #$ff
lenL          equ   *-1
              bne   @+
              dec   lenH
@             dec   lenL
              bne   cop0
              lda   #$ff
lenH          equ   *-1
              bne   cop0
              pla
              asl   @
              bcs   dzx1_new_offset
              jsr   dzx1_elias
dzx1_copy     pha
              lda   ZX1_OUTPUT
              clc
              adc   #$ff
offsetL       equ   *-1
              sta   copysrc
              lda   ZX1_OUTPUT+1
              adc   #$ff
offsetH       equ   *-1
              sta   copysrc+1
              ldy   #$00
              ldx   lenH
              beq   Remainder
Page          lda   (copysrc),y
              sta   (ZX1_OUTPUT),y
              iny
              bne   Page
              inc   copysrc+1
              inc   ZX1_OUTPUT+1
              dex
              bne   Page
Remainder     ldx   lenL
              beq   copyDone
copyByte      lda   (copysrc),y
              sta   (ZX1_OUTPUT),y
              iny
              dex
              bne   copyByte
              tya
              clc
              adc   ZX1_OUTPUT
              sta   ZX1_OUTPUT
              bcc   copyDone
              inc   ZX1_OUTPUT+1
copyDone      stx   lenH
              stx   lenL
              pla
              asl   @
              bcc   dzx1_literals
dzx1_new_offset
              ldx   #$ff
              stx   offsetH
              pha
              jsr   GET_BYTE
              sta   offsetL
              ror   offsetL
              bcc   dzx1_msb_skip
              jsr   GET_BYTE
              sta   offsetH
              ror   offsetH
              inc   offsetH
              bne   @+
              pla
              rts                 ; end
@             rol   offsetL
dzx1_msb_skip pla
              jsr   dzx1_elias
              inc   lenL
              bne   @+
              inc   lenH
@             jmp   dzx1_copy

dzx1_elias    inc   lenL
dzx1_elias_loop
              asl   @
              bne   dzx1_elias_skip
              jsr   GET_BYTE
              sec
              rol   @
dzx1_elias_skip
              bcs   dzx1_elias_backtrack
              rts
dzx1_elias_backtrack
              asl   @
              rol   lenL
              rol   lenH
              jmp   dzx1_elias_loop

Jeśli dane znajdują się w pamięci a nie w pliku należy wymienić odwołania:

jsr xBIOS_GET_BYTE na jsr GET_BYTE

GET_BYTE          lda    $ffff
ZX1_INPUT         equ    *-2
                  inw    ZX1_INPUT
                  rts

zobacz:
https://github.com/einar-saukas/ZX1