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

Identify/fix some mcard inlines #177

Merged
merged 2 commits into from
Sep 18, 2024
Merged

Conversation

cadmic
Copy link
Collaborator

@cadmic cadmic commented Sep 18, 2024

I started matching more mcard functions and I think these are correct now, although I'm not sure on mcardFinishFile vs mcardFinishGame. Highlights:

  • UnkInlinemCardReplaceFileBlock -> mcardReadAnywhereNoTime
  • UnkInlinemCardReplaceFileBlock2, UnkInlinemCardVerifyChecksumFileHeader2 -> mcardWriteAnywhereNoTime
  • UnkInlinemCardVerifyChecksumFileHeader, mcardGameEraseInline -> mcardReadyFile
  • UnkINlinemCardVerifyChecksumFileHeader3, UnkINlinemCardVerifyChecksumFileHeader4 -> mcardFinishFile
  • mcardGetFileTime: missing pMCard->saveToggle == true check
  • mcardFileRelease: should call mcardGameRelease

Copy link
Collaborator

@Yanis002 Yanis002 left a comment

Choose a reason for hiding this comment

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

dolphin/card.h got some macros that could be used here, I made suggestions but idk if that makes sense or not

@@ -287,12 +257,12 @@ static bool mcardReplaceFileBlock(MemCard* pMCard, s32 index) {

simulatorPrepareMessage(S_M_CARD_SV09);

if (!UnkInlinemCardReplaceFileBlock2(pMCard, index << 13)) {
if (!mcardWriteAnywhereNoTime(pMCard, index << 13, 0x2000, pMCard->writeBuffer)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!mcardWriteAnywhereNoTime(pMCard, index << 13, 0x2000, pMCard->writeBuffer)) {
if (!mcardWriteAnywhereNoTime(pMCard, index << 13, CARD_SYSTEM_BLOCK_SIZE, pMCard->writeBuffer)) {


memcpy(buffer, pMCard->writeBuffer, 0x2000);

if (!UnkInlinemCardReplaceFileBlock(pMCard)) {
if (!mcardReadAnywhereNoTime(pMCard, 0x4000, 0x2000, pMCard->writeBuffer)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!mcardReadAnywhereNoTime(pMCard, 0x4000, 0x2000, pMCard->writeBuffer)) {
if (!mcardReadAnywhereNoTime(pMCard, 0x4000, CARD_SYSTEM_BLOCK_SIZE, pMCard->writeBuffer)) {

maybe that 0x4000 is CARD_SYSTEM_BLOCK_SIZE * 2? not sure if that makes sense though

@@ -263,11 +233,11 @@ static bool mcardReplaceFileBlock(MemCard* pMCard, s32 index) {
s32 checksum1;
s32 checksum2;
char buffer[0x2000];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
char buffer[0x2000];
char buffer[CARD_SYSTEM_BLOCK_SIZE];

Comment on lines +199 to 204
char buffer2[0x2000];
s32 checksum;
s32 pad[2];

memcpy(buffer2, pMCard->writeBuffer, 0x2000);
memcpy(pMCard->writeBuffer, buffer, 0x2000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
char buffer2[0x2000];
s32 checksum;
s32 pad[2];
memcpy(buffer2, pMCard->writeBuffer, 0x2000);
memcpy(pMCard->writeBuffer, buffer, 0x2000);
char buffer2[CARD_SYSTEM_BLOCK_SIZE];
s32 checksum;
s32 pad[2];
memcpy(buffer2, pMCard->writeBuffer, CARD_SYSTEM_BLOCK_SIZE);
memcpy(pMCard->writeBuffer, buffer, CARD_SYSTEM_BLOCK_SIZE);

@cadmic
Copy link
Collaborator Author

cadmic commented Sep 18, 2024

I definitely agree on CARD_SYSTEM_BLOCK_SIZE (though maybe we want a shorter name) but there are quite a lot of places it should be used, much more than the ones you pointed out. Is it already if we leave it for a cleanup PR?

@Yanis002
Copy link
Collaborator

I don't mind if it's done in this PR but do like you want

about the name, CARD_BLOCK_SIZE might be better?

@cadmic
Copy link
Collaborator Author

cadmic commented Sep 18, 2024

Yeah sorry, I think I'd like to do a cleanup pass after the rest of mcard is decompiled, because it's a bit hard to tell how things are used right now

@cadmic cadmic merged commit 51366eb into zeldaret:main Sep 18, 2024
1 check passed
@cadmic cadmic deleted the mcard-fix-inlines branch September 20, 2024 16:10
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