home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-2 / LOAD.C < prev    next >
Text File  |  2000-06-30  |  2KB  |  96 lines

  1. /*
  2.     LOAD.C        written by Leo Kenen (I think --LZ)
  3.  
  4.     Works like the standard CP/M LOAD.COM utility, except it's
  5.     written in C.
  6. */
  7.  
  8. #include "bdscio.h"
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char **argv;
  13. {
  14.         char buf[BUFSIZ], obuf[BUFSIZ];
  15.         int     lfd, ofd;
  16.         char    name[20], oname[20];
  17.  
  18.         if (!(--argc))
  19.         {
  20.                 printf("Useage:load <filename>");
  21.                 exit();
  22.         }
  23.         strcpy(name,argv[1]);
  24.         lfd = fopen(name,buf);
  25.         if (lfd == ERROR)
  26.         {
  27.                 strcat(name,".HEX");
  28.                 lfd = fopen(name,buf);
  29.                 if (lfd == ERROR)
  30.                 {
  31.                         printf("File not found.\n");
  32.                         exit();
  33.                 }
  34.         }
  35.         /* Open the output file */
  36.         strcpy(oname,argv[1]);
  37.         strip(oname);
  38.         strcat(oname,".OBJ");
  39.         ofd = fcreat(oname,obuf);
  40.         if (ofd == ERROR)
  41.         {
  42.                 printf("Can not create output file");
  43.                 exit();
  44.         }
  45.         load(buf,obuf); /* DO the load operation to fname.obj */
  46.         fflush(obuf);
  47.         fclose(buf);
  48.         fclose(obuf);
  49. }
  50.  
  51. load(fb,ofb)
  52. char fb[], ofb[];
  53. {
  54.         unsigned  address;
  55.         int       bytes, chksum, count, foo;
  56.         char      ch;
  57.  
  58.         while((ch=getc(fb)) != ':' );
  59.         while((bytes=rdhex(fb)) != 0 )
  60.         {
  61.                 address = rdword(fb);
  62.                 foo = rdhex(fb);
  63.                 for (count=1;count<=bytes;count++) putc(rdhex(fb),ofb);
  64.                 foo = rdhex(fb);
  65.                 while((ch=getc(fb)) != ':');
  66.         }
  67. }
  68.  
  69. rdhex(fbuf)
  70. char fbuf[];
  71. {
  72.         char first, second;
  73.  
  74.         if (ishex(first=getc(fbuf)) && ishex(second=getc(fbuf)))
  75.         return((tohex(first)*16)+tohex(second));
  76.         else { printf("\nBad hex digit, error.\n");
  77.                exit();
  78.              }
  79. }
  80.  
  81. rdword(fb)
  82. char fb[];
  83. {
  84.         return((rdhex(fb)<<8)+rdhex(fb));
  85. }
  86.  
  87. /* Remove anything after a . from a file name */
  88.  
  89.  
  90. strip(s)
  91. char *s;
  92. {
  93.         while ((*s != '.') && (*s))  *s++;
  94.         *s = '\0';
  95. }
  96.