Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <exec/types.h>
  2. #include <exec/devices.h>
  3. #include <exec/io.h>
  4. #include <exec/memory.h>
  5. #include <exec/ports.h>
  6.  
  7. #include <devices/timer.h>
  8.  
  9. #include <proto/exec.h>
  10. #include <proto/timer.h>
  11. #include <proto/dos.h>
  12. #include <proto/intuition.h>
  13. #include <proto/expansion.h>
  14.  
  15. #include <clib/timer_protos.h>
  16. #include <clib/exec_protos.h>
  17.  
  18. #include <devices/scsidisk.h>
  19. #include <dos/dosextens.h>
  20.  
  21. #include <math.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <stdbool.h>
  25. #include <string.h>
  26.  
  27. struct Device* TimerBase;
  28. static struct IORequest timereq;
  29.  
  30. bool DoDevIO(struct IOStdReq *ior, LONG cmd, ULONG off, ULONG len, WORD *data)
  31. {
  32.     ior->io_Command = cmd;
  33.     ior->io_Offset = off;
  34.     ior->io_Length = len;
  35.     ior->io_Data   =  data;
  36.     DoIO(ior);
  37.     bool result = ior->io_Error == 0L;
  38.  
  39.     if (!result)
  40.     {                                                                                                                                                      
  41.         printf("DoDevIO() ERROR!!! io_Error= %ld\r\n", ior->io_Error);
  42.     }
  43.  
  44.     return result;
  45. }
  46.  
  47. long DevCmd(struct IOStdReq *ior, LONG cmd, LONG len)
  48. {
  49.     ior->io_Command = cmd;
  50.     ior->io_Offset = 0L;
  51.     ior->io_Length = len;
  52.     ior->io_Data   =  0L;
  53.     ior->io_Actual = 0L;
  54.  
  55.     DoIO(ior);
  56.  
  57.     return ior->io_Actual;
  58. }
  59.  
  60. static ULONG timer()
  61. {
  62.   struct timeval a;
  63.   GetSysTime(&a);
  64.  
  65.   return a.tv_secs*1000 + a.tv_micro/1000;
  66. }
  67.  
  68. #define STRIDE 16
  69.  
  70. void printbuffer(UBYTE *data, int len)
  71. {
  72.     int count = 0;
  73.     char row[STRIDE+1];
  74.     row[STRIDE] = 0;
  75.  
  76.     while (count < len)
  77.     {
  78.         for (int i =0; i < STRIDE; i++)
  79.         {
  80.             UBYTE v = data[count+i];
  81.             row[i] = (v < 32) || (v > 128) ? '.' : (char) v;
  82.             printf("%02x", v);
  83.         }
  84.         count += STRIDE;        
  85.         printf("%s\r\n", row);
  86.     }
  87. }
  88.  
  89. #define KB 1024
  90. #define MB KB*KB
  91. #define BUFSIZE 128*KB
  92. #define MEGS_TO_READ 100
  93.    
  94. int main (int argc, char ** argv)
  95. {
  96.     struct MsgPort *MsgPort;
  97.     struct IOStdReq SCSIReq;        /* a standard IORequest structure */
  98.     struct SCSICmd  Cmd;             /* where the actual SCSI command goes */
  99.    
  100.     char *deviceName = "scsi.device";
  101.     int unit = 0;
  102.  
  103.     printf("TF Dumbass Drive Speed Tool\n");
  104.     printf("(C) 2019 S.J Leary\n");
  105.  
  106.     printf(" - opening the device\n");
  107.     if (OpenDevice(deviceName, unit, &SCSIReq, 0))
  108.     {
  109.         printf("Couldn't open unit %ld on %s\n",unit, deviceName);
  110.         exit(100);
  111.     }
  112.  
  113.     printf(" - allocating the buffer\n");
  114.     UWORD *buffer = (UWORD *) AllocMem(BUFSIZE, MEMF_PUBLIC|MEMF_CLEAR);  
  115.          
  116.     printf(" - initializing the timer\n");
  117.     OpenDevice(TIMERNAME, UNIT_MICROHZ, &timereq, 0);
  118.     TimerBase = timereq.io_Device;  
  119.  
  120.     DevCmd(&SCSIReq, CMD_START, 0 );
  121.  
  122.    
  123.     printf(" - Reading %iMb of data... ", MEGS_TO_READ);
  124.     ULONG startTime = timer();
  125.  
  126.     //Disable();
  127.  
  128.     // bloody thing locks up
  129.     for (int i = 0; i < 100; i++)
  130.     {
  131.         printf("Reading a sector %i... ", i);
  132.         if (DoDevIO(&SCSIReq, CMD_READ, i*512, 1024, buffer))
  133.         {
  134.             printf("Done.\r\n");
  135.             printbuffer((UWORD*)buffer, 512);
  136.         }
  137.     }
  138.  
  139.    
  140.  
  141.     //Enable();
  142.    
  143.     ULONG endTime = timer();
  144.     printf("Done.\n");
  145.  
  146.     DevCmd(&SCSIReq, CMD_STOP, 0 );
  147.  
  148.     double timeTaken = ((double) endTime - (double) startTime) / 1000.0;
  149.     printf("Total time taken in seconds: %2.2f\n", timeTaken);
  150.  
  151.     double readRate = (double) MEGS_TO_READ / timeTaken;
  152.     printf("Read data rate is: %2.2fMb/sec\n", readRate);
  153.  
  154.     CloseDevice( &timereq );
  155.  
  156.     CloseDevice( &SCSIReq );
  157.     FreeMem(buffer, BUFSIZE);
  158.  
  159.     return 0;
  160. }