1 ; -*- fundamental -*- ---------------------------------------------------
3 ; Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 ; This program is free software; you can redistribute it and/or modify
6 ; it under the terms of the GNU General Public License as published by
7 ; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ; Boston MA 02111-1307, USA; either version 2 of the License, or
9 ; (at your option) any later version; incorporated herein by reference.
11 ; -----------------------------------------------------------------------
16 ; Very simple RLL compressor/decompressor, used to pack binary structures
19 ; Format of leading byte
20 ; 1-128 = x verbatim bytes follow
21 ; 129-223 = (x-126) times subsequent byte
22 ; 224-255 = (x-224)*256+(next byte) times the following byte
25 ; These structures are stored *in reverse order* in high memory.
26 ; High memory pointers point to one byte beyond the end.
33 ; Pack CX bytes from SI into EDI.
34 ; Returns updated SI and EDI.
47 xor ebx,ebx ; Run length zero
49 mov edx,edi ; Pointer to header byte
50 mov [edi],al ; Create header byte
51 jcxz .done ; If done, this was the terminator
71 ; 3 bytes or more in a row, time to convert sequence
74 inc edi ; We killed a whole stretch,
78 add edi,ebx ; Remove the stored run bytes
84 cmp bx,(256-224)*256-1 ; Maximum run size
104 dec si ; Reload subsequent byte
113 ; Unpack bytes from ESI into DI
114 ; On return ESI, DI are updated and CX contains number of bytes output.