Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/vcdsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,38 @@ int vcdEquipBdma(int source, int mode, char *diag, int diagSize)
return (mr != 0) ? mr : 0;
}

// 1.0.1-style fast path for the launch equip: a card with NO marker but BOTH driver modules present is
// a pair the user (or an install predating the marker file) manages MANUALLY. vcdReadBdmaMode()
// collapses "marker absent" into VCD_BDMA_FAT32, so before this check every launch on such a card read
// as a MISMATCH and paid the FULL equip -- source-device module loads with bounded waits plus two module
// copies onto the memory card -- on EVERY VCD launch (NathanNeurotic: "unnecessary over work... extended
// wait on game launch... unnecessary MC transfer"). Trust the card and hand off. An EXPLICIT different
// marker (a real variant switch, checked by the caller before this) or a missing/partial pair still does
// the copy work -- ONCE -- after which the marker matches and every later launch takes the cheap path.
static int vcdBdmaManualPairPresent(void)
{
char mcDir[64];
char path[96];
int fd, i;

if (!vcdResolvePopstarterMc(mcDir, sizeof(mcDir)))
return 0;
snprintf(path, sizeof(path), "%s/%s", mcDir, VCD_BDMA_MARKER);
fd = open(path, O_RDONLY);
if (fd >= 0) {
close(fd);
return 0; // marker PRESENT -> its verdict stands (the caller already compared it)
}
Comment on lines +897 to +902

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Only treat ENOENT as an absent marker.

A marker open() failure is currently indistinguishable from “no marker.” If the marker exists but the card returns an I/O or access error, this helper can trust an arbitrary module pair and suppress the repair/equip attempt. Return false for all errors other than ENOENT, so the fast path is used only when marker absence is confirmed.

Proposed fix
     fd = open(path, O_RDONLY);
     if (fd >= 0) {
         close(fd);
         return 0; // marker PRESENT -> its verdict stands (the caller already compared it)
     }
+    if (errno != ENOENT)
+        return 0; // marker state is unknown; do not trust the manual pair
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
snprintf(path, sizeof(path), "%s/%s", mcDir, VCD_BDMA_MARKER);
fd = open(path, O_RDONLY);
if (fd >= 0) {
close(fd);
return 0; // marker PRESENT -> its verdict stands (the caller already compared it)
}
snprintf(path, sizeof(path), "%s/%s", mcDir, VCD_BDMA_MARKER);
fd = open(path, O_RDONLY);
if (fd >= 0) {
close(fd);
return 0; // marker PRESENT -> its verdict stands (the caller already compared it)
}
if (errno != ENOENT)
return 0; // marker state is unknown; do not trust the manual pair
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/vcdsupport.c` around lines 897 - 902, Update the marker check near
VCD_BDMA_MARKER so only an open() failure with errno equal to ENOENT is treated
as marker absence; return 0 immediately for other errors, including I/O or
permission failures. Preserve the existing success path that closes the
descriptor and returns 0 when the marker is present.

for (i = 0; i < 2; i++) {
snprintf(path, sizeof(path), "%s/%s", mcDir, vcdBdmaModule[i]);
fd = open(path, O_RDONLY);
if (fd < 0)
return 0; // pair incomplete -> a real equip is useful work
close(fd);
}
return 1;
}

// Best-effort auto-equip of the device-matching BDMA driver before a VCD launch (POPSLoader's
// ApplyBdmaMode parity). POPSTARTER does its OWN SifIopReset, then reloads its block-device drivers
// from the FIXED memory-card files mc?:/POPSTARTER/usbd.irx + usbhdfsd.irx; equipping copies the
Expand All @@ -901,6 +933,8 @@ void vcdEnsureBdmaForLaunch(int source, int mode)
return; // FAT32 / invalid -> POPSTARTER's built-in driver, nothing to equip
if (vcdReadBdmaMode() == mode)
return; // the matching variant is already on the card
if (vcdBdmaManualPairPresent())
return; // no marker but a full pair on the card -- manually managed; dumb 1.0.1-style handoff

int er = vcdEquipBdma(source, mode, diag, sizeof(diag));
if (er == 0)
Expand Down