home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 274.lha / DiskHandler / subs.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  5KB  |  202 lines

  1. /* Subs.c - Basic disk handler 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                                   (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include "handler.h"
  13.  
  14. #ifdef DEBUG
  15. long _ECS;
  16. static long *debuglog;
  17.  
  18. void initdebug()
  19. {
  20. debuglog = (long *)Open("CON:200/0/440/200/DISK-HANDLER", 1006);
  21. }
  22.  
  23. void xwrite(str,len)
  24. char *str;
  25. int len;
  26. {
  27. long args[3];
  28. struct FileHandle *fh;
  29.  
  30. fh = (struct FileHandle *)BADDR(debuglog);
  31. args[0] = (long)fh->fh_Arg1;
  32. args[1] = (long)str;
  33. args[2] = (long)len;
  34. sendpkt(fh->fh_Type,ACTION_WRITE,args,3);
  35. }
  36.  
  37. void myprintf(str,p1,p2,p3,p4,p5,p6,p7,p8,p9)
  38. char *str;
  39. char *p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
  40. {
  41.    char buf[128];
  42.    int len;
  43.  
  44.    len = sprintf(buf,str,p1,p2,p3,p4,p5,p6,p7,p8,p9);
  45.    if (len>128) len = 128;
  46.    xwrite(buf,len);
  47. }
  48.  
  49. void myputbstr(str, name)
  50. char *str;
  51. char *name;
  52. {
  53.    int len;
  54.  
  55.    xwrite(str, strlen(str));
  56.    len = *name++;
  57.    xwrite(name, len);
  58.    xwrite("\n", 1);
  59. }
  60.  
  61. void myputlstr(str, name, len)
  62. char *str;
  63. char *name;
  64. int len;
  65. {
  66.    xwrite(str, strlen(str));
  67.    xwrite(name, len);
  68.    xwrite("\n", 1);
  69. }
  70.  
  71. #endif
  72.  
  73. /* misc.c  - support routines - Phillip Lindsay (C) Commodore 1986  
  74.  *  You may freely distribute this source and use it for Amiga Development -
  75.  *  as long as the Copyright notice is left intact.
  76.  *
  77.  * 30-SEP-86
  78.  */
  79.  
  80. /* returnpkt() - packet support routine 
  81.  * here is the guy who sends the packet back to the sender...
  82.  */
  83.  
  84. void retpkt(global, packet)
  85. GLOBAL global;
  86. struct DosPacket *packet;
  87. {
  88.  struct Message *mess;
  89.  struct MsgPort *replyport;
  90.  
  91.  replyport                = packet->dp_Port;
  92.  mess                     = packet->dp_Link;
  93.  packet->dp_Port          = global->port;
  94.  
  95.  PutMsg(replyport,mess); 
  96. }
  97.  
  98. /*
  99.  * taskwait() ... Waits for a message to arrive at your port and 
  100.  *   extracts the packet address which is returned to you.
  101.  */
  102.  
  103. struct DosPacket *taskwait(global)
  104. GLOBAL global;
  105. {
  106.  struct Message *mymess;
  107.  
  108.  WaitPort(global->port); /* wait for packet */
  109.  mymess = (struct Message *) GetMsg(global->port);
  110.  
  111.  global->pkt = (struct DosPacket *) mymess->mn_Node.ln_Name;
  112.  
  113. #if 0
  114.  BUG(("Incoming at %08lx from %08lx\n", global->pkt, global->pkt->dp_Port));
  115. #endif
  116.  /* give them the pointer to the packet */
  117.  
  118.  return(global->pkt);
  119.  
  120. char *DosAllocMem(global, len)
  121. GLOBAL global;
  122. long len;
  123. {
  124. long *p;
  125.  
  126. if (( p = (long *)AllocMem(len+4, MEMF_PUBLIC | MEMF_CLEAR)) == NULL)
  127.    {
  128.    if (global->pkt != NULL)
  129.       {
  130.       global->pkt->dp_Res1 = DOS_FALSE;
  131.       global->pkt->dp_Res2 = ERROR_NO_FREE_STORE;
  132.       }
  133.    else
  134.       {
  135.       /* Gee.  Out of memory AND there is nobody to tell about it ...  */
  136.       /* Only choice is to GURU.  Maybe we could do something clever   */
  137.       /* but I doubt it...                                             */
  138.       BUG(("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
  139.       BUG(("!!!!!!!!!!!!               !!!!!!!!\n"));
  140.       BUG(("!!!!!!!!!!!! OUT OF MEMORY !!!!!!!!\n"));
  141.       BUG(("!!!!!!!!!!!!               !!!!!!!!\n"));
  142.       BUG(("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
  143.       }
  144.    }
  145. else
  146.    *p++ = len;
  147.  
  148. return((char *)p);
  149. }
  150.  
  151. void DosFreeMem(p)
  152. char *p;
  153. {
  154. long *lp;
  155. long len;
  156.  
  157.    lp = (long *)p;
  158.    len = *--lp;
  159.    FreeMem((char *)lp, len);
  160. }
  161.  
  162. #if 0
  163. /***********************************************************************
  164. *
  165. *       Support Function -- Extended IO Request plus DosPacket
  166. *
  167. ***********************************************************************/
  168.  
  169. struct IOExtPacket *CreateExtPkt(ioReplyPort,size)
  170. struct MsgPort *ioReplyPort;
  171. LONG size;
  172. {
  173.    register struct IOExtPacket  *ioExtPkt;
  174.  
  175.    if (ioReplyPort == 0)
  176.       return (NULL);
  177.  
  178.    ioExtPkt = (struct IOExtPacket *)AllocMem (size, MEMF_CLEAR | MEMF_PUBLIC);
  179.  
  180.    if (ioExtPkt == 0)
  181.       return (NULL);
  182.  
  183.    ioExtPkt->io_req.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  184.    ioExtPkt->io_req.io_Message.mn_Node.ln_Pri  = 0;
  185.    ioExtPkt->io_req.io_Message.mn_ReplyPort    = ioReplyPort;
  186.    ioExtPkt->io_req.io_Message.mn_Node.ln_Name = (char *)&(ioExtPkt -> io_pkt);
  187.  
  188.    ioExtPkt -> io_pkt.dp_Link = &(ioExtPkt ->io_req.io_Message);  
  189.    ioExtPkt -> io_pkt.dp_Port = ioReplyPort;
  190.  
  191.    return(ioExtPkt);
  192. }
  193.  
  194. void DeleteExtPkt(ioExtPkt,size)
  195. struct IOExtPacket  *ioExtPkt;
  196. LONG size;
  197. {
  198.    FreeMem ((char *)ioExtPkt, size);
  199. }
  200. #endif
  201.