In some Triforce games (e.g. _F-Zero AX_), the bytes that follow the
region flag in the `boot.id` file (at `0x38`) happen to be `0x00`.
However, in other games (e.g _Mario Kart Arcade GP 2_), it seems the
region flag is padded with `0xFF`.
_Mario Kart Arcade GP 2_ (`boot.id` in the USA version):
```
00000 0000: 42 54 49 44 00 00 01 E0 00 00 00 01 00 00 00 01 BTID.... ........
00000 0010: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF ........ ........
00000 0020: 47 43 41 4D 00 00 01 C0 07 D3 05 0F 00 00 00 07 GCAM.... ........
00000 0030: 53 42 4E 4C 00 00 00 00 0E FF FF FF FF FF FF FF SBNL.... ........
-----------
^
|
region flag
```
When the region flag was tested in `switch` statements (where a single
byte was expected in the `case`s), the test would fail, depending
on the game.
This issue would lead to the wrong calculation of the country in
`VolumeDisc::GetCountry()`, which was then used to build the game ID in
`VolumeDisc::GetGameID()`.
The solution is to test using only the least meaningful byte in the
region flag.
Unexpected game IDs were first noticed with USA version of _Mario Kart
Arcade GP 2_, which was wrongly assigned the same game ID that is given
to the Japan version (i.e. `GNLJ82`). The correct game ID for the USA
version is `GNLE82`.
Added SerialDevice base class interface.
Adapted MagneticCardReader to use the SerialDevice interface.
Implemented The Key of Avalon touchscreen SerialDevice.
Altered CSIDevice_AMBaseboard to use SerialDevice.
Made serial reads happen every GCAMCommand rather than only upon write.
Use the normal state changed `HookableEvent` instead of having
`Core::NotifyStateChanged` call `g_perf_metrics.OnEmulationStateChanged`
directly.
The direct call was added in bad78cfed4 to
avoid a crash. At the time state changed callbacks were stored in a
vector, and the crash was caused by `g_perf_metric`'s destructor trying
to remove the callback from the already-destroyed vector.
Later a97627e736 switched state changed
callbacks to use `HookableEvent`, which is specifically designed to
handle the case where a hook outlives its associated event.
Since the workaround is no longer necessary replace it with a standard
`EventHook`.
This switches from an O(log(N) * M) algorithm to an O(N * log(M))
algorithm. This is advantageous because N, the size of `mappings`, is
usually much smaller than M, the size of `m_page_table_mapped_entries`.
RemoveLargePageTableMapping already did something similar, so we can
even deduplicate some code between it and RemoveHostPageTableMappings.
Speeds up Rogue Squadron 3 by roughly 3% on my PC.
If Dolphin crashes, changes that have been made to settings are often
lost. This has been a minor annoyance for me when developing, but it has
become a much bigger issue recently due to the problem where Dolphin
freezes on shutdown for ROG Ally users.
Instead of saving the config when certain arbitrary settings are
changed, let's save the config when the user closes the settings window.
Fixes a macOS Metal crash when stopping immediately after boot starts.
m_upload_encoder and m_texture_upload_encoder could be dealloc'd during shutdown before endEncoding could be called, which causes a Metal assertion failure.
Co-authored-by: OatmealDome <julian@oatmealdome.me>
Don't set cached array bases to invalid pointers. If a game tries to set
an invalid base just keep the old one, which might cause game problems
but won't crash the emulator.