A2osX/BIN/ASM.S.FIO.txt

342 lines
5.1 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
AUTO 4,1
2015-10-28 16:55:12 +00:00
*---------------------------------------
FIO.Init >LDYA L.ASM.6502
FIO.LOAD.ASM.T >STYA ZPPtr2
2018-01-11 16:34:09 +00:00
2018-10-16 15:48:03 +00:00
ldy #S.PS.hARGV
lda (pPS),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1
ldy #$ff
ldx #$ff
2018-01-11 16:34:09 +00:00
.1 iny
inx
lda (ZPPtr1),y
sta ASM.T.FILENAME,x
bne .1
lda #'.'
sta ASM.T.FILENAME,x
2015-12-04 16:33:33 +00:00
inx
2018-01-11 16:34:09 +00:00
lda #'T'
sta ASM.T.FILENAME,x
2018-01-11 16:34:09 +00:00
inx
2018-01-11 16:34:09 +00:00
lda #'.'
sta ASM.T.FILENAME,x
ldy #$ff
2018-01-11 16:34:09 +00:00
.2 iny
inx
lda (ZPPtr2),y
jsr SRC.IsLetterOrDigit
bcs .3
sta ASM.T.FILENAME,x
bra .2
.3 stz ASM.T.FILENAME,x
ldy #ASM.T.hMem
lda (pData),y
beq .4
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
ldy #ASM.T.hMem
lda #0
sta (pData),y
.4 >PUSHW L.ASM.T.FILENAME
2018-11-26 21:52:49 +00:00
>PUSHBI 2
>LDYA L.MSG.T.FILE
jsr OUT.Print
>PUSHWI 0 Aux type
>PUSHBI 6 S.FI.T.BIN
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY
2018-07-25 15:26:14 +00:00
>LDYA L.ASM.T.FILENAME
>SYSCALL LoadFile
bcs .9
txa
ldy #ASM.T.hMem
sta (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPPtr1
2018-01-15 06:50:44 +00:00
ldy #ASM.T.AM
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPAMPtr
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPAMPtr+1
iny
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPRPtr
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPRPtr+1
iny
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPOpsPtr
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPOpsPtr+1
.9 rts
*---------------------------------------
FIO.OpenFile >STYA ZPPtr1
>PUSHW ZPPtr1
2018-11-26 21:52:49 +00:00
>PUSHBI 2
>LDYA L.MSG.SRC.FILE
jsr OUT.Print
ldy #SRC.COUNT
lda (pData),y
cmp #IN.MAXDEPTH
bne .1
lda #ERR.SRC.TOO.MANY.IN
sec
rts
.1 >PUSHW L.FIO.Stat
>PUSHW ZPPtr1
>SYSCALL Stat
bcs .99
lda FIO.Stat+S.STAT.P.TYPE
cmp #$04 TXT ?
bne .2
2018-01-29 16:48:07 +00:00
>PUSHWI 0
>PUSHBI 4
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY+O.TEXT
bra .3
.2 cmp #$FA S-C/BAS?
bne .98
>PUSHWI 0
>PUSHBI $FA
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY
2018-07-25 15:26:14 +00:00
.3 >LDYA ZPPtr1
>SYSCALL FOpen
bcs .99
pha
ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILES
tay
pla
sta (pData),y
ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILETYPES
tay
2015-10-28 16:55:12 +00:00
lda FIO.Stat+S.STAT.P.TYPE
sta (pData),y
ldy #SRC.COUNT
lda (pData),y
inc
sta (pData),y
lda #0
>STA.G SRC.LINENUM
iny
sta (pData),y
clc
rts
.98 lda #ERR.SRC.INV.TYPE
sec
.99 rts
2015-10-28 16:55:12 +00:00
*---------------------------------------
FIO.ReadLine >LDYA ZPLineBuf
>STYA ZPLinePtr
ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILETYPES-1
tay
lda (pData),y
bmi .10
2018-01-29 16:48:07 +00:00
>PUSHW ZPLineBuf
>PUSHWI 256
2018-01-29 16:48:07 +00:00
jsr FIO.ReadFromFile
bcs .19
tya
beq .13
2018-01-29 16:48:07 +00:00
dey
2018-01-29 16:48:07 +00:00
lda #0 replace ending $0D with $00
.13 sta (ZPLineBuf),y
>INC.G SRC.LINENUM
bne .19
>INC.G SRC.LINENUM+1
.19 rts
2018-01-11 16:34:09 +00:00
*---------------------------------------
.10 >PUSHW ZPTmpBuf
>PUSHWI 3
jsr FIO.ReadFromFile
bcs .19
2015-10-28 16:55:12 +00:00
ldy #1
lda (ZPTmpBuf),y
pha
iny
lda (ZPTmpBuf),y
>STA.G SRC.LINENUM+1
pla
>STA.G SRC.LINENUM
lda (ZPTmpBuf) LEN
sec
sbc #3
bcc .9 LEN should be at least 3
2015-10-28 16:55:12 +00:00
tay
lda #0
>PUSHYA
2018-07-25 15:26:14 +00:00
>PUSHW ZPTmpBuf
jsr FIO.ReadFromFile
bcs .9
>LDYA ZPTmpBuf
>STYA ZPPtr1
ldy #0
.1 lda (ZPPtr1)
inc ZPPtr1
bne .11
inc ZPPtr1+1
.11 tax
bmi .2
sta (ZPLineBuf),y
beq .8 Ending 00
2018-01-11 16:34:09 +00:00
iny
bne .1
bra .99
.2 cmp #$C0 REPEAT char?
bne .5
2018-01-12 16:05:04 +00:00
lda (ZPPtr1) Get Repeat Count
inc ZPPtr1
bne .3
inc ZPPtr1+1
.3 tax
2018-01-11 16:34:09 +00:00
lda (ZPPtr1) Get Repeat Char
inc ZPPtr1
bne .4
inc ZPPtr1+1
.4 sta (ZPLineBuf),y
iny
beq .99
dex
bne .4
2018-01-11 16:34:09 +00:00
bra .1
.5 and #$3F Compute blank count
tax
lda #$20
.6 sta (ZPLineBuf),y
iny
beq .99
dex
bne .6
bra .1
.8 clc
.9 rts
2015-10-28 16:55:12 +00:00
.99 lda #ERR.LINE.TOO.LONG
sec
rts
2015-10-28 16:55:12 +00:00
*--------------------------------------
FIO.ReadFromFile
ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILES-1
tay
lda (pData),y
>SYSCALL FRead
bcs .9
tax $100 byte transfered ?
beq .9
lda #ERR.LINE.TOO.LONG
sec
.9 rts
2015-10-28 16:55:12 +00:00
*---------------------------------------
FIO.FileClose ldy #SRC.COUNT
lda (pData),y
beq .8
clc
adc #SRC.hFILES-1
tay
lda (pData),y
2018-07-20 11:51:08 +00:00
>SYSCALL fclose
ldy #SRC.COUNT
lda (pData),y
dec
sta (pData),y
.8 clc
rts
2015-10-28 16:55:12 +00:00
*---------------------------------------
MAN
2018-11-26 21:52:49 +00:00
SAVE USR/SRC/BIN/DEV/ASM.S.FIO
LOAD USR/SRC/BIN/DEV/ASM.S
2015-10-28 16:55:12 +00:00
ASM