; An Intuition front end for A68k.

; This was a joint project programmed by ( in alphabetical order ):

; Add your name to list and also brief discription of what you worked on.

;		S.Marshall	ARP Filerequester subroutines.
;		M.Meany 	The rest so far !

		opt 		o+,ow-

		incdir		"devmaster:include/"
		include		"exec/exec_lib.i"
		include		"exec/exec.i"
		include		"intuition/intuition_lib.i"
		include		"intuition/intuition.i"
		include		"libraries/dos.i"
		include		"libraries/dosextens.i"
		include		"graphics/gfx.i"
		include		"graphics/graphics_lib.i"
		include		"misc/arpbase.i"
		
ciaapra		equ		$bfe001

*****************************************************************************

; The main routine that opens and closes things

start		move.l		a7,stack	save stack pointer
		
		bsr		Initialise	clear some variables
		
		bsr		OpenLibs	open libraries
		beq.s		no_libs		quit if error
		
		bsr		MakeBuffer	get some memory for text
		beq.s		no_libs		quit if error
			
		bsr		OpenMainWindow	open window+attatch menu
		beq.s		no_mem		quit if error
		
		bsr		WaitForMsg	IDCMP check loop (main body)
		
		bsr		CloseMainWin	release menu + close window

no_mem		bsr		CloseBuffer	release text memory

no_libs		bsr		CloseLibs	close libraries

		move.l		stack,a7	restore stack (just in case)

		moveq.l		#0,d0		No return code !

		rts

*****************************************************************************

; At present this routine clears the library base pointers. The CloseLibs
;routine checks if each pointer is zero, if not it closes the library !

Initialise	moveq.l		#0,d0
		move.l		d0,_GfxBase
		move.l		d0,_DOSBase
		move.l		d0,_IntuitionBase
		move.l		d0,_ArpBase
		move.w		d0,quit_flag
		move.l		#10,linenum		us
		rts

*****************************************************************************

; This routine opens the intuition, graphics and dos libraries. Base pointers
;are saved for each. If a library refuses to be opened the Z flag is set. 
;This is checked on return and the program aborts if any of the libs failed.

OpenLibs	lea		intname,a1
		moveq.l		#0,d0
		CALLEXEC	OpenLibrary
		move.l		d0,_IntuitionBase
		beq		error
	
		lea		grafname,a1
		moveq.l		#0,d0
		CALLEXEC	OpenLibrary
		move.l		d0,_GfxBase
		beq		error
	
		lea		dosname,a1
		moveq.l		#0,d0
		CALLEXEC	OpenLibrary
		move.l		d0,_DOSBase

		OPENARP				;use arp's own open macro
		movem.l		(sp)+,d0/a0	;restore d0 and a0 as the
						;the macro leaves these on
						;the stack causing corrupt stack
		move.l		a6,_ArpBase	;store arpbase

		
error		rts

*****************************************************************************
; Reserve memory for text buffer. If the size of the buffer has not been set
;it is set to a default size of 50000 bytes.

MakeBuffer	tst.l		max_text_size
		bne.s		size_set
		move.l		#50000,max_text_size
size_set	move.l		max_text_size,d0
		addq.l		#1,d0
		move.l		#MEMF_CLEAR!MEMF_PUBLIC,d1
		CALLEXEC	AllocMem
		move.l		d0,a0
		move.b		#$0a,(a0)+
		move.l		a0,text_top
		rts
		
*****************************************************************************
; Opens the main window and attatches the main menu to it.
;Again the Z flag is set if the window cannot be opened, the program aborts
;if this is the case.
		
OpenMainWindow	lea		a68k_window,a0
		CALLINT		OpenWindow
		move.l		d0,a0
		move.l		wd_RPort(a0),window.rp	store rastport pointer
		move.l		wd_UserPort(a0),window.up store userport pointer
		move.l		d0,window.ptr		store window pointer
		beq		no_window
		
		move.l		d0,a0
		lea		main_menu,a1
		CALLINT		SetMenuStrip
		
; Print initial status line

		bsr		PrintStatus
		
		moveq.l		#1,d0		make sure Z flag clear
		
no_window	rts

*****************************************************************************

; The main routine. This is where we wait for intuition to report all user
;inputs. When a message is received, it is tested and the appropriate server
;routine is called .

; Execution will stay in this loop until the value in quit_flag becomes non-
;zero. Any routine that gives the user the oportunity to quit the program
;should call the subroutine QuitReq. This gives the user the chance to 
;change his ( her ? ) mind. QuitReq is the only routine at present that 
;alters the value of quit_flag.

WaitForMsg	move.l		window.up,a0	a0-->user port
		CALLEXEC	WaitPort	wait for something to happen
		move.l		window.up,a0	a0-->window pointer
		CALLEXEC	GetMsg		get any messages
		tst.l		d0		was there a message ?
		beq		WaitForMsg	if not loop back
		move.l		d0,a1		a1-->message
		move.l		im_Class(a1),d2	d2=IDCMP flags
		move.w		im_Code(a1),d3	d3=key code or menu details
		move.w		im_Qualifier(a1),d4 d4=special key details
		move.l		im_IAddress(a1),d7
		CALLEXEC	ReplyMsg	answer os or it get angry
		cmp.l		#CLOSEWINDOW,d2	window closed ?
		bne.s		check_resize	if not check if window resized
		bsr		QuitReq		otherwise verify QUIT
check_resize	cmp.l		#NEWSIZE,d2	window resized ?
		bne.s		check_menu	if not check menu selection
		bsr		ReSize		else deal with resize
check_menu	cmp.l		#MENUPICK,d2	menu selection made ?
		bne.s		check_key	if not check for keyboard input
		bsr		find_menu	otherwise jump to menu handler
check_key	cmp.l		#RAWKEY,d2	keyboard input ?
		bne.s		check_quit	if not then check for quit
		bsr		find_key	otherwise jump to key handler
check_quit	tst.w		quit_flag	was QUIT selected and verified?
		beq		WaitForMsg	if not wait for next message
		rts				otherwise return

*****************************************************************************		
; Refreshes display and updates scrn_size after window has been resized. The
;number of lines that can be printed on screen is calculated as follows:

; number of lines = ( window height / 10 ) - 2

; It would be possible to get more text in the window by dividing by 8, but I
;prefer to look at well spaced text. Other routines will need to be alterd if
;you want to change this.

ReSize		move.l		window.ptr,a0
		moveq.l		#0,d0
		move.w		wd_Height(a0),d0
		divu.w		#10,d0
		and.l		#$ffff,d0
		subq.l		#2,d0
		move.l		d0,scrn_size
		bsr		refresh_display
		bsr		PrintStatus
		moveq.l		#0,d2
		rts

*****************************************************************************		
; This routine deals with menu selections. The address of the subroutine that
;deals with a menu selection is stored after the menu item definition. This
;way the address is obtainable by getting the address of the menu items data
;structure ( by calling ItemAddress () ) into a0 and using mi_SIZEOF(a0)
;thanks to Steve Marshall for this tip.

; At the end of this routine the status line is re-printed so routines may
;set error messages via the status_msg.ptr, these will appear in the status
;line at the bottom of the display. Before returning to WaitForMsg, d2 is set
;to 0 so that other IDCMP tests fail.

find_menu	lea		main_menu,a0
		move.l		d3,d0
		CALLINT		ItemAddress
		tst.l		d0
		beq		no_selection
		move.l		d0,a0
		move.l		mi_SIZEOF(a0),a0
		jsr		(a0)
no_selection	bsr		PrintStatus
		moveq.l		#0,d2		makes other tests fail	
		rts		

*****************************************************************************		
; Here are all the routines that service menu selections	
	
; This routine pops a requester up on the screen giving the user the choice
;of QUITting or CONTinuing. If quit is selected then quit_flag is made non-
;zero and WaitForMsg will know that the user wishes to quit.
		
QuitReq		move.l		window.ptr,a0	a0-->window
		lea		body,a1		a1-->requester text
		lea		left,a2		a2-->requester button text
		lea		right,a3	a3-->requester button text
		moveq.l		#0,d0		left activated by click
		move.l		d0,d1		right activated by click
		move.l		#250,d2		requester width
		move.l		#70,d3		requester height
		CALLINT		AutoRequest	turn it on !
		tst.l		d0		CONT selected ?
		bne		dont_quit	if so continue
		move.w		#1,quit_flag	otherwise set flag
