mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
added diskio.f_readline()
This commit is contained in:
parent
1ef9b8be61
commit
db314ed903
@ -51,7 +51,7 @@ io_error:
|
||||
c64.CLRCHN() ; restore default i/o devices
|
||||
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_ub(status)
|
||||
txt.nl()
|
||||
@ -97,7 +97,7 @@ io_error:
|
||||
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 {
|
||||
; -- 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 {
|
||||
; -- open a file for iterative reading with f_read
|
||||
@ -258,8 +258,8 @@ _in_buffer sta $ffff
|
||||
inc list_blocks+1
|
||||
+
|
||||
}}
|
||||
first_byte = c64.READST()
|
||||
if first_byte==64
|
||||
first_byte = c64.READST() ; TODO optimize: only check status when char was read as $0d
|
||||
if first_byte==64 ; TODO only check bit 6 rather than value
|
||||
f_close() ; end of file, close it
|
||||
if first_byte
|
||||
return list_blocks
|
||||
@ -270,6 +270,7 @@ _in_buffer sta $ffff
|
||||
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!
|
||||
; 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
|
||||
return
|
||||
|
||||
@ -337,6 +338,30 @@ _done
|
||||
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() {
|
||||
; -- end an iterative file loading session (close channels).
|
||||
|
@ -80,7 +80,7 @@ bitmap {
|
||||
offsetx = (gfx2.width - width) / 2
|
||||
if height < gfx2.height
|
||||
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() {
|
||||
@ -88,7 +88,7 @@ bitmap {
|
||||
py++
|
||||
y_ok = py < gfx2.height
|
||||
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 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
%import test_stack
|
||||
%import textio
|
||||
%import diskio
|
||||
%import string
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
@ -7,70 +8,35 @@
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
txt.print_ub(conv.any2uword("1"))
|
||||
txt.chrout(':')
|
||||
txt.print_uw(cx16.r0)
|
||||
if diskio.f_open(8, "romdis.asm") {
|
||||
uword buffer = memory("diskbuffer", $1000)
|
||||
|
||||
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.print_ub(conv.any2uword("11"))
|
||||
txt.chrout(':')
|
||||
txt.print_uw(cx16.r0)
|
||||
txt.print("\ntime: ")
|
||||
txt.print_uw(c64.RDTIM16())
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user