home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtrsutl.zip / DUMPCMD.C < prev    next >
C/C++ Source or Header  |  1992-12-31  |  4KB  |  154 lines

  1. /* 
  2.     8/4/92
  3.     
  4.     This program will dump a TRS-80 Disk BASIC program to the screen.
  5.     To be used with xtrs1.0
  6.  
  7.     By Abel M. Hernandez  amh@hp835.mitek.com
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <dos.h>
  13. #include <io.h>
  14. #include <fcntl.h>
  15. #include <sys\types.h>
  16. #include <sys\stat.h>
  17.  
  18. int fptr;
  19. unsigned char buffer[256];
  20. char filename[20];      /* source file */
  21. char mod_file[20];      /* destination file */
  22. char cas_fname[10];     /* storage for cassette filename */
  23.  
  24. unsigned char blk_size, lsb, msb, blk_type;
  25. int addr;
  26.  
  27. main(argc, argv)
  28. int argc;
  29. char *argv[];
  30.     {
  31.     int i;
  32.     
  33.     if (argc < 2)
  34.         usage();
  35.     else
  36.         strcpy (filename,argv[1]);
  37.  
  38.     mkupper(filename);
  39.     
  40.     strcat (filename,".CMD");
  41.  
  42.     fptr = open(filename, O_RDONLY+O_BINARY);   /* open for read binary */
  43.  
  44.     if ( fptr == -1 )
  45.         {
  46.         printf("\nError! Opening %s \n",filename);
  47.         usage();
  48.         }
  49.  
  50. loop:
  51.     read(fptr,buffer,1);        /* get block type */
  52.     blk_type=buffer[0];
  53.  
  54.     printf("Block type=0x%02X   ----- ",blk_type);
  55.  
  56.     if (blk_type == 0x01)       /* block type = data? */
  57.         {
  58.         get_blk();              /* get a block of data */
  59.         goto loop;
  60.         }
  61.     else if (blk_type != 0x02)  /* block type = entry point? */
  62.         {
  63.         printf("\nText Block: ");
  64.         read(fptr,buffer,1);        /* get block size */
  65.         blk_size = buffer[0];
  66.         for (i=0; i<blk_size; i++)
  67.             {
  68.             read(fptr,buffer,1);
  69.             printf("%c",buffer[0]);
  70.             }
  71.         printf("\n");
  72.         goto loop;
  73.         }
  74.  
  75.     read(fptr,buffer,1);        /* read pass the block size */
  76.  
  77.     read(fptr,buffer,1);        /* get entry point address */
  78.     lsb  = buffer[0];
  79.     
  80.     read(fptr,buffer,1);
  81.     msb  = buffer[0];
  82.  
  83.     addr = msb*256+lsb;
  84.     
  85.     printf("Entry point=0x%04X\n",addr);
  86.  
  87.     close(fptr);
  88.  
  89.     }
  90.  
  91. /****************************************************************************/
  92.  
  93. get_blk()
  94.     {
  95.     int bytes_rd, i;
  96.     unsigned char chksum;
  97.  
  98.     read(fptr,buffer,1);        /* get block size */
  99.     blk_size=buffer[0];
  100.     printf("Block size=0x%02X\n",blk_size);
  101.  
  102.     read(fptr,buffer,1);        /* get destination address */
  103.     lsb  = buffer[0];
  104.     chksum = lsb;
  105.  
  106.     read(fptr,buffer,1);
  107.     msb  = buffer[0];
  108.     chksum += msb;
  109.     
  110.     addr = msb*256+lsb;
  111.     blk_size -= 3;
  112.     
  113.     printf("Dest addr =0x%04X ----- ",addr);
  114.  
  115.     bytes_rd = read(fptr,buffer,blk_size+1);        /* read in blk_size of data */
  116.     printf("Bytes read=0x%02X\n",bytes_rd);
  117.  
  118.     for (i=0; i<bytes_rd; i++)      /* calculate the checksum */
  119.         chksum += buffer[i];
  120.     printf("Cal CkSum =0x%02X\n",chksum);
  121.         
  122.     }
  123.  
  124. /****************************************************************************/
  125.  
  126. mkupper(string)
  127. char *string;
  128.     {
  129.     int i;
  130.  
  131.     i = strlen(string);
  132.     while(i--)
  133.         {
  134.         *string = toupper(*string);
  135.         string++;
  136.         }
  137.     }
  138.  
  139. /****************************************************************************/
  140.  
  141. usage()
  142.     {
  143.     printf("\nTRS-80 Disk object program displayer\n");
  144.     printf("\nUsage: dumpcmd <filename>\n");
  145.     printf("\nWhere <fileaname> is a TRS-80 Disk object program without\n");
  146.     printf("      an extension. The extension CMD is assumed.\n");
  147.     printf("\nThis program will display a TRS-80 disk object (machine\n");
  148.     printf("language) program on the screen.\n");
  149.     printf("\nby Abel M. Hernandez 8/4/92 amh@hp835.mitek.com.\n");
  150.     exit(1);
  151.     }
  152.  
  153.  
  154.