🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #1798

Re: CreatePort() help

#1798
From: Fred Gilham
Date: Mon, 23 Oct 1989 20:25
95 lines
3148 bytes

Here is some code from the speeddir code by Bryce Nesbit from fish
disk 75.  I know there is other stuff out there, some kind of
executive support code for assembly language, but I don't remember
where it is.  This code will give an idea of how things are supposed
to work, but perhaps it would not be as helpful as it could be unless
one has the Rom Kernel Manual.

Other helpful examples might be found in the example libraries (I
think one is called mylib or something like that) on the fish disks.

Note that you need to be able to link in all the kernel calls (say,
from small.lib).  That is, the code uses things like

		jsrlib	AllocMem

AllocMem is a reference to a rom kernel call.  This reference will get
resolved if you link in small.lib or amiga.lib.  Otherwise, you have
to replace Allocmem with the right (negative) number.

-----------------------------

jsrlib MACRO
 xref _LVO\1
 jsr _LVO\1(a6)
 ENDM
jmplib MACRO
 xref _LVO\1
 jmp _LVO\1(a6)
 ENDM

;
; port=CREATEPORTE(),exec
; d0		     a6
; z=error
;
;FUNCTION: Create a nameless message port, 0 priority.
;RESULT: The port pointer or Z=1 if an error occured.
;REGISTERS: A6 must contain exec!
;EXAMPLE:	bsr	CREATEPORTE
;		beq.s	noport	;Not enough memory (or signals)
;
		;xref	CREATEPORTE
CREATEPORTE	move.l	a2,-(a7)
		move.l	#MEMF_PUBLIC+MEMF_CLEAR,d1
		moveq	#MP_SIZE,d0
		jsrlib	AllocMem
		move.l	d0,a2
		tst.l	d0
		beq.s	cp_nomemory
		moveq	#-1,d0
		jsrlib	AllocSignal	;d0=return
		moveq	#-1,d1
		cmp.l	d0,d1	;-1 indicates bad signal
		bne.s	cp_sigok
		move.l	a2,a1
		moveq	#MP_SIZE,d0
		jsrlib	FreeMem
cp_nomemory	move.l	(a7)+,a2
		moveq	#0,d0
		rts

cp_sigok	move.b	d0,MP_SIGBIT(a2)
		move.b	#PA_SIGNAL,MP_FLAGS(a2)
		move.b	#NT_MSGPORT,LN_TYPE(a2)
		clr.b	LN_PRI(a2)
		suba.l	a1,a1		   ;a1=0/Find this task
		jsrlib	FindTask       ;[d0=this task]
		move.l	d0,MP_SIGTASK(a2)
		lea	MP_MSGLIST(a2),a0  ;Point to list header
		NEWLIST a0		;Init new list macro
		move.l	a2,d0
		move.l	(a7)+,a2	;cc's NOT affected
		rts
;
;DELETEPORTE(port),exec
;	     a1    a6
;
;FUNCTION:  Deletes the port by first setting some
; fields to illegal values then calling FreeMem.
;RESULT: none
;REGISTERS: A6 must contain exec!
;
		;xref	DELETEPORTE
DELETEPORTE	move.l	a1,-(a7)
		moveq	#-1,d0
		move.b	d0,LN_TYPE(a1)
		move.l	d0,MP_MSGLIST+LH_HEAD(a1)
		moveq	#0,d0	;Clear upper 3/4 of d0
		move.b	MP_SIGBIT(a1),d0
		jsrlib	FreeSignal
		move.l	(a7)+,a1
		moveq	#MP_SIZE,d0
		jmplib	FreeMem
Technical Details
Message-ID: <GILHAM.89Oct23132543@cassius.csl.sri.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!gem.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!hercules!gilham
References: <1448@ultb.UUCP> <9443@etana.tut.fi>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!gem.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!hercules!gilham
From: gilham@csl.sri.com (Fred Gilham)
Newsgroups: comp.sys.amiga.tech
Subject: Re: CreatePort() help
Message-ID: <GILHAM.89Oct23132543@cassius.csl.sri.com>
Date: 23 Oct 89 20:25:43 GMT
References: <1448@ultb.UUCP> <9443@etana.tut.fi>
Sender: usenet@csl.sri.com
Distribution: comp
Organization: Computer Science Lab, SRI International, Menlo Park, CA.
Lines: 95
In-reply-to: pl@etana.tut.fi's message of 20 Oct 89 09:16:17 GMT