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