PackFire decompressor

PackFire decompressor. (last update: 05/04/21)

CODE: xxl
ENTRY: destination adress store in decompressing and compressed data addr in compressed_data

compressed_data      equ $80
decompressing        equ $82
copsrc               equ $84
token                equ $86
_IYL                 equ $87
_IYH                 equ $88
_L                   equ $89
_H                   equ $8a
_B                   equ $8b

PackFireTiny
            lda   compressed_data
            sta   sm_ix
            clc
            adc   #$1a
            sta   compressed_data
            lda   compressed_data+1
            sta   sm_ix+1
            adc   #$00
            sta   compressed_data+1
            ldy   #$00
            jsr   _GET_BYTE
            sta   token

literal_copy
            jsr   _GET_BYTE
            sta   (decompressing),y
            inw   decompressing
main_loop   jsr   get_bit
            bcs   literal_copy

            ldx   #$ff
            stx   _IYL
get_index   inc   _IYL
            jsr   get_bit
            bcc   get_index
            ;c=1

            ldx   _IYL
            cpx   #$10
            bne   @+
            rts                   ; koniec
@           jsr   get_pair
            ldx   _IYL
            stx   sm_len_L
            lda   _IYH
            sta   sm_len_H

            cpx   #$02
            beq   r2
            cpx   #$01
            beq   r1
            ldx   #$10        ; 0 i >2
            bne   fin_cmp1
r1          ldx   #$30        ; =1
            lda   #$02
            bne   fin_cmp
r2          ldx   #$20        ; =2
fin_cmp1    lda   #$04
fin_cmp     stx   sm_d0_L
            sty   sm_d0_H
            sta   _B

            jsr   get_bits
            jsr   get_pair

            sec
            lda   decompressing
            sbc   _IYL
            sta   copsrc
            lda   decompressing+1
            sbc   _IYH
            sta   copsrc+1

            ldx   #$ff
sm_len_H    equ   *-1
            beq   Remainder
Page        lda   (copsrc),y
            sta   (decompressing),y
            iny
            bne   Page
            inc   copsrc+1
            inc   decompressing+1
            dex
            bne   Page
Remainder   ldx   #$ff
sm_len_L    equ   *-1
            beq   copyDone
copyByte    lda   (copsrc),y
            sta   (decompressing),y
            iny
            dex
            bne   copyByte
            tya
            clc
            adc   decompressing
            sta   decompressing
            bcc   copyDone
            inc   decompressing+1
copyDone    ldy   #$00

            jmp   main_loop

; ---------------------------------

get_pair    inc   _IYL            ; zawsze < 256 ?  y=0
calc_len_dist
            tya
            and   #$0f
            bne   @+
            sta   _H
            ldx   #$01
            stx   _L
@           lsr   @
            php
            tya
            lsr   @
            tax
            lda   $ffff,x
sm_ix       equ   *-2
            plp
            bcc   nibble
         :4 lsr   @
nibble      and   #$0f
            sta   _B
            ldx   _L
            stx   sm_d0_L
            ldx   _H
            stx   sm_d0_H
            cmp   #$08
            bcc   mn8
            sbc   #$08     ; c=1
            tax
            lda   tab_bit,x         ;    D=n    E=0
            tax
            lda   #$00
            beq   @+
mn8         tax
            lda   tab_bit,x         ;    D=0    E=n
            ldx   #$00
@           clc
            adc   _L
            sta   _L
            txa
            adc   _H
            sta   _H
            iny
            dec   _IYL
            bne   calc_len_dist
            ldy   #$00

get_bits
            sty   _IYL
            sty   _IYH
            inc   _B

getting_bits
            dec   _B
            beq   _gb1

            jsr   get_bit
            bcc   @+
            asl   _IYL
            rol   _IYH
            inc   _IYL
            bne   getting_bits       ; jmp
@           asl   _IYL
            rol   _IYH
            jmp   getting_bits

_gb1        ;clc
            lda   #$ff
sm_d0_L     equ   *-1
            adc   _IYL
            sta   _IYL
            lda   #$ff
sm_d0_H     equ   *-1
            adc   _IYH
            sta   _IYH
            rts

get_bit     asl   token
            beq   @+
            rts
@           jsr   _GET_BYTE
            rol   @
            sta   token
            rts

_GET_BYTE   lda   (compressed_data),y
            inw   compressed_data
            rts

tab_bit     .byte $01,$02,$04,$08,$10,$20,$40,$80

zobacz:
https://www.pouet.net/prod.php?which=54840
https://www.cpcwiki.eu/forum/programming/dumb-question-15839-bitbuster-1-2/msg32069/#msg32069