Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: USB hotswapping for replay storage #39

Merged
merged 7 commits into from
Sep 26, 2024

Conversation

jmlee337
Copy link

@jmlee337 jmlee337 commented Sep 26, 2023

the general methodology of this change is as follows

  1. copy the technique from HID.c to set up a thread and addition to main loop to manage the IOCTLs and keep track of devices being inserted or removed
  2. copy enough of libogc/usb.c and libogc/usbstorage.c in to mount inserted devices
  3. modify SlippiFileWriter logic to enable hotswap for usb

caveat: as currently implemented, the game will still not boot without the usb replay device inserted. I am working on removing this limitation as a follow-up.

another note: this may require some closed testing before wide use. I encountered some game crashes while implementing. However I believe those were attributable solely to errors at the time. Additionally the crashes always occurred as the game started (between stage select and go) and not during the middle of games

please feel free to @ me in discord if there are any questions or explanations required

@jmlee337
Copy link
Author

Here's a sample of aforementioned game crash btw:

HSD ArchiveParse: byte-order mismatch! Please check data format 20004002 56
HSD ArchiveParse error!
assertion "0" failed in lbarchive.c on line 73.
DATE Feb 13 2002 TIME 22:06:27

SN v1.11.1-5-9bc7eda8-dirty
 Console runtime: 2415 frames
 Scene runtime: 144 frames

- STACK -----------------------
 Address:  Back Chain  LR Save
804EE9A8:   804EE9D0   803882EC
804EE9D0:   804EE9F0   80388260
804EE9F0:   804EEA18   80016AA4
804EEA18:   804EEAB8   80016D20
804EEAB8:   804EEB10   800222E4
804EEB10:   804EEB30   8016E7C8
804EEB30:   804EEB48   8016E94C
804EEB48:   804EEB80   801A40E8
804EEB80:   804EEBB0   801A44C4
804EEBB0:   804EEBD0   801A45C8
804EEBD0:   804EEBF8   801601AC
804EEBF8:   FFFFFFFF   8000533C

PXL_20230926_140715561

the general methodology of this change is as follows

1. copy the technique from HID.c to set up a thread and addition to main loop to manage the IOCTLs and keep track of devices being inserted or removed
2. copy enough of libogc/usb.c and libogc/usbstorage.c in to mount inserted devices
3. modify SlippiFileWriter logic to enable hotswap for usb
yes: on while usb inserted and write thread is keeping up
stealth: flash when usb inserted, flash when end of game is successfully written
no: no led behavior
I think we got away with this before cuz all __cycle invocations used the same command length. Not sure if this can actually cause errors but for correctness...
@jmlee337
Copy link
Author

squashed commits.

To reiterate from discord, I've had testers running weeklies for 10 months and larger locals (up to 64 entrants) for 3 months. No regressions or confirmed bugs have been found

Copy link
Member

@NikhilNarayana NikhilNarayana left a comment

Choose a reason for hiding this comment

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

some quick thoughts while i get my head around the rest

}
if (ncfg->Version == 0xC)
{
// 0 defaults are fine
Copy link
Member

Choose a reason for hiding this comment

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

check if replays are currently enabled and set the LED to stealth if so

bool failedToMount = false;
bool hasFile = false;
bool mounted = true;
const bool use_usb = ConfigGetUseUSB() != 1;
Copy link
Member

Choose a reason for hiding this comment

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

u32 UseUSB = ConfigGetUseUSB(); // Returns 0 for SD, 1 for USB

based on the line above, shouldn't this be const bool use_usb = ConfigGetUseUSB() (== 1);?

Copy link
Author

@jmlee337 jmlee337 Sep 16, 2024

Choose a reason for hiding this comment

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

ConfigGetUseUSB refers to ISO device, so file write device is 'opposite'

@jmlee337
Copy link
Author

Removed "stealth" Replays LED setting as discussed in discord
As well see below, Replays LED setting description with the existing UCF setting description for comparison
PXL_20240925_120155904
PXL_20240925_085314432

Comment on lines 179 to 185
"How Drive LED should be used to",
"indicate replay device status",
"",
" [Yes]",
" Drive LED will stay lit as long",
" as a replay device is inserted",
" and working properly.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"How Drive LED should be used to",
"indicate replay device status",
"",
" [Yes]",
" Drive LED will stay lit as long",
" as a replay device is inserted",
" and working properly.",
"Use the Wii Disc Drive LED",
"to indicate replay device status.",
"The LED will remain on while",
"the replay device is inserted",
"and working properly.",

@NikhilNarayana NikhilNarayana changed the title enable device hotswapping when using USB for replays feat: USB hotswapping for replay storage Sep 26, 2024
@NikhilNarayana NikhilNarayana merged commit 6deec6c into project-slippi:slippi Sep 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants