A2osX/BIN/ACOS.S.txt

605 lines
11 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-04-08 20:30:18 +00:00
CONSTSEG .EQ 1024
DATASEG .EQ 256
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-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
.BS 1
2021-04-08 20:30:18 +00:00
ZPPtr1 .BS 2
ZPPtr2 .BS 2
ZPPtr3 .BS 2
hIn .BS 1
hOut .BS 1
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-15 14:03:04 +00:00
ArgIndex .BS 1
bFlag .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-04-10 17:17:40 +00:00
.DA #128 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
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.ERR .DA MSG.ERR
L.MSG.RUN .DA MSG.RUN
2021-04-15 14:03:04 +00:00
L.MSG.FWREFERR .DA MSG.FWREFERR
2021-04-08 20:30:18 +00:00
L.MSG.STR .DA MSG.STR
L.MSG.INT32 .DA MSG.INT32
*--------------------------------------
L.ACOS.AOPS .DA ACOS.AOPS
J.ACOS.AOPS .DA EXP.ADD
.DA EXP.SUB
.DA EXP.MUL
.DA EXP.DIV
.DA EXP.MOD
L.ACOS.BOPS .DA ACOS.BOPS
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.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
.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
jsr CORE.Init
bcs CS.INIT.RTS
>PUSHW L.MSG.COMPILING
>PUSHW ZPPtr2
>PUSHBI 2
>SYSCALL PrintF
bcs CS.INIT.RTS
.1 >SLEEP
>LDA.G bDebug
bpl .2
jsr PrintDebugMsg
.2 >LDA.G bTrace
bpl .3
>LDYA ZPInputBufPtr
jsr PrintTraceMsg
.3 jsr CORE.Compile
bcc .1
cmp #MLI.E.EOF
bne .9
2021-04-15 14:03:04 +00:00
jsr CORE.FWREF
bcs .9
2021-04-08 20:30:18 +00:00
jsr CORE.Run
bcc .8
.9 pha
jsr PrintErrMsg
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 hFileBuf
bne .90
>LDYA ZPPtr1
>STYA ZPPtr2 form printing later
jsr CS.RUN.LoadFile
bcs .9
>STYA ZPInputBufPtr
txa
>STA.G hFileBuf
bra CS.RUN.ARGS
.7 >LDA.G hFileBuf
beq .90
clc
.9 rts
.90 >PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
lda #E.SYN
sec QUIT Process
rts
*--------------------------------------
CS.RUN.LoadFile >SYSCALL LoadTxtFile
bcs .9
phx
txa
>SYSCALL GetMemPtr
plx
.9 rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT jsr CORE.Quit
clc
rts
*--------------------------------------
PrintErrMsg >LDA.G hFileBuf
>SYSCALL GetMemPtr
>STYA ZPPtr1
stz ZPPtr2
stz ZPPtr2+1 Line counter
.1 inc ZPPtr2
bne .2
inc ZPPtr2+1
.2 >LDYA ZPPtr1
>STYA ZPPtr3 save line start
.20 lda (ZPPtr1)
beq .4 EoF
inc ZPPtr1
bne .3
inc ZPPtr1+1
.3 cmp #C.CR
bne .20 Scan until EoL
ldx ZPPtr1
cpx ZPInputBufPtr
lda ZPPtr1+1
sbc ZPInputBufPtr+1
bcc .1 not this line....
.4 >LDA.G bTrace
bmi .5
jsr PrintTraceMsg.3
.5 lda ZPPtr3
cmp ZPInputBufPtr
bne .6
lda ZPPtr3+1
cmp ZPInputBufPtr+1
beq .8
.6 >PUSHBI '-'
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL FPutC
inc ZPPtr3
bne .5
inc ZPPtr3+1
bra .5
.8 ldy #S.PS.hStdErr
lda (pPS),y
>PUSHA
>PUSHW L.MSG.ERR
>PUSHW ZPPtr2 Line counter
>PUSHBI 2
>SYSCALL FPrintF
rts
*--------------------------------------
PrintDebugMsg >LDYA pStack
>STYA ZPPtr2
>PUSHW L.MSG.DEBUG
>PUSHW ZPPtr2
>PUSHW ZPCodeBufPtr
>PUSHBI 4
>SYSCALL PrintF
rts
*--------------------------------------
PrintTraceMsg >STYA ZPPtr3
PrintTraceMsg.3 >PUSHBI '>'
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL FPutC
ldy #$ff
.1 iny
lda (ZPPtr3),y
beq .8
cmp #C.CR
beq .8
phy
>PUSHA
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL FPutC
ply
bra .1
.8 ldy #S.PS.hStdErr
lda (pPS),y
>PUSHA
>PUSHW L.MSG.ECHOCRLF
>PUSHBI 0
>SYSCALL FPrintF
rts
*--------------------------------------
CCODE.PUSHLYA >STYA ZPADDR
ldy #3
.1 lda (ZPADDR),y
>PUSHA
dey
bpl .1
CCODE.PUSHLYA.LEN .EQ *-CCODE.PUSHLYA
*--------------------------------------
CCODE.PULLLYA >STYA ZPADDR
ldy #0
.1 >PULLA
sta (ZPADDR),y
iny
cpy #4
bcc .1
CCODE.PULLLYA.LEN .EQ *-CCODE.PULLLYA
*--------------------------------------
CCODE.PUSHA >PUSHA
CCODE.PUSHA.LEN .EQ *-CCODE.PUSHA
*--------------------------------------
CCODE.PULLA >PULLA
CCODE.PULLA.LEN .EQ *-CCODE.PULLA
*--------------------------------------
CCODE.FPRINTSTR pha
>PUSHW L.MSG.STR
pla
>PUSHA
tya
>PUSHA
>PUSHBI 2
>SYSCALL PrintF
CCODE.FPRINTSTR.LEN .EQ *-CCODE.FPRINTSTR
*--------------------------------------
CCODE.FPRINTL >PUSHW L.MSG.INT32
ldx #4
ldy #5
.1 lda (pStack),y
>PUSHA
dex
bne .1
2021-04-10 17:17:40 +00:00
2021-04-08 20:30:18 +00:00
>PUSHBI 4
>SYSCALL PrintF
>POP 4 Discard long on stack
CCODE.FPRINTL.LEN .EQ *-CCODE.FPRINTL
*--------------------------------------
.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
*--------------------------------------
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 "pStack=%H CodePtr=%H\r\n"
MSG.ERR .AZ "-^\r\nLine #%D:"
2021-04-15 14:03:04 +00:00
MSG.RUN .AZ "Success, Code size = %D Bytes\r\nResolving FWRefs...\r\n"
MSG.FWREFERR .AZ "Unresolved FWRef : %s\r\n"
2021-04-08 20:30:18 +00:00
MSG.STR .AZ "%s"
MSG.INT32 .AZ "%L"
*--------------------------------------
OptionList .AS "DdTt"
OptionVars .DA #bDebug,#bDebug,#bTrace,#bTrace
*--------------------------------------
ACOS.AOPSChars .AS "+-*/"
ACOS.AOPSChars.Cnt .EQ *-ACOS.AOPSChars
*--------------------------------------
ACOS.AOPS .AT "MOD"
.HS 00
*--------------------------------------
ACOS.BOPS .AT "="
.AT "<>"
.AT "><"
.AT "<"
.AT ">"
.AT "<="
.AT "=<"
.AT ">="
.AT "=>"
.AT "NOT"
.AT "AND"
.AT "OR"
.HS 00
*--------------------------------------
ACOS.KW .AT "ADDINT"
.AT "APPEND"
.AT "BYTE"
.AT "CLEAR"
.AT "CLOCK"
.AT "CLOSE"
.AT "COPY"
.AT "CREATE"
.AT "ECHO"
.AT "EDIT"
.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 "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
bDebug .BS 1
bTrace .BS 1
hFileBuf .BS 1
hCodeBuf .BS 1
hConstBuf .BS 1
hDataBuf .BS 1
hLabels .BS 1
hVars .BS 1
2021-04-15 14:03:04 +00:00
hFWRefBuf .BS 1
2021-04-08 20:30:18 +00:00
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/acos.s
ASM