;SAVE#D:bcalc.pt4
;
;start of parsing	;!!!!!!!! INVERSE CHARS !!!!!!!!
TRYFNC	LDA #0
	STA FPPTR
	JSR ZFR0
PARS	LDX #0
	STX STR
PLP	LDA STRING,X
	STA BF1,X
	CMP #EOL
	BEQ PDON
	INX 
	BNE PLP
PDON	STX STR
;pass 1 remove @	;!!!!!!!! INVERSE CHARS !!!!!!!!
;replace with #	;!!!!!!!! INVERSE CHARS !!!!!!!!
; @ABS(---,---,---)
; TM  !TM1!       TM2	;!!!!!!!! SPECIAL CHARS !!!!!!!!
;fpn1-3 fp tokens
FNDFUN	LDX #1
FFK	LDA BF1,X
	CMP #'@
	BEQ FFN
	INX 
	CPX STR
	BNE FFK
FFT	JMP PASS2 	;none
FFN	STX TM
	LDA # >FTAB
	STA LL+1
	LDA # <FTAB
	STA LL
	INX 
	STX TM1
FFS	LDY #0
FFR	LDA (LL),Y
	BEQ FFT 	;no mat
	BMI FFP 	;lst chr
	CMP BF1,X
	BNE FFQ 	;next
	INX 
	INY 
	BNE FFR
FFQ	LDA #4
	JSR INCLL
	LDX TM1
	BNE FFS
FFP	AND #$7F
	CMP BF1,X
	BNE FFQ
	LDY #3
	LDA (LL),Y 	;F#
	STA ASAV
	INX 
	STX TM1 	;)?
	ASL A
	TAX 
	LDA JTAB,X
	STA JPOFF+1
	LDA JTAB+1,X
	STA JPOFF+2
;now get arguments	;!!!!!!!! INVERSE CHARS !!!!!!!!
;if 1 arg. in fr0	;!!!!!!!! INVERSE CHARS !!!!!!!!
	LDA #0
	STA NARG
	LDY TM1
	LDA BF1,Y
	CMP #'(
	BEQ FFD
FFX	SEC  	;error
	RTS 
FFD	INY 
	LDA BF1,Y 	;ck 4 cell
	CMP #'D
	BCS FFX 	;error
	CMP #'A
	BCS FFW 	;cell
	STY CIX 	;#
	STY TM1
	JSR FP2BF1
	JSR AFP
	BCS FFX
	JSR SPFR2ST
	BCS FFX
	LDY CIX
FFH	LDA BF1,Y 	; , or )
	CMP #')
	BNE FFC
	JMP FFI
FFC	CMP #',
	BEQ FFD
	BNE FFX
FFW	STY TM1
	JSR GTCLRW
FFY	BCS FFX 	;error
	LDY NARG
	LDA COLNU
	STA COLF,Y
	LDA ROWNU
	STA ROWF,Y
	LDA ASAV
	CMP #7 	;cnting only
	BEQ FVA
	LDX COLNU
	LDA ROWNU
	JSR CL2FR0
	BCS FFY
FVA	LDY NARG
	LDA #$80
	STA ARGT,Y
	JSR SPFR2ST
	BCS FFY
FVB	LDA TM1
	CLC 
	ADC #4
	STA TM1
	TAY 
	JMP FFH
;collapse & do fp	;!!!!!!!! INVERSE CHARS !!!!!!!!
FFI	INY 
	STY TM2
	LDY TM
	LDX TM2
	JSR COLAPS
	LDX #0
FFO	LDA BF1,X
	CMP #EOL
	BEQ FFL
	INX 
	BNE FFO
FFL	STX STR
	JSR ADD2SP
	LDY TM
	LDA #'#
	STA BF1,Y
	LDA FPN1
	STA BF1+1,Y
JPOFF	JSR $FFFF
;back to begin	;!!!!!!!! INVERSE CHARS !!!!!!!!
	BCC JJJ
	RTS 
JJJ	JMP FNDFUN
SPFR2ST	LDA FPPTR
	LDY NARG
	STA FPN1,Y
	INC NARG
	INY 
	CPY #3
	BCS FFG
	TAX 
	JSR FR0X
	INC FPPTR
	CLC 
	RTS 
FFG	SEC 
	RTS 
;get a cell's #	;!!!!!!!! INVERSE CHARS !!!!!!!!
;X=col A=row FR0=#	;!!!!!!!! INVERSE CHARS !!!!!!!!
CL2FR0	STX COLNU
	JSR STRAD
