
------------------------------------------
The include file Startup.i follows:

You need this to handle what happens if this is run from the workbench.
If it is, then all stuff that should be done, is done. You don't really
need to know what it does, but for your information, if the program is
started from the CLI then this does basically nothing bar open the dos
library. If from the WB, it opens a default window, replys to the message
etc to keep WB happy.
	Does contain a handy routine called PrintMessage, a0 points to
a NULL terminated string, this is printed to STDIO (CLI window or the
CON window opened by this)
;
; ---- Startup handler ....
;	Written by Toby W.Simpson, Dec 28 1990.
;	Copyright Toby W.Simpson 1990. All Rights reserved.
;
BEGIN:		bra	BEGIN_CODE
;
BG_Title:	dc.b	"Startup code/T.Simpson",0
BG_Version:	dc.b	"1.05",0
BG_IncDate:	dc.b	"Assembled on "
;
; ---- Comment this chunk out if you want. I have an env variable
;      called ASSEMDATE that contains the date (Done with
;      date >env:assemdate) so I know by typing opt h I can find the
;      date and time this program was assembled. ....
		incbin	"ENV:ASSEMDATE"
		even
;
BEGIN_CODE:	clr.l	ST_Message
		clr.l	ST_TaskNum
		move.l	a0,ST_Command
		move.l	d0,ST_Bytes
		suba.l	a1,a1
		move.l	$04,a6
		jsr	_LVOFindTask(a6)	; Find our task
		move.l	d0,ST_TaskNum		; Store task number
		move.l	d0,a4
		tst.l	$ac(a4)
		bne	ST_CLI			; Run from CLI
		lea	$5c(a4),a0
		move.l	a0,a3
		jsr	_LVOWaitPort(a6)	; Wait for WB message
		move.l	a3,a0
		jsr	_LVOGetMsg(a6)
		move.l	d0,ST_Message		; WB Message
		lea	ST_DosName(pc),a1
		moveq	#0,d0
		jsr	_LVOOpenLibrary(a6)	; Open dos lib
		move.l	d0,ST_DosBase
		beq	QUIT
		lea	ST_Standard(pc),a0
		move.l	a0,d1
		move.l	#1005,d2
		move.l	ST_DosBase,a6
		jsr	_LVOOpen(a6)		; Open console window
		move.l	d0,ST_Handle
		beq	QUIT			; Failed
		move.l	d0,STDOUT
		move.l	d0,STDERR
		move.l	d0,STDIN		; Standard IO channels
		bra	ST_Go
;
; ---- CLI Startup ....
ST_CLI:		lea	ST_DosName(pc),a1
		moveq	#0,d0
		jsr	_LVOOpenLibrary(a6)	; Open dos lib.
		move.l	d0,ST_DosBase
		beq	QUIT
		move.l	d0,a6
		jsr	-60(a6)
		move.l	d0,STDERR
		move.l	d0,STDOUT
		jsr	-54(a6)
		move.l	d0,STDIN		; Find IO channels
ST_Go:		jsr	START			; Call main program
;
; ---- Quit handler ....
QUIT:		tst.l	ST_Message
		beq	QT_CLI			; CLI Quit.
		tst.l	ST_Handle
		beq	QT_SkipWindow		; No window to close.
		move.l	ST_DosBase,a6
		move.l	ST_Handle,d1
		jsr	_LVOClose(a6)		; Close window
QT_SkipWindow:	move.l	$04,a6
		jsr	_LVOForbid(a6)		; Dunno why but no work wivout
		move.l	ST_Message,a1
		jsr	_LVOReplyMsg(a6)	; Reply to workbench msg
QT_CLI:		tst.l	ST_DosBase
		beq	QT_Err
		move.l	$04,a6
		move.l	ST_DosBase,a1
		jsr	_LVOCloseLibrary(a6)	; Close dos library
		clr.l	d0
		rts
QT_Err:		moveq	#20,d0
		rts				; Signal WARN and quit
;
; ---- Variables for startup procedure ....
ST_Message:	dc.l	0			; Workbench message ptr
ST_TaskNum:	dc.l	0			; Our task number
ST_DosBase:	dc.l	0			; Dos base
ST_Handle:	dc.l	0			; Standard IO window
ST_Command:	dc.l	0			; Address of pars
ST_Bytes:	dc.l	0			; Bytes in par.
ST_Standard:	dc.b	"con:0/10/640/100/IO Window",0
STDIN:		dc.l	0
STDOUT:		dc.l	0
STDERR:		dc.l	0			; IO Channels.
ST_DosName:	dc.b	"dos.library",0
		even
;
; ---- Message handler ....
PrintMessage:	moveq	#$00,d3
PM_FindLen:	tst.b	0(a0,d3.w)
		beq	PM_GotLen
		addq.l	#$01,d3
		bra	PM_FindLen		; Get Str Len.
PM_GotLen:	move.l	STDOUT,d1
		move.l	a0,d2
		move.l	ST_DosBase,a6
		jsr	-48(a6)			; Print this string
		rts
;

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