Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cc65: file I/O on external drive?

39 views
Skip to first unread message

Colin Leroy-Mira

unread,
Aug 10, 2023, 9:31:35 AM8/10/23
to
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/

mmphosis

unread,
Aug 10, 2023, 11:01:52 AM8/10/23
to
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);





Colin Leroy-Mira

unread,
Aug 10, 2023, 12:03:20 PM8/10/23
to
Hi,
Thanks, I had missed those! This is really helpful.

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

Colin Leroy-Mira

unread,
Aug 10, 2023, 12:22:31 PM8/10/23
to
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/

Oliver Schmidt

unread,
Aug 10, 2023, 4:08:03 PM8/10/23
to
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

Colin Leroy-Mira

unread,
Aug 11, 2023, 6:07:23 AM8/11/23
to
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/

Oliver Schmidt

unread,
Aug 11, 2023, 7:31:38 AM8/11/23
to
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

0 new messages