Handle GBA cartridge SRAM writes

This commit is contained in:
Raphaël Zumer 2019-12-08 17:56:22 -05:00
parent 48a8a25548
commit 62b9f51e23
3 changed files with 106 additions and 0 deletions

View File

@ -104,6 +104,60 @@ void RelocateSave(const char* path, bool write)
fclose(f);
}
void Write8(u32 addr, u8 val)
{
u8 prev = *(u8*)&SRAM[addr];
if (prev != val)
{
*(u8*)&SRAM[addr] = val;/*
FILE* f = Platform::OpenFile(SRAMPath, "r+b");
if (f)
{
fseek(f, addr, SEEK_SET);
fwrite((u8*)&SRAM[addr], 1, 1, f);
fclose(f);
}*/
}
}
void Write16(u32 addr, u16 val)
{
u16 prev = *(u16*)&SRAM[addr];
if (prev != val)
{
*(u16*)&SRAM[addr] = val;/*
FILE* f = Platform::OpenFile(SRAMPath, "r+b");
if (f)
{
fseek(f, addr, SEEK_SET);
fwrite((u8*)&SRAM[addr], 2, 1, f);
fclose(f);
}*/
}
}
void Write32(u32 addr, u32 val)
{
u32 prev = *(u32*)&SRAM[addr];
if (prev != val)
{
*(u32*)&SRAM[addr] = val;/*
FILE* f = Platform::OpenFile(SRAMPath, "r+b");
if (f)
{
fseek(f, addr, SEEK_SET);
fwrite((u8*)&SRAM[addr], 3, 1, f);
fclose(f);
}*/
}
}
}

View File

@ -29,6 +29,10 @@ namespace GBACart_SRAM
extern u8* SRAM;
extern u32 SRAMLength;
void Write8(u32 addr, u8 val);
void Write16(u32 addr, u16 val);
void Write32(u32 addr, u32 val);
}

View File

@ -1802,6 +1802,14 @@ void ARM9Write8(u32 addr, u8 val)
case 0x07000000:
// checkme
return;
case 0x0A000000:
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write8(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
printf("unknown arm9 write8 %08X %02X\n", addr, val);
@ -1845,6 +1853,14 @@ void ARM9Write16(u32 addr, u16 val)
if (!(PowerControl9 & ((addr & 0x400) ? (1<<9) : (1<<1)))) return;
*(u16*)&GPU::OAM[addr & 0x7FF] = val;
return;
case 0x0A000000:
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write16(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
//printf("unknown arm9 write16 %08X %04X\n", addr, val);
@ -1888,6 +1904,14 @@ void ARM9Write32(u32 addr, u32 val)
if (!(PowerControl9 & ((addr & 0x400) ? (1<<9) : (1<<1)))) return;
*(u32*)&GPU::OAM[addr & 0x7FF] = val;
return;
case 0x0A000000:
if (ExMemCnt[0] & (1<<7)) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write32(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
printf("unknown arm9 write32 %08X %08X | %08X\n", addr, val, ARM9->R[15]);
@ -2152,6 +2176,14 @@ void ARM7Write8(u32 addr, u8 val)
case 0x06800000:
GPU::WriteVRAM_ARM7<u8>(addr, val);
return;
case 0x0A000000:
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write8(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
printf("unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]);
@ -2198,6 +2230,14 @@ void ARM7Write16(u32 addr, u16 val)
case 0x06800000:
GPU::WriteVRAM_ARM7<u16>(addr, val);
return;
case 0x0A000000:
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write16(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
//printf("unknown arm7 write16 %08X %04X @ %08X\n", addr, val, ARM7->R[15]);
@ -2245,6 +2285,14 @@ void ARM7Write32(u32 addr, u32 val)
case 0x06800000:
GPU::WriteVRAM_ARM7<u32>(addr, val);
return;
case 0x0A000000:
if (!(ExMemCnt[0] & (1<<7))) return; // deselected CPU, skip the write
if (GBACart::CartInserted)
{
GBACart_SRAM::Write32(addr & (GBACart_SRAM::SRAMLength-1), val);
}
return;
}
//printf("unknown arm7 write32 %08X %08X @ %08X\n", addr, val, ARM7->R[15]);