NEW
  AUTO 3,1
*--------------------------------------
XBBD7			.BS 1
XBBD8			.BS 1

XBBD9			.BS 1					.DA #4 ????
XBBDA			.BS 1
XBBDB			.BS 1
XBBDD			.BS 1
*--------------------------------------
BSX.FRE0		jsr	BSX.FRE1
				bcs	.9

				lda ASX.PGRMSTART+1
				sta	BS.TXTTAB+1
				lda ASX.PGRMSTART
				sta	BS.TXTTAB

				lda ASX.HIMEM+1
				sta	XBBD8
				lda #$03
				sta	XBBD9

				lda ASX.STRINGSTART+1
				sta	BS.MEMSIZE+1

				lda	#$00
				sta	BS.MEMSIZE
				bra	BSX.FRE2			Z
				
.9				rts				
*--------------------------------------
BSX.FRE1		stz	BS.TXTTAB

				lda ASX.HIMEM+1
				sta	XBBD8
				lda #$03
				sta	XBBD9

				lda ASX.STRINGSTART+1
				sta	BS.TXTTAB+1
				sec
				sbc	ASX.ARRAYEND+1
				cmp	#$07
				bcc	.1

				sbc	#$03
				sta	XBBD9

				lda ASX.ARRAYEND+1
				adc	#$00
				sta	XBBD8

				lda ASX.HIMEM+1
				sbc	ASX.STRINGSTART+1
				adc	#$01
				cmp	XBBD9
				bcs	.1

				sta	XBBD9

.1				lda ASX.HIMEM+1
				sta	BS.MEMSIZE+1

				lda ASX.HIMEM
				sta	BS.MEMSIZE
				sta	ASX.STRINGSTART
*--------------------------------------
BSX.FRE2		clc
				beq	.1

				sec

.1				lda BS.MEMSIZE+1
				sta	ASX.STRINGSTART+1
				sbc	#$00
				sta	XBBDA
				adc	#$00
				sta	XBBDB
				lda ASX.ARRAYEND+1
				adc	#$01
				sta	XBBDD

.2				lda ASX.VARSTART
				sbc	#$06
				sta	ZP.A2L

				lda ASX.VARSTART+1
				sbc	#$00
				sta	ZP.A2H

				lda ASX.ARRAYSTART
				sta	XBBDC
				lda XBBDA
				cmp	BS.TXTTAB+1
				bcc	.9

				sbc	XBBD9
				sta	XBBD7

				lda ASX.STRINGSTART+1
				sbc	XBBDA
				sbc	XBBD7
				eor	#$FF
				adc	#$02
				cmp	XBBD7
				bcc	.3

				lda XBBD7

.3				cmp	BS.TXTTAB+1
				bcs	.4

				lda BS.TXTTAB+1
				sbc	#$00

.4				sta	XBBDA
				jsr	BSX.LA199
				ldx	ASX.ARRAYSTART+1
				jsr	BSX.LA0FB
				bcs	.5

				jsr	BSX.LA131
				lda XBBDA
				sta	XBBDB
				bcc	.2

.5				lda #BS.E.NOBUFFER
.9				rts
*--------------------------------------
BSX.LA0FB		clc

.1				lda ZP.A2L
				adc	#$07
				sta	ZP.A2L
				bcc	.2

				inc	ZP.A2H

.2				eor	ASX.ARRAYSTART
				bne	.3

				cpx	ZP.A2H
				beq	BSX.LA12F

.3				ldy	#$00
				lda (ZP.A2L),y
				iny
				eor	(ZP.A2L),y
				bpl	BSX.LA0FB

				lda (ZP.A2L),y
				bpl	BSX.LA0FB

				ldy	#$04
				lda (ZP.A2L),y
				cmp	XBBDA
				bcc	.1

				cmp	XBBDB
				bcs	BSX.LA0FB

				jsr	BSX.LA1BC
				bcc	.1

				rts

BSX.LA12F		clc
				rts
*--------------------------------------
BSX.LA131		jsr	BSX.LA160
				bcs	BSX.LA12F

.1				ldy	#$02
				lda (ZP.A2L),y
				cmp	XBBDA
				bcc	.2

				cmp	XBBDB
				bcs	.2

				jsr	BSX.LA1BC
				bcc	.3

				rts

.2				clc

.3				lda #$03
				adc	ZP.A2L
				sta	ZP.A2L
				bcc	.4

				inc	ZP.A2H

.4				cmp	XBBDC
				bne	.1

				cpx	ZP.A2H
				bne	.1

				beq	BSX.LA131
*--------------------------------------
BSX.LA160		clc
				lda XBBDC
				sta	ZP.A2L
				stx	ZP.A2H
				eor	ASX.ARRAYEND
				bne	.1

				cpx	ASX.ARRAYEND+1
				beq	.9

.1				ldy	#$02
				lda (ZP.A2L),y
				adc	ZP.A2L
				sta	XBBDC
				iny
				lda (ZP.A2L),y
				adc	ZP.A2H
				tax
				ldy	#$00
				lda (ZP.A2L),y
				iny
				eor	(ZP.A2L),y
				bpl	BSX.LA160

				ldy	#$04
				lda (ZP.A2L),y
				asl
				adc	#$05
				adc	ZP.A2L
				sta	ZP.A2L
				bcc	.9

				inc	ZP.A2H

				clc
.9				rts
*--------------------------------------
BSX.LA199		lda XBBD7
				sta	ZP.PCH
				lda XBBD8
				sta	ZP.A1H
				ldy	#$00
				sty	ZP.PCL
				sty	ZP.A1L
				ldx	XBBD9
				inx

.1				lda (ZP.PCL),y
				sta	(ZP.A1L),y
				iny
				bne	.1

				inc	ZP.A1H
				inc	ZP.PCH
				dex
				bne	.1

				rts
*--------------------------------------
BSX.LA1BC		cmp	XBBD7
				bcc	.1

				sbc	XBBD7
				clc
				adc	XBBD8

.1				sta	ZP.PCH
				dey
				lda (ZP.A2L),y
				sta	ZP.PCL
				dey

				sec
				lda ASX.STRINGSTART
				sbc	(ZP.A2L),y
				sta	ASX.STRINGSTART
				sta .3+1
				iny
				sta	(ZP.A2L),y

				lda ASX.STRINGSTART+1
				sbc	#$00
				sta	ASX.STRINGSTART+1
				sta .3+2
				iny
				sta	(ZP.A2L),y
				dey
				dey
				lda (ZP.A2L),y
				beq	.8

				tay

.2				dey
				lda (ZP.PCL),y
.3				sta	$FFFF,y				SELF MODIFIED
				tya
				bne	.2

.8				clc
				lda XBBDD
				sbc	ASX.STRINGSTART+1
				rts
*--------------------------------------
*--------------------------------------
MAN
SAVE usr/src/basic.fx/basic.s.xm
LOAD usr/src/basic.fx/basic.s
ASM
