exit() now also resets the io channels. Optimized diskio data read subroutines. added diskio.f_read_all()

This commit is contained in:
Irmen de Jong 2020-12-31 16:46:24 +01:00
parent ca83092aed
commit b6fa361bcc
3 changed files with 149 additions and 12 deletions

View File

@ -201,7 +201,7 @@ close_end:
f_close()
c64.SETNAM(strlen(filenameptr), filenameptr)
c64.SETLFS(11, drivenumber, 0)
c64.SETLFS(11, drivenumber, 3)
void c64.OPEN() ; open 11,8,0,"filename"
if_cc {
iteration_in_progress = true
@ -221,15 +221,28 @@ close_end:
uword actual = 0
void c64.CHKIN(11) ; use #11 as input channel again
%asm {{
lda bufferpointer
sta _in_buffer+1
lda bufferpointer+1
sta _in_buffer+2
}}
repeat num_bytes {
ubyte data = c64.CHRIN()
@(bufferpointer) = data
bufferpointer++
actual++
ubyte status = c64.READST()
if status==64
%asm {{
jsr c64.CHRIN
_in_buffer sta $ffff
inc _in_buffer+1
bne +
inc _in_buffer+2
+ inc actual
bne +
inc actual+1
+
}}
ubyte data = c64.READST()
if data==64
f_close() ; end of file, close it
if status
if data
return actual
}
return actual
@ -242,12 +255,57 @@ close_end:
return
void c64.CHKIN(11) ; use #11 as input channel again
repeat num_bytes {
@(bufferpointer) = c64.CHRIN()
bufferpointer++
}
; repeat num_bytes {
; @(bufferpointer) = c64.CHRIN()
; bufferpointer++
; }
%asm {{
lda bufferpointer
sta P8ZP_SCRATCH_W1
lda bufferpointer+1
sta P8ZP_SCRATCH_W1+1
lda #0
sta P8ZP_SCRATCH_B1
lda num_bytes+1
sta P8ZP_SCRATCH_W2
beq _no_msb
- jsr c64.CHRIN
ldy P8ZP_SCRATCH_B1
sta (P8ZP_SCRATCH_W1),y
inc P8ZP_SCRATCH_B1
bne -
inc P8ZP_SCRATCH_W1+1
dec P8ZP_SCRATCH_W2
bne -
_no_msb
lda num_bytes
beq _done
- jsr c64.CHRIN
ldy P8ZP_SCRATCH_B1
sta (P8ZP_SCRATCH_W1),y
iny
sty P8ZP_SCRATCH_B1
cpy num_bytes
bne -
_done
}}
}
sub f_read_all(uword bufferpointer) -> uword {
; -- read the full contents of the file, returns number of bytes read.
if not iteration_in_progress
return 0
uword total = 0
while not c64.READST() {
total += f_read(bufferpointer, 256)
txt.chrout('.')
bufferpointer += 256
}
return total
}
sub f_close() {
; -- end an iterative file loading session (close channels).
if iteration_in_progress {

View File

@ -1080,6 +1080,7 @@ _loop_hi ldy _index_first
func_exit .proc
; -- immediately exit the program with a return code in the A register
jsr c64.CLRCHN ; reset i/o channels
ldx orig_stackpointer
txs
rts ; return to original caller

View File

@ -1,5 +1,6 @@
%import test_stack
%import textio
%import diskio
%zeropage basicsafe
%option no_sysinit
@ -7,7 +8,84 @@ main {
sub start () {
uword large_buffer_ptr = progend()
ubyte[256] buffer
uword size
if diskio.f_open(8, "rom.asm2") {
txt.print("read-exact\n")
c64.SETTIM(0,0,0)
size = 0
while not c64.READST() {
diskio.f_read_exact(&buffer, len(buffer))
size += 256
}
diskio.f_close()
txt.print_uw(size)
txt.chrout('\n')
print_time()
txt.chrout('\n')
} else
txt.print("can't open file!\n")
txt.print(diskio.status(8))
txt.chrout('\n')
if diskio.f_open(8, "rom.asm2") {
txt.print("read-all\n")
c64.SETTIM(0,0,0)
size = 0
size = diskio.f_read_all(large_buffer_ptr)
diskio.f_close()
txt.print_uw(size)
txt.chrout('\n')
print_time()
txt.chrout('\n')
} else
txt.print("can't open file!\n")
txt.print(diskio.status(8))
txt.chrout('\n')
; if diskio.f_open(8, "rom.asm") {
; txt.print("read\n")
; c64.SETTIM(0,0,0)
; size = 0
; while not c64.READST() {
; size += diskio.f_read(&buffer, len(buffer))
; }
;
; diskio.f_close()
; txt.print_uw(size)
; txt.chrout('\n')
; print_time()
; txt.chrout('\n')
; }
test_stack.test()
}
sub print_time() {
ubyte time_lo
ubyte time_mid
ubyte time_hi
%asm {{
stx P8ZP_SCRATCH_REG
jsr c64.RDTIM ; A/X/Y
sta time_lo
stx time_mid
sty time_hi
ldx P8ZP_SCRATCH_REG
}}
txt.print_ub(time_hi)
txt.chrout(':')
txt.print_ub(time_mid)
txt.chrout(':')
txt.print_ub(time_lo)
txt.chrout('\n')
}
}