_SECTION MACRO
	section	main,code
	section	sub,code
	section	texts,data
	section	data_b,data
	section	data_w,data
	section	data_l,data
	section	bss_b,bss
	section	bss_w,bss
	section	bss_l,bss
	section	main
	ENDM

_NEXTERR MACRO
	addq.b	#4,error_number
	ENDM

LINKSYS	MACRO
	move.l	a6,-(sp)
	move.l	\2,a6
	jsr	_LVO\1(a6)
	move.l	(sp)+,a6
	ENDM

CALLSYS	MACRO
	JSR	_LVO\1(A6)
	ENDM

CALLRT	MACRO
	move.l	_ReqToolsBase,a6
	jsr	_LVO\1(a6)
	ENDM

CALLXPK	MACRO
	move.l	_XpkBase,a6
	jsr	_LVO\1(a6)
	ENDM

CALLLOC	MACRO
	move.l	_LocaleBase,a6
	jsr	_LVO\1(a6)
	ENDM

CALLUTIL MACRO
	move.l	_UtilityBase,a6
	jsr	_LVO\1(a6)
	ENDM


_STARTUP MACRO
	move.l	$4.w,_SysBase
	sub.l	a1,a1
	CALLEXEC FindTask
	move.l	d0,a4
	move.l	d0,control_proc_ptr
	tst.l	pr_CLI(a4)
	bne.s	.started_from_cli
	lea	pr_MsgPort(a4),a0
	CALLEXEC WaitPort
	lea	pr_MsgPort(a4),a0
	CALLEXEC GetMsg
	move.l	d0,WB_return_message
.started_from_cli
	ENDM


_END	MACRO
	tst.l	WB_return_message
	beq.s	.was_started_from_cli
	CALLEXEC Forbid
	move.l	WB_return_message,a1
	CALLEXEC ReplyMsg
.was_started_from_cli
	move.l	return_code,d0
	rts
	ENDM


_OPENLIBS	MACRO
	lea	\1,a5
	move.l	_SysBase,a6
.open_all_libs_begin
	move.l	-(a5),a1
	tst.l	a1
	beq.s	.open_all_libs_end
	clr.l	d0
	move.b	(a1)+,d0
	move.b	(a1)+,-(sp)
	move.l	a5,-(sp)
	jsr	_LVOOpenLibrary(a6)
	move.l	(sp)+,a5
	move.l	d0,-(a5)
	tst.b	(sp)+
	bne.s	.open_all_libs_begin
	tst.l	d0
	beq	err_exit
	bra.s	.open_all_libs_begin
.open_all_libs_end
	ENDM


_CLOSELIBS	MACRO
	lea	\1,a5
	move.l	_SysBase,a6
.close_all_libs_begin
	tst.l	-(a5)
	beq.s	.close_all_libs_end
	move.l	-(a5),a1
	jsr	_LVOCloseLibrary(a6)
	bra.s	.close_all_libs_begin
.close_all_libs_end
	ENDM
