NEW
  AUTO 3,1
*--------------------------------------
BS.KW.BSAVE		bcc	LAE2D

				lda	GP.FoundBITS+1
				and	#$B0
				cmp	#$90

XAE00			bcc	LAE31

				lda	GP.ParamA
				sta	GP.CRAUXTYPE
				sta	GP.FIAUXTYPE
				lda	GP.ParamA+1
				sta	GP.CRAUXTYPE+1
				sta	GP.FIAUXTYPE+1
				lda	#$06
				sta	GP.ParamT
				sta	GP.FITYPE
				lda	GP.FoundBITS
				and	#$04
				bne	LAE31

				jsr	BS.CreateFileOrDir
				bcs	LAE33

				jsr	BS.GetFileInfo
				bcs	LAE33

LAE2D			lda	#$02
				bne LAE44

LAE31			lda	#$06

LAE33			sec
				rts

BS.KW.BRUN		jsr	BS.KW.BLOAD
				bcs	LAE33

				jsr	LAE3F
				clc
				rts

LAE3F			jmp	(GP.MLIRW.DATAPTR)

BS.KW.BLOAD		lda	#$01
LAE44			ldx	#$06
				jsr	BS.CheckFTypeXAccessA
				bcs	LAE33

				ldx	GP.ParamA
				ldy	GP.ParamA+1
				lda	GP.FoundBITS+1
				bmi	LAE66

				ldx	GP.FIAUXTYPE
				ldy	GP.FIAUXTYPE+1
				lda	GP.FoundBITS
				and	#$04
				bne	LAEAB

				lda	GP.FoundBITS+1

LAE66			stx	GP.MLIRW.DATAPTR
				sty	GP.MLIRW.DATAPTR+1
				bit	GP.FoundBITS+1
				bvs	LAE80

				pha
				lda	GP.FITYPE
				cmp	#$06
				bne	LAE7F

				stx	GP.FIAUXTYPE
				sty	GP.FIAUXTYPE+1

LAE7F			pla
LAE80			ldx	GP.ParamL
				ldy	GP.ParamL+1
				and	#$30
				beq	LAEAF

				eor	#$30
				beq	LAEAB

				and	#$10
				beq	LAEC5

				lda	GP.ParamE
				sec
				sbc	GP.ParamA
				tax
				lda	GP.ParamE+1
				sbc	GP.ParamA+1
				tay
				inx
				bne	LAEA5

				iny

LAEA5			bcs	LAEC5

				lda	#$02
				sec
				rts

LAEAB			lda	#$0B
				sec
				rts

LAEAF			lda	#MLI.C.GETEOF
				jsr	GP.GOSYSTEM
				bcs	LAEC3

				ldx	GP.SBUFADR
				ldy	GP.SBUFADR+1
				lda	GP.SBUFADR+2
				beq	LAEC5

				lda	#$0E
LAEC3			sec
				rts

LAEC5			stx	GP.MLIRW.COUNT
				sty	GP.MLIRW.COUNT+1
				lda	GP.FoundBITS+1
				and	#$40
				beq	LAEF7

				ldx	#$02
LAED4			lda	GP.ParamB,x
				sta	GP.SBUFADR,x
				dex
				bpl	LAED4

LAEDD			lda	#MLI.C.SETMARK
				jsr	GP.GOSYSTEM
				ldx	GP.XCNUM
				bcc	LAEF7

				cmp	#$02
				bne	LAEC3

				cpx	#$0F
				bne	LAEC3

				lda	#MLI.C.SETEOF
				jsr	GP.GOSYSTEM
				bcc	LAEDD
				rts

LAEF7			ldx	GP.XCNUM
				lda	#$CA
				cpx	#$0F
				bne	LAF24

				bit	GP.FoundBITS+1
				bvs	LAF22

				lda	GP.FoundBITS+1
				and	#$30
				beq	LAF22

				lda	GP.MLIRW.COUNT
				sta	GP.SBUFADR
				lda	GP.MLIRW.COUNT+1
				sta	GP.SBUFADR+1
				lda	#$00
				sta	GP.SBUFADR+2
				lda	#MLI.C.SETEOF
				jsr	GP.GOSYSTEM

LAF22			lda	#MLI.C.WRITE

LAF24			jsr	GP.GOSYSTEM
				bcs	LAF38
				bit	GP.FoundBITS+1
				bvs	LAF35

				cpx	#$0F
				bne	LAF35

				jsr	BS.SetFileInfoNoDate

