1188
|
1 /*
|
|
2 * gifwin.c - window functions for ViewGIF 2.0
|
|
3 * by Vaughn Cato
|
|
4 */
|
|
5
|
|
6 #include "viewgif.h"
|
|
7
|
|
8 char *mapgpb();
|
|
9 extern int errno;
|
|
10
|
|
11 checksig()
|
|
12 {
|
|
13 char buf[6];
|
|
14
|
|
15 fread(buf, sizeof(*buf), 6, infile);
|
|
16 if (strncmp(buf, "GIF", 3) != 0)
|
|
17 fatal("file is not a GIF file");
|
|
18 if (strncmp(&buf[3], "87a", 3) != 0)
|
|
19 fatal("Unknown GIF version number");
|
|
20 }
|
|
21
|
|
22 perror(str)
|
|
23 char *str;
|
|
24 {
|
|
25 fprintf(stderr, "%s: error\n", str);
|
|
26 }
|
|
27
|
|
28 error(str, errnum)
|
|
29 char *str;
|
|
30 int errnum;
|
|
31 {
|
|
32 fprintf(stderr, "viewgif: %s\n", str);
|
|
33 exit(errnum);
|
|
34 }
|
|
35
|
|
36 sleep(ticks)
|
|
37 int ticks;
|
|
38 {
|
|
39 #asm
|
|
40 ldx 4,s
|
|
41 os9 F$Sleep
|
|
42 #endasm
|
|
43 }
|
|
44
|
|
45 static char *ustext[] = {
|
|
46 "OS9 ViewGIF 2.0 by Vaughn Cato\n",
|
|
47 "usage: viewgif <filename> [-<option> ...]\n",
|
|
48 " displays a gif picture\n",
|
|
49 "\n",
|
|
50 " options:\n",
|
|
51 " -d[[=]dfactor] Set dithering factor, default is 0\n",
|
|
52 " -a Align to pixels\n",
|
|
53 " -u[=]<filename> Create/use a color usage file\n",
|
|
54 " -m[=]<magfact> Set magnification factor (1-64)\n",
|
|
55 " -x[=]<start x> Set start x (0-64)\n",
|
|
56 " -y[=]<start y> Set start y (0-64)\n",
|
|
57 " -v[[=]<filename>] Generate vef format picture\n",
|
|
58 " -g grey scale picture (average color brite)\n",
|
|
59 " -g2 grey scale picture (max color brite)\n",
|
|
60 " -g3 grey scale picture (NTSC color brite)\n",
|
|
61 " -r Use random generator instead of table\n",
|
|
62 " -s Silent. No info printed\n",
|
|
63 " -i Extended information\n",
|
|
64 " -n No display\n",
|
|
65 " -p[[=]seconds] Pause time (default 0)\n",
|
|
66 " -c Use current screen\n",
|
|
67 " -f Disable flicker\n",
|
|
68 " -b[=]<britefact> Set brightness (1-16)\n",
|
|
69 " -z Zap unused global color map entries\n",
|
|
70 NULL
|
|
71 };
|
|
72
|
|
73 usage()
|
|
74 {
|
|
75 register char **uscan;
|
|
76
|
|
77 for (uscan = ustext; *uscan != NULL; uscan++)
|
|
78 fputs(*uscan, stderr);
|
|
79 exit(1);
|
|
80 }
|
|
81
|
|
82 initwin(firstscreen, oldpath)
|
|
83 bool firstscreen;
|
|
84 int oldpath;
|
|
85 {
|
|
86 register bool newwin;
|
|
87
|
|
88 newwin = (oldpath == -1);
|
|
89
|
|
90 if (newwin) {
|
|
91 if (!newscrn && firstscreen) {
|
|
92 /* just use stdout */
|
|
93 actwin = oldpath = 1;
|
|
94 dwend();
|
|
95 } else if ((actwin = oldpath = open("/w", 3)) == -1)
|
|
96 exit(errno);
|
|
97 } else {
|
|
98 actwin = oldpath;
|
|
99 dwend();
|
|
100 }
|
|
101
|
|
102 dwset(gmode ? 7 : 8, 0, 0, gmode ? 80 : 40, 24, 0, 0, 0);
|
|
103 curoff();
|
|
104 select();
|
|
105 flushwin();
|
|
106
|
|
107 if (newwin && firstscreen) {
|
|
108 groupnum = getpid();
|
|
109 bufnum = 1;
|
|
110 getblk(groupnum, bufnum, 0, 0, 640, 1);
|
|
111 flushwin();
|
|
112 if ((gpbufptr = mapgpb(actwin, groupnum, bufnum, 1)) == NULL)
|
|
113 exit(errno);
|
|
114 }
|
|
115
|
|
116 return actwin;
|
|
117 }
|
|
118
|
|
119 dwset(sty, cpx, cpy, szx, szy, prn1, prn2, prn3)
|
|
120 int sty, cpx, cpy, szx, szy, prn1, prn2, prn3;
|
|
121 {
|
|
122 static char outstr[] = {
|
|
123 0x1b, 0x20, 0, 0, 0, 0, 0, 0, 0, 0
|
|
124 };
|
|
125 int size;
|
|
126
|
|
127 outstr[2] = sty;
|
|
128 outstr[3] = cpx;
|
|
129 outstr[4] = cpy;
|
|
130 outstr[5] = szx;
|
|
131 outstr[6] = szy;
|
|
132 if (sty > 0 && sty <= 8) {
|
|
133 outstr[7] = prn1;
|
|
134 outstr[8] = prn2;
|
|
135 outstr[9] = prn3;
|
|
136 size = sizeof(outstr);
|
|
137 } else
|
|
138 size = sizeof(outstr) - 3;
|
|
139 writemem(outstr, size);
|
|
140 }
|
|
141
|
|
142 dwend()
|
|
143 {
|
|
144 static char outstr[] = {0x1b, 0x24};
|
|
145
|
|
146 writemem(outstr, sizeof(outstr));
|
|
147 }
|
|
148
|
|
149 select()
|
|
150 {
|
|
151 static char outstr[] = {0x1b, 0x21};
|
|
152
|
|
153 writemem(outstr, sizeof(outstr));
|
|
154 }
|
|
155
|
|
156 bell()
|
|
157 {
|
|
158 char c = 7;
|
|
159 writemem(&c, 1);
|
|
160 }
|
|
161
|
|
162 palette(prn, ctn)
|
|
163 {
|
|
164 static char outstr[] = {0x1b, 0x31, 0, 0};
|
|
165
|
|
166 outstr[2] = prn;
|
|
167 outstr[3] = ctn;
|
|
168 writemem(outstr, sizeof(outstr));
|
|
169 }
|
|
170
|
|
171 point(x, y)
|
|
172 int x, y;
|
|
173 {
|
|
174 static char outstr[] = {0x1b, 0x42, 0, 0, 0, 0};
|
|
175
|
|
176 *(int *) &outstr[2] = x;
|
|
177 *(int *) &outstr[4] = y;
|
|
178 writemem(outstr, sizeof(outstr));
|
|
179 }
|
|
180
|
|
181 lineto(x, y)
|
|
182 int x, y;
|
|
183 {
|
|
184 static char outstr[] = {0x1b, 0x46, 0, 0, 0, 0};
|
|
185
|
|
186 *(int *) &outstr[2] = x;
|
|
187 *(int *) &outstr[4] = y;
|
|
188 writemem(outstr, sizeof(outstr));
|
|
189 }
|
|
190
|
|
191 fcolor(c)
|
|
192 int c;
|
|
193 {
|
|
194 static char outstr[] = {0x1b, 0x32, 0};
|
|
195
|
|
196 outstr[2] = c;
|
|
197 writemem(outstr, sizeof(outstr));
|
|
198 }
|
|
199
|
|
200 border(c)
|
|
201 int c;
|
|
202 {
|
|
203 static char outstr[] = {0x1b, 0x34, 0};
|
|
204
|
|
205 outstr[2] = c;
|
|
206 writemem(outstr, sizeof(outstr));
|
|
207 }
|
|
208
|
|
209 SetDPtr(x, y)
|
|
210 int x, y;
|
|
211 {
|
|
212 static char outstr[] = {0x1b, 0x40, 0, 0, 0, 0};
|
|
213
|
|
214 *(int *) &outstr[2] = x;
|
|
215 *(int *) &outstr[4] = y;
|
|
216 writemem(outstr, sizeof(outstr));
|
|
217 }
|
|
218
|
|
219 curoff()
|
|
220 {
|
|
221 static char outstr[] = {0x05, 0x20};
|
|
222
|
|
223 writemem(outstr, sizeof(outstr));
|
|
224 }
|
|
225
|
|
226 getblk(grp, bfn, cpx, cpy, szx, szy)
|
|
227 int grp, bfn, cpx, cpy, szx, szy;
|
|
228 {
|
|
229 static char outstr[] = {0x1b, 0x2c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
230
|
|
231 outstr[2] = grp;
|
|
232 outstr[3] = bfn;
|
|
233 *(int *) (&outstr[4]) = cpx;
|
|
234 *(int *) (&outstr[6]) = cpy;
|
|
235 *(int *) (&outstr[8]) = szx;
|
|
236 *(int *) (&outstr[10]) = szy;
|
|
237 writemem(outstr, sizeof(outstr));
|
|
238 }
|
|
239
|
|
240 putblk(grp, bfn, cpx, cpy)
|
|
241 int grp, bfn, cpx, cpy;
|
|
242 {
|
|
243 static char outstr[] = {0x1b, 0x2d, 0, 0, 0, 0, 0, 0};
|
|
244
|
|
245 outstr[2] = grp;
|
|
246 outstr[3] = bfn;
|
|
247 *(int *) (&outstr[4]) = cpx;
|
|
248 *(int *) (&outstr[6]) = cpy;
|
|
249 writemem(outstr, sizeof(outstr));
|
|
250 }
|
|
251
|
|
252 killbuf(grp, bfn)
|
|
253 int grp, bfn;
|
|
254 {
|
|
255 static char outstr[] = {0x1b, 0x2a, 0, 0};
|
|
256
|
|
257 outstr[2] = grp;
|
|
258 outstr[3] = bfn;
|
|
259 writemem(outstr, sizeof(outstr));
|
|
260 }
|
|
261
|
|
262 char *
|
|
263 mapgpb(path, grp, bfn, action)
|
|
264 int path, grp, bfn, action;
|
|
265 {
|
|
266 #asm
|
|
267 lda 7,s group
|
|
268 ldb 9,s buffer
|
|
269 tfr d,x ->X
|
|
270 lda 5,s path
|
|
271 ldb #$SS.MpGPB setstat code
|
|
272 pshs y
|
|
273 ldy 10+2,s action (1 => map, 0 => unmap)
|
|
274 os9 I$SetStt
|
|
275 puls y
|
|
276 bcc _mapgpb1
|
|
277 clra error--
|
|
278 std errno,y save error code,
|
|
279 ldx #0 return NULL pointer
|
|
280 _mapgpb1: tfr x,d move pointer into position for return
|
|
281 #endasm
|
|
282 }
|
|
283
|
|
284 static char outbuf[256];
|
|
285 static DIRECT char *outptr = outbuf;
|
|
286 static DIRECT int bufleft = sizeof(outbuf);
|
|
287
|
|
288 writemem(str, size)
|
|
289 register char *str;
|
|
290 register int size;
|
|
291 {
|
|
292 while (size > bufleft) {
|
|
293 size -= bufleft;
|
|
294 while (--bufleft >= 0)
|
|
295 *outptr++ = *str++;
|
|
296 flushwin();
|
|
297 }
|
|
298 bufleft -= size;
|
|
299 while (--size >= 0)
|
|
300 *outptr++ = *str++;
|
|
301 }
|
|
302
|
|
303 flushwin()
|
|
304 {
|
|
305 write(actwin, outbuf, outptr - outbuf);
|
|
306 outptr = outbuf;
|
|
307 bufleft = sizeof(outbuf);
|
|
308 }
|