
#define MOVE(a,b,c) a->cp_x=b;a->cp_y=c 
#define SETDRMD(a,b) a->DrawMode=b

struct NewScreen MyScreen =
{0,0,320,200,2,0,0,0,CUSTOMSCREEN,0,0,0};
struct Screen *screen = 0;
struct RastPort *rp;
struct ViewPort *vp;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
ULONG  *DosBase;
UBYTE *picbuffer;
USHORT colors[] = {0x000,0xf00,0x00f,0xfff};
 long farbe[4];
struct FileHandle *c64_bild;

#asm
       public _key

_key   moveq #0,d0
       move.b $bfec01,d0
       rts
#endasm

main(argc,argv)
int argc;
char *argv[];
{
 register long i,j,k,x,y;
 register UBYTE *data,b;
 long farbe[4];

  if(argc < 3) {
                printf("Nanana...    das war wohl nichts !!!\n");
                printf("%s [64'er Bild] [Amiga.IFF Bild]\n",argv[0]); 

                goto ende;
	       }
  if(!(DosBase = (ULONG *)
      OpenLibrary("dos.library",0L))) goto ende;
  if(!(c64_bild = Open(argv[1],MODE_OLDFILE))) {
                printf("64'er Datei %s kann nicht geöffnet werden\n",argv[1]);
                goto ende;
               }   
  if(!(picbuffer = (UBYTE *)AllocMem(8002L,MEMF_PUBLIC))) goto ende;
  data = (UBYTE *)picbuffer+2;
  Read(c64_bild,picbuffer,8002L);
  Close(c64_bild);

  if(!(IntuitionBase = (struct IntuitionBase *)
      OpenLibrary("intuition.library",0L))) goto ende;
  if(!(GfxBase = (struct GfxBase *)
      OpenLibrary("graphics.library",0L))) goto ende;     
  if(!(screen = (struct Screen *)OpenScreen(&MyScreen))) goto ende;
  rp    = (struct RastPort *) &screen->RastPort;
  vp    = (struct ViewPort *) &screen->ViewPort;
  LoadRGB4(vp,&colors[0],4L);
 
  j=0;y=0;x=0;
  for(i=0;i<8000;i++)
     {
      b = (UBYTE )(*(data+i));
      farbe[0]= (b>>6);
      farbe[1]= ((b>>4) & 3);
      farbe[2]= ((b>>2) & 3);
      farbe[3]= (b & 3);
      
      for(k=0;k<4;k++){ SetAPen(rp,farbe[k]);
                        WritePixel(rp,x+2*k,j+y);
  			WritePixel(rp,x+1+2*k,j+y);
                      } 
      y = y+1; if(y > 7) {
			   y = 0;
			   x = x + 8;
			   if (x > 312) { x = 0; j = j+8; }
		          }
    }
     if(!(SaveIff(screen,argv[2]))) 
      printf("Amiga IFF File %s konnte nicht geschrieben werden\n",argv[2]);
ende:
      
     if (picbuffer)                FreeMem(picbuffer,8002L);
     if (screen)                   CloseScreen(screen);
     if (IntuitionBase)            CloseLibrary(IntuitionBase);
     if (GfxBase)                  CloseLibrary(GfxBase);
     if (DosBase)                  CloseLibrary(DosBase);
}