LAF35			jmp	BS.FileClose

LAF38			sec
				rts

BS.KW.SAVE		bcc	LAF4E

				lda	#$FD
				sta	GP.ParamT
				sta	GP.FITYPE
				lda	#$C3
				sta	GP.FIACCESS
				jsr	BS.CreateFileOrDir
				bcs	LAF9C

LAF4E			jsr	LA411
				bcs	LAF9C

				ldx	#$FD
				lda	#$02
				jsr	BS.CheckFTypeXAccessA
				bcs	LAF95

				jsr	BS.SetupRW5AtBBE4
				jsr	BS.WriteXYBytes
				bcs	LAF95

				lda	XBBE9
				sta	GP.MLIRW.DATAPTR
				sta	GP.FIAUXTYPE
				lda	XBBEA
				sta	GP.MLIRW.DATAPTR+1
				sta	GP.FIAUXTYPE+1
				ldy	XBBEC
				ldx	XBBEB
				jsr	BS.WriteXYBytes
				bcs	LAF95

				lda	#MLI.C.GETMARK
				jsr	GP.GOSYSTEM
				lda	#MLI.C.SETEOF
				jsr	GP.GOSYSTEM
				bcs	LAF95

				jsr	BS.SetFileInfoNoDate
				bcs	LAF95

				jsr	BS.FileClose

LAF95			php
				pha
				jsr	LA480
				pla
				plp
LAF9C			rts

BS.SetupRW5AtBBE4
				lda	#$E4
				sta	GP.MLIRW.DATAPTR
				lda	#$BB
				sta	GP.MLIRW.DATAPTR+1
				ldy	#$00
				ldx	#$05
				rts

BS.KW.LOAD		ldx	#$FD
				lda	#$01
				jsr	BS.CheckFTypeXAccessA
				bcs	LAF9C

				jsr	BS.SetupRW5AtBBE4
				jsr	BS.ReadXYBytes
				bcs	LAF9C

				lda	GP.FIAUXTYPE
				sta	XBBE9
				sta	GP.MLIRW.DATAPTR
				lda	AS.HIMEM+1
				sec
				sbc	BS.BAS.HDR+4
				clc
				adc	GP.FIAUXTYPE+1
				sta	GP.MLIRW.DATAPTR+1
				sta	XBBEA
				cmp	AS.PGRMEND+1
				bcc	LAFF3

				beq	LAFF3

				lda	#$00
				sbc	XBBE9
				tax
				lda	AS.HIMEM+1
				sbc	XBBEA
				tay
				jsr	BS.ReadXYBytes
				bcs	LAF9C

				jsr	BS.FileClose
				jmp	LAF95

LAFF3			lda	#$0E
				sec
				rts

BS.FileClose	lda	#MLI.C.CLOSE
				bne	LB007

BS.ReadXYBytes	lda	#MLI.C.READ
				bne	LB001

BS.WriteXYBytes	lda	#MLI.C.WRITE
LB001			sty	GP.MLIRW.COUNT+1
				stx	GP.MLIRW.COUNT

LB007			jmp	GP.GOSYSTEM

BS.KW.IN		lda	#$00
				sta	BS.GetCharSep
				beq	LB018

BS.KW.PR		lda	#$02
				sta	BS.GetCharSep
				lda	#$08
LB018			ora	GP.ParamINPR
				asl
				tax
				lda	GP.FoundBITS
				and	#$40
				beq	LB035

				lda	GP.FoundBITS+1
				bmi	LB04A

				lda	GP.OUTVECT0,x
				sta	GP.ParamA
				lda	GP.OUTVECT0+1,x
				sta	GP.ParamA+1

LB035			jsr	LB05C
				bcs	LB049

				ldy	BS.GetCharSep
				lda	GP.ParamA
				sta	ZP.CSW,y
				lda	GP.ParamA+1
				sta	ZP.CSW+1,y
LB049			rts

LB04A			jsr	LB05C
				bcs	LB05B

				lda	GP.ParamA+1
				sta	GP.OUTVECT0+1,x
				lda	GP.ParamA
				sta	GP.OUTVECT0,x
LB05B			rts

LB05C			lda	GP.ParamA
				sta	ZP.PCL
				lda	GP.ParamA+1
				sta	ZP.PCH
				ldy	#$00
				cmp	#$C0
				bcc	LB081

				lda	$CFFF
				sty	ZP.A1L
				lda	(ZP.PCL),y
				cmp	#$FF
				beq	LB087

