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 char device)
19 if ((status = cbm_open (lfn, device, CBM_READ, "$")) == 0) {
20 if (cbm_k_chkin (lfn) == 0) {
21 if (cbm_k_basin () == 0x01) { /* Start address */
22 if (cbm_k_basin () == 0x04) {
38 unsigned char __fastcall__ cbm_readdir (unsigned char lfn, register struct cbm_dirent* l_dirent)
40 unsigned char byte, i;
42 unsigned char is_header;
43 static const unsigned char types[] = {
44 CBM_T_OTHER, CBM_T_OTHER, CBM_T_CBM, CBM_T_DIR, /* a b c d */
45 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, /* e f g h */
46 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, /* i j k l */
47 CBM_T_OTHER, CBM_T_OTHER, CBM_T_OTHER, CBM_T_PRG, /* m n o p */
48 CBM_T_OTHER, CBM_T_REL, CBM_T_SEQ, CBM_T_OTHER, /* q r s t */
49 CBM_T_USR, CBM_T_VRP /* u v */
55 if (!cbm_k_chkin(lfn)) {
56 if (!cbm_k_readst()) {
57 /* skip 2 bytes, next basic line pointer */
62 l_dirent->size = cbm_k_basin() | ((cbm_k_basin()) << 8);
66 /* "B" BLOCKS FREE. */
68 /* Read until end, careless callers may call us again */
69 while (!cbm_k_readst()) {
76 /* reverse text shows that this is the directory header */
77 if (byte == 0x12) { /* RVS_ON */
81 while (byte != '\"') {
83 /* prevent endless loop */
91 while ((byte = cbm_k_basin()) != '\"') {
92 /* prevent endless loop */
98 if (i < sizeof (l_dirent->name) - 1) {
99 l_dirent->name[i] = byte;
103 l_dirent->name[i] = '\0';
105 while ((byte = cbm_k_basin()) == ' ') {
106 /* prevent endless loop */
107 if (cbm_k_readst()) {
114 l_dirent->type = CBM_T_HEADER;
116 if (byte >= 'a' && byte < 'a' + sizeof(types)) {
117 l_dirent->type = types[byte - 'a'];
119 l_dirent->type = CBM_T_OTHER;
125 byte = cbm_k_basin();
127 l_dirent->access = (byte == 0x3C)? CBM_A_RO : CBM_A_RW;
130 /* read to end of line */
132 byte = cbm_k_basin();
133 /* prevent endless loop */
134 if (cbm_k_readst()) {
151 void __fastcall__ cbm_closedir( unsigned char lfn)