*****************************************************************
*	THIS IS THE TT/STE OR ST VERSION OF THE FILESELECTOR	*
*								*
*	TO MAKE IT USE THE ST COMPATABLE FSEL SET THE STFLAG	*
*	VARIABLE TO 1, TO MAKE IT USE TT/STE FSEL SET STFLAG	*
*	TO -1.							*
*								*
*****************************************************************
	opt	C8+
	xref	_intin,_intout,_ptsin,_ptsout,_contrl
	xref	_loadlength,_delete,_createdir
	xdef	_fileselector,_myfp,_aespb,_doalert
	xdef	_savefile,_loadfile,_format
	xdef	_addrin,_addrout,_global

*****************************************************************
*	This is the save file bit, it'll handle all warnings	*
*	about overwriting existing files etc, so it should be	*
*	fairly user friendly.					*
*	Call like this...SAVEFILE(data.L,length.L)		*
*								*
*	Returns:	0.L	for user decided not to		*
*				overwrite an existing file	*
*				or not correct an error		*
*				either way the file did not	*
*				get written			*
*			1.L	for complete success		*
*			-1.L	for some general error		*
*								*
*	I'll handle most general errors such as disk write	*
*	protected by asking if they wanna try again.		*
*****************************************************************
_savefile:
	move.l	4(sp),filelength
	move.l	8(sp),fileaddress
	movem.l	d1-d7/a0-a6,-(sp)
retry:
	move    #1,-(SP)        ;Open file for write
	move.l  #_myfp,-(SP) 	;Address of filename
	move    #$3d,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0		;doesn't exist
	beq	create
	tst.w	d0		;other error
	bmi	docn2
	move.w	d0,-(sp)
	lea	existalert,a0
	jsr	_doalert
	move.w	(sp)+,d0
	cmpi.w	#1,_intout
	beq	conts
	moveq	#0,d0
	bra	saveback
conts:
	move.w	d0,-(sp)
cb:
	move.w	(sp),d0
	move.l  fileaddress,-(SP)
	move.l  filelength,-(SP)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	add.l   #12,SP
	tst.w	d0
	bmi	failwrite
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	moveq	#1,d0
saveback:
	movem.l	(sp)+,d1-d7/a0-a6
	rts
create:
	move.w	#$0,-(sp)	;its a new file so I gotta create it
	move.l	#_myfp,-(sp)	;filename
	move.w	#$3c,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bmi.s	docn		;still something wrong
	move.w	d0,-(sp)	;put the handle on the stack
	bra	cb
docn:
	lea	save1,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	create
	moveq	#0,d0
	bra	saveback
docn2:
	lea	save1,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	retry
	moveq	#0,d0
	bra	saveback
failwrite:
	lea	save2,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	cb
	
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	moveq	#-1,d0
	bra	saveback

filelength:	dc.l	0
fileaddress:	dc.l	0
save1:
		dc.b	'[1][Cannot create file.|'
		dc.b	'Is the disk write protected ?]'
		dc.b	'[Try again|Cancel]',0,0
save2:
		dc.b	'[1][Cannot write file.|'
		dc.b	'Is the disk write protected ?]'
		dc.b	'[Try again|Cancel]',0,0
existalert:
		dc.b	'[1][File already exists !|'
		dc.b	'Overwrite ?]'
		dc.b	'[Yes|No]',0,0

	even

*****************************************************************
*	Load a file with complete path and name in myfp		*
*	Simplicity itself					*
*	call LOADFILE(address.L)				*
*				just give me the place to put	*
*				it.				*
*	Returns:						*
*				1.L	for complete success	*
*				-1.L	for file did not exist	*
*					and user wants to try	*
*					again.			*
*				-2.L	for file did not exist	*
*					and user doesn't give	*
*					a shit.			*
*				-3.L	for some general error	*
*****************************************************************
_loadfile:
	move.l	4(sp),fileaddress
	movem.l	d1-d7/a0-a6,-(sp)

	move    #0,-(SP)        ;Open file
	move.l  #_myfp,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	tst.w	d0
	bmi	loaderror
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  fileaddress,-(SP)	;load it straight onto screen
	move.l  #1000000,-(SP)	;shouldn't be any files bigger than this
	move    D0,-(SP)	;Handle
	move    #$3F,-(SP)	;bios number
	trap    #1		;Read file in
	add.l   #12,SP
	tst.l	d0
	bmi	loade2
	move.l	d0,_loadlength
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	moveq	#1,d0
loadback:
	movem.l	(sp)+,d1-d7/a0-a6
	rts

loaderror:
	cmpi.w	#-33,d0
	beq	fnferror
	moveq	#-3,d0
	bra	loadback
