*********************************
*	  Pause.asm		*
*	     by			*
*	Larry Phillips		*
*	 SYSOP - ICUG		*
*				*
*  Placed in the public domain  *
*  Feel free to use any or all  *
*  parts of this code, and to   *
*  distribute any way you want. *
*				*
*********************************


*--------------------------------
*
* Some commonly used macros
* 
*--------------------------------

XTERN	MACRO		;XTERN <reference> 
	XREF	_LVO\1	; Adds the '_LVO' prefix to it.
	ENDM

call	MACRO		;call < routine(register) >
	jsr	_LVO\1	; Adds the '_LVO' prefix to the routine name.
	ENDM

*----------------------
* Equates
*----------------------

Absbase	EQU	4

*----------------------
* External references
*----------------------

	XTERN	OpenLibrary
	XTERN	Output
	XTERN	Input
	XTERN	Write
	XTERN	Read

*----------------------
* Main Program
*----------------------

start	movem.l	a0/d0,-(SP)	;push command line args
				;a0 is address of command line string
				;d0 is length of string

	move.l	Absbase,a6	;find library
	move.l	#dosname,a1	;point to libname string
	clr.l	d0		;any version
	call	OpenLibrary(a6)	;open dos library
	move.l	d0,a6		;point to doslib for next operation
	move.l	d0,dosptr	;save dos pointer for later use
	beq	abort		;OpenLibrary failed, tell user and exit

*---- print command line to screen -----

	call	Output(a6)	;get file handle for screen
	move.l	d0,d1		;filehandle to d1 for Write
	beq	abort		;couldn't get screen handle
	move.l	d0,stdout	;screen handle to stdout
	movem.l	(SP)+,a0/d0	;get command line args
	cmpi.l	#0,d0		;is there anything to print?
	beq	waitmsg		;no, just print default.

	cmpi.b	#'-',(a0)	;check for Query
	bne	notQ
	cmpi.b	#'Q',1(a0)	;check for Query
	beq	Q		;yes, it is query
	cmpi.b	#'q',1(a0)
	bne	notQ

Q	move.l	d0,Qflag	;for later use

	addq.l	#3,a0
	subq.l	#4,d0		;adjust for Q argument -1 to get rid of C/R
	move.l	a0,tempa0	;save for later
	move.l	d0,tempd0
again	move.l	dosptr,a6
notQ	move.l	a0,d2
	move.l	d0,d3
	call	Write(a6)	;print command line or prompt

	cmpi.l	#0,Qflag	;was it a query?
	beq	waitmsg		;no, go print "RETURN... " message

	move.l	stdout,d1	;re-get screen handle
	move.l	#Qmsg,d2	;get " (Y/N) " message
	move.l	#7,d3		;and length of it
	call	Write(a6)	;then print it.
	bra	doinput

waitmsg	move.l	stdout,d1	;re-get screen handle
	move.l	#message,d2	;address where message lives
	move.l	#msglen,d3	;length of it.
	call	Write(a6)	;do it.

doinput	call	Input(a6)	;get stdin file handle
	move.l	d0,d1		;stdin handle to d1
	move.l	#buffer,d2	;buffer (dummy, input not used)
	move.l	#2,d3		;read one character (eat C/R)
	call	Read(a6)

	cmpi.l	#0,Qflag	;check for query
	beq	abort		; if not, exit with no error

	cmpi.b	#'Y',buffer	;check for 'Y'
	beq	abort
	cmpi.b	#'y',buffer	;or 'y'
	beq	abort		;exit with no error if 'Y' or 'y'
	cmpi.b	#'N',buffer	;check for 'N'
	beq	errexit
	cmpi.b	#'n',buffer	;chck for 'n'
	beq	errexit

	move.l	tempa0,a0	;no,try again
	move.l	tempd0,d0	;restore d2,d3 to print command line
	bra	again		;not Y or y, N or n

errexit	move.l	#10,d0		;otherwise return with error code 20
	bra exit

abort	clr.l	d0
exit	rts

*------------------------
* Data and storage areas
*------------------------

	CNOP	0,4
dosptr	ds.l	1
stdout	ds.l	1
Qflag	dc.l	0
tempa0	dc.l	1
tempd0	dc.l	1
	CNOP	0,4
dosname	dc.b	'dos.library',0
buffer	ds.l	1

	CNOP	0,4
Qmsg	dc.b	' (Y/N) '
Qlen	EQU	*-Qmsg
message	dc.b	'Hit RETURN to continue...',0
msglen	EQU	*-message

	END
