home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dspgroup / asms.arc / INTEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-08  |  1.5 KB  |  67 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <memory.h>
  4. #include <dos.h>
  5.  
  6. main(argc,argv)
  7. int argc;
  8. char *argv[];
  9. {
  10.     unsigned char line[81],bytes[80],far *byte,tmp, *strupr();
  11.     int addr,val,num,fh,type,i,seg320,io320,go;
  12.     FILE *fp;
  13.     if (argc>4) {
  14.         if ((fp = fopen(argv[1],"r")) == NULL) {
  15.             strcpy(line,argv[1]);
  16.             strcat(line,".hex");
  17.             puts(line);
  18.             if ((fp = fopen(line,"r")) == NULL) {
  19.                 fprintf(stderr,"%s couldn't find the file %s\n",argv[0],argv[1]);
  20.                 exit(1);
  21.             }
  22.         }
  23.         seg320=atoh(strupr(argv[2]),0,4);
  24.         io320=atoh(argv[3],0,3);
  25.         go=atoi(argv[4]);
  26.     }
  27.     else {
  28.         fprintf(stderr,"usage: intel filename(.hex) segment ioport go(0 or 1)\n");
  29.         exit(1);
  30.     }
  31.     inp(io320+7);
  32.     fh=fileno(fp);
  33.     byte = bytes;
  34.     while (1) {
  35.         fgets(line,80,fp);
  36.         num=atoh(line,1,2);
  37.         addr=atoh(line,3,4);
  38.         type=atoh(line,7,2);
  39.         if (type==0) {
  40.             for(i=0;i<num;i+=2) {
  41.                 bytes[i]=atoh(line,2*i+9,2);
  42.                 bytes[i+1]=atoh(line,2*i+11,2);
  43.                 tmp=bytes[i];
  44.                 bytes[i]=bytes[i+1];
  45.                 bytes[i+1]=tmp;
  46.             }
  47.             movedata(FP_SEG(byte),FP_OFF(byte),seg320,addr,(unsigned)num);
  48.         }
  49.         else break;
  50.     }
  51.     printf("\n segment=%x ioaddr=%x go=%x\n",(unsigned)seg320,io320,go);
  52.     if (go==1) inp(io320+6);
  53. }
  54.  
  55. int atoh(str,pos,len)
  56. unsigned char *str;
  57. int pos,len;
  58. {
  59.     int num,i;
  60.     num = 0;
  61.     for(i=0;i<len;i++) {
  62.         if (*(str+i+pos)<58) num += ((*(str+i+pos)-48)<<(4*(len-i-1)));
  63.         else num += ((*(str+i+pos)-55)<<(4*(len-i-1)));
  64.     }
  65.     return(num);
  66. }
  67.