Skip to content

Commit

Permalink
Use image_index=-1 to mark "restart from beginning".
Browse files Browse the repository at this point in the history
Previously IMAGE_INDEX_MAX was used, but the later checks for
image_index > 0 would mistakenly believe there were multiple images.

Mainly resulted in confusing log messages for drives with only a single image.
  • Loading branch information
PetteriAimonen authored and erichelgeson committed Jun 20, 2023
1 parent 0cf1912 commit 44f40af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/BlueSCSI_cdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,9 @@ void cdromReinsertFirstImage(image_config_t &img)
if (img.image_index > 0)
{
// Multiple images for this drive, force restart from first one
debuglog("---- Restarting from first CD-ROM image");
img.image_index = IMAGE_INDEX_MAX;
uint8_t target = img.scsiId & 7;
debuglog("---- Restarting from first CD-ROM image for ID ", (int)target);
img.image_index = -1;
img.current_image[0] = '\0';
cdromSwitchNextImage(img);
}
Expand Down
6 changes: 3 additions & 3 deletions src/BlueSCSI_disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
else
{
img.image_index++;
if (img.image_index > IMAGE_INDEX_MAX)
if (img.image_index > IMAGE_INDEX_MAX || img.image_index < 0)
{
img.image_index = 0;
}
Expand All @@ -693,13 +693,13 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
{
// there may be more than one image but we've ran out of new ones
// wrap back to the first image
img.image_index = IMAGE_INDEX_MAX;
img.image_index = -1;
return scsiDiskGetNextImageName(img, buf, buflen);
}
else
{
// images are not defined in config
img.image_index = IMAGE_INDEX_MAX;
img.image_index = -1;
return 0;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/BlueSCSI_disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ struct image_config_t: public S2S_TargetCfg
bool image_directory;
// the name of the currently mounted image in a dynamic image directory
char current_image[MAX_FILE_PATH];

// Index of image, for when image on-the-fly switching is used for CD drives
// This is also used for dynamic directories to track how many images have been seen
uint8_t image_index;
// Negative value forces restart from first image.
int image_index;

// Cue sheet file for CD-ROM images
FsFile cuesheetfile;
Expand Down

0 comments on commit 44f40af

Please sign in to comment.