;****************************************************************
;*								*
;*			TINY VIEW  V0.5				*
;*			~~~~~~~~~~~~~~~				*
;*								*
;*    This Source is coded in a few hours when experimenting	*
;*								*
;*      with arp library. This is coded in Seka but should 	*
;*								*
;*  	         assemble with all other assemblers.		*
;*								*
;*--------------------------------------------------------------*
;*								*
;*	Coder: Thomas Slørdahl.		Date: 10.4.1990		*
;*								*
;*--------------------------------------------------------------*
;*								*
;*	Thanks to Jonny Niska for supporting and help.		*
;*								*
;****************************************************************


Start:
	move.l	$4,a6
	move.l	#200,d0
	move.l	#$10002,d1
	jsr	-198(a6)	;Alocate memory for buffers
	move.l	d0,mem
	beq	nomem

	move.l	d0,fbuf
	add.l	#100,d0
	move.l	d0,a0
	move.w	#$ffff,(a0)+
	move.l	a0,file

	move.l	$4,a6
	move.l	#$0,d0
	lea	arp,a1
	jsr	-408(a6)	;Open Arp.library
	move.l	d0,arpbase

	move.l	arpbase,a6
	jsr	-660(a6)	;Make FileRequester Structure
	move.l	d0,fre

	move.l	fre,a0
	lea	text,a1
	move.l	a1,(a0)

	lea	con,a0
	move.l	a0,d1
	move.l	#1005,d2
	move.l	arpbase,a6
	jsr	-30(a6)		;Open window for output
	move.l	d0,conhandle
	beq	nocclose

new:	move.l	fre,a0
	move.l	arpbase,a6
	jsr	-294(a6)	;Get Requester

	cmp.l	#0,d0
	beq	nocclose

	move.l	file,a3		;Fix name from filerequester
	move.l	fre,a2
	move.l	8(a2),a0
l1:	cmp.b	#0,(a0)
	beq	l2
	move.b	(a0)+,(a3)+
	bra	l1
l2:	cmp.b	#$ff,-1(a3)
	beq	l5
	cmp.b	#':',-1(a3)
	beq	l5
	move.b	#'/',(a3)+
l5:	move.l	fre,a2
	move.l	4(a2),a0
l3:	cmp.b	#0,(a0)
	beq	l4
	move.b	(a0)+,(a3)+
	bra	l3
l4:	move.b	#0,(a3)+

	move.l	conhandle,d1
	lea	cls,a0
	move.l	a0,d2
	move.l	#1,d3
	move.l	arpbase,a1
	jsr	-48(a6)		;Send ClearScreen to otput window
	
	clr.l	d7
	move.l	file,a0
	move.l	a0,d1
	move.l	#1005,d2
	move.l	arpbase,a6
	jsr	-30(a6)		;Open file to diplay
	move.l	d0,filehandle
	beq	nocclose

l7:	move.l	filehandle,d1
	move.l	fbuf,a0
	move.l	a0,d2
	move.l	#100,d3
	move.l	arpbase,a1
	jsr	-42(a6)		;Read 100 chars from file
	move.l	d0,chars

	move.l	fbuf,a0		;Dot ControlCodes before output
	move.l	#99,d0
l20:	move.b	(a0),d1
	bclr	#7,d1
	cmp.b	#$9,d1
	beq	l21
	cmp.b	#$a,d1
	beq	l21
	cmp.b	#$20,d1
	bhs	l21
	move.b	#'.',(a0)
l21:	addq.l	#1,a0
	dbra	d0,l20

	move.l	fbuf,a0		;Test if 26 lines has been displayed
	move.l	#99,d0
l9:	cmp.b	#$a,(a0)+
	bne	l8
	add.l	#1,d7
	cmp.b	#26,d7
	bne	l8
	move.l	#0,d7
l10:	btst	#10,$dff016
	beq	end
	btst	#6,$bfe001
	bne	l10
l8:	dbra	d0,l9

l6:	move.l	conhandle,d1
	move.l	fbuf,a0
	move.l	a0,d2
	move.l	chars,d3
	move.l	arpbase,a1
	jsr	-48(a6)		;Output text to window
	cmp.l	#100,chars
	bne	end
	btst	#10,$dff016
	beq	end
	bra	l7

end:	bra	new

nocclose:
	move.l	conhandle,d1
	move.l	arpbase,a6
	jsr	-36(a6)		;Close file

	move.l	$4,a6
	move.l	#200,d0
	move.l	mem,a1
	jsr	-210(a6)	;Free allocated memory

	move.l	arpbase,a6
	move.l	arpbase,a1
	moveq	#0,d0
	moveq	#0,d2
	jsr	-378(a6)	;Exit all
nomem:	rts


cls:
	dc.b	$c,$c
mem:
	dc.l	0
chars:
	dc.l	0
filehandle:
	dc.l	0
fre:
	dc.l	0

arpbase:
	dc.l	0

arp:
	dc.b	'arp.library',0
even
fbuf:
	dc.l	0
file:
	dc.l	0
text:
	dc.b	'Tiny View V0.5',0
even
conhandle:
	dc.l	0
con:
	dc.b	'CON:0/3/640/252/Right MB to terminate, Left MB to continue.',0
