
; ***********************************************************
; *                                                         *
; *    P L A T I N U M - M O R E - R E P L A C E M E N T    *
; *                                                         *
; *        P L U S  (File-Requester)  V E R S I O N         *
; *                                                         *
; *                        V 2.00                           *
; *                                                         *
; ***********************************************************
; *                                                         *
; *          Assembler-Source / Assembler: Devpac II        *
; *                                                         *
; *                    (C)March 1991 by                     *
; *                                                         *
; *                    Joerg Schliesser                     *
; *                  Platinum-Softwareline                  *
; *                   Rotenwaldstrasse 20                   *
; *                   D-7000 Stuttgart 1                    *
; *                         Germany                         *
; *                                                         *
; ***********************************************************

; *** Amiga OS-Routinen ***

	; Exec-Library
AllocMem	=	-198
FreeMem		=	-210
FindTask	=	-294
GetMsg		=	-372
ReplyMsg	=	-378
WaitPort	=	-384
CloseLibrary	=	-414
OpenLibrary	=	-552

	; Dos-Library
Open		=	-30
Close		=	-36
Read		=	-42
Write		=	-48
Lock		=	-84
UnLock		=	-90
DupLock		=	-96
Examine		=	-102
ExNext		=	-108
CurrentDir	=	-126
ParentDir	=	-210

	; Intuition-Library
AddGadget	=	-42
ClearPointer	=	-60
CloseWindow	=	-72
DrawImage	=	-114
OpenWindow	=	-204
PrintIText	=	-216
RefreshGadgets	=	-222
RemoveGadget	=	-228
SetPointer	=	-270
AutoRequest	=	-348

	; Graphics-Library
MovePen		=	-240
Draw		=	-246
RectFill	=	-306
WritePixel	=	-324
SetAPen		=	-342
ScrollRaster	=	-396

	; Konstanten
execbase	=	$4

; assembler-options

	section	programm,code	;one section, code, public_mem

; check WB- or CLI-start and get  WB-startup-message

start:
	move.l	sp,startsp	;save stackpointer 
	move.l	a0,memo1	;cli textpointer
	move.w	d0,memo2	;cli textlength
	move.l	4,a6
	suba.l	a1,a1		;get adress of PLTMore-Task
	jsr	FindTask(a6)
	move.l	d0,thistask

	lea	dosname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)		;open dos_lib
	move.l	d0,dosbase
	beq	quitpltmore

	lea	graphname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)		;open graph_lib
	move.l	d0,graphbase
	beq	quitpltmore

	lea	intuiname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)		;open intui_lib
	move.l	d0,intuibase
	beq	quitpltmore

	move.l	#44000,d0
	move.l	#$10001,d1
	jsr	AllocMem(a6)		;get diskmem (for filenames)
	move.l	d0,diskmem
	beq	quitpltmore

	move.l	#1024,d0
	move.l	#$10003,d1
	jsr	AllocMem(a6)		;get infomem (for fileinfos)
	move.l	d0,infomem
	beq	quitpltmore

	move.l	graphbase,a0	;get vertical standart resolution
	move.w	216(a0),wplt+6	;for opening window with max-size

	move.l	thistask,a4	;pointer to task struct
	tst.l	$ac(a4)		;started from CLI ?
	beq	wbstart

; get filename if started from CLI

	move.l	memo1,a0	;text-pointer
	move.w	memo2,d0	;text-length
	subq.w  #1,d0		;no text ?
	beq	nofile		;well then ... waiting
lforname:
	cmpi.b	#$20,(a0)+	;look for 'space'
	bne	foundname	;no space ... got beginning of filename
	dbra	d0,lforname
	bra	nofile		;no space ... no filename !
foundname:
	subq.l	#1,a0		;got filename
getfilename:
	lea	filename,a1	;adress of memory for filename
	cmp.b	#34,(a0)	;drop " - char at the beginning
	beq	dropfirst
	cmp.b	#39,(a0)	;drop ' - char at the beginning
	bne	copyname
dropfirst:
	adda.l	#1,a0
copyname:			;copy filename
	move.b	(a0)+,d1
	beq	eofname		;zero => end
	cmp.b	#10,d1
	beq	eofname		;linefeed => end
	cmp.b	#13,d1
	beq	eofname		;carriag return => end
	move.b	d1,(a1)+
	bra	copyname
eofname:
	clr.b	(a1)		;zero-byte to end filename
	cmp.b	#34,-(a1)	;drop " - char at the end
	beq	droplast
	cmp.b	#39,(a1)	;drop ' - char at the end
	bne	gotfilename
droplast:
	clr.b	(a1)
	bra	gotfilename

; get parameters if programm is started from wb

wbstart:
	lea	$5c(a4),a0	;pointer to task's message-port 
	jsr	Waitport(a6)	;wait for wb-start-message
	lea	$5c(a4),a0
	jsr	GetMsg(a6)	;get wb-start-message
	move.l	d0,startmsg
	beq	nofile		;no message ? ... strange !
	move.l	d0,a0
	cmp.l	#1,$1c(a0)	;number of arguments < 1 ... nofilename
	bls	nofile
	move.l	$24(a0),a2	;pointer to list of segments (picked icons)
	beq	nofile		;... very strange !
	move.l	8(a2),d1	;pointer to directory of text(?)-icon
	beq	noselectdir
	move.l	dosbase,a6
	jsr	CurrentDir(a6)	;actual dir => new dir
	move.l	d0,d1
	beq	noselectdir
	jsr	UnLock(a6)
noselectdir:
	move.l	12(a2),d0	;pointer to filename
	beq	nofile		;... no filename !
	move.l	d0,a0
	tst.b	(a0)		;get first character of filename
	beq	nofile		;... still very strange !
	bra	getfilename	;well then get the filename

; well ... now we open the window !

nofile:
	bset	#0,pltflag
gotfilename:
	move.l	intuibase,a6
	lea	wplt,a0		;open display-window
	jsr	OpenWindow(a6)
	move.l	d0,wdwhandle	;keep wdwhandle
	bne	gotpltwdw	;one window ! ... that's unbeliveable
	move.w	#200,wplt+6	;if opening the window failed, try to
	btst	#3,pltflag	;open one with 200 lines, but if the
	bne	quitpltmore	;2nd try failed too, then quit 
	bset	#3,pltflag	;the programm ... sorry !
	bra	gotfilename
gotpltwdw:
	move.l	d0,a0
	move.l	50(a0),wdwrast	;keep rastport
	bsr	dowindow	;draw the wonderful pltmore-window
	btst	#0,pltflag
	bne	loadrequest	;did we get one file to start ?

; now we load our text (?) - file

gotloadfile:
	bsr	pltworkon
	lea	filename,a0	;filename-pointer
	move.l	#$10001,d0	;type of memory: public/clear
	bsr	loadfile	;one file-load-routine
	move.l	d0,memlong	;keep length of data
	beq	loadferror	;data length = 0 ... really very strange !
	move.l	a0,membase	;data-adress-pointer
	clr.w	linecount	;clear line-counter
	bclr	#7,pltflag	;clear flag for scanning page
	bra	scanpage	;get adresses of lines

; we scann the text and print it on the screen !

newshowpage:
	bsr	scantabs	;get the possible tab positions
	bsr	dowindow	;redraw window (necessary in case of newsize)
	bsr	scanlength	;get length of page
	bsr	showpage	;show one whole page
	bset	#6,pltflag

; waiting for some user-request

loadferror:
	bsr	pltworkoff
waitmessage:
	move.l	4,a6
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window-user-port
	jsr	WaitPort(a6)	;waiting for intuimessage
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window user-port
	jsr	GetMsg(a6)	;get intuimessage
	tst.l	d0
	beq	waitmessage	;there wasn't one ... stra...
	move.l	d0,a1
	move.l	20(a1),d6	;get idcmp-code of event
	move.l	28(a1),a3	;get (possibly) adress of gadget
	move.w	24(a1),d5	;get (possibly) raw-key-code	
	move.w	26(a1),d4	;get (possibly) qualifier
	jsr	ReplyMsg(a6)	;and reply message
	cmp.l	#$4,d6		
	bne	norefreshmsg	;if there was a refresh-request
	btst	#6,pltflag
	bne	waitmessage
	bra	newshowpage	;we have to redraw the window
norefreshmsg:
	bclr	#6,pltflag
	cmp.l	#$2,d6
	bne	nosizemsg	;if the window was sized
	move.w	lines,d0	;get the total number of lines
	subq.w	#1,d0
	move.w	d0,maxline
	bsr	scanlength	;get length of new display
	move.w	pagelength,d0	;and get the number of the first line 
	sub.w	d0,maxline	;of the last display-page
	bpl	newshowpage
	clr.w	maxline
	bra	newshowpage	;and redraw the window
nosizemsg:
	cmp.l	#$40,d6
	bne	noupgadgetmsg	;wasn't any gadget at all
	cmpa.l	#gdgspcup,a3
	beq	upspacetab	;request for more spaces per tab
	cmpa.l	#gdgprint,a3
	beq	printtext	;request for printing text
	cmpa.l	#gdgspcdn,a3
	beq	dnspacetab	;request for less spaces per tab
	cmpa.l	#gdgexit,a3	;user selected exit-gadget ??
	beq	quitpltmore	;well ... may he/her be damned !
	cmpa.l	#gdgprevpage,a3	;request for previous page ?
	beq	showprevpage
	cmpa.l	#gdgprevline,a3	;request for previous line ?
	beq	showprevline
	cmpa.l	#gdgnextline,a3	;request for next line ?
	beq	shownextline
	cmpa.l	#gdgnextpage,a3	;request for next page ?
	beq	shownextpage
	cmpa.l	#gdgboftext,a3	;request for first page ?
	beq	firstpage
	cmpa.l	#gdgeoftext,a3	;request for last page ?
	beq	lastpage
	cmpa.l	#gdgsearchnext,a3	;request for next entry to search ?
	beq	searchnext
	cmpa.l	#gdgsearchprev,a3	;request for previous entry to search ?
	beq	searchprev
	cmpa.l	#gdgloadfile,a3	;request for new file to load ?
	bne	noloadtext
loadrequest:
	bsr	filerequest
	tst.l	d0
	beq	waitmessage
	bra	loadtextfile
noloadtext:
	cmpa.l	#gdghelp,a3	;request for help-window ?
	bne	waitmessage
	bsr	plthelp		;draw the help-window
	bra	waitmessage
noupgadgetmsg:
	btst	#0,d4
	bne	shifted		;was any shift-key pressed too ?
	btst	#1,d4
	bne	shifted
	cmp.w	#$45,d5
	beq	quitpltmore	;'esc' - quit programm ?
	cmp.w	#$3f,d5
	beq	showprevpage	;'9 / PgUp' - previous page ?
	cmp.w	#$4c,d5
	beq	showprevline	;'CRSR UP' - previous line ?
	cmp.w	#$3e,d5
	beq	showprevline	;'8 / up' - previous line ?
	cmp.w	#$4d,d5
	beq	shownextline	;'CRSR DN' - next line ?
	cmp.w	#$1e,d5
	beq	shownextline	;'2 / dn' - next line ?
	cmp.w	#$1f,d5
	beq	shownextpage	;'3 / PgDn' - next page ?
	cmp.w	#$3d,d5
	beq	firstpage	;'7 / Home' - first page ?
	cmp.w	#$1d,d5
	beq	lastpage	;'1 / End' - last page ?
	cmp.w	#$5f,d5
	bne	waitmessage
	bsr	plthelp		;'Help' - show help window
	bra	waitmessage
