1 /* This is very simplified version of POSIX opendir(), readdir() and closedir() */
2 /* for Commodore computers. */
3 /* Created by Josef Soucek, 2003 E-mail:josef.soucek@ct.cz */
5 /* Version 0.1 - 21.1.2003 */
6 /* Tested with floppy drive and IDE64 devices */
7 /* Not tested with messed (buggy) directory listing */
8 /* Limits filenames to 16 chars (VICE supports more in directory listing) */
16 unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned
19 if ((status = cbm_open (lfn, device, CBM_READ, "$")) == 0) {
20 if (cbm_k_chkin (lfn) == 0) {
21 /* Ignore start address */
39 unsigned char __fastcall__ cbm_readdir (unsigned char lfn, register struct cbm_dirent* l_dirent)
41 unsigned char byte, i;
43 unsigned char is_header;
44 static const unsigned char types[] = {
45 CBM_T_OTHER, CBM_T_OTHER, CBM_T_CBM, CBM_T_DIR, /* a b c d */
46 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, /* e f g h */
47 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, /* i j k l */
48 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_PRG, /* m n o p */
49 CBM_T_OTHER, CBM_T_REL, CBM_T_SEQ, CBM_T_OTHER, /* q r s t */
50 CBM_T_USR, CBM_T_VRP /* u v */
56 if (!cbm_k_chkin(lfn)) {
57 if (!cbm_k_readst()) {
58 /* skip 2 bytes, next basic line pointer */
63 l_dirent->size = cbm_k_basin() | ((cbm_k_basin()) << 8);
67 /* "B" BLOCKS FREE. */
69 /* Read until end, careless callers may call us again */
70 while (!cbm_k_readst()) {
77 /* reverse text shows that this is the directory header */
78 if (byte == 0x12) { /* RVS_ON */
82 while (byte != '\"') {
84 /* prevent endless loop */
92 while ((byte = cbm_k_basin()) != '\"') {
93 /* prevent endless loop */
99 if (i < sizeof (l_dirent->name) - 1) {
100 l_dirent->name[i] = byte;
104 l_dirent->name[i] = '\0';
106 while ((byte = cbm_k_basin()) == ' ') {
107 /* prevent endless loop */
108 if (cbm_k_readst()) {
115 l_dirent->type = CBM_T_HEADER;
117 if (byte >= 'a' && byte < 'a' + sizeof(types)) {
118 l_dirent->type = types[byte - 'a'];
120 l_dirent->type = CBM_T_OTHER;
126 byte = cbm_k_basin();
128 l_dirent->access = (byte == 0x3C)? CBM_A_RO : CBM_A_RW;
131 /* read to end of line */
133 byte = cbm_k_basin();
134 /* prevent endless loop */
135 if (cbm_k_readst()) {
152 void __fastcall__ cbm_closedir( unsigned char lfn)