ITotalJustice / notorious_beeg

gba emulator written in c++23
https://notorious-beeg.netlify.app/
GNU General Public License v3.0
41 stars 4 forks source link

[kirby & the magic mirror] - crashes during demo with normmatts bios #106

Closed ITotalJustice closed 1 year ago

ITotalJustice commented 1 year ago

image

this happens during the demo (wait about 2 mins at the title screen) when kirby walks through the mirror. the game does two 16bit reads from bios region 0x6 and 0x12.

this results in the beloved openbus value being returned for the bios. the openbus bios value is the last value that was read from the bios (when the cpu is executing from it). for normmatts bios, this value should be 0x00001524 and official bios is 0xE3A02004.

the returned value is modified slightly depending if the access is 8/16 bit. for 8 bit, the byte selected depends on the lower 3 bits of the addr. for 16 bit, the halfword selected depends on bit1.

heres an implementation:

template<typename T>
auto openbus_bios(const u32 addr, const u32 openbus_value) -> T
{
    if constexpr(std::is_same<T, u8>())
    {
        // selects byte to return
        return openbus_value >> ((addr & 0x3) * 8);
    }
    else if constexpr(std::is_same<T, u16>())
    {
        // returns either upper or lower half
        return openbus_value >> ((addr & 2) * 8);
    }
    else if constexpr(std::is_same<T, u32>())
    {
        return openbus_value;
    }
}

this means that the returned value using normmatts bios should be 0x000 and 0xE3A0 for official bios.


Thanks to @ladystarbreeze for explaining all of the above!