home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- /*
- * sputoppm.c - Reads an uncompressed Spectrum file on stdin and
- * writes a portable pixmap (ppm) file on stdout.
- *
- * Copyright (C) 1990, Steve Belczyk
- */
-
- /* Remove the following definition if you don't want raw ppm files */
- #define RAWBITS
-
- int pal[200][48]; /* Spectrum palettes, three per row */
- short screen[16000]; /* Simulates the Atari's video RAM */
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- int x, y;
-
- /* Check for bogus arguments */
- if (argc > 1)
- {
- fprintf (stderr, "usage: %s <spufile >ppmfile\n",
- argv[0]);
- exit (-1);
- }
-
- /* Read the SPU file */
- ReadSPU();
-
- /* Write PPM header */
- #ifdef RAWBITS
- printf ("P6\n320 200\n255\n"); /* Magic, resolution, max pixel */
- #else
- printf ("P3\n320 200\n255\n");
- #endif
-
- /* Convert and write */
- for (y=0; y<200; y++)
- {
- for (x=0; x<320; x++)
- {
- DoPixel (x, y);
- }
- }
- }
-
- ReadSPU ()
- {
- int i, j;
-
- /* Read the screen data */
- for (i=0; i<16000; i++)
- {
- screen[i] = GetWord();
- }
-
- /* Read the palettes */
- for (i=1; i<200; i++)
- {
- for (j=0; j<48; j++)
- {
- pal[i][j] = GetWord();
- }
- }
-
- /* Clear the first palette line */
- for (i=0; i<48; pal[0][i++]=0);
- }
-
- int GetWord()
- {
- int w;
-
- w = (0xff & getchar()) << 8;
- w |= 0xff & getchar();
-
- return (w);
- }
-
- DoPixel (x, y)
- int x, y;
- {
- int c, x1;
-
- c = GetPixel (x, y);
-
- /* Compute palette index */
- x1 = 10 * c;
-
- if (1 & c)
- {
- x1 -= 5;
- }
- else
- {
- x1++;
- }
-
- if ( (x >= x1) && (x < (x1+160)) ) c += 16;
- if (x >= (x1+160)) c += 32;
-
- /* Write the proper color */
- DoColor (pal[y][c]);
- }
-
- DoColor (p)
- int p;
- {
- int r, g, b;
-
- r = (0x700 & p) >> 3;
- g = (0x070 & p) << 1;
- b = (0x007 & p) << 5;
-
- #ifdef RAWBITS
- putchar (0xff & r);
- putchar (0xff & g);
- putchar (0xff & b);
- #else
- printf ("%d %d %d\n", r, g, b);
- #endif
- }
-
- int GetPixel (x, y)
- int x, y;
- {
- int c, index, bit, plane;
-
- c = 0;
-
- /* index = (80*y) + 4*(x/16); */
- index = (y << 6) + (y << 4) + ((x >> 4) << 2);
-
- /* bit = 0x8000 >> (x % 16); */
- bit = 0x8000 >> (x & 0x0f);
-
- for (plane=0; plane<4; plane++)
- {
- if (bit & screen[index+plane])
- {
- c |= (1 << plane);
- }
- }
- return (c);
- }
-
-