; FILE: Source:HackdiskTest.ASM          REV: 1 --- test for hackdisk.device
; History
;  0      I took the original hackdisk V2.02 release source and rewrote it
;

; HackdiskTest.ASM -- test for hackdisk and print out IDString
; Returns error level 5 if Hackdisk is not installed.

	include	"exec/types.i"
	include	"exec/libraries.i"
	include	"exec/execbase.i"
	include	"dos/dosextens.i"
	include	"exec/exec_lib.i"
	include	"dos/dos_lib.i"
call	MACRO
	jsr	(_LVO\1,a6)
	ENDM

Main	move.l	(4).w,a6
	move.l	a6,_ExecBase
	bsr.b	InitDOS
	move.l	(_DosBase,pc),d0
	beq.b	.end
	lea	(DeviceList,a6),a0
	lea	(TrackDiskName,pc),a1
	call	Forbid
	call	FindName
	call	Permit
	tst.l	d0
	beq.b	.end		system is serously screwed!
	move.l	d0,a0
	move.l	(LIB_IDSTRING,a0),a0
	move.l	a0,d0
	beq.b	.notinstalled
	bsr.b	Print
	moveq	#0,d0
	cmp.b	#'H',(a0)
	beq.b	.end

.notinstalled	moveq	#5,d0
.end	bra.b	CloseDOS

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

	movem.l	d0-d3/a0-a1/a6,-(sp)
	move.l	a0,d2
	moveq	#-1,d3
.getlen	addq.l	#1,d3
	tst.b	(a0)+
	bne.b	.getlen
	move.l	(_DosBase,pc),a6
	call	Output
	move.l	d0,d1  
	call	Write
	movem.l	(sp)+,d0-d3/a0-a1/a6
	rts

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

	movem.l	d0-d1/a0-a1/a6,-(sp)
	move.l	(_ExecBase,pc),a6
	sub.l	a1,a1
	call	FindTask
	move.l	d0,a0
	tst.l	(pr_CLI,a0)	; executed from CLI?
	beq.b	.end		; no
	moveq	#0,d0
	move.w	#_LVOOldOpenLibrary,d1
	cmp.w	#31,(LIB_VERSION,a6)
	blo.b	.open
	move.w	#_LVOOpenLibrary,d1
.open	lea	(.DosName,pc),a1
	jsr	0(a6,d1.w)
	move.l	d0,_DosBase
.end	movem.l	(sp)+,d0-d1/a0-a1/a6
	rts
.DosName:	dc.b	'dos.library',0
	even

	CNOP	0,4
_ExecBase:	dc.l	0
_DosBase:	dc.l	0

CloseDOS:	movem.l	d0-d1/a0-a1/a6,-(sp)
	lea	(_DosBase,pc),a0
	tst.l	(a0)
	beq.b	.end
	move.l	(a0),a1
	clr.l	(a0)
	move.l	(_ExecBase,pc),a6
	call	CloseLibrary
.end	movem.l	(sp)+,d0-d1/a0-a1/a6
	rts

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

	END
