home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / DiskHandler / disk.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  6KB  |  192 lines

  1. /* Disk.c - Disk support routines */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  5. /* |. o.| || This program may not be distributed without the permission of   */
  6. /* | .  | || the author.                                           BBS:      */
  7. /* | o  | ||   John Toebes    Dave Baker                     (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include "handler.h"
  13. #define PHYSSIZE 512
  14. extern void  DskChngIntA(); /* Assem disk change interrupt server routine */ 
  15.  
  16.  
  17. void RemDskChngInt(global)
  18. GLOBAL global;
  19. {
  20.    BUG(("RemChngInt\n"));
  21.    if (global->dskchngpkt != NULL)
  22.       {
  23.       /* now remove the disk change interrupt */
  24.       global->devreq->iotd_Req.io_Command = TD_REMCHANGEINT;
  25. BUG(("devreq Rmsgprt: %08lx\n",global->devreq->iotd_Req.io_Message.mn_ReplyPort))
  26. BUG(("dskchngR msgprt: %08lx\n",global->dskchngpkt->dc_req.iotd_Req.io_Message.mn_ReplyPort));
  27. BUG(("task msgprt: %08lx\n",global->port));
  28. BUG(("devmsg msgprt: %08lx\n",global->devport));
  29.       DoIO((struct IORequest *)global->devreq);
  30.      
  31. BUG(("DoIO end\n"));
  32.       DeleteExtIO((struct IORequest *)global->dskchngpkt);
  33.    }
  34. BUG(("RemChngInt Exit\n"));
  35. }
  36.  
  37. void DskChngInt(global)
  38. GLOBAL global;
  39. {
  40.    BUG(("Disk Change Interrupt Called\n"));
  41.    BUG(("DskChng devname:%s\n",global->devname));
  42.    global->changedisk = 1;
  43. }
  44.  
  45. int AddDskChngInt(global)
  46. GLOBAL global;    
  47. {
  48.  
  49.    /* assumes that a msg port has been allocated */   
  50.    if (((global->dskchngpkt) = (struct DskChngPacket *)
  51.       CreateExtIO(global->port, sizeof(struct DskChngPacket)))== NULL)
  52.       return(NULL);
  53.  
  54.    /* Copy the Device and Unit pointers from OpenDevice */
  55.    global->dskchngpkt->dc_req.iotd_Req.io_Device =
  56.                        global->devreq->iotd_Req.io_Device;
  57.    global->dskchngpkt->dc_req.iotd_Req.io_Unit =
  58.                        global->devreq->iotd_Req.io_Unit;
  59.    global->dskchngpkt->dc_req.iotd_Req.io_Flags = 0;
  60.  
  61.    BUG(("Reply port %08lx vs %08lx\n", 
  62.          global->dskchngpkt->dc_req.iotd_Req.io_Message.mn_ReplyPort,
  63.          global->port));
  64.    global->dskchngpkt->dc_req.iotd_Req.io_Command = TD_ADDCHANGEINT;
  65.    global->dskchngpkt->dc_req.iotd_Req.io_Data    = 
  66.                 (APTR)&(global->dskchngpkt->dc_int);     
  67.  
  68.    /* Initialize the interrupt structure */
  69.    global->dskchngpkt->dc_int.is_Node.ln_Type = NT_INTERRUPT;
  70.    global->dskchngpkt->dc_int.is_Node.ln_Pri  = 0;
  71.    global->dskchngpkt->dc_int.is_Node.ln_Name = "DskChngInt";
  72.    global->dskchngpkt->dc_int.is_Data         = (APTR)global;
  73.    global->dskchngpkt->dc_int.is_Code         = DskChngIntA;
  74.      
  75.    /* Async IO so we don't sleep here for the msg */
  76.    SendIO((struct IORequest *)&global->dskchngpkt->dc_req);
  77.  
  78.    return(1);
  79.     
  80. }
  81.  
  82. int ReadPhy(global, block, key)
  83. GLOBAL global;
  84. char *block;
  85. KEY key;
  86. {
  87.    BUG(("ReadPhy Block:%08lx Key:%ld\n",block,key));
  88.  
  89.    /* Make sure the disk is there! */
  90.    if (global->diskstatus == ID_NO_DISK_PRESENT)
  91.       demanddisk(global);
  92.  
  93.    Motor(global,1);
  94.  
  95.    global->deviotimeout = 2;
  96.    global->devreq->iotd_Req.io_Length = PHYSSIZE;
  97.    global->devreq->iotd_Req.io_Data   = (APTR)block;
  98.  
  99.    /* show where to put the data when read */
  100.    global->devreq->iotd_Req.io_Command = ETD_READ;
  101.  
  102.    /* check that disk not changed before reading */
  103.    global->devreq->iotd_Count = global->DiskChange;
  104.  
  105.    global->devreq->iotd_Req.io_Offset = TD_SECTOR * key;
  106.    DoIO((struct IORequest *)global->devreq);
  107.  
  108.    return((int)global->devreq->iotd_Req.io_Error);
  109. }
  110.  
  111. int WritePhy(global, block, key)
  112. GLOBAL global;
  113. char  *block;
  114. KEY key;
  115. {
  116.    BUG(("WritePhy Block:%08lx Key:%ld\n",block,key));
  117.  
  118.    /* make sure the disk is there */
  119.    if (global->diskstatus == ID_NO_DISK_PRESENT)
  120.       demanddisk(global);
  121.  
  122.    Motor(global,1);
  123.    global->deviotimeout = 2;
  124.    global->devreq->iotd_Req.io_Length = PHYSSIZE;
  125.    global->devreq->iotd_Req.io_Data   = (APTR)block;
  126.  
  127.    /* show where to put the data when read */
  128.    global->devreq->iotd_Req.io_Command = ETD_WRITE;
  129.  
  130.    /* check that disk not changed before reading */
  131.    global->devreq->iotd_Count = global->DiskChange;
  132.  
  133.    global->devreq->iotd_Req.io_Offset = TD_SECTOR * key;
  134.    DoIO((struct IORequest *)global->devreq);
  135.  
  136.    return((int)global->devreq->iotd_Req.io_Error);
  137. }
  138.  
  139. int Motor(global,flag)
  140. GLOBAL global;
  141. int flag;
  142. {
  143.    /* TURN ON DISK MOTOR ... old motor state is returned in io_Actual */
  144.    global->devreq->iotd_Req.io_Length = flag;
  145.  
  146.    /* this says motor is to be turned on */
  147.    global->devreq->iotd_Req.io_Command = TD_MOTOR;
  148.  
  149.    /* do something with the motor */
  150.    DoIO((struct IORequest *)global->devreq);
  151.    return((int)global->devreq->iotd_Req.io_Error);
  152. }
  153.  
  154. /* Reset the drive for a new disk and return the protection status of it */
  155. int ResetDrive(global)
  156. GLOBAL global;
  157. {
  158.    /* now get the disk change value */
  159.    global->devreq->iotd_Req.io_Command = TD_CHANGESTATE;
  160.    DoIO((struct IORequest *)global->devreq);
  161.    if (global->devreq->iotd_Req.io_Actual)
  162.       {
  163.       BUG(("Pretending no disk in drive\n"));
  164.       global->diskstatus = ID_NO_DISK_PRESENT;
  165.       return(-1);
  166.       }
  167.  
  168.    global->diskstatus = ID_NOT_REALLY_DOS;
  169.  
  170.    global->devreq->iotd_Req.io_Command = TD_CHANGENUM;
  171.    DoIO((struct IORequest *)global->devreq);
  172.  
  173.    global->DiskChange = global->devreq->iotd_Req.io_Actual;
  174.  
  175.    global->devreq->iotd_Req.io_Command = TD_PROTSTATUS;
  176.    DoIO((struct IORequest *)global->devreq);
  177.  
  178.    return(global->devreq->iotd_Req.io_Actual);
  179. }
  180.  
  181. void demanddisk(global)
  182. GLOBAL global;
  183. {
  184. while(global->diskstatus == ID_NO_DISK_PRESENT)
  185.    {
  186.    request(global, REQ_MUST, NULL);
  187.    ResetDrive(global);
  188.    /* We really should verify that we have the right disk but for now */
  189.    /* we will trust the user to follow the requesters                 */
  190.    }
  191. }
  192.