/[projet1]/users/twilighte/Stormlord/unpack.s
Defence Force logotype

Contents of /users/twilighte/Stormlord/unpack.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (show annotations)
Thu Oct 7 20:50:23 2010 UTC (8 years, 3 months ago) by dbug
File size: 3356 byte(s)
Added Stormlord
1 PackedDataAddressLo
2 .byt <Storm1_pac
3 .byt <Storm2_pac
4 .byt <Storm3_pac
5 PackedDataAddressHi
6 .byt >Storm1_pac
7 .byt >Storm2_pac
8 .byt >Storm3_pac
9
10
11
12 UnpackData
13 lda PackedDataAddressLo,x
14 sta ptr_source
15 lda PackedDataAddressHi,x
16 sta ptr_source+1
17
18 lda #<Stormlord_Map
19 sta ptr_destination
20 lda #>Stormlord_Map
21 sta ptr_destination+1
22
23 lda #<Stormlord_Map_End-1
24 sta ptr_destination_end
25 lda #>Stormlord_Map_End-1
26 sta ptr_destination_end+1
27
28 jmp _file_unpack
29
30
31
32 ; void file_unpack(void *ptr_dst,void *ptr_src)
33
34 _file_unpack
35 .(
36 ; Initialise variables
37 ; We try to keep "y" null during all the code,
38 ; so the block copy routine has to be sure that
39 ; y is null on exit
40 ldy #0
41 lda #1
42 sta mask_value
43
44 unpack_loop
45 ; Handle bit mask
46 lsr mask_value
47 bne end_reload_mask
48
49 ; Read from source stream
50 lda (ptr_source),y
51
52 .(
53 ; Move stream pointer (one byte)
54 inc ptr_source
55 bne skip
56 inc ptr_source+1
57 skip
58 .)
59 ror
60 sta mask_value
61 end_reload_mask
62 bcc back_copy
63
64 write_byte
65 ; Copy one byte from the source stream
66 lda (ptr_source),y
67 sta (ptr_destination),y
68
69 .(
70 ; Move stream pointer (one byte)
71 inc ptr_source
72 bne skip
73 inc ptr_source+1
74 skip
75 .)
76
77 lda #1
78 sta nb_dst
79
80
81
82 _UnpackEndLoop
83 ;// We increase the current destination pointer,
84 ;// by a given value, white checking if we reach
85 ;// the end of the buffer.
86 clc
87 lda ptr_destination
88 adc nb_dst
89 sta ptr_destination
90
91 .(
92 bcc skip
93 inc ptr_destination+1
94 skip
95 .)
96 cmp ptr_destination_end
97 lda ptr_destination+1
98 sbc ptr_destination_end+1
99 bcc unpack_loop
100 rts
101
102
103 back_copy
104 ;BreakPoint jmp BreakPoint
105 ; Copy a number of bytes from the already unpacked stream
106 ; Here we know that y is null. So no need for clearing it.
107 ; Just be sure it's still null at the end.
108 ; At this point, the source pointer points to a two byte
109 ; value that actually contains a 4 bits counter, and a
110 ; 12 bit offset to point back into the depacked stream.
111 ; The counter is in the 4 high order bits.
112 ;clc <== No need, since we access this routie from a BCC
113 lda (ptr_source),y
114 adc #1
115 sta offset
116 iny
117 lda (ptr_source),y
118 tax
119 and #$0f
120 adc #0
121 sta offset+1
122
123 txa
124 lsr
125 lsr
126 lsr
127 lsr
128 clc
129 adc #3
130 sta nb_dst
131
132 sec
133 lda ptr_destination
134 sbc offset
135 sta ptr_source_back
136 lda ptr_destination+1
137 sbc offset+1
138 sta ptr_source_back+1
139
140 ; Beware, in that loop, the direction is important
141 ; since RLE like depacking is done by recopying the
142 ; very same byte just copied... Do not make it a
143 ; reverse loop to achieve some speed gain...
144 ; Y was equal to 1 after the offset computation,
145 ; a simple decrement is ok to make it null again.
146 dey
147 .(
148 copy_loop
149 lda (ptr_source_back),y ; Read from already unpacked stream
150 sta (ptr_destination),y ; Write to destination buffer
151 iny
152 cpy nb_dst
153 bne copy_loop
154 .)
155 ldy #0
156
157 ;// C=1 here
158 lda ptr_source
159 adc #1
160 sta ptr_source
161 bcc _UnpackEndLoop
162 inc ptr_source+1
163 bne _UnpackEndLoop
164 rts
165 .)
166
167
168 ; Taille actuelle du code 279 octets
169 ; 0x08d7 - 0x07e8 => 239 octets
170 ; 0x08c8 - 0x07e5 => 227 octets
171 ; 0x08d5 - 0x0800 => 213 octets
172 ; 0x08c9 - 0x0800 => 201 octets
173 ; 0x08c5 - 0x0800 => 197 octets
174 ; 0x08c3 - 0x0800 => 195 octets
175 ; 0x08c0 - 0x0800 => 192 octets
176 ; => 146 octets

  ViewVC Help
Powered by ViewVC 1.1.26