Jump to content
IGNORED

Open Directory in cc65


Recommended Posts

Is there a way to open a directory in cc65, in BASIC it's easy, some demo code below, but fopen in C uses :- fd=fopen(infile,"r");

ICAUX1 need to be 2 to open a directory, not sure this is supported ?, if not any examples using assembler would help.

 

thanks

 

I just want to be able to read the directory and display the contents.

 

DIM A$(18)
5 TRAP 1000
10 OPEN #1,2,0,"D:*.DAT"
20 GET #1,A:GET #1,A : REM throw away first 2 spaces
30 GOSUB 2000
90 ? A$
100 GOTO 20
1000 CLOSE #1
1010 END
2000 A$=""
2005 FOR I=1 TO 11
2010 GET #1,A
2020 A$(LEN(A$)+1)=CHR$(A)
2100 NEXT I
2110 GET #1,A: throw away size
2120 IF A<>155 THEN 2110: rem look for end of string
2130 RETURN

outputs :-

READY
RUN
PLAYERM DAT
UFO     DAT
TEMP    DAT
SPACE   DAT
REBOUND DAT
SPRITE  DAT
SP1     DAT
SP2     DAT
SP3     DAT
MISSILE DAT
M       DAT
SP0     DAT

Link to comment
Share on other sites

Gave it a try, just had to figure out a few things, but this works great

@Wrathchild many thanks again.

 

The printf's are like that to put space padded strings in 2 columns for formatting.

 

Here a sample in cc65

 

void directory(void)
{
    DIR *fd;
    char name[]="D:*.*";
    struct dirent *mydir;
    cls();
    gotoxy(0,0);
    fd = opendir(name);
    if(fd != NULL)
    {
        do
        {
            mydir = readdir(fd);
            if(mydir != 0)
            {
                printf("%s%*s",mydir->d_name,16-strlen(mydir->d_name)," ");
            }
            else
                break;
            mydir = readdir(fd);
            if(mydir != 0)
            {
                printf("%s%*s\n",mydir->d_name,16-strlen(mydir->d_name)," ");
            }
            else
                break;
        }while(1);
        closedir(fd);
    }
    gets(infile); // for debug
}

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...