1 ; -*- fundamental -*- ---------------------------------------------------
3 ; Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 ; Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 ; This program is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ; Boston MA 02111-1307, USA; either version 2 of the License, or
10 ; (at your option) any later version; incorporated herein by reference.
12 ; -----------------------------------------------------------------------
17 ; Very simple RLL compressor/decompressor, used to pack binary structures
20 ; Format of leading byte
21 ; 1-128 = x verbatim bytes follow
22 ; 129-223 = (x-126) times subsequent byte
23 ; 224-255 = (x-224)*256+(next byte) times the following byte
26 ; These structures are stored *in reverse order* in high memory.
27 ; High memory pointers point to one byte beyond the end.
34 ; Pack ECX bytes from ESI into EDI.
35 ; Returns updated ESI and EDI.
48 xor eax,eax ; Zero byte
49 xor ebx,ebx ; Run length zero
51 mov edx,edi ; Pointer to header byte
52 mov [edi],al ; Create header byte
53 jcxz .done ; If done, this was the terminator
73 ; 3 bytes or more in a row, time to convert sequence
76 inc edi ; We killed a whole stretch,
80 add edi,ebx ; Remove the stored run bytes
86 cmp bx,(256-224)*256-1 ; Maximum run size
106 dec esi ; Reload subsequent byte
117 ; Unpack bytes from ESI into EDI
118 ; On return ESI, EDI are updated and
119 ; ECX contains number of bytes output.