A2osX/BIN/ASM.S.FIO.txt
2018-01-15 06:50:44 +00:00

323 lines
5.2 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
PREFIX /A2OSX.BUILD
AUTO 4,1
*---------------------------------------
FIO.Init >LDYA L.ASM.6502
FIO.LOAD.ASM.T >STYA ZPPtr2
ldy #S.PS.hARGS
lda (pPS),y
>SYSCALL GetMemPtr.A
>STYA ZPPtr1
ldy #$ff
ldx #$ff
.1 iny
inx
lda (ZPPtr1),y
sta ASM.T.FILENAME,x
bne .1
lda #'.'
sta ASM.T.FILENAME,x
inx
lda #'T'
sta ASM.T.FILENAME,x
inx
lda #'.'
sta ASM.T.FILENAME,x
ldy #$ff
.3 iny
inx
lda (ZPPtr2),y
sta ASM.T.FILENAME,x
bne .3
ldy #ASM.T.hMem
lda (pData),y
beq .4
>SYSCALL FreeMem.A
ldy #ASM.T.hMem
lda #0
sta (pData),y
.4 >PUSHW L.ASM.T.FILENAME
>LDYA L.MSG.T.FILE
>SYSCALL PrintF.YA
>PUSHWI 0 Aux type
>PUSHBI 6 S.FI.T.BIN
>PUSHBI SYS.FOpen.R
>PUSHW L.ASM.T.FILENAME
>SYSCALL LoadFile
bcs .9
txa
ldy #ASM.T.hMem
sta (pData),y
>SYSCALL GetMemPtr.A
>STYA ZPPtr1
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 ZPOPtr
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPOPtr+1
.9 rts
*---------------------------------------
FIO.OpenFile >STYA ZPPtr1
>PUSHW ZPPtr1
>LDYA L.MSG.SRC.FILE
>SYSCALL PrintF.YA
ldy #SRC.COUNT
lda (pData),y
cmp #SRC.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
>PUSHWI 0
>PUSHBI 4
>PUSHBI SYS.FOpen.R+SYS.FOpen.T
bra .3
.2 cmp #$FA S-C/BAS?
bne .98
>PUSHWI 0
>PUSHBI $FA
>PUSHBI SYS.FOpen.R
.3 >PUSHW 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
lda FIO.Stat+S.STAT.P.TYPE
sta (pData),y
ldy #SRC.COUNT
lda (pData),y
inc
sta (pData),y
clc
rts
.98 lda #ERR.SRC.INV.TYPE
sec
.99 rts
*---------------------------------------
FIO.ReadLine >LDYA ZPLineBuf
>STYA ZPLinePtr
ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILETYPES-1
tay
lda (pData),y
bmi .10
>PUSHW ZPLineBuf
>PUSHWI 256
jsr FIO.ReadFromFile
bcs .19
lda #0 replace ending $0D with $00
sta (ZPLineBuf),y
.19 rts
*---------------------------------------
.10 >PUSHW ZPTmpBuf
>PUSHWI 3
jsr FIO.ReadFromFile
bcs .19
ldy #1
lda (ZPTmpBuf),y
sta SRC.LINENUM
iny
lda (ZPTmpBuf),y
sta SRC.LINENUM+1
lda (ZPTmpBuf) LEN
sec
sbc #3
bcc .9 LEN should be at least 3
tay
>PUSHW ZPTmpBuf
lda #0
>PUSHYA
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
iny
bne .1
bra .99
.2 cmp #$C0 REPEAT char?
bne .5
lda (ZPPtr1) Get Repeat Count
inc ZPPtr1
bne .3
inc ZPPtr1+1
.3 tax
lda (ZPPtr1) Get Repeat Char
inc ZPPtr1
bne .4
inc ZPPtr1+1
.4 sta (ZPLineBuf),y
iny
beq .99
dex
bne .4
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
.99 lda #ERR.LINE.TOO.LONG
sec
rts
*--------------------------------------
FIO.ReadFromFile ldy #SRC.COUNT
lda (pData),y
clc
adc #SRC.hFILES-1
tay
lda (pData),y
>PUSHA
>SYSCALL FRead
bcs .9
tax $100 byte transfered ?
beq .9
lda #ERR.LINE.TOO.LONG
sec
.9 rts
*---------------------------------------
FIO.FileClose ldy #SRC.COUNT
lda (pData),y
beq .8
clc
adc #SRC.hFILES-1
tay
lda (pData),y
>SYSCALL FClose.A
ldy #SRC.COUNT
lda (pData),y
dec
sta (pData),y
.8 clc
rts
*---------------------------------------
FIO.EmitByte clc
rts
*---------------------------------------
MAN
SAVE /A2OSX.BUILD/BIN/DEV/ASM.S.FIO
LOAD /A2OSX.BUILD/BIN/DEV/ASM.S
ASM