fnferror:
	lea	fnealert,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	bne	fnf2
	moveq	#-1,d0		;say user wants to try again
	bra	loadback
fnf2:
	moveq	#-2,d0
	bra	loadback

loade2:
	addq.l	#2,sp
	moveq	#-3,d0
	bra	loadback
fnealert:
	dc.b	'[1][Cannot load file!]'
	dc.b	'[Try again|Cancel]'
	even
*****************************************************************
*	FORMAT, this is a bit clumsy at present as nothing	*
*	is visible when the format is happenning, something	*
*	to look at in the phase II release.			*
*	Call by:						*
*			Format()				*
*								*
*	I do all the alerts n shit and let em choose A or B.	*
*****************************************************************
_format:
	movem.l	d0-d7/a0-a6,-(sp)	;save all the regs
	lea	formatexplain,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	beq	formatreturn
	lea	format2,a0
	bsr	_doalert
	cmpi.w	#1,_intout
	bne	fb
	move.w	#0,drive
	bra	formatter
fb:
	move.w	#1,drive
formatter:
	dc.w	$a00a
	bsr	putbox		;put box up here
	dc.w	$a009
	moveq	#0,d7
fml:
	move.w	d7,-(sp)
	dc.w	$a00a		;mouse off
	moveq	#0,d0		;print side
	moveq	#10,d1
	moveq	#45,d2
	moveq	#14,d3
	bsr	prtnum
	moveq	#0,d0
	move.w	d7,d0		;print track
	moveq	#10,d1
	moveq	#45,d2
	moveq	#16,d3
	bsr	prtnum
	dc.w	$a009		;mouse on
	

	move.w	(sp),d7
	move.w	#$0,-(sp)
	move.l	#$87654321,-(sp)
	move.w	#1,-(sp)
	move.w	#0,-(sp)	;side
	move.w	d7,-(sp)
	move.w	#9,-(sp)
	move.w	drive,-(sp)
	clr.l	-(sp)
	move.l	#fbuffer,-(sp)
	move.w	#10,-(sp)
	trap	#14
	add.l	#26,sp
	tst.w	d0
	bmi	ferror


	dc.w	$a00a		;mouse off
	moveq	#1,d0		;print side
	moveq	#10,d1
	moveq	#45,d2
	moveq	#14,d3
	bsr	prtnum
*	moveq	#0,d0
*	move.w	d7,d0		;print track
*	moveq	#10,d1
*	moveq	#23,d2
*	moveq	#13,d3
*	bsr	prtnum
	dc.w	$a009		;mouse on
	move.w	(sp),d7
	move.w	#$0,-(sp)
	move.l	#$87654321,-(sp)
	move.w	#1,-(sp)
	move.w	#1,-(sp)	;side
	move.w	d7,-(sp)
	move.w	#9,-(sp)
	move.w	drive,-(sp)
	clr.l	-(sp)
	move.l	#fbuffer,-(sp)
	move.w	#10,-(sp)
	trap	#14
	add.l	#26,sp
	tst.w	d0
	bmi	ferror
	move.w	(sp)+,d7
	addq.w	#1,d7
	cmpi.w	#79,d7
	ble	fml

	move.w	#0,-(sp)	;not executable
	move.w	#3,-(sp)	;80 trks dbl
	move.l	#$01000001,-(sp)
	move.l	#fbuffer,-(sp)	;produce boot sector
	move.w	#18,-(sp)
	trap	#14
	add.l	#14,sp

	MOVE #1,-(A7)		number of sectors
	MOVE #0,-(A7)		side 0
	MOVE #0,-(A7)		track 0
	MOVE #1,-(A7)		sector 1
	MOVE drive,-(A7)		drive 0
	MOVE.L #0,-(A7)		not used
	MOVE.L #fbuffer,-(A7)		buffer address
	MOVE #9,-(A7)		_FLOPWR
	TRAP #14		write boot sector & directory
	ADDA.L #20,A7		tidy stack
	tst.w	d0
	bmi	ferror2
	lea	fsuccess,a0
	bsr	_doalert
	bra	formatreturn
ferror:
	move.w	(sp)+,d7
	lea	ferroralert,a0
ferror2:
	bsr	_doalert
	bra	formatreturn

formatreturn:
	movem.l	(sp)+,d0-d7/a0-a6
	rts

putbox:
	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	lea	box,a0
	move.l	d0,a2
	moveq	#111,d0		;yheight
	add.l	#173*320+240/16*4*2,a2
	move.l	a2,a1