LB077			cmp	(ZP.PCL),y
				bne	LB087

				dec	ZP.A1L
				bne	LB077

LB07F			clc
				rts

LB081			lda	(ZP.PCL),y
				cmp	#$D8
				beq	LB07F

LB087			lda	#$03
				sec
				rts

BS.KW.BYE		jsr	LB562
				jsr	LB36B
				lda	#$65
				jsr	MLI
				.DA #MLI.C.QUIT
				.DA	GP.MLIRW

LB099			jsr	MLI
				.DA #MLI.C.QUIT
				.DA BS.MLIQUIT2.Param
BS.MLIQUIT2.Param
				.DA #4
				.DA #$EE
				.DA MLI.PATHBUF
				.DA #0
				.DA 0

BS.KW.CAT		lda	#$27
				bne	LB0AC

BS.KW.CATALOG	lda	#$4F

LB0AC			sta	BS.CATWIDTH
				lda	GP.FoundBITS
				and	#$05
				lsr
				bne	LB0BA

				sta	GP.ParamT

LB0BA			bcs	LB0C1

				jsr	BS.GetFileInfo
				bcs	LB127

LB0C1			jsr	LB1BA
				bcs	LB127

				jsr	BS.CROUT
				jsr	LB128
				jsr	BS.LINEBUFOUT
				jsr	BS.CROUT
				jsr	BS.LINEBUFCLR80
				ldx	#$10
				jsr	BS.PRINTERRMSGX
				jsr	BS.LINEBUFOUT
				jsr	BS.CROUT
				lda	XBC14
				ora	XBC15
				nop
				nop

LB0E8			jsr	LB241
				bcs	LB113

				lda	GP.ParamT
				beq	LB0F7

				cmp	DIRENTBUF.TYPE
				bne	LB0FD

LB0F7			jsr	LA4D2
				jsr	BS.LINEBUFOUT

LB0FD			lda	IO.KBD
				cmp	#$83
				bne	LB10E

				lda	GP.STATE
				bne	LB113

				bit	IO.KSTROBE
				bcs	LB113

LB10E			nop
				lda	#$FF
				bne	LB0E8

LB113			jsr	BS.FileClose
				bcs	LB127

				jsr	BS.CROUT
				jsr	LB157
				bcs	LB127

				jsr	BS.LINEBUFOUT
				jsr	BS.CROUT

				clc
LB127			rts

LB128			jsr	BS.LINEBUFCLR80
				ldx	#$01
				ldy	DIRENTBUF.STNL
				lda	#$AF
				cpy	#$F0
				bcc	LB13A

				sta	IO.LINEBUF,x
				inx

LB13A			tya
				and	#$0F
				sta	IO.LINEBUF
				ldy	#$05

LB142			lda	DIRENTBUF,y
				ora	#$80
				sta	IO.LINEBUF,x
				iny
				inx
				dec	IO.LINEBUF
				bne	LB142

				lda	#$A2
				sta	IO.LINEBUF
				rts

LB157			lda	#$18
				sta	GP.SBUFADR
				lda	#$BC
				sta	GP.SBUFADR+1
				lda	MLI.DEVNUM
				sta	GP.MLIMRKEOFBUF.REFNUM
				lda	#MLI.C.ONLINE
				jsr	GP.GOSYSTEM
				bcs	LB127

				lda	BS.CMDBUF
				and	#$0F
				tax
				inx
				stx	BS.CMDBUF.LEN
				lda	#$AF
				sta	BS.CMDBUF
				jsr	BS.GetFileInfo
				bcs	LB127

				jsr	BS.LINEBUFCLR80
				ldx	#$36
				jsr	BS.PRINTERRMSGX
				jsr	BS.TMPBUF3Reset
				lda	GP.FIAUXTYPE
				ldx	GP.FIAUXTYPE+1
				ldy	#$3D
				jsr	BS.AXDEC2LINEBUFY
				lda	GP.FIBLOKS
				ldx	GP.FIBLOKS+1
				ldy	#$26
				jsr	BS.AXDEC2LINEBUFY
				lda	GP.FIAUXTYPE
				sec
				sbc	GP.FIBLOKS
				pha
				lda	GP.FIAUXTYPE+1
				sbc	GP.FIBLOKS+1
				tax
				pla
				ldy	#$10
				jsr	BS.AXDEC2LINEBUFY
				clc
				rts

