TGB1718 Posted February 1, 2021 Share Posted February 1, 2021 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 Quote Link to comment Share on other sites More sharing options...
drac030 Posted February 1, 2021 Share Posted February 1, 2021 8 minutes ago, TGB1718 said: ICAUX1 need to be 2 to open a directory No clue about CC65, but generally ICAUX1 beeds to be *6* to open a directory (bit 1 set beside bit 2 being set too). Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted February 1, 2021 Share Posted February 1, 2021 Check dirent.h, you should be able to utilise opendir/readdir/closedir 2 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 1, 2021 Author Share Posted February 1, 2021 1 minute ago, Wrathchild said: Check dirent.h, you should be able to utilise opendir/readdir/closedir Many thanks, I thought it would be in there somewhere, I'll give it a try Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 1, 2021 Author Share Posted February 1, 2021 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 } 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.