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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26