mirror of
https://github.com/irmen/prog8.git
synced 2025-02-19 11:31:07 +00:00
exit() now also resets the io channels. Optimized diskio data read subroutines. added diskio.f_read_all()
This commit is contained in:
parent
ca83092aed
commit
b6fa361bcc
@ -201,7 +201,7 @@ close_end:
|
|||||||
f_close()
|
f_close()
|
||||||
|
|
||||||
c64.SETNAM(strlen(filenameptr), filenameptr)
|
c64.SETNAM(strlen(filenameptr), filenameptr)
|
||||||
c64.SETLFS(11, drivenumber, 0)
|
c64.SETLFS(11, drivenumber, 3)
|
||||||
void c64.OPEN() ; open 11,8,0,"filename"
|
void c64.OPEN() ; open 11,8,0,"filename"
|
||||||
if_cc {
|
if_cc {
|
||||||
iteration_in_progress = true
|
iteration_in_progress = true
|
||||||
@ -221,15 +221,28 @@ close_end:
|
|||||||
|
|
||||||
uword actual = 0
|
uword actual = 0
|
||||||
void c64.CHKIN(11) ; use #11 as input channel again
|
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 {
|
repeat num_bytes {
|
||||||
ubyte data = c64.CHRIN()
|
%asm {{
|
||||||
@(bufferpointer) = data
|
jsr c64.CHRIN
|
||||||
bufferpointer++
|
_in_buffer sta $ffff
|
||||||
actual++
|
inc _in_buffer+1
|
||||||
ubyte status = c64.READST()
|
bne +
|
||||||
if status==64
|
inc _in_buffer+2
|
||||||
|
+ inc actual
|
||||||
|
bne +
|
||||||
|
inc actual+1
|
||||||
|
+
|
||||||
|
}}
|
||||||
|
ubyte data = c64.READST()
|
||||||
|
if data==64
|
||||||
f_close() ; end of file, close it
|
f_close() ; end of file, close it
|
||||||
if status
|
if data
|
||||||
return actual
|
return actual
|
||||||
}
|
}
|
||||||
return actual
|
return actual
|
||||||
@ -242,11 +255,56 @@ close_end:
|
|||||||
return
|
return
|
||||||
|
|
||||||
void c64.CHKIN(11) ; use #11 as input channel again
|
void c64.CHKIN(11) ; use #11 as input channel again
|
||||||
repeat num_bytes {
|
; repeat num_bytes {
|
||||||
@(bufferpointer) = c64.CHRIN()
|
; @(bufferpointer) = c64.CHRIN()
|
||||||
bufferpointer++
|
; 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() {
|
sub f_close() {
|
||||||
; -- end an iterative file loading session (close channels).
|
; -- end an iterative file loading session (close channels).
|
||||||
|
@ -1080,6 +1080,7 @@ _loop_hi ldy _index_first
|
|||||||
|
|
||||||
func_exit .proc
|
func_exit .proc
|
||||||
; -- immediately exit the program with a return code in the A register
|
; -- immediately exit the program with a return code in the A register
|
||||||
|
jsr c64.CLRCHN ; reset i/o channels
|
||||||
ldx orig_stackpointer
|
ldx orig_stackpointer
|
||||||
txs
|
txs
|
||||||
rts ; return to original caller
|
rts ; return to original caller
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
%import test_stack
|
%import test_stack
|
||||||
%import textio
|
%import textio
|
||||||
|
%import diskio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
@ -7,7 +8,84 @@ main {
|
|||||||
|
|
||||||
sub start () {
|
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()
|
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')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user