Skip to content

Commit

Permalink
implement 8- and 16-bit DSi AES register accesses
Browse files Browse the repository at this point in the history
fixes NAND access through Godmode9i
  • Loading branch information
RSDuck committed Aug 21, 2022
1 parent 4c97731 commit 22b312b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/DSi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,6 +2806,39 @@ void ARM7IOWrite8(u32 addr, u8 val)
return;
}

if (addr >= 0x04004420 && addr < 0x04004430)
{
u32 shift = (addr&3)*8;
addr -= 0x04004420;
addr &= ~3;
DSi_AES::WriteIV(addr, (u32)val << shift, 0xFF << shift);
return;
}
if (addr >= 0x04004430 && addr < 0x04004440)
{
u32 shift = (addr&3)*8;
addr -= 0x04004430;
addr &= ~3;
DSi_AES::WriteMAC(addr, (u32)val << shift, 0xFF << shift);
return;
}
if (addr >= 0x04004440 && addr < 0x04004500)
{
u32 shift = (addr&3)*8;
addr -= 0x04004440;
addr &= ~3;

int n = 0;
while (addr >= 0x30) { addr -= 0x30; n++; }

switch (addr >> 4)
{
case 0: DSi_AES::WriteKeyNormal(n, addr&0xF, (u32)val << shift, 0xFF << shift); return;
case 1: DSi_AES::WriteKeyX(n, addr&0xF, (u32)val << shift, 0xFF << shift); return;
case 2: DSi_AES::WriteKeyY(n, addr&0xF, (u32)val << shift, 0xFF << shift); return;
}
}

return NDS::ARM7IOWrite8(addr, val);
}

Expand Down Expand Up @@ -2849,6 +2882,39 @@ void ARM7IOWrite16(u32 addr, u16 val)
return;
}

if (addr >= 0x04004420 && addr < 0x04004430)
{
u32 shift = (addr&1)*16;
addr -= 0x04004420;
addr &= ~1;
DSi_AES::WriteIV(addr, (u32)val << shift, 0xFFFF << shift);
return;
}
if (addr >= 0x04004430 && addr < 0x04004440)
{
u32 shift = (addr&1)*16;
addr -= 0x04004430;
addr &= ~1;
DSi_AES::WriteMAC(addr, (u32)val << shift, 0xFFFF << shift);
return;
}
if (addr >= 0x04004440 && addr < 0x04004500)
{
u32 shift = (addr&1)*16;
addr -= 0x04004440;
addr &= ~1;

int n = 0;
while (addr >= 0x30) { addr -= 0x30; n++; }

switch (addr >> 4)
{
case 0: DSi_AES::WriteKeyNormal(n, addr&0xF, (u32)val << shift, 0xFFFF << shift); return;
case 1: DSi_AES::WriteKeyX(n, addr&0xF, (u32)val << shift, 0xFFFF << shift); return;
case 2: DSi_AES::WriteKeyY(n, addr&0xF, (u32)val << shift, 0xFFFF << shift); return;
}
}

if (addr >= 0x04004800 && addr < 0x04004A00)
{
SDMMC->Write(addr, val);
Expand Down

0 comments on commit 22b312b

Please sign in to comment.