home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff339.lzh / PCQ / Runtime.lzh / Runtime / Extras / ExecIOUtils.p < prev    next >
Text File  |  1989-10-21  |  2KB  |  90 lines

  1. External;
  2.  
  3. {
  4.     ExecIOUtils.p
  5.  
  6.     This file has the NewList, CreatePort, DeletePort, CreateStdIO,
  7. and DeleteStdIO.  You never know when you'll need them....  Note that
  8. the Create functions do _not_ use PCQ's memory routines, and thus if
  9. you fail to Delete them, the memory will be lost to the system.
  10. }
  11.  
  12. {$I "Include/Exec.i"}
  13. {$I "Include/ExecIO.i"}
  14.  
  15. Procedure NewList(var NList : List);
  16. begin
  17. {$A    move.l    8(sp),a0
  18.     move.l    a0,(a0)
  19.     addq.l    #4,(a0)
  20.     clr.l    4(a0)
  21.     move.l    a0,8(a0)
  22. }
  23. end;
  24.  
  25. Function CreatePort(Name : String; pri : Integer) : MsgPortPtr;
  26. var
  27.     sigBit : Byte;
  28.     port   : MsgPortPtr;
  29. begin
  30.     sigBit := AllocSignal(-1);
  31.     if sigBit = -1 then
  32.     CreatePort := nil;
  33.     port := AllocMem(SizeOf(MsgPort), MemClear + MemPublic);
  34.     if port = nil then begin
  35.     FreeSignal(sigBit);
  36.     CreatePort := nil;
  37.     end;
  38.     with Port^ do begin
  39.     mpNode.lnName := Name;
  40.     mpNode.lnPri := pri;
  41.     mpNode.lnType := Ord(NTMsgPort);
  42.  
  43.     mpFlags := Byte(PASignal);
  44.     mpSigBit := sigBit;
  45.     mpSigTask := FindTask(nil);
  46.     end;
  47.     if name <> nil then
  48.     AddPort(port)
  49.     else
  50.     NewList(Port^.mpMsgList);
  51.     CreatePort := port;
  52. end;
  53.  
  54. Procedure DeletePort(port : MsgPortPtr);
  55. begin
  56.     if port^.mpNode.lnName <> nil then
  57.     RemPort(port);
  58.     port^.mpNode.lnType := $FF;
  59.     port^.mpMsgList.lhHead := NodePtr(-1);
  60.     FreeSignal(Port^.mpSigBit);
  61.     FreeMem(port, SizeOf(MsgPort));
  62. end;
  63.  
  64. Function CreateStdIO(ioReplyPort : MsgPortPtr) : IOStdReqPtr;
  65. var
  66.     Request : IOStdReqPtr;
  67. begin
  68.     if ioReplyPort = Nil then
  69.     CreateStdIO := Nil;
  70.  
  71.     Request := AllocMem(SizeOf(IOStdReq), MemClear + MemPublic);
  72.     if Request = Nil then
  73.     CreateStdIO := Nil;
  74.  
  75.     with Request^.ioReq.ioMessage.mnNode do begin
  76.     lnType := Byte(NTMessage);
  77.     lnPri := 0;
  78.     end;
  79.     Request^.ioReq.ioMessage.mnReplyPort := ioReplyPort;
  80.     CreateStdIO := Request;
  81. end;
  82.  
  83. Procedure DeleteStdIO(Request : IOStdReqPtr);
  84. begin
  85.     Request^.ioReq.ioMessage.mnNode.lnType := $FF;
  86.     Request^.ioReq.ioDevice := Address(-1);
  87.     Request^.ioReq.ioUnit := Address(-1);
  88.     FreeMem(Request, SizeOf(IOStdReq));
  89. end;
  90.