A2osX/BIN/ACOS.S.txt

661 lines
12 KiB
Plaintext
Raw Normal View History

2021-04-08 20:30:18 +00:00
NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/acos
*--------------------------------------
2021-04-10 17:17:40 +00:00
CODESEG .EQ 4096
2021-06-23 19:07:21 +00:00
CONSTSEG .EQ 2048
2021-04-08 20:30:18 +00:00
DATASEG .EQ 256
2021-06-23 19:07:21 +00:00
STRVSEG .EQ 4096
2021-04-15 14:03:04 +00:00
FWREF .EQ 1024
2021-04-10 17:17:40 +00:00
EXP.DEPTH.MAX .EQ 16
2021-05-09 12:39:40 +00:00
CCS.MAX .EQ 128
2021-04-08 20:30:18 +00:00
*--------------------------------------
.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
2021-04-11 19:47:48 +00:00
ZPTYPE .BS 1
2021-04-29 11:56:34 +00:00
hStrings .BS 1
ZPStrBuf .BS 2
2021-04-08 20:30:18 +00:00
ZPPtr1 .BS 2
ZPPtr2 .BS 2
2021-05-09 12:39:40 +00:00
ArgIndex .EQ *
pCCS .BS 1
2021-04-29 11:56:34 +00:00
bFlag .BS 1
2021-04-08 20:30:18 +00:00
ZPCodeBufPtr .BS 2
ZPConstBufPtr .BS 2
ZPDataBufPtr .BS 2
2021-04-15 14:03:04 +00:00
ZPFWRefBufPtr .BS 2
2021-04-08 20:30:18 +00:00
EXP.ADDR .BS 2
2021-04-11 19:47:48 +00:00
EXP.TYPE .BS 1
2021-04-10 17:17:40 +00:00
EXP.AOPS .BS 1
2021-04-29 11:56:34 +00:00
STRID .BS 2
hIn .BS 1
hOut .BS 1
2021-04-08 20:30:18 +00:00
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
2021-05-04 17:31:21 +00:00
.DA #256 Stack Size
2021-04-08 20:30:18 +00:00
.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
2021-04-29 11:56:34 +00:00
*--------------------------------------
2021-04-08 20:30:18 +00:00
L.MSG.GREETINGS .DA MSG.GREETINGS
L.MSG.USAGE .DA MSG.USAGE
L.MSG.COMPILING .DA MSG.COMPILING
L.MSG.DEBUG .DA MSG.DEBUG
2021-04-29 11:56:34 +00:00
L.MSG.TRACE .DA MSG.TRACE
L.MSG.ERROR .DA MSG.ERROR
L.MSG.FWREF .DA MSG.FWREF
2021-04-15 14:03:04 +00:00
L.MSG.FWREFERR .DA MSG.FWREFERR
L.MSG.RUN .DA MSG.RUN
2021-04-08 20:30:18 +00:00
L.MSG.STR .DA MSG.STR
2021-04-29 11:56:34 +00:00
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
2021-04-08 20:30:18 +00:00
*--------------------------------------
2021-05-04 17:31:21 +00:00
L.ACOS.OPS .DA ACOS.OPS
2021-04-08 20:30:18 +00:00
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
2021-05-09 12:39:40 +00:00
.DA KW.ELSE
2021-04-08 20:30:18 +00:00
.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
2021-05-09 12:39:40 +00:00
KWID.IF .EQ *-J.ACOS.KW
2021-04-08 20:30:18 +00:00
.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
2021-04-08 20:30:18 +00:00
.DA FN.CLOCK
.DA FN.DATEd
.DA FN.FLAG
.DA FN.INFO
2021-04-08 20:30:18 +00:00
.DA FN.INSTR
.DA FN.KEY
.DA FN.LEFTd
.DA FN.LEN
2021-04-08 20:30:18 +00:00
.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
2021-07-09 13:54:42 +00:00
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
*--------------------------------------
2021-07-09 20:40:57 +00:00
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
2021-04-08 20:30:18 +00:00
.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
2021-04-29 11:56:34 +00:00
>PUSHW ZPPtr2 File name
2021-04-08 20:30:18 +00:00
>PUSHBI 2
>SYSCALL PrintF
bcs CS.INIT.RTS
2021-04-29 11:56:34 +00:00
CS.RUN.LOOP >SLEEP
2021-04-08 20:30:18 +00:00
>LDA.G bDebug
bpl .2
jsr PrintDebugMsg
2021-04-29 11:56:34 +00:00
.2 jsr CS.RUN.FGetS
bcs .4
>LDA.G bTrace
2021-04-08 20:30:18 +00:00
bpl .3
jsr PrintTraceMsg
.3 jsr CORE.Compile
2021-04-29 11:56:34 +00:00
bcc CS.RUN.LOOP
2021-04-08 20:30:18 +00:00
cmp #MLI.E.EOF
2021-04-29 11:56:34 +00:00
beq CS.RUN.LOOP
.4 cmp #MLI.E.EOF
2021-04-08 20:30:18 +00:00
bne .9
lda #$60 RTS
sta (ZPCodeBufPtr)
lda #0
sta (ZPFWRefBufPtr)
2021-04-29 11:56:34 +00:00
jsr CS.FClose
2021-04-15 14:03:04 +00:00
jsr CORE.FWREF
bcs .99
2021-04-15 14:03:04 +00:00
2021-04-08 20:30:18 +00:00
jsr CORE.Run
bcc .8
.9 pha
2021-04-29 11:56:34 +00:00
jsr PrintErrorMsg
2021-04-08 20:30:18 +00:00
pla
sec
rts
.8 lda #0 Exit Code = Success
sec
.99 rts
2021-04-08 20:30:18 +00:00
*--------------------------------------
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
2021-04-29 11:56:34 +00:00
.4 >LDA.G hFile
2021-04-08 20:30:18 +00:00
bne .90
>LDYA ZPPtr1
2021-04-29 11:56:34 +00:00
>STYA ZPPtr2 for printing later
jsr CS.RUN.FOpen
bcc CS.RUN.ARGS
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
.9 rts
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
.7 >LDA.G hFile
2021-04-08 20:30:18 +00:00
beq .90
clc
2021-04-29 11:56:34 +00:00
rts
2021-04-08 20:30:18 +00:00
.90 >PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
lda #E.SYN
sec QUIT Process
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
CS.RUN.FOpen >PUSHYA
>PUSHBI O.RDONLY
>PUSHBI S.FI.T.TXT
>PUSHWZ Aux type
>SYSCALL FOpen
2021-04-08 20:30:18 +00:00
bcs .9
2021-04-29 11:56:34 +00:00
>STA.G hFile
2021-04-08 20:30:18 +00:00
2021-07-09 13:54:42 +00:00
>LDYAI 256
>SYSCALL GetMem
bcs .9
>STYA.G InputBufPtr
txa
>STA.G hInputBuf
2021-04-08 20:30:18 +00:00
.9 rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
CS.RUN.FGetS >LDYA.G InputBufPtr
>STYA ZPInputBufPtr
>INCW.G LineCounter
>PUSHB.G hFile
>PUSHW ZPInputBufPtr
>PUSHWI 256
>SYSCALL FGetS
2021-04-08 20:30:18 +00:00
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
CS.DOEVENT sec
2021-04-08 20:30:18 +00:00
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
CS.QUIT jsr CORE.Quit
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
CS.FClose >LDA.G hFile
2021-07-09 13:54:42 +00:00
beq .1
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
>SYSCALL FClose
>STZ.G hFile
2021-04-08 20:30:18 +00:00
2021-07-09 13:54:42 +00:00
.1 >LDA.G hInputBuf
beq .8
>SYSCALL FreeMem
>STZ.G hInputBuf
.8
* clc
2021-04-08 20:30:18 +00:00
rts
*--------------------------------------
PrintDebugMsg >LDYA pStack
>STYA ZPPtr2
>PUSHW L.MSG.DEBUG
>PUSHW ZPCodeBufPtr
2021-05-09 12:39:40 +00:00
>PUSHW ZPConstBufPtr
>PUSHW ZPDataBufPtr
>PUSHW ZPPtr2
2021-04-08 20:30:18 +00:00
2021-05-09 12:39:40 +00:00
>PUSHBI 8
2021-04-08 20:30:18 +00:00
>SYSCALL PrintF
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
PrintTraceMsg ldy #S.PS.hStdErr
2021-04-08 20:30:18 +00:00
lda (pPS),y
2021-04-29 11:56:34 +00:00
>PUSHA
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
>PUSHW L.MSG.TRACE
>PUSHW.G LineCounter
>PUSHW.G InputBufPtr
>PUSHBI 4
>SYSCALL FPrintF
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
rts
*--------------------------------------
PrintErrorMsg >LDA.G bTrace
bmi .1
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
jsr PrintTraceMsg
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
.1 lda ZPInputBufPtr
sec
>SBC.G InputBufPtr
tax
2021-05-09 12:39:40 +00:00
2021-04-29 11:56:34 +00:00
>LDYA.G InputBufPtr
>STYA ZPInputBufPtr
txa
beq .3
ldy #0
lda #'-'
.2 sta (ZPInputBufPtr),y
iny
dex
bne .2
txa
.3 sta (ZPInputBufPtr),y
2021-04-08 20:30:18 +00:00
2021-04-29 11:56:34 +00:00
.8 ldy #S.PS.hStdErr
2021-04-08 20:30:18 +00:00
lda (pPS),y
>PUSHA
2021-04-29 11:56:34 +00:00
>PUSHW L.MSG.ERROR
>PUSHW ZPInputBufPtr
>PUSHBI 2
2021-04-08 20:30:18 +00:00
>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
2021-04-08 20:30:18 +00:00
*--------------------------------------
* Pre-compiled code
2021-04-29 11:56:34 +00:00
*--------------------------------------
2021-04-08 20:30:18 +00:00
CCODE.PUSHA >PUSHA
CCODE.PUSHA.LEN .EQ *-CCODE.PUSHA
*--------------------------------------
2021-05-09 12:39:40 +00:00
CCODE.TESTTRUE lda (pStack)
inc pStack
ora (pStack)
php
inc pStack
plp
.1 bne .1+5
.HS 4C JMP abs
2021-05-09 12:39:40 +00:00
CCODE.TESTTRUE.LEN .EQ *-CCODE.TESTTRUE
*--------------------------------------
2021-04-08 20:30:18 +00:00
* 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"
2021-04-29 11:56:34 +00:00
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"
2021-07-09 13:54:42 +00:00
MSG.RUN .AZ "***Code size: %D, Data Size: %D, Running...\r\n"
2021-04-08 20:30:18 +00:00
MSG.STR .AZ "%s"
2021-04-29 11:56:34 +00:00
MSG.INT16 .AZ "%I"
2021-04-08 20:30:18 +00:00
*--------------------------------------
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"
*--------------------------------------
2021-07-24 20:42:23 +00:00
FMT.DATE .AZ "%m/%d/%y"
FMT.TIME .AZ "%H:%M:%S"
*--------------------------------------
2021-04-08 20:30:18 +00:00
OptionList .AS "DdTt"
OptionVars .DA #bDebug,#bDebug,#bTrace,#bTrace
*--------------------------------------
2021-05-04 17:31:21 +00:00
ACOS.OPSChars .AS "+-*/<>="
ACOS.OPSChars.Cnt .EQ *-ACOS.OPSChars
2021-04-08 20:30:18 +00:00
*--------------------------------------
2021-05-04 17:31:21 +00:00
ACOS.OPS .AT "*"
.AT "/"
.AT "MOD"
.AT "+"
.AT "-"
2021-04-08 20:30:18 +00:00
.AT "<"
.AT "<="
.AT "=<"
2021-05-04 17:31:21 +00:00
.AT ">"
2021-04-08 20:30:18 +00:00
.AT ">="
.AT "=>"
2021-05-04 17:31:21 +00:00
.AT "<>"
.AT "><"
.AT "="
2021-04-08 20:30:18 +00:00
.AT "AND"
.AT "OR"
.HS 00
*--------------------------------------
2021-05-09 12:39:40 +00:00
ACOS.OPS2FPU .DA #FPU.iMUL,#FPU.iDIV,#FPU.iMOD,#FPU.iADD,#FPU.iSUB
2021-05-04 17:31:21 +00:00
.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
*--------------------------------------
2021-04-08 20:30:18 +00:00
ACOS.KW .AT "ADDINT"
.AT "APPEND"
.AT "BYTE"
.AT "CLEAR"
.AT "CLOCK"
.AT "CLOSE"
.AT "COPY"
.AT "CREATE"
.AT "ECHO"
.AT "EDIT"
2021-05-09 12:39:40 +00:00
.AT "ELSE"
2021-04-08 20:30:18 +00:00
.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"
2021-04-08 20:30:18 +00:00
.AT "DATE$"
.AT "FLAG"
.AT "INFO"
.AT "INSTR"
.AT "KEY"
.AT "LEFT$"
.AT "LEN"
2021-04-08 20:30:18 +00:00
.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
2021-05-09 12:39:40 +00:00
CCS .BS CCS.MAX
2021-04-08 20:30:18 +00:00
bDebug .BS 1
bTrace .BS 1
2021-04-29 11:56:34 +00:00
LineCounter .BS 2
hFile .BS 1
2021-07-09 13:54:42 +00:00
hInputBuf .BS 1
2021-04-29 11:56:34 +00:00
InputBufPtr .BS 2
2021-04-08 20:30:18 +00:00
hCodeBuf .BS 1
hConstBuf .BS 1
hDataBuf .BS 1
hLabels .BS 1
hVars .BS 1
2021-04-29 11:56:34 +00:00
hStrBuf .BS 1
2021-04-15 14:03:04 +00:00
hFWRefBuf .BS 1
TimeBuf .BS S.TIME
2021-04-08 20:30:18 +00:00
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/acos.s
ASM