EE	LDY #0
	LDA (LL),Y
	CMP #$FF
	BEQ ED
	CMP COLNU
	BEQ EB
	BCC EC
ED	SEC  	;err
	RTS 
EC	JSR UP1COL
	JMP EE
	RTS  	;c is set
EB	LDY #3 	;data typ
	LDA (LL),Y
	AND #3
	BEQ EN 	;txt!
	CMP #1
	BEQ EF
	LDY #2 	;fn
	LDA (LL),Y
	SEC 
	SBC #6
	JSR INCLL
EF	LDA #4
	JSR INCLL
	LDX LL
	LDY LL+1
	JSR FLD0R 	;2 fr0
EN	CLC 
	RTS 
;func tabl pad 3 spaces! + tok	;!!!!!!!! INVERSE CHARS !!!!!!!!
FTAB	.BYTE "SQU",0	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "ABS",1	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "SQR",2	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "RND",3	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "EXP",4	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "LOG",5	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "INT",6	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "CNT",7	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "SUM",8	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE "AVE",9	;!!!!!!!! INVERSE CHARS !!!!!!!!
	.BYTE 0
;jmp tabl	;!!!!!!!! INVERSE CHARS !!!!!!!!
JTAB	.WORD SQU
	.WORD ABS
	.WORD SQR
	.WORD RND
	.WORD EXP
	.WORD LOG
	.WORD INT
	.WORD CNT
	.WORD SUM
	.WORD AVE
;absolute val	;!!!!!!!! INVERSE CHARS !!!!!!!!
ABS	JSR CHKONE
AXB	LDA FR0
	AND #$7F
	STA FR0
EXX	LDX FPN1
	JSR FR0X
	CLC 
	RTS 
;int	;!!!!!!!! INVERSE CHARS !!!!!!!!
INT	LDA #0 	;default
	STA TRCF
	JSR CHKONE
MF	JSR SETINB
	JSR FASC
	JSR TRUNC
	LDA FR0
	PHA 
	JSR AFP
	PLA 
	BPL EX2
	LDA TRCF 	;trunc flag
	BEQ EX2
	LDX # <ONE
	LDY # >ONE
	JSR FLD1R
	JSR FSUB
EX2	JMP EXX
;sqr	;!!!!!!!! INVERSE CHARS !!!!!!!!
SQR	JSR CHKONE
	LDX # <SFPN
	LDY # >SFPN
	JSR FST0R
	JSR LOG10
	LDX # <TWO
	LDY # >TWO
SQI2	JSR FLD1R
	JSR FDIV
	BCC SQQ 	;xit
	RTS 
SQQ	JSR EXP10
EX3	BCS BDEX
	JSR RNDSQR
EX8	JMP EX2
BDEX	RTS 
;square	;!!!!!!!! INVERSE CHARS !!!!!!!!
SQU	JSR CHKONE
	JSR LOG10
	LDX # <TWO
	LDY # >TWO
	JSR FLD1R
	JSR FMUL
	BCC SQ7
	RTS 
SQ7	JSR EXP10
	BCC EX8
	RTS 
;rnd	;!!!!!!!! INVERSE CHARS !!!!!!!!
RND	JSR CHKONE
	LDX # <HALF
	LDY # >HALF
	JSR FLD1R
	JSR FADD
	BCC RP
	RTS 
RP	JSR FASC
	JSR TRUNC
	JSR SETINB
	JSR AFP
EX4	JMP EXX
;cnt	;!!!!!!!! INVERSE CHARS !!!!!!!!
CNT	JSR CHKTWO
	JSR CHKCEL
	JSR CHKSIZ
	JSR CNTSUB
	JMP EXX
	RTS 
;sum	;!!!!!!!! INVERSE CHARS !!!!!!!!
SUM	JSR CHKTWO
	JSR CHKCEL
	JSR CHKSIZ
	JSR SUMSUB
	BCS SUMR
	JMP EXX
SUMR	RTS 
;sum subr	;!!!!!!!! INVERSE CHARS !!!!!!!!
SUMSUB	JSR DUPDAT
	JSR ZFR0
DAG	LDA DM0
	STA DM2
SO	JSR FMOVE
	LDX DM2
	LDA DM4
	JSR CL2FR0
	BCS SN 	;mt cell
	BEQ SP 	;txt
	JSR FADD
	BCC SP
SN	SEC 
	RTS 
SP	INC DM2
	LDA DM2
	CMP DM1
	BEQ SO
	BCC SO
	INC DM4
	LDA DM4
	CMP DM5
	BEQ DAG
	BCC DAG
	CLC 
	RTS 
