cx16: added diskio.f_fatlba()

This commit is contained in:
Irmen de Jong
2025-11-15 20:01:43 +01:00
parent 818774ab84
commit fb5290e17b
8 changed files with 104 additions and 48 deletions

View File

@@ -1027,45 +1027,60 @@ io_error:
sub f_tell() -> long, long {
; -- Returns the current read position of the opened read file, and the file size.
; Returns 0,0 if the command is not supported by the DOS implementation/version.
ubyte[2] command = ['t',0]
command[1] = READ_IO_CHANNEL ; f_open uses this secondary address
cbm.SETNAM(sizeof(command), &command)
cbm.SETLFS(15, drivenumber, 15)
void cbm.OPEN()
void cbm.CHKIN(15) ; use #15 as input channel
ubyte[3] command = ['?','?',0]
bool success=false
; valid response starts with "07," followed by hex notations of the position and filesize
if cbm.CHRIN()=='0' and cbm.CHRIN()=='7' and cbm.CHRIN()==',' {
cx16.r1 = read4hex()
cx16.r0 = read4hex() ; position in R1:R0
void cbm.CHRIN() ; separator space
cx16.r3 = read4hex()
cx16.r2 = read4hex() ; filesize in R3:R2
success = true
}
long filesize, filepos
ubyte commandoffset
while cbm.READST()==0 {
cx16.r5L = cbm.CHRIN()
if cx16.r5L=='\r' or cx16.r5L=='\n'
break
}
command[1] = 't'
commandoffset = 1
f_tell_internal()
return filepos, filesize
cbm.CLOSE(15)
reset_read_channel() ; back to the read io channel
if not success
cx16.r0 = cx16.r1 = cx16.r2 = cx16.r3 = 0
sub f_tell_internal() {
; this code is used for both the T (tell) and FL (fatlba) commands
command[2] = READ_IO_CHANNEL ; f_open uses this secondary address
cbm.SETNAM(sizeof(command)-commandoffset, &command+commandoffset)
cbm.SETLFS(15, drivenumber, 15)
void cbm.OPEN()
void cbm.CHKIN(15) ; use #15 as input channel
&long posl = &cx16.r0
&long sizel = &cx16.r2
return posl, sizel
; valid response starts with "07," followed by hex notations of the position and filesize
if cbm.CHRIN()=='0' and cbm.CHRIN()=='7' and cbm.CHRIN()==',' {
filepos = read8hex()
void cbm.CHRIN() ; separator space
filesize = read8hex()
success = true
} else {
filesize = filepos = 0
}
sub read4hex() -> uword {
str hex = "0000"
hex[0] = cbm.CHRIN()
hex[1] = cbm.CHRIN()
hex[2] = cbm.CHRIN()
hex[3] = cbm.CHRIN()
return conv.hex2uword(hex)
while cbm.READST()==0 {
cx16.r5L = cbm.CHRIN()
if cx16.r5L=='\r' or cx16.r5L=='\n'
break
}
cbm.CLOSE(15)
reset_read_channel() ; back to the read io channel
}
}
sub f_fatlba() -> long, long {
; -- Return the current LBA, cluster number (sector index and shift value are ignored for now)
diskio.f_tell.command[0] = 'f'
diskio.f_tell.command[1] = 'l'
diskio.f_tell.commandoffset = 0
diskio.f_tell.f_tell_internal()
return diskio.f_tell.filepos, diskio.f_tell.filesize
}
sub read8hex() -> long {
str hex = "00000000"
for cx16.r0L in 0 to 7 {
hex[cx16.r0L] = cbm.CHRIN()
}
return conv.hex2long(hex)
}
}

View File

