home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / emu / PCDisk91b.lha / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-14  |  2.1 KB  |  92 lines

  1.  
  2. /*
  3.  *  MISC.C  - support routines - Phillip Lindsay (C) Commodore 1986
  4.  *  You may freely distribute this source and use it for Amiga Development -
  5.  *  as long as the Copyright notice is left intact.
  6.  *
  7.  * 30-SEP-86
  8.  *
  9.  *  major modifications by Matthew Dillon for my PIPE: and other devices,
  10.  *  but basic theorem still Phil's.
  11.  *
  12.  * 09-OKT-88
  13.  *
  14.  *  (Olaf Seibert) added provision for an external taskwait routine.
  15.  *  Changed returnpkt and returnpktplain.
  16.  */
  17.  
  18. #include <exec/types.h>
  19. #include <exec/nodes.h>
  20. #include <exec/lists.h>
  21. #include <exec/ports.h>
  22. #include <libraries/dos.h>
  23. #include <libraries/dosextens.h>
  24.  
  25. extern void returnpkt();
  26.  
  27. void
  28. returnpktplain(packet, myproc)
  29. struct DosPacket *packet;
  30. struct Process *myproc;
  31. {
  32.     register struct Message *mess;
  33.     register struct MsgPort *replyport;
  34.  
  35.     replyport             = packet->dp_Port;
  36.     mess             = packet->dp_Link;
  37.     packet->dp_Port         = &myproc->pr_MsgPort;
  38.     mess->mn_Node.ln_Name    = (char *)packet;
  39.     mess->mn_Node.ln_Succ    = NULL;
  40.     mess->mn_Node.ln_Pred    = NULL;
  41.     PutMsg(replyport, mess);
  42. }
  43.  
  44.  
  45. void
  46. returnpkt(packet, myproc, res1, res2)
  47. register struct DosPacket *packet;
  48. struct Process *myproc;
  49. long res1, res2;
  50. {
  51.     packet->dp_Res1         = res1;
  52.     packet->dp_Res2         = res2;
  53.     returnpktplain(packet, myproc);
  54. }
  55.  
  56.  
  57. /*
  58.  * taskwait() ... Waits for a message to arrive at your port and
  59.  *   extracts the packet address which is returned to you.
  60.  */
  61.  
  62. typedef struct Message *(*funcptr)();
  63.  
  64. struct DosPacket *
  65. taskwait(myproc)
  66. register struct Process *myproc;
  67. {
  68.     register struct MsgPort *myport;
  69.     register struct Message *mymess;
  70.  
  71.     if (myproc->pr_PktWait) {
  72.     /* As per AmigaDOS tech. ref. man (V1.1) page 265: */
  73.     /* ``In the same way as GetMsg, the function should */
  74.     /*   return a message when one is available.'' */
  75.     mymess = (*(funcptr)myproc->pr_PktWait)(myproc);
  76.     } else {
  77.     myport = &myproc->pr_MsgPort;
  78.     WaitPort(myport);
  79.     mymess = (struct Message *)GetMsg(myport);
  80.     }
  81.     return((struct DosPacket *)mymess->mn_Node.ln_Name);
  82. }
  83.  
  84. taskpktrdy(myproc)
  85. struct Process *myproc;
  86. {
  87.     if (myproc->pr_MsgPort.mp_MsgList.lh_Tail == NULL)
  88.     return(0);
  89.     return(1);
  90. }
  91.  
  92.