LB1BA			lda	#$01
				ldx	#$0F
				ldy	GP.STTYPE
				cpy	#$0F
				bne	LB1C8

				stx	GP.FITYPE

LB1C8			jsr	LB210
				bcs	LB203

BS.ReadDirEnt	lda	#$59
				sta	GP.MLIRW.DATAPTR
				lda	#$02
				sta	GP.MLIRW.DATAPTR+1
				lda	#$2B
				sta	GP.MLIRW.COUNT
				lda	#$00
				sta	GP.MLIRW.COUNT+1
				lda	#MLI.C.READ
				jsr	GP.GOSYSTEM
				bcs	LB203

				ldx	#$03

LB1EA			lda	$27C,x
				sta	XBC12,x
				dex
				bpl	LB1EA

				sta	GP.MLIRW.COUNT
				lda	#$01
				sta	XBC16
				lda	#$00
				sta	GP.SBUFADR+1
				sta	GP.SBUFADR+2
LB203			rts

BS.CheckFTypeXAccessA
				pha
				lda	GP.FoundBITS
				and	#$04
				beq	LB20F

				ldx	GP.ParamT

LB20F			pla

LB210			cpx	GP.FITYPE
				bne	LB239

				and	GP.FIACCESS
				beq	LB23D

				lda	XBBE3
				sta	GP.OSYSBUF+1
				lda	#$0F
				sta	MLI.LEVEL
				lda	#MLI.C.OPEN
				jsr	GP.GOSYSTEM
				bcs	LB238

				lda	GP.OREFNUM
				sta	GP.MLIRW.REFNUM
				sta	GP.MLICF.REFNUM
				sta	GP.MLIMRKEOFBUF.REFNUM

LB238			rts

LB239			lda	#$0D
				sec
				rts

LB23D			lda	#$0A
				sec
				rts

LB241			lda	GP.SBUFADR+1
				and	#$FE
				sta	GP.SBUFADR+1
				ldy	XBC16
				lda	#$00
				cpy	XBC13
				bcc	LB25D

				tay
				sty	XBC16
				inc GP.SBUFADR+1

LB25A			inc GP.SBUFADR+1

LB25D			dey
				clc
				bmi	LB268

				adc	XBC12
				bcc	LB25D

				bcs	LB25A

LB268			adc	#$04
				sta	GP.SBUFADR
				lda	#MLI.C.SETMARK
				jsr	GP.GOSYSTEM
				bcs	LB28D

				lda	#MLI.C.READ
				jsr	GP.GOSYSTEM
				bcs	LB28D

				inc	XBC16
				lda	DIRENTBUF
				and	#$F0
				beq	LB241

				dec	XBC14
				bne	LB28D

				dec	XBC15

LB28D			rts
BS.JMP.XTRNADDR	jmp	(GP.XTRNADDR)

BS.KW.EXEC		jsr	BS.CheckFilename
				bcs	LB2C0

				bit	GP.EXECFILE
				bpl	LB2BC

				sta	GP.MLIMRKEOFBUF.REFNUM
				lda	#$00
				sta	GP.SBUFADR
				sta	GP.SBUFADR+1
				sta	GP.SBUFADR+2
				lda	#MLI.C.SETMARK
				jsr	GP.GOSYSTEM
				bcs	LB2B5

				lda	GP.MLIMRKEOFBUF.REFNUM
				bne	LB333

LB2B5			pha
				jsr	LB36B
				pla
				sec
				rts

LB2BC			lda	#$14
				sec
				rts

LB2C0			bit	GP.EXECACTV
				bpl	LB2CA

				jsr	LB36B
				bcs	LB2D3

LB2CA			lda	GP.FITYPE
				cmp	#$04
				beq	LB2D5

				lda	#$0D
LB2D3			sec
				rts

LB2D5			jsr	LA1F9
				bcs	LB2D3

				lda	#$00
				sta	GP.SBUFADR
				lda	XBBE3
				sta	GP.SBUFADR+1
				ldx	GP.OPENCNT
				beq	LB30E

				tay
				txa
				asl
				asl
				adc	XBBE3
				pha
LB2F2			cmp	XBBEE,x
				beq	LB2FB

				dex
				bne	LB2F2

				brk

LB2FB			tya
				sta	XBBEE,x
				lda	XBBF6,x
				sta	GP.MLIMRKEOFBUF.REFNUM
				lda	#MLI.C.SETBUF
				jsr	GP.GOSYSTEM
				bcc	LB30D

				brk

