wok view memtest/stuff/unzx0.S @ rev 25613
Add grub-btrfs
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Aug 02 09:46:03 2023 +0000 (12 months ago) |
parents | f1ad7cb7989b |
children | a794ec0a6495 |
line source
1 #ifndef FLAT32
2 // input ds:si=inStream, es:di=outStream
3 // output outStream[], ds:si, es:di
4 .code16
5 #define BX %bx
6 #define SI %si
7 #define DI %di
8 #else
9 // input esi=inStream, edi=outStream
10 // output outStream[], ds:esi, es:edi
11 .code32
12 #define BX %ebx
13 #define SI %esi
14 #define DI %edi
15 #endif
17 // unzx0_8088.S - ZX0 decompressor for 8088 - 73 bytes - NASM
18 //
19 // inputs:
20 // * ds:si: start of compressed data
21 // * es:di: start of decompression buffer
22 //
23 // Copyright (C) 2021 Emmanuel Marty
24 // ZX0 compression (c) 2021 Einar Saukas, https://github.com/einar-saukas/ZX0
25 //
26 // This software is provided 'as-is', without any express or implied
27 // warranty. In no event will the authors be held liable for any damages
28 // arising from the use of this software.
29 //
30 // Permission is granted to anyone to use this software for any purpose,
31 // including commercial applications, and to alter it and redistribute it
32 // freely, subject to the following restrictions:
33 //
34 // 1. The origin of this software must not be misrepresented; you must not
35 // claim that you wrote the original software. If you use this software
36 // in a product, an acknowledgment in the product documentation would be
37 // appreciated but is not required.
38 // 2. Altered source versions must be plainly marked as such, and must not be
39 // misrepresented as being the original software.
40 // 3. This notice may not be removed or altered from any source distribution.
42 zx0_decompress:
43 cld // make string operations go forward
44 movb $0x80, %al // initialize empty bit queue
45 // plus bit to roll into carry
46 stc
47 sbb BX, BX // initialize rep-offset to 1
49 .literals:
50 #if !defined(FLAT16) && !defined(FLAT32)
51 cmpw $32768, %si // assume 32767 literals max
52 jb .si_ok
53 subw $32768, %si
54 movw %ds, %dx
55 addb $8, %dh
56 movw %dx, %ds
57 .si_ok:
58 #endif
59 call .get_elias // read number of literals to copy
60 rep movsb // copy literal bytes
62 addb %al, %al // shift bit queue, and high bit into carry
63 jc .get_offset // if 1: read offset, if 0: rep-match
65 call .get_elias // read rep-match length (starts at 1)
67 #if !defined(FLAT16OUT) && !defined(FLAT32)
68 jmp .copy_match
69 .fix_di:
70 subw $256, %di
71 movw %es, %dx
72 addw $16, %dx
73 movw %dx, %es
74 .copy_match:
75 cmpw $-32640, %di // assume 32639 max window
76 ja .fix_di
77 #else
78 .copy_match:
79 #endif
80 push SI // save si (current pointer to compressed data)
81 lea (BX,DI), SI // point to destination in es:di + offset in bx
82 rep movsb %es:(SI), %es:(DI) // copy matched bytes
83 pop SI // restore si
85 addb %al, %al // read 'literal or match' bit
86 jnc .literals // if 0: go copy literals
88 .get_offset:
89 movb $0xfe, %cl // initialize value to FEh
90 call .elias_loop // read high byte of match offset, set carry
91 incb %cl // obtain negative offset high byte
92 je .done // exit if EOD marker
94 movb %cl, %bh // transfer negative high byte into bh
95 movw $1, %cx // initialize match length value to 1
96 movb (%si), %bl // read low byte of offset + 1 bit of len
97 incw %si // inc instruction keep carry set
98 // set high bit that is shifted into bit 15
99 rcrw $1, %bx // shift len bit into carry/offset in place
100 call .elias_bt // if len bit is set, no need for more
101 // else read rest of elias-encoded match length
102 incw %cx // fix match length
103 jmp .copy_match // go copy match
105 .get_elias:
106 movw $1, %cx // initialize value to 1
107 .elias_loop:
108 addb %al, %al // shift bit queue, and high bit into carry
109 jnz .got_bit // queue not empty, bits remain
110 lodsb // read 8 new bits
111 adcb %al, %al // shift bit queue, and high bit into carry
112 .got_bit:
113 .elias_bt:
114 jc .got_elias // done if control bit is 1
115 addb %al, %al // read data bit
116 adcw %cx, %cx // shift into cx
117 jmp .elias_loop // keep reading
118 .got_elias:
119 .done:
120 ret