dont_quit	rts				else quit

*****************************************************************************
; Load in a text file. This is a biggy. The ARP file requester is used to 
;obtain the full pathname of the file to load. No pathname causes a message
;to appear in status line and the routine aborts.

; Once a filename has been specified, the size of the file is determined by
;examaning the File Info Block ( fib_ ). If the file is bigger than the text
;buffer then a message is displayed in the status line and the subroutine
;aborts.

; If the file will fit in the buffer it is opened and the text is read into
;the buffer. If the file cannot be opened, a message appears in the status 
;line and the subroutine aborts.

; Once the text has been read into memory the number of lines of text present
;is determined and the text output variables start_line_num ( number of line
;to appear in top line of window ) and start_line ( address in text buffer of
;of line to appear in top line of window ) are both initialised to the start
;of the text buffer. The first window of text is then printed and the
;subroutine finishes. Phew !

Load		bsr		arpload
		bne.s		.ok
		move.l		#status_msg7,status_msg.ptr
		bra		load_error
.ok		lea		LoadPathName,a5
		bsr		filelen
		tst.l		d7
		beq		load_error
		cmp.l		max_text_size,d7
		bls.s		will_fit
		move.l		#status_msg6,status_msg.ptr
		bra		load_error
		
will_fit	bsr		read_text
		beq.s		load_error
		bsr		count_lines
		move.l		#1,start_line_num
		move.l		text_top,start_line
		bsr		refresh_display
load_error	rts

; Uses ARP filerequester to get source filename.
	
arpload		lea		LoadFileStruct,a0	;get file struct
		CALLARP		FileRequest 		;and open requester
		tst.l		d0			;did the user cancel ?
		beq.s		NoPath
		lea		LoadFileStruct,a0	;get file struct
		bsr		CreatePath		;make full pathname
		tst.b		LoadPathName		;is there a pathname ?
NoPath		rts					;and return to calling routine

; Find the length of the text file. Exits with d7 = size in bytes, 0 if error

; Allocate some memory for the File Info block

filelen		moveq.l		#0,d7		flag
		move.l		#fib_SIZEOF,d0
		move.l		#MEMF_PUBLIC,d1
		CALLEXEC	AllocMem
		move.l		d0,file_info
		bne.s		.ok
		move.l		#status_msg8,status_msg.ptr
		bra		err1
		
; Lock the file
		
.ok		move.l		a5,d1
		move.l		#ACCESS_READ,d2
		CALLDOS		Lock
		move.l		d0,file_lock
		bne		got_lock
		move.l		#status_msg9,status_msg.ptr
		bra		err2

; Use Examine to load the File Info block

got_lock	move.l		d0,d1
		move.l		file_info,d2
		CALLDOS		Examine

; Copy the length of the file into text_size

		move.l		file_info,a0
		move.l		fib_Size(a0),text_size
		move.l		fib_Size(a0),d7

; Release the file

		move.l		file_lock,d1
		CALLDOS		UnLock

; Release allocated memory

err2		move.l		file_info,a1
		move.l		#fib_SIZEOF,d0
		CALLEXEC	FreeMem
		
err1		rts

file_info	dc.l		0
file_lock	dc.l		0

; Read the text from the file into the text buffer.

read_text	move.l		#LoadPathName,d1
		move.l		#MODE_OLDFILE,d2
		CALLDOS		Open
		move.l		d0,d6
		bne		.ok
		move.l		#status_msg10,status_msg.ptr
		moveq.l		#0,d0		set Z flag
		bra		read_error
		
.ok		move.l		d0,d1
		move.l		text_top,d2
		move.l		d7,d3
		CALLDOS		Read
		move.l		d6,d1
		CALLDOS		Close
		move.l		#1,d0		clear Z flag
read_error	rts

; Count the number of lines of text in the file. Set the maximum line number

count_lines	move.l		text_top,a0	a0-->start of text
		move.l		text_size,d1	d1=size of file
		subq.b		#1,d1		adjust size for dbra
		moveq.l		#1,d0		init the line counter
		moveq.l		#$0a,d2		d2=code of CR
cl_loop		cmp.b		(a0)+,d2	is char a CR
		bne.s		not_CR		if not loop back
		addq.l		#1,d0		else bump line counter
not_CR		dbra		d1,cl_loop	repeat until all text done
		move.l		d0,num_lines	store the number of lines
		rts				and return

*****************************************************************************
; Save text in buffer to name specified. This subroutin has two entry points,
;entering at SaveAs causes an ARP file requester to appear so a file name can
;be specified, Entering at Save will save text to a previousley specified
;file.

; If no file name is specified a message is displayed in the status line and
;the subroutine aborts.

; Providing a file name exsists then, the subroutine opens the file. If the
;file cannot be opened a message is sent to the status line and the
;subroutine aborts.

; Once the file has been opened the contents of the text buffer are written
;to the file. The size of the text to write is determined by text_size, not
;the size of the buffer.

; After the text has been saved, the file is close and the subroutine ends.

; Added a third entry point ( entry2 ??? ). The section of code following
;this is called by the assemble subroutine to write the text to ram: prior
;to invoking A68K.

SaveAs		bsr		arpsave
Save		tst.b		SavePathName
		bne.s		name_set
		move.l		#status_msg7,status_msg.ptr
		bra		save_error
name_set	move.l		#SavePathName,d1
entry2		move.l		#MODE_NEWFILE,d2
		CALLDOS		Open
		move.l		d0,d7
		bne		.ok
		move.l		#status_msg11,status_msg.ptr
		bra		save_error
.ok		move.l		d0,d1
		move.l		text_top,d2
		move.l		text_size,d3
		CALLDOS		Write
		move.l		d7,d1
		CALLDOS		Close
save_error	rts

; Use ARP file requester to obtain save file name.

arpsave		lea		SaveFileStruct,a0	;get file struct
		CALLARP		FileRequest 		;and open requester 
		tst.l		d0			;did the user cancel ?
		beq		NoPath2			;yes then quit
		lea		SaveFileStruct,a0	;get file struct
		bsr		CreatePath		;make full pathname
NoPath2		rts					;and return to calling routine

*****************************************************************************
;	General subroutines called by anybody
*****************************************************************************

;Subroutine to create a single pathname from the seperate directory
;and filename strings.Adds ':' or '/' as needed.Called by

;CreatePath(FileRequest)
;		a0

;This routine assumes that a pointer to the pathname buffer
;is placed directly after the FileRequest structure.(My extension)
		

CreatePath:
	move.l		a2,-(sp)		;save a2
	move.l		a0,a2			;file struct to a2
	move.l		fr_Dir(a2),a0		;directory string to a0
	move.l		fr_SIZEOF(a2),a1	;get destination address
	moveq		#DSIZE,d0		;get size
	CALLEXEC	CopyMem			;and copy dir string
	
	move.l		fr_SIZEOF(a2),a0	;get path (dest) address
	move.l		fr_File(a2),a1		;get file string
	CALLARP		TackOn			;and tack onto dir string
	move.l		(sp)+,a2		;restore a2
	rts					;and quit

*****************************************************************************		
; Clears text buffer and assosiated variables.

Clear		moveq.l		#0,d0
		move.l		d0,start_line_num
		move.l		d0,start_line
		move.l		d0,num_lines
		move.l		d0,text_size
		bsr		refresh_display
		rts
		
*****************************************************************************
; This subroutine assembles and links the contents of the text buffer.

; Another biggy !



Assemble	tst.l		text_size
		bne.s		.ok
		move.l		#status_msg1,status_msg.ptr
		bra		cant_assemble
.ok		bsr		GoAsmP
		move.l		#ramname,d1
		bsr		entry2		part of Save subroutine
		move.l		#asm_CON,d1
		move.l		#MODE_NEWFILE,d2
		CALLDOS		Open
		move.l		d0,asm_handle
		bne.s		assemble_now
		move.l		#status_msg12,status_msg.ptr
		bra		cant_assemble
