# XPK meta-compression library ## How-Tos ### Compress and decompress in assembler #### Open the library ```asm MOVE.L 4,A6 LEA XpkmasterLibraryName,A1 MOVEQ #0,D0 CALLLIB _LVOOpenLibrary MOVE.L D0,XpkmasterBase CNOP 0,4 XpkmasterBase DS.L 1 XpkmasterLibraryName DC.B "xpkmaster.library",0 ``` #### Compress some data and get the length of the compressed data ```asm LEA TagData,A3 ; pack from MOVE.L #XPK_InBuf,(A3)+ MOVE.L MemoryPtr,(A3)+ MOVE.L #XPK_InLen,(A3)+ MOVE.L FileSize,(A3)+ ; pack to MOVE.L FileSize,D0 ; word aligned ADDQ #2,D0 AND.W #$FFFFFFFE,D0 MOVE.L D0,D1 ADD.L MemoryPtr,D0 MOVE.L #XPK_OutBuf,(A3)+ MOVE.L D0,(A3)+ ; XPK needs lots of space to work when compressing ADD.L #XPK_MARGIN,D1 ADD.L #XPK_MARGIN,D1 MOVE.L #XPK_OutBufLen,(A3)+ MOVE.L D1,(A3)+ ; pack how LEA FASTPacker,A1 MOVE.L #XPK_PackMethod,(A3)+ MOVE.L A1,(A3)+ ; how did it go LEA OutLen,A1 MOVE.L #XPK_GetOutLen,(A3)+ MOVE.L A1,(A3)+ ; technically a TagItem is two ULONGs so be sure to have enough allocated for them ; XPKExamine was acting poorly when i wasn't providing enough ULONGs MOVE.L #TAG_DONE,(A3)+ MOVE.L #TAG_DONE,(A3)+ ; pack! MOVE.L XpkmasterBase,A6 LEA TagData,A0 CALLLIB _LVOXpkPack CNOP 0,4 TagData DS.L 32 MemoryPtr DS.L 1 ; place where compressed data is stored. long enough to handle buffer needed for compression and decompression FileSize DS.L 1 ; the total bytes to compress OutLen DS.L 1 ; how big is the compressed output FASTPacker DC.B "FAST",0 ``` #### Unpack the data ```asm LEA TagData,A3 ; unpack from MOVE.L FileSize,D0 ; word aligned ADDQ #2,D0 AND.W #$FFFFFFFE,D0 MOVE.L D0,D1 ADD.L MemoryPtr,D0 MOVE.L #XPK_InBuf,(A3)+ MOVE.L D0,(A3)+ MOVE.L #XPK_InLen,(A3)+ MOVE.L OutLen,(A3)+ ; unpack to ADD.L #XPK_MARGIN,D0 ADD.L #XPK_MARGIN,D0 MOVE.L #XPK_OutBuf,(A3)+ MOVE.L D0,(A3)+ MOVE.L D0,UncompressedArea MOVE.L #XPK_OutBufLen,(A3)+ MOVE.L OutLen,D0 ADD.L #XPK_MARGIN,D0 MOVE.L D0,(A3)+ MOVE.L #TAG_DONE,(A3)+ ; unpack! MOVE.L XpkmasterBase,A6 LEA TagData,A0 CALLLIB _LVOXpkUnpack CNOP 0,4 UncompressedArea DS.L 1 ; you can interact with the compressed data here ``` #### Close the library ```asm MOVE.L 4,A6 ; close xpkmaster.library MOVE.L XpkmasterBase,A1 CALLLIB _LVOCloseLibrary ```