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

big endian support #77

Closed ITotalJustice closed 2 years ago

ITotalJustice commented 2 years ago

currently, the emulator only works on little endian. reason for this is how the IO regs are defined:

https://github.com/ITotalJustice/notorious_beeg/blob/master/src/core/mem.hpp#L250-L390

a simple runtime test can show this:

REG_DISPSTAT = 1;
if (gba.mem.io[gba::mem::IO_DISPSTAT & 0x3FF] != 1)
{
    printf("big endian :(\n");
}

there's many ways to "fix" this, however i still want to keep the macros around for now.

the simplest way i see is to make the io array a u16, as almost all io regs are u16. this causes some problems with some regs, such as REG_BG3Xand all dma regs REG_DMA0SAD, REG_DMA0DAD, REG_DMA0CNT

/* old */ #define REG_DISPCNT  *reinterpret_cast<std::uint16_t*>(gba.mem.io + (gba::mem::IO_DISPCNT & 0x3FF))
/* new */ #define REG_DISPCNT  gba.mem.io[(gba::mem::IO_DISPCNT & 0x3FF) >> 1]
ITotalJustice commented 2 years ago

this isn't yet fixed, rendering will still be broken in big endian.

see the n64 port for how i handle it there: https://github.com/ITotalJustice/notorious_beeg/blob/n64-port/src/core/ppu/render.cpp