added diskio.f_read_exact()

This commit is contained in:
Irmen de Jong 2020-12-24 06:24:52 +01:00
parent 45bfecee73
commit e0d2b60d8b
4 changed files with 43 additions and 20 deletions

View File

@ -227,13 +227,15 @@ close_end:
return false return false
} }
sub f_read(uword bufferpointer, uword buffersize) -> uword { 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 iteration_in_progress if not iteration_in_progress
return 0 return 0
uword actual = 0 uword actual = 0
void c64.CHKIN(11) ; use #11 as input channel again void c64.CHKIN(11) ; use #11 as input channel again
repeat buffersize { repeat num_bytes {
ubyte data = c64.CHRIN() ubyte data = c64.CHRIN()
@(bufferpointer) = data @(bufferpointer) = data
bufferpointer++ bufferpointer++
@ -247,6 +249,19 @@ close_end:
return actual return actual
} }
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.
if not iteration_in_progress
return
void c64.CHKIN(11) ; use #11 as input channel again
repeat num_bytes {
@(bufferpointer) = c64.CHRIN()
bufferpointer++
}
}
sub f_close() { sub f_close() {
; -- end an iterative file loading session (close channels). ; -- end an iterative file loading session (close channels).
if iteration_in_progress { if iteration_in_progress {

View File

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

View File

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

View File

@ -11,14 +11,24 @@ main {
; TODO asmsub version generates LARGER CODE , why is this? ; TODO asmsub version generates LARGER CODE , why is this?
sub vpoke(ubyte bank, uword address, ubyte value) { sub vpoke(ubyte bank, uword address, ubyte value) {
%asm {{
rts
}}
} }
asmsub vpokeasm(uword address @R0, ubyte bank @A, ubyte value @Y) { asmsub vpokeasm(uword address @R0, ubyte bank @A, ubyte value @Y) {
%asm {{
rts
}}
} }
sub start () { sub start () {
txt.chrout('!') txt.chrout('!')
ubyte bank = 1
uword address = 1000
ubyte value = 123
bank++
vpoke(bank, address, value)
vpokeasm(address, bank, value)
} }
} }