removed diskio.f_read_exact() - wasn't worth it over f_read()

This commit is contained in:
Irmen de Jong 2021-01-10 14:29:51 +01:00
parent db314ed903
commit 9fc0c3f849
3 changed files with 25 additions and 71 deletions

View File

@ -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 TODO only check bit 6 instead of value
if status and status & $40 == 0 { ; bit 6=end of file
txt.print("\ni/o error, status: ")
txt.print_ub(status)
txt.nl()
@ -249,6 +249,7 @@ close_end:
repeat num_bytes {
%asm {{
jsr c64.CHRIN
sta cx16.r5
_in_buffer sta $ffff
inc _in_buffer+1
bne +
@ -258,66 +259,18 @@ _in_buffer sta $ffff
inc list_blocks+1
+
}}
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
if cx16.r5==$0d { ; chance on I/o error status?
first_byte = c64.READST()
if first_byte & $40
f_close() ; end of file, close it
if first_byte
return list_blocks
}
}
return list_blocks
}
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
if have_first_byte {
have_first_byte=false
@(bufferpointer) = first_byte
bufferpointer++
num_bytes--
}
void c64.CHKIN(11) ; use #11 as input channel again
; repeat num_bytes {
; @(bufferpointer) = c64.CHRIN()
; 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

View File

@ -41,7 +41,7 @@ iff_module {
while read_chunk_header() {
if chunk_id == "bmhd" {
diskio.f_read_exact(buffer, chunk_size_lo)
void diskio.f_read(buffer, chunk_size_lo)
width = mkword(buffer[0], buffer[1])
height = mkword(buffer[2], buffer[3])
num_planes = buffer[8]
@ -49,7 +49,7 @@ iff_module {
compression = buffer[10]
}
else if chunk_id == "camg" {
diskio.f_read_exact(buffer, chunk_size_lo)
void diskio.f_read(buffer, chunk_size_lo)
camg = mkword(buffer[2], buffer[3])
if camg & $0800 {
txt.print("ham mode not supported!\n")
@ -58,13 +58,13 @@ iff_module {
}
else if chunk_id == "cmap" {
have_cmap = true
diskio.f_read_exact(cmap, chunk_size_lo)
void diskio.f_read(cmap, chunk_size_lo)
}
else if chunk_id == "crng" {
; DeluxePaint color cycle range
if not cycle_ccrt {
cycle_crng = true
diskio.f_read_exact(buffer, chunk_size_lo)
void diskio.f_read(buffer, chunk_size_lo)
ubyte flags = buffer[5]
if flags & 1 {
cycle_rates[num_cycles] = mkword(buffer[2], buffer[3])
@ -81,7 +81,7 @@ iff_module {
; Graphicraft color cycle range
if not cycle_crng {
cycle_ccrt = true
diskio.f_read_exact(buffer, chunk_size_lo)
void diskio.f_read(buffer, chunk_size_lo)
ubyte direction = buffer[1]
if direction {
; delay_sec = buffer[4] * 256 * 256 * 256 + buffer[5] * 256 * 256 + buffer[6] * 256 + buffer[7]
@ -142,9 +142,9 @@ iff_module {
sub skip_chunk() {
repeat lsb(chunk_size_hi)*8 + (chunk_size_lo >> 13)
diskio.f_read_exact(scanline_data_ptr, $2000)
void diskio.f_read(scanline_data_ptr, $2000)
diskio.f_read_exact(scanline_data_ptr, chunk_size_lo & $1fff)
void diskio.f_read(scanline_data_ptr, chunk_size_lo & $1fff)
}
sub make_ehb_palette() {
@ -189,9 +189,9 @@ iff_module {
ubyte interlaced = (camg & $0004) != 0
uword y
for y in 0 to height-1 {
diskio.f_read_exact(scanline_data_ptr, interleave_stride)
void diskio.f_read(scanline_data_ptr, interleave_stride)
if interlaced
diskio.f_read_exact(scanline_data_ptr, interleave_stride)
void diskio.f_read(scanline_data_ptr, interleave_stride)
gfx2.position(offsetx, offsety+y)
planar_to_chunky_scanline()
}

View File

@ -11,11 +11,12 @@ koala_module {
if diskio.f_open(8, filenameptr) {
uword size = diskio.f_read(load_location, 2) ; skip the first 2 bytes (load address)
if size==2 {
diskio.f_read_exact(load_location, 10001)
; set a better C64 color palette, the Cx16's default is too saturated
palette.set_c64pepto()
convert_koalapic()
load_ok = true
if diskio.f_read(load_location, 10001)==10001 {
; set a better C64 color palette, the Cx16's default is too saturated
palette.set_c64pepto()
convert_koalapic()
load_ok = true
}
}
diskio.f_close()
}