
createport	macro
		movem.l	d2-d3/a2-a3,-(sp)
		ifc	"\1","0"	;name
		move.l	#0,a3
		endc
		ifnc	"\1","0"
		addrtxin	\1,a3
		endc
		varin	\2,d3		;pri
		ifnc	'\3',''
		varin	\3,d2		;size
		endc
		ifc	'\3',''
		move.l	#34,d2		;#MP_SIZEOF
		endc
		jsr	createprcd(pc)
		movem.l	(sp)+,d2-d3/a2-a3
		ifnd	_createprid
		bra	createprovr
createprcd	addq.l	#4,d2
		move.l	d2,d0
		move.l	#$10001,d1
		move.l	4,a6
		jsr	-198(a6)		;AllocMem
		move.l	d0,a2
		tst.l	d0
		beq	createprl
		move.l	d2,(a2)+
		moveq.l	#-1,d0			;sigbit
		jsr	-330(a6)		;allocsignal
		move.b	d0,15(a2)		;MP_SIGNAL(a2)
		move.l	a3,10(a2)		;LN_NAME(a2)
		bmi	createprte		;no bit
		sub.l	a1,a1
		jsr	-294(a6)		;FindTask
		move.l	d0,16(a2)		;MP_SIGTASK(a2)
		move.b	#4,8(a2)		;#NT_MSGPORT,LN_TYPE(a2)
		move.b	#0,14(a2)		;#PA_SIGNAL,MP_FLAGS(a2)
		move.b	d3,9(a2)		;MP_PRIORITY(a2)
		move.l	a3,d0
		beq	createprlst
		move.l	a2,a1
		jsr	-354(a6)		;AddPort
		bra	createprl
createprlst	lea	20(a2),a0		;MP_MSGLIST(a2),a0
		move.l	a0,(a0)			;NEWLIST	a0
		addq.l	#4,(a0)
		clr.l	4(a0)
		move.l	a0,8(a0)
		bra	createprl
createprte	move.l	-(a2),d0
		move.l	a2,a1
		move.l	4,a6
		jsr	-210(a6)		;FreeMem
		moveq	#0,d0
		rts
createprl	move.l	a2,d0
		rts
_createprid	set	1
createprovr
		endc
		endm

Deleteport	macro
		move.l	a2,-(sp)
		addrin	\1,a2
		jsr	deleteportcd(pc)
		move.l	(sp)+,a2
		ifnd	deleteportid
		bra	deleteportovr
deleteportcd	move.l	a2,d0
		beq	312$			;no port
		move.l	10(a2),d0		;LN_NAME
		beq	311$
		move.l	a2,a1
		move.l	4,a6
		jsr	-360(a6)		;RemPort
311$		move.b	#$ff,8(a2)		;LN_TYPE
		move.l	#-1,20(a2)		;LH_HEAD
		move.b	15(a2),d0		;MP_SIGBIT
		move.l	4,a6
		jsr	-336(a6)		;FreeSignal
		move.l	-(a2),d0
		move.l	a2,a1
		jsr	-210(a6)		;FreeMem
312$		rts
deleteportid	set	1
deleteportovr	
		endc
		endm
				
CreateExtIO	macro
		movem.l	d2/a2,-(sp)
		addrin	\1,a2
		varin	\2,d2
		jsr	createextcd(pc)
		movem.l	(sp)+,d2/a2
		ifnd	createextid
		bra	createextovr
createextcd	move.l	a2,d0
		beq	320$
		addq.l	#4,d2
		move.l	d2,d0
		move.l	#$10001,d1
		move.l	4,a6
		jsr	-198(a6)		;AllocMem
		tst.l	d0
		beq	320$
		move.l	d0,a0
		move.l	d2,(a0)+
		move.b	#5,8(a0)		;MT_MESSAGE,LN_TYPE(a0)
		move.b	#0,9(a0)		;LN_PRI(a0)
		move.l	a2,14(a0)		;MN_REPLYPORT
		move.l	a0,d0
320$		rts
createextid	set	1
createextovr
		endc
		endm

