mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-03 12:06:05 +00:00
277 lines
4.1 KiB
Plaintext
277 lines
4.1 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
FILE.New >LDYAI 4096
|
||
>STYA BufLen
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
|
||
>STYA BufPtr
|
||
>STYA.G BufBase
|
||
|
||
txa
|
||
>STA.G hBuffer FileLen already set to 0
|
||
|
||
lda #0
|
||
sta (BufPtr)
|
||
|
||
stz FileLen
|
||
stz FileLen+1
|
||
|
||
>LDYA L.MSG.NEWFILE
|
||
>SYSCALL RealPath
|
||
bcs .9
|
||
|
||
txa
|
||
>STA.G hFileName
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
FILE.Load jsr BUF.ResetSel
|
||
|
||
>PUSHEA.G STATBUF
|
||
>LDA.G hFileName
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL stat
|
||
bcs FILE.New
|
||
|
||
>LDA.G STATBUF+S.STAT.P.TYPE
|
||
cmp #S.FI.T.TXT
|
||
beq FILE.Load.TXT
|
||
cmp #$FA S-C/ASM?
|
||
bne .9
|
||
|
||
jmp FILE.Load.ASM
|
||
|
||
.9 lda #MLI.E.INCFF
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
FILE.Load.TXT stz FileLen
|
||
stz FileLen+1
|
||
|
||
stz TmpByte hLineBuffer
|
||
stz TmpIndex hFile
|
||
|
||
>STZ.G FileType
|
||
|
||
jsr FILE.GetBuffer
|
||
bcs .99
|
||
|
||
>LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .99
|
||
|
||
>STYA ZPPTR1
|
||
stx TmpByte
|
||
|
||
>PUSHWZ Aux type
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHBI O.RDONLY+O.TEXT
|
||
>LDA.G hFileName
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL fopen
|
||
.99 bcs .9
|
||
|
||
sta TmpIndex
|
||
|
||
.1 >PUSHWI 254
|
||
>PUSHW ZPPTR1
|
||
lda TmpIndex
|
||
>SYSCALL fread
|
||
bcs .7
|
||
|
||
lda #0
|
||
sta (ZPPTR1),y Y = line len
|
||
|
||
ldx #0
|
||
ldy #0
|
||
lda (ZPPTR1)
|
||
beq .8
|
||
|
||
eor #C.LF
|
||
bne .2
|
||
|
||
phy
|
||
|
||
lda #2
|
||
>STA.G FileType
|
||
|
||
ply
|
||
iny
|
||
|
||
.2 lda (ZPPTR1),y
|
||
beq .4
|
||
|
||
sta (BufPtr)
|
||
inc BufPtr
|
||
bne .3
|
||
|
||
inc BufPtr+1
|
||
|
||
.3 inx
|
||
iny
|
||
bra .2
|
||
|
||
.4 txa
|
||
clc
|
||
adc FileLen
|
||
sta FileLen
|
||
bcc .1
|
||
|
||
inc FileLen+1
|
||
bra .1
|
||
|
||
.7 cmp #MLI.E.EOF
|
||
bne .9
|
||
|
||
.8 lda #0
|
||
sta (BufPtr)
|
||
|
||
clc
|
||
.HS B0 BCS
|
||
.9 sec
|
||
jmp FILE.Close
|
||
*--------------------------------------
|
||
FILE.Load.ASM
|
||
lda #MLI.E.INCFF
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
FILE.Save >LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs .9
|
||
|
||
>STYA ZPPTR1
|
||
stx TmpByte
|
||
|
||
>LDA.G FileType
|
||
tax
|
||
|
||
jmp (J.SAVE,x)
|
||
.9 rts
|
||
*--------------------------------------
|
||
FILE.Save.CR clc
|
||
.HS B0 BCS
|
||
FILE.Save.CRLF sec
|
||
ror TmpIndex+1
|
||
|
||
>PUSHWZ Aux type
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHBI O.CREATE+O.WRONLY
|
||
>LDA.G hFileName
|
||
>SYSCALL GetMemPtr
|
||
>SYSCALL FOpen
|
||
bcs .9
|
||
|
||
sta TmpIndex
|
||
|
||
>LDYA.G BufBase
|
||
>STYA BufPtr
|
||
|
||
.1 lda (BufPtr)
|
||
beq .8
|
||
|
||
ldy #$ff
|
||
|
||
.2 iny
|
||
lda (BufPtr),y
|
||
sta (ZPPTR1),y
|
||
beq .3
|
||
|
||
cmp #C.CR
|
||
bne .2
|
||
|
||
iny
|
||
|
||
bit TmpIndex+1
|
||
bpl .3
|
||
|
||
iny
|
||
|
||
lda #C.LF
|
||
sta (ZPPTR1),y
|
||
|
||
.3 tya
|
||
beq .8
|
||
|
||
clc
|
||
adc BufPtr
|
||
sta BufPtr
|
||
bcc .4
|
||
|
||
inc BufPtr+1
|
||
|
||
.4 lda #0
|
||
>PUSHYA
|
||
>PUSHW ZPPTR1
|
||
lda TmpIndex
|
||
>SYSCALL FWrite
|
||
bcs .9
|
||
|
||
bra .1
|
||
|
||
.8 lda #$80
|
||
>STA.G bSaved
|
||
jsr SCRN.UpdateTopBar
|
||
clc
|
||
.9 jmp FILE.Close
|
||
*--------------------------------------
|
||
FILE.Save.ASM
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
FILE.GetBuffer >LDA.G STATBUF+S.STAT.SIZE+3
|
||
dey
|
||
ora (pData),y
|
||
bne .9
|
||
|
||
dey
|
||
lda (pData),y Size HI
|
||
cmp #16
|
||
bcs .1
|
||
|
||
lda #13 Min = 3k
|
||
|
||
.1 adc #3 1K more
|
||
|
||
ldy #0 Size LO
|
||
>STYA BufLen
|
||
>SYSCALL GetMem
|
||
bcs .99
|
||
|
||
>STYA BufPtr
|
||
>STYA.G BufBase
|
||
txa
|
||
>STA.G hBuffer
|
||
|
||
lda #0
|
||
sta (BufPtr)
|
||
|
||
rts
|
||
|
||
.9 lda #E.FTB
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
FILE.Close php
|
||
pha
|
||
lda TmpByte
|
||
beq .1
|
||
>SYSCALL freemem
|
||
|
||
.1 lda TmpIndex
|
||
beq .2
|
||
|
||
>SYSCALL fclose
|
||
|
||
.2 pla
|
||
plp
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/BIN/EDIT.S.FILE
|
||
LOAD USR/SRC/BIN/EDIT.S
|
||
ASM
|