1706
|
1 ********************************************************************************
|
|
2 *
|
|
3 * SUBS for IMG picture formats
|
|
4 *
|
|
5 * IMGshowpic -- displays picture on screen
|
|
6 *
|
|
7 ********************************************************************************
|
|
8
|
|
9 check macro
|
|
10 pshs b,cc This macro will print "ERROR #xxx", where xxx is the
|
|
11 ldb #\1 . number given as an argument. Very useful for
|
|
12 os9 F$PErr . checkpointing, to make sure certain routines are
|
|
13 puls b,cc . executed. Printed to StdErr path.
|
|
14 endm
|
|
15
|
|
16 ifp1
|
|
17 use /dd/defs/os9defs.a
|
|
18 endc
|
|
19
|
|
20 StdOut equ 1
|
|
21 StdErr equ 2
|
|
22
|
|
23 psect view_img_a,0,0,0,0,0
|
|
24
|
|
25 vsect dp
|
|
26 nscreens rmb 1 Number of screens in this picture.
|
|
27 endsect
|
|
28
|
|
29 IMGshowpic:
|
|
30 bsr header
|
|
31 *lbsr setscreen Unlike some formats, these are handled by "header".
|
|
32 *lbsr setpals
|
|
33 lbsr setbuffer
|
|
34
|
|
35 spscreens
|
|
36 lbsr flipscreen Select next screen
|
|
37 ldd <Skiplines First, skip any lines.
|
|
38 beq skip01
|
|
39 skip00
|
|
40 lbsr getline
|
|
41 subd #1
|
|
42 bne skip00
|
|
43 skip01
|
|
44
|
|
45 ldd #00
|
|
46 ldx #25
|
|
47 showpicloop
|
|
48 lbsr getline
|
|
49
|
|
50 tst <Size If we're displaying a "small" pic, skip every 25th line.
|
|
51 bne showpic2
|
|
52 leax -1,x
|
|
53 bne showpic2
|
|
54 ldx #25
|
|
55 bra spnoput
|
|
56 showpic2
|
|
57
|
|
58 lbsr putline
|
|
59 addd #1
|
|
60 spnoput
|
|
61 cmpd #192
|
|
62 bne showpicloop
|
|
63 spfinish
|
|
64 lbsr getline Read rest of this screen.
|
|
65 tst <endofpic
|
|
66 beq spfinish
|
|
67 clr <endofpic Clear for next screen.
|
|
68 spendscreen
|
|
69 dec nscreens Any more?
|
|
70 bne spscreens Yes, get it.
|
|
71 rts
|
|
72
|
|
73 *
|
|
74 * read header info from file, and set window type information
|
|
75 * Uses altbuff.
|
|
76 *
|
|
77 vsect dp
|
|
78 count rmb 1 Count/value is used for compressed packets
|
|
79 value rmb 1
|
|
80 straight rmb 1 Number of straight bytes.
|
|
81 compressed fcb $ff T=we're in a compressed block.
|
|
82 endoffile rmb 1 T= EOF reached, so always return linebuff all 0
|
|
83 endofpic rmb 1 T= end-of-picture seen.
|
|
84 zeroflag rmb 1 T= We've seen one zero.. another will be end-of-pic
|
|
85 endsect
|
|
86
|
|
87 header
|
|
88 pshs a,b,x,y,u
|
|
89
|
|
90 * Set default Skiplines.
|
|
91 ldd <Skiplines
|
|
92 cmpd #$ffff
|
|
93 bne headskip
|
|
94 ldd #0
|
|
95 std <Skiplines
|
|
96 headskip
|
|
97
|
|
98 * Set default Size
|
|
99 lda <Size
|
|
100 bpl headsize
|
|
101 lda #1
|
|
102 sta <Size
|
|
103 headsize
|
|
104
|
|
105 * Cancel any color cycling or rotation
|
|
106 lda <cyclestart one-palette cycle is effectively none
|
|
107 sta <cycleend
|
|
108 clr <extranum no colors to rotate.
|
|
109
|
|
110 * Now, read in header
|
|
111 leax altbuff,y read in type and palettes
|
|
112 pshs y
|
|
113 ldy #18 Number of bytes in header.
|
|
114 lbsr I_Read
|
|
115 lbcs _error
|
|
116 puls y
|
|
117 leax altbuff,y
|
|
118 lda ,x+ This byte contains RGB/CMP bit and other useless info.
|
|
119
|
|
120 lda ,x+ This specifies the picture format and palettes to be used.
|
|
121
|
|
122 cmpa #0 Dithered grey
|
|
123 bne header0
|
|
124 lda #7
|
|
125 sta <type
|
|
126 lbsr setscreen
|
|
127 lda #1
|
|
128 sta nscreens
|
|
129 lda #3
|
|
130 lbsr setborder
|
|
131 leax greypals,pcr
|
|
132 lbsr headpals
|
|
133 bra headend
|
|
134 header0
|
|
135
|
|
136 cmpa #1 false 16-color
|
|
137 bne header1
|
|
138 lda #8
|
|
139 sta <type
|
|
140 lbsr setscreen
|
|
141 lda #1
|
|
142 sta nscreens
|
|
143 lda #15
|
|
144 lbsr setborder
|
|
145 lbsr headpals Use palettes in header
|
|
146 bra headend
|
|
147 header1
|
|
148
|
|
149 cmpa #2 Solid grey
|
|
150 bne header2
|
|
151 leax greypals,pcr Set pals to grey palettes.
|
|
152 lda #7 Use type 7 screen
|
|
153 sta <type
|
|
154 lbsr setscreen Set it.
|
|
155 lda #1
|
|
156 sta nscreens Only one screen for this format.
|
|
157 lda #3
|
|
158 lbsr setborder
|
|
159 lbsr headpals
|
|
160 bra headend
|
|
161 header2
|
|
162
|
|
163 cmpa #3
|
|
164 bne header3
|
|
165 lda #7
|
|
166 sta <type
|
|
167 lda #3
|
|
168 sta nscreens
|
|
169 lda #$ff
|
|
170 sta <flipping Turn on flipping.
|
|
171 lbsr setscreen Set up red screen
|
|
172 lda #3
|
|
173 lbsr setborder
|
|
174 leax redpals,pcr
|
|
175 lbsr headpals
|
|
176 lbsr setscreen Set up green screen
|
|
177 lbsr setborder
|
|
178 leax greenpals,pcr
|
|
179 lbsr headpals
|
|
180 lbsr setscreen Set up blue screen
|
|
181 lbsr setborder
|
|
182 leax bluepals,pcr
|
|
183 lbsr headpals
|
|
184 bra headend
|
|
185 header3
|
|
186
|
|
187 lbsr E$Format Illegal file format.
|
|
188
|
|
189
|
|
190 headend
|
|
191 puls a,b,x,y,u,pc
|
|
192
|
|
193 headpals
|
|
194 pshs a,b,x,u Set the palettes.
|
|
195 leau palette,y
|
|
196 ldb #16
|
|
197 headloop
|
|
198 lda ,x+
|
|
199 sta ,u+
|
|
200 decb
|
|
201 bne headloop
|
|
202 lbsr setpals
|
|
203 puls a,b,x,u,pc
|
|
204
|
|
205 greypals fcb $3f,$38,$07,$00 Only first four palettes matter here.
|
|
206 redpals fcb $24,$20,$04,$00
|
|
207 greenpals fcb $12,$10,$02,$00
|
|
208 bluepals fcb $09,$08,$01,$00
|
|
209
|
|
210 *
|
|
211 * Getline
|
|
212 *
|
|
213 getline
|
|
214 pshs a,b,x,y,u
|
|
215 leau linebuff,y First, clear out line buffer to $ff, the background pattern.
|
|
216 ldx #160
|
|
217 lda #$ff Since palette 3 is the background, use this for fill pattern.
|
|
218 getl1
|
|
219 sta ,u+
|
|
220 leax -1,x
|
|
221 bne getl1
|
|
222
|
|
223 tst endoffile Are we at end-of-file?
|
|
224 lbne getline1 Yes, just leave buffer of zeros
|
|
225 tst endofpic
|
|
226 lbne getline1
|
|
227
|
|
228 * Get a line from file
|
|
229 leau linebuff,y Where we'll put the line.
|
|
230 ldx #160 Number of bytes in one line.
|
|
231 * Check if we're in a compressed or uncompressed packet.
|
|
232 tst count Did we reach the end of the line in a compressed packet?
|
|
233 bne uncompress Yes, finish uncompressing
|
|
234 tst straight Did we reach it in a straight packet?
|
|
235 bne copystraight Yes, finish the packet.
|
|
236 tst compressed Did we just finish a straight packet?
|
|
237 beq getcomp Yes, we're just starting a compressed one.
|
|
238 * Get a straight packet
|
|
239 getstraight
|
|
240 clr compressed Mark that we're in a straight packet
|
|
241 lbsr I_GetByte
|
|
242 bcs geteof
|
|
243 sta straight
|
|
244 bne copystraight non-zero count, handle it.
|
|
245 tst zeroflag
|
|
246 bne geteop If already one zero, set endofpic
|
|
247 com zeroflag Otherwise, set zeroflag.
|
|
248 bra getcomp If zero, next type of packet.
|
|
249 * Read in straight data
|
|
250 copystraight
|
|
251 clr zeroflag
|
|
252 ldb straight Get number of bytes
|
|
253 getstr1
|
|
254 lbsr I_GetByte Get the next byte
|
|
255 bcs geteof
|
|
256 sta ,u+ Store the byte.
|
|
257 decb Count down number of reps
|
|
258 leax -1,x Count down size of line
|
|
259 beq getstr2 If end of line, finish.
|
|
260 tstb
|
|
261 bne getstr1
|
|
262 stb straight
|
|
263 bra getcomp Get a compressed packet.
|
|
264 getstr2
|
|
265 stb straight Hit end of line, store remaining count.
|
|
266 bra getline1
|
|
267 * Get a compressed packet
|
|
268 getcomp
|
|
269 com compressed Mark that we're in a compressed packet
|
|
270 lbsr I_GetByte
|
|
271 bcs geteof
|
|
272 sta count
|
|
273 bne getcomp1
|
|
274 tst zeroflag
|
|
275 bne geteop If already one zero, set endofpic
|
|
276 com zeroflag Otherwise, set zeroflag.
|
|
277 bra getstraight If zero, next type of packet.
|
|
278 getcomp1
|
|
279 lbsr I_GetByte
|
|
280 bcs geteof
|
|
281 sta value
|
|
282 * Expand compressed data
|
|
283 uncompress
|
|
284 clr zeroflag
|
|
285 ldd count Get count/value
|
|
286 getunc1
|
|
287 stb ,u+ Store a copy of current value
|
|
288 deca Count down number of reps
|
|
289 leax -1,x Count down size of line
|
|
290 beq getunc2 If end of line, finish.
|
|
291 tsta
|
|
292 bne getunc1
|
|
293 std count
|
|
294 bra getstraight Get a straight packet.
|
|
295 getunc2
|
|
296 std count Otherwise, store remaining count.
|
|
297 bra getline1
|
|
298
|
|
299 geteop
|
|
300 lda #$ff
|
|
301 sta endofpic Mark end of picture.
|
|
302 sta compressed
|
|
303 clr straight
|
|
304 clr count
|
|
305 clr zeroflag Clear zeroflag.
|
|
306 bra getline1
|
|
307 geteof
|
|
308 cmpb #E$EOF
|
|
309 lbne _error
|
|
310 lda #$ff
|
|
311 sta endoffile endoffile is also endofpic
|
|
312 sta endofpic
|
|
313 getline1
|
|
314 puls a,b,x,y,u,pc
|
|
315
|
|
316
|
|
317 endsect
|