home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 468.lha / Scrub / scrub.c < prev    next >
C/C++ Source or Header  |  1991-02-08  |  3KB  |  122 lines

  1. /* SCRUB -- a program to spin the motor on an Amiga floppy drive and move the
  2. head back and forth for thirty seconds while a disk cleaner is inserted in
  3. it.  It searches for the lowest numbered drive that has a non-Dos disk in it,
  4. and that's the one it spins.
  5.  
  6. 11/21/90 made it move the head to more different cylinders starting from one
  7. of ten random first cylinders, and recompiled with aztec 5.0 instead of 3.6
  8.  
  9. 12/24/90  oops!  made it notice if you remove the disk in the middle
  10. */
  11.  
  12.  
  13. #include <devices/trackdisk.h>
  14. #include <libraries/dosextens.h>
  15. #include <Paul.h>
  16.  
  17.  
  18. #undef put
  19.  
  20. void put(s) register str s;
  21. {
  22.     register BPTR o = Output();
  23.     if (o) Write(o, s, (long) strlen(s));
  24. }
  25.  
  26.  
  27.  
  28. long _main()
  29. {
  30.     int drive;
  31.     static char dame[] = "df#:";
  32.     struct InfoData *fo = New(struct InfoData);
  33.     struct Process *me = ThisProcess();
  34.     struct MsgPort *p;
  35.     APTR e = me->pr_WindowPtr;
  36.     struct Message *wbs = null;
  37.     void Clean();
  38.  
  39.     if (!me->pr_CLI) {
  40.     WaitPort(&me->pr_MsgPort);
  41.     wbs = GetMsg(&me->pr_MsgPort);
  42.     }
  43.     me->pr_WindowPtr = (APTR) -1;
  44.     if (!fo)
  45.     put("No memory!\n");
  46.     else {
  47.     for (drive = 0; drive <= 3; drive++) {
  48.         dame[2] = drive + '0';
  49.         if ((p = DeviceProc(dame)) &&
  50.             dos_packet(p, ACTION_DISK_INFO, (long) fo >> 2) &&
  51.             fo->id_DiskType == ID_UNREADABLE_DISK) {
  52.         Clean((long) drive);
  53.         break;
  54.         }
  55.     }
  56.     if (drive > 3)
  57.         put("Couldn't find a drive with a cleaner in it.\n");
  58.     Free(struct InfoData, fo);
  59.     }
  60.     me->pr_WindowPtr = e;
  61.     if (wbs) {
  62.     Forbid();
  63.     ReplyMsg(wbs);
  64.     }
  65.     return (0L);
  66. }
  67.  
  68.  
  69.  
  70. #define DIVISIONS 30
  71. #define WEIRDNESS 22
  72.  
  73. void Clean(unit) long unit;
  74. {
  75.     struct DateStamp date_with_rosie_palm;
  76.     struct IOExtTD *qxt = NewPZ(struct IOExtTD);
  77.     short track, trax, tout;
  78.     ulong changes;
  79. #define qr qxt->iotd_Req
  80. #define q ((struct IORequest *) qxt)
  81.  
  82.     if (!q) {
  83.     put("Out of memory!");
  84.     return;
  85.     }
  86.     qr.io_Message.mn_ReplyPort = &ThisProcess()->pr_MsgPort;
  87.     if (OpenDevice(TD_NAME, unit, q, TDF_ALLOW_NON_3_5)) {
  88.     put("Couldn't open device!\n");
  89.     Free(struct IOExtTD, q);
  90.     return;
  91.     }
  92.     qr.io_Command = TD_GETNUMTRACKS;
  93.     DoIO(q);
  94.     trax = qr.io_Actual;
  95.     qr.io_Command = TD_CHANGENUM;
  96.     DoIO(q);
  97.     changes = qr.io_Actual;
  98.     qr.io_Command = TD_MOTOR;
  99.     qr.io_Length = 1;            /* ON */
  100.     DoIO(q);
  101.     DateStamp(&date_with_rosie_palm);
  102.     track = (date_with_rosie_palm.ds_Tick / TICKS_PER_SECOND) % 10;
  103.     qr.io_Command = ETD_SEEK;
  104.     qxt->iotd_Count = changes;
  105.     for (tout = 0; tout < DIVISIONS; tout++) {
  106.     qr.io_Offset = track * (NUMSECS << TD_SECSHIFT);
  107.     DoIO(q);
  108.     if (qr.io_Error == TDERR_DiskChanged) {
  109.         put("You popped the disk out!\n");
  110.         break;
  111.     }
  112.     Delay(1500L / DIVISIONS);
  113.     track = (track + WEIRDNESS) % trax;
  114.     }
  115.     DoIO(q);
  116.     qr.io_Command = TD_MOTOR;
  117.     qr.io_Length = 0;            /* OFF */
  118.     DoIO(q);
  119.     CloseDevice(q);
  120.     Free(struct IOExtTD, q);
  121. }
  122.