assemble_now	move.l		#Asm_comm,d1
		moveq.l		#0,d2
		move.l		d0,d3
		CALLDOS		Execute
		move.l		#Link_comm,d1
		moveq.l		#0,d2
		move.l		asm_handle,d3
		CALLDOS		Execute
		move.l		asm_handle,d1
		move.l		#mb_msg,d2
		move.l		#mb_len,d3
		CALLDOS		Write
.loop		btst		#6,ciaapra
		bne.s		.loop		
		move.l		#ramname,d1
		CALLDOS		DeleteFile
		move.l		#objname,d1
		CALLDOS		DeleteFile
		move.l		asm_handle,d1
		CALLDOS		Close
cant_assemble	rts


GoAsmP		lea		AsmP_window,a0	a0-->window structure
		CALLINT		OpenWindow	open this window
		move.l		d0,AsmP.ptr	save its pointer
		lea		AsmPWinText,a1	a1-->text structure
		move.l		AsmP.ptr,a0	a0-->window
		move.l		50(a0),a0	
		moveq.l		#0,d0		x position of text
		move.l		#0,d1		y position of text
		CALLINT		PrintIText	print the help message
WaitForAsmP	move.l		AsmP.ptr,a0	a0-->window
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	WaitPort	wait for something to happen
		move.l		AsmP.ptr,a0	a0-->window pointer
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	GetMsg		get any messages
		tst.l		d0		was there a message ?
		beq		WaitForAsmP	if not loop back
		move.l		d0,a1		a1-->message
		move.l		im_Class(a1),d2	d2=IDCMP flags
		move.l		im_IAddress(a1),a5 a5=addr of structure
		CALLEXEC	ReplyMsg	answer o/s or it gets angry
		cmp.l		#GADGETUP,d2
		bne.s		WaitForAsmP
		move.l		gg_UserData(a5),a5
		jsr		(a5)
		move.l		AsmP.ptr,a0	a0-->window
		CALLINT		CloseWindow	close this window
		rts
	
GotAsmPName	rts

NoAsmPName	moveq.l		#10,d0
		lea		AsmPBuffer,a0
		lea		AsmMemName,a1
.loop		move.b		(a1)+,(a0)+
		dbra		d0,.loop
		rts
	
AsmP.ptr	dc.l		0
	
AsmMemName	dc.b		'ram:source',0
		even

	
AsmP_window	dc.w		150,90	
		dc.w		279,67		
		dc.b		0,3		
		dc.l		GADGETUP
		dc.l		ACTIVATE		
		dc.l		AsmPGadg
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.w		5,5		
		dc.w		640,200		
		dc.w		WBENCHSCREEN		

AsmPGadg	dc.l		AsmPOKGadg		
		dc.w		120,22		
		dc.w		120,8
		dc.w		0		
		dc.w		RELVERIFY
		dc.w		STRGADGET		
		dc.l		AsmPGadgBorder
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.l		AsmPGadgInfo		
		dc.w		0		
		dc.l		GotAsmPName

AsmPGadgInfo	dc.l		AsmPBuffer
		dc.l		0		
		dc.w		0		
		dc.w		32		
		dc.w		0		
		dc.w		0,0,0,0,0		
		dc.l		0		
		dc.l		0		
		dc.l		0		

AsmPGadgBorder	dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		AsmPGadgVectors
		dc.l		0		

AsmPGadgVectors	dc.w		0,0
		dc.w		125,0
		dc.w		125,9
		dc.w		0,9
		dc.w		0,0

AsmPOKGadg	dc.l		AsmPCancelGadg		
		dc.w		33,49		
		dc.w		64,12		
		dc.w		0		
		dc.w		RELVERIFY		
		dc.w		BOOLGADGET		
		dc.l		AsmPOKBorder
		dc.l		0		
		dc.l		AsmPOKStruct
		dc.l		0		
		dc.l		0		
		dc.w		0		
		dc.l		GotAsmPName		

AsmPOKBorder	dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		AsmPOKVectors
		dc.l		0		

AsmPOKVectors	dc.w		0,0
		dc.w		67,0
		dc.w		67,13
		dc.w		0,13
		dc.w		0,0

AsmPOKStruct	dc.b		3,0,RP_JAM2,0		
		dc.w		22,3		
		dc.l		0		
		dc.l		AsmPOKText	
		dc.l		0		

AsmPOKText	dc.b		'OK',0
		even

AsmPCancelGadg	dc.l		0		
		dc.w		180,49		
		dc.w		64,12		
		dc.w		0		
		dc.w		RELVERIFY		
		dc.w		BOOLGADGET		
		dc.l		AsmPCancelBorder
		dc.l		0		
		dc.l		AsmPCancelStruct
		dc.l		0		
		dc.l		0		
		dc.w		0		
		dc.l		NoAsmPName

AsmPCancelBorder dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		AsmPCancelVectors
		dc.l		0		

AsmPCancelVectors dc.w		0,0
		dc.w		67,0
		dc.w		67,13
		dc.w		0,13
		dc.w		0,0

AsmPCancelStruct dc.b		3,0,RP_JAM2,0		
		dc.w		4,3		
		dc.l		0		
		dc.l		AsmPCancelText
		dc.l		0		

AsmPCancelText	dc.b		'DEFAULT',0
		even

AsmPWinText	dc.b		3,0,RP_JAM2,0		
		dc.w		15,23		
		dc.l		0		
		dc.l		AsmPWinTextStr	
		dc.l		AsmPWinText1		

AsmPWinTextStr	dc.b		'FILE NAME  :',0
		even

AsmPWinText1	dc.b		3,0,RP_JAM2,0		
		dc.w		20
plc1		dc.w		5		
		dc.l		0		
plc2		dc.l		AsmPWinText1Str	
		dc.l		0		

AsmPWinText1Str	dc.b		'Assembly Output File Name',0
		even

Asm_comm	dc.b		'c:A68K ram:source.s -iworkdisc:include -d',0
		even
Link_comm	dc.b		'c:Blink ram:source.o to '
AsmPBuffer	dcb.b		32,0
		even
ramname		dc.b		'ram:source.s',0
		even
objname		dc.b		'ram:source.o',0
		even		
asm_CON		dc.b		'con:0/11/640/200/Assembling',0
		even
asm_handle	dc.l		0

*****************************************************************************
; This routine executes the file ram:source, produced by assembling
;the file ram:source.s

Run		move.l		#default_CON,d1
		move.l		#MODE_NEWFILE,d2
		CALLDOS		Open
		move.l		d0,default_handle
		bne.s		run_now
		move.l		#status_msg13,status_msg.ptr	
		bra		cant_run
run_now		move.l		#AsmPBuffer,d1
		moveq.l		#0,d2
		move.l		d0,d3
		CALLDOS		Execute
		move.l		default_handle,d1
		move.l		#mb_msg,d2
		move.l		#mb_len,d3
		CALLDOS		Write
.loop		btst		#6,ciaapra
		bne.s		.loop		
		move.l		default_handle,d1
		CALLDOS		Close
cant_run	rts

default_CON	dc.b		'con:0/11/640/200/Default_Window',0
		even
default_handle	dc.l		0

*****************************************************************************
; Print the file

PrintFile	tst.l		start_line_num
		bne.s		.ok
		move.l		#status_msg1,status_msg.ptr
		bra.s		no_printfile
.ok		move.l		text_top,print_start
		move.l		text_size,print_size
		bsr		Printer
no_printfile	rts
		
*****************************************************************************
; Print the current page of text

PrintPage	tst.l		start_line_num
		bne.s		.ok
		move.l		#status_msg1,status_msg.ptr
		bra		no_printpage
.ok		move.l		num_lines,d0
		cmp.l		scrn_size,d0
		bgt		.go
		bsr		PrintFile
		bra		no_printpage
.go		move.l		scrn_size,d2
		subq.l		#1,d2
		move.l		start_line,a0
		move.l		a0,print_start
		move.l		a0,a5
prt_len_loop	bsr		start_nextln
		dbra		d2,prt_len_loop
		suba.l		a0,a5
		move.l		a5,print_size
		bsr		Printer
