103 register short * fbptr;
104 register struct fd_file * fbbuf =
106 register int fbx, fby, n;
108 int fbbufsize = (
sizeof buffer - 1024) /
sizeof(
short);
109 short word, long_data;
117 if ( fbbufsize > 2048 ) fbbufsize = 2048;
120 fprintf (stderr,
"getgmr: Couldn't read setup information\n");
127 SWAB( setup.h_xpos );
128 SWAB( setup.h_ypos );
129 SWAB( setup.h_xlen );
130 SWAB( setup.h_ylen );
137 bg_color = (
unsigned char *)
malloc( 1 + (setup.h_ncolors/2) * 2 );
138 bread( (
char *)bg_color, 1 + (setup.h_ncolors/2) * 2,
fd );
148 maplen = 1 << setup.h_cmaplen;
149 if ( maplen * setup.h_ncmap > (
sizeof buffer) )
152 "Color map too big (%d entries total), giving up\n",
153 maplen * setup.h_ncmap );
155 for ( i = 0; i < setup.h_ncmap; i++ )
157 bread((
char *)&
buffer[maplen*i],
sizeof(
short) * maplen,
fd);
158 for ( j = 0; j < 256; j++ )
169 for ( j = 0; j < 255; j++ )
178 short comlen, evenlen;
182 BREAD(
short, comlen,
sizeof comlen );
184 evenlen = (comlen + 1) & ~1;
185 comment_buf = (
char *)
malloc( (
unsigned) evenlen );
186 if ( comment_buf == NULL )
189 "getgmr: Malloc failed for comment buffer of size %d\n",
193 fread( comment_buf, 1, evenlen,
fd );
195 for ( i = 0, cp = comment_buf; cp < comment_buf + comlen; cp++ )
200 comments = (
char **)
malloc( (
unsigned)(i *
sizeof(
char *)) );
201 if ( comments == NULL )
204 "getgmr: Malloc failed for %d comment pointers\n",
209 *comments = comment_buf;
210 for ( i = 1, cp = comment_buf + 1; cp < comment_buf + comlen; cp++ )
211 if ( *(cp - 1) == 0 )
218 if ( setup.h_ncolors != 3 )
219 fprintf( stderr,
"%d color channels were saved.\n",
222 fprintf( stderr,
"Alpha channel was saved.\n" );
223 fprintf (stderr,
"Originally positioned at (%d, %d), size (%d %d)\n",
224 setup.h_xpos, setup.h_ypos, setup.h_xlen, setup.h_ylen);
226 fprintf( stderr,
"Screen will be cleared to " );
228 fprintf( stderr,
"Saved in overlay mode with original " );
230 fprintf( stderr,
"No background color was saved.\n" );
233 fprintf (stderr,
"background color" );
234 for ( i = 0; i < setup.h_ncolors; i++ )
235 fprintf( stderr,
" %d", bg_color[i] );
236 fprintf( stderr,
"\n" );
242 "%d channels of color map %d entries long were saved.\n",
243 setup.h_ncmap, 1 << setup.h_cmaplen );
248 fprintf( stderr,
"Comments:\n" );
249 for ( i = 0; comments[
i] != NULL; i++ )
250 fprintf( stderr,
"%s\n", comments[i] );
272 if (
getchan > setup.h_ncolors && setup.h_ncolors > 1 )
275 "Requested channel (%d) not in input file (%d channels)\n",
281 fprintf( stderr,
"getgmr: No alpha channel in input file\n" );
286 if ( putchan < 0 || putchan > 2 )
289 "getgmr: Requested output channel (%d) doesn't exist.\n",
293 if ( setup.h_ncolors == 1 &&
getchan > 0 )
299 fprintf (stderr,
"Originally positioned at (%d, %d)\n",
300 setup.h_xpos, setup.h_ypos);
303 setup.h_xpos = (
x + setup.h_xpos) & 0777;
304 setup.h_ypos = (
y + setup.h_ypos) & 0777;
308 setup.h_xpos =
x & 0777;
309 setup.h_ypos =
y & 0777;
323 Fdstart(fbbuf, fbbufsize, 0);
330 Frvput( 0, 511, 0, 511, bg_color[
getchan] );
333 if ( setup.h_ncolors >= 3 )
334 Fr3put(0, 511, 0, 511, bg_color[0], bg_color[1], bg_color[2]);
336 Fr3put(0, 511, 0, 511, bg_color[0], bg_color[0], bg_color[0]);
345 BREAD(
struct inst, inst, 2 );
346 if ( feof(
fd) )
break;
353 BREAD(
short, long_data,
sizeof long_data );
357 fprintf(stderr,
"Skip Lines %d\n", long_data);
363 fprintf(stderr,
"Skip Lines %d\n", inst.datum);
377 if (setup.h_ncolors == 1)
380 Fchn(1<<
DATUM(inst));
384 fprintf(stderr,
"Set Color %d\n", inst.datum);
390 BREAD(
short, long_data,
sizeof long_data );
394 fprintf(stderr,
"Skip Pixels %d\n", long_data);
400 fprintf(stderr,
"Skip Pixels %d\n",
DATUM(inst));
407 BREAD(
short, long_data,
sizeof long_data );
418 fprintf(stderr,
"Byte Data, length %d\n", n);
420 len = n <= 510 ? n : 510;
421 _Fdreserve( (len+1)/2 + 7 );
424 *fbptr++ =
LoadEA | (fbx & 0777);
426 *fbptr++ =
LoadLA | (fby & 0777);
430 bread((
char *)fbptr, (len+1) & ~1,
fd);
441 BREAD(
short, long_data,
sizeof long_data );
449 BREAD(
short, word,
sizeof(
short) );
453 *fbptr++ =
LoadEA | (fbx & 0777);
455 *fbptr++ =
LoadLA | (fby & 0777);
461 fprintf(stderr,
"Run, length %d, color %d\n", n+1, word);
468 fprintf(stderr,
"getgmr: Unrecognized opcode: %d\n",
OPCODE(inst));
#define BREAD(type, var, len)
#define SelectPeripheralDevice
#define LoadSubchannelMask
bread(char *ptr, unsigned size, FILE *iop)