/* TOHEX.C Written in BDS C ED GANGER 605 Laurel Ave Johnson City, TN 37601 (615)929-7053 This Program changes a file from .REL format to .HEX format See the L80 Reference Manual for details. */ #include /* ** link tags */ #define SPECIAL 0 #define ABSOLUTE 0 #define PROG_REL 1 #define DAT_REL 2 #define COMM_REL 3 /* ** subfields of SPECIAL */ /* ** These have a name field only */ #define ENTRY_SYM 0 #define SELECT_COM 1 #define PROGNAME 2 /* undefined 3 */ /* undefined 4 */ /* ** Value field and name field: */ #define COMM_SIZE 5 #define CHAIN_EXT 6 #define DEFINE_ENTRY 7 /* undefined 8 */ /* ** Value field only: */ #define EXT_PLUS_OFFS 9 #define DATA_SIZE 10 #define ORIGIN 11 #define CHAIN_ADDR 12 #define PROG_SIZE 13 #define END_MOD 14 /* ** No fields: */ #define ENDFILE 15 #define stderr 4 FILE infile,outfile; char inbyte,bitnum; char line[100]; int lineptr; int here; int cksum; /* ** grab next bit from file */ nextbit() { if (! bitnum ) { bitnum = 8; inbyte = getc(infile); } return ((inbyte >> --bitnum)&0x01); } /* ** grab next N bits from file and return packed into an integer */ bits(n) int n; { int bitval,i; bitval=0; for (i=0;i= 0x40) flshx(); } /* ** flush a bunch of bytes in INTEL HEX FORMAT */ flshx() { if (lineptr) { cksum += (lineptr >> 1); cksum += (here & 0xff); cksum += here >> 8; cksum = (-cksum) & 0xff; printf(":%02X%04X00%s%02X\n" ,lineptr >>1 ,here, line,cksum); fprintf(outfile,":%02X%04X00%s%02X\n" ,lineptr >>1 ,here, line,cksum); cksum = 0; here += lineptr >> 1; lineptr = 0; *line=0; } } /* ** print error message and abort */ error(string) char *string; { fprintf(stderr,"%s\n",string); exit(); } /* ** do special tag */ special() { int tag,i,j; char name[9]; int val; char *text; tag = bits(4); switch (tag){ case ENTRY_SYM: getname(name); printf("Entry = %s\n",name); return; case PROGNAME: getname(name); printf("Program is %s\n",name); return; case DEFINE_ENTRY: val = getval(); getname(name); printf ( "Entry of %s at %04X\n",name,val); return; case DATA_SIZE: val = getval(); printf ("Data Size: %04X\n",val); return; case ORIGIN: flshx(); here = getval(); printf ("NEW ORIGIN: %04X\n",here); return; case PROG_SIZE: val = getval(); printf ("Program Size: %04X\n",val); return; case END_MOD: printf("Module End ... Bye\n"); flshx(); fprintf(outfile,":00000000FF\n%c",CPMEOF); printf(":00000000FF\n%c",CPMEOF); fclose(outfile); exit(); } } /* ** get a name string */ getname(name) char *name; { int i,j; j=bits(3); if (!j) j=8; for (i=0;i