*	CheckForPrinter
* written in 1991 by Stephan Fuhrmann
* Contact : Stephan Fuhrmann / Erikstr.30 / 2380 Schleswig / Germany
* DevPac-Source

	incdir	include/
	include	exec/exec_lib.i
	include	exec/io.i
	include	exec/ports.i
	include	devices/parallel.i
	include	libraries/dos_lib.i
	include	libraries/dos.i

	section	CheckPrinter,code
	sub.l	a1,a1
	CallExec	FindTask
	lea	_Reply(pc),a1
	move.l	d0,MP_SigTask(a1)
	lea	_ParIO(pc),a0
	move.l	a1,MN_ReplyPort(a0)
	CallExec	AddPort 

	lea	_ParName(pc),a0
	lea	_ParIO(pc),a1
	moveq	#0,d0
	moveq	#0,d1
	CallExec	OpenDevice
	tst.l	d0
	bne.s	RMSG
	lea	_ParIO(pc),a1
	move.w	#PDCMD_QUERY,IO_COMMAND(a1)
	CallExec	DoIo
		;IO-Struktur mit Parallel-Port-STATUS füllen

CDEV:
	lea	_ParIO(pc),a1
	CallExec	CloseDevice
RMSG:
	lea	_Reply(pc),a1
	CallExec	RemPort

	lea	_ParIO(pc),a1
	move.b	IO_PARSTATUS(a1),d0

; D0 enthält jetzt das Status-Byte des Parallel-Ports .
; Siehe devices/parallel.i für weitere Informationen :
; Bit 0 : 1-OffLine
;	: 0-OnLine
; Bit 1 : 1-OK
;	: 0-PAPER_OUT
; Bit 2 : 1-PRINTER_READY
;	: 0-PRINTER_BUSY
; Bit 3 : 1-Direction WRITE
;	: 0-Direction READ

	move.b	d0,d7		;für später retten

	lea	_DOSNAME(pc),a1
	moveq	#0,d0
	CallExec	OpenLibrary
	lea	_DosBase(pc),a0
	move.l	d0,(a0)
	beq.s	Error
	CallDos	Output
	move.l	d0,d1
	btst	#0,d7
	beq.s	ONLINE
	move.l	#_OfflineTXT,d2
	move.l	#_OffLineLng,d3
PrintIt:
	CallDos	Write
Error:	moveq	#0,d0
	rts
ONLINE:
	move.l	#_OnlineTXT,d2
	move.l	#_OnLineLng,d3
	bra.s	PrintIt

; Daten für die eigentliche Routine (PAR-Status)

_ParName:	PARALLELNAME
_ParIO:		ds.l	20
_Reply:		ds.l	8

; Daten für Textausgabe

_DosBase:	ds.l	1
_OnlineTxt:	dc.b	"Printer is ONLINE",$a
_OnlineLng=*-_OnlineTxt
_OfflineTxt:	dc.b	"Printer is OFFLINE/Not connected",$a
_OfflineLng=*-_OfflineTxt
_DosName:	DOSNAME
