	Section	Main,Code

	;sourcecode to print out any textfile. Used as VOTER.EXE
	;on grapevine

	;permission given to use as long as you credit shagratt/LSD

	;by Shagratt/LSD

	opt	c+
	
	IncDir	"dh0:Include/"
	include	Intuition/intuition.I
	Include	Intuition/Intuition_Lib.I
	Include	Libraries/dos_LIb.i
	Include	Libraries/Dos.i
	Include	Utility/Reqtools.i
	Include	Utility/Reqtools_lib.i
	Include	Exec/Exec_Lib.I
	Include	Exec/Exec.I
	Include	Misc/EasyStart.i	

CALLREQ	Macro
	Move.l	_ReqBase,A6
	Jsr	_LVOrt\1(a6)
	Endm

alert_text	MACRO
	dc.w	320-((\1)*4)	; x co-ords
	dc.b	\2		; y co-ord
down	SET down+10
	Endm


	*-----------------------------------------------------------*
	
go:	Lea	DosName,A1		; Open Dos Library
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l 	D0,_DOSBase
	Beq	Error

	Lea	IntName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l	D0,_IntuitionBase
	Beq	Error

	Lea	ReqName,A1		; Open reqtools library
	Moveq	#0,d0
	CALLEXEC	OpenLibrary
	Move.l	D0,_ReqBase
	Beq	NoReq
	
	Move.l	#RT_REQINFO,D0	; Prepare requester for use
	Move.l 	#0,A0
	CALLREQ	AllocRequestA
	Move.l	D0,ReqInfoStructPtr

	*-----------------------------------------------------------*

	Lea	AboutText,A1	;Text for body
	Lea	GadgeText,A2	;ok gadgets
	Lea	AboutValues,A4	;value list for %ld
	Move.l	ReqInfoStructPtr,A3
	Lea	AboutTagList,A0
	CALLREQ	EZRequestA		; display requester
	cmp.l	#0,d0
	beq	Quit
	
	bsr	PrintForm
	beq	Quit
	bsr	Prt_Error
	
	*-----------------------------------------------------------*

Quit	Move.l	ReqToolsStructPtr,A1
	CALLREQ	FreeRequest		; Dealocate Requester 

CloseReq	Move.l	_ReqBase,A1
	CALLEXEC	CloseLibrary	; Close req library

	Move.l	_IntuitionBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary

	Moveq	#0,d0		; no return code
	Rts

	*-----------------------------------------------------------*

PrintForm:	move.l	#printer_filename,d1
	move.l	#MODE_NEWFILE,d2
	CALLDOS	Open		; open file
	beq	.Prt_Error
	move.l	d0,file_handle

	move.l	file_handle,d1
	move.l	#text,d2
	move.l	#textend-text,d3
	CALLDOS	Write
	
	move.l	file_handle,d1
	CALLDOS	Close

	clr.l	d0
	rts

.Prt_Error
	move.l	#-1,d0
	rts

	*-----------------------------------------------------------*

NoReq	move.l	#0,d0
	move.l	#alert_string,a0
	move.l	#alert_size,d1

	CALLINT	DisplayAlert

	bsr	PrintForm

	Move.l	_IntuitionBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary

Error	Moveq	#0,d0		; no return code
	Rts

	*-----------------------------------------------------------*

Prt_Error	Lea	PrtText,A1		;Text for body
	Lea	OkText,A2		;ok gadgets
	Lea	AboutValues,A4	;value list for %ld
	Move.l	ReqInfoStructPtr,A3
	Lea	AboutTagList,A0
	CALLREQ	EZRequestA

	rts

	*-----------------------------------------------------------*

AboutText	dc.b	10
	Dc.b	"LSD HARDNESS CHART",10
	Dc.b	"VOTING FORM PRINTER",10
	Dc.b	" ",10
	Dc.b	"By Shagratt/LSD",10
	dc.b	0

PrtText	Dc.b	" ",10
	dc.b	"Failed to open device PRT:",10
	dc.b	0

	*-----------------------------------------------------------*

GadgeText	Dc.b	"  PRINT  |  CANCEL  ",0
OkText	Dc.b	"  OK  ",0
AboutTitle	Dc.b	"",0
	Even

	*-----------------------------------------------------------*

AboutValues	dc.l	0

	*-----------------------------------------------------------*

AboutTagList
	Dc.l	RT_Window
	Dc.l	0
	Dc.l	RT_ReqPos
	Dc.l	REQPOS_CENTERSCR	
	Dc.l	RT_WaitPointer
	Dc.l	-1
	Dc.l	RTEZ_ReqTitle
	Dc.l	AboutTitle
	Dc.l	RTEZ_Flags
	DC.l	EZREQF_CENTERTEXT
	DC.l	TAG_END

	*-----------------------------------------------------------*

alert_string:

down SET	20

	alert_text (.a2-.a1),down
.a1	dc.b	"Can't open REQTOOLS.Library - No user interface available",0
.a2	dc.b	1	; another line
	
	dc.b	0
	even

alert_size	= down+5

	*-----------------------------------------------------------*

ReqToolsStructPtr	Dc.l	0
ReqInfoStructPtr	Dc.l	0

	*-----------------------------------------------------------*

file_handle		dc.l	0
printer_filename	dc.b	"PRT:",0

	*-----------------------------------------------------------*

_DOSBase	Dc.l	0
_ReqBase	Dc.l	0
_IntuitionBase	Dc.l	0

DosName	DOSNAME
IntName	INTNAME
ReqName	Dc.b	"reqtools.library",0
	Even
	
	*-----------------------------------------------------------*

text:	incbin	"textfile.txt"	;file to print!
	dc.b	12		; formfeed	
textend:	

	
	end
	