LB30D			pla
LB30E			sta	XBBE3
				sta	GP.OSYSBUF+1
				lda	#$00
				sta	MLI.LEVEL
				lda	#MLI.C.OPEN
				jsr	GP.GOSYSTEM
				bcc	LB327

				pha
				jsr	LA250
				pla
				sec
				rts

LB327			ldx	GP.OSYSBUF+1
				stx	XBBF6
				lda	GP.OREFNUM
				sta	XBBFE
LB333			sta	GP.MLIRW.REFNUM
				sta	GP.MLIMRKEOFBUF.REFNUM
				sta	GP.NEWLREF
				ldx	GP.FIAUXTYPE
				stx	GP.ParamL
				ldx	GP.FIAUXTYPE+1
				stx	GP.ParamL+1
				jsr	LB45B
				lda	#$7F
				sta	GP.NLINEMASK
				lda	#MLI.C.NEWLINE
				jsr	GP.GOSYSTEM
				lda	GP.FoundBITS+1
				and	#$03
				beq	LB364

				jsr	LB592
				bcc	LB364

				jmp	LB2B5

LB364			lda	#$FF
				sta	GP.EXECACTV
				clc
				rts

LB36B			lda	GP.EXECACTV
				bpl	LB37B

				sta	GP.EXECFILE
				ldx	#$08
				lda	XBBF6,x
				jsr	LB515

LB37B			rts

BS.KW.X10		bcs	LB3B7

				lda	GP.FoundBITS
				and	#$01
				bne	LB38D

				ldx	#$00
				jsr	BS.PRINTERRX
				jsr	BS.CROUT

LB38D			clc
				rts

				lda	#$00
				beq	LB39F

BS.KW.FLUSH		lda	GP.FoundBITS
				and	#$01
				beq	LB39F

				jsr	BS.CheckFilename
				bcs	LB3A7

LB39F			sta	GP.MLICF.REFNUM
				lda	#MLI.C.FLUSH
				jsr	GP.GOSYSTEM

LB3A7			rts

BS.KW.03		php
				jsr	BS.CheckFilename
				bcs	LB3BB

				plp
				lda	#$14
				sec
				rts

LB3B3			lda	#$0D
				sec
				rts

LB3B7			lda	#$06
LB3B9			sec
				rts

LB3BB			plp
				ldx	#$00
				ldy	#$00
				lda	GP.FoundBITS+1
				and	#$10
				bne	LB3CD

				stx	GP.ParamL+1
				sty	GP.ParamL

LB3CD			lda	GP.FoundBITS
				and	#$04
				eor	#$04
				beq	LB3DB

				lda	#$04
				sta	GP.ParamT

LB3DB			bcc	LB3FE

				beq	LB3B7

				sta	GP.FITYPE
				lda	#$C3
				sta	GP.FIACCESS
				ldx	GP.ParamL+1
				ldy	GP.ParamL
				stx	GP.CRAUXTYPE+1
				stx	GP.FIAUXTYPE+1
				sty	GP.CRAUXTYPE
				sty	GP.FIAUXTYPE
				jsr	BS.CreateFileOrDir
				bcs	LB3B9

LB3FE			lda	GP.FITYPE
				cmp	GP.ParamT
				bne	LB3B3

				cmp	#$04
				bne	LB41D

				ldx	GP.FIAUXTYPE+1
				ldy	GP.FIAUXTYPE
				lda	GP.FoundBITS+1
				and	#$10
				bne	LB41D

				stx	GP.ParamL+1
				sty	GP.ParamL

LB41D			jsr	LA1F9
				bcs	LB3B9

				lda	XBBE3
				sta	GP.OSYSBUF+1
				lda	#$07
				sta	MLI.LEVEL
				lda	#MLI.C.OPEN
				jsr	GP.GOSYSTEM
				bcc	LB43B

				pha
				jsr	LA250
				pla
				sec
				rts

LB43B			lda	GP.FITYPE
				cmp	#$0F
				beq	LB443

				clc

LB443			lda	#$00
				ror
				sta	GP.DIRFLG
				ldx	GP.OPENCNT
				lda	XBBE3
				sta	XBBEF,x
				lda	GP.OREFNUM
				sta	XBBF7,x
				inc	GP.OPENCNT
LB45B			asl
				asl
				asl
				asl
				asl
				tax
				lda	MLI.PATHBUF
				ora	GP.DIRFLG
				sta	XBC59,x
				and	#$7F
				tay
				cmp	#$1E
				bcc	LB473

				lda	#$1D