pbloop:
	rept	10
	move.w	(a0),(a1)+
	move.w	(a0),(a1)+
	move.w	(a0),(a1)+
	move.w	(a0)+,(a1)+
	endr
	lea	320(a2),a2
	move.l	a2,a1
	dbf	d0,pbloop
	rts

*****************************************
*	number in d0.l			*
*	d1.l is base			*
*	d2,x cursor			*
*	d3,y cursor			*
*****************************************
prtnum:
	movem.l	d0/d1,-(sp)
	lea	posstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
	move.b	d3,8(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
	move.b	d2,9(a0)	
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d0/d1

	lea	linebuffer,a0
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
loop1:
	divu	d1,d0
	swap	d0
	addi	#'0',d0
	cmpi.w	#'9',d0
	ble.s	ok
	addq.w	#7,d0
ok:
	move.b	d0,-(a0)
	clr	d0
	swap	d0
	bne	loop1
loop2:
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts


linebuffer:
	ds.l	5
digits:
	dc.b	0
posstring:	dc.b	27,'Y',0,0,' ',' ',27,'Y',0,0,0
	even



drive:	dc.w	0
fsuccess:
	dc.b	'[1][Disk formatting complete.|'
	dc.b	'This disk has 726016 bytes|'
	dc.b	'available.][ OK ]',0,0
ferroralert:
	dc.b	'[1][An error has occurred|'
	dc.b	'during formatting. Disk|'
	dc.b	'may be unusable.][ OK ]',0,0
formatexplain:
	dc.b	'[3][Formatting a disk will|'
	dc.b	'ERASE everything on it, click|'
	dc.b	'OK only if you are sure you|'
	dc.b	'wish to continue.]'
	dc.b	'[CANCEL|OK]',0,0
format2:
	dc.b	'[2][Which drive do you wish|'
	dc.b	'to format ?][ A | B ]',0,0
	even
fbuffer:	ds.b	$2000

*****************************************************************
*	Call fileselector, call with address of search pattern	*
*	On stack and address of name for fselector on stack	*
*	ie:							*
*		fileselector(name.l,extender.l)			*
*								*
*	If pattern matching is not required ie: we don't give	*
*	a shit what the 3 byte extender is, then set the search	*
*	mask with the first byte negative.			*
*	eg:							*
*		searchmask:	dc.b	-1			*
*	Returns in d0:		0.L for user chose cancel	*
*				1.L for complete success	*
*				    and filename and path	*
*				    are both in myfp		*
*				-1.Lfor file not matching search*
*				    criteria			*
*				-2.Lfor some general error	*
*				-3.Lfor OK hit but no file	*
*				    selected.			*
*								*
*	Note that for errors -2 and -3 myfp is not valid	*
*								*
*								*
*	Also:		The complete filename and path in	*
*			myfp.					*
*								*
*****************************************************************
_fileselector:
	move.l	8(sp),savetitle	;save the title
	move.l	4(sp),savesearch	;save the ad of .xxx
	movem.l	d1-d7/a0-a6,-(sp)

*	tst.w	firstfile
*	bpl	firsttime
*fback:
*	bsr	setsearch		;go and set the path and pattern
	lea	myfile,a0
	move.b	#0,(a0)
ttstefsel:
	move.l	#_myfp,_addrin		;must get these adresses
	move.l	#myfile,_addrin+4	;from C
	move.l	savetitle,_addrin+8	;title for fsel
	move.w	#91,_contrl		;new routine with 91 for ext in TT
	move.w	#0,_contrl+2		;title ability
	move.w	#2,_contrl+4
	move.w	#3,_contrl+6		;3 for ext in TT
	move.w	#0,_contrl+8
	move.l	#_aespb,d1
	move.w	#$c8,d0
	trap	#2
fselok:
	tst.w	_intout
	bne	nogeneralerror
	moveq	#-2,d0			;return general error occurred
	movem.l	(sp)+,d1-d7/a0-a6
	rts
nogeneralerror:
	tst.w	_intout+2		;was it exited by cancel
	beq	chosecancel

getfileandpath:
	move.l	savesearch,a6
	lea	mypath,a0
	lea	myfile,a2
	lea	_myfp,a1			;place to put the final
gpl:					;construction of file and path
	move.b	(a0)+,d0
	beq	getf
	move.b	d0,(a1)+
	bra.s	gpl
getf:
	move.b	-(a1),d0
	cmpi.b	#'\',d0
	bne.s	getf
	addq.l	#1,a1

	tst.b	(a2)		;check if any file was selected
	beq	nofile		;if first char of file name is 0
getf2:
	move.b	(a2)+,d0
	beq	geto
	move.b	d0,(a1)+
	bra.s	getf2
geto:
	move.b	#0,(a1)		;null terminator
	subq.l	#3,a1
	tst.b	(a6)		;if first byte is negative
	bmi.s	nocheckpath	;skip check
	cmp.b	(a6)+,(a1)+	;check for correct file type
	bne	notright
	cmp.b	(a6)+,(a1)+
	bne	notright
	cmp.b	(a6)+,(a1)+
	bne	notright
nocheckpath:
	pea	dta
	move.w	#$1a,-(sp)	;set disk transfer address
	trap	#1
	addq.l	#6,sp
	move.w	#0,-(sp)	;search for normal files
	pea	_myfp
	move.w	#$4e,-(sp)
	trap	#1
	addq.l	#8,sp
	lea	dta,a0
	move.l	26(a0),_loadlength
	moveq	#1,d0		;return success
	movem.l	(sp)+,d1-d7/a0-a6
	rts
chosecancel:
	moveq	#0,d0		;return that cancel was chosen
	movem.l	(sp)+,d1-d7/a0-a6
	rts
notright:
	moveq	#-1,d0		;return that file was not correct
	movem.l	(sp)+,d1-d7/a0-a6
	rts			;extender
nofile:
	moveq	#-3,d0		;return that file was not correct
	movem.l	(sp)+,d1-d7/a0-a6
	rts			;extender
savesearch:	dc.l	0
savetitle:	dc.l	0
*****************************************************************
*	Subroutine to get path and set search string		*
*	Pass the address of the 3 byte extender in a0		*
*****************************************************************
setsearch:
	lea	mypath,a0
epl:					;construction of file and path
	move.b	(a0)+,d0
	beq	etf
	bra.s	epl
etf:
	move.b	(a0),d0
	cmp.b	#'\',d0
	beq	etf2
	move.b	#0,(a0)
	subq.l	#1,a0
	bra.s	etf
etf2:
*	move.w	#0,-(sp)
	move.l	#mypath,-(sp)
	move.w	#$3b,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	savesearch,a1
	lea	mypath,a0
infloop:
	tst.b	(a0)+
	bne.s	infloop		;find the end of the path, null byte
	subq.l	#1,a0
*	move.b	#'\',(a0)+	;stick in the new search pattern
	move.b	#'*',(a0)+
	move.b	#'.',(a0)+
	tst.b	(a1)
	bmi.s	nopat
	move.b	(a1)+,(a0)+	;3 byte extender
	move.b	(a1)+,(a0)+
	move.b	(a1)+,(a0)+
	move.b	#0,(a0)+
	rts
nopat:
	move.b	#'*',(a0)+
	move.b	#0,(a0)+
	rts

firsttime:
	move.w	#-1,firstfile
	move.w	#0,-(sp)
	move.l	#mypath,-(sp)
	move.w	#$47,-(sp)
	trap	#1
	addq.l	#8,sp
	lea	mypath,a0
sple:
	move.b	(a0)+,d0
	beq	sple2
	bra	sple
sple2:
	move.b	#'\',-1(a0)
	move.b	#0,(a0)
*	bra	fback

firstfile:	dc.w	1
*********************************************************
*	Pass a0 address of description			*
*********************************************************
_doalert:
	move.w	#52,_contrl
	move.w	#1,_contrl+2
	move.w	#1,_contrl+4
	move.w	#1,_contrl+6
	move.w	#0,_contrl+8
	move.w	#1,_intin
	move.l	a0,_addrin
	move.l	#_aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts
box:
; pixel width of image = 160
; pixel height of image = 112
; word width of image = 10
; planes in image = 1
    dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF
    dc.w    $FFFF,$FFFF,$8000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0001,$8000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0001,$9FFF,$FFFF
    dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFF9
    dc.w    $9FFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF
    dc.w    $FFFF,$FFF9,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$007E,$3CF8,$C618,$7E7E
    dc.w    $7E66,$3E00,$0000,$0019,$9800,$0000,$007E,$7EFC
    dc.w    $C63C,$7E7E,$7E66,$7E00,$0000,$0019,$9800,$0000
    dc.w    $0060,$66CC,$EE7E,$1818,$1866,$6000,$0000,$0019
    dc.w    $9800,$0000,$0060,$66CC,$EE66,$1818,$1876,$6000
    dc.w    $0000,$0019,$9800,$0000,$007C,$66CC,$FE66,$1818
    dc.w    $1876,$6E00,$0000,$0019,$9800,$0000,$007C,$66FC
    dc.w    $D666,$1818,$187E,$6E00,$0000,$0019,$9800,$0000
    dc.w    $0060,$66F8,$D67E,$1818,$187E,$6600,$0000,$0019
    dc.w    $9800,$0000,$0060,$66D8,$C67E,$1818,$186E,$6600
    dc.w    $0000,$0019,$9800,$0000,$0060,$66CC,$C666,$1818
    dc.w    $186E,$6600,$0000,$0019,$9800,$0000,$0060,$66CC
    dc.w    $C666,$1818,$1866,$6600,$0000,$0019,$9800,$0000
    dc.w    $0060,$7EC6,$C666,$1818,$7E66,$7E00,$0000,$0019
    dc.w    $9800,$0000,$0060,$3CC6,$C666,$1818,$7E66,$3C00
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$3E7E,$787E,$0000,$0000,$0000
    dc.w    $0000,$003C,$3C00,$0019,$9800,$7E7E,$7C7E,$0000
    dc.w    $0000,$0000,$0000,$007E,$7E00,$0019,$9800,$6018
    dc.w    $6E60,$1800,$0000,$0000,$0000,$0066,$6600,$0019
    dc.w    $9800,$6018,$6660,$1800,$0000,$0000,$0000,$0066
    dc.w    $6600,$0019,$9800,$7018,$667C,$1800,$0000,$0000
    dc.w    $0000,$0066,$6600,$0019,$9800,$3818,$667C,$1800
    dc.w    $0000,$0000,$0000,$006E,$6E00,$0019,$9800,$1C18
    dc.w    $6660,$0000,$0000,$0000,$0000,$0076,$7600,$0019
    dc.w    $9800,$0E18,$6660,$0000,$0000,$0000,$0000,$0066
    dc.w    $6600,$0019,$9800,$0618,$6660,$1800,$0000,$0000
    dc.w    $0000,$0066,$6600,$0019,$9800,$0618,$6E60,$1800
    dc.w    $0000,$0000,$0000,$0066,$6600,$0019,$9800,$7E7E
    dc.w    $7C7E,$1800,$0000,$0000,$0000,$007E,$7E00,$0019
    dc.w    $9800,$7C7E,$787E,$1800,$0000,$0000,$0000,$003C
    dc.w    $3C00,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$7EF8,$183C,$CC00,$0000,$0000
    dc.w    $0000,$003C,$3C00,$0019,$9800,$7EFC,$3C7E,$CC00
    dc.w    $0000,$0000,$0000,$007E,$7E00,$0019,$9800,$18CC
    dc.w    $7E66,$D818,$0000,$0000,$0000,$0066,$6600,$0019
    dc.w    $9800,$18CC,$6666,$D818,$0000,$0000,$0000,$0066
    dc.w    $6600,$0019,$9800,$18CC,$6660,$F018,$0000,$0000
    dc.w    $0000,$0066,$6600,$0019,$9800,$18FC,$6660,$F018
    dc.w    $0000,$0000,$0000,$006E,$6E00,$0019,$9800,$18F8
    dc.w    $7E60,$D800,$0000,$0000,$0000,$0076,$7600,$0019
    dc.w    $9800,$18D8,$7E60,$D800,$0000,$0000,$0000,$0066
    dc.w    $6600,$0019,$9800,$18CC,$6666,$CC18,$0000,$0000
    dc.w    $0000,$0066,$6600,$0019,$9800,$18CC,$6666,$CC18
    dc.w    $0000,$0000,$0000,$0066,$6600,$0019,$9800,$18C6
    dc.w    $667E,$C618,$0000,$0000,$0000,$007E,$7E00,$0019
    dc.w    $9800,$18C6,$663C,$C618,$0000,$0000,$0000,$003C
    dc.w    $3C00,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9800,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0000,$0000,$0019
    dc.w    $9800,$0000,$0000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0019,$9800,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0019,$9800,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0019,$9FFF,$FFFF
    dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFF9
    dc.w    $9FFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF
    dc.w    $FFFF,$FFF9,$8000,$0000,$0000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0001,$8000,$0000,$0000,$0000
    dc.w    $0000,$0000,$0000,$0000,$0000,$0001,$FFFF,$FFFF
    dc.w    $FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF,$FFFF

mypath:
	ds.b	64
	even
myfile:	ds.b	13
	even

_myfp:	ds.b	100
_addrin:		ds.w	128
_addrout:	ds.w	128
_global:		dc.w	0,0,0,0,0,0,0
		dc.w	0,0,0,0,0,0,0,0
_aespb:		dc.l	_contrl,_global,_intin,_intout,_addrin,_addrout
dta:		ds.b	44
**********************************************************
**********************************************************
**********************************************************
**********************************************************
