A2osX/BIN/CSH.S.txt
2019-08-27 17:13:00 +02:00

256 lines
5.1 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 Enable MASM3 auto line num
.LIST OFF
.OP 65C02 Target CPU, must match CPU level in header
.OR $2000 usualy $2000, but any value > $100 allowed
.TF BIN/CSH
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/MLI.I
.INB INC/MLI.E.I
*--------------------------------------
.INB USR/SRC/BIN/CSH.E
*--------------------------------------
* Zero Page Segment, up to 32 bytes
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPFileBuf .BS 2
ZPFileBufPtr .BS 2
ZPCSHConst .BS 2
ZPCSHStack .BS 2
ZPPtr1 .BS 2
ZPPtr2 .BS 2
ZPPtr3 .BS 2
ZPVarID .BS 2
ZPVarType .BS 1
ZPVarData .BS 6
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 #64 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.ECHOCRLF .DA MSG.ECHOCRLF
L.MSG.ERR .DA MSG.ERR
.INB USR/SRC/BIN/CSH.R
.DA 0
*--------------------------------------
* Called once at process creation
* Put code for loading LIB here
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
* Called until exit with CS
* if RUN exits with CC, RN entered again
*--------------------------------------
CS.RUN lda #$ff
>STA.G bTrace
>PUSHWI K.VER
>PUSHBI 2
>LDYA L.MSG.GREETINGS
>SYSCALL printf
bcs .99
jsr CSH.Init
bcs .99
ldy #S.PS.ARGC
lda (pPS),y
beq .90 no arg, usage
>PUSHWZ Aux type
>PUSHBI S.FI.T.TXT
>PUSHBI O.RDONLY
lda #1
>SYSCALL ArgV
>SYSCALL LoadTxtFile
bcs .99
txa
>STA.G hFileBuf
>SYSCALL GetMemPtr
>STYA ZPFileBuf
>STYA ZPFileBufPtr
.1 >SLEEP
>LDA.G bTrace
bpl .2
>LDYA ZPFileBufPtr
jsr PrintTraceMsg
.2 jsr CSH.Run
bcc .1
cmp #MLI.E.EOF
beq .8
pha
jsr PrintErrMsg
pla
sec
rts
.8 lda #0
sec
rts
.90 lda #E.SYN Exit Code = Succes
sec QUIT Process
.99 rts
*--------------------------------------
* Called if option S.PS.F.EVENT enabled in Header
* Timer Event : every 10th seconds
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
* Called once, when RUN exited with CS
* Put code for unloading LIB here
*--------------------------------------
CS.QUIT jsr CSH.Quit
clc
rts
*--------------------------------------
PrintErrMsg >LDYA ZPFileBuf
>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 ZPFileBufPtr
lda ZPPtr1+1
sbc ZPFileBufPtr+1
bcc .1 not this line....
.4 >LDA.G bTrace
bmi .5
jsr PrintTraceMsg.3
.5 lda ZPPtr3
cmp ZPFileBufPtr
bne .6
lda ZPPtr3+1
cmp ZPFileBufPtr+1
beq .8
.6 >PUSHBI '-'
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL fputc
inc ZPPtr3
bne .5
inc ZPPtr3+1
bra .5
.8 >PUSHW ZPPtr2 Line counter
>PUSHBI 2
>PUSHW L.MSG.ERR
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL fprintf
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 >PUSHBI 0
>PUSHW L.MSG.ECHOCRLF
ldy #S.PS.hStdErr
lda (pPS),y
>SYSCALL fprintf
rts
*--------------------------------------
.INB USR/SRC/BIN/CSH.S.CORE
*--------------------------------------
CS.END
*--------------------------------------
* Initialized DATA
*--------------------------------------
MSG.Greetings .AZ "\r\nCSH-Shell %d.%d\r\n\r\n"
MSG.ECHOCRLF .AZ "\r\n"
MSG.ERR .AZ "^\r\nLine #%D:"
*--------------------------------------
.INB USR/SRC/BIN/CSH.I
*--------------------------------------
.DUMMY
.OR 0
DS.START .INB USR/SRC/BIN/CSH.D
bTrace .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/CSH.S
ASM