Re: A85: Compress levels


[Prev][Next][Index][Thread]

Re: A85: Compress levels




At 01:22 1998-03-22 GMT, you wrote:
>
>i do plan on making the game for Usgard, but will most likely also
>make it for Rigel (the game should be quite a bit smaller for this
>shell).  That's why i wanted the source code.

This is the source to HUFFEXTR. It uses the format created
by HUFFMAN.EXE. It supports "multifiles", which mean that
you can compress many files (levels, graphics for instance)
using the same huffman tree, thus saving space.

For info how to use it, well, read the documentation
by downloading huffman lib for Fargo 0.1.x.


 #include usgard.h

 .org 0
 push de
 push de
 push hl
 inc hl
 ld a,(hl)
 cp 1
 jr nz,MultiFile
 ld b,0
MultiFile:
 push bc
 inc hl
 ld d,(hl)
 inc hl
 ld e,(hl) ; DE = noDifChars
 inc hl
 push hl
 add a,a
 ld c,a
 add a,a
 add a,c
 ld b,0
 ld c,a
 add hl,bc ; HL -> chars
 ld b,e
 dec b	   ; B = noDifChars-1
 push hl
 add hl,de
 pop de    ; DE -> chars, HL -> tree, IX -> treeaddr
 ld (&treeaddr),ix
 ld a,1
UncrunchTree:
 ld c,a
 and (hl)
 jr z,NoBranch
 push ix
 inc ix
 inc ix
NextTreeBit:
 ld a,c
 rlca
 jr nc,UncrunchTree
 inc hl
 jr UncrunchTree
NoBranch:
 ld a,(de)
 inc de
 ld (ix),0
 ld (ix+1),a
 inc ix
 inc ix
 ld a,b
 or a
 jr z,TreeBuilt
 ex (sp),hl
 push de
 push ix
 pop de
 ld (hl),e
 inc hl
 ld (hl),d
 pop de
 ex (sp),hl
 inc sp
 inc sp
 dec b
 jr NextTreeBit
TreeBuilt:
 pop ix  ; IX -> fileInfo
 pop af  ; A = file no
 pop hl  ; HL -> noFiles
 add a,a
 ld c,a
 add a,a
 add a,c
 ld b,0
 ld c,a
 add ix,bc  ; IX -> fileInfo[file no]
 ld d,(ix)
 ld e,(ix+1)
 add hl,de   ; HL -> data
 ld b,(ix+3) ; B = start bit
 ld a,1
Shift:
 rlca
 djnz Shift
 ld c,a      ; C = start bit vlaue
 ld d,(ix+4)
 ld e,(ix+5) ; DE = length of uncompressed data
 pop ix  ; HL -> Data, C = bitval, DE = length, IX -> Storage
UncrunchData:
 push de
 ld de,(&treeaddr)
CheckTree:
 ld a,(de)
 or a
 jr z,EndOfBranch
 ld a,c
 and (hl)
 jr nz,RightBranch
 inc de
 inc de
 jr NextDataBit
RightBranch:
 ex de,hl
 call LD_HL_MHL
 ex de,hl
NextDataBit:
 rlc c
 jr nc,CheckTree
 inc hl
 jr CheckTree
EndOfBranch:
 inc de
 ld a,(de)
 ld (ix),a
 inc ix
 pop de
 dec de
 ld a,d
 or e
 jr nz,UncrunchData
 pop de
 ret
treeaddr:
 .dw 0
.end

--
Real name: Jimmy Mårdell                 
IRC......: Yarin                         
Email....: mailto:yarin@acc.umu.se      <-- NEW E-MAIL ADDRESS!!!!
Homepage.: http://www.algonet.se/~mja/


Follow-Ups: References: