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

Mimic 8-bit overflow manually in SCBRR2_write #1729

Closed

Conversation

vkedwardli
Copy link
Collaborator

Fixes MUSHIKING cannot insert card with macOS arm64. (Issue reported from Discord)

Details:
In macOS arm64, the SCIFSerialPort::schedCallback would stop calling after the Now Loading... screen.

SCIFSerialPort::schedCallback
SCIFSerialPort::rxSched()
return scif.frameSize * scif.cyclesPerBit (10, 2560)
SH4 SCIF: Frame size 10 cycles/bit 2560 (78125 bauds) pipe 0x600002b78460, SCIF_SCBRR2 = 19, SCIF_SCSMR2.CKS = 0
SCIFSerialPort::SCBRR2_write: 4294967202
SH4 SCIF: Frame size 10 cycles/bit 0 (0 bauds) pipe 0x600002b78460, SCIF_SCBRR2 = 4294967202, SCIF_SCSMR2.CKS = 0
SCIFSerialPort::schedCallback
SCIFSerialPort::rxSched()
return scif.frameSize * scif.cyclesPerBit (10, 0)

This happens when SCIFSerialPort::SCBRR2_write is trying to write a -94, overflowing to become 4294967202, making cyclesPerBit become 0.
(But on the debug build, it is writing 162, the 8-bit overflow value for -94)

Since static_cast<signed char>(data) or static_cast<u8>(static_cast<signed char>(data)> does not work, so I just add 256 directly to mimic the 8-bit overflow

Question:

  • Should I add ifdef directive so the new code only runs on macOS arm64?
  • Is there a better 8-bit overflow handling?

@vkedwardli vkedwardli force-pushed the fix-SCBRR2write-overflow branch from 301a926 to 599b53c Compare November 7, 2024 06:11
@vkedwardli
Copy link
Collaborator Author

It is writing FFFFFFA2 (4294967202) which should be masked as 000000A2 (162) for u8

@vkedwardli vkedwardli closed this Nov 7, 2024
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.

1 participant