;average	;!!!!!!!! INVERSE CHARS !!!!!!!!
AVE	JSR CHKTWO
	JSR CHKCEL
	JSR CHKSIZ
	JSR CNTSUB
	BCS AV2
	JSR SAVFPN 	;2 stck
	JSR SUMSUB
	BCS AV2
	JSR RETFPN 	;2 fr1-fpptr
	JSR FDIV 	;does not chng
	BCS AV2
EX5	JMP EXX
AV2	RTS 
;exp	;!!!!!!!! INVERSE CHARS !!!!!!!!
EXP	JSR CHKONE
	JSR EXP10
EX1	BCC EX5 	;xit
	RTS 
;log	;!!!!!!!! INVERSE CHARS !!!!!!!!
LOG	JSR CHKONE
	JSR LOG10
	BCC EX1
	RTS 
;count subrt	;!!!!!!!! INVERSE CHARS !!!!!!!!
CNTSUB	JSR DUPDAT
	LDA #0
	STA DM6
	STA DM7 	;cntrs
CNC	LDA DM0
	STA DM2
;is cell empty
CNB	LDX DM2
	LDA DM4
	JSR CL2FR0
	BCS CNA 	;skip empties
	INC DM6 	;add rows
	BNE CNA
	INC DM7
CNA	INC DM2 	;nxt col
	LDA DM2
	CMP DM1
	BEQ CNB
	BCC CNB
	INC DM4 	;nxt row
	LDA DM4
	CMP DM5
	BEQ CNC
	BCC CNC
	JSR ZFR0
	LDA DM6 	;gt cnt
	STA FR0
	LDA DM7
	STA FR0+1
	JSR IFP
	CLC 
	RTS 
;chekc 4 1 arg	;!!!!!!!! INVERSE CHARS !!!!!!!!
CHKONE	LDA NARG
	BEQ CZ
	CMP #1
	BEQ CY
CZ	PLA  	;pull ret
	PLA 
	SEC 
CY	RTS 
;chk 4 2 arg	;!!!!!!!! INVERSE CHARS !!!!!!!!
CHKTWO	LDA NARG
	CMP #2
	BNE CZ 	;err
	RTS 
;entries cells?	;!!!!!!!! INVERSE CHARS !!!!!!!!
CHKCEL	LDY #1
CWP	LDA ARGT,Y
	BPL CZ 	;err
	DEY 
	BPL CWP
	RTS 
;right size?	;!!!!!!!! INVERSE CHARS !!!!!!!!
CHKSIZ	LDA ROWS
	CMP ROWF
	BCC CZ 	;err
	LDA COLS
	CMP COLF
	BCC CZ 	;err
	RTS 
;dup colf-rowz	;!!!!!!!! INVERSE CHARS !!!!!!!!
DUPDAT	LDX #7
DDT	LDA COLF,X
	STA DM0,X
	DEX 
	BPL DDT
	RTS 
;truncate	;!!!!!!!! INVERSE CHARS !!!!!!!!
TRUNC	LDY #0
TI	LDA (INBUF),Y
	BMI TEX
	CMP #'.
	BEQ TJAA
	INY 
	BNE TI
TJAA	STA TRCF 	;flag
TJ	LDA #EOL
	STA (INBUF),Y
	RTS  	;NEW	;!!!!!!!! INVERSE CHARS !!!!!!!!
TEX	AND #$7F
	STA (INBUF),Y
	INY 
	BNE TJ
;save fp #	;!!!!!!!! INVERSE CHARS !!!!!!!!
SAVFPN	LDX FPPTR
	LDA STHI,X
	TAY 
	LDA STLO,X
	TAX 
	JSR FST0R
	RTS 
;retrv fpn to fr1	;!!!!!!!! INVERSE CHARS !!!!!!!!
RETFPN	LDX FPPTR
	LDA STHI,X
	TAY 
	LDA STLO,X
	TAX 
	JSR FLD1R
	RTS 
;pass 2 find cells	;!!!!!!!! INVERSE CHARS !!!!!!!!
;replace with #	;!!!!!!!! INVERSE CHARS !!!!!!!!
PASS2	LDY #1
LCEL	LDA BF1,Y
	CMP #'D
	BCS NXY
	CMP #'A
	BCS AHA
NXY	INY 
	CPY STR
	BNE LCEL
	JMP PASS3 	;do #'s next
