Z80 Routines:Other:IonCompress
From WikiTI
This code is untested and may not work as advertised or at all.
;Ion Compression Routines ;These routines are <supposed to> compress data in the format used by ;the IonDecompress routine. I, Saibot84, have only reverse-engineered ;the compression algorithm based on the IonDecompress routine. ; ;Just a note: The way I consider this, there is a routine that does ;the work, and then there may be a routine that modifies slightly the ;inputs and outputs of the first routine. This modifying routine, I ;call the MetaLibrary routine as an analogy to how physics is under ;metaphysics. ;-) ; ;I know it's not good to post untested bits of code, but I just ;stumbled upon this on my computer and remembered I wanted to ;release it. ; ;IonCompress ;Inputs: ; hl->where to read the data from ; de->where to store the compressed output ; b = number of bytes to copmpress ; c = compression factor (see IonDecompress) ;Outputs: ; hl->end of where to read ; de->end of where to store ; carry flag: set->error res->all is well ; ;MetaLib_IonCompress ;Inputs: ; hl->where to read the data from ; de->where to store the compressed output ; bc = number of bytes to copmpress ; a = compression factor (see IonDecompress) ;Outputs: ; hl->end of where to read ; de->end of where to store ; bc = new length ; carry flag: set->error res->all is well IonCompress: ;016-7-2005 ;=>hl->read ;=>de->sto ;=>b=len ;=>c=comp factor ;<=hl->read+len ;<=de->sto+len(new) ;<=cf=error ld a,c cp 2 jr nc, IC_Next1 srl b IC_Next1: cp 4 jr nc,IC_Next2 srl b IC_Next2: srl b push ix IC_Loop: push bc ld ixh,0 ld ixl,8 ld a,c ld b,8 cp 1 jr z,IC_cmp1 ld b,4 cp 3 jr z,IC_cmp1 ld b,2 IC_cmp1: push bc ld a,c ld b,1 cp 1 jr z,IC_cmp2 inc b cp 3 jr z,IC_cmp2 ld b,4 IC_cmp2: ld a,ixl sub b ld b,a ld ixl,a ld a,c cp (hl) jr c,IC_Error ld a,(hl) IC_cmp3: sla a djnz IC_cmp3 or ixh inc hl pop bc djnz IC_cmp1 inc de pop bc djnz IC_Loop IC_Exit: pop ix ret IC_Error: pop bc pop bc jr IC_Exit MetaLib_IonCompress: ;016-7-2005 ;=>hl->read ;=>de->sto ;=>bc=len ;=>a=comp factor ;<=hl->read+len ;<=de->sto+len(new) ;<=bc=new length ;<=cf=error push de push af push bc ld b,a ld a,c or a ld a,b pop bc jr z,ML_IC_Loop inc b ML_IC_Loop: push bc push af ld b,c ld c,a call IonCompress ret c pop af pop bc ld c,0 djnz ML_IC_Loop pop af ex (sp),hl ex de,hl push hl or a sbc hl,de pop de push hl pop bc pop hl ret
Special Thanks
Joe Wingbermuhele for creating Ion for the 83/83+
XDG Kat-Productions's Justin Haygood and Benny Baumann for encouraging my coding abilities in both z80 Asm and TI-BASIC.