diff --git a/compiler/res/prog8lib/cx16/diskio.p8 b/compiler/res/prog8lib/cx16/diskio.p8 index 5f2bfd950..60a7b8e42 100644 --- a/compiler/res/prog8lib/cx16/diskio.p8 +++ b/compiler/res/prog8lib/cx16/diskio.p8 @@ -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 - return 0 + 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' diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 792c68ba8..d3fbbefad 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -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 diff --git a/compiler/res/prog8lib/virtual/diskio.p8 b/compiler/res/prog8lib/virtual/diskio.p8 new file mode 100644 index 000000000..4583a7fcc --- /dev/null +++ b/compiler/res/prog8lib/virtual/diskio.p8 @@ -0,0 +1 @@ +; there is no diskio yet for the VM target. diff --git a/compiler/res/version.txt b/compiler/res/version.txt index dd98ee6cb..e518ae312 100644 --- a/compiler/res/version.txt +++ b/compiler/res/version.txt @@ -1 +1 @@ -9.0 +9.1-dev diff --git a/docs/docs.iml b/docs/docs.iml index d5a201713..9f467ff8c 100644 --- a/docs/docs.iml +++ b/docs/docs.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 7e04dc0cf..9459abc06 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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) + ... diff --git a/examples/test.p8 b/examples/test.p8 index 92a7124b9..f46f5a0f8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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!") } } -