A2osX/BIN/ACOS.S.txt
2021-07-24 22:42:23 +02:00

661 lines
12 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/acos
*--------------------------------------
CODESEG .EQ 4096
CONSTSEG .EQ 2048
DATASEG .EQ 256
STRVSEG .EQ 4096
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.COMPILING .DA MSG.COMPILING
L.MSG.DEBUG .DA MSG.DEBUG
L.MSG.TRACE .DA MSG.TRACE
L.MSG.ERROR .DA MSG.ERROR
L.MSG.FWREF .DA MSG.FWREF
L.MSG.FWREFERR .DA MSG.FWREFERR
L.MSG.RUN .DA MSG.RUN
L.MSG.STR .DA MSG.STR
L.MSG.INT16 .DA MSG.INT16
L.OUT .DA OUT.ELW
.DA OUT.DLW
.DA OUT.CRLF
.DA OUT.BSSPBS
.DA OUT.CLRSCR
L.FMT.DATE .DA FMT.DATE
L.FMT.TIME .DA FMT.TIME
*--------------------------------------
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.CHRd
.DA FN.CLOCK
.DA FN.DATEd
.DA FN.FLAG
.DA FN.INFO
.DA FN.INSTR
.DA FN.KEY
.DA FN.LEFTd
.DA FN.LEN
.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
*--------------------------------------
J.RT
RT.GET.ID .EQ *-J.RT
.DA RT.GET
RT.INPUT.ID .EQ *-J.RT
.DA RT.INPUT
*--------------------------------------
RT.DATEd.ID .EQ *-J.RT
.DA RT.DATEd
RT.LEFTd.ID .EQ *-J.RT
.DA RT.LEFTd
RT.LEN.ID .EQ *-J.RT
.DA RT.LEN
RT.MIDd.ID .EQ *-J.RT
.DA RT.MIDd
RT.RIGHTd.ID .EQ *-J.RT
.DA RT.RIGHTd
RT.STRd.ID .EQ *-J.RT
.DA RT.STRd
RT.TIMEd.ID .EQ *-J.RT
.DA RT.TIMEd
RT.VAL.ID .EQ *-J.RT
.DA RT.VAL
*--------------------------------------
RT.NOT.ID .EQ *-J.RT
.DA RT.NOT
RT.StrSet.ID .EQ *-J.RT
.DA RT.StrSet
RT.StrGet.ID .EQ *-J.RT
.DA RT.StrGet
RT.StrOut.ID .EQ *-J.RT
.DA RT.StrOut
RT.IntSet.ID .EQ *-J.RT
.DA RT.IntSet
RT.IntGet.ID .EQ *-J.RT
.DA RT.IntGet
RT.IntOut.ID .EQ *-J.RT
.DA RT.IntOut
RT.OUTCRLF.ID .EQ *-J.RT
.DA RT.OUTCRLF
RT.OUTX.ID .EQ *-J.RT
.DA RT.OUTX
.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
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
lda #$60 RTS
sta (ZPCodeBufPtr)
lda #0
sta (ZPFWRefBufPtr)
jsr CS.FClose
jsr CORE.FWREF
bcs .99
jsr CORE.Run
bcc .8
.9 pha
jsr PrintErrorMsg
pla
sec
rts
.8 lda #0 Exit Code = Success
sec
.99 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
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA.G InputBufPtr
txa
>STA.G hInputBuf
.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 .1
>SYSCALL FClose
>STZ.G hFile
.1 >LDA.G hInputBuf
beq .8
>SYSCALL FreeMem
>STZ.G hInputBuf
.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
*--------------------------------------
.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
*--------------------------------------
* Pre-compiled code
*--------------------------------------
CCODE.PUSHA >PUSHA
CCODE.PUSHA.LEN .EQ *-CCODE.PUSHA
*--------------------------------------
CCODE.TESTTRUE lda (pStack)
inc pStack
ora (pStack)
php
inc pStack
plp
.1 bne .1+5
.HS 4C JMP abs
CCODE.TESTTRUE.LEN .EQ *-CCODE.TESTTRUE
*--------------------------------------
* 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"
.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.FWREF .AZ "***Resolving FWRefs..."
MSG.FWREFERR .AZ "***Unresolved FWRef : %s\r\n"
MSG.RUN .AZ "***Code size: %D, Data Size: %D, Running...\r\n"
MSG.STR .AZ "%s"
MSG.INT16 .AZ "%I"
*--------------------------------------
OUT.ELW .DA #C.ESC
.AZ "[?7h" Enable Line Wrap
OUT.DLW .DA #C.ESC
.AZ "[?7l" Disable Line Wrap
OUT.CRLF .DA #C.CR,#C.LF,#0
OUT.BSSPBS .DA #C.BS,#C.SPACE,#C.BS,#0
OUT.CLRSCR .DA #C.ESC
.AS "c"
.DA #C.ESC
.AS "(B"
.DA #C.ESC
.AZ ")0"
*--------------------------------------
FMT.DATE .AZ "%m/%d/%y"
FMT.TIME .AZ "%H:%M:%S"
*--------------------------------------
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 "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 "CHR$"
.AT "CLOCK"
.AT "DATE$"
.AT "FLAG"
.AT "INFO"
.AT "INSTR"
.AT "KEY"
.AT "LEFT$"
.AT "LEN"
.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
hInputBuf .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
TimeBuf .BS S.TIME
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/acos.s
ASM