shifted:
	cmp.w	#$4c,d5
	beq	showprevpage	;'CRSR UP' - previous page ?
	cmp.w	#$4d,d5
	beq	shownextpage	;'CRSR DN' - next page ?
	cmp.w	#$36,d5
	beq	searchnext	;'N' - search next
	cmp.w	#$19,d5
	beq	searchprev	;'P' - search previous
	cmp.w	#$28,d5
	beq	loadrequest	;'L' - load textfile
	cmp.w	#$1b,d5
	beq	upspacetab	;'+' - add one space
	cmp.w	#$3a,d5
	beq	dnspacetab	;'-' - sub one space
	cmp.w	#$0b,d5
	beq	dnspacetab	;'ß' ('-' on US-keymap) - sub one space
	cmp.b	#$0c,d5
	beq	upspacetab	;''' ('+' on US-keymap) - add one space
	bra	waitmessage

; load one new text-file

loadtextfile:
	move.l	4,a6
	move.l	membase,a1
	move.l	memlong,d0
	beq	nooldfilemem
	jsr	FreeMem(a6)	;free old data memory
	clr.l	memlong
nooldfilemem:
	move.l	linemem,a1
	moveq	#0,d0
	move.w	lines,d0	;free old data for line-adresses
	beq	nooldlinemem
	asl.l	#2,d0
	jsr	FreeMem(a6)
	clr.w	lines
nooldlinemem:
	bsr	cleardisplay	;clear the display
	bra	gotloadfile

; clear text-display

cleardisplay:
	move.l	graphbase,a6
	move.l	wdwrast,a1
	moveq	#0,d0
	jsr	SetAPen(a6)	;set actual pen to background-color
	move.l	wdwhandle,a2
	move.l	wdwrast,a1
	moveq	#4,d0
	moveq	#32,d1
	move.w	8(a2),d2
	subq.w	#4,d2
	move.w	10(a2),d3	;clear text-display
	sub.w	#9,d3
	jsr	RectFill(a6)
	move.l	wdwrast,a1
	moveq	#4,d0
	move.w	10(a2),d1
	sub.w	#9,d1
	move.w	8(a2),d2
	sub.w	#16,d2
	move.w	10(a2),d3	;clear bottom of text-display
	subq.w	#2,d3
	jsr	RectFill(a6)
	rts

; quit this wonderfull program ...

quitpltmore:
	tst.l	startmsg
	beq	nousinglock
	move.l	dosbase,a6	;unlock used lock, if PLTMore was
	move.l	uselock,d1	;started from the workbench
	beq	nousinglock
	jsr	UnLock(a6)
nousinglock:
	move.l	intuibase,a6
	tst.l	wdwhandle
	beq	nowdwclose	;close PLTMore-window
	move.l	wdwhandle,a0
	jsr	CloseWindow(a6)
nowdwclose:	
	move.l	4,a6
	tst.w	lines
	beq	nolinememclear
	move.l	linemem,a1	;free memory for line-adresses
	moveq	#0,d0
	move.w	lines,d0
	asl.l	#2,d0
	jsr	FreeMem(a6)
nolinememclear:
	move.l	membase,a1
	move.l	memlong,d0
	beq	nomemtclr	;free memory for text
	jsr	FreeMem(a6)
nomemtclr:
	move.l	4,a6
	tst.l	dosbase
	beq	nodropdos
	move.l	dosbase,a1
	jsr	CloseLibrary(a6)	;close dos_lib
nodropdos:
	tst.l	graphbase
	beq	nodropgraph
	move.l	graphbase,a1
	jsr	CloseLibrary(a6)	;close graph_lib
nodropgraph:
	tst.l	intuibase
	beq	nodropintui
	move.l	intuibase,a1
	jsr	CloseLibrary(a6)	;close intui_lib
nodropintui:
	tst.l	diskmem
	beq	nodropdiskmem
	move.l	#44000,d0
	move.l	diskmem,a1
	jsr	FreeMem(a6)	;drop diskmem
nodropdiskmem:
	tst.l	infomem
	beq	nodropinfomem
	move.l	#1024,d0
	move.l	infomem,a1
	jsr	FreeMem(a6)	;drop infomem
nodropinfomem:
	tst.l	startmsg
	beq	quitpltmoreprog
	move.l	startmsg,a1	
	jsr	ReplyMsg(a6)	;reply wb-start-message
quitpltmoreprog:
	moveq	#0,d0
	moveq	#0,d1
	move.l	startsp,sp
	rts			;and ... that's the end of PLTMore

; loadfile-routine, gets length of file, allocates mem and finally loads it

loadfile:
	move.l	a0,a5		;keep pointer to filename
	move.l	d0,d5		;keep mem-type
	move.l	dosbase,a6
	move.l	a5,d1
	moveq	#-2,d2		;lock-mode = -2 ... read !
	jsr	Lock(a6)	;get filelock
	move.l	d0,d7		;keep pointer to filelock
	beq	lerror1		;no lock ... error !
	move.l	dosbase,a6
	move.l	d7,d1		;filelock
	move.l	infomem,d2	;info-memory
	jsr	Examine(a6)	;examine file-info-data
	tst.l	d0		;d0 = 0 ? ... Error !
	beq	lerror1
	move.l	d7,d1		;drop filelock
	jsr	UnLock(a6)
	move.l	infomem,a3
	move.l	124(a3),d0	;get length of file
	addq.l	#2,d0		;we want some zero-bytes at the end
	move.l	4,a6
	move.l	d5,d1		;get requested mem-type
	jsr	AllocMem(a6)	;allocate memory
	move.l	d0,a2		;keep memory-pointer
	tst.l	d0		;no memory ... error !
	beq	lerror1
	move.l	a5,d1		;filename-pointer
	move.l	#1005,d2	;open-mode: old
	move.l	dosbase,a6
	jsr	Open(a6)	;open file
	move.l	d0,d4		;keep filehandle
	beq	lerror1		;filehandle = 0 ? ... error !
	move.l	d0,d1
	move.l	a2,d2		;memory-pointer
	move.l	124(a3),d3	;length of file
	jsr	Read(a6)	;read file
	move.l	d4,d1
	jsr	Close(a6)	;close file
	move.l	124(a3),d4	;keep length of file
	addq.l	#2,d4		;we still want some zero-bytes at the end
	move.l	a2,a0		;data-pointer in a0
	move.l	d4,d0		;length of data in d0
exitloadfile:
	rts			;we are ready !
lerror1:
	moveq	#0,d0		;d0 = 0 ... that means one error
	bra	exitloadfile	;and we are ready too !

; display the wonderfull PLTMore-help-window

plthelp:
	move.l	intuibase,a6
	lea	wabout,a0	;open help-window
	jsr	OpenWindow(a6)
	move.l	d0,d7		;keep wdwhandle
	beq	quitplthelp	;no window ! ... that's unbeliveable
	move.l	graphbase,a6
	move.l	d7,a1
	move.l	50(a1),a1
	moveq	#2,d0		;set pen to color 2
	jsr	SetAPen(a6)
	move.l	d7,a1
	move.l	50(a1),a1
	moveq	#2,d0		;rect allmost the whole window
	moveq	#1,d1
	move.w	#537,d2
	move.w	#188,d3
	jsr	RectFill(a6)
	move.l	intuibase,a6
	moveq	#5,d3		;y-pos of first line
	lea	helptx,a5	;pointer to help-lines
	moveq	#19,d5		;20 lines to print
plthelploop1:
	lea	texttext,a4	;memory for text-line
	moveq	#-1,d6		;counter for length to pre-zero
plthelploop2:
	addq.w	#1,d6		;count one more character
	move.b	(a5)+,(a4)+	;copy it
	bne	plthelploop2	;not zero ... go on copying
	asl.w	#3,d6		;8 points per char 
	move.w	#540,d0		;width of window
	sub.w	d6,d0		;sub width of text
	lsr.w	#1,d0		;and divide through 2 to center
	move.l	d7,a0
	move.l	50(a0),a0	;window-rastport
	lea	textline,a1	;text-struct
	move.b	#2,1(a1)	;set background-color to color 2
	move.l	d3,d1		;get y-pos
	jsr	PrintIText(a6)	;and print the line
	add.w	#9,d3		;add 9 to y-pos
	dbra	d5,plthelploop1	;and go on printing
	lea	textline,a1	;as the same text-struct is used to display
	clr.b	1(a1)		;the 'real' text reset back-col to 0
	bclr	#2,pltflag	;clear flag (see below for the sense of it)
plthelpwait:
	move.l	4,a6
	move.l	d7,a0
	move.l	86(a0),a0	;window-user-port
	jsr	WaitPort(a6)	;wait for message ... task is sleeping
	move.l	d7,a0
	move.l	86(a0),a0
	jsr	GetMsg(a6)	;now ... there's one user-request !
	tst.l	d0
	beq	plthelpwait	;no ...there's none ... (...strange!)
	move.l	d0,a1
	move.l	20(a1),d6	;get idcmp of message-cause
	jsr	ReplyMsg(a6)	;and send message back
	cmp.l	#$8,d6		;did the user (got bless him/her)
	beq	helpmousepick	;press one mouse-button ?
	btst	#2,pltflag	;drop the first key, which possibly opened
	bne	helpmousepick	;the window (a strange way to avoid that
	bset	#2,pltflag	;the window is closed at once if it was
	bra	plthelpwait	;called with the help-key)
helpmousepick:
	move.l	intuibase,a6
	move.l	d7,a0
	jsr	CloseWindow(a6)
quitplthelp:
	rts

; display the wonderfull PLTMore-window

dowindow:
	lea	rects,a5	;table of rects
	moveq	#16,d7		;number of rects -1
dorecting:
	move.l	graphbase,a6
	move.l	wdwrast,a1
	move.w	(a5)+,d0	;read color of rect to paint
	jsr	SetAPen(a6)
	move.l	wdwrast,a1
	move.w	(a5)+,d0
	move.w	(a5)+,d1	;read dimensions of actual rect
	move.w	(a5)+,d2
	move.w	(a5)+,d3
	jsr	RectFill(a6)	;and finaly do it !
	dbra	d7,dorecting
	bsr	cleardisplay
	move.l	intuibase,a6
	lea	gdgexit,a0
	move.l	wdwhandle,a1
	move.l	#0,a2		;now we redraw the (text-) gadgets
	jsr	RefreshGadgets(a6)
	moveq	#25,d0
	lea	filename,a0
	lea	tx4,a1
copdofname:
	move.b	(a0)+,(a1)+
	dbra	d0,copdofname
	lea	texte,a5	;table of texts
	moveq	#4,d7		;number of texts -1
dotexting:
	move.l	wdwrast,a0
	lea	txtext,a1	;get text-struct
	move.b	#1,(a1)
	move.b	#0,2(a1)	;drawmode: jam1
	move.l	(a5)+,d0	;read x-pos of text
	move.l	(a5)+,d1	;read y-pos of text
	move.l	(a5)+,txtextpoint	;adress of textline
	jsr	PrintIText(a6)	;and print it !
	dbra	d7,dotexting
	rts

; get the line adresses of one wonderfull text

scanpage:
	bsr	scanlength	;at first get the length of one page
	move.l	linemem,a4	;memory for line-adresses
	move.l	membase,a5	;data-memory
	btst	#7,pltflag	;first scan: only counting the lines
	beq	firstscan1
	move.l	a5,(a4)+	;first line is at zero-pos
firstscan1:
	moveq	#0,d5		;clear line-counter
	clr.w	maxline		;clear number of last line
scanpageloop:
	cmp.b	#10,(a5)
	beq	gotlinefeed	;is there one linefeed ?
	cmp.b	#13,(a5)
	beq	gotcarriage	;is there one carriage ?
	tst.b	(a5)+
	bne	scanpageloop	;we are not at the end of the text now !
ermitend:
	btst	#7,pltflag	;first scan: counting the lines
	beq	firstscan2
	move.w	pagelength,d0	;get the number of the first line 
	sub.w	d0,maxline	;of the last display-page
	bpl	longtext1
	clr.w	maxline
longtext1:
	bsr	pltworkoff
	bra	newshowpage	;ready scanning the page, now show it!
firstscan2:
	bset	#7,pltflag	;set flag for second scan
	move.l	4,a6
	moveq	#1,d0
	add.w	maxline,d0
	move.w	d0,lines	;get memory for adresses of lines
	asl.l	#2,d0
	move.l	#$10001,d1
	jsr	AllocMem(a6)
	move.l	d0,linemem	;no memory ??? ... damned !
	beq	quitpltmore
	bra	scanpage	;now second scan ... getting adresses
gotlinefeed:
gotcarriage:
	adda.l	#1,a5		;add one to get adress of the next line
	btst	#7,pltflag	;first scan: only counting
	beq	firstscan3
	move.l	a5,(a4)+	;keep the adress
firstscan3:
	addq.w	#1,maxline	;count the lines
	bra	scanpageloop	;goon scanning the page

; get length of display-page

scanlength:
	move.l	wdwhandle,a0
	moveq	#0,d0
	move.w	10(a0),d0	;get window height
	sub.w	#40,d0		;sub 40 lines for gadgets and border
	divu	#9,d0		;divide through 9 to get length
	move.w	d0,pagelength	;of page
	rts

; get the tab-positions in a line

scantabs:
	lea	tabmem,a0	;pointer to memory of tabs
	move.l	a0,a1
	moveq	#19,d0
cleartabs:
	clr.l	(a1)+		;clear memory for tab-positions
	dbra	d0,cleartabs
	move.b	spacecount,d0	;read the spaces per tab value
	moveq	#79,d2		;get the last possible tab-position
	sub.b	d0,d2		;within a line of a length of 79 chars
	move.b	d0,d1
scannintab:
	move.b	d1,(a0)+	;write actual tab-position in memory
	add.b	d0,d1		;add the spaces per tab value
	cmp.b	d2,d1		;and go on until the last tab-position
	bls	scannintab	;is passed
	clr.b	(a0)		;zero-byte at the end of tab-pos-table
scantabout:
	move.l	intuibase,a6
	move.l	wdwrast,a0	;print the spaces per tab value
	lea	txtext,a1
	lea	tx3,a2		;on the screen
	move.b	spacecount,8(a2)
	add.b	#48,8(a2)
	move.b	#1,2(a1)	;drawmode: jam2
	move.b	#2,1(a1)	;back-color
	move.w	#498,d0
	moveq	#22,d1
	move.l	a2,txtextpoint
	jsr	PrintIText(a6)
	rts

; look for the previous or next appearance of the selected 'search-text'

searchprev:
	bset	#1,pltflag	;set flag for searching the previous
	bra	searcher
searchnext:
	bclr	#1,pltflag	;set flag for searching the next
searcher:
	bsr	pltworkon
	move.w	linecount,memo2	;remember actual line
searchon:
	move.l	linemem,a4
	moveq	#0,d6		;get memory-pointer to first
	move.w	linecount,d6
	asl.l	#2,d6		;character of the actual line
	adda.l	d6,a4
	move.l	(a4),a5
	bsr	searchline	;and search this line
	tst.b	d7
	bne	foundthisline	;text was found in this line or not ?
	btst	#1,pltflag
	bne	searchingprev	;if the text wasn't found and we are
	move.w	maxline,d0	
	add.w	pagelength,d0	;searching next then look if there is
	cmp.w	linecount,d0
	beq	nosearchnextline	;a next line to scan
	addq.w	#1,linecount
	bra	searchon	;and then go on searching
searchingprev:
	tst.w	linecount	;if we are searching previous then
	beq	nosearchnextline
	subq.w	#1,linecount	;look if there is a previous line
	bra	searchon
foundthisline:
	move.l	a5,searchfound	;keep the adress of text we found and
	move.w	linecount,foundline	;number of the line
	bsr	showpage	;and show the page
	move.l	graphbase,a6
	move.l	wdwrast,a1
	moveq	#3,d0		;set color to 3 to underline
	jsr	SetAPen(a6)
	move.l	wdwrast,a1
	move.w	searchlinea,d0	;set pen to beginning of the
	moveq	#40,d1
	jsr	MovePen(a6)	;first char of text
	move.l	wdwrast,a1
	move.w	searchlineb,d0
	moveq	#40,d1		;and the underline it
	jsr	Draw(a6)
	bra	readysearching	;ready !
nosearchnextline:
	move.w	memo2,linecount	;if text wasn't found
	bsr	showpage	;redisplay original page
readysearching:
	bsr	pltworkoff
	bra	waitmessage

; look if requested text appears in this line

searchline:
	moveq	#0,d7
	lea	searchtext,a4	;pointer text
	moveq	#0,d4
getsearchlength:
	addq.b	#1,d4		;get length of requested text plus 1
	tst.b	(a4)+
	bne	getsearchlength
	cmp.b	#1,d4		;length = 1 => no text
	beq	emptysearch	
	moveq	#0,d2		;counter for actual position in line
searchline1:
	addq.b	#1,d2
	move.l	a5,a3		;get actual start-position for searching
	cmp.b	#9,(a3)		;look for 'tab' -char
	bne	notabinsearch
	lea	tabmem,a0	;get table of tab-positions
searchgettabs:
	move.b	(a0)+,d0	;no more tabs ... we are ready
	beq	notabinsearch
	cmp.b	d0,d2		;found tab at the actual pos ?
	beq	notabinsearch
	bge	searchgettabs	;pos is behind tab ? ... go on looking
foundsearchtab:
	cmp.b	d0,d2		;if actual pos = tab-pos
	beq	notabinsearch	;we ar ready
	addq.b	#1,d2		;if not add one pos to counter until
	bra	foundsearchtab	;actual pos = tab-pos
notabinsearch:
	lea	searchtext,a4	;pointer to requested text
	move.l	d4,d3
	subq.l	#2,d3		;length minus 2
searchline2:
	move.b	(a3)+,d0	;get actual char in text
	beq	searchlineend
	cmp.b	#10,d0		;zero, linefeed and carriage return
	beq	searchlineend
	cmp.b	#13,d0		;reports end of line
	beq	searchlineend
	bclr	#5,d0		;search-routine is not to be case sensitive
	move.b	(a4)+,d1	;get next char of requested text
	bclr	#5,d1		;not case sensitive
	cmp.b	d0,d1
	bne	notsearchfound	;are the two characters equal ?
	dbra	d3,searchline2	;go on searching
	move.w	memo2,d0
	cmp.w	linecount,d0	;if actual line is first line which was
	bne	nochecksame	;was searched, no check is made
	cmpa.l	searchfound,a5	;if the position of found text is equal to
	beq	notsearchfound	;the last one nothing of interest was found
	move.w	foundline,d0
	cmp.w	linecount,d0
	beq	notsearchfound
nochecksame:
	asl.w	#3,d2
	subq.w	#6,d2
	move.w	d2,searchlinea	;get start and end position of line
	move.w	d2,searchlineb
	subq.w	#1,d4		;to mark the text
	asl.w	#3,d4
	add.w	d4,searchlineb
	moveq	#1,d7
	rts
notsearchfound:
	adda.l	#1,a5		;add one to text-pointer to compare
	bra	searchline1	;and go on searching
searchlineend:
emptysearch:
	rts

; increase spaces per tab value

upspacetab:
	cmp.b	#9,spacecount	;maximum is 9 spaces per tab
	beq	waitmessage
	addq.b	#1,spacecount
	bra	newshowpage

; print text to prt:

printtext:
	move.l	dosbase,a6
	move.l	#prtname,d1
	move.l	#1006,d2	;Mode: NEW
	jsr	Open(a6)	;open prt: for output
	move.l	d0,prthandle
	beq	waitmessage
	bsr	pltworkon	;turn on sleeping-pointer
	move.w	linecount,prtcount
printtextloop:
	move.l	linemem,a4
	moveq	#0,d5
	move.w	prtcount,d5	;get adress of first char of 
	asl.l	#2,d5
	add.l	d5,a4
	move.l	(a4),a5		;line to be shown
	bsr	getline
	lea	texttext,a0
	move.b	#13,79(a0)	;linefeed and
	move.b	#10,80(a0)	;carriage-return at the end of the line
	move.l	dosbase,a6
	move.l	prthandle,d1
	move.l	a0,d2
	moveq	#81,d3		;print line to prt:
	jsr	Write(a6)
	move.l	4,a6
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window user-port
	jsr	GetMsg(a6)	;get intuimessage
	tst.l	d0
	beq	noprintstop	;and look if a gadget or a key was
	move.l	d0,a1		;pressed to abort printing
	move.l	20(a1),d7
	jsr	ReplyMsg(a6)	;and reply message
	cmp.l	#$40,d7
	beq	printoutend
	cmp.l	#$400,d7
	beq	printoutend
noprintstop:
	addq.w	#1,prtcount
	move.w	maxline,d0
	add.w	pagelength,d0	;go on printing untill the end
	cmp.w	prtcount,d0
	bls	printoutend	;of the text
	bra	printtextloop
printoutend:
	bsr	pltworkoff
	lea	texttext,a0
	clr.b	79(a0)
	move.l	dosbase,a6
	move.l	prthandle,d1	;close prt:
	jsr	Close(a6)
	bra	waitmessage	

;decrease spaces per tab value

dnspacetab:
	cmp.b	#1,spacecount	;minimum ist 1 space per tab
	beq	waitmessage
	subq.b	#1,spacecount
	bra	newshowpage

;show first page of text

firstpage:
	clr.w	linecount
	bsr	showpage
	bra	waitmessage

;show last page of text

lastpage:
	move.w	maxline,linecount
	bsr	showpage
	bra	waitmessage

;show previous page of text

showprevpage:
	tst.w	linecount
	beq	waitmessage
	move.w	pagelength,d0	;look if there is another previous
	subq.w	#1,d0
	cmp.w	linecount,d0	;page to show
	bls	okshowprevpage
	move.w	d0,linecount	;if not ... show the first page
okshowprevpage:
	sub.w	d0,linecount
	bsr	showpage
	bra	waitmessage

;show next page of text

shownextpage:
	move.w	maxline,d0	;look if there is another
	cmp.w	linecount,d0
	beq	waitmessage
	move.w	pagelength,d1
	subq.w	#1,d1		;page to show
	add.w	d1,linecount
	cmp.w	linecount,d0	;if not ... show the last page
	bge	okshownextpage
	move.w	maxline,linecount
okshownextpage:
	bsr	showpage
	bra	waitmessage

;show previous line of text

showprevline:
	tst.w	linecount	;we are still at the beginning of
	beq	waitmessage	;of the text ?
	subq.w	#1,linecount	;if not, decrease the line number
	move.l	wdwrast,a1
	move.l	wdwhandle,a0
	moveq	#0,d0
	moveq	#-9,d1		;scroll down text-display one line
	moveq	#4,d2
	moveq	#32,d3
	move.w	8(a0),d4
	subq.w	#4,d4
	move.w	10(a0),d5
	sub.w	#9,d5
	move.l	graphbase,a6
	jsr	ScrollRaster(a6)
	bsr	getlineadress
	moveq	#32,d3
	bsr	showline	;and print it
	bra	waitmessage

getlineadress:
	move.l	linemem,a4
	moveq	#0,d5
	move.w	linecount,d5	;get adress of first char of
	asl.l	#2,d5
	adda.l	d5,a4
	move.l	(a4),a5		;line to be shown
	rts

; show next line of text

shownextline:
	move.w	maxline,d0	;look if there is another line
	cmp.w	linecount,d0
	bls	waitmessage	;to show ?
	addq.w	#1,linecount
	move.l	wdwrast,a1
	move.l	wdwhandle,a0
	moveq	#0,d0
	moveq	#9,d1		;scroll up text-display one line
	moveq	#4,d2
	moveq	#32,d3
	move.w	8(a0),d4
	subq.w	#4,d4
	move.w	10(a0),d5
	sub.w	#9,d5
	move.l	graphbase,a6
	jsr	ScrollRaster(a6)
	move.l	linemem,a4
	moveq	#0,d5
	move.w	linecount,d5
	add.w	pagelength,d5
	subq.w	#1,d5		;get adress of first char of 
	asl.l	#2,d5
	adda.l	d5,a4
	move.l	(a4),a5		;line to be shown
	moveq	#32,d3
	moveq	#0,d2
	move.w	pagelength,d2
	subq.w	#1,d2
	mulu	#9,d2
	add.w	d2,d3		;and print it
	bsr	showline
	bra	waitmessage

;show one page of text, beginning with the actual line

showpage:
	bsr	cleardisplay
	bsr	getlineadress
	move.w	pagelength,d5	;get number of lines to show
	subq.w	#1,d5
	moveq	#32,d3		;first y-pos is 32
	moveq	#0,d6		;count the lines (necessary for displaying
showpageloop:			;lines of the last page on the first
	bsr	showline	;display-line if 'search' found s.th.
	adda.l	#1,a5		;within these lines
	add.w	#9,d3
	addq.w	#1,d6
	move.w	linecount,d0
	add.w	d6,d0		;if displaying passed the last line
	move.w	maxline,d1	;(reason for this see above)
	add.w	pagelength,d1
	cmp.w	d1,d0
	bge	endtext		;abord displaying the lines
	cmp.w	lines,d0
	bge	endtext
	dbra	d5,showpageloop
endtext:
	rts

; convert one line of text into puffer

getline:
	lea	texttext,a4	;memory in intuitext-struct
	moveq	#78,d4		;display a maximum of 79 characters
	moveq	#0,d7		;count the characters
showlloop:
	move.b	(a5),d0		;read next character
	cmp.b	#9,d0
	beq	foundtabu	;is this one tab ???
	cmp.b	#10,d0
	beq	linefeed
	cmp.b	#13,d0		;or even the end of the line ???
	beq	carriage
	tst.b	d0
	beq	linefeed
	move.b	(a5)+,(a4)+	;copy character and
	addq.b	#1,d7
	dbra	d4,showlloop	;go on scanning the text
	bra	lineready
foundtabu:
	adda.l	#1,a5
dotabin:			;if a tab is found add spaces
	move.b	#32,(a4)+	
	addq.b	#1,d7
	dbra	d4,tabon
	bra	lineready	;until the next tab-pos
tabon:
	lea	tabmem,a0
gettabsloop:			;is reached
	move.b	(a0)+,d0
	beq	dotabin
	cmp.b	d0,d7
	beq	showlloop
	bra	gettabsloop
linefeed:
carriage:
	move.b	#32,(a4)+	;fill up the rest of the line
	dbra	d4,carriage	;with spaces
lineready:
	rts

;show one line of text, terminated by linefeed of carriage return

showline:
	bsr	getline
	move.l	wdwhandle,a0
	lea	texttext,a1
	move.w	8(a0),d0
	lsr.w	#3,d0
	clr.b	-1(a1,d0)
	move.l	intuibase,a6
	move.l	wdwrast,a0
	lea	textline,a1	;and then print the line
	move.l	d3,d1
	moveq	#5,d0
	jsr	PrintIText(a6)


; show actual position and last page-beginning-position
posanzeige:
	lea	postxt,a0
	moveq	#0,d0
	moveq	#16,d1
	move.w	linecount,d0	;convert actual line
	divu	#10000,d0
	addi.b	#48,d0
	move.b	d0,4(a0)
	lsr.l	d1,d0		;into ASCII-text
	divu	#1000,d0
	addi.b	#48,d0
	move.b	d0,5(a0)
	lsr.l	d1,d0
	divu	#100,d0
	addi.b	#48,d0
	move.b	d0,6(a0)
	lsr.l	d1,d0
	divu	#10,d0
	addi.b	#48,d0
	move.b	d0,7(a0)
	lsr.l	d1,d0
	addi.b	#48,d0
	move.b	d0,8(a0)
	moveq	#0,d0
	move.w	maxline,d0
	divu	#10000,d0	;convert beginning-line of the
	addi.b	#48,d0
	move.b	d0,10(a0)
	lsr.l	d1,d0
	divu	#1000,d0
	addi.b	#48,d0
	move.b	d0,11(a0)
	lsr.l	d1,d0
	divu	#100,d0
	addi.b	#48,d0		;last page into ASCII-text
	move.b	d0,12(a0)
	lsr.l	d1,d0
	divu	#10,d0
	addi.b	#48,d0
	move.b	d0,13(a0)
	lsr.l	d1,d0
	addi.b	#48,d0
	move.b	d0,14(a0)
	move.l	wdwrast,a0
	move.l	intuibase,a6
	lea	postext,a1	;and print them
	moveq	#0,d1
	moveq	#0,d0
	jsr	PrintIText(a6)
	rts

; variables, texts, names, flags, handles, pointers and so on ...

searchtext:	ds.b	42	;memory for text to be searches
		even
tabmem:		ds.b	82	;memory for tabulator positions
		even
dosname:	dc.b	"dos.library",0
		even
intuiname:	dc.b	"intuition.library",0
		even
graphname:	dc.b	"graphics.library",0
		even
prtname:	dc.b	"prt:",0
		even
dosbase:	dc.l	0
intuibase:	dc.l	0
graphbase:	dc.l	0
diskmem:	dc.l	0
infomem:	dc.l	0
wdwhandle:	dc.l	0	;windowhandle
wdwrast:	dc.l	0	;windowrastport
linemem:	dc.l	0	;pointer to memory to keep line adresses
lines:		dc.w	0	;number of lines
thistask:	dc.l	0	;pointer to task struct
startsp:	dc.l	0	;stackpointer when programm is started
startmsg:	dc.l	0	;wb-startup-message-handle
membase:	dc.l	0	;pointer to memory keeping the text
memlong:	dc.l	0	;length of the text
searchfound:	dc.l	0	;pointer to last succesfull search
memo1:		dc.l	0	;one longword to keep s.th. in
memo2:		dc.w	0	;one word to keep s.th. in
foundline:	dc.w	0	;number of line with succesfull search
linecount:	dc.w	0	;actual line-number
maxline:	dc.w	0	;maximum line-number
pagelength:	dc.w	0	;length of display-page
searchlinea:	dc.w	0	;beginning pos of line to underline
searchlineb:	dc.w	0	;ending pos of line to underline
prthandle:	dc.l	0
prtcount:	dc.w	0
spacecount:	dc.b	8	;spaces per tab value
pltflag:	dc.b	0	;one byte to keep s.th. in
		even

;table of dimensions of the rectangles that make the window-look

rects:	dc.w	1,0,10,639,30
	dc.w	2,2,11,47,19
	dc.w	2,50,11,93,19
	dc.w	2,96,11,179,19
	dc.w	0,182,11,394,19
	dc.w	2,497,11,637,19
	dc.w	2,2,21,36,29
	dc.w	2,39,21,66,29
	dc.w	2,69,21,91,29
	dc.w	2,94,21,115,29
	dc.w	2,118,21,147,29
	dc.w	2,150,21,179,29
	dc.w	2,497,21,637,29
	dc.w	2,182,21,266,29
	dc.w	2,269,21,351,29
	dc.w	0,354,21,494,29
	dc.w	2,397,11,493,19

;table of texts and their positions that make the window-look

texte:	dc.l	8,12,tx1,12,22,tx2,498,22,tx3,186,12,tx4,409,12,tx0

tx0:	dc.b	"PRINT TEXT",0
	even
tx1:	dc.b	"EXIT  HELP  LOAD FILE",0
	even
tx2:	dc.b	"[<  <<  <  >  >>  >]  SEEK PREV  SEEK NEXT",0
	even
tx3:	dc.b	"SPC/TAB:8|UP|DN",0
	even
tx4:	ds.b	28


;help-message

helptx:
 dc.b	"-----===== Platinum-More-Replacement - PLTMore+ =====-----",0
 dc.b	"© 1991 by Joerg Schliesser / Platinum Softwareline",0
 dc.b	"Rotenwaldstrasse 20 / D-7000 Stuttgart 1 / Germany",0
 dc.b	"PLTMore is freely distributable (also on commercially",0
 dc.b	"distributed disks) as long as this text remains unchanged",0
 dc.b	" ",0
 dc.b	"PLTMore keyboard command summary:",0
 dc.b	"Show first page .................................... 7/Home",0
 dc.b	"Show last page ...................................... 1/End",0
 dc.b	"Show next page ................. Shift & CRSR Dn or 3/Pg Dn",0
 dc.b	"Show previous page ............. Shift & CRSR Up or 9/Pg Up",0
 dc.b	"Show next line ............................ CRSR Dn or 2/Dn",0
 dc.b	"Show previous line ........................ CRSR Up or 8/Up",0
 dc.b	"Seek next ....................................... Shift & N",0
 dc.b	"Seek previous ................................... Shift & P",0
 dc.b	"Load textfile ................................... Shift & L",0
 dc.b	"Add one more space per tab ...................... Shift & +",0
 dc.b	"Sub one space per tab ........................... Shift & -",0
 dc.b	"Quit PLTMore .......................................... Esc",0
 dc.b	"To close this window press any key or mouse button",0
	even

;window-structs

wplt:
	dc.w	0,0,640,200	;x,y,w,h
	dc.b	2,1		;colors
	dc.l	$446		;idcmp,rawkey,upgadget,newsize,refresh
	dc.l	$2011007	;activ,rmbtrap,front/back,sizing,drag
	dc.l	gdgexit,0,wplttitle,0,0
	dc.w	80,60,640,512
	dc.w	1
wplttitle:
 dc.b "PLTMore+ V2.0 © 1991 by Joerg Schliesser / Platinum Softwareline",0
	even

wabout:
	dc.w	49,5,540,190	;x,y,w,h
	dc.b	2,1		;colors
	dc.l	$408		;idcmp,rawkey,mousebuttons
	dc.l	$2011000	;activ,rmbtrap,borderless
	dc.l	0,0,0,0,0,0,0
	dc.w	1

; gadget structs

gdgexit:
	dc.l	gdgloadfile
	dc.w	2,11,46,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	1
	dc.l	0
gdgloadfile:
	dc.l	gdgboftext
	dc.w	96,11,84,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	2
	dc.l	0
gdgboftext:
	dc.l	gdgprevpage
	dc.w	2,21,35,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	3
	dc.l	0
gdgprevpage:
	dc.l	gdgprevline
	dc.w	39,21,28,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	4
	dc.l	0
gdgprevline:
	dc.l	gdgnextline
	dc.w	69,21,23,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	5
	dc.l	0
gdgnextline:
	dc.l	gdgnextpage
	dc.w	94,21,22,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	6
	dc.l	0
gdgnextpage:
	dc.l	gdgeoftext
	dc.w	118,21,30,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	7
	dc.l	0
gdgeoftext:
	dc.l	gdgsearchtext
	dc.w	150,21,30,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	8
	dc.l	0
gdgsearchtext:
	dc.l	gdgspcup
	dc.w	356,22,136,8,0,2,4
	dc.l	0,0,0,0,searchtextgdginfo
	dc.w	9
	dc.l	0
searchtextgdginfo:
	dc.l	searchtext,0
	dc.w	0,40,0,0,0,0,0,0
	dc.l	0,0,0
gdgspcup:
	dc.l	gdgspcdn
	dc.w	575,21,23,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	10
	dc.l	0
gdgspcdn:
	dc.l	gdgsearchprev
	dc.w	599,21,23,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	11
	dc.l	0
gdgsearchprev:
	dc.l	gdgsearchnext
	dc.w	182,21,85,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	12
	dc.l	0
gdgsearchnext:
	dc.l	gdghelp
	dc.w	269,21,83,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	13
	dc.l	0
gdghelp:
	dc.l	gdgprint
	dc.w	50,11,44,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	14
	dc.l	0
gdgprint:
	dc.l	0
	dc.w	397,11,97,9,0,1,1
	dc.l	0,0,0,0,0
	dc.w	15
	dc.l	0

; text-structs

postext:
	dc.b	1,2,1
	even
	dc.w	499,12
	dc.l	0,postxt,0
postxt:	dc.b	"POS:00000/00000",0
	even

textline:
	dc.b    1,0,1
	even
	dc.l	0,0,texttext,0
texttext:	ds.b	82

; display rendered fields (field-table => a5, number of fields => d7)

dofields:
	move.l	graphbase,a6
fielding:
	move.w	(a5)+,d4	;x-pos
	move.w	(a5)+,d5	;y-pos
	move.w	(a5)+,d6	;width of field
	move.w	(a5)+,fieldheight	;height of field
	move.l	dorast,a1	;get rastport
	moveq	#1,d0
	jsr	SetAPen(a6)	;set color for outline
	move.l	dorast,a1
	move.w	d4,d0
	move.w	d5,d1
	move.w	d4,d2
	move.w	d5,d3
	add.w	d6,d2
	add.w	fieldheight,d3
	jsr	RectFill(a6)	;draw outline of field
	move.l	dorast,a1
	move.w	(a5)+,d0
	jsr	SetAPen(a6)	;set color for field
	move.l	dorast,a1
	move.w	d4,d0
	move.w	d5,d1
	move.w	d4,d2
	move.w	d5,d3
	add.w	#2,d0
	add.w	#1,d1
	add.w	d6,d2
	add.w	fieldheight,d3
	sub.w	#2,d2
	sub.w	#1,d3		;draw field
	jsr	RectFill(a6)
	dbra	d7,fielding	;go on...
	rts			

; print some texts (table of texts => a5, number of texts => d7)

dotexts:
	move.l	intuibase,a6
texting:
	move.l	dorast,a0	;get rastport
	lea	txtext,a1
	move.w	(a5)+,d0	;get x-pos
	move.w	(a5)+,d1	;get y-pos
	move.l	(a5)+,txtextpoint	;pointer to ascii-text
	jsr	PrintIText(a6)	;print it ...
	dbra	d7,texting
	rts

; request one file-selection

filerequest:
	clr.b	infoflag	;don't disply '.info'-files
	clr.w	iactiv		;and unselect the gadgets
	move.l	intuibase,a6
	lea	filewdw,a0
	jsr	OpenWindow(a6)	;try to open requester-window
	move.l	d0,filewdwhandle
	beq	filewindopenerror
	move.l	d0,a0
	move.l	50(a0),filerast	;keep the rastport
	lea	filefields,a5
	moveq	#19,d7
	move.l	filerast,dorast
	bsr	dofields	;display fields for file-requester
	lea	filetexte,a5
	moveq	#16,d7
	bsr	dotexts		;display texts for file-requester
	lea	parentgdg,a0
	move.l	filewdwhandle,a1
	move.l	#0,a2		;remake the gadgets (... strings)
	jsr	RefreshGadgets(a6)
	bsr	showdir		;display the old directory
filewait:
	move.l	4,a6
	move.l	filewdwhandle,a0
	move.l	86(a0),a0
	jsr	WaitPort(a6)	;wait for user-action
	move.l	filewdwhandle,a0
	move.l	86(a0),a0
	jsr	GetMsg(a6)	;get the message ...
	tst.l	d0
	beq	filewait	;if there was one ...
	move.l	d0,a1
	cmp.l	#$8,20(a1)	;mouse-button-message only is necessary
	bne	norequebutton	;if scroll-gadget is still selected
	jsr	ReplyMsg(a6)	;... drop it
	bra	filewait
norequebutton:
	move.l	28(a1),a5	;get adress of selected gadget
	jsr	ReplyMsg(a6)	;reply the message
	moveq	#0,d4
	cmpa.l	#e1gdg,a5
	beq	selentry	;look if one of the 10
	moveq	#1,d4
	cmpa.l	#e2gdg,a5
	beq	selentry	;directory-entries
	moveq	#2,d4
	cmpa.l	#e3gdg,a5
	beq	selentry	;was selected
	moveq	#3,d4
	cmpa.l	#e4gdg,a5
	beq	selentry
	moveq	#4,d4
	cmpa.l	#e5gdg,a5
	beq	selentry
	moveq	#5,d4
	cmpa.l	#e6gdg,a5
	beq	selentry
	moveq	#6,d4
	cmpa.l	#e7gdg,a5
	beq	selentry
	moveq	#7,d4
	cmpa.l	#e8gdg,a5
	beq	selentry
	moveq	#8,d4
	cmpa.l	#e9gdg,a5
	beq	selentry
	moveq	#9,d4
	cmpa.l	#e10gdg,a5
	bne	noe10
selentry:
	move.l	d4,d0
	add.l	dirstart,d0	;number of fileentry in dir-list
	cmp.l	entryzahl,d0	;if position is past last entry
	bge	filewait	;no file was selected
	mulu	#44,d4
	move.l	dirstart,d3	;get pointer to filename-entry
	mulu	#44,d3
	move.l	diskmem,a5	;in directory-list
	add.l	d3,a5
	add.l	d4,a5
	add.l	#2,a5
	lea	dirname,a4	;look if the same entry is selected
	move.l	a5,a3
	moveq	#38,d7
compareselect:			;a second time
	move.b	(a3)+,d0
	cmp.b	(a4)+,d0
	bne	getselentry
	tst.b	d0
	beq	sameentry
	dbra	d7,compareselect
sameentry:			;if it is the same entry ... try to
	bsr	trydir		;load the directory
	bra	filewait
getselentry:	
	lea	dirname,a4	;if a new entry was selected
	moveq	#38,d7
copyenttodir:
	move.b	(a5)+,(a4)+	;copy the filename and
	dbra	d7,copyenttodir
	bsr	nonewdir	;remake the display of the file-requester
	bra	filewait
noe10:
	cmpa.l	#pointupgdg,a5	;scroll-dir-up-gadget selected ???
	bne	noupdir
updiring:
	tst.l	dirstart	;top of directory still reached ???
	beq	filewait
	subq.l	#1,dirstart	;scroll up one entry
	move.l	graphbase,a6
	move.l	filerast,a1
	moveq	#0,d0
	moveq	#-10,d1
	moveq	#102,d2		;scroll up the display
	moveq	#24,d3
	move.w	#477,d4
	move.w	#121,d5
	jsr	ScrollRaster(a6)
	bsr	showfirst	;print the new entry
	move.l	4,a6
	move.l	filewdwhandle,a0
	move.l	86(a0),a0	;look if the mouse-button was released
	jsr	GetMsg(a6)
	tst.l	d0
	beq	updiring	;if not, go on scrolling the directory
	move.l	d0,a1
	jsr	ReplyMsg(a6)
	bra	filewait
noupdir:
	cmpa.l	#pointdowngdg,a5
	bne	nodowndir
downdiring:
	move.l	entryzahl,d0
	cmp.w	#10,d0		;are there more than 10 entries ???
	bls	filewait
	sub.w	#10,d0
	cmp.l	dirstart,d0	;bottom of directory still reached ???
	bls	filewait
	addq.l	#1,dirstart	;scroll down one entry
	move.l	graphbase,a6
	move.l	filerast,a1
	moveq	#0,d0
	moveq	#10,d1
	moveq	#102,d2		;scroll down the disply
	moveq	#24,d3
	move.w	#477,d4
	move.w	#121,d5
	jsr	ScrollRaster(a6)
	bsr	showlast	;display the new entry
	move.l	4,a6
	move.l	filewdwhandle,a0
	move.l	86(a0),a0
	jsr	GetMsg(a6)	;look if mouse-button was released
	tst.l	d0
	beq	downdiring	;if not, go on scrolling down
	move.l	d0,a1
	jsr	ReplyMsg(a6)
	bra	filewait
nodowndir:
	move.l	#"dh0:",d0
	cmpa.l	#dh0gdg,a5
	beq	dirgadget	;look if one of the 'Device'-
	move.l	#"dh1:",d0
	cmpa.l	#dh1gdg,a5
	beq	dirgadget	;gadgets was selected
	move.l	#"dh2:",d0
	cmpa.l	#dh2gdg,a5
	beq	dirgadget
	move.l	#"df0:",d0
	cmpa.l	#df0gdg,a5
	beq	dirgadget
	move.l	#"df1:",d0
	cmpa.l	#df1gdg,a5
	beq	dirgadget
	move.l	#"df2:",d0
	cmpa.l	#df2gdg,a5
	beq	dirgadget
	move.l	#"ram:",d0
	cmpa.l	#ramgdg,a5
	beq	dirgadget
	move.l	#"rad:",d0
	cmpa.l	#radgdg,a5
	bne	noradgdg
dirgadget:
	move.l	d0,dirname
	clr.b	dirname+4
	bsr	trydir		;get new directory
	bra	filewait
noradgdg:
	cmpa.l	#parentgdg,a5
	bne	noparentgdg	;parent-gadget selected ?
	move.l	dosbase,a6
	move.l	uselock,d1
	jsr	ParentDir(a6)
	move.l	d0,d6
	beq	filewait	;get parent-dir if there is one
	move.l	d6,d1
	jsr	CurrentDir(a6)
	move.l	uselock,d1
	jsr	UnLock(a6)
	move.l	d6,uselock
	bsr	fullnewdir
	move.l	#0,dirname
	bra	filewait
noparentgdg:
	cmpa.l	#propgdg,a5
	bne	nopropgdg	;look if prop-mover was moved
	moveq	#0,d2
	move.w	moverypos,d2
	move.l	entryzahl,d0
	move.l	#$ffff,d1	;and redisplay directory
	cmp.w	#10,d0
	bls	filewait
	sub.w	#10,d0
	divu	d0,d1
	moveq	#0,d3
	move.w	d1,d3
	divu	d3,d2
	moveq	#0,d4
	move.w	d2,d4
	move.l	d4,dirstart
	bsr	cleardirrect
	bsr	showdir
	bra	filewait
nopropgdg:
	cmpa.l	#dirgdg,a5	;look if 'dir'-gadget was selected
	bne	nodirgdg
	lea	dirname,a1
	lea	directorygdgbuffer,a0
cpfltdrnm:
	move.b	(a0)+,(a1)+
	bne	cpfltdrnm
	suba.l	#2,a1
	cmp.b	#"/",(a1)	;and load directory
	bne	nosubddr
	clr.b	(a1)
nosubddr:
	bsr	trydir
	tst.b	d7
	beq	filewait
diredited:
	bsr	fullnewdir
	bra	filewait
nodirgdg:
	cmpa.l	#volumesgdg,a5	;volumes-gadget selected ?
	bne	novolumesgdg
	bsr	cleardiskimems
	move.l	diskmem,a4
	clr.l	entryzahl	;get all volumes/assigns etc.
	move.l	dosbase,a6
	move.l	34(a6),a6	;pointer to rootnode
	move.l	24(a6),d6	;bpointer to dosinfo
	asl.l	#2,d6		;get adress out of bptr
	move.l	d6,a6		;('bptr' is a really strange invention!)
	move.l	4(a6),d6	;get bpointer to first deviceinfo
	asl.l	#2,d6		;get 'real' adress of deviceinfo-struct
	move.l	d6,a6
getdevloop:
	tst.l	4(a6)		;type = 0 ???
	beq	nextdevice	;ignore devices, only get dirs&volumes
	move.l	40(a6),d3	;bpointer to name of volume
	asl.l	#2,d3
	move.l	d3,a3
	adda.l	#1,a3		;get 'real' adress
	move.l	a4,a2
	adda.l	#2,a2
	move.w	#"> ",(a4)	;and copy name into directory-buffer
	moveq	#38,d6
copdevname:
	move.b	(a3)+,(a2)+
	beq	devnamecoped
	dbra	d6,copdevname
devnamecoped:			
	move.b	#":",-(a2)
	addq.l	#1,entryzahl
	adda.l	#44,a4		;go on looking for volumes ...
nextdevice:
	move.l	(a6),d6
	beq	gotvolumes
	asl.l	#2,d6
	move.l	d6,a6
	bra	getdevloop
gotvolumes:
	bsr	newdir		;display list of volumes
	bsr	showdir
	bra	filewait
novolumesgdg:
	cmpa.l	#infogdg,a5	;info-gadget selected ?
	bne	noinfogdg
	eor.b	#255,infoflag	;change 'info-status' and
	bra	diredited	;re-get directory
noinfogdg:
	moveq	#0,d7
	cmpa.l	#cancelgdg,a5	;cancel-gadget selected ?
	beq	exitfiler
	moveq	#1,d7
	cmpa.l	#okgdg,a5	;ok-gadget selected ?
	beq	exitfiler
	bra	filewait

; check 'dir'-gadgets during loading a directory if a change is requested

zwiask:
	move.l	4,a6
	move.l	filewdwhandle,a0
	move.l	86(a0),a0
	jsr	GetMsg(a6)	;is there one message ?
	tst.l	d0
	beq	nozwiask
	move.l	d0,a1
	cmp.l	#$8,20(a1)
	bne	zgadget
	jsr	ReplyMsg(a6)
	bra	nozwiask
zgadget:
	move.l	28(a1),a5
	jsr	ReplyMsg(a6)
	move.l	#"dh0:",d0
	cmpa.l	#dh0gdg,a5	;look if one of the
	beq	zdirgadget
	move.l	#"dh1:",d0
	cmpa.l	#dh1gdg,a5	;dir-gadgets was selected
	beq	zdirgadget
	move.l	#"dh2:",d0
	cmpa.l	#dh2gdg,a5
	beq	zdirgadget
	move.l	#"df0:",d0
	cmpa.l	#df0gdg,a5
	beq	zdirgadget
	move.l	#"df1:",d0
	cmpa.l	#df1gdg,a5
	beq	zdirgadget
	move.l	#"df2:",d0
	cmpa.l	#df2gdg,a5
	beq	zdirgadget
	move.l	#"ram:",d0
	cmpa.l	#ramgdg,a5
	beq	zdirgadget
	move.l	#"rad:",d0
	cmpa.l	#radgdg,a5
	bne	nozwiask
zdirgadget:
	move.l	d0,dirname
	clr.b	dirname+4
	move.l	dosbase,a6
	move.l	#dirname,d1
	moveq	#-2,d2
	jsr	Lock(a6)
	move.l  d0,d1
	beq	nozwiask
	move.l	d0,d6
	move.l	infomem,d2
	jsr	Examine(a6)
	tst.l	d0
	beq	nozwiask
	move.l	infomem,a0
	tst.l	4(a0)
	bmi	nozwiask
	move.l	d6,d1
	jsr	CurrentDir(a6)
	move.l	uselock,d1
	jsr	UnLock(a6)
	move.l	d6,uselock
	bra	getdir

; clear rect for directory-display

cleardirrect:
	move.l	graphbase,a6
	moveq	#0,d0
	move.l	filerast,a1
	jsr	SetAPen(a6)	
	move.l	filerast,a1
	moveq	#102,d0
	moveq	#23,d1
	move.w	#477,d2
	moveq	#122,d3
	jsr	RectFill(a6)
	rts

; look if there is one directory with the name, specified in the dir-gadget

trydir:
	move.l	dosbase,a6
	move.l	#dirname,d1
	moveq	#-2,d2
	jsr	Lock(a6)	;look for the lock
	move.l  d0,d1
	beq	nonewdir
	move.l	d0,d6
	move.l	infomem,d2
	jsr	Examine(a6)	;examine the lock
	tst.l	d0
	beq	nonewdirlock
	move.l	infomem,a0
	tst.l	4(a0)		;is this a directory or only a file ?
	bmi	nonewdirlock
	move.l	d6,d1
	jsr	CurrentDir(a6)	;make directory current
	move.l	uselock,d1	
	jsr	UnLock(a6)	;unlock the old lock
	move.l	d6,uselock	;keep the new one and
	bsr	fullnewdir	;get the new directory
	moveq	#0,d7
	rts
nonewdirlock:
	move.l	d6,d1		;if the new lock is no dir-lock
	jsr	UnLock(a6)	;unlock it
nonewdir:
	move.l	intuibase,a6
	move.l	filewdwhandle,a0
	lea	filenamegdg,a1
	jsr	RemoveGadget(a6)
	bsr	emptyfilenamebuffer
	lea	filenamegdgbuffer,a5
	lea     dirname,a4
	moveq	#79,d0		;and copy the selected directory-
copforfselect:
	move.b	(a4)+,(a5)+
	beq	cpffslctd	;entry into the filenamegadget
	dbra	d0,copforfselect
cpffslctd:
	move.l	filewdwhandle,a0
	lea	filenamegdg,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)
	move.l	filewdwhandle,a1
	lea	filenamegdg,a0
	jsr	RefreshGadgets(a6)
	moveq	#1,d7
	rts

; display the whole directory

showdir:
	move.l	diskmem,a5	;pointer to filenames
	move.l	dirstart,d0
	mulu	#44,d0		;get pointer to first filename
	add.l	d0,a5		;to show
	moveq	#9,d7		;show 10 filenames
	moveq	#24,d5		;y-pos of first entry
	move.l	intuibase,a6
showdirloop:
	bsr	gettheent	;get entry
	move.l	d5,d1
	jsr	PrintIText(a6)	;and print filename
	move.l	40(a5),d0
	bsr	setbytetext	;get ascii-text out of integer
	move.l	filerast,a0
	lea	bytezahltxt,a1
	move.l	#430,d0
	move.l	d5,d1
	jsr	PrintIText(a6)	;and print length of file
	add.l	#10,d5
	add.l	#44,a5		;go on showing the directory
	dbra	d7,showdirloop
shown:
	move.l	filewdwhandle,a0
	lea	propgdg,a1
	jsr	RemoveGadget(a6)	;finaly recalculate
	move.l	entryzahl,d0
	move.l	#$ffff,d1
	cmp.w	#10,d0		;position of mover of
	bls	onepshowdir
	sub.w	#10,d0
	divu	d0,d1		;prop-gadget
	move.l	dirstart,d0
	mulu    d0,d1
onepshowdir:
	move.w	d1,moverypos	;and redraw the gadget
	move.l	filewdwhandle,a0
	lea	propgdg,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)
	move.l	filewdwhandle,a1
	lea	propgdg,a0
	jsr	RefreshGadgets(a6)
	rts

gettheent:
	lea	direntrytxt,a1	;get pointer to text-struct
	move.l	filerast,a0	;get rastport
	move.l	a5,direntrypoint	;set pointer to textline
	moveq	#102,d0		;set x-pos for printing
	rts

; print the first of 10 directory-entries

showfirst:
	move.l	diskmem,a5
	move.l	dirstart,d0
	mulu	#44,d0
	add.l	d0,a5
	move.l	intuibase,a6
	bsr	gettheent	;get the entry and
	moveq	#24,d1
	jsr	PrintIText(a6)	;print it
	move.l	40(a5),d0
	bsr	setbytetext	;get length of file as ascii-text
	move.l	filerast,a0
	lea	bytezahltxt,a1
	move.l	#430,d0		;and print it and finaly
	moveq	#24,d1
	jsr	PrintIText(a6)
	bra	shown		;redraw prop-gadget

;print the last of 10 directory-entries

showlast:
	move.l	diskmem,a5	;see above ...
	move.l	dirstart,d0
	add.w	#9,d0
	mulu	#44,d0
	add.l	d0,a5
	move.l	intuibase,a6
	bsr	gettheent
	moveq	#114,d1
	jsr	PrintIText(a6)
	move.l	40(a5),d0
	bsr	setbytetext
	move.l	filerast,a0
	lea	bytezahltxt,a1
	move.l	#430,d0
	moveq	#114,d1
	jsr	PrintIText(a6)
	bra	shown

; get ascii-text of length of file...
; (as the number can be larger than 65536 one cannot use 'divu' to
; get the digits, so the routine is a little bit complicated ...
; i couldn't do better, maybe someone can !)

setbytetext:
	lea	bytezahltext,a0
	moveq	#5,d1
spacezahl:			;fill text with spaces
	move.b	#32,(a0)+
	dbra	d1,spacezahl
	clr.b	(a0)+
	moveq	#0,d1
	lea	bytezahltext,a0
	tst.l	d0		;length of zero means a directory
	bne	hundert1000
	rts
hundert1000:
	cmp.l	#99999,d0
	bls	gothundert1000	;get digit of hundred-thousands
	sub.l	#100000,d0
	addq.b	#1,d1
	bra	hundert1000
gothundert1000:
	add.b	#48,d1
	move.b	d1,(a0)+
	moveq	#0,d1
zehn1000:
	cmp.l	#9999,d0
	bls	gotzehn1000	;get digit of ten-thousands
	sub.l	#10000,d0
	add.b	#1,d1
	bra	zehn1000
gotzehn1000:
	add.b	#48,d1
	move.b	d1,(a0)+
	moveq	#0,d1
ein1000:
	cmp.l	#999,d0
	bls	gotein1000	;get digit of thousands
	sub.l	#1000,d0
	addq.b	#1,d1
	bra	ein1000
gotein1000:
	add.b	#48,d1
	move.b	d1,(a0)+
	moveq	#0,d1
ein100:
	cmp.l	#99,d0
	bls	gotein100	;get digit of hundreds
	sub.l	#100,d0
	addq.b	#1,d1
	bra	ein100
gotein100:
	add.b	#48,d1
	move.b	d1,(a0)+
	moveq	#0,d1
ein10:
	cmp.l	#9,d0
	bls	gotein10	;get digit of tens
	sub.l	#10,d0
	addq.b	#1,d1
	bra	ein10
gotein10:
	add.b	#48,d1
	move.b	d1,(a0)+
	moveq	#0,d1
	add.b	#48,d0
	move.b	d0,(a0)+
	clr.b	(a0)
	lea	bytezahltext,a0
vorspaceing:
	cmp.b	#48,(a0)+	;if the first spaces are zero
	beq	spacevor
	rts			;replace them by 'spaces'
spacevor:
	move.b	#32,-(a0)
	adda.l	#1,a0
	bra	vorspaceing

;clear memory for filenames and length of files

cleardiskimems:
	clr.l	dirstart
	move.l	diskmem,a0
	move.l	#43999,d0
clrdiskmem:
	clr.b	(a0)+
	dbra	d0,clrdiskmem
	rts

;change window-pointer to sleeping

pltworkon:
	move.l	wdwhandle,a0
	bra	pltworkgo
diskworkon:
	move.l	filewdwhandle,a0
pltworkgo:
	move.l	intuibase,a6
	lea	sleeppoint,a1
	moveq	#16,d1
	moveq	#9,d0
	moveq	#0,d2
	moveq	#0,d3
	jsr	SetPointer(a6)
	rts

;change window-pointer to normal pointer

pltworkoff:
	move.l	wdwhandle,a0
	bra	pltworkoffgo
workwindoff:
	move.l	filewdwhandle,a0
pltworkoffgo:
	move.l	intuibase,a6
	jsr	ClearPointer(a6)
	rts

;get a complete new directory and display it

fullnewdir:
	bsr	getdir
	bsr	newdir
	bsr	showdir
	rts

;examine a directory, get all entries and sort'em

getdir:
	bsr	diskworkon	;get the sleep-pointer
	bsr	cleardiskimems	;clear the filename-memories
	clr.l	entryzahl
	move.l	dosbase,a6
	move.l	uselock,d1
	move.l	infomem,d2
	jsr	Examine(a6)	;examine the lock
	tst.l	d0
	beq	gotdirready	;nothing to examine... no dir !
	move.l	infomem,a2
	adda.l	#8,a2
	lea	dirname,a3	;copy the name of the directory
	move.l	#160,d6
copdirhead:
	move.b	(a2)+,(a3)+
	beq	getdirloop
	dbra	d6,copdirhead
getdirloop:
	bra	zwiask		;look if a new device-gadget was selected
nozwiask:	
	move.l	dosbase,a6
	cmp.l	#998,entryzahl	;we can manage a maximum of 998 entries
	bge	gotdirready
infoentry:
	move.l	uselock,d1
	move.l	infomem,d2	;examine the next entry
	jsr	ExNext(a6)
	tst.l	d0
	beq	gotdirready
	move.l	infomem,a4
	adda.l	#8,a4		;pointer to filename
	tst.b	infoflag
	bne	noinfofile	;should we drop '.info'-files ?
lookforfileend:
	tst.b	(a4)+
	bne     lookforfileend	;get end of filename
	suba.l	#1,a4		;drop zero at the end
	move.b	-(a4),d0	;get last character
	bclr	#5,d0		;ignore lower/capital letter
	move.b	d0,infoname+3
	move.b	-(a4),d0
	bclr	#5,d0
	move.b	d0,infoname+2	;get the 4 last letters
	move.b	-(a4),d0
	bclr	#5,d0
	move.b	d0,infoname+1
	move.b	-(a4),d0
	bclr	#5,d0
	move.b	d0,infoname
	move.b	-(a4),d0
	cmp.b	#46,d0
	bne	noinfofile	;and look it this is one '.info'-file
	cmp.l	#"INFO",infoname
	bne	noinfofile
	bra	infoentry	;drop info-entry
noinfofile:
	addq.l	#1,entryzahl
	moveq	#0,d7
	move.l	diskmem,a5	;find out the position
	suba.l	#44,a5
nextintrol1:
	adda.l	#44,a5		;were to put the filename
	addq.l	#1,d7
	tst.b	(a5)
	beq	foundpos	;into the filename-buffer,
	move.l	a5,a3
	adda.l	#2,a3
	move.l  infomem,a2	;to be sorted in alphabetical
	adda.l	#8,a2
comparethis1:
	move.b	(a2)+,d0	;order
	move.b	(a3)+,d1
	bclr	#5,d0
	bclr	#5,d1		;shift the following filenames
	cmp.b	d0,d1
	beq	comparethis1
	bls	nextintrol1	;get also the right position for
foundpos:
	subq.l	#1,d7
	move.l	diskmem,a5
	move.l	d7,d6
	mulu	#44,d6
	adda.l	d6,a5
	move.l	entryzahl,d6
	subq.l	#1,d6
	mulu	#44,d6
	move.l	diskmem,a2
	adda.l	d6,a2
	move.l	entryzahl,d6
	sub.l	d7,d6
	mulu	#44,d6
	tst.l	d6
	beq	noschieb2
	subq.l	#1,d6
schiebdirloop2:
	move.b	0(a2),44(a2)
	suba.l	#1,a2
	dbra	d6,schiebdirloop2
noschieb2:
	move.l	a5,a3
	move.l	infomem,a2
	move.l	124(a2),40(a3)
	tst.l	4(a2)
	bmi	nodirentry
	move.b	#62,(a3)+
	move.b	#32,(a3)+
	bra	direntry
nodirentry:
	move.b	#32,(a3)+
	move.b	#32,(a3)+
direntry:
	moveq	#37,d6
	adda.l	#8,a2
copyentry:
	move.b	(a2)+,(a3)+
	beq	gotdirentry
	dbra	d6,copyentry
gotdirentry:	
	bra	getdirloop	
gotdirready:
	bsr	workwindoff
	rts

; redraw the dirname-, filename- and the prop-gadget

newdir:
	bsr	cleardirrect
	move.l	intuibase,a6
	move.l	filewdwhandle,a0
	lea	propgdg,a1
	jsr	RemoveGadget(a6)
	clr.w	moverypos
	move.l	entryzahl,d0	;recalculate size of mover
	move.l	#$ffff,d1
	cmp.w	#10,d0
	bls	onepagedir	;of prop-gadget
	divu	d0,d1
	mulu    #10,d1
onepagedir:
	move.w	d1,moverybody
	move.l	filewdwhandle,a0
	lea	propgdg,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)
	move.l	filewdwhandle,a0
	lea	directorygdg,a1
	jsr	RemoveGadget(a6)
	bsr	emptydirectorybuffer
	lea	directorygdgbuffer,a5
	lea	dirname,a4
	moveq	#80,d0		;copy name of directory to
copforfpuffdir:
	move.b	(a4)+,(a5)+
	beq	cpffpffrd	;dir-gadget
	dbra	d0,copforfpuffdir
cpffpffrd:
	move.l	dosbase,a6
	move.l	uselock,d1	;and look if it is a sub-dir
	jsr	ParentDir(a6)
	move.b	#58,-(a5)	;( '/' at the end ) or a
	move.l	d0,d1
	beq	volncopff	;main-dir ( ':' at the end )
	jsr	UnLock(a6)
	move.b	#47,(a5)
volncopff:
	move.l	intuibase,a6
	move.l	filewdwhandle,a0
	lea	directorygdg,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)
	move.l	filewdwhandle,a0
	lea	filenamegdg,a1
	jsr	RemoveGadget(a6)
	bsr	emptyfilenamebuffer	;clear actual filename
	move.l	intuibase,a6
	move.l	filewdwhandle,a0
	lea	filenamegdg,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)	;and redraw the gadgets
	move.l	filewdwhandle,a1
	lea	df0gdg,a0
	jsr	RefreshGadgets(a6)
	rts

; clear filename & directory - buffer

emptyfilenamebuffer:
	lea	filenamegdgbuffer,a1
	bra	emptyfigo
emptydirectorybuffer:
	lea	directorygdgbuffer,a1
emptyfigo:
	move.l	#80,d0
clrvzmpffr:
	clr.b	(a1)+
	dbra	d0,clrvzmpffr
	rts

;close the filerequester

exitfiler:
	move.l	intuibase,a6
	move.l	filewdwhandle,a0
	jsr	CloseWindow(a6)	;close the window
	clr.l	filewdwhandle
	tst.l	d7		;'cancel' selected ???
	beq	filewindopenerror
	move.l	uselock,d0	;pointer to actual lock in d0
	lea	filename,a0	;pointer to filename in a0
	rts
filewindopenerror:
	move.l	#0,a0		;clear pointers to indicate 'cancel'
	moveq	#0,d0
	rts

; Filerequest... Parameter

dirname:		ds.b	82
dorast:			dc.l	0
infoname:		dc.l	0
uselock:		dc.l	0
filewdwhandle:		dc.l	0
entryzahl:		dc.l	0
dirstart:		dc.l	0
enterbuffer:		dc.l	0
filerast:		dc.l	0
fieldheight:		dc.w	0
infoflag:		dc.b	0
			even

; Filerequest... window

filewdw:
	dc.w	41,12,558,155	;x,y,B,H
	dc.b	0,1		;pens
	dc.l	$68		;IDCMP,gadget up/down, mouse-buttons
	dc.l	$2011800	;activ,workbenchwindow,rmbtrap,borderless
	dc.l	parentgdg,0,0	;gadget,checkmark,titel
	dc.l	0,0,0,0		;screen-pointer,bitmap,min,max
	dc.w	1		;Screen-Typ

; Filerequest... gadgets

parentgdg:
		dc.l	infogdg
		dc.w	486,32,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	1
		dc.l	0
infogdg:
		dc.l	df0gdg
		dc.w	486,46,64,12
iactiv:		dc.w	0,$101,1
		dc.l	0,0,0,0,0
		dc.w	2
		dc.l	0
df0gdg:
		dc.l	df1gdg
		dc.w	7,18,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	3
		dc.l	0
df1gdg:
		dc.l	df2gdg
		dc.w	7,32,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	4
		dc.l	0
df2gdg:
		dc.l	ramgdg
		dc.w	7,46,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	5
		dc.l	0
ramgdg:
		dc.l	dh0gdg
		dc.w	7,102,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	6
		dc.l	0
dh0gdg:
		dc.l	dh1gdg
		dc.w	7,60,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	7
		dc.l	0
dh1gdg:
		dc.l	dh2gdg
		dc.w	7,74,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	8
		dc.l	0
dh2gdg:
		dc.l	volumesgdg
		dc.w	7,88,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	9
		dc.l	0
volumesgdg:
		dc.l	dirgdg
		dc.w	486,60,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	10
		dc.l	0
dirgdg:
		dc.l	cancelgdg
		dc.w	486,18,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	11
		dc.l	0
cancelgdg:
		dc.l	okgdg
		dc.w	405,4,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	12
		dc.l	0
okgdg:
		dc.l	radgdg
		dc.w	100,4,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	13
		dc.l	0
radgdg:
		dc.l	pointupgdg
		dc.w	7,116,64,12,0,1,1
		dc.l	0,0,0,0,0
		dc.w	14
		dc.l	0
pointupgdg:
		dc.l	pointdowngdg
		dc.w	78,21,16,16,4,2,1
		dc.l	upimg,0,0,0,0
		dc.w	15
		dc.l	0
pointdowngdg:
		dc.l	e1gdg
		dc.w	78,109,16,16,4,2,1
		dc.l	downimg,0,0,0,0
		dc.w	16
		dc.l	0
e1gdg:	
		dc.l	e2gdg
		dc.w	102,22,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	17
		dc.l	0
e2gdg:
		dc.l	e3gdg
		dc.w	102,32,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	18
		dc.l	0
e3gdg:
		dc.l	e4gdg
		dc.w	102,42,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	19
		dc.l	0
e4gdg:
		dc.l	e5gdg
		dc.w	102,52,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	20
		dc.l	0
e5gdg:
		dc.l	e6gdg
		dc.w	102,62,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	21
		dc.l	0
e6gdg:
		dc.l	e7gdg
		dc.w	102,72,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	22
		dc.l	0
e7gdg:
		dc.l	e8gdg
		dc.w	102,82,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	23
		dc.l	0
e8gdg:
		dc.l	e9gdg
		dc.w	102,92,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	24
		dc.l	0
e9gdg:
		dc.l	e10gdg
		dc.w	102,102,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	25
		dc.l	0
e10gdg:	
		dc.l	draggdg
		dc.w	102,112,376,10,0,1,1
		dc.l	0,0,0,0,0
		dc.w	26
		dc.l	0
draggdg:
		dc.l	filenamegdg
		dc.w	171,3,227,14,0,1,$20
		dc.l	0,0,0,0,0
		dc.w	27
		dc.l	0
filenamegdg:
		dc.l	directorygdg
		dc.w	56,137,208,9,0,2,4
		dc.l	0,0,0,0,filenamegdginfo
		dc.w	28
		dc.l	0
filenamegdginfo:
		dc.l	filenamegdgbuffer,0
		dc.w	0,80,0,0,0,0,0,0
		dc.l	0,0,0
filename:
filenamegdgbuffer:
		ds.b	82
directorygdg:
		dc.l	propgdg
		dc.w	334,137,208,9,0,2,4
		dc.l	0,0,0,0,directorygdginfo
		dc.w	29
		dc.l	0
directorygdginfo:
		dc.l	directorygdgbuffer,0
		dc.w	0,80,0,0,0,0,0,0
		dc.l	0,0,0
directorygdgbuffer:
		ds.b	82
propgdg:
		dc.l	0
		dc.w	78,37,16,72,4,1,3
		dc.l	propmoverbuffer,0,0,0,propgdginfo
		dc.w	30
		dc.l	0
propgdginfo:	dc.w	5		;autoknob,freevert
		dc.w	0		;x-pos des Schiebers
moverypos:	dc.w	0		;y-pos des Schiebers
		dc.w	0		;x-body
moverybody:	dc.w	$ffff/16	;y-body
		dc.w	0,0,0,0,0,0	
propmoverbuffer:
		dc.w	0,0,0,0	

; Filerequest... text-structs

txtext:		dc.b	1,0,0
		even
		dc.l	0,0
txtextpoint:	dc.l	0,0

direntrytxt:	dc.b	1,0,0
		even
		dc.l	0,0
direntrypoint:	dc.l	0,0

bytezahltxt:	dc.b	1,0,0
		even
		dc.w	0,0
		dc.l	0,bytezahltext,0
bytezahltext:	ds.b	10

; Filerequest... rect-table

filefields:
	dc.w	0,0,557,154,2
	dc.w	100,4,63,11,2
	dc.w	171,3,226,13,2
	dc.w	405,4,63,11,2
	dc.w	7,18,63,11,2
	dc.w	7,32,63,11,2
	dc.w	7,46,63,11,2
	dc.w	7,60,63,11,2
	dc.w	7,74,63,11,2
	dc.w	7,88,63,11,2
	dc.w	7,102,63,11,2
	dc.w	7,116,63,11,2
	dc.w	76,20,19,105,2
	dc.w	98,21,383,103,0
	dc.w	486,18,63,11,2
	dc.w	486,32,63,11,2
	dc.w	486,46,63,11,2
	dc.w	486,60,63,11,2
	dc.w	7,134,262,13,0
	dc.w	287,134,262,13,0

; Filerequest... text-table

filetexte:
	dc.w	110,6
	dc.l	ftx1
	dc.w	413,6
	dc.l	ftx2
	dc.w	24,20
	dc.l	ftx3
	dc.w	24,34
	dc.l	ftx4
	dc.w	24,48
	dc.l	ftx5
	dc.w	24,62
	dc.l	ftx6
	dc.w	24,76
	dc.l	ftx7
	dc.w	24,90
	dc.l	ftx8
	dc.w	24,104
	dc.l	ftx9
	dc.w	24,118
	dc.l	ftx10
	dc.w	503,20
	dc.l	ftx11
	dc.w	495,34
	dc.l	ftx12
	dc.w	498,48
	dc.l	ftx13
	dc.w	490,62
	dc.l	ftx14
	dc.w	12,137
	dc.l	ftx15
	dc.w	292,137
	dc.l	ftx16
	dc.w	202,6
	dc.l	ftx17

ftx1:	dc.b	"> OK <",0
	even
ftx2:	dc.b	"Cancel",0
	even
ftx3:	dc.b	"df0:",0
	even
ftx4:	dc.b	"df1:",0
	even
ftx5:	dc.b	"df2:",0
	even
ftx6:	dc.b	"dh0:",0
	even
ftx7:	dc.b	"dh1:",0
	even
ftx8:	dc.b	"dh2:",0
	even
ftx9:	dc.b	"ram:",0
	even
ftx10:	dc.b	"rad:",0
	even
ftx11:	dc.b	"DIR",0
	even
ftx12:	dc.b	"Parent",0
	even
ftx13:	dc.b	".info",0
	even
ftx14:	dc.b	"Volumes",0
	even
ftx15:	dc.b	"File:",0
	even
ftx16:	dc.b	"Dir :",0
	even
ftx17:	dc.b	"PLTMore-Filerequest",0
	even

	section	pltdaten,data_c		;section 2, daten, chipmem

; image-data

upimg:
	dc.w	0,0,16,16,1
	dc.l	updata
	dc.b	1,0
	dc.l	0
updata:
	dc.w	%1111111111111111
	dc.w	%1100000000000011
	dc.w	%1100000110000011
	dc.w	%1100000110000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100011111100011
	dc.w	%1100011111100011
	dc.w	%1100111111110011
	dc.w	%1100111111110011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100000000000011
	dc.w	%1111111111111111

downimg:
	dc.w	0,0,16,16,1
	dc.l	downdata
	dc.b	1,0
	dc.l	0
downdata:
	dc.w	%1111111111111111
	dc.w	%1100000000000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100111111110011
	dc.w	%1100111111110011
	dc.w	%1100011111100011
	dc.w	%1100011111100011
	dc.w	%1100001111000011
	dc.w	%1100001111000011
	dc.w	%1100000110000011
	dc.w	%1100000110000011
	dc.w	%1100000000000011
	dc.w	%1111111111111111

sleeppoint:
	dc.l	0
	dc.l	%00000000000000000001000100010000
	dc.l	%00010001000100000010101010101000
	dc.l	%00100010001000000101010101010000
	dc.l	%01000100010000001010101010100000
	dc.l	%11101110111000000001000100010000
	dc.l	%01000100010000001011101110100000
	dc.l	%01000100010000001010101010110101
	dc.l	%01000100010101011010101010101010
	dc.l	%00000000000000000100010001010101
	dc.l	0

notone:	dc.l	0

 END

