mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-29 02:49:54 +00:00
680 lines
13 KiB
Plaintext
680 lines
13 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF bin/acos
|
||
*--------------------------------------
|
||
CODESEG .EQ 4096
|
||
CONSTSEG .EQ 1024
|
||
DATASEG .EQ 256
|
||
STRVSEG .EQ 2048
|
||
FWREF .EQ 1024
|
||
EXP.DEPTH.MAX .EQ 16
|
||
CCS.MAX .EQ 128
|
||
*--------------------------------------
|
||
.INB inc/macros.i
|
||
.INB inc/a2osx.i
|
||
.INB inc/mli.i
|
||
.INB inc/mli.e.i
|
||
*--------------------------------------
|
||
* Zero Page Segment, up to 32 bytes
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR ZPBIN
|
||
ZS.START
|
||
|
||
ZPInputBufPtr .BS 2
|
||
ZPSID .BS 2
|
||
ZPADDR .BS 2
|
||
ZPTYPE .BS 1
|
||
hStrings .BS 1
|
||
|
||
ZPStrBuf .BS 2
|
||
|
||
ZPPtr1 .BS 2
|
||
ZPPtr2 .BS 2
|
||
ArgIndex .EQ *
|
||
pCCS .BS 1
|
||
bFlag .BS 1
|
||
|
||
ZPCodeBufPtr .BS 2
|
||
ZPConstBufPtr .BS 2
|
||
ZPDataBufPtr .BS 2
|
||
ZPFWRefBufPtr .BS 2
|
||
|
||
EXP.ADDR .BS 2
|
||
EXP.TYPE .BS 1
|
||
EXP.AOPS .BS 1
|
||
|
||
STRID .BS 2
|
||
hIn .BS 1
|
||
hOut .BS 1
|
||
|
||
ZS.END .ED
|
||
*--------------------------------------
|
||
* File Header (16 Bytes)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp (.1,x)
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 BIN Layout Version 1
|
||
.DA #0 S.PS.F.EVENT
|
||
.DA #0
|
||
.DA CS.END-CS.START Code Size (without Constants)
|
||
.DA DS.END-DS.START Data SegmentSize
|
||
.DA #256 Stack Size
|
||
.DA #ZS.END-ZS.START Zero Page Size
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
.1 .DA CS.INIT
|
||
.DA CS.RUN
|
||
.DA CS.DOEVENT
|
||
.DA CS.QUIT
|
||
*--------------------------------------
|
||
L.MSG.GREETINGS .DA MSG.GREETINGS
|
||
L.MSG.USAGE .DA MSG.USAGE
|
||
L.MSG.ECHOCRLF .DA MSG.ECHOCRLF
|
||
L.MSG.COMPILING .DA MSG.COMPILING
|
||
L.MSG.DEBUG .DA MSG.DEBUG
|
||
L.MSG.TRACE .DA MSG.TRACE
|
||
L.MSG.ERROR .DA MSG.ERROR
|
||
L.MSG.RUN .DA MSG.RUN
|
||
L.MSG.FWREFERR .DA MSG.FWREFERR
|
||
L.MSG.STR .DA MSG.STR
|
||
L.MSG.INT16 .DA MSG.INT16
|
||
*--------------------------------------
|
||
L.ACOS.OPS .DA ACOS.OPS
|
||
L.ACOS.KW .DA ACOS.KW
|
||
J.ACOS.KW .DA KW.ADDINT
|
||
.DA KW.APPEND
|
||
.DA KW.BYTE
|
||
.DA KW.CLEAR
|
||
.DA KW.CLOCK
|
||
.DA KW.CLOSE
|
||
.DA KW.COPY
|
||
.DA KW.CREATE
|
||
.DA KW.ECHO
|
||
.DA KW.EDIT
|
||
.DA KW.ELSE
|
||
.DA KW.END
|
||
.DA KW.FILL
|
||
.DA KW.FLAG
|
||
.DA KW.FOR
|
||
.DA KW.FREE
|
||
.DA KW.GET
|
||
.DA KW.GOSUB
|
||
.DA KW.GOTO
|
||
.DA KW.HOME
|
||
KWID.IF .EQ *-J.ACOS.KW
|
||
.DA KW.IF
|
||
.DA KW.INFO
|
||
.DA KW.INPUT
|
||
.DA KW.KILL
|
||
.DA KW.LINK
|
||
.DA KW.LOG
|
||
.DA KW.MARK
|
||
.DA KW.MODEM
|
||
.DA KW.MOVE
|
||
.DA KW.MSG
|
||
.DA KW.NEXT
|
||
.DA KW.NIBBLE
|
||
.DA KW.NOT
|
||
.DA KW.ON
|
||
.DA KW.NOCAR
|
||
.DA KW.OPEN
|
||
.DA KW.POKE
|
||
.DA KW.POP
|
||
.DA KW.POSITION
|
||
.DA KW.PRINT
|
||
.DA KW.PUBLIC
|
||
.DA KW.PUSH
|
||
.DA KW.RAM
|
||
.DA KW.RAM2
|
||
.DA KW.READ
|
||
.DA KW.READY
|
||
.DA KW.RETURN
|
||
.DA KW.REWIND
|
||
.DA KW.RIPCO
|
||
.DA KW.SET
|
||
.DA KW.SETINT
|
||
.DA KW.TEXT
|
||
.DA KW.THEN
|
||
.DA KW.TONE
|
||
.DA KW.UPDATE
|
||
.DA KW.USE
|
||
.DA KW.WHENd
|
||
.DA KW.WRITE
|
||
*--------------------------------------
|
||
L.ACOS.FN .DA ACOS.FN
|
||
J.ACOS.FN .DA FN.BYTE
|
||
.DA FN.CLOCK
|
||
.DA FN.DATEd
|
||
.DA FN.FLAG
|
||
.DA FN.CHRd
|
||
.DA FN.INSTR
|
||
.DA FN.KEY
|
||
.DA FN.LEN
|
||
.DA FN.LEFTd
|
||
.DA FN.MIDd
|
||
.DA FN.PDL
|
||
.DA FN.PEEK
|
||
.DA FN.RANDOM
|
||
.DA FN.RIGHTd
|
||
.DA FN.RNDd
|
||
.DA FN.STRd
|
||
.DA FN.TIMEd
|
||
.DA FN.VAL
|
||
.DA FN.WHENd
|
||
.DA FN.WIDTH
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Called once at process creation
|
||
* Put code for loading LIB here
|
||
*--------------------------------------
|
||
CS.INIT clc
|
||
CS.INIT.RTS rts
|
||
*--------------------------------------
|
||
* Called until exit with CS
|
||
* if RUN exits with CC, RN entered again
|
||
*--------------------------------------
|
||
CS.RUN >PUSHW L.MSG.GREETINGS
|
||
>PUSHW A2osX.KVER
|
||
>PUSHBI 2
|
||
>SYSCALL PrintF
|
||
bcs CS.INIT.RTS
|
||
|
||
jsr CS.RUN.ARGS
|
||
bcs CS.INIT.RTS
|
||
|
||
>LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs CS.INIT.RTS
|
||
>STYA.G InputBufPtr
|
||
|
||
jsr CORE.Init
|
||
bcs CS.INIT.RTS
|
||
|
||
>PUSHW L.MSG.COMPILING
|
||
>PUSHW ZPPtr2 File name
|
||
>PUSHBI 2
|
||
>SYSCALL PrintF
|
||
bcs CS.INIT.RTS
|
||
|
||
CS.RUN.LOOP >SLEEP
|
||
|
||
>LDA.G bDebug
|
||
bpl .2
|
||
|
||
jsr PrintDebugMsg
|
||
|
||
.2 jsr CS.RUN.FGetS
|
||
bcs .4
|
||
|
||
>LDA.G bTrace
|
||
bpl .3
|
||
|
||
jsr PrintTraceMsg
|
||
|
||
.3 jsr CORE.Compile
|
||
bcc CS.RUN.LOOP
|
||
|
||
cmp #MLI.E.EOF
|
||
beq CS.RUN.LOOP
|
||
|
||
.4 cmp #MLI.E.EOF
|
||
bne .9
|
||
|
||
jsr CS.FClose
|
||
|
||
jsr CORE.FWREF
|
||
bcs .9
|
||
|
||
jsr CORE.Run
|
||
bcc .8
|
||
|
||
.9 pha
|
||
jsr PrintErrorMsg
|
||
pla
|
||
sec
|
||
rts
|
||
|
||
.8 lda #0 Exit Code = Success
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.ARGS inc ArgIndex
|
||
|
||
lda ArgIndex
|
||
>SYSCALL ArgV
|
||
bcs .7
|
||
|
||
>STYA ZPPtr1
|
||
lda (ZPPtr1)
|
||
cmp #'-'
|
||
bne .4
|
||
|
||
ldy #1
|
||
lda (ZPPtr1),y
|
||
|
||
ldx #OptionVars-OptionList-1
|
||
|
||
.1 cmp OptionList,x
|
||
beq .2
|
||
|
||
dex
|
||
bpl .1
|
||
|
||
bra .90
|
||
|
||
.2 ldy OptionVars,x
|
||
lda #$ff
|
||
sta (pData),y
|
||
bra CS.RUN.ARGS
|
||
|
||
.4 >LDA.G hFile
|
||
bne .90
|
||
|
||
>LDYA ZPPtr1
|
||
>STYA ZPPtr2 for printing later
|
||
jsr CS.RUN.FOpen
|
||
bcc CS.RUN.ARGS
|
||
|
||
.9 rts
|
||
|
||
.7 >LDA.G hFile
|
||
beq .90
|
||
|
||
clc
|
||
rts
|
||
|
||
.90 >PUSHW L.MSG.USAGE
|
||
>PUSHBI 0
|
||
>SYSCALL PrintF
|
||
|
||
lda #E.SYN
|
||
sec QUIT Process
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.FOpen >PUSHYA
|
||
>PUSHBI O.RDONLY
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHWZ Aux type
|
||
>SYSCALL FOpen
|
||
bcs .9
|
||
|
||
>STA.G hFile
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN.FGetS >LDYA.G InputBufPtr
|
||
>STYA ZPInputBufPtr
|
||
|
||
>INCW.G LineCounter
|
||
|
||
>PUSHB.G hFile
|
||
>PUSHW ZPInputBufPtr
|
||
>PUSHWI 256
|
||
>SYSCALL FGetS
|
||
|
||
rts
|
||
*--------------------------------------
|
||
CS.DOEVENT sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.QUIT jsr CORE.Quit
|
||
|
||
CS.FClose >LDA.G hFile
|
||
beq .8
|
||
|
||
>SYSCALL FClose
|
||
|
||
>STZ.G hFile
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
PrintDebugMsg >LDYA pStack
|
||
>STYA ZPPtr2
|
||
>PUSHW L.MSG.DEBUG
|
||
|
||
>PUSHW ZPCodeBufPtr
|
||
>PUSHW ZPConstBufPtr
|
||
>PUSHW ZPDataBufPtr
|
||
>PUSHW ZPPtr2
|
||
|
||
>PUSHBI 8
|
||
>SYSCALL PrintF
|
||
rts
|
||
*--------------------------------------
|
||
PrintTraceMsg ldy #S.PS.hStdErr
|
||
lda (pPS),y
|
||
>PUSHA
|
||
|
||
>PUSHW L.MSG.TRACE
|
||
>PUSHW.G LineCounter
|
||
>PUSHW.G InputBufPtr
|
||
>PUSHBI 4
|
||
>SYSCALL FPrintF
|
||
|
||
rts
|
||
*--------------------------------------
|
||
PrintErrorMsg >LDA.G bTrace
|
||
bmi .1
|
||
|
||
jsr PrintTraceMsg
|
||
|
||
.1 lda ZPInputBufPtr
|
||
|
||
sec
|
||
>SBC.G InputBufPtr
|
||
tax
|
||
|
||
>LDYA.G InputBufPtr
|
||
>STYA ZPInputBufPtr
|
||
|
||
txa
|
||
beq .3
|
||
|
||
ldy #0
|
||
lda #'-'
|
||
|
||
.2 sta (ZPInputBufPtr),y
|
||
iny
|
||
dex
|
||
bne .2
|
||
|
||
txa
|
||
|
||
.3 sta (ZPInputBufPtr),y
|
||
|
||
.8 ldy #S.PS.hStdErr
|
||
lda (pPS),y
|
||
>PUSHA
|
||
>PUSHW L.MSG.ERROR
|
||
>PUSHW ZPInputBufPtr
|
||
>PUSHBI 2
|
||
>SYSCALL FPrintF
|
||
rts
|
||
*--------------------------------------
|
||
* Precompiled code
|
||
*--------------------------------------
|
||
CCODE.PULLWS >PULLA
|
||
pha
|
||
>PULLA
|
||
pha
|
||
CCODE.PULLWS.LEN .EQ *-CCODE.PULLWS
|
||
*--------------------------------------
|
||
CCODE.PUSHWS pla
|
||
>PUSHA
|
||
pla
|
||
>PUSHA
|
||
CCODE.PUSHWS.LEN .EQ *-CCODE.PUSHWS
|
||
*--------------------------------------
|
||
CCODE.PUSHWYA >STYA ZPADDR
|
||
ldy #1
|
||
lda (ZPADDR),y
|
||
>PUSHA
|
||
lda (ZPADDR)
|
||
>PUSHA
|
||
CCODE.PUSHWYA.LEN .EQ *-CCODE.PUSHWYA
|
||
*--------------------------------------
|
||
CCODE.PULLWYA >STYA ZPADDR
|
||
>PULLA
|
||
sta (ZPADDR)
|
||
>PULLA
|
||
ldy #1
|
||
sta (ZPADDR),y
|
||
CCODE.PULLWYA.LEN .EQ *-CCODE.PULLWYA
|
||
*--------------------------------------
|
||
CCODE.PUSHA >PUSHA
|
||
CCODE.PUSHA.LEN .EQ *-CCODE.PUSHA
|
||
*--------------------------------------
|
||
CCODE.PULLA >PULLA
|
||
CCODE.PULLA.LEN .EQ *-CCODE.PULLA
|
||
*--------------------------------------
|
||
CCODE.TESTTRUE lda (pStack)
|
||
inc pStack
|
||
ora (pStack)
|
||
php
|
||
inc pStack
|
||
plp
|
||
.1 bne .1+5
|
||
CCODE.TESTTRUE.LEN .EQ *-CCODE.TESTTRUE
|
||
*--------------------------------------
|
||
CCODE.FPRINTSTR ldy #S.PS.hStdOut
|
||
lda (pPS),y
|
||
>PUSHA
|
||
ldy #2
|
||
lda (pStack),y
|
||
>PUSHA
|
||
lda (pStack),y
|
||
>PUSHA
|
||
>SYSCALL fputs
|
||
inc pStack
|
||
inc pStack
|
||
CCODE.FPRINTSTR.LEN .EQ *-CCODE.FPRINTSTR
|
||
*--------------------------------------
|
||
CCODE.FPRINTINT >PUSHW L.MSG.INT16
|
||
ldy #3
|
||
lda (pStack),y
|
||
>PUSHA
|
||
lda (pStack),y
|
||
>PUSHA
|
||
>PUSHBI 2
|
||
>SYSCALL PrintF
|
||
inc pStack
|
||
inc pStack
|
||
CCODE.FPRINTINT.LEN .EQ *-CCODE.FPRINTINT
|
||
*--------------------------------------
|
||
CCODE.LEN >PULLW ZPPtr1
|
||
|
||
ldy #$FF
|
||
|
||
.1 iny
|
||
lda (ZPPtr1),y
|
||
bne .1
|
||
|
||
>PUSHYA
|
||
CCODE.LEN.LEN .EQ *-CCODE.LEN
|
||
*--------------------------------------
|
||
CCODE.LEFT >PULLW ZPPtr2 cnt
|
||
lda (pStack)
|
||
sta ZPPtr1
|
||
ldy #1
|
||
lda (pStack),y
|
||
sta ZPPtr1+1
|
||
|
||
ldy #0
|
||
|
||
.1 lda (ZPPtr1),y
|
||
beq .8
|
||
|
||
iny
|
||
cpy ZPPtr2
|
||
bne .1
|
||
|
||
lda #0
|
||
sta (ZPPtr1),y
|
||
.8
|
||
|
||
CCODE.LEFT.LEN .EQ *-CCODE.LEFT
|
||
*--------------------------------------
|
||
CCODE.STR >PULLYA int
|
||
pha
|
||
>PUSHW ZPStrBuf
|
||
>PUSHW L.MSG.INT16
|
||
pla
|
||
>PUSHYA
|
||
>PUSHBI 2
|
||
>SYSCALL sprintf
|
||
>PUSHW ZPStrBuf
|
||
CCODE.STR.LEN .EQ *-CCODE.STR
|
||
*--------------------------------------
|
||
CCODE.VAL >PULLYA str
|
||
>SYSCALL atoi
|
||
>PUSHYA
|
||
CCODE.VAL.LEN .EQ *-CCODE.VAL
|
||
*--------------------------------------
|
||
.INB usr/src/bin/acos.s.code
|
||
.INB usr/src/bin/acos.s.core
|
||
.INB usr/src/bin/acos.s.exp
|
||
.INB usr/src/bin/acos.s.fn
|
||
.INB usr/src/bin/acos.s.kw
|
||
.INB usr/src/bin/acos.s.rt
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
* Initialized DATA
|
||
*--------------------------------------
|
||
MSG.GREETINGS .AZ "\r\nACOS-Shell %d.%d\r\n\r\n"
|
||
MSG.USAGE .AS "Usage : ACOS <option> file\r\n"
|
||
.AS " -D : Debug Mode\r\n"
|
||
.AS " -T : Trace On"
|
||
MSG.ECHOCRLF .AZ "\r\n"
|
||
MSG.COMPILING .AZ "Compiling : %s...\r\n"
|
||
MSG.DEBUG .AZ "CodePtr=%H ConstPtr=%H DataPtr=%H StackPtr=%H\r\n"
|
||
MSG.TRACE .AZ "%05D>%s\r\n"
|
||
MSG.ERROR .AZ " %s^\r\n"
|
||
MSG.RUN .AZ "Success, Code size = %D Bytes\r\nResolving FWRefs...\r\n"
|
||
MSG.FWREFERR .AZ "Unresolved FWRef : %s\r\n"
|
||
MSG.STR .AZ "%s"
|
||
MSG.INT16 .AZ "%I"
|
||
*--------------------------------------
|
||
OptionList .AS "DdTt"
|
||
OptionVars .DA #bDebug,#bDebug,#bTrace,#bTrace
|
||
*--------------------------------------
|
||
ACOS.OPSChars .AS "+-*/<>="
|
||
ACOS.OPSChars.Cnt .EQ *-ACOS.OPSChars
|
||
*--------------------------------------
|
||
ACOS.OPS .AT "*"
|
||
.AT "/"
|
||
.AT "MOD"
|
||
.AT "+"
|
||
.AT "-"
|
||
.AT "<"
|
||
.AT "<="
|
||
.AT "=<"
|
||
.AT ">"
|
||
.AT ">="
|
||
.AT "=>"
|
||
.AT "<>"
|
||
.AT "><"
|
||
.AT "="
|
||
* .AT "NOT"
|
||
.AT "AND"
|
||
.AT "OR"
|
||
.HS 00
|
||
*--------------------------------------
|
||
ACOS.OPS2FPU .DA #FPU.iMUL,#FPU.iDIV,#FPU.iMOD,#FPU.iADD,#FPU.iSUB
|
||
.DA #FPU.iL,#FPU.iLE,#FPU.iLE
|
||
.DA #FPU.iG,#FPU.iGE,#FPU.iGE
|
||
.DA #FPU.iNE,#FPU.iNE,#FPU.iE
|
||
.DA #FPU.iLAND,#FPU.iLOR
|
||
*--------------------------------------
|
||
ACOS.KW .AT "ADDINT"
|
||
.AT "APPEND"
|
||
.AT "BYTE"
|
||
.AT "CLEAR"
|
||
.AT "CLOCK"
|
||
.AT "CLOSE"
|
||
.AT "COPY"
|
||
.AT "CREATE"
|
||
.AT "ECHO"
|
||
.AT "EDIT"
|
||
.AT "ELSE"
|
||
.AT "END"
|
||
.AT "FILL"
|
||
.AT "FLAG"
|
||
.AT "FOR"
|
||
.AT "FREE"
|
||
.AT "GET"
|
||
.AT "GOSUB"
|
||
.AT "GOTO"
|
||
.AT "HOME"
|
||
.AT "IF"
|
||
.AT "INFO"
|
||
.AT "INPUT"
|
||
.AT "KILL"
|
||
.AT "LINK"
|
||
.AT "LOG"
|
||
.AT "MARK"
|
||
.AT "MODEM"
|
||
.AT "MOVE"
|
||
.AT "MSG"
|
||
.AT "NEXT"
|
||
.AT "NIBBLE"
|
||
.AT "NOT"
|
||
.AT "ON"
|
||
.AT "NOCAR"
|
||
.AT "OPEN"
|
||
.AT "POKE"
|
||
.AT "POP"
|
||
.AT "POSITION"
|
||
.AT "PRINT"
|
||
.AT "PUBLIC"
|
||
.AT "PUSH"
|
||
.AT "RAM"
|
||
.AT "RAM2"
|
||
.AT "READ"
|
||
.AT "READY"
|
||
.AT "RETURN"
|
||
.AT "REWIND"
|
||
.AT "RIPCO"
|
||
.AT "SET"
|
||
.AT "SETINT"
|
||
.AT "TEXT"
|
||
.AT "THEN"
|
||
.AT "TONE"
|
||
.AT "UPDATE"
|
||
.AT "USE"
|
||
.AT "WHEN$"
|
||
.AT "WRITE"
|
||
.HS 00
|
||
*--------------------------------------
|
||
ACOS.FN .AT "BYTE"
|
||
.AT "DATE$"
|
||
.AT "FLAG"
|
||
.AT "CHR$"
|
||
.AT "INFO"
|
||
.AT "INSTR"
|
||
.AT "KEY"
|
||
.AT "LEN"
|
||
.AT "LEFT$"
|
||
.AT "MID$"
|
||
.AT "PDL"
|
||
.AT "PEEK"
|
||
.AT "RANDOM"
|
||
.AT "RIGHT$"
|
||
.AT "RND$"
|
||
.AT "STR$"
|
||
.AT "TIME$"
|
||
.AT "VAL"
|
||
.AT "WHEN$"
|
||
.AT "WIDTH"
|
||
.HS 00
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
CCS .BS CCS.MAX
|
||
bDebug .BS 1
|
||
bTrace .BS 1
|
||
LineCounter .BS 2
|
||
hFile .BS 1
|
||
InputBufPtr .BS 2
|
||
hCodeBuf .BS 1
|
||
hConstBuf .BS 1
|
||
hDataBuf .BS 1
|
||
hLabels .BS 1
|
||
hVars .BS 1
|
||
hStrBuf .BS 1
|
||
hFWRefBuf .BS 1
|
||
DS.END .ED
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE usr/src/bin/acos.s
|
||
ASM
|