LB473			sta	ZP.PCL
				lda	GP.ParamL
				sta	XBC5A,x
				lda	GP.ParamL+1
				sta	XBC5B,x

LB481			inx
				lda	MLI.PATHBUF,y
				sta	XBC5B,x
				dey
				dec	ZP.PCL
				bne	LB481

BS.KW.X07		clc
				rts

BS.CheckFilename
				lda	GP.FoundBITS
				and	#$01
				bne	LB49A

				lda	#$10
				sec
				rts

LB49A			ldx	GP.OPENCNT
				beq	LB4B8

				stx	GP.EXECFILE

LB4A2			stx	ZP.PCH
				lda	XBBF6,x
				jsr	LB4D2
				bne	LB4B3

				ldx	ZP.PCH

LB4AE			lda	XBBF6,x
LB4B1			clc
				rts

LB4B3			ldx	ZP.PCH
				dex
				bne	LB4A2

LB4B8			lda	GP.EXECACTV
				bpl	LB4CE

				lda	XBBFE
				jsr	LB4D2
				bne	LB4CE

				lda	#$FF
				sta	GP.EXECFILE
				ldx	#$08
				bne	LB4AE

LB4CE			lda	#$12
				sec
				rts

LB4D2			asl
				asl
				asl
				asl
				asl
				tax
				lda	XBC59,x
				sta	GP.DIRFLG
				and	#$7F
				cmp	MLI.PATHBUF
				bne	LB508

				tay
				cmp	#$1E
				bcc	LB4EC

				lda	#$1D

LB4EC			sta	ZP.PCL
				lda	XBC5A,x
				sta	XBBFF
				lda	XBC5B,x
				sta	XBC00

LB4FA			inx
				lda	MLI.PATHBUF,y
				cmp	XBC5B,x
				bne	LB508

				dey
				dec	ZP.PCL
				bne	LB4FA

LB508			rts

BS.KW.X06		lda	GP.FoundBITS
				and	#$01
				beq	LB562

				jsr	BS.CheckFilename
				bcs	LB4B1

LB515			sta	GP.MLICF.REFNUM
				lda	XBBEE,x
				sta	XBBE3
				bit	GP.EXECFILE
				bmi	LB53F

				ldy	GP.OPENCNT
				pha
				lda	XBBEE,y
				sta	XBBEE,x
				pla
				sta	XBBEE,y
				lda	XBBF6,x
				pha
				lda	XBBF6,y
				sta	XBBF6,x
				pla
				sta	XBBF6,y

LB53F			lda	#$00
				sta	MLI.LEVEL
				lda	#MLI.C.CLOSE
				jsr	GP.GOSYSTEM
				bcs	LB572

				jsr	LA250
				bit	GP.EXECFILE
				bpl	LB55E

				pha
				lda	#$00
				sta	GP.EXECACTV
				sta	GP.EXECFILE
				pla
				rts

LB55E			dec GP.OPENCNT
				rts

LB562			ldx	GP.OPENCNT
				beq	LB573

				stx	GP.EXECFILE
				lda	XBBF6,x
				jsr	LB515
				bcc	LB562

LB572			rts

LB573			lda	#$00
				sta	GP.MLICF.REFNUM
				lda	#$07
				sta	MLI.LEVEL
				lda	#MLI.C.CLOSE
				jmp	GP.GOSYSTEM

BS.KW.CLOSE		jsr	BS.CheckFilename
				bcs	LB5EF

				sta	GP.MLIRW.REFNUM
				sta	GP.NEWLREF
				bit	GP.DIRFLG
				bmi	LB5F0

LB592			lda	GP.FoundBITS+1
				and	#$03
				beq	LB5ED

				cmp	#$03
				beq	LB5ED

				and	#$01
				beq	LB5AD

				lda	GP.ParamR
				sta	GP.ParamF
				lda	GP.ParamR+1
				sta	GP.ParamF+1

LB5AD			lda	#$EF
				sta	GP.MLIRW.COUNT
				lda	#$00
				sta	GP.MLIRW.COUNT+1
				sta	GP.MLIRW.DATAPTR
				lda	#$02
				sta	GP.MLIRW.DATAPTR+1
				lda	#$7F
				sta	GP.NLINEMASK
				lda	#MLI.C.NEWLINE
				jsr	GP.GOSYSTEM
				bcs	LB5EF

