
| stripped baserelative startup code for gcc v2.3.3
| (c) by Gunther Nikl Die Jan 11 17:45 1994
| No real bugs known

| some specific defines

_LVOForbid	=	-132
_LVOGetMsg	=	-372
_LVOReplyMsg	=	-378
_LVOWaitPort	=	-384
_LVOCloseLibrary =	-414
_LVOOpenLibrary	=	-552

_LVOCurrentDir	=	-126

| public symbols

		.globl	__exit
		.globl	_geta4

		.text

| first entry - init some vars, check for cli or wb start

start:		moveml	d2-d7/a2-a6,sp@-

		jbsrs	_geta4

		movel	sp,a4@(_SaveSP:W)
		movel	4:W,a6
		movel	a6,a4@(_SysBase:W)

		movel	a6@(276),a3
		tstl	a3@(172)
		bnes	fromCLI

| wb start - get wbmsg, open dos, change dir

fromWB:		lea	a3@(92),a0
		jsr	a6@(_LVOWaitPort)
		lea	a3@(92),a0
		jsr	a6@(_LVOGetMsg)
		movel	d0,a4@(_WbMsg:W)

| cli start - open dos

fromCLI:	jbsrs	OpenDOS
		beqs	cleanup
		movel	a4@(_WbMsg:W),d1
		beqs	isCLI
		movel	d1,a1
		movel	a1@(36),a1
		movel	a1@,d1
		jsr	a6@(_LVOCurrentDir)
isCLI:		jbsr	__main
		jras	cleanup

| exit() entry - get return val, restore stackptr

__exit:		movel	sp@(4:W),d0
		movel	a4@(_SaveSP:W),sp

| cleanup - close dos, reply wbmsg

cleanup:	movel	d0,d7
		movel	a4@(_SysBase:W),a6
		movel	a4@(_DOSBase:W),d0
		beqs	nodos
		movel	d0,a1
		jsr	a6@(_LVOCloseLibrary)
nodos:		movel	a4@(_WbMsg:W),d2
		beqs	todos
		jsr	a6@(_LVOForbid)
		movel	d2,a1
		jsr	a6@(_LVOReplyMsg)
todos:		movel	d7,d0
		moveml	sp@+,d2-d7/a2-a6
		rts

| get baseptr

_geta4:		lea	___a4_init,a4
		rts

| open dos v33+

OpenDOS:	lea	pc@(DosName+2),a1
		movql	#33,d0
		jsr	a6@(_LVOOpenLibrary)
		movel	d0,a6
		movel	a6,a4@(_DOSBase:W)
		rts

DosName:	.asciz	"dos.library"

		.even

| data area

		.data

.comm		_SysBase,4
.comm		_DOSBase,4
.comm		_SaveSP,4
.comm		_WbMsg,4
