Skip to content

Commit

Permalink
Better parsing of dir command
Browse files Browse the repository at this point in the history
  • Loading branch information
KimJorgensen committed Jan 16, 2022
1 parent 53826b0 commit 1fde24c
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions firmware/disk_drive.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,13 @@ static void disk_handle_load_prg(DISK_CHANNEL *channel, char *filename)
}
}

static bool disk_parse_dir(DISK_CHANNEL *channel, char *filename)
static bool disk_parse_dir(DISK_CHANNEL *channel, char **filename_ptr)
{
char *filename = *filename_ptr;

// Check drive number
if (filename[0] >= '0' && filename[0] <= '9')
if (filename[0] >= '0' && filename[0] <= '9' &&
(filename[1] == 0 || filename[1] == ':'))
{
if (filename[0] != '0')
{
Expand All @@ -550,34 +553,33 @@ static bool disk_parse_dir(DISK_CHANNEL *channel, char *filename)
{
filename[0] = '*';
}
else
{
// Scan for filename
char c;
while ((c = *filename))
{
filename++;
if (c == ':')
{
break;
}
}
}
}
else if (filename[0] == 0)
{
filename[0] = '*';
filename[1] = 0;
}

// Scan for filename
char c;
while ((c = *filename))
{
filename++;
if (c == ':')
{
*filename_ptr = filename;
break;
}
}

// TODO: Also support '=' to filter on filetype

return true;
}

static void disk_handle_load_dir(DISK_CHANNEL *channel, char *filename)
{
if (!disk_parse_dir(channel, filename))
if (!disk_parse_dir(channel, &filename))
{
c64_send_reply(REPLY_NO_DRIVE); // Try serial device (if any)
return;
Expand Down Expand Up @@ -787,7 +789,7 @@ static void disk_handle_open_dir(DISK_CHANNEL *channel, char *filename)
}
else // Channel 0
{
if (!disk_parse_dir(channel, filename))
if (!disk_parse_dir(channel, &filename))
{
c64_send_reply(REPLY_NO_DRIVE); // Try serial device (if any)
return;
Expand Down

0 comments on commit 1fde24c

Please sign in to comment.