1706
|
1 *
|
|
2 * Setup and Screen support for GIF
|
|
3 *
|
|
4 * Globals
|
|
5 * gifoutinit -- Initialize output machinery
|
|
6 * gifoutpix -- output one pixel, with scaling, etc.
|
|
7 *
|
|
8 ifp1
|
1912
|
9 use os9defs.d
|
1706
|
10 endc
|
|
11
|
|
12 psect view_gifpix_a,0,0,0,0,0
|
|
13
|
|
14 *
|
|
15 * Screen support-- output one GIF pixel to screen, with scaling and dithering.
|
|
16 *
|
|
17 vsect dp
|
|
18 pixpline rmb 2 Number of pixels on a virtual screen line.
|
|
19 pixscrn rmb 2 Number of pixels on actual screen line.
|
|
20 pixcnt rmb 2 Count of pixels on actual screen line.
|
|
21 lineptr rmb 2 Pointer to linebuff, for putting pixels
|
|
22 pixleft rmb 2 Number of pixels left for this GIF line
|
|
23 horscale rmb 2 Horizontal scaling counter.
|
|
24 linecount rmb 2 Current GIF line number
|
|
25 linenumb rmb 2 Current Coco Line number
|
|
26 linemax rmb 2 Max Coco line number
|
|
27 lineinc rmb 2 Increment between lines
|
|
28 verscale rmb 2 vertical scaling counter.
|
|
29 endsect
|
|
30
|
|
31 * gifinterlace holds T if we do interlace.
|
|
32 gifoutinit:
|
|
33 pshs d,x
|
|
34 ldd #1
|
|
35 tst <gifinterlace
|
|
36 beq init1
|
|
37 ldd #8
|
|
38 init1
|
|
39 std lineinc
|
|
40
|
|
41 ldd #0
|
|
42 std linecount
|
|
43 std horscale
|
|
44 std verscale
|
|
45
|
|
46 ldd <Skipcols
|
|
47 bpl init20 Default value is zero
|
|
48 ldd #0
|
|
49 std <Skipcols
|
|
50 init20
|
|
51
|
|
52 ldd <Skiplines
|
|
53 bpl init21 Default value is zero
|
|
54 ldd #0
|
|
55 std <Skiplines
|
|
56 init21
|
|
57
|
|
58 ldd #0
|
|
59 subd <Skipcols
|
|
60 std pixcnt
|
|
61
|
|
62 leax linebuff,y
|
|
63 stx lineptr
|
|
64 ldd <gifiwidth
|
|
65 std pixleft
|
|
66
|
|
67 ldx #320 Type 8 and 6 screens are 320 pixels across.
|
|
68 lda <type
|
|
69 cmpa #8
|
|
70 beq init8
|
|
71 cmpa #6
|
|
72 beq init8
|
|
73 ldx #640 Type 7 and 5 are 640 pixels across.
|
|
74 init8
|
|
75 stx pixscrn
|
|
76 stx pixpline
|
|
77
|
|
78 ldd #192 For default size, scale pic to 192 lines.
|
|
79 std linemax
|
|
80
|
|
81 lda <Size
|
|
82 bne init98
|
|
83 ldx <gifiheight For small, choose divisor of actual height.
|
|
84 clra
|
|
85 pshs a
|
|
86 init92
|
|
87 inc ,s
|
|
88 lda ,s
|
|
89 lbsr div168 Divide height by number
|
|
90 cmpd #200
|
|
91 bhi init92 If not <200, keep going
|
|
92 std linemax
|
|
93 puls a Clear stack
|
|
94 bra init99
|
|
95 init98
|
|
96 cmpa #2
|
|
97 bne init99
|
|
98 ldd <gifiheight Huge is 1:1 height
|
|
99 std linemax
|
|
100 ldd <gifiwidth And 1:1 width
|
|
101 cmpd <pixscrn ... but not less than screen width
|
|
102 blo init99
|
|
103 std pixpline
|
|
104 init99
|
|
105
|
|
106 puls d,x,pc
|
|
107
|
|
108 * Output pixel to screen
|
|
109 *
|
|
110 * Expects
|
|
111 * alt2buff holds color translation table
|
|
112 * A holds pixel to output
|
|
113 * gifiheight, gifiwidth hold picture dimensions
|
|
114 gifoutpix:
|
|
115 pshs a,b,x
|
|
116 tst verscale
|
|
117 bmi outpix5
|
|
118 ldx lineptr
|
|
119 ldd horscale
|
|
120 subd pixpline
|
|
121 std horscale
|
|
122 bpl outpix5
|
|
123 outpix1
|
|
124 ldd pixcnt
|
|
125 addd #1
|
|
126 std pixcnt
|
|
127 bmi outpix11
|
|
128 cmpd pixscrn
|
|
129 bgt outpix11
|
|
130 lda ,s
|
|
131 sta ,x+
|
|
132 outpix11
|
|
133 ldd horscale
|
|
134 addd <gifiwidth
|
|
135 std horscale
|
|
136 bmi outpix1
|
|
137 stx lineptr
|
|
138 outpix5
|
|
139 ldx pixleft Count down number of GIF pixels on this line.
|
|
140 leax -1,x
|
|
141 stx pixleft
|
|
142 bne outpix9
|
|
143 tst verscale
|
|
144 bmi outpix7
|
|
145 lbsr dithline Translate GIF pixels to CoCo colors
|
|
146 lbsr convline Convert the pixels to bytes.
|
|
147 lbsr outline If we're done, output the line.
|
|
148 lbsr clrline
|
|
149 outpix7
|
|
150 lbsr setline
|
|
151 leax linebuff,y
|
|
152 stx lineptr
|
|
153 ldx <gifiwidth
|
|
154 stx pixleft
|
|
155 ldx #00
|
|
156 stx horscale
|
|
157
|
|
158 ldd #0
|
|
159 subd <Skipcols
|
|
160 std pixcnt
|
|
161 outpix9
|
|
162 puls a,b,x,pc
|
|
163
|
|
164 dithline
|
|
165 pshs a,b,x,y,u
|
|
166 leau alt2buff,y Color mapping table.
|
|
167 ldd pixscrn Number of pixels on this line.
|
|
168 lsra Divide by 4, since main loop does 4 pixels at a time.
|
|
169 rorb
|
|
170 lsra
|
|
171 rorb
|
|
172 pshs b Even for a 640-pixel line, this will be less than 256.
|
|
173 leay linebuff,y Y points to line data.
|
|
174
|
|
175 lda linenumb+1 What line (mod 4) are we on?
|
|
176 anda #3
|
|
177 leax dithtable,pcr
|
|
178 leax a,x
|
|
179 jsr a,x
|
|
180 puls b
|
|
181 puls a,b,x,y,u,pc
|
|
182
|
|
183 dithtable
|
|
184 bra dithloop1 Different sub for each line (mod 4).
|
|
185 bra dithloop2
|
|
186 bra dithloop3
|
|
187 bra dithloop4
|
|
188
|
|
189 dithloop1
|
|
190 bsr dofastdith
|
|
191 ldb #$60
|
|
192 bsr dodither
|
|
193 bsr dofastdith
|
|
194 ldb #$40
|
|
195 bsr dodither
|
|
196 dec 3,s
|
|
197 bne dithloop1
|
|
198 rts
|
|
199
|
|
200 dithloop2
|
|
201 ldb #$20
|
|
202 bsr dodither
|
|
203 bsr dofastdith
|
|
204 ldb #$00
|
|
205 bsr dodither
|
|
206 bsr dofastdith
|
|
207 dec 3,s
|
|
208 bne dithloop2
|
|
209 rts
|
|
210
|
|
211 dithloop3
|
|
212 bsr dofastdith
|
|
213 ldb #$50
|
|
214 bsr dodither
|
|
215 bsr dofastdither
|
|
216 ldb #$70
|
|
217 bsr dodither
|
|
218 dec 3,s
|
|
219 bne dithloop3
|
|
220 rts
|
|
221
|
|
222 dithloop4
|
|
223 ldb #$10
|
|
224 bsr dodither
|
|
225 bsr dofastdith
|
|
226 ldb #$30
|
|
227 bsr dodither
|
|
228 bsr dofastdith
|
|
229 dec 3,s
|
|
230 bne dithloop4
|
|
231 rts
|
|
232
|
|
233 * Dither one pixel. Get GIF color from ,y and convert it into primary
|
|
234 * color iff B is above the threshold value.
|
|
235 dodither
|
|
236 pshs b
|
|
237 ldb ,y
|
|
238 clra
|
|
239 leax d,u
|
|
240 abx
|
|
241 abx
|
|
242 lda ,x Get primary color.
|
|
243 puls b
|
|
244 cmpb 2,x Are we above the threshold?
|
|
245 bhs dodither1
|
|
246 lda 1,x If not, choose secondary color.
|
|
247 dodither1
|
|
248 anda #$0f
|
|
249 sta ,y+ Store the color.
|
|
250 rts
|
|
251
|
|
252 * Since every other pixel is gauranteed to be a primary color, it seems
|
|
253 * worthwhile to have a faster version of the dither sub for that case.
|
|
254 dofastdith
|
|
255 ldb ,y
|
|
256 clra
|
|
257 leax d,u
|
|
258 abx
|
|
259 lda d,x Get primary color.
|
|
260 anda #$0f
|
|
261 sta ,y+ Store the color.
|
|
262 rts
|
|
263
|
|
264 convline
|
|
265 pshs a,b,x,y,u
|
|
266 lda <type
|
|
267 cmpa #8
|
|
268 bne conv4no
|
|
269 bsr conv4line Type 8 screen has 4 bits/pixel
|
|
270 bra conv10
|
|
271 conv4no
|
|
272 cmpa #7
|
|
273 beq conv2
|
|
274 cmpa #6
|
|
275 bne conv2no
|
|
276 conv2
|
|
277 bsr conv2line type 7,6 are 2 bits/pix
|
|
278 bra conv10
|
|
279 conv2no
|
|
280 bsr conv1line type 5 is 1 bit/pix
|
|
281 conv10
|
|
282 puls a,b,x,y,u,pc
|
|
283
|
|
284 conv4table fcb $00,$10,$20,$30,$40,$50,$60,$70,$80,$90,$a0,$b0,$c0,$d0,$e0,$f0
|
|
285 conv4line
|
|
286 leax linebuff,y
|
|
287 tfr x,u
|
|
288 leay conv4table,pcr
|
|
289 ldb #160
|
|
290 pshs b
|
|
291 conv4loop
|
|
292 lda ,x+
|
|
293 ldb ,x+
|
|
294 orb a,y
|
|
295 stb ,u+
|
|
296 dec ,s
|
|
297 bne conv4loop
|
|
298 puls b
|
|
299 rts
|
|
300
|
|
301 conv2table fcb $00,$40,$80,$c0,$00,$10,$20,$30,$00,$04,$08,$0c
|
|
302 conv2line
|
|
303 leax linebuff,y
|
|
304 tfr x,u
|
|
305 leay conv2table,pcr
|
|
306 ldd pixscrn
|
|
307 lsra
|
|
308 rorb
|
|
309 lsra
|
|
310 rorb
|
|
311 pshs b
|
|
312 conv2loop
|
|
313 lda ,x+
|
|
314 lda a,y Convert 1st pixel in byte.
|
|
315 ldb ,x+
|
|
316 addb #4
|
|
317 ora b,y
|
|
318 ldb ,x+
|
|
319 addb #8
|
|
320 ora b,y
|
|
321 ora ,x+
|
|
322 sta ,u+
|
|
323 dec ,s
|
|
324 bne conv2loop
|
|
325 puls b
|
|
326 rts
|
|
327
|
|
328 conv1line
|
|
329 leax linebuff,y
|
|
330 tfr x,u
|
|
331 ldy #80
|
|
332 conv1loop
|
|
333 ldb #$80
|
|
334 pshs b
|
|
335 clra
|
|
336 conv10loop
|
|
337 tst ,x+
|
|
338 beq conv11
|
|
339 ora ,s
|
|
340 conv11
|
|
341 ror ,s
|
|
342 bne conv10loop
|
|
343 puls b
|
|
344 sta ,u+
|
|
345 leay -1,y
|
|
346 bne conv1loop
|
|
347 rts
|
|
348
|
|
349 clrline
|
|
350 pshs a,b,x,y
|
|
351 leax linebuff,y
|
|
352 ldy pixscrn
|
|
353 clra
|
|
354 clrline1
|
|
355 sta ,x+
|
|
356 leay -1,y
|
|
357 bne clrline1
|
|
358 puls a,b,x,y,pc
|
|
359
|
|
360 nextline
|
|
361 pshs d,x,u
|
|
362 ldx lineinc
|
|
363 beq nextline9
|
|
364 ldd verscale
|
|
365 nextline1
|
|
366 tsta Actually, test sign of D
|
|
367 bmi nextline2
|
|
368 subd <gifiheight If it's positive, that's another screen line.
|
|
369 ldu linenumb
|
|
370 leau 1,u
|
|
371 stu linenumb
|
|
372 bra nextline1
|
|
373 nextline2
|
|
374 addd linemax
|
|
375 ldu linecount That's another gif line.
|
|
376 leau 1,u
|
|
377 stu linecount
|
|
378 leax -1,x
|
|
379 bne nextline1
|
|
380 std verscale
|
|
381 nextline9
|
|
382 puls d,x,u,pc
|
|
383
|
|
384 setline
|
|
385 pshs a,b,x
|
|
386 bsr nextline
|
|
387 ldd linecount
|
|
388 cmpd <gifiheight
|
|
389 blo setline5
|
|
390 andb #$7
|
|
391 beq setline3
|
|
392 ldd lineinc
|
|
393 lsrb
|
|
394 std lineinc
|
|
395 setline3
|
|
396 ldd #0
|
|
397 std linecount
|
|
398 std linenumb
|
|
399 std verscale
|
|
400 ldd lineinc
|
|
401 lsrb
|
|
402 clra
|
|
403 std lineinc Start off by moving 1/2 of the increment
|
|
404 bsr nextline
|
|
405 lslb
|
|
406 std lineinc Now, set the increment right.
|
|
407 setline5
|
|
408 puls a,b,x,pc
|
|
409
|
|
410 outline
|
|
411 pshs a,b,x
|
|
412 ldd linenumb
|
|
413 subd <Skiplines
|
|
414 bmi outline1
|
|
415 cmpd #192
|
|
416 bhs outline1
|
|
417 lbsr putline Put the line onto the screen
|
|
418 outline1
|
|
419 puls a,b,x,pc
|
|
420
|
|
421 endsect
|