;HackDiskTest.s -- test for hackdisk and print out IDString
;Returns error level 5 if Hackdisk not installed.

	exeobj
	objfile	'c:HackDiskTest'
	multipass

	move.l	4,a6
	bsr	InitDOS
	tst.l	DosBase
	beq	.End
	lea	DeviceList(a6),a0
	lea	TrackName(pc),a1
	SYS	Forbid
	SYS	FindName
	SYS	Permit
	tst.l	d0
	beq	.End	;system is serously screwed!
	move.l	d0,a0
	move.l	LIB_IDSTRING(a0),a0
	move.l	a0,d0
	beq	.NotInstalled
	bsr	Print
	moveq	#0,d0
	cmp.b	#'H',(a0)
	beq	.End
.NotInstalled:
	moveq	#5,d0
.End:	bsr	CloseDOS
	rts

Print:
;Output a string to the CLI
;Enter with pointer to a zero-terminated string in a0
;All registers are preserved

	movem.l	d0-d7/a0-a6,-(sp)
	move.l	a0,a5
	move.l	DosBase(pc),a6
	move.l	a5,a0
	move.l	a5,a4
.PrintLine:
	tst.b	(a5)+
	bne	.PrintLine
	subq.l	#1,a5
	sub.l	a0,a5
	SYS	Output
	move.l	d0,d1  
	move.l	a4,d2
	move.l	a5,d3
	SYS	Write
.End:	movem.l	(sp)+,d0-d7/a0-a6
	rts

InitDOS:
;Open dos.library
;Should check DosBase afterward in case of fatel error (unlikely)

	movem.l	d0-d7/a0-a6,-(sp)
	move.l	4,a6
	move.l	ThisTask(a6),a0
	tst.l	pr_CLI(a0)	;executed from CLI?
	beq.s	.End	;no
	lea	.DosName(pc),a1
	SYS	OldOpenLibrary
	move.l	d0,DosBase
.End:	movem.l	(sp)+,d0-d7/a0-a6
	rts
.DosName:	dc.b	'dos.library',0
	even

DosBase:	dc.l	0

CloseDOS:	movem.l	d0-d1/a0-a1/a6,-(sp)
	move.l	4,a6
	move.l	DosBase(pc),d0
	beq.s	.End
	clr.l	DosBase
	move.l	d0,a1
	SYS	CloseLibrary
.End:	movem.l	(sp)+,d0-d1/a0-a1/a6
	rts

TrackName:
	dc.b	'trackdisk.device',0

	end