LB5CB			lda	GP.ParamF
				ora	GP.ParamF+1
				clc
				beq	LB5F0

				lda	#MLI.C.READ
				jsr	GP.GOSYSTEM
				bcs	LB5EF

				lda	GP.ParamF
				sbc	#$00
				sta	GP.ParamF
				lda	GP.ParamF+1
				sbc	#$00
				sta	GP.ParamF+1
				bcs	LB5CB

LB5ED			lda	#$0B
LB5EF			sec
LB5F0			rts

LB5F1			lda	XBBFF
				sta	BS.TMPBUF4
				lda	XBC00
				sta	BS.TMPBUF4+1
				lda	#$00
				sta	BS.TMPBUF4+2
				sta	BS.TMPBUF4+3
				sta	GP.SBUFADR
				sta	GP.SBUFADR+1
				sta	GP.SBUFADR+2
LB60E			lsr GP.ParamR+1
				ror GP.ParamR
				ldx	#$00
				bcc	LB62F

				clc

LB619			lda	BS.TMPBUF4,x
				adc	GP.SBUFADR,x
				sta	GP.SBUFADR,x
				inx
				txa
				eor	#$03
				bne	LB619

				bcs	LB642

				ldx	BS.TMPBUF4+3
				bne	LB642

LB62F			rol BS.TMPBUF4,x
				inx
				txa
				eor	#$04
				bne	LB62F

				lda	GP.ParamR
				ora	GP.ParamR+1
				bne	LB60E

				clc
				rts

LB642			lda	#$02
				sec
				rts

BS.KW.X04		jsr	BS.CheckFilename
				bcs	LB69B

				sta	GP.MLIRW.REFNUM
				sta	GP.MLIMRKEOFBUF.REFNUM
				sta	GP.NEWLREF
				bit	GP.DIRFLG
				bmi	LB69C

				jsr	LB6D0
				bcs	LB69B

				ldx	#$7F
				ldy	#$EF
				lda	GP.FoundBITS+1
				and	#$10
				beq	LB67C

				ldy	GP.ParamL
				ldx	GP.ParamL+1
				bne	LB6CB

				cpy	#$EF
				bcs	LB6CB

				lda	#$22
				sta	IO.LINEBUF

				lda	#$01

LB67C			sta	GP.MLIRW.DATAPTR
				sty	GP.MLIRW.COUNT
				stx	GP.NLINEMASK
				lda	#$02
				sta	GP.MLIRW.DATAPTR+1
				lda	#$00
				sta	GP.MLIRW.COUNT+1
				lda	#MLI.C.NEWLINE
				jsr	GP.GOSYSTEM
				bcs	LB69B

LB696			lda	#$FF
				sta	GP.IFILACTV
LB69B			rts

LB69C			lda	#$59
				sta	GP.MLIRW.DATAPTR
				lda	#$02
				sta	GP.MLIRW.DATAPTR+1
				lda	#$01
				sta	GP.CATFLAG
				lda	GP.FoundBITS+1
				and	#$01
				clc
				beq	LB696

				lda	#$00
				sta	GP.SBUFADR
				sta	GP.SBUFADR+1
				sta	GP.SBUFADR+2
				lda	#MLI.C.SETMARK
				jsr	GP.GOSYSTEM
				bcs	LB6CA

				lda	#$FF
				sta	GP.IFILACTV

LB6CA			rts

LB6CB			lda	#$02
				tax
				sec
				rts

LB6D0			lda	GP.FoundBITS+1
				and	#$43
				beq	LB719

				and	#$01
				beq	LB6E5

				jsr	LB5F1
				bcs	LB6CB

LB6E0			jsr	LB712
				bcs	LB71A
LB6E5
				lda	GP.FoundBITS+1
				and	#$02
				beq	LB6F1

				jsr	LB5AD
				bcs	LB71A

LB6F1			lda	GP.FoundBITS+1
				and	#$40
				beq	LB719

				lda	#MLI.C.GETMARK
				jsr	GP.GOSYSTEM
				bcs	LB71A

				ldx	#$00
				ldy	#$02

LB703			lda	GP.ParamB,x
				adc	GP.SBUFADR,x
				sta	GP.SBUFADR,x
				inx
				dey
				bpl	LB703

				bcs	LB6CB

LB712			lda	#MLI.C.SETMARK
				jsr	GP.GOSYSTEM
				bcs	LB71A

LB719			clc
LB71A			ldx	#$00
				rts

