added diskio.f_readline()

This commit is contained in:
Irmen de Jong 2021-01-10 05:04:56 +01:00
parent 1ef9b8be61
commit db314ed903
3 changed files with 60 additions and 69 deletions

View File

@ -51,7 +51,7 @@ io_error:
c64.CLRCHN() ; restore default i/o devices c64.CLRCHN() ; restore default i/o devices
c64.CLOSE(13) c64.CLOSE(13)
if status and status != 64 { ; 64=end of file if status and status != 64 { ; 64=end of file TODO only check bit 6 instead of value
txt.print("\ni/o error, status: ") txt.print("\ni/o error, status: ")
txt.print_ub(status) txt.print_ub(status)
txt.nl() txt.nl()
@ -97,7 +97,7 @@ io_error:
return files_found return files_found
} }
; ----- iterative file lister functions ----- ; ----- iterative file lister functions (uses io channel 12) -----
sub lf_start_list(ubyte drivenumber, uword pattern_ptr) -> ubyte { sub lf_start_list(ubyte drivenumber, uword pattern_ptr) -> ubyte {
; -- start an iterative file listing with optional pattern matching. ; -- start an iterative file listing with optional pattern matching.
@ -198,7 +198,7 @@ close_end:
} }
; ----- iterative file loader functions ----- ; ----- iterative file loader functions (uses io channel 11) -----
sub f_open(ubyte drivenumber, uword filenameptr) -> ubyte { sub f_open(ubyte drivenumber, uword filenameptr) -> ubyte {
; -- open a file for iterative reading with f_read ; -- open a file for iterative reading with f_read
@ -258,8 +258,8 @@ _in_buffer sta $ffff
inc list_blocks+1 inc list_blocks+1
+ +
}} }}
first_byte = c64.READST() first_byte = c64.READST() ; TODO optimize: only check status when char was read as $0d
if first_byte==64 if first_byte==64 ; TODO only check bit 6 rather than value
f_close() ; end of file, close it f_close() ; end of file, close it
if first_byte if first_byte
return list_blocks return list_blocks
@ -270,6 +270,7 @@ _in_buffer sta $ffff
sub f_read_exact(uword bufferpointer, uword num_bytes) { sub f_read_exact(uword bufferpointer, uword num_bytes) {
; -- read from the currently open file, the given number of bytes. File must contain enough data! ; -- read from the currently open file, the given number of bytes. File must contain enough data!
; doesn't check for error conditions or end of file, to make the read as fast as possible. ; doesn't check for error conditions or end of file, to make the read as fast as possible.
; TODO get rid of this once f_read has been optimized
if not iteration_in_progress or not num_bytes if not iteration_in_progress or not num_bytes
return return
@ -337,6 +338,30 @@ _done
return list_blocks return list_blocks
} }
asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y {
; Routine to read text lines from a text file. Lines must be less than 255 characters.
; Reads characters from the input file until (and including) a newline or return character (or EOF).
; The line read will be 0-terminated in the buffer. The length of the line is returned in Y.
%asm {{
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
ldx #11
jsr c64.CHKIN ; use channel 11 again for input
ldy #0
_loop jsr c64.CHRIN
sta (P8ZP_SCRATCH_W1),y
beq _end
iny
cmp #$0a
beq _zero_end
cmp #$0d
bne _loop
_zero_end lda #0
sta (P8ZP_SCRATCH_W1),y
_end rts
}}
}
sub f_close() { sub f_close() {
; -- end an iterative file loading session (close channels). ; -- end an iterative file loading session (close channels).

View File

@ -80,7 +80,7 @@ bitmap {
offsetx = (gfx2.width - width) / 2 offsetx = (gfx2.width - width) / 2
if height < gfx2.height if height < gfx2.height
offsety = (gfx2.height - height) / 2 offsety = (gfx2.height - height) / 2
status = (not c64.READST()) or c64.READST()==64 status = (not c64.READST()) or c64.READST()==64 ; TODO only check bit 6 rather than value
} }
sub next_scanline() { sub next_scanline() {
@ -88,7 +88,7 @@ bitmap {
py++ py++
y_ok = py < gfx2.height y_ok = py < gfx2.height
gfx2.position(offsetx, offsety+py) gfx2.position(offsetx, offsety+py)
status = (not c64.READST()) or c64.READST()==64 status = (not c64.READST()) or c64.READST()==64 ; TODO only check bit 6 rather than value
} }
sub do1bpp(uword width, uword height) -> ubyte { sub do1bpp(uword width, uword height) -> ubyte {

View File

@ -1,5 +1,6 @@
%import test_stack %import test_stack
%import textio %import textio
%import diskio
%import string %import string
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit %option no_sysinit
@ -7,70 +8,35 @@
main { main {
sub start() { sub start() {
txt.print_ub(conv.any2uword("1")) if diskio.f_open(8, "romdis.asm") {
txt.chrout(':') uword buffer = memory("diskbuffer", $1000)
txt.print_uw(cx16.r0)
uword linenr = 0
c64.SETTIM(0,0,0)
while not c64.READST() {
ubyte length = diskio.f_readline(buffer)
if length {
linenr++
if not lsb(linenr)
txt.chrout('.')
} else
goto io_error
}
io_error:
txt.print("\n\n\n\n\n\n\nnumber of lines: ")
txt.print_uw(linenr)
txt.nl()
diskio.f_close()
}
txt.print(diskio.status(8))
txt.nl() txt.nl()
txt.print_ub(conv.any2uword("11")) txt.print("\ntime: ")
txt.chrout(':') txt.print_uw(c64.RDTIM16())
txt.print_uw(cx16.r0)
txt.nl() txt.nl()
txt.print_ub(conv.any2uword("12345"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("65501"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("999999999"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("%10101010"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("$ff"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("$ff99aa"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("%ff"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("abc"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword("$zzzz"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword(" 1234"))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
txt.print_ub(conv.any2uword(""))
txt.chrout(':')
txt.print_uw(cx16.r0)
txt.nl()
test_stack.test()
} }
} }