LiveSplit / asr

Helper crate to write auto splitters for LiveSplit One's auto splitting runtime.
https://livesplit.org/asr/asr
Apache License 2.0
10 stars 10 forks source link

Incorrect memory readings on SEGA Genesis emulator #86

Open Jujstme opened 8 months ago

Jujstme commented 8 months ago

This issue specifically affects emulators using a byte-swapped memory layout.

For historical reasons, most of the current emulators for the SEGA Genesis swap odd and even bytes in the emulated memory, effectively swapping an internal big endian memory layout to a little endian one. The crate currently deals with this with an internal enum that reports whether the emulator is using an original, big endian, or a byte swapped layout.

This allows for easily reading single u8 and u16 values from memory, as well as [u16; N] arrays, but breaks completely when dealing with [u8; N] due to the fact no additional abstraction is performed other than checking the original memory address to start reading from.

The solution, which I plan on implementing eventually, is to swap odd and even bytes from the [u8; N] array after reading it and before returning it to the calling function. This would require a bit of unsafe but would be safely wrapped inside the read() function anyway.