BS.KW.X08		jsr	BS.CheckFilename
				bcs	LB732

				sta	GP.MLIRW.REFNUM
				sta	GP.MLIMRKEOFBUF.REFNUM
				sta	GP.NEWLREF
				bit	GP.DIRFLG
				bpl	LB734

				lda	#$0A

LB732			sec
				rts

LB734			lda	#$00
				sta	GP.MLIRW.DATAPTR
				lda	#$02
				sta	GP.MLIRW.DATAPTR+1
				jsr	LB6D0
				bcc	LB757

				cmp	#$02
				bne	LB732

				cpx	#$02
				beq	LB732

LB74B			lda	#MLI.C.SETEOF
				jsr	GP.GOSYSTEM
				bcs	LB732

				jsr	LB6E0
				bcs	LB732

LB757			lda	AS.HIMEM
				sta	GP.MLIRW.DATAPTR
				lda	AS.HIMEM+1
				sta	GP.MLIRW.DATAPTR+1
				lda	#$FF
				sta	GP.OFILACTV
				clc
				rts

BS.KW.X09		php
				jsr	BS.CheckFilename
				bcc	LB77A

				plp
				jsr	BS.KW.03
				bcs	LB788

				lda	GP.OREFNUM
				bne	LB77B

				brk

LB77A			plp

LB77B			sta	GP.MLIRW.REFNUM
				sta	GP.MLIMRKEOFBUF.REFNUM
				bit	GP.DIRFLG
				bpl	LB78A

				lda	#$0A

LB788			sec
				rts

LB78A			ldx	GP.ParamL
				ldy	GP.ParamL+1
				lda	GP.FoundBITS+1
				and	#$10
				bne	LB79D

				ldx	GP.FIAUXTYPE
				ldy	GP.FIAUXTYPE+1
LB79D			txa
				pha
				lda	GP.MLIRW.REFNUM
				lsr
				ror
				ror
				ror
				tax
				pla
				sta	XBC5A,x
				sta	XBBFF
				tya
				sta	XBC5B,x
				sta	XBC00
				lda	#MLI.C.GETEOF
				jsr	GP.GOSYSTEM
				bcs	LB788

				lda	XBC00
				bne	LB7C8

				lda	XBBFF
				cmp	#$02
				bcc	LB7CD

LB7C8			jsr	LB7D0
				bcs	LB788

LB7CD			jmp	LB74B

LB7D0			ldx	#$03
LB7D2			lda	GP.MLIMRKEOFBUF.REFNUM,x
				sta	XBC09,x
				dex
				bne	LB7D2

				stx	BS.TMPBUF4+3
				stx	XBC0E
				ldy	#$18

LB7E3			jsr	BS.TMPBUF3x2
				rol BS.TMPBUF4+3
				rol XBC0E
				sec
				lda	BS.TMPBUF4+3
				sbc	XBBFF
				tax
				lda	XBC0E
				sbc	XBC00
				bcc	LB805

				stx	BS.TMPBUF4+3
				sta	XBC0E
				inc	BS.TMPBUF4

LB805			dey
				bne	LB7E3

				lda	BS.TMPBUF4+3
				ora	XBC0E
				clc
				beq	LB839

				lda	XBBFF
				sec
				sbc	BS.TMPBUF4+3
				tax
				lda	XBC00
				sbc	XBC0E
				tay
				txa
				clc
				adc	GP.SBUFADR
				sta	GP.SBUFADR
				tya
				adc	GP.SBUFADR+1
				sta	GP.SBUFADR+1
				lda	GP.SBUFADR+2
				adc	#$00
				sta	GP.SBUFADR+2
				lda	#$02

LB839			rts

BS.GetFileInfo	lda	#$0A
				sta	GP.SSGINFO
				lda	#MLI.C.GETFILEINFO
				bne	LB858

BS.SetFileInfoNoDate
				lda	#$00
				sta	GP.FIMDATE
				sta	GP.FIMDATE+1
				sta	GP.FICDATE
				sta	GP.FICDATE+1

BS.SetFileInfo	lda	#$07
				sta	GP.SSGINFO
				lda	#MLI.C.SETFILEINFO

LB858			jmp	GP.GOSYSTEM

BS.JMP.GP.VSYSO	jmp	(GP.VSYSO)
BS.JMP.GP.VSYSI	jmp	(GP.VSYSI)
*--------------------------------------
MAN
SAVE usr/src/basic.15/basic.s.c
LOAD usr/src/basic.15/basic.s
ASM