no_printpage	rts
		
*****************************************************************************

; Dump text to printer

Printer		move.l		#printername,d1
		move.l		#MODE_NEWFILE,d2
		CALLDOS		Open
		move.l		d0,d7
		bne.s		.ok
		move.l		#status_msg14,status_msg.ptr
		bra		no_printer
.ok		move.l		d0,d1
		move.l		print_start,d2
		move.l		print_size,d3
		CALLDOS		Write
		move.l		d7,d1
		CALLDOS		Close
no_printer	rts

printername	dc.b		'prt:',0
		even
print_start	dc.l		0
print_size	dc.l		0

*****************************************************************************

InsertFile	tst.l		start_line_num
		beq		no_insertfile
		move.l		max_text_size,d6
		sub.l		text_size,d6
		bsr		arpinsert
		beq		no_insertfile
		lea		InsertPathName,a5
		move.l		text_size,old_size
		bsr		filelen
		move.l		old_size,text_size
		tst.l		d7
		beq.s		no_insertfile
		cmp.l		d7,d6
		blt		no_insertfile
		move.l		start_line,a5
		bsr		start_nextln
		movea.l		a5,a0
		movea.l		a5,a1
		add.l		d7,a1
		move.l		d7,d0
		CALLEXEC	CopyMem
		move.l		#InsertPathName,d1
		move.l		#MODE_OLDFILE,d2
		CALLDOS		Open
		move.l		d0,d6
		move.l		d0,d1
		move.l		a5,d2
		move.l		d7,d3
		CALLDOS		Read
		move.l		d6,d1
		CALLDOS		Close
		add.l		d7,text_size
		bsr		count_lines
		bsr		refresh_display
no_insertfile	rts

old_size	dc.l		0

arpinsert	lea		InsertFileStruct,a0	;get file struct
		CALLARP		FileRequest 		;and open requester
		tst.l		d0			;did the user cancel ?
		beq		NoPath3			;yes then quit
		lea		InsertFileStruct,a0	;get file struct
		bsr		CreatePath		;make full pathname
		tst.b		InsertPathName		;is there a pathname ?
NoPath3		rts					;and return to calling routine
		
*****************************************************************************	

; Display the ABOUT window
		
About		lea		about_win,a0	a0-->window structure
		CALLINT		OpenWindow	open this window
		move.l		d0,about.ptr	save window pointer
		beq.s		no_win
		lea		about_text,a1	a1-->text structure
		move.l		about.ptr,a0	a0-->window
		move.l		50(a0),a0	
		moveq.l		#0,d0		x position of text
		move.l		#0,d1		y position of text
		CALLINT		PrintIText	print the help message
wait_about	btst		#6,ciaapra	wait for left mouse button
		bne.s		wait_about
		move.l		about.ptr,a0	a0-->window
		CALLINT		CloseWindow	close this window
no_win		rts

about.ptr	dc.l		0

*****************************************************************************	

GoLine		tst.l		start_line_num
		bne		.ok
		move.l		#status_msg1,status_msg.ptr
		bra		no_goline
.ok		bsr		WhatLine
GoLine_entry2	move.l		num_lines,d1
		sub.l		scrn_size,d1
		bhi		.ok1
		move.l		#status_msg4,status_msg.ptr
		bra		no_goline
.ok1		tst.l		d7
		bne		.ok2
		move.l		#status_msg4,status_msg.ptr
		bra.s		no_goline
.ok2		cmp.l		d1,d7
		ble		.ok3
		move.l		#status_msg4,status_msg.ptr
		bra		no_goline
.ok3		move.l		d7,start_line_num
		move.l		d7,d1
		bsr		find_ln
		move.l		a5,start_line
		bsr		refresh_display
no_goline	rts


WhatLine	move.l		#0,LineBuffer
		lea		line_window,a0	a0-->window structure
		CALLINT		OpenWindow	open this window
		move.l		d0,line.ptr	save its pointer
		lea		LineWinText,a1	a1-->text structure
		move.l		line.ptr,a0	a0-->window
		move.l		50(a0),a0	
		moveq.l		#0,d0		x position of text
		move.l		#0,d1		y position of text
		CALLINT		PrintIText	print the help message
WaitForLine	move.l		line.ptr,a0	a0-->window
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	WaitPort	wait for something to happen
		move.l		line.ptr,a0	a0-->window pointer
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	GetMsg		get any messages
		tst.l		d0		was there a message ?
		beq		WaitForLine	if not loop back
		move.l		d0,a1		a1-->message
		move.l		im_Class(a1),d2	d2=IDCMP flags
		move.l		im_IAddress(a1),a5 a5=addr of structure
		CALLEXEC	ReplyMsg	answer o/s or it gets angry
		cmp.l		#GADGETUP,d2
		bne.s		WaitForLine
		move.l		gg_UserData(a5),a5
		jsr		(a5)
		move.l		line.ptr,a0	a0-->window
		CALLINT		CloseWindow	close this window
		rts
	
GotLineNum	lea		LineGadgInfo,a5
		move.l		si_LongInt(a5),d7
		bpl.s		.ok
		moveq.l		#0,d7
.ok		rts

NoLineNum	moveq.l		#0,d7
		rts
	
line.ptr	dc.l		0

*****************************************************************************	

GoTop		tst.l		start_line_num
		beq		no_gotop
		move.l		text_top,start_line
		move.l		#1,start_line_num
		bsr		refresh_display
no_gotop	rts

*****************************************************************************	

GoBot		tst.l		start_line_num
		beq.s		no_gobot
		move.l		num_lines,d1
		sub.l		scrn_size,d1
		bls		no_gobot
		move.l		d1,start_line_num
		bsr		find_ln
		move.l		a5,start_line
		bsr		refresh_display
no_gobot	rts
		
*****************************************************************************	
		
Find
FindN
FindP
Replace
DoNothing
ReplaceAll
Prefs
Help		move.l		#status_msg20,status_msg.ptr
		rts

*****************************************************************************
; Keyboard service routine

find_key	and.w		#$0003,d4
		beq.s		no_shift
		cmp.w		#$55,d3
		blt.s		.ok		< F6
		cmp.w		#$59,d3		> F10
		bgt.s		.ok
		bsr		GotoMarker
		bra		done_keys
			
.ok		cmp.w		#$4d,d3
		bne.s		page_down
		bsr		next_page
		bra.s		done_keys
		
page_down	cmp.w		#$4c,d3
		bne.s		done_keys
		bsr		prev_page
		bra.s		done_keys

no_shift	cmp.w		#$55,d3
		blt.s		.ok		< F6
		cmp.w		#$59,d3		> F10
		bgt		.ok
		bsr		SetMarker
		bra		done_keys

.ok		cmp.w		#$4d,d3
		bne		line_down
		bsr		scroll_up
		bra		done_keys
		
line_down	cmp.w		#$4c,d3
		bne		ignore_keys
		bsr		scroll_down
done_keys	bsr		PrintStatus
ignore_keys	moveq.l		#0,d2
		rts

; Print the message defined by the Intuition text structure at msg_text

printmsg	lea		msg_text,a1	a1-->text structure
		move.l		window.rp,a0	a0-->window rastport
		moveq.l		#5,d0		x position of text
		move.l		linenum,d1	y position of text
		CALLINT		PrintIText	print the help message
		add.l		#10,linenum
		rts

*****************************************************************************

SetMarker	sub.w		#$55,d3
		asl.w		#2,d3		x4
		lea		PositionMarker,a0
		move.l		start_line_num,0(a0,d3)
		move.l		#status_msg16,status_msg.ptr
		rts
		

*****************************************************************************

GotoMarker	sub.w		#$55,d3
		asl.w		#2,d3
		lea		PositionMarker,a0
		move.l		0(a0,d3),d7
		tst.l		d7
		bne.s		.ok
		move.l		#status_msg17,status_msg.ptr
		bra.s		NoGoMarker
		
.ok		bsr		GoLine_entry2
NoGoMarker	rts
		
PositionMarker	dc.l		0,0,0,0,0,0

*****************************************************************************

; Scroll on to next page

next_page	move.l		scrn_size,d7
		subq.l		#2,d7
