*\ :ts=8 bk=0
*
* neeto.asm:	I wrote this because I was bored out of my skull this
*		morning, and had to do something.  This is based very
*		heavily on a program written by a very dear friend of
*		mine named Jon Foreman, and is named after the program
*		he wrote at College on Marin in VAX assembly under UNIX.
*		This program is really stupid...
*		CLI only; use ^C to exit.
*
* Leo L. Schwab				8803.01		(415)-456-3960
*/

		include	"exec/types.i"
		include	"exec/libraries.i"
		include "libraries/dos.i"

xlib		macro
		xref	_LVO\1
		endm

callsys		macro
		CALLLIB	_LVO\1
		endm

		xlib	OpenLibrary
		xlib	CloseLibrary
		xlib	Write
		xlib	Open
		xlib	Close
		xlib	SetSignal

		far	code
		far	data

VERSION		equ	0


****************
* Code
****************

		section	code

begin		lea	dosname,a1	; Open the dos.library
		moveq	#VERSION,d0
		movea.l	4,a6
		callsys	OpenLibrary
		movea.l	d0,a5		; Cache lib pointer in A5

		move.l	#stdout,d1	; Open stdout
		move.l	#MODE_OLDFILE,d2
		movea.l	a5,a6
		callsys	Open
		move.l	d0,d4		; Store filehandle in D4
		move.l	#SIGBREAKF_CTRL_C,d7

again:
		moveq	#69,d5		; Hard coded (ACK!).  Assumes 80-col
					; CLI window.
fwdloop:
		move.l	d4,d1		; Filehandle
		move.l	#forward,d2	; Buffer pointer
		move.l	#backward-forward,d3	; Length
		movea.l	a5,a6		; LibPtr
		callsys	Write
		bsr.s	chkabort
		dbra	d5,fwdloop

		moveq	#69,d5
bkloop:
		move.l	d4,d1		; FH
		move.l	#backward,d2	; Buffer
		move.l	#break-backward,d3	; Length
		movea.l	a5,a6
		callsys	Write
		bsr.s	chkabort
		dbra	d5,bkloop

		bra.s	again

chkabort:
		moveq	#0,d0
		moveq	#0,d1
		movea.l	4,a6
		callsys	SetSignal
		and.l	d7,d0		; Check for break
		bne.s	exit
		rts
exit:
		move.l	d4,d1		; FH
		move.l	#break,d2	; Buffer
		move.l	#enddat-break,d3	; Length
		movea.l	a5,a6
		callsys	Write		; Output ^C

		move.l	d4,d1
		movea.l	a5,a6
		callsys	Close		; Close stdout
		movea.l	a5,a1
		movea.l	4,a6
		callsys	CloseLibrary	; Close DOS
		addq.w	#4,sp		; Flush wrong return address
		rts


****************
* Data!  Wow!  *
****************
		section	data

dosname		dc.b	"dos.library",0
stdout		dc.b	"*",0

forward		dc.b	" =--->",8,8,8,8,8
backward	dc.b	"<---= ",8,8,8,8,8,8,8
break		dc.b	"^C",10
enddat:

		end
