Skip to content

Commit

Permalink
force-align all read/write accesses. fixes melonDS-emu#1540 (unaligne…
Browse files Browse the repository at this point in the history
…d DMA address)
  • Loading branch information
Arisotura committed Oct 22, 2022
1 parent b6776bd commit dd74e93
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/DSi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,8 @@ u8 ARM9Read8(u32 addr)

u16 ARM9Read16(u32 addr)
{
addr &= ~0x1;

if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1))))
{
if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0)))
Expand Down Expand Up @@ -1331,6 +1333,8 @@ u16 ARM9Read16(u32 addr)

u32 ARM9Read32(u32 addr)
{
addr &= ~0x3;

if ((addr >= 0xFFFF0000) && (!(SCFG_BIOS & (1<<1))))
{
if ((addr >= 0xFFFF8000) && (SCFG_BIOS & (1<<0)))
Expand Down Expand Up @@ -1488,6 +1492,8 @@ void ARM9Write8(u32 addr, u8 val)

void ARM9Write16(u32 addr, u16 val)
{
addr &= ~0x1;

switch (addr & 0xFF000000)
{
case 0x03000000:
Expand Down Expand Up @@ -1578,6 +1584,8 @@ void ARM9Write16(u32 addr, u16 val)

void ARM9Write32(u32 addr, u32 val)
{
addr &= ~0x3;

switch (addr & 0xFF000000)
{
case 0x03000000:
Expand Down Expand Up @@ -1763,6 +1771,8 @@ u8 ARM7Read8(u32 addr)

u16 ARM7Read16(u32 addr)
{
addr &= ~0x1;

if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9))))
{
if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8)))
Expand Down Expand Up @@ -1820,6 +1830,8 @@ u16 ARM7Read16(u32 addr)

u32 ARM7Read32(u32 addr)
{
addr &= ~0x3;

if ((addr < 0x00010000) && (!(SCFG_BIOS & (1<<9))))
{
if ((addr >= 0x00008000) && (SCFG_BIOS & (1<<8)))
Expand Down Expand Up @@ -1972,6 +1984,8 @@ void ARM7Write8(u32 addr, u8 val)

void ARM7Write16(u32 addr, u16 val)
{
addr &= ~0x1;

switch (addr & 0xFF800000)
{
case 0x03000000:
Expand Down Expand Up @@ -2067,6 +2081,8 @@ void ARM7Write16(u32 addr, u16 val)

void ARM7Write32(u32 addr, u32 val)
{
addr &= ~0x3;

switch (addr & 0xFF800000)
{
case 0x03000000:
Expand Down
18 changes: 17 additions & 1 deletion src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ void debug(u32 param)
// printf("VRAM %c: %02X\n", 'A'+i, GPU::VRAMCNT[i]);

FILE*
shit = fopen("debug/inazuma.bin", "wb");
shit = fopen("debug/crayon.bin", "wb");
fwrite(ARM9->ITCM, 0x8000, 1, shit);
for (u32 i = 0x02000000; i < 0x02400000; i+=4)
{
Expand Down Expand Up @@ -2093,6 +2093,8 @@ u8 ARM9Read8(u32 addr)

u16 ARM9Read16(u32 addr)
{
addr &= ~0x1;

if ((addr & 0xFFFFF000) == 0xFFFF0000)
{
return *(u16*)&ARM9BIOS[addr & 0xFFF];
Expand Down Expand Up @@ -2151,6 +2153,8 @@ u16 ARM9Read16(u32 addr)

u32 ARM9Read32(u32 addr)
{
addr &= ~0x3;

if ((addr & 0xFFFFF000) == 0xFFFF0000)
{
return *(u32*)&ARM9BIOS[addr & 0xFFF];
Expand Down Expand Up @@ -2255,6 +2259,8 @@ void ARM9Write8(u32 addr, u8 val)

void ARM9Write16(u32 addr, u16 val)
{
addr &= ~0x1;

switch (addr & 0xFF000000)
{
case 0x02000000:
Expand Down Expand Up @@ -2319,6 +2325,8 @@ void ARM9Write16(u32 addr, u16 val)

void ARM9Write32(u32 addr, u32 val)
{
addr &= ~0x3;

switch (addr & 0xFF000000)
{
case 0x02000000:
Expand Down Expand Up @@ -2484,6 +2492,8 @@ u8 ARM7Read8(u32 addr)

u16 ARM7Read16(u32 addr)
{
addr &= ~0x1;

if (addr < 0x00004000)
{
if (ARM7->R[15] >= 0x00004000)
Expand Down Expand Up @@ -2548,6 +2558,8 @@ u16 ARM7Read16(u32 addr)

u32 ARM7Read32(u32 addr)
{
addr &= ~0x3;

if (addr < 0x00004000)
{
if (ARM7->R[15] >= 0x00004000)
Expand Down Expand Up @@ -2682,6 +2694,8 @@ void ARM7Write8(u32 addr, u8 val)

void ARM7Write16(u32 addr, u16 val)
{
addr &= ~0x1;

switch (addr & 0xFF800000)
{
case 0x02000000:
Expand Down Expand Up @@ -2760,6 +2774,8 @@ void ARM7Write16(u32 addr, u16 val)

void ARM7Write32(u32 addr, u32 val)
{
addr &= ~0x3;

switch (addr & 0xFF800000)
{
case 0x02000000:
Expand Down

0 comments on commit dd74e93

Please sign in to comment.