.loop		bsr		scroll_up
		dbra		d7,.loop
		rts
		
*****************************************************************************

; Scroll to previous page

prev_page	move.l		scrn_size,d7
		subq.l		#2,d7
.loop		bsr		scroll_down
		dbra		d7,.loop
		rts

*****************************************************************************

; This routine scrolls the display up one line and displays the next line of
;text at the bottom of the display. No scroll is done if the bottom line is
;off the display.

scroll_up	tst.l		start_line_num
		bne.s		.ok
		move.l		#status_msg1,status_msg.ptr
		bra		no_scroll_up
.ok		move.l		num_lines,d0		calc max value of last
		subq.l		#1,d0
		sub.l		scrn_size,d0		line on screen
		bhi		.ok1
		move.l		#status_msg3,status_msg.ptr
		bra.s		no_scroll_up
.ok1		addq.l		#1,d0
		cmp.l		start_line_num,d0	
		bne.s		.ok3
		move.l		#status_msg3,status_msg.ptr
		bra.s		no_scroll_up		if so branch to end
.ok3		addi.l		#1,start_line_num	else bump top line
		movea.l		start_line,a5		get addr of top line
		bsr		start_nextln		get addr of next line
		move.l		a5,start_line		make this the top line
		move.l		window.rp,a1		: : : : : : : : : : :
		moveq.l		#0,d0			: : : : : : : : : : :
		moveq.l		#10,d1			: : : : : : : : : : :
		moveq.l		#4,d2			set params for 
		moveq.l		#10,d3			ScrollRaster routine
		move.l		#635,d4			: : : : : : : : : : :
		move.l		scrn_size,d5		calculate height of 
		mulu.w		#10,d5			screen.
		add.w		#9,d5			: : : : : : : : : : :
		CALLGRAF	ScrollRaster		and scroll up
		bsr		print_bot		display bottom line
no_scroll_up	rts					and return

*****************************************************************************

; This routine scrolls the display down one line and displays the next line of
;text at the top. If the top of the file is already being displayed, then no
;scroll takes place.

scroll_down	tst.l		start_line_num
		bne.s		.ok
		move.l		#status_msg1,status_msg.ptr
		bra.s		no_scroll_down
.ok		move.l		start_line_num,d0	d0=num of line at top
		cmpi.l		#1,d0			1st line of file ?
		bne.s		.ok1
		move.l		#status_msg2,status_msg.ptr
		bra.s		no_scroll_down		if so branch to end
.ok1		subi.l		#1,start_line_num	else bump top line
		movea.l		start_line,a5		get addr of top line
		bsr		start_prevln		get addr of previous ln
		move.l		a5,start_line		make this the top line
		move.l		window.rp,a1		: : : : : : : : : : :
		moveq.l		#0,d0			: : : : : : : : : : :
		moveq.l		#-10,d1			: : : : : : : : : : :
		moveq.l		#4,d2			set params for
		moveq.l		#10,d3			ScrollRaster routine
		move.l		#635,d4			: : : : : : : : : : :
		move.l		scrn_size,d5		calculate height of 
		mulu.w		#10,d5			screen
		add.w		#9,d5			: : : : : : : : : : :
		CALLGRAF	ScrollRaster		and scroll down
		bsr		print_top		display top line
no_scroll_down	rts					and return

*****************************************************************************


; Print the top line of text ( used by line up/down routines )

print_top	movea.l		start_line,a1	get addr of 1st line of text
		move.l		#10,linenum	set screen position
		bsr		print_line	and print it
		rts
		
*****************************************************************************

; Print the bottom line of text ( used by line up/down routines )

print_bot	movea.l		start_line,a5	get addr of 1st line of text
		move.l		scrn_size,d1	get num of lines on screen
		subq.l		#2,d1		adjust for last line
.loop		bsr		start_nextln	find addr of last line
		dbra		d1,.loop
		movea.l		a5,a1		move this addr into a1
		move.l		scrn_size,d1	calculate screen position
		mulu.w		#10,d1
		move.l		d1,linenum	set screen position
		bsr		print_line	and print the line
		rts
		
*****************************************************************************

; Prints a new page of text. the number of lines displayed is controled by
;scrn_size.

; Set pen to background colour

refresh_display	move.l		window.rp,a1
		moveq.l		#0,d0
		CALLGRAF	SetAPen

; Blit a great big rectangle over the window ( clear the screen )
		
		move.l		window.ptr,a0
		move.w		wd_Width(a0),d2
		subi.w		#4,d2
		move.w		wd_Height(a0),d3
		subi.w		#11,d3
		move.w		#2,d0
		move.w		#10,d1
		move.l		window.rp,a1
		CALLGRAF	RectFill

; Now print the text. Checks that there is text in the buffer, if not 
;no text is printed and a status message is returned. Checks that there is
;enough text in the buffer to fill the screen, if not only text present
;is printed.

		tst.l		start_line_num
		beq.s		no_refresh
		move.l		#10,linenum
		move.l		num_lines,d5
		cmp.l		scrn_size,d5
		bgt.s		do_lines
		subq.l		#1,d5
		beq.s		part_refresh
		subq.l		#1,d5
		bra		part_refresh
do_lines	move.l		scrn_size,d5	get num of lines to print
		subq.l		#1,d5		adjust for dbra
part_refresh	move.l		start_line,a1	get addr of 1st text line
.loop		movea.l		a1,a5		save addr of text line
		bsr		print_line	print this line
		bsr		start_nextln	get addr of next line of text
		movea.l		a5,a1		put it in a1
		dbra		d5,.loop	loop until all lines printed
no_refresh	rts				return

*****************************************************************************

; Expands a line of text and prints the result on the screen. The position of
;the text must already be set ( linenum ).

; Entry		a1 must hold address of unexpanded text.

print_line	lea		msg1,a0		a0-->destination buffer
		bsr		expand_text	process the text
		bsr		printmsg	print the message
		rts				and return
		
*****************************************************************************

; Finds the address of the next line of text.

; Entry		a1 must hold address of start of current line of text

; Exit		a1 will hold address of start of next line.

start_nextln	moveq.l		#$0a,d0		d0=CR
.loop		cmp.b		(a5)+,d0	is character a CR
		bne.s		.loop		if not loop back
		rts				else end of line found.

*****************************************************************************

start_prevln	move.b		-(a5),d0	bump a5
		moveq.l		#$0a,d0		d0=CR
.loop		cmp.b		-(a5),d0	is character a CR
		bne.s		.loop		if not loop back
		adda.l		#1,a5		else bump a5
		rts				and return

*****************************************************************************

; Finds the address of the start of a given line in the text.

; Entry		d1 must hold the line number required ( 0 NOT allowed )

; Exit		a5 will hold the address of the start of required line.

find_ln		cmp.l		num_lines,d1	is this a valid size
		ble.s		valid_size	if so don't worry
		move.l		num_lines,d1	else set line = max value
valid_size	subq.l		#1,d1		convert line num to offset
		tst.l		d1		top of file ?
		bne		adjust		if not don't worry
		move.l		text_top,a5	else set top of file
		rts				and return
adjust		subq.l		#1,d1		adjust for dbra		
		move.l		text_top,a5	a5 = start of text file
line_loop	bsr		start_nextln	get addr of next line
		dbra		d1,line_loop	until addr found
		rts
		

*****************************************************************************

