home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / diskutil / tapebios / tapetest.c < prev    next >
C/C++ Source or Header  |  1993-08-06  |  6KB  |  233 lines

  1. /* Test to exercise the TAPEBIOS.TOS program         */
  2. /* This program is part of the TapeBIOS distribution    */
  3. /* Adapted by Alan Hourihane, from code by P. Moreau    */
  4. /* Needs TapeBIOS driver loaded                */
  5.  
  6. #include<stdio.h>
  7. #include<osbind.h>
  8. #include"tapebind.h"
  9.  
  10. extern long get_cookie();
  11. extern void exit();
  12. extern int Mode_Sense();
  13. extern int RSense();
  14. extern void bclear();
  15.  
  16. #define BBLKS 254L
  17. #define BBLKW 254
  18. #define HBLKS 127L
  19. #define HBLKW 127
  20. #define BSIZE BBLKS*512L
  21. #define HSIZE HBLKS*512L
  22.  
  23. /* 3.5 megs for disc/tape io test */
  24. #define IOTS BBLKW * 30
  25.  
  26. int
  27. main()
  28. {
  29.     int i, blk, stat;
  30.     long x;                 /* Long index and GP */
  31.     char *buffer;
  32.     char *ptr;
  33.  
  34.     printf("Tape Test Program for TapeBIOS. Copyright 1992, A. Hourihane.\r\n");
  35.  
  36.     if (!get_cookie("TAPE")) {
  37.         printf("TapeBIOS is not installed.\r\n");
  38.         exit(1);
  39.     }
  40.  
  41.     buffer = (char*)Malloc(BSIZE);
  42.     if(!buffer)
  43.     {
  44.         printf("Malloc error allocating %ld byte buffer\r\n", BSIZE);
  45.         exit(1);
  46.     }
  47.  
  48.     printf("Test Unit Ready\r\n");
  49.     stat = Tready();
  50.     if(stat)
  51.     {
  52.        printf("\tTape drive is Not ready\r\n");
  53.        goto bye;
  54.     }
  55.  
  56.     printf("Load Tape\r\n");
  57.     stat = Tload(0L);            /* Load tape NO RETENSION */
  58.     if (stat) goto bye;
  59.  
  60.     printf("Mode Sense\r\n");
  61.     stat = Mode_Sense();            /* Mode Sense */
  62.  
  63.     printf("Creating data buffer patterns\r\n");
  64.     for(ptr = buffer, x = 0L; x < BSIZE; x++) *ptr++ = (char)(x);
  65.     
  66.     printf("Write Tape\r\n");
  67.     stat = Twrite(buffer, BBLKS);        /* Write 64 512 byte blocks */
  68.     if(stat) goto bye;
  69.     
  70.     printf("Write Filemark\r\n");
  71.     stat = Tfmark(2L);            /* Write 2 filemarks */
  72.     if(stat) goto bye;
  73.     
  74.     printf("Rewind Tape\r\n");
  75.     stat = Trewind();            /* Rewind tape */
  76.     if(stat) goto bye;
  77.     
  78.     printf("Clearing data buffer\r\n");
  79.     bclear(buffer, BSIZE);
  80.     
  81.     printf("Read Tape\r\n");
  82.     stat = Tread(buffer, BBLKS);        /* Read 64 512 byte blocks */
  83.     if(stat) goto bye;
  84.     
  85.     printf("Rewind Tape\r\n");
  86.     stat = Trewind();            /* Rewind Tape */
  87.     if(stat) goto bye;
  88.     
  89.     printf("Checking data buffer\r\n");
  90.     for(ptr = buffer, x = 0L; x < BSIZE; x++, ptr++)
  91.     {
  92.         if(*ptr != (char)(x))
  93.         printf("\r\nData error offset %lx, was %02x, sb %02x",
  94.             x, (unsigned int)(*ptr), (int)(x));
  95.     }
  96.     
  97.     printf("Disk - Tape I/O test\r\n");
  98.  
  99.     for(blk = 0; blk < IOTS; blk += BBLKW)
  100.     {
  101.         i = Rwabs(0, buffer, BBLKW, blk, 2);    /* Read Hard Disk */
  102.         if(i)
  103.         {
  104.         printf("\r\n\tDisk IO error 0x%02x reading block %d\r\n", i, blk);
  105.         goto bye;
  106.         }
  107.         stat = Twrite(buffer, BBLKS);    /* Write 1 Tape block */
  108.         if(stat)
  109.         {
  110.         printf("\r\n\tTape IO error 0x%02x writing block %d\r\n", stat, blk);
  111.         if(stat == 2)            /* Check Condition ? */
  112.         {
  113.             printf("\tCheck Condition\r\n");
  114.             stat = RSense();    /* Request Sense if Check */
  115.         }
  116.         }
  117.         printf("Blocks transfered %d\r\n\033A", blk);
  118.     }
  119.     
  120.     printf("\r\nWrite Filemark\r\n");
  121.     stat = Tfmark(2L);            /* Write 2 file marks */
  122.     if(stat) goto bye;
  123.     
  124.     printf("Rewind Tape\r\n");
  125.     stat = Trewind();            /* Rewind Tape */
  126.     if(stat) goto bye;
  127.     
  128.     /*  Read data from disc and tape and compare data */
  129.     
  130.     for(blk = 0; blk < IOTS; blk += HBLKW)
  131.     {
  132.         i = Rwabs(0, buffer, HBLKW, blk, 2);    /* Read Hard Disk */
  133.         if(i)
  134.         {
  135.         printf("\r\n\tDisk IO error 0x%02x reading block %d\r\n", i, blk);
  136.         goto bye;
  137.         }
  138.         stat = Tread(&buffer[HSIZE], HBLKS);    /* Write Tape drive */
  139.         if(stat)
  140.         {
  141.         printf("\r\n\tTape IO error 0x%02x reading block %d\r\n", stat, blk);
  142.         if(stat == 2)            /* Check Condition ? */
  143.         {
  144.             printf("\tCheck Condition\r\n");
  145.             stat = RSense();    /* Request Sense if Check */
  146.         }
  147.         }
  148.         
  149.         for(x = 0L; x < HSIZE; x++)
  150.         {
  151.            if(buffer[x] != buffer[x+HSIZE])
  152.            {
  153.            printf("\r\n\033pData Error!\033q\7\r\n");
  154.            x = HSIZE+1L;
  155.            }
  156.         }
  157.         printf("Blocks verified %d\r\n\033A", blk);
  158.     } 
  159.     printf("\r\nTest Completed.\r\n");
  160. bye:
  161.     if (stat == 0x02)            /* Check Condition */
  162.     {
  163.         printf("\tCheck Condition\n");
  164.         stat = RSense();
  165.     }
  166.     else if(stat) 
  167.     {
  168.         printf("\tExit with Error - Tape status = %02x\r\n");
  169.         printf("\tCheck Programmers manual.\r\n");
  170.     }
  171.     
  172.     printf("Unload Tape\r\n");
  173.     stat = Tunload(0L);            /* Unload tape NO RETENSION */
  174.  
  175.     printf("Hit [RETURN] when ready ... ");
  176.     i = getc(stdin);    
  177.  
  178.     return 0;
  179. }
  180.  
  181. int RSense()
  182. {
  183.     int stat, i;
  184.     char sense[512];
  185.     
  186.     bclear(&sense[0], 32L);
  187.     stat = Trsense(&sense[0], 64L);
  188.     printf("\tSense Data: ");
  189.     for(i = 0; i < 11; i++) printf(" %02x", (int)(sense[i]) & 0xFF);
  190.     printf("\r\n");
  191.     return(stat);
  192. }
  193.  
  194. int Mode_Sense()
  195. {
  196.     int stat;
  197.     long x;
  198.     char buffer[512];
  199.  
  200.     bclear(&buffer[0], 13L);
  201.     stat = Tmsense(&buffer[0], 255L);    /* Display Mode Sense */
  202.     if(stat) return(stat);
  203.     printf("    Media Type         : %02x\r\n", (int)(buffer[1]) & 0xFF);
  204.     printf("    Write Protect     : %s\r\n", (buffer[2] & 0x80) ? "On" : "Off");
  205.     printf("    Buffered Mode     : %s\r\n", (buffer[2] & 0x10) ? "On" : "Off");
  206.     printf("    Speed         : %d\r\n", (int)(buffer[2] & 3));
  207.     printf("    Density Code     : %02x\r\n", (int)(buffer[4]));
  208.     x = ((long)(buffer[5]) & 0xff) << 16;
  209.     x |= ((long)(buffer[6]) & 0xff) << 8;
  210.     x |= ((long)(buffer[7]) & 0xff);
  211.     printf("    Number of Blocks     : %ld\r\n", x);
  212.     x = ((buffer[9] & 0xff) << 16);
  213.     x |= ((buffer[10] & 0xff) << 8);
  214.     x |= ((buffer[11]) & 0xff);
  215.     printf("    Block Size         : %ld\r\n", x);
  216.     printf("    Disable Erase Ahead  : %s\r\n", (buffer[12] & 4) ? "On" : "Off");
  217.     printf("    Auto Inhibit     : %s\r\n", (buffer[12] & 2) ? "On" : "Off");
  218.     printf("    Soft Error Count     : %s\r\n", (buffer[12] & 1) ? "Supressed" : "Enabled");
  219.     return(stat);
  220. }
  221.  
  222. void
  223. bclear(p, cnt)
  224. char *p;
  225. long cnt;
  226. {
  227.     long x;
  228.  
  229.     for(x = 0L; x < cnt; x++)
  230.     *p++ = 0;
  231. }
  232.  
  233.