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

Support array-of-bytes binary display #126

Merged
merged 1 commit into from
May 6, 2024

Conversation

malleoz
Copy link
Contributor

@malleoz malleoz commented May 5, 2024

Viewing an array of bytes entry as binary can be especially useful when observing bitfields. For example, Mario Kart Wii uses bitfields to track whether we are accelerating, braking, drifting, tricking, etc. Being able to view each bit in the field makes viewing the current state of each scenario a bit easier!

I didn't add octal or decimal support, because I can't imagine any scenarios where such a display could be useful.

@cristian64
Copy link
Collaborator

I've given it a go, and it works well. I've added a few comments, but I wouldn't be against to get it merged in its current state.

(The macOS error appears to be unrelated; might need to retry.)

@malleoz
Copy link
Contributor Author

malleoz commented May 5, 2024

@cristian64 I don't see your comments. Do you have a pending review that you forgot to click "Submit review" for?

Comment on lines 669 to 671
u8 unsignedByte = 0;
std::memcpy(&unsignedByte, memory + i, sizeof(u8));
ss << std::bitset<sizeof(u8) * 8>(unsignedByte).to_string() << " ";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could be just:

        ss << std::bitset<sizeof(u8) * 8>(Common::bit_cast<u8, char>(memory[i])).to_string() << " ";

(Given that it's a single byte, not even the bit_cast would be necessary; a regular static_cast would work too.

Comment on lines 680 to 682
u8 aByte = 0;
std::memcpy(&aByte, memory + i, sizeof(u8));
ss << std::setfill('0') << std::setw(2) << static_cast<int>(aByte) << " ";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, this could be:

        ss << std::setfill('0') << std::setw(2)
           << static_cast<int>(Common::bit_cast<u8, char>(memory[i])) << " ";

And, again, the bit_cast could just be a static_cast.

@malleoz
Copy link
Contributor Author

malleoz commented May 5, 2024

Those changes seem to work fine on my end, so I'm all for cleaning it up!

@dreamsyntax dreamsyntax merged commit 95cc20d into aldelaro5:master May 6, 2024
4 checks 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.

3 participants