From 69f953fd9b9a19353a36ba7a3c7db2555e06345b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 6 Jul 2024 22:25:01 +0200 Subject: [PATCH] diskio.f_readline() now also returns I/O status as secondary return value in A --- compiler/res/prog8lib/cx16/diskio.p8 | 9 ++++++--- compiler/res/prog8lib/diskio.p8 | 8 ++++++-- compiler/res/prog8lib/virtual/diskio.p8 | 4 +++- docs/source/todo.rst | 2 ++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/compiler/res/prog8lib/cx16/diskio.p8 b/compiler/res/prog8lib/cx16/diskio.p8 index 2a1087cf0..6b37c3b7f 100644 --- a/compiler/res/prog8lib/cx16/diskio.p8 +++ b/compiler/res/prog8lib/cx16/diskio.p8 @@ -379,6 +379,7 @@ m_in_buffer sta $ffff ; optimized for Commander X16 to use MACPTR block read kernal call sub f_read_all(uword bufferpointer) -> uword { ; -- read the full contents of the file, returns number of bytes read. + ; It is assumed the file size is less than 64 K. ; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.MACPTR() yourself with the vera data register as address. if not iteration_in_progress return 0 @@ -393,12 +394,12 @@ m_in_buffer sta $ffff return total_read } - asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y { + asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y, ubyte @A { ; Routine to read text lines from a text file. Lines must be less than 255 characters. ; Reads characters from the input file UNTIL a newline or return character (or EOF). ; The line read will be 0-terminated in the buffer (and not contain the end of line character). ; The length of the line is returned in Y. Note that an empty line is okay and is length 0! - ; I/O error status should be checked by the caller itself via READST() routine. + ; The I/O error status byte is returned in A. %asm {{ sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 @@ -415,7 +416,8 @@ _loop jsr cbm.CHRIN _line_end dey ; get rid of the trailing end-of-line char lda #0 sta (P8ZP_SCRATCH_W1),y -_end rts +_end jsr cbm.READST + rts }} } @@ -467,6 +469,7 @@ _end rts sub f_write(uword bufferpointer, uword num_bytes) -> bool { ; -- write the given number of bytes to the currently open file + ; you can call this multiple times to append more data if num_bytes!=0 { reset_write_channel() do { diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 9485497ca..a1a2b14ca 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -333,6 +333,7 @@ m_in_buffer sta $ffff sub f_read_all(uword bufferpointer) -> uword { ; -- read the full contents of the file, returns number of bytes read. + ; It is assumed the file size is less than 64 K. if not iteration_in_progress return 0 @@ -346,12 +347,13 @@ m_in_buffer sta $ffff return total_read } - asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y { + asmsub f_readline(uword bufptr @AY) clobbers(X) -> ubyte @Y, ubyte @A { ; Routine to read text lines from a text file. Lines must be less than 255 characters. ; Reads characters from the input file UNTIL a newline or return character (or EOF). ; The line read will be 0-terminated in the buffer (and not contain the end of line character). ; The length of the line is returned in Y. Note that an empty line is okay and is length 0! ; I/O error status should be checked by the caller itself via READST() routine. + ; The I/O error status byte is returned in A. %asm {{ sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 @@ -368,7 +370,8 @@ _loop jsr cbm.CHRIN _line_end dey ; get rid of the trailing end-of-line char lda #0 sta (P8ZP_SCRATCH_W1),y -_end rts +_end jsr cbm.READST + rts }} } @@ -405,6 +408,7 @@ _end rts sub f_write(uword bufferpointer, uword num_bytes) -> bool { ; -- write the given number of bytes to the currently open file + ; you can call this multiple times to append more data if num_bytes!=0 { reset_write_channel() repeat num_bytes { diff --git a/compiler/res/prog8lib/virtual/diskio.p8 b/compiler/res/prog8lib/virtual/diskio.p8 index 61a1d681d..23d67bda4 100644 --- a/compiler/res/prog8lib/virtual/diskio.p8 +++ b/compiler/res/prog8lib/virtual/diskio.p8 @@ -72,6 +72,7 @@ diskio { sub f_read_all(uword bufferpointer) -> uword { ; -- read the full contents of the file, returns number of bytes read. + ; It is assumed the file size is less than 64 K. txt.print("@TODO: f_read_all\n") return 0 } @@ -81,7 +82,7 @@ diskio { ; Reads characters from the input file UNTIL a newline or return character (or EOF). ; The line read will be 0-terminated in the buffer (and not contain the end of line character). ; The length of the line is returned in Y. Note that an empty line is okay and is length 0! - ; I/O error status should be checked by the caller itself via READST() routine. + ; This routine is not able here to return the status as well in a secondary return value, so you have to do that yourself. txt.print("@TODO: f_readline\n") return 0 } @@ -107,6 +108,7 @@ diskio { sub f_write(uword bufferpointer, uword num_bytes) -> bool { ; -- write the given number of bytes to the currently open file + ; you can call this multiple times to append more data txt.print("@TODO: f_write\n") return false } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index bb2f88d02..62accb287 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,6 +3,8 @@ TODO See open issues on github. +Re-generate the skeleons doc files. + IR: add SEC and CLC instructions in place of call to sys.set_carry() and sys.clear_carry(). (check more inline sub calls that should be a single instruction?) optimize signed byte/word division by powers of 2 (and shift right?), it's now using divmod routine. (also % ?)