From 0349d1d57cc217dcef87e6e35486d468dfb8a22a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 4 Jun 2022 00:25:17 +0200 Subject: [PATCH] diskio: moved cx16 optimized f_read() to cx16diskio instead so unfortunately you have to select the faster version yourself when on cx16 --- compiler/res/prog8lib/cx16/cx16diskio.p8 | 96 ++++++++++++++++++++++++ compiler/res/prog8lib/diskio.p8 | 22 ------ docs/source/todo.rst | 2 - 3 files changed, 96 insertions(+), 24 deletions(-) diff --git a/compiler/res/prog8lib/cx16/cx16diskio.p8 b/compiler/res/prog8lib/cx16/cx16diskio.p8 index 071ff70ec..3730a4c0a 100644 --- a/compiler/res/prog8lib/cx16/cx16diskio.p8 +++ b/compiler/res/prog8lib/cx16/cx16diskio.p8 @@ -71,4 +71,100 @@ cx16diskio { }} } + + ; replacement function that makes use of fast block read capability of the X16 + ; use this in place of regular diskio.f_read() + sub f_read(uword bufferpointer, uword num_bytes) -> uword { + ; -- read from the currently open file, up to the given number of bytes. + ; returns the actual number of bytes read. (checks for End-of-file and error conditions) + if not diskio.iteration_in_progress or not num_bytes + return 0 + + diskio.list_blocks = 0 ; we reuse this variable for the total number of bytes read + if diskio.have_first_byte { + diskio.have_first_byte=false + @(bufferpointer) = diskio.first_byte + bufferpointer++ + diskio.list_blocks++ + num_bytes-- + } + + void c64.CHKIN(11) ; use #11 as input channel again + + ; commander X16 supports fast block-read via macptr() kernal call + uword size + while num_bytes { + size = 255 + if num_bytes uword { + ; -- read the full contents of the file, returns number of bytes read. + if not diskio.iteration_in_progress + return 0 + + uword total_read = 0 + if diskio.have_first_byte { + diskio.have_first_byte=false + @(bufferpointer) = diskio.first_byte + bufferpointer++ + total_read = 1 + } + + while not c64.READST() { + uword size = cx16diskio.f_read(bufferpointer, 256) + total_read += size + bufferpointer += size + } + return total_read + } + } diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 9c11a994b..bbb512c63 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -240,28 +240,6 @@ close_end: void c64.CHKIN(11) ; use #11 as input channel again - if sys.target==16 { - ; commander X16 supports fast block-read via macptr() kernal call - uword size - while num_bytes { - size = 255 - if num_bytes