/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib2/unpack.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib2/unpack.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1154 - (show annotations)
Sun Aug 10 18:19:54 2014 UTC (5 years, 6 months ago) by dbug
File size: 4090 byte(s)


1
2
3 ; Packed source data adress
4 #define ptr_source tmp0
5
6 ; Destination adress where we depack
7 #define ptr_destination tmp1
8
9 ; Point on the end of the depacked stuff
10 #define ptr_destination_end tmp2
11
12 ; Temporary used to hold a pointer on depacked stuff
13 #define ptr_source_back tmp3
14
15 ; Temporary
16 #define offset tmp4
17
18 #define mask_value reg0
19 #define nb_src reg1
20 #define nb_dst reg2
21
22
23 UnpackError
24 rts
25
26 UnpackLetters .byt "LZ77"
27
28
29 ; void file_unpack(void *ptr_dst,void *ptr_src)
30
31 _file_unpack
32 .(
33 ldy #0
34 lda (sp),y
35 sta ptr_destination
36 iny
37 lda (sp),y
38 sta ptr_destination+1
39
40
41 ; Source adress
42 ldy #2
43 lda (sp),y
44 sta ptr_source
45 iny
46 lda (sp),y
47 sta ptr_source+1
48
49
50 ; Test if it's LZ77
51 ldy #3
52 .(
53 test_lz77
54 lda (ptr_source),y
55 cmp UnpackLetters,y
56 bne UnpackError
57 dey
58 bpl test_lz77
59 .)
60
61
62 ; Get the unpacked size, and add it to the destination
63 ; adress in order to get the end adress.
64 ldy #4
65 clc
66 lda ptr_destination
67 adc (ptr_source),y
68 sta ptr_destination_end+0
69 iny
70 lda ptr_destination+1
71 adc (ptr_source),y
72 sta ptr_destination_end+1
73
74
75 ; Move the source pointer ahead to point on packed data (+0)
76 clc
77 lda ptr_source
78 adc #8
79 sta ptr_source
80 lda ptr_source+1
81 adc #0
82 sta ptr_source+1
83
84
85 ; Initialise variables
86 ; We try to keep "y" null during all the code,
87 ; so the block copy routine has to be sure that
88 ; y is null on exit
89 ldy #0
90 lda #1
91 sta mask_value
92
93 unpack_loop
94 ; Handle bit mask
95 lsr mask_value
96 bne end_reload_mask
97
98 ; Read from source stream
99 lda (ptr_source),y
100
101 .(
102 ; Move stream pointer (one byte)
103 inc ptr_source
104 bne skip
105 inc ptr_source+1
106 skip
107 .)
108 ror
109 sta mask_value
110 end_reload_mask
111 bcc back_copy
112
113 write_byte
114 ; Copy one byte from the source stream
115 lda (ptr_source),y
116 sta (ptr_destination),y
117
118 .(
119 ; Move stream pointer (one byte)
120 inc ptr_source
121 bne skip
122 inc ptr_source+1
123 skip
124 .)
125
126 lda #1
127 sta nb_dst
128
129
130
131 _UnpackEndLoop
132 ;// We increase the current destination pointer,
133 ;// by a given value, white checking if we reach
134 ;// the end of the buffer.
135 clc
136 lda ptr_destination
137 adc nb_dst
138 sta ptr_destination
139
140 .(
141 bcc skip
142 inc ptr_destination+1
143 skip
144 .)
145 cmp ptr_destination_end
146 lda ptr_destination+1
147 sbc ptr_destination_end+1
148 bcc unpack_loop
149 rts
150
151
152 back_copy
153 ;BreakPoint jmp BreakPoint
154 ; Copy a number of bytes from the already unpacked stream
155 ; Here we know that y is null. So no need for clearing it.
156 ; Just be sure it's still null at the end.
157 ; At this point, the source pointer points to a two byte
158 ; value that actually contains a 4 bits counter, and a
159 ; 12 bit offset to point back into the depacked stream.
160 ; The counter is in the 4 high order bits.
161 ;clc <== No need, since we access this routie from a BCC
162 lda (ptr_source),y
163 adc #1
164 sta offset
165 iny
166 lda (ptr_source),y
167 tax
168 and #$0f
169 adc #0
170 sta offset+1
171
172 txa
173 lsr
174 lsr
175 lsr
176 lsr
177 clc
178 adc #3
179 sta nb_dst
180
181 sec
182 lda ptr_destination
183 sbc offset
184 sta ptr_source_back
185 lda ptr_destination+1
186 sbc offset+1
187 sta ptr_source_back+1
188
189 ; Beware, in that loop, the direction is important
190 ; since RLE like depacking is done by recopying the
191 ; very same byte just copied... Do not make it a
192 ; reverse loop to achieve some speed gain...
193 ; Y was equal to 1 after the offset computation,
194 ; a simple decrement is ok to make it null again.
195 dey
196 .(
197 copy_loop
198 lda (ptr_source_back),y ; Read from already unpacked stream
199 sta (ptr_destination),y ; Write to destination buffer
200 iny
201 cpy nb_dst
202 bne copy_loop
203 .)
204 ldy #0
205
206 ;// C=1 here
207 lda ptr_source
208 adc #1
209 sta ptr_source
210 bcc _UnpackEndLoop
211 inc ptr_source+1
212 bne _UnpackEndLoop
213 rts
214 .)
215
216
217 ; Taille actuelle du code 279 octets
218 ; 0x08d7 - 0x07e8 => 239 octets
219 ; 0x08c8 - 0x07e5 => 227 octets
220 ; 0x08d5 - 0x0800 => 213 octets
221 ; 0x08c9 - 0x0800 => 201 octets
222 ; 0x08c5 - 0x0800 => 197 octets
223 ; 0x08c3 - 0x0800 => 195 octets
224 ; 0x08c0 - 0x0800 => 192 octets
225 ; => 146 octets

  ViewVC Help
Powered by ViewVC 1.1.26