DeleteExtIO	macro
		addrin	\1,a1
		jsr	deleteextcd(pc)
		ifnd	deleteextid
		bra	deleteextovr
deleteextcd	move.l	a1,d0
		beq	330$
		move.b	#$ff,8(a1)		;LN_TYPE
		move.l	#-1,14(a1)		;IO_DEVICE
		move.l	#-1,18(a1)		;IO_UNIT
		move.l	-(a1),d0
		move.l	4,a6
		jsr	-210(a6)		;FreeMem
330$		rts
deleteextid	set	1
deleteextovr	
		endc
		endm

CreateTask	macro
		movem.l	d2-d4/a2-a4,-(sp)
		ifc	'\1','0'
		move.l	#0,a3
		endc
		ifnc	'\1','0'
		addrtxin	\1,a3
		endc
		varin	\2,d2			;taskpri
		addrin	\3,a2			;taskentry
		varin	\4,d3			;stacksize
		jsr	creattkcd(pc)
		movem.l	(sp)+,d2-d4/a2-a4
		ifnd	Creattkid
		bra	creattkovr
creattkcd	move.l	d3,d4
		add.l	#100,d3			;tasksizeof+8
		move.l	d3,d0
		move.l	#$10001,d1
		move.l	4,a6
		jsr	-198(a6)		;AllocMem
		move.l	d0,a1
		tst.l	d0
		beq	200$
		move.l	d3,(a1)+
		add.l	#92,d0			;tasksizeof
		move.l	d0,58(a1)		;Task->TC_SPLOWER
		add.l	d4,d0
		move.l	d0,62(a1)		;Task->TC_SPUPPER
		move.l	d0,54(a1)		;Task->TC_SPREG
		move.b	#1,8(a1)
		move.b	d2,9(a1)		;task->LN_PRI
		move.l	a3,10(a1)
		move.l	a1,-(sp)
		move.l	#0,a3
		move.l	4,a6
		jsr	-282(a6)		;AddTask
		move.l	(sp)+,d0
200$		rts
		
Creattkid	set	1
creattkovr
		endc
		endm		

DeleteTask	macro
		addrin	\1,a1			;task
		jsr	dlttaskcd(pc)
		ifnd	dlttaskid
		bra	dlttaskovr
dlttaskcd	move.l	a1,-(sp)
		move.l	4,a6
		jsr	-288(a6)		;RemTask
		move.l	(sp)+,a1
		move.l	-(a1),d0		;sizeof block
		move.l	4,a6
		jsr	-210(a6)		;FreeMem
		rts
dlttaskid	set	1
dlttaskovr
		endc
		endm		
CreateStdIO	macro
		movem.l	d2/a2,-(sp)
		addrin	\1,a2			;Taskreplyport
		jsr	createsdcd(pc)
		movem.l	(sp)+,d2/a2
		ifnd	createsdid
		bra	createsdovr
createsdcd	move.l	a2,d0
		beq	320$
		addq.l	#36,d2			;sizeofIOstuct+4
		move.l	d2,d0
		move.l	#$10001,d1
		move.l	4,a6
		jsr	-198(a6)		;AllocMem
		tst.l	d0
		beq	320$
		move.l	d0,a0
		move.l	d2,(a0)+
		move.b	#5,8(a0)		;MT_MESSAGE,LN_TYPE(a0)
		move.b	#0,9(a0)		;LN_PRI(a0)
		move.l	a2,14(a0)		;MN_REPLYPORT
		move.l	a0,d0
320$		rts
createsdid	set	1
createsdovr
		endc
		endm

DeleteStdIO	macro
		addrin	\1,a1
		jsr	deletesdcd(pc)
		ifnd	deletesdid
		bra	deletesdovr
deletesdcd	move.l	a1,d0
		beq	330$
		move.b	#$ff,8(a1)		;LN_TYPE
		move.l	#-1,14(a1)		;IO_DEVICE
		move.l	#-1,18(a1)		;IO_UNIT
		move.l	-(a1),d0
		move.l	4,a6
		jsr	-210(a6)		;FreeMem
330$		rts
deletesdid	set	1
deletesdovr	
		endc
		endm
