5

I have a simple program on my Apple IIc written in assembly language. It starts by getting a filename from the user (just the file name, not the full path), then it opens the corresponding file with a MLI call ($C8). To my suprise, the MLI call returned error $40: "Pathname has invalid syntax". I have checked all parameters, but they where OK. I have tried to type PREFIX /myvolume before starting my program. And this time, it worked! (The file was opened without any error.) I understood that when you start ProDOS (just PRODOS and BASIC.SYSTEM), then the prefix is empty. I have checked it, by replacing the open MLI call by a get_prefix call. And yes, the prefix length is 0.

Did you know that? Until then, I believed that the prefix was set to the root prefix of the booting disk by the system at boot.

For the story, reading here and there, I have found a workaround by reading the path of the running program (my program in that case) at memory address $280, and calling set_prefix to that path. A lot of assembly lines. My assembly program and the file to read have the same prefix (same directory).

Can you confirm my analysis?

1
  • 3
    Would you mind adding some information like the file/pathnames used, ProDOS Version, what kind of drives and if its a real IIc or an emulation?
    – Raffzahn
    Feb 10, 2021 at 11:18

3 Answers 3

8

Unlike the current directory on modern operating systems, ProDOS's "prefix" can be empty, and when it is, you have to specify the full path to files you want to work with. It actually is empty at boot (well, BASIC.System clears it). It was a common practice to detect an empty prefix at startup and get the volume name of the last accessed disk and set the prefix to that.

BASIC.System uses the empty prefix as a sort of flag to emulate DOS 3.3's slot and drive specifications. If the prefix is not set, then BASIC.System tracks the last-specified device by slot and drive, and if you don't specify some other way of locating the file, it fetches the volume name in that drive and adds that to the beginning of the specified path. Note that in BASIC.System you can reset the prefix to empty with PREFIX /.

1
3

Extending on @kindall's answer, here's some sample code to deal with that problem:

-   jsr    $bf00
op_c7
    !byte  $c7
    !word  c7_parms
    ldx    $300
    bne    +
    lda    $bf30
    sta    c5_parms+1
    jsr    $bf00
    !byte  $c5
    !word  c5_parms
    lda    $301
    and    #$0f
    tax
    inx
    stx    $300
    lda    #$2f
    sta    $301
    dec    op_c7
    bne    -

c7_parms
    !byte  1
    !word  $300

c5_parms
    !byte  2
    !byte  0
    !word  $301

+

It works by querying for the prefix, and if it's empty it sets the prefix to the current volume name. It assembles with ACME, but it's trivial to change for Merlin.

1
  • 1
    This uses DEVNUM ($BF30), which is the last-accessed unit number. If you're working within BASIC.SYSTEM - e.g. in an external command - you can better match the BI's logic by using DEFSLT ($BE3C) and DEFDRV ($BE3D) on the BI Global Page to construct a unit number. For example, CAT RAM will update DEVNUM but not DEFSLT or DEFDRV. In contrast CAT,S3,D2 will update all 3. (If you're implementing an extended command that takes a single filename, setting the SD flag in PBITS+1 automatically corrects VPATH1. But this fails if you're consuming two filenames, so you need to do it manually.) Apr 15, 2021 at 3:28
0

Error $40 means

$40 Invalid pathname syntax. The pathname contains illegal characters.

So it might be helpful to see what names are used. Programmers comming from a DOS environment often add unnecessary slashes

The ProDOS 8 Technical Reference Manual says at page 53 SET_PREFIX:

When ProDOS is started up, the system prefix is set to the name of the volume in the startup drive.

So, the question might be is there a volume name?

To see what volumes are online an ON_LINE MLI call is rather helpful. Best done with the ProDOS Machine Language Exerciser - saves a lot of programming while learning how Prodos Works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .