External; { ExecIOUtils.p This file has the NewList, CreatePort, DeletePort, CreateStdIO, and DeleteStdIO. You never know when you'll need them.... Note that the Create functions do _not_ use PCQ's memory routines, and thus if you fail to Delete them, the memory will be lost to the system. } {$I "Include/Exec.i"} {$I "Include/ExecIO.i"} Procedure NewList(var NList : List); begin {$A move.l 8(sp),a0 move.l a0,(a0) addq.l #4,(a0) clr.l 4(a0) move.l a0,8(a0) } end; Function CreatePort(Name : String; pri : Integer) : MsgPortPtr; var sigBit : Byte; port : MsgPortPtr; begin sigBit := AllocSignal(-1); if sigBit = -1 then CreatePort := nil; port := AllocMem(SizeOf(MsgPort), MemClear + MemPublic); if port = nil then begin FreeSignal(sigBit); CreatePort := nil; end; with Port^ do begin mpNode.lnName := Name; mpNode.lnPri := pri; mpNode.lnType := Ord(NTMsgPort); mpFlags := Byte(PASignal); mpSigBit := sigBit; mpSigTask := FindTask(nil); end; if name <> nil then AddPort(port) else NewList(Port^.mpMsgList); CreatePort := port; end; Procedure DeletePort(port : MsgPortPtr); begin if port^.mpNode.lnName <> nil then RemPort(port); port^.mpNode.lnType := $FF; port^.mpMsgList.lhHead := NodePtr(-1); FreeSignal(Port^.mpSigBit); FreeMem(port, SizeOf(MsgPort)); end; Function CreateStdIO(ioReplyPort : MsgPortPtr) : IOStdReqPtr; var Request : IOStdReqPtr; begin if ioReplyPort = Nil then CreateStdIO := Nil; Request := AllocMem(SizeOf(IOStdReq), MemClear + MemPublic); if Request = Nil then CreateStdIO := Nil; with Request^.ioReq.ioMessage.mnNode do begin lnType := Byte(NTMessage); lnPri := 0; end; Request^.ioReq.ioMessage.mnReplyPort := ioReplyPort; CreateStdIO := Request; end; Procedure DeleteStdIO(Request : IOStdReqPtr); begin Request^.ioReq.ioMessage.mnNode.lnType := $FF; Request^.ioReq.ioDevice := Address(-1); Request^.ioReq.ioUnit := Address(-1); FreeMem(Request, SizeOf(IOStdReq)); end;