; Given the address of a $0a terminated line of text, this(subroutine will
;produce a printable line ( TAB's expanded ) in a line buffer.

; Entry		a0 must hold address of line buffer for expanded text
;		a1 must hold address of start of text string
		
		
expand_text	movem.l		d0-d7/a0-a1,-(sp) save registers
		moveq.l		#0,d6		d6=line length
		moveq.l		#$09,d2		d2=TAB
		moveq.l		#$0a,d3		d3=CR
		moveq.l		#' ',d4		d4=space
next_char	move.b		(a1)+,d0	d0=next char
		cmp.b		d3,d0		new line ?
		beq.s		line_done	if so finish up
		cmp.b		d2,d0		TAB ?
		beq		do_tab		if so deal with it
		move.b		d0,0(a0,d6)	position character
		addq.w		#1,d6		bump counter
		bra		next_char	go back for next char
		
line_done	move.b		#0,0(a0,d6)	null terminate line
		movem.l		(sp)+,d0-d7/a0-a1 restore registers
		rts
		
do_tab		move.l		d6,d1		copy chars so far
		asr.w		#3,d1		calculate num of spaces
		addq.w		#1,d1
		asl.w		#3,d1
		sub.w		d6,d1
		sub.w		#1,d1		adjust for dbra
next_spc	move.b		d4,0(a0,d6)	add a space
		addq.w		#1,d6		bump line length
		dbra		d1,next_spc	until tab position reached
		bra		next_char

; The Intuition text structure

msg_text	dc.b	1,3	colours to use
		dc.b	0	mode to use (normal)
		even
		dc.w	0,0	text position in window
		dc.l	0	font to use (standard)
msg.ptr		dc.l	msg1	pointer to text
		dc.l	0	end of text list

; Your message should go here

msg1		ds.b	256
		even
*****************************************************************************
PrintStatus	movem.l		d0-d7/a0-a7,-(sp)
		move.l		status_msg.ptr,a0
		lea		status_msg_start,a1
.loop		move.b		(a0)+,(a1)+
		bne.s		.loop
		move.l		#status_msg0,status_msg.ptr
		move.l		#'    ',status_ln
		move.l		start_line_num,d0
		lea		status_line_num,a0
		bsr		word2ascii

		lea		status_struct,a1	a1-->text structure
		moveq.l		#5,d0			x pos of text
		move.l		window.ptr,a0
		move.w		wd_Height(a0),d1
		sub.l		#10,d1			y pos of text
		move.l		window.rp,a0		a0-->window rastport
		CALLINT		PrintIText		print status line
		movem.l		(sp)+,d0-d7/a0-a7
		rts

status_struct	dc.b	3,0	colours to use
		dc.b	RP_JAM2	mode to use
		dc.b	0
		dc.w	0,0	text position in window
		dc.l	0	font to use (standard)
		dc.l	status_text	pointer to text
		dc.l	0	end of text list

status_text	dc.b	'Line: '
status_ln	dc.b	'     '
status_line_num	dc.b	' Col: '
		dc.b	'    0'
status_col_num	dc.b	' Message: '
status_msg_start ds.b	37
		even
status_msg.ptr	dc.l	status_msg1

word2ascii	and.l		#$ffff,d0
		move.b		#'0',-1(a0)
.loop		tst.w		d0
		beq.s		no_ascii
		divu		#10,d0
		swap		d0
		move.w		d0,d1
		and.w		#0,d0
		swap		d0
		add.b		#'0',d1
		move.b		d1,-(a0)
		bra		.loop
no_ascii	rts

*****************************************************************************
; Free the memory used for the text buffer

CloseBuffer	movea.l		text_top,a1
		move.b		-(a0),d0
		move.l		max_text_size,d0
		addq.l		#1,d0
		CALLEXEC	FreeMem
		rts
		
*****************************************************************************

; Releases the main menu and then shuts down the main window.

CloseMainWin	move.l		window.ptr,a0
		CALLINT		ClearMenuStrip

		move.l		window.ptr,a0
		CALLINT		CloseWindow
		
		rts
		
*****************************************************************************

; This routine checks each of the libraries base pointers and closes all 
;those that are set.

CloseLibs	move.l		_IntuitionBase,a1
		beq.s		closeGFX
		CALLEXEC	CloseLibrary
		
closeGFX	move.l		_GfxBase,a1
		beq.s		closeDOS
		CALLEXEC	CloseLibrary
		
closeDOS	move.l		_DOSBase,a1
		beq.s		allclosed
		CALLEXEC	CloseLibrary

allclosed	rts

*****************************************************************************
*******************************  VARIABLES  *********************************
*****************************************************************************

; Variables and data defenition area

intname		dc.b		'intuition.library',0
		even
_IntuitionBase	dc.l		0

grafname	dc.b		'graphics.library',0
		even
_GfxBase	dc.l		0

dosname		dc.b		'dos.library',0
		even
_DOSBase	dc.l		0

_ArpBase	 dc.l		0

stack		dc.l		0		for initial stack pointer

window.ptr	dc.l		0		window structure pointer

window.rp	dc.l		0		window rastport pointer

window.up	dc.l		0		windows userport pointer

linenum		dc.l		10		text y position	

quit_flag	dc.w		0		indicates if user selects quit

scrn_size	dc.l		21		lines on screen

; Text buffer variables

max_text_size	dc.l		0		maximum buffer size

text_top	dc.l		0		address of text buffer

start_line	dc.l		0		address of 1st line on screen

start_line_num	dc.l		0		number of 1st line

num_lines	dc.l		0		number of lines in file

text_size	dc.l		0		size of text file ( bytes )

*****************************************************************************		
; Messages displayed in console windows

mb_msg		dc.b		$0a,' ACC Message: PRESS LEFT MOUSE BUTTON TO CONTINUE.'
mb_len		equ		*-mb_msg
		even
*****************************************************************************
; Data for QUIT requester

body	dc.b	2,2	
	dc.b	0	
	even
	dc.w	50,10	
	dc.l	0	
	dc.l	b_text	
	dc.l	body1	
	
b_text	dc.b	'QUIT, are you sure ?',0
	even
body1	dc.b	2,2	
	dc.b	0	
	even
	dc.w	57,20	
	dc.l	0	
	dc.l	b_text1	
	dc.l	0	
	
b_text1	dc.b	'M.Meany  1990 ',0  message
	even


left	dc.b	2,2	
	dc.b	0	
	even
	dc.w	5,3	
	dc.l	0	
	dc.l	l_text	
	dc.l	0	
	
l_text	dc.b	'CONT',0
	even


right	dc.b	2,2	
	dc.b	0	
	even
	dc.w	5,3	
	dc.l	0	
	dc.l	r_text	
	dc.l	0	
	
r_text	dc.b	'QUIT',0
	even


*****************************************************************************
; Main window data definition

a68k_window	dc.w		0,10	
		dc.w		640,230	
		dc.b		0,1	
		dc.l		NEWSIZE+MOUSEBUTTONS+GADGETDOWN+GADGETUP+MENUPICK+CLOSEWINDOW+RAWKEY
		dc.l		WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIZEBRIGHT+ACTIVATE+NOCAREREFRESH
		dc.l		0	
		dc.l		0	
		dc.l		WindowName
		dc.l		0	
		dc.l		0	
		dc.w		50,50	
		dc.w		640,250	
		dc.w		WBENCHSCREEN

WindowName	dc.b		'A68K Front End v2.6  © M.Meany 1990',0
		even

*****************************************************************************
		
; About window data definition

about_win	dc.w		184,12		
		dc.w		262,122		
		dc.b		0,1		
		dc.l		0		
		dc.l		WINDOWDRAG+ACTIVATE	other window flags
		dc.l		0		
		dc.l		0		
		dc.l		AboutName	
		dc.l		0		
		dc.l		0		
		dc.w		5,5		
		dc.w		640,200		
		dc.w		WBENCHSCREEN	

AboutName	dc.b		'An intuition front end for A68k',0
		even


about_text	dc.b		2,0,RP_JAM2,0	
		dc.w		13,20		
		dc.l		0		
		dc.l		AboutText1	
		dc.l		About2		

AboutText1	dc.b		'This program © M.Meany 1990',0
		even

About2		dc.b		2,0,RP_JAM2,0	
		dc.w		13,31		
		dc.l		0		
		dc.l		AboutText2	
		dc.l		About3		

AboutText2	dc.b		'Feel free to write to me at',0
		even

About3		dc.b		2,0,RP_JAM2,0	
		dc.w		15,42		
		dc.l		0		
		dc.l		AboutText3	
		dc.l		About5		

AboutText3	dc.b		'the following address',0
		even

About5		dc.b		1,0,RP_JAM2,0	
		dc.w		80,64		
		dc.l		0		
		dc.l		AboutText5	
		dc.l		About6		

AboutText5	dc.b		'Mark Meany,',0
		even

About6		dc.b		1,0,RP_JAM2,0	
		dc.w		80,74		
		dc.l		0		
		dc.l		AboutText6	
		dc.l		About7		

AboutText6	dc.b		'1 Cromwell Road,',0
		even

About7		dc.b		1,0,RP_JAM2,0	
		dc.w		80,84		
		dc.l		0		
		dc.l		AboutText7	
		dc.l		About8		

AboutText7	dc.b		'Southampton,',0
		even

About8		dc.b		1,0,RP_JAM2,0	
		dc.w		80,94		
		dc.l		0		
		dc.l		AboutText8	
		dc.l		About9		

AboutText8	dc.b		'Hants.,',0
		even

About9		dc.b		1,0,RP_JAM2,0	
		dc.w		80,104		
		dc.l		0		
		dc.l		AboutText9	
		dc.l		0		

AboutText9	dc.b		'SO1 2JH',0
		even

*****************************************************************************
; Main menu data defenition

main_menu	dc.l		SearchMenu		
		dc.w		10,0		
		dc.w		80,10		
		dc.w		MENUENABLED	
		dc.l		ProjectName	
		dc.l		Project1	
		dc.w		0,0,0,0		

ProjectName	dc.b		'Project',0
		even

Project1	dc.l		Project2	
		dc.w		0,0		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP		Item flags
		dc.l		0		
		dc.l		ClearStruct		
		dc.l		0		
		dc.b		'C'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Clear

ClearStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		ClearText	
		dc.l		0		

ClearText	dc.b		'Clear',0
		even

Project2	dc.l		Project3	
		dc.w		0,10		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP		Item flags
		dc.l		0		
		dc.l		LoadStruct	
		dc.l		0		
		dc.b		'L'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Load

LoadStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		LoadFText
		dc.l		0		

LoadFText	dc.b		'Load',0
		even

Project3	dc.l		Project4	
		dc.w		0,22		
		dc.w		160,8		
		dc.w		ITEMTEXT+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		SaveStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Save

SaveStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		SaveFText
		dc.l		0		

SaveFText	dc.b		'Save',0
		even

Project4	dc.l		Project5	
		dc.w		0,32		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		SaveAsStruct
		dc.l		0		
		dc.b		'S'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		SaveAs

SaveAsStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		SaveAsText
		dc.l		0		

SaveAsText	dc.b		'Save As',0
		even

Project5	dc.l		Project6	
		dc.w		0,44		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		InsertFStruct
		dc.l		0		
		dc.b		'I'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		InsertFile

InsertFStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		InsertFileText
		dc.l		0		

InsertFileText	dc.b		'Insert file',0
		even

Project6	dc.l		Project7	
		dc.w		0,54		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		PrintStruct	
		dc.l		0		
		dc.b		0
		dc.b		0		
		dc.l		Project6a	
		dc.w		MENUNULL	
		dc.l		DoNothing

PrintStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		PrintText
		dc.l		0		

PrintText	dc.b		'Print',0
		even

Project6a	dc.l		Project6b	
		dc.w		145,-8		
		dc.w		64,8		
		dc.w		ITEMTEXT+ITEMENABLED+HIGHCOMP	
		dc.l		0		
		dc.l		PrintFStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		PrintFile

PrintFStruct	dc.b		3,1,RP_COMPLEMENT,0
		dc.w		0,0		
		dc.l		0		
		dc.l		PrintFText
		dc.l		0		

PrintFText	dc.b		' File   ',0
		even

Project6b	dc.l		0		
		dc.w		145,0		
		dc.w		64,8		
		dc.w		ITEMTEXT+ITEMENABLED+HIGHCOMP	
		dc.l		0		
		dc.l		PrintPStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		PrintPage

PrintPStruct	dc.b		3,1,RP_COMPLEMENT,0		
		dc.w		0,0		
		dc.l		0		
		dc.l		PrintPText
		dc.l		0		

PrintPText	dc.b		' Page   ',0
		even

Project7	dc.l		Project8	
		dc.w		0,64		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		AboutStruct
		dc.l		0		
		dc.b		'O'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		About

AboutStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		AboutText
		dc.l		0		

AboutText	dc.b		'About',0
		even

Project8	dc.l		0		
		dc.w		0,76		
		dc.w		160,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		QuitStruct
		dc.l		0		
		dc.b		'Q'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		QuitReq

QuitStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		QuitText
		dc.l		0		

QuitText	dc.b		'Quit',0
		even

SearchMenu	dc.l		OptionsMenu		
		dc.w		100,0		
		dc.w		72,10		
		dc.w		MENUENABLED	
		dc.l		SearchName	
		dc.l		Search1
		dc.w		0,0,0,0		

SearchName	dc.b		'Search',0
		even

Search1		dc.l		Search2
		dc.w		0,0		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		FindStruct
		dc.l		0		
		dc.b		'F'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Find

FindStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		FindText
		dc.l		0		

FindText	dc.b		'Find',0
		even

Search2		dc.l		Search3
		dc.w		0,10		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		FindNStruct
		dc.l		0		
		dc.b		'N'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		FindN

FindNStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		FindNText
		dc.l		0		

FindNText	dc.b		'Find Next',0
		even

Search3		dc.l		Search4
		dc.w		0,20		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		FindPStruct
		dc.l		0		
		dc.b		'P'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		FindP

FindPStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		FindPText
		dc.l		0		

FindPText	dc.b		'Find Previous',0
		even

Search4		dc.l		Search5
		dc.w		0,30		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		ReplaceStruct
		dc.l		0		
		dc.b		'R'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Replace

ReplaceStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		ReplaceText
		dc.l		0		

ReplaceText	dc.b		'Replace',0
		even

Search5		dc.l		0		
		dc.w		0,40		
		dc.w		176,8		
		dc.w		ITEMTEXT+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		ReplaceAllStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		Search6	
		dc.w		MENUNULL	
		dc.l		DoNothing

ReplaceAllStruct dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		ReplaceAllText
		dc.l		0		

ReplaceAllText	dc.b		'Replace All',0
		even

Search6		dc.l		0		
		dc.w		132,6		
		dc.w		128,8		
		dc.w		ITEMTEXT+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		CheckStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		ReplaceAll


CheckStruct	dc.b		2,2,RP_JAM1,0	
		dc.w		0,0		
		dc.l		0		
		dc.l		CheckText
		dc.l		0		

CheckText	dc.b		'Are you sure?',0
		even

OptionsMenu	dc.l		ProgramMenu		
		dc.w		182,0		
		dc.w		80,10		
		dc.w		MENUENABLED	
		dc.l		OptionsName	
		dc.l		Options1
		dc.w		0,0,0,0		

OptionsName	dc.b		'Options',0
		even

Options1	dc.l		Options2
		dc.w		0,0		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		GoLineStruct
		dc.l		0		
		dc.b		'G'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		GoLine

GoLineStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		GoLineText
		dc.l		0		

GoLineText	dc.b		'Goto line',0
		even

Options2	dc.l		Options3
		dc.w		0,10		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		GoTopStruct
		dc.l		0		
		dc.b		'T'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		GoTop

GoTopStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		GoTopText
		dc.l		0		

GoTopText	dc.b		'Goto Top',0
		even

Options3	dc.l		Options4
		dc.w		0,20		
		dc.w		176,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		GoBotStruct
		dc.l		0		
		dc.b		'B'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		GoBot

GoBotStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		GoBotText
		dc.l		0		

GoBotText	dc.b		'Goto Bottom',0
		even

Options4	dc.l		0		
		dc.w		0,35		
		dc.w		176,8		
		dc.w		ITEMTEXT+HIGHCOMP+ITEMENABLED
		dc.l		0		
		dc.l		PrefsStruct
		dc.l		0		
		dc.b		0		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Prefs

PrefsStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		PrefsText
		dc.l		0		

PrefsText	dc.b		'Preferences',0
		even

ProgramMenu	dc.l		0		
		dc.w		272,0		
		dc.w		80,10		
		dc.w		MENUENABLED	
		dc.l		ProgramName	
		dc.l		Program1
		dc.w		0,0,0,0		

ProgramName	dc.b		'Program',0
		even

Program1	dc.l		Program2
		dc.w		0,0		
		dc.w		194,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		AssembleStruct
		dc.l		0		
		dc.b		'A'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Assemble

AssembleStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		AssembleText
		dc.l		0		

AssembleText	dc.b		'Assemble',0
		even

Program2	dc.l		Program3
		dc.w		0,10		
		dc.w		194,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		RunStruct
		dc.l		0		
		dc.b		'X'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Run

RunStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		RunText
		dc.l		0		

RunText		dc.b		'Run',0
		even

Program3	dc.l		0		
		dc.w		0,60		
		dc.w		194,8		
		dc.w		ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP
		dc.l		0		
		dc.l		HelpStruct
		dc.l		0		
		dc.b		'H'		
		dc.b		0		
		dc.l		0		
		dc.w		MENUNULL	
		dc.l		Help

HelpStruct	dc.b		0,0,RP_JAM1,0	
		dc.w		8,0		
		dc.l		0		
		dc.l		HelpText
		dc.l		0		

HelpText	dc.b		'Help',0
		even
	
****************************************************************************

; Data for Go To Line window, gadgets and text.
	
line_window	dc.w		150,90	
		dc.w		279,67		
		dc.b		0,3		
		dc.l		GADGETUP
		dc.l		ACTIVATE		
		dc.l		LineGadg
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.w		5,5		
		dc.w		640,200		
		dc.w		WBENCHSCREEN		

LineGadg	dc.l		LineOKGadg		
		dc.w		120,22		
		dc.w		44,8
		dc.w		0		
		dc.w		RELVERIFY+LONGINT
		dc.w		STRGADGET		
		dc.l		LineGadgBorder
		dc.l		0		
		dc.l		0		
		dc.l		0		
		dc.l		LineGadgInfo		
		dc.w		0		
		dc.l		GotLineNum

LineGadgInfo	dc.l		LineBuffer
		dc.l		0		
		dc.w		0		
		dc.w		5		
		dc.w		0		
		dc.w		0,0,0,0,0		
		dc.l		0		
		dc.l		0		
		dc.l		0		

LineBuffer	dc.b		0,0,0,0,0
		even

LineGadgBorder	dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		LineGadgVectors
		dc.l		0		

LineGadgVectors	dc.w		0,0
		dc.w		47,0
		dc.w		47,9
		dc.w		0,9
		dc.w		0,0

LineOKGadg	dc.l		LineCancelGadg		
		dc.w		33,49		
		dc.w		64,12		
		dc.w		0		
		dc.w		RELVERIFY		
		dc.w		BOOLGADGET		
		dc.l		LineOKBorder
		dc.l		0		
		dc.l		LineOKStruct
		dc.l		0		
		dc.l		0		
		dc.w		0		
		dc.l		GotLineNum		

LineOKBorder	dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		LineOKVectors
		dc.l		0		

LineOKVectors	dc.w		0,0
		dc.w		67,0
		dc.w		67,13
		dc.w		0,13
		dc.w		0,0

LineOKStruct	dc.b		3,0,RP_JAM2,0		
		dc.w		24,3		
		dc.l		0		
		dc.l		LineOKText	
		dc.l		0		

LineOKText	dc.b		'OK',0
		even

LineCancelGadg	dc.l		0		
		dc.w		180,49		
		dc.w		64,12		
		dc.w		0		
		dc.w		RELVERIFY		
		dc.w		BOOLGADGET		
		dc.l		LineCancelBorder
		dc.l		0		
		dc.l		LineCancelStruct
		dc.l		0		
		dc.l		0		
		dc.w		0		
		dc.l		NoLineNum

LineCancelBorder dc.w		-2,-1		
		dc.b		3,0,RP_JAM1		
		dc.b		5		
		dc.l		LineCancelVectors
		dc.l		0		

LineCancelVectors dc.w		0,0
		dc.w		67,0
		dc.w		67,13
		dc.w		0,13
		dc.w		0,0

LineCancelStruct dc.b		3,0,RP_JAM2,0		
		dc.w		8,3		
		dc.l		0		
		dc.l		LineCancelText
		dc.l		0		

LineCancelText	dc.b		'CANCEL',0
		even

LineWinText	dc.b		3,0,RP_JAM2,0		
		dc.w		15,23		
		dc.l		0		
		dc.l		LineWinTextStr	
		dc.l		0		

LineWinTextStr	dc.b		'GO TO LINE :',0
		even
****************************************************************************

; ACC messages for the status line.
;				'                                   '
status_msg0	dc.b		'OK.                                ',0
		even

status_msg1	dc.b		'No file loaded.                    ',0
		even
		
status_msg2	dc.b		'Top of file.                       ',0
		even
		
status_msg3	dc.b		'Bottom of file.                    ',0
		even
		
status_msg4	dc.b		'Invalid line number.               ',0
		even

status_msg5	dc.b		'String not found.                  ',0
		even
		
status_msg6	dc.b		'Text file larger than buffer.      ',0
		even

status_msg7	dc.b		'No pathname selected.              ',0
		even

status_msg8	dc.b		'No memory for file info block.     ',0
		even
		
status_msg9	dc.b		'Could not Lock file.               ',0
		even
		
status_msg10	dc.b		'Could not open Input file.         ',0
		even
		
status_msg11	dc.b		'Could not open Output file.        ',0
		even
		
status_msg12	dc.b		'Could not open Assembly window.    ',0
		even
		
status_msg13	dc.b		'Could not open Default window.     ',0
		even
		
status_msg14	dc.b		'Could not open Printer Device prt:.',0
		even
		
status_msg15	dc.b		'Not enough room in buffer.         ',0
		even

status_msg16	dc.b		'Position marked.                   ',0
		even
		
status_msg17	dc.b		'No position specified.             ',0
		even
		
status_msg20	dc.b		'Function not yet implemented.      ',0
		even
;***********************************************************
;	FileRequester Structures
;***********************************************************


;------	hail text is what will appear in requesters window title	

Requesterflags	EQU	0

LoadFileStruct	dc.l		LoadText	
		dc.l		LoadFileData	
		dc.l		LoadDirData	
		dc.l		0		
		dc.b		Requesterflags	
		dc.b		0		
		dc.l		0		
		dc.l		0		

;------	this is not part of the Filerequest structure but is our
;	extension and can be accessed using the fr_SIZEOF offset

		dc.l		LoadPathName
	
SaveFileStruct	dc.l		SaveText	
		dc.l		SaveFileData	
		dc.l		SaveDirData	
		dc.l		0		
		dc.b		Requesterflags!FRF_DoColor
		dc.b		0		
		dc.l		0		
		dc.l		0		

;------	this is not part of the Filerequest structure but is our
;	extension and can be accessed using the fr_SIZEOF offset

		dc.l		SavePathName

InsertFileStruct dc.l		InsertTitle	
		dc.l		InsertFileData	
		dc.l		InsertDirData	
		dc.l		0		
		dc.b		Requesterflags	
		dc.b		0		
		dc.l		0		
		dc.l		0		

;------	this is not part of the Filerequest structure but is our
;	extension and can be accessed using the fr_SIZEOF offset

		dc.l		InsertPathName

;------	This is the text for requesters title

LoadText	dc.b	'Load File ',0

SaveText	dc.b	'Save File ',0

InsertTitle	dc.b	'Insert File ',0
		even

;***********************************************************
	SECTION	FileRequest,BSS
;***********************************************************

LoadFileData	ds.b	FCHARS+1	;reserve space for filename buffer
		EVEN
	
LoadDirData	ds.b	DSIZE+1		;reserve space for path buffer
		EVEN

SaveFileData	ds.b	FCHARS+1	;reserve space for filename buffer
		EVEN
	
SaveDirData	ds.b	DSIZE+1		;reserve space for path buffer
		EVEN
		
InsertFileData	ds.b	FCHARS+1
		even
		
InsertDirData	ds.b	DSIZE+1

LoadPathName	ds.b	DSIZE+FCHARS+2	;reserve space for full pathname name buffer
		EVEN

SavePathName	ds.b	DSIZE+FCHARS+2	;reserve space for full pathname name buffer
		even

InsertPathName	ds.b	DSIZE+FCHARS+2
		even
