fix diskio.diskname(). cx16: add diskio.curdir()

This commit is contained in:
Irmen de Jong 2023-06-07 22:31:46 +02:00
parent 7ee162d98b
commit ba25b7fee6
7 changed files with 118 additions and 48 deletions

View File

@ -73,39 +73,42 @@ io_error:
}
sub diskname() -> uword {
; -- Returns pointer to disk name string or 0 if failure.
cbm.SETNAM(1, "$")
cbm.SETLFS(12, drivenumber, 0)
ubyte okay = false
void cbm.OPEN() ; open 12,8,0,"$"
; returns disk label name or 0 if error
cbm.SETNAM(3, "$")
cbm.SETLFS(12, diskio.drivenumber, 0)
ubyte status = 1
void cbm.OPEN() ; open 12,8,0,"$=c"
if_cs
goto io_error
void cbm.CHKIN(12) ; use #12 as input channel
if_cs
goto io_error
repeat 6 {
void cbm.CHRIN() ; skip the 6 prologue bytes
while cbm.CHRIN()!='"' {
; skip up to entry name
}
if cbm.READST()!=0
goto io_error
cx16.r0 = &list_filename
cx16.r0 = &diskio.list_filename
repeat {
@(cx16.r0) = cbm.CHRIN()
if @(cx16.r0)==0
if @(cx16.r0)=='"' {
@(cx16.r0) = ' '
while @(cx16.r0)==' ' and cx16.r0>=&diskio.list_filename {
@(cx16.r0) = 0
cx16.r0--
}
break
}
cx16.r0++
}
okay = true
status = cbm.READST()
io_error:
cbm.CLRCHN() ; restore default i/o devices
cbm.CLRCHN()
cbm.CLOSE(12)
if okay
return &list_filename
if status and status & $40 == 0
return 0
return diskio.list_filename
}
; internal variables for the iterative file lister / loader
@ -684,6 +687,75 @@ internal_vload:
send_command(list_filename)
}
sub curdir() -> uword {
; return current directory name or 0 if error
; special X16 dos command to only return the current path in the entry list (R42+)
const ubyte MAX_PATH_LEN=80
uword reversebuffer = memory("curdir_buffer", MAX_PATH_LEN, 0)
cx16.r12 = reversebuffer + MAX_PATH_LEN-1
@(cx16.r12)=0
cbm.SETNAM(3, "$=c")
cbm.SETLFS(12, diskio.drivenumber, 0)
void cbm.OPEN() ; open 12,8,0,"$=c"
if_cs
goto io_error
void cbm.CHKIN(12) ; use #12 as input channel
if_cs
goto io_error
repeat 6 {
void cbm.CHRIN()
}
while cbm.CHRIN() {
; skip first line (drive label)
}
while cbm.CHRIN()!='"' {
; skip to first name
}
ubyte status = cbm.READST()
cx16.r10 = &list_filename
while status==0 {
repeat {
@(cx16.r10) = cbm.CHRIN()
if @(cx16.r10)==0
break
cx16.r10++
}
while @(cx16.r10)!='"' and cx16.r10>=&list_filename {
@(cx16.r10)=0
cx16.r10--
}
@(cx16.r10)=0
prepend(list_filename)
cx16.r10 = &list_filename
while cbm.CHRIN()!='"' and status==0 {
status = cbm.READST()
; skipping up to next entry name
}
}
io_error:
cbm.CLRCHN()
cbm.CLOSE(12)
if status and status & $40 == 0
return 0
if @(cx16.r12)==0 {
cx16.r12--
@(cx16.r12)='/'
}
return cx16.r12
sub prepend(str dir) {
if dir[0]=='/' and dir[1]==0
return
cx16.r9L = string.length(dir)
cx16.r12 -= cx16.r9L
sys.memcopy(dir, cx16.r12, cx16.r9L)
cx16.r12--
@(cx16.r12)='/'
}
}
sub relabel(str name) {
; -- change the disk label.
list_filename[0] = 'r'

View File

@ -84,8 +84,8 @@ io_error:
if_cs
goto io_error
repeat 6 {
void cbm.CHRIN() ; skip the 6 prologue bytes
while cbm.CHRIN()!='"' {
; skip up to entry name
}
if cbm.READST()!=0
goto io_error
@ -93,8 +93,14 @@ io_error:
cx16.r0 = &list_filename
repeat {
@(cx16.r0) = cbm.CHRIN()
if @(cx16.r0)==0
if @(cx16.r0)=='"' {
@(cx16.r0) = ' '
while @(cx16.r0)==' ' and cx16.r0>=&diskio.list_filename {
@(cx16.r0) = 0
cx16.r0--
}
break
}
cx16.r0++
}
okay = true

View File

@ -0,0 +1 @@
; there is no diskio yet for the VM target.

View File

@ -1 +1 @@
9.0
9.1-dev

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (py3)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +1,14 @@
TODO
====
- c64 fix diskio.diskname
- fix undefined symbol error for sub curdir() -> str { return "todo" }
- fix placeholder error for
str result = "todo" , sub curdir() -> str { return result }
- document some library modules better (diskio, etc)
...

View File

@ -1,34 +1,17 @@
%import textio
%import diskio
%zeropage basicsafe
main {
sub start() {
str name1 = "name1"
str name2 = "name2"
uword[] @split names = [name1, name2, "name3"]
uword ww
; for ww in names {
; txt.print(ww)
; txt.spc()
; }
; txt.nl()
ubyte idx=1
names[idx] = $20ff
txt.print_uwhex(names[1], true)
names[idx]++
txt.print_uwhex(names[1], true)
names[idx]--
txt.print_uwhex(names[1], true)
names = [1111,2222,3333]
for ww in names {
txt.print_uw(ww)
txt.spc()
}
txt.nl()
txt.print("end.")
txt.print("pwd: ")
txt.print(diskio.curdir())
txt.print("\ndisk name: ")
uword name = diskio.diskname()
if name
txt.print(name)
else
txt.print("!error!")
}
}