• cc65: file I/O on external drive?

    From Colin Leroy-Mira@21:1/5 to All on Thu Aug 10 15:31:28 2023
    Hi there,

    I've - finally - found an external disk drive for my Apple //c! And I'd
    like to make use of it on my own cc65-based projects.

    From what I see, there's no helper in place to select a device before
    fopen, opendir or anything. Could someone point me in the right
    direction?

    Thanks!
    --
    Colin
    https://www.colino.net/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mmphosis@21:1/5 to All on Thu Aug 10 15:01:50 2023
    I thought that the slot and drive would be specified in the pathname. For example: FILE,S6,D1 but maybe not. There is a low level DEV_NUM and I found these device.h helper functions...

    https://cc65.github.io/doc/funcref.html#ss2.20

    unsigned char getfirstdevice (void);
    unsigned char __fastcall__ getnextdevice (unsigned char device);
    unsigned char getcurrentdevice (void);

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Colin Leroy-Mira@21:1/5 to All on Thu Aug 10 18:03:15 2023
    Hi,

    I thought that the slot and drive would be specified in the pathname.
    For example: FILE,S6,D1 but maybe not. There is a low level DEV_NUM
    and I found these device.h helper functions...

    https://cc65.github.io/doc/funcref.html#ss2.20

    unsigned char getfirstdevice (void);
    unsigned char __fastcall__ getnextdevice (unsigned char device);
    unsigned char getcurrentdevice (void);

    Thanks, I had missed those! This is really helpful.

    --
    Colin
    https://www.colino.net/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Colin Leroy-Mira@21:1/5 to All on Thu Aug 10 18:22:25 2023
    Hi,

    I thought that the slot and drive would be specified in the pathname.
    For example: FILE,S6,D1 but maybe not. There is a low level DEV_NUM
    and I found these device.h helper functions...

    https://cc65.github.io/doc/funcref.html#ss2.20

    unsigned char getfirstdevice (void);
    unsigned char __fastcall__ getnextdevice (unsigned char device);
    unsigned char getcurrentdevice (void);

    This is in fact extremely easy: you just fopen("/PREFIX/FILENAME") and
    it finds the correct drive all by itself :)
    --
    Colin
    https://www.colino.net/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Schmidt@21:1/5 to All on Thu Aug 10 20:08:01 2023
    Hi Colin,

    This is in fact extremely easy: you just fopen("/PREFIX/FILENAME") and
    it finds the correct drive all by itself :)

    Yes, ProDOS is about volumes and paths, not about slots and drives.

    However, if you have to access a certain drive then the way to do it
    is this:

    1. Calculate the device number according to the formula
    device = slot + (drive - 1) * 8
    (https://cc65.github.io/doc/apple2.html#ss9)

    2. Call getdevicedir() with the device from 1. (https://cc65.github.io/doc/funcref.html#ss3.135)

    3. Construct an absolute path from 2. or call chdir() with 2.

    If you want to return where you've been before calling chdir(), you
    can call getcwd() before chdir().

    In general, you might want to have a look at https://github.com/cc65/cc65/blob/master/samples/enumdevdir.c

    Regards,
    Oliver

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Colin Leroy-Mira@21:1/5 to All on Fri Aug 11 12:07:18 2023
    Hi Oliver,

    Yes, ProDOS is about volumes and paths, not about slots and drives.
    [...]
    In general, you might want to have a look at >https://github.com/cc65/cc65/blob/master/samples/enumdevdir.c

    Thanks! Grepping from mmphosis' pointed me to this file, and it helped
    a lot. I now have a functional multi-device file selector :

    https://piaille.fr/@colin_mcmillen/110870419691108842

    --
    Colin
    https://www.colino.net/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Schmidt@21:1/5 to All on Fri Aug 11 11:31:35 2023
    Hi Colin,

    https://github.com/cc65/cc65/blob/master/samples/enumdevdir.c

    Thanks! Grepping from mmphosis' pointed me to this file, and it helped
    a lot. I now have a functional multi-device file selector

    Yes, an interactive file selector was more less the use case I had in mind
    when developing the functionality (and the sample) :-)

    Regards,
    Oliver

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)