AHA	STY TM 	;for collps
	TYA  	;strt
	CLC 
	ADC #4
	STA TM2 	;end
	JSR GTCLRW
	BCS ACD
	LDA ROWNU
	JSR STRAD
ACC	LDY #0
	LDA (LL),Y
	CMP #$FF 	;end?
	BEQ ACD 	;error
	CMP COLNU
	BEQ ACA 	;yup
	BCC ACB
ACD	RTS 
ACB	JSR UP1COL
	JMP ACC
ACA	LDY #3 	;gt cell
	LDA (LL),Y
	AND #3 	;dt type
	BEQ ACD 	;text!
	CMP #1 	;#?
	BEQ ACE
	LDY #2
	LDA (LL),Y
	SEC 
	SBC #6
	JSR INCLL
;default
ACE	LDA #4
	JSR INCLL
	LDX LL
	LDY LL+1
	JSR FLD0R
	LDA #4
	STA TM1
	JSR PUTTOK
	LDY TM
	JMP NXY
;put tok in2 bf1	;!!!!!!!! INVERSE CHARS !!!!!!!!
PUTTOK	LDY TM
	LDX TM2
	JSR COLAPS
	LDA STR
	SEC 
	SBC TM1
	STA STR
	JSR ADD2SP
	LDY TM
	LDA #'#
	STA BF1,Y
	LDA FPPTR
	INY 
	STA BF1,Y
	STY TM
;move fp to stck	;!!!!!!!! INVERSE CHARS !!!!!!!!
	TAX 
	LDA STHI,X
	TAY 
	LDA STLO,X
	TAX 
	JSR FST0R
	INC FPPTR
	RTS 
;pass 3 find #'s	;!!!!!!!! INVERSE CHARS !!!!!!!!
;replace with tokens	;!!!!!!!! INVERSE CHARS !!!!!!!!
PASS3	LDY #1 	;find # loop
FNLP	LDA BF1,Y
	CMP #EOL
	BEQ PSS
	CMP #'(
	BEQ PSM
	CMP #')
	BEQ PSM
	CMP #'#
	BNE PSI
	INY 
	INY 
	JMP PSS
PSM	INY 
	JMP FNLP 	;look again
PSI	STY CIX 	;get #
	STY TM 	;1st byte #
	JSR FP2BF1
	JSR AFP 	;get fp#
	BCS PSL
	LDX CIX
	TXA 
	STA TM2
	SEC 
	SBC TM
	STA TM1 	;# less
	JSR PUTTOK
	LDY TM 	;get pos. back
NXEN	INY 
	CPY STR
	BEQ PASS4
PSS	LDA BF1,Y
	CMP #EOL
	BEQ PASS4
PSK	LDX #4
PSJ	CMP OPTAB,X
	BEQ NXA
	DEX 
	BPL PSJ
	CMP #')
	BEQ NXEN
PSL	SEC 
	RTS 
NXA	INY 
	JMP FNLP
;pass 4 find nested ()	;!!!!!!!! INVERSE CHARS !!!!!!!!
;calculate & quit !	;!!!!!!!! INVERSE CHARS !!!!!!!!
PASS4	LDY #0
P4A	LDA BF1,Y
	CMP #EOL
	BEQ NOLF
	CMP #'(
	BEQ FLP
	INY 
	BNE P4A
NOLF	LDY #0
P4B	LDA BF1,Y
	CMP #EOL
	BEQ NOPRN
	CMP #')
	BEQ P4ER
	INY 
	BNE P4B
	BEQ P4ER 	;error
NOPRN	LDX #0
PSW	LDA BF1+1,X
	STA BF2,X
	CMP #EOL
	BEQ PSV
	INX 
	INY 
	JMP PSW
PSV	JSR CALCIT
	BCS P4ER
	RTS 
FLP	INY 
	LDA BF1,Y
	CMP #')
	BEQ FRP
	CMP #EOL
	BEQ P4ER
	BNE FLP
P4ER	SEC 
	RTS 
FRP	STY RIGHTP
P4C	DEY 
	LDA BF1,Y
	CMP #'(
	BNE P4C
	STY LEFTP
	LDX #$FF
	LDY LEFTP
PSR	INX 
	INY 
	CPY RIGHTP
	BEQ PST
	LDA BF1,Y
	STA BF2,X
	JMP PSR
PST	LDA #EOL
	STA BF2,X
	JSR CALCIT
	BCS P4ER
	LDA RIGHTP
	SEC 
	SBC LEFTP
	CMP #1
	BEQ P4ER
	LDX LEFTP
	LDA BF2
	STA BF1,X
	LDA BF2+1
	INX 
	STA BF1,X
	LDY RIGHTP
PSU	INX 
	INY 
	LDA BF1,Y
	STA BF1,X
	CMP #EOL
	BNE PSU
	JMP PASS4
;go up 1 col	;!!!!!!!! INVERSE CHARS !!!!!!!!
UP1COL	LDY #2
	LDA (LL),Y
	JSR INCLL
ADDDT	LDA #DTLEN
INCLL	CLC 
	ADC LL
	STA LL
	LDA LL+1
	ADC #0
	STA LL+1
	RTS 
;calculate bf2	;!!!!!!!! INVERSE CHARS !!!!!!!!
;exponents first	;!!!!!!!! INVERSE CHARS !!!!!!!!
CALCIT
CALCEX	LDY #0
CCW	STY TM4 	;save for clpse
	JSR GT2TOK
	CMP #EOL
	BEQ CALMD 	;try *,/
	BCC CCA
CCB	RTS  	;SEC=error
CCA	JSR MV2FPN
	LDA OPERAT
	CMP #'^
	BNE CCE
	JSR FIGEXP
	BCS CCB 	;error
	JSR CLPSBF2 	;collpase
	JSR FR02ST
	JMP CALCEX
CCE	LDA TM4
	CLC 
	ADC #3
	TAY 
	JMP CCW 	;look 4 more
;calculate * & /	;!!!!!!!! INVERSE CHARS !!!!!!!!
CALMD	LDY #0
CDC	STY TM4
	JSR GT2TOK
	CMP #EOL
	BEQ CALAS
	BCC CDA
CDB	RTS  	;error
CDA	JSR MV2FPN
	LDA OPERAT
	CMP #'*
	BNE CDD
	JSR FMUL
	BCS CDB 	;error
	BCC CDE
CDD	CMP #'/
	BNE CDF
	JSR FDIV
	BCS CDB 	;error
CDE	JSR CLPSBF2
	JSR FR02ST
	LDY TM4
	JMP CDC
CDF	LDA TM4
	CLC 
	ADC #3
	TAY 
	JMP CDC
;calculate +,-	;!!!!!!!! INVERSE CHARS !!!!!!!!
CALAS	LDY #0
CEG	STY TM4
	JSR GT2TOK
	CMP #EOL
	BEQ CDONE
	BCC CEA
CEB	RTS  	;SEC =error
CEA	JSR MV2FPN
	LDA OPERAT
	CMP #'+
	BNE CEC
	JSR FADD
	BCS CEB
	BCC CED
CEC	CMP #'-
	BNE CEB 	;error
	JSR FSUB
	BCS CEB 	;error
CED	JSR CLPSBF2
	JSR FR02ST
	LDY TM4
	JMP CEG
CDONE	CLC  	;ok
	RTS 
;get 2 tokens & operation	;!!!!!!!! INVERSE CHARS !!!!!!!!
GT2TOK	LDA BF2,Y
	CMP #'#
	BEQ GBA
	CMP #EOL 	;done?
	BEQ GBB
GBC	SEC  	;error
	RTS 
GBA	INY 
	LDA BF2,Y
	CMP #EOL
	BEQ GBC 	;error
	STA FTOK
	INY 
	LDA BF2,Y
	STA OPERAT
	CMP #EOL
	BEQ GBB 	;done
	INY 
	LDA BF2,Y
	CMP #EOL
	BEQ GBB 	;done
	CMP #'#
	BNE GBC 	;error
	INY 
	LDA BF2,Y
	CMP #EOL
	BEQ GBC 	;error
	STA STOK
GBB	CLC  	;A=eol if done
	RTS 
;move tok # to fp reg	;!!!!!!!! INVERSE CHARS !!!!!!!!
MV2FPN	LDX FTOK
	JSR STFLPTR
	JSR FLD0P
	LDX STOK
	JSR STFLPTR
	JSR FLD1P
	RTS 
;set pointers	;!!!!!!!! INVERSE CHARS !!!!!!!!
STFLPTR	LDA STLO,X
	STA FLPTR
	LDA STHI,X
	STA FLPTR+1
	RTS 
;collapse bf2	;!!!!!!!! INVERSE CHARS !!!!!!!!
CLPSBF2	LDA TM4
	CLC 
	ADC #2
	TAY 
	CLC 
	ADC #3
	TAX 
CF1	LDA BF2,X
	STA BF2,Y
	CMP #EOL
	BEQ CF2
	INY 
	INX 
	JMP CF1
