• Porting DirMenu to PET: need help!

    From Harry Potter@3:770/3 to All on Sun Feb 11 15:52:57 2018
    Hi! Recently, somebody e-mailed me a request for a PET version of DirMenu. I started work on it but am having a problem: when I try to read the directory, I
    get a ?Syntax Error. I don't know what's causing this, but the following code
    seems to cause
    the problem (I'm using cc65):
    ----------------------------
    .__asm__ (
    ..//Set LFNs.
    .."\tlda\t#1\n"
    .."\tldx\t#8\n"
    .."\tldy\t#0\n"
    .."\tsty\t_c\n"
    .."\tsty\t_e\n"
    .."\tjsr\t$FFBA\n"
    ..//Set name ("$", as above in dire).
    .."\tldx\t#<_dire\n"
    .."\tldy\t#>_dire\n"
    .."\tjsr\t$FFBD\n"
    ..//Open directory.
    .."\tjsr\t$FFC0\n"
    ..);
    ----------------------------
    Can you help me out?

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Tilmann Hentze@3:770/3 to Harry Potter on Mon Feb 12 02:29:34 2018
    Harry Potter <rose.joseph12@yahoo.com> schrieb:
    having a problem: when I try to read the directory,
    I get a ?Syntax Error.

    It means KERNAL OPEN failed, because the file number is zero
    according to "Compute's Programming The PET/CBM".

    I don't know what's causing this, but the following code seems to
    cause the problem (I'm using cc65):
    ----------------------------
    .__asm__ (
    ..//Set LFNs.
    .."\tlda\t#1\n"
    .."\tldx\t#8\n"
    .."\tldy\t#0\n"
    .."\tsty\t_c\n"
    .."\tsty\t_e\n"
    .."\tjsr\t$FFBA\n"
    This calls the SCRATCH routine in BASIC 4.
    ..//Set name ("$", as above in dire).
    .."\tldx\t#<_dire\n"
    .."\tldy\t#>_dire\n"
    .."\tjsr\t$FFBD\n"
    This reads the disk device status.
    ..//Open directory.
    .."\tjsr\t$FFC0\n"
    ..);
    ----------------------------
    Can you help me out?

    Use cc65's cbm_opendir and cbm_readdir declared in cbm.h
    e.g:

    #include <cbm.h>
    #include <pet.h>
    #include <stdio.h>

    int main(int argc, unsigned char **argv)
    {

    .struct cbm_dirent dire;
    .unsigned char result = 0;
    .unsigned char lfn = 1;
    .unsigned char device = 8;
    .unsigned char dirname[17] = "$";

    .result = cbm_opendir(lfn, device, dirname);
    .if (result)
    .{
    ..printf("error: %hhd\n", result);
    ..return result;
    .}

    .while (result == 0)
    .{
    ..result = cbm_readdir(lfn, &dire);
    ..switch (result)
    ..{
    ...case 0:
    ....printf("%3hd %-16s %#hhx %#hhx\n",
    ......dire.size,
    ......dire.name,
    ......dire.type,
    ......dire.access
    ....);
    ....break;
    ...case 2:
    ....printf("%3hd blocks free.\n", dire.size);
    ....break;
    ...default:
    ....break;
    ..}
    .}
    .cbm_closedir(lfn);
    .return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)