/* ******************************************************************

Programma ......... XBoot.c
Versione .......... 1.0I - Giugno 1989
Autore ............ Francois Rouaix
Scopo ............. Conversione bootblock in file eseguibile
Hardware .......... Amiga 512K + Kickstart V1.2/V1.3
Software .......... Lattice C (V5.02) o Aztec C (V3.6a)
Sintassi .......... Xboot fileinput fileoutput (solo da CLI)
Note .............. Traduzione ed adattamento per EAD di L.Callegari

****************************************************************** */

#include <libraries/dos.h>
#include <stdio.h>

#ifdef LATTICE
#include <proto/dos.h>
#else
#include <functions.h>
#endif

char buffer[1024];

long header[12] = { 0x000003f3,   /* Hunk_Header */
                    0x00000000,   /* nessun hunk_name */
                    0x00000002,   /* dimensione hunk_table */
                    0x00000000,   /* primo hunk */
                    0x00000001,   /* ultimo hunk */
                    0x000000fd,   /* dimensione hunk 0 */
                    0x00000003,   /* dimensione hunk 1 */
                    0x000003e9,   /* hunk_code */
                    0x000000fd,   /* dimensione hunk_code = 253 /*
                    /* fine header */
		    
                    0x000003ea,   /* hunk_data */
                    0x00000003,   /* dimensione */
                    /* fine header */
                    0x000003f2
                  } ;

void main( argc, argv )
int argc; char *argv[];
{
   struct FileHandle *infile=0,*outfile=0 ;
   int b = 0;

   if ( argc != 3 ) 
      {
      printf("Uso: %s infile outfile \n",argv[0]);
      Exit( 10 );
      }
      
   if (!(infile = (struct FileHandle *)Open(argv[1],MODE_OLDFILE)))
      {
      printf("Non si apre %s\n",argv[1]);
      Exit( 10 );
      }
      
   if (!(outfile = (struct FileHandle *)Open(argv[2],MODE_NEWFILE)))
      {
      Close( infile );
      printf("Non si apre %s\n",argv[2]);
      Exit( 10 );
      }
      
   b = Read( infile, &buffer[0], 1024 );
   if ( b != 1024 )  printf("Attenzione, file errato!\n");
   Close( infile );


   Write(outfile,(char *)&header[0],4*9);      /* header */
   Write(outfile,(char *)&buffer[12],4*253);   /* codice */
   Write(outfile,(char *)&header[11],4);       /* hunk_end */
   Write(outfile,(char *)&header[9],4*2);      /* header dati */
   Write(outfile,(char *)&buffer[0],4*3);      /* dati */
   Write(outfile,(char *)&header[11],4);       /* hunk_end */

   Close(outfile);
}

