1706
|
1 *
|
|
2 * Save compression routines.
|
|
3 * VEFSquash: Squashes data for VEF format.
|
|
4 * CM3Compress: Compresses altbuff using CM3 compression
|
|
5 * MGEsame: copy linebuff to altbuff
|
|
6 *
|
|
7
|
|
8 ifp1
|
1912
|
9 use os9defs.d
|
1706
|
10 endc
|
|
11
|
|
12 check macro
|
|
13 pshs b,cc
|
|
14 ldb #\1
|
|
15 os9 F$PErr
|
|
16 puls b,cc
|
|
17 endm
|
|
18
|
|
19 psect view_savecomp_a,0,0,0,0,0
|
|
20
|
|
21 *
|
|
22 * Compress one line with CM3 compression.
|
|
23 * Expects: line data in altbuff
|
|
24 * Returns: compressed line in altbuff, preceded by 2-byte size
|
|
25 * Uses: alt2buff to store last line of data
|
|
26 Stash equ 160 Stash new line at end of old line
|
|
27 CM3compress:
|
|
28 pshs a,b
|
|
29 bsr CM3stash Stash line at alt2buff+Stash
|
|
30 lbsr CM3docomp Try to compress it
|
|
31 ldd altbuff,y Get the result size
|
|
32 cmpd #160
|
|
33 bls CM3comp0 If its small, use compressed line
|
|
34 bsr CM3nocomp Else don't compress it
|
|
35 CM3comp0
|
|
36 bsr CM3save Save old line
|
|
37 puls a,b,pc
|
|
38
|
|
39 * Copy from altbuff to stash area
|
|
40 CM3stash
|
|
41 pshs a,b,x,u
|
|
42 leax altbuff,y
|
|
43 leau alt2buff+Stash,y
|
|
44 ldb #160
|
|
45 CM3st1
|
|
46 lda ,x+
|
|
47 sta ,u+
|
|
48 decb
|
|
49 bne CM3st1
|
|
50 puls a,b,x,u,pc
|
|
51
|
|
52 * Copy from stash area to save area
|
|
53 CM3save
|
|
54 pshs a,b,x,u
|
|
55 leax alt2buff+Stash,y
|
|
56 leau alt2buff,y
|
|
57 ldb #160
|
|
58 CM3save1
|
|
59 lda ,x+
|
|
60 sta ,u+
|
|
61 decb
|
|
62 bne CM3save1
|
|
63 puls a,b,x,u,pc
|
|
64
|
|
65 * No compression: from stash area to altbuff
|
|
66 CM3nocomp
|
|
67 pshs a,b,x,y,u
|
|
68 leax altbuff,y First try, no compression at all.
|
|
69 ldd #161
|
|
70 std ,x++
|
|
71 ldb #160
|
|
72 stb ,x+
|
|
73 leau alt2buff+Stash,y Get data from stash area.
|
|
74 CM3noc1
|
|
75 lda ,u+
|
|
76 sta ,x+
|
|
77 decb
|
|
78 bne CM3noc1
|
|
79 puls a,b,x,y,u,pc
|
|
80
|
|
81 vsect dp
|
|
82 ImagePtr rmb 2
|
|
83 ImageBit rmb 1
|
|
84 ActionPtr rmb 2
|
|
85 ActionBit rmb 1
|
|
86 endsect
|
|
87
|
|
88 SetAction
|
|
89 pshs a,x
|
|
90 lda ActionBit
|
|
91 ldx ActionPtr
|
|
92 ora ,x
|
|
93 sta ,x
|
|
94 puls a,x
|
|
95 ClrAction
|
|
96 pshs a,x
|
|
97 lda ActionBit
|
|
98 lsra
|
|
99 bcc ClrAct1
|
|
100 ldx ActionPtr
|
|
101 leax 1,x
|
|
102 stx ActionPtr
|
|
103 inc altbuff+2,y Increment count of Action bytes.
|
|
104 rora
|
|
105 ClrAct1
|
|
106 sta ActionBit
|
|
107 puls a,x,pc
|
|
108
|
|
109 SetImage
|
|
110 pshs a,x
|
|
111 lda ImageBit
|
|
112 ldx ImagePtr
|
|
113 ora ,x
|
|
114 sta ,x
|
|
115 puls a,x
|
|
116 ClrImage
|
|
117 pshs a,x
|
|
118 lda ImageBit
|
|
119 lsra
|
|
120 bcc ClrIm1
|
|
121 ldx ImagePtr
|
|
122 leax 1,x
|
|
123 stx ImagePtr
|
|
124 rora
|
|
125 ClrIm1
|
|
126 sta ImageBit
|
|
127 puls a,x,pc
|
|
128
|
|
129 * Try doing CM3 compression
|
|
130 CM3docomp
|
|
131 pshs a,b,x,y,u
|
|
132
|
|
133 leax altbuff,y Clear out receiving area.
|
|
134 clrb
|
|
135 CM3do1
|
|
136 clr ,x+
|
|
137 decb
|
|
138 bne CM3do1
|
|
139
|
|
140 leax altbuff+2+1,y Set up Image and Action stuff
|
|
141 stx ImagePtr
|
|
142 leax altbuff+2+1+20,y
|
|
143 stx ActionPtr
|
|
144 lda #$80
|
|
145 sta ImageBit Start with MSBit
|
|
146 sta ActionBit
|
|
147 lda #1
|
|
148 sta altbuff+2,y Set # Action bytes to 1
|
|
149
|
|
150 leax alt2buff+Stash,y Point to line data
|
|
151 leau altbuff+2+1+20+20,y Point to space for extra bytes.
|
|
152 ldb #160 Number of bytes.
|
|
153 CM3do3
|
|
154 lda ,x+ Get next byte
|
|
155 cmpa -2,x Same as previous?
|
|
156 bne CM3do4
|
|
157 bsr ClrImage Yes, mark it.
|
|
158 bra CM3do6
|
|
159 CM3do4
|
|
160 bsr SetImage
|
|
161 cmpa -(Stash+1),x Same as above?
|
|
162 bne CM3do5
|
|
163 bsr ClrAction Mark as such
|
|
164 bra CM3do6
|
|
165 CM3do5
|
|
166 lbsr SetAction
|
|
167 sta ,u+ Store byte value
|
|
168 CM3do6
|
|
169 decb
|
|
170 bne CM3do3
|
|
171
|
|
172 ldb altbuff+2,y Minimize this value.
|
|
173 lda ActionBit
|
|
174 cmpa #$80 If this is true, then last action byte hasn't been used.
|
|
175 bne CM3do7
|
|
176 decb so we can decrement it.
|
|
177 beq CM3do7 ... but not to zero.
|
|
178 stb altbuff+2,y
|
|
179 CM3do7
|
|
180
|
|
181 leax altbuff+2+1+20+20,y Point to start of extra bytes
|
|
182 ldb altbuff+2,y Get # of action bytes
|
|
183 subb #20 Number of unused action bytes
|
|
184 bne CM3do8 If none are unused, just leave extra bytes in place.
|
|
185 tfr u,x Set X to end.
|
|
186 bra CM3do11
|
|
187 CM3do8
|
|
188
|
|
189 pshs u Save end of extra bytes
|
|
190 CM3do9
|
|
191 cmpx ,s
|
|
192 beq CM3do10
|
|
193 lda ,x
|
|
194 sta b,x
|
|
195 leax 1,x Move extra bytes down
|
|
196 bra CM3do9
|
|
197 CM3do10
|
|
198
|
|
199 puls u
|
|
200 leax b,x Point to new end of extra bytes.
|
|
201 CM3do11
|
|
202
|
|
203 tfr x,d
|
|
204 leax altbuff+2,y
|
|
205 pshs x
|
|
206 subd ,s D holds size of compressed data
|
|
207 puls x
|
|
208 std altbuff,y store size.
|
|
209 puls a,b,x,y,u,pc
|
|
210
|
|
211 *
|
|
212 * Squash one packet worth of data
|
|
213 * Expects: Number of bytes to squash in D.
|
|
214 * Bytes to squash pointed to by X.
|
|
215 * Returns: Squashed packet in altbuff
|
|
216 VEFSquash:
|
|
217 pshs a,b,x,y,u
|
|
218 leau altbuff+1,y Data goes here
|
|
219 tfr d,y Size of data to compress
|
|
220 clrb This will count up size of compressed packet
|
|
221 Sq1
|
|
222 lda ,x
|
|
223 cmpa 1,x
|
|
224 bne Sq2
|
|
225 cmpa 2,x If three bytes are the same, then do compression.
|
|
226 bne Sq2
|
|
227 bsr sqcomprs Get a compressed subpacket.
|
|
228 bra Sq3
|
|
229 Sq2
|
|
230 bsr sqstraight
|
|
231 Sq3
|
|
232 sty -2,s Same as tsty
|
|
233 bne Sq1
|
|
234 ldy 4,s Restore Y
|
|
235 stb altbuff,y Store packet size.
|
|
236 puls a,b,x,y,u,pc
|
|
237
|
|
238 * Encode a sequence of straight data
|
|
239 *
|
|
240 sqstraight
|
|
241 pshs u Save address of subpacket size.
|
|
242 clr ,u+ Set zero count.
|
|
243 lda ,x+
|
|
244 sqstr1
|
|
245 sta ,u+
|
|
246 incb Increment total bytes
|
|
247 inc [,s] Increment subpacket size
|
|
248 leay -1,y Count down bytes to compress
|
|
249 beq sqstr2
|
|
250 lda ,x+
|
|
251 cmpa ,x Three like bytes mean we stop here.
|
|
252 bne sqstr1
|
|
253 cmpa 1,x
|
|
254 bne sqstr1
|
|
255 leax -1,x
|
|
256 sqstr2
|
|
257 incb Include subpacket size in total count.
|
|
258 leas 2,s Clean up stack.
|
|
259 rts
|
|
260
|
|
261 * Encode a sequence of compressed data
|
|
262 * B is increased by 2, X points to byte after repeated data,
|
|
263 * U is increased by 2, Y is decreased by number of bytes compressed.
|
|
264 sqcomprs
|
|
265 lda ,x+ Store the byte as the second byte.
|
|
266 sta 1,u
|
|
267 clr ,u Clear our count
|
|
268 sqcomprs1
|
|
269 inc ,u
|
|
270 leay -1,y
|
|
271 beq sqcomprs2 Abort the loop if Y goes to zero.
|
|
272 cmpa ,x+
|
|
273 beq sqcomprs1
|
|
274 leax -1,x Backup to point to different byte
|
|
275 sqcomprs2
|
|
276 lda ,u
|
|
277 ora #$80 Set high bit for compressed subpacket
|
|
278 sta ,u
|
|
279 leau 2,u Move past this subpacket
|
|
280 addb #2 and bump total packet size.
|
|
281 rts
|
|
282
|
|
283 *
|
|
284 * MGEsame -- copy linebuff to altbuff
|
|
285 *
|
|
286 MGEsame:
|
|
287 pshs a,b,x,u
|
|
288 leax linebuff,y
|
|
289 leau altbuff,y
|
|
290 ldb #160
|
|
291 MGEsameloop
|
|
292 lda ,x+
|
|
293 sta ,u+
|
|
294 decb
|
|
295 bne MGEsameloop
|
|
296 puls a,b,x,u,pc
|
|
297
|
|
298 endsect
|