[comp.sys.apple] Apple ][+ screen format pgm

LYMAN@IASSNS.BITNET (05/12/87)

If anyone is interested, here is the source (in C) for programs which
convert an Apple ][+ hi-res screen image (obtained via
BSAVE SCREEN,A$4000,L$2000) to SUN Microsystems raster format and
back.  I do not assume that most of you out there have SUN's, but the
code should be easy to generalize, and contains an algorithm for going
from Apple layout to a more usual memory map.

The programs work strictly in Black & White (that's the only kind of
monitor I own) but are not hard to generalize.  The application?  I
wanted to be able to make pictures for my Apple on a much more
powerful machine.

/* apl2sun.c - filter for going from Apple II images to SUN raster format */
/* usage apl2sun < {apple file} > {SUN raster file (B&W)} */
/* cc -O apl2sun.c -o apl2sun -lpixrect */

#include<pixrect/pixrect_hs.h>
#include<stdio.h>

#define WIDTH 280
#define HEIGHT 192
#define DEPTH 1
#define BLACK 1
#define NBITS 8192
#define TRUE 1

main()
{
  struct pixrect *cur_pixr;
  short int array[NBITS];
  register x=0,y=0,bit,i=0;
  int row, col, index, pass;

  while (EOF != (array[i++]=getchar()));

/* setup and clear pixrect */

  cur_pixr = mem_create(WIDTH,HEIGHT,DEPTH);

/* graph points */

  for (pass=0;pass<8;pass++)   /* 8 banks of 1024 bytes */
    {
      for (row=0;row<24;row++)  /* 24 rows (0,24...,1,25...) */
        {
          for (col=0;col<40;col++) /* 40 * 7 pixels accross page */
            {
              index = 1024*pass + 128*(row%8) + 40 * (row/8) + col;
              y = row * 8 + pass;
              for (bit=0;bit<7;bit++) /* 7 bits for each word */
                {
                  x = col * 7 + bit;
                  if ((1 << bit) & array[index])
                    pr_put(cur_pixr,x,y,BLACK);
                }
            }
        }
    }
  pr_dump(cur_pixr,stdout,NULL,RT_STANDARD,TRUE); /* dump image */
}

/* sun2apl.c - filter for going from Apple II images to SUN raster format */
/* usage sun2apl < {apple file} > {SUN raster file (B&W)} */
/* cc -O sun2apl.c -o sun2apl -lpixrect */

#include<pixrect/pixrect_hs.h>
#include<stdio.h>

#define WIDTH 280
#define HEIGHT 192
#define DEPTH 1
#define BLACK 1
#define NBITS 8192
#define TRUE 1
#define MASK 128

main()
{
  struct pixrect *cur_pixr,*pr_load();
  short int array[NBITS];
  register x=0,y=0,bit,i=0;
  int row, col, index, pass;

  /* open raster file */

  cur_pixr = pr_load(stdin,NULL);
  if (cur_pixr == NULL)
    {
      printf("Unable to open raster file.\n");
      exit(1);
    }
/* graph points */

  for (pass=0;pass<8;pass++)   /* 8 banks of 1024 bytes */
    {
      for (row=0;row<24;row++)  /* 24 rows (0,24...,1,25...) */
        {
          for (col=0;col<40;col++) /* 40 * 7 pixels accross page */
            {
              index = 1024*pass + 128*(row%8) + 40 * (row/8) + col;
              y = row * 8 + pass;
              for (bit=0;bit<7;bit++) /* 7 bits for each word */
                {
                  x = col * 7 + bit;
                  if (pr_get(cur_pixr,x,y))
                    array[index] |= MASK + (1 << bit);
                }
            }
        }
    }
  for (i=0;i<NBITS;i++) putchar(array[i]);
}