@@ -113,6 +113,7 @@ conv {
ubyte[] @shared string_out
any2uword (str string @AY) -> uword @AY, ubyte @X
bin2uword (str string @AY) -> uword @AY
hex2long (str string @AY) -> long @R0R1_32
hex2uword (str string @AY) -> uword @AY
internal_byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X
internal_ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @X, ubyte @A

View File

@@ -113,6 +113,7 @@ conv {
ubyte[] @shared string_out
any2uword (str string @AY) -> uword @AY, ubyte @X
bin2uword (str string @AY) -> uword @AY
hex2long (str string @AY) -> long @R0R1_32
hex2uword (str string @AY) -> uword @AY
internal_byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X
internal_ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @X, ubyte @A

View File

@@ -151,6 +151,7 @@ conv {
ubyte[] @shared string_out
any2uword (str string @AY) -> uword @AY, ubyte @X
bin2uword (str string @AY) -> uword @AY
hex2long (str string @AY) -> long @R0R1_32
hex2uword (str string @AY) -> uword @AY
internal_byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X
internal_ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @X, ubyte @A
@@ -230,20 +231,20 @@ diskio {
exists (str filename) -> bool
f_close ()
f_close_w ()
f_fatlba () -> long, long
f_open (str filenameptr) -> bool
f_open_w (str filename) -> bool
f_open_w_seek (str filename) -> bool
f_read (uword bufferpointer, uword num_bytes) -> uword
f_read_all (uword bufferpointer) -> uword
f_readline (^^ubyte bufptr @AY) clobbers (X) -> ubyte @Y, ubyte @A
f_seek (uword pos_hiword, uword pos_loword)
f_seek_w (uword pos_hiword, uword pos_loword)
f_tell () -> uword @R0, uword @R1, uword @R2, uword @R3
f_seek (long position)
f_seek_w (long position)
f_tell () -> long, long
f_write (uword bufferpointer, uword num_bytes) -> bool
fastmode (ubyte mode) -> bool
get_loadaddress (str filename) -> uword
internal_f_open_w (str filename, bool open_for_seeks) -> bool
internal_f_tell ()
internal_load_routine (str filenameptr, uword address_override, bool headerless) -> uword
internal_save_routine (str filenameptr, uword startaddress, uword savesize, bool headerless) -> bool
lf_end_list ()
@@ -257,7 +258,7 @@ diskio {
load_size (ubyte startbank, uword startaddress, uword endaddress) -> long
loadlib (str libnameptr, uword libaddress) -> uword
mkdir (str name)
read4hex () -> uword
read8hex () -> long
relabel (str name)
rename (str oldfileptr, str newfileptr)
reset_read_channel ()
@@ -851,13 +852,17 @@ cx16 {
const ubyte EXTAPI16_stack_pop
const ubyte EXTAPI16_stack_push
const ubyte EXTAPI16_test
const ubyte EXTAPI_blink_enable
const ubyte EXTAPI_clear_status
const ubyte EXTAPI_cursor_blink
const ubyte EXTAPI_default_palette
const ubyte EXTAPI_getlfs
const ubyte EXTAPI_has_machine_property
const ubyte EXTAPI_iso_cursor_char
const ubyte EXTAPI_joystick_ps2_keycodes
const ubyte EXTAPI_kbd_leds
const ubyte EXTAPI_kbdbuf_clear
const ubyte EXTAPI_kbdbuf_get
const ubyte EXTAPI_led_update
const ubyte EXTAPI_memory_decompress_from_func
const ubyte EXTAPI_mouse_set_position
@@ -1157,6 +1162,7 @@ cx16 {
bas_psgnote (ubyte voice @A, ubyte note @X, ubyte fracsemitone @Y) clobbers (A,X,Y) -> bool @Pc @bank 10 = $c012
bas_psgplaystring (ubyte length @A, str string @XY) clobbers (A,X,Y) @bank 10 = $c018
bas_psgwav (ubyte voice @A, ubyte waveform @X) clobbers (A,X,Y) -> bool @Pc @bank 10 = $c015
blink_enable (bool enable @X) clobbers (A,X)
clock_get_date_time () clobbers (A,X,Y) -> uword @R0, uword @R1, uword @R2, uword @R3 = $ff50
clock_set_date_time (uword yearmonth @R0, uword dayhours @R1, uword minsecs @R2, uword jiffiesweekday @R3) clobbers (A,X,Y) = $ff4d
console_get_char () clobbers (X,Y) -> ubyte @A = $fee1
@@ -1179,6 +1185,7 @@ cx16 {
getlfs () -> ubyte @X, ubyte @A, ubyte @Y
getrambank () -> ubyte @A
getrombank () -> ubyte @A
has_machine_property (ubyte property @X) clobbers (A,X) -> bool @Pc
i2c_batch_read (ubyte device @X, uword buffer @R0, uword length @R1, bool advance @Pc) clobbers (A,Y) -> bool @Pc = $feb4
i2c_batch_write (ubyte device @X, uword buffer @R0, uword length @R1, bool advance @Pc) clobbers (A,Y) -> bool @Pc = $feb7
i2c_read_byte (ubyte device @X, ubyte offset @Y) clobbers (X,Y) -> ubyte @A, bool @Pc = $fec6
@@ -1188,6 +1195,8 @@ cx16 {
joystick_scan () clobbers (A,X,Y) = $ff53
joysticks_detect () -> ubyte
joysticks_getall (bool also_keyboard_js) -> uword
kbdbuf_clear () clobbers (A)
kbdbuf_get () clobbers (X,Y) -> ubyte @A
kbdbuf_get_modifiers () -> ubyte @A = $fec0
kbdbuf_peek () -> ubyte @A, ubyte @X = $febd
kbdbuf_put (ubyte key @A) clobbers (X) = $fec3

View File

@@ -113,6 +113,7 @@ conv {
ubyte[] @shared string_out
any2uword (str string @AY) -> uword @AY, ubyte @X
bin2uword (str string @AY) -> uword @AY
hex2long (str string @AY) -> long @R0R1_32
hex2uword (str string @AY) -> uword @AY
internal_byte2decimal (byte value @A) -> ubyte @Y, ubyte @A, ubyte @X
internal_ubyte2decimal (ubyte value @A) -> ubyte @Y, ubyte @X, ubyte @A
@@ -553,7 +554,7 @@ txt {
scroll_left () clobbers (A,X,Y)
scroll_right () clobbers (A,X)
scroll_up () clobbers (A,X)
setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor)
setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor)
setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers (A,Y)
setclr (ubyte col, ubyte row, ubyte color)
size () clobbers (A) -> ubyte @X, ubyte @Y

View File

@@ -89,6 +89,7 @@ conv {
str string_out
any2uword (str string) -> uword, ubyte
bin2uword (str string) -> uword
hex2long (str string) -> long
hex2uword (str string) -> uword
internal_str_ub (ubyte value, str out_ptr)
internal_str_uw (uword value, str out_ptr)

View File

@@ -1,11 +1,39 @@
%import diskio
%import textio
%zeropage basicsafe
main {
sub start() {
const long buffer = 2000
const long bufferl = 999999
uword @shared addr = &buffer[2]
long @shared addr2 = &bufferl[2]
const long width = 100
uword @shared addr3 = &buffer[width]
long @shared addr4 = &bufferl[width]
void diskio.f_open("t8s.wav")
long size, pos
pos, size = diskio.f_tell()
txt.print_l(pos)
txt.spc()
txt.print_l(size)
txt.nl()
diskio.f_seek(999999)
pos, size = diskio.f_tell()
txt.print_l(pos)
txt.spc()
txt.print_l(size)
txt.nl()
long lba, cluster
lba, cluster = diskio.f_fatlba()
txt.print_l(lba)
txt.spc()
txt.print_l(cluster)
txt.nl()
diskio.f_seek(0)
lba, cluster = diskio.f_fatlba()
txt.print_l(lba)
txt.spc()
txt.print_l(cluster)
txt.nl()
diskio.f_close()
}
}

View File

@@ -4,4 +4,4 @@ org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configuration-cache=false
kotlin.code.style=official
version=12.0-BETA6
version=12.0-BETA7