CF2	RTS 
;figure exp	;!!!!!!!! INVERSE CHARS !!!!!!!!
FIGEXP	LDX FTOK
	JSR STFLPTR
	JSR FLD0P
	JSR LOG10
	BCC FIA
FIB	SEC 
	RTS 
FIA	LDX STOK
	JSR STFLPTR
	JSR FLD1P
	JSR FMUL
	BCS FIB
	JSR EXP10
	BCS FIB
	CLC 
	RTS 
;get a cell	;!!!!!!!! INVERSE CHARS !!!!!!!!
;colnu,rownu have col,row	;!!!!!!!! INVERSE CHARS !!!!!!!!
GTCLRW	JSR GET2CH
	BCS GRX
	JSR FINCNU
	BCC GRW
GRX	RTS  	;error
GRW	LDY HLDY
	INY 
	JSR GET2CH
	BCS GRX
	JSR FINRNU
	LDY HLDY
	RTS 
;find the column #	;!!!!!!!! INVERSE CHARS !!!!!!!!
FINCNU	LDA HLDF
	LDX #2
FCA	CMP AS26,X
	BEQ FCC
	DEX 
	BPL FCA
	BMI FCER
FCC	LDA N26,X
	STA TM3
	LDA HLDS
	CMP #'[
	BCS FCER
	CMP #'A
	BCS FCB
FCER	SEC  	;error
	RTS 
FCB	SEC 
	SBC #'A
	CLC 
	ADC TM3
	STA COLNU 	;col #
	CMP #64 	;0-63
	BCS FCER
	RTS 
;get 2 chr's from bf1	;!!!!!!!! INVERSE CHARS !!!!!!!!
GET2CH	LDA BF1,Y
	CMP #EOL
	BEQ GERR
	STA HLDF
	INY 
	LDA BF1,Y
	CMP #EOL
	BEQ GERR
	STA HLDS
	STY HLDY
	CLC 
	RTS 
GERR	SEC 
	RTS 
;get the row #	;!!!!!!!! INVERSE CHARS !!!!!!!!
FINRNU	LDA HLDF
	JSR GETDEC
	BCS FRER
	STA ROWNU
	LDA HLDS
	JSR GETDEC
	BCS FRER
	TXA 
	CLC 
	ADC ROWNU
	TAX 
	DEX 
	CPX #64
	BCS FRER
	STX ROWNU
	CLC 
	RTS 
FRER	SEC 
	RTS 
;get a decimal # (row)	;!!!!!!!! INVERSE CHARS !!!!!!!!
GETDEC	LDX #9
DECB	CMP DECN,X
	BEQ DECA
	DEX 
	BPL DECB
	SEC 
	RTS 
DECA	LDA DECM,X
	CLC 
	RTS 
;move fr0 to fpstack	;!!!!!!!! INVERSE CHARS !!!!!!!!
FR02ST	LDX FTOK
FR0X	JSR STFLPTR
	JSR FST0P
	RTS 
;collapse ;x=beg y=des	;!!!!!!!! INVERSE CHARS !!!!!!!!
;uses tm3
COLAPS	LDA BF1,X
	STA BF1,Y
	CMP #EOL
	BEQ CPF
	INY 
	INX 
	BNE COLAPS
CPF	RTS 
;room for fp token	;!!!!!!!! INVERSE CHARS !!!!!!!!
ADD2SP	LDX STR
ASLP	LDA BF1,X
	STA BF1+2,X
	DEX 
	CPX TM
	BEQ ASLP
	BCS ASLP
	INC STR
	INC STR
	RTS 
;point 2 bf1	;!!!!!!!! INVERSE CHARS !!!!!!!!
FP2BF1	LDA # >BF1
	STA INBUF+1
	LDA # <BF1
	STA INBUF
	RTS 
TRCF	    1
;round off sqrts	;!!!!!!!! INVERSE CHARS !!!!!!!!
RNDSQR	JSR FMOVE 	;rt to fr1
	LDX # <SROOT 	;save root
	LDY # >SROOT
	JSR FST0R
	LDX # <SFPN
	LDY # >SFPN
	JSR FLD0R 	;N to fr0
	JSR FDIV 	;N/rt
	LDX # <SROOT
	LDY # >SROOT
	JSR FLD1R 	;res. root
	JSR FADD 	;add rts
	LDX # <HALF
	LDY # >HALF
	JSR FLD1R
	JSR FMUL 	;x .5
	RTS 
SFPN	    6
SROOT	    6
