Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ARMJIT_Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,12 @@ bool ARMJIT_Memory::GetMirrorLocation(int region, u32 num, u32 addr, u32& memory
}
return false;
case memregion_MainRAM:
// 0x02xxxxxx region is limited to 16MiB
if (addr < 0x0C000000) {
mirrorStart = addr & ~(NDS.MainRAMMask & 0xFFFFFF);
mirrorSize = (NDS.MainRAMMask & 0xFFFFFF) + 1;
return true;
}
mirrorStart = addr & ~NDS.MainRAMMask;
mirrorSize = NDS.MainRAMMask + 1;
return true;
Expand Down Expand Up @@ -1283,6 +1289,8 @@ int ARMJIT_Memory::ClassifyAddress9(u32 addr) const noexcept
return memregion_VRAM;
case 0x0C000000:
return (NDS.ConsoleType==1) ? memregion_MainRAM : memregion_Other;
case 0x0D000000:
return (NDS.ConsoleType==1 && NDS.MainRAMMask>=0x1FFFFFF) ? memregion_MainRAM : memregion_Other;
default:
return memregion_Other;
}
Expand Down Expand Up @@ -1341,6 +1349,9 @@ int ARMJIT_Memory::ClassifyAddress7(u32 addr) const noexcept
case 0x0C000000:
case 0x0C800000:
return (NDS.ConsoleType==1) ? memregion_MainRAM : memregion_Other;
case 0x0D000000:
case 0x0D800000:
return (NDS.ConsoleType==1 && NDS.MainRAMMask>=0x1FFFFFF) ? memregion_MainRAM : memregion_Other;
default:
return memregion_Other;
}
Expand Down
123 changes: 118 additions & 5 deletions src/DSi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const u32 NDMAModes[] =
}*/

DSi::DSi(DSiArgs&& args, void* userdata) noexcept :
NDS(std::move(args), 1, userdata),
NDS(std::move(args), 1, 0, userdata),
NDMAs {
DSi_NDMA(0, 0, *this),
DSi_NDMA(0, 1, *this),
Expand Down Expand Up @@ -1278,15 +1278,18 @@ void DSi::ApplyNewRAMSize(u32 size)
switch (size)
{
case 0:
case 1:
case 1: // TODO(shinyquagsire23): Is 1 actually 8MiB (NDS devkit)?
MainRAMMask = 0x3FFFFF;
Log(LogLevel::Debug, "RAM: 4MB\n");
break;
case 2:
case 3: // TODO: debug console w/ 32MB?
case 2: // Retail 16MiB
MainRAMMask = 0xFFFFFF;
Log(LogLevel::Debug, "RAM: 16MB\n");
break;
case 3: // Debug/3DS 32MiB
MainRAMMask = 0x1FFFFFF;
Log(LogLevel::Debug, "RAM: 32MB\n");
break;
}
}

Expand Down Expand Up @@ -1367,6 +1370,12 @@ u8 DSi::ARM9Read8(u32 addr)

case 0x0C000000:
return *(u8*)&MainRAM[addr & MainRAMMask];
case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u8*)&MainRAM[addr & MainRAMMask];
}

return NDS::ARM9Read8(addr);
Expand Down Expand Up @@ -1418,6 +1427,12 @@ u16 DSi::ARM9Read16(u32 addr)

case 0x0C000000:
return *(u16*)&MainRAM[addr & MainRAMMask];
case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u16*)&MainRAM[addr & MainRAMMask];
}

return NDS::ARM9Read16(addr);
Expand Down Expand Up @@ -1474,6 +1489,12 @@ u32 DSi::ARM9Read32(u32 addr)

case 0x0C000000:
return *(u32*)&MainRAM[addr & MainRAMMask];
case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u32*)&MainRAM[addr & MainRAMMask];
}

return NDS::ARM9Read32(addr);
Expand Down Expand Up @@ -1569,6 +1590,14 @@ void DSi::ARM9Write8(u32 addr, u8 val)
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u8*)&MainRAM[addr & MainRAMMask] = val;
return;
case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u8*)&MainRAM[addr & MainRAMMask] = val;
return;
}

return NDS::ARM9Write8(addr, val);
Expand Down Expand Up @@ -1654,6 +1683,14 @@ void DSi::ARM9Write16(u32 addr, u16 val)
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u16*)&MainRAM[addr & MainRAMMask] = val;
return;
case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u16*)&MainRAM[addr & MainRAMMask] = val;
return;
}

return NDS::ARM9Write16(addr, val);
Expand Down Expand Up @@ -1739,6 +1776,15 @@ void DSi::ARM9Write32(u32 addr, u32 val)
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u32*)&MainRAM[addr & MainRAMMask] = val;
return;

case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<0, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u32*)&MainRAM[addr & MainRAMMask] = val;
return;
}

return NDS::ARM9Write32(addr, val);
Expand All @@ -1754,6 +1800,16 @@ bool DSi::ARM9GetMemRegion(u32 addr, bool write, MemRegion* region)
region->Mem = MainRAM;
region->Mask = MainRAMMask;
return true;

case 0x0D000000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
region->Mem = NULL;
return false;
}
region->Mem = MainRAM;
region->Mask = MainRAMMask;
return true;
}

if ((addr & 0xFFFF0000) == 0xFFFF0000 && !write)
Expand Down Expand Up @@ -1835,6 +1891,13 @@ u8 DSi::ARM7Read8(u32 addr)
case 0x0C000000:
case 0x0C800000:
return *(u8*)&MainRAM[addr & MainRAMMask];
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (MainRAMPresent<=0x1000000 && MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u8*)&MainRAM[addr & MainRAMMask];
}

return NDS::ARM7Read8(addr);
Expand Down Expand Up @@ -1894,7 +1957,14 @@ u16 DSi::ARM7Read16(u32 addr)

case 0x0C000000:
case 0x0C800000:
return *(u16*)&MainRAM[addr & MainRAMMask];
return *(u16*)&MainRAM[addr & NDS::MainRAMMask];
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u16*)&MainRAM[addr & NDS::MainRAMMask];
}

return NDS::ARM7Read16(addr);
Expand Down Expand Up @@ -1954,6 +2024,13 @@ u32 DSi::ARM7Read32(u32 addr)
case 0x0C000000:
case 0x0C800000:
return *(u32*)&NDS::MainRAM[addr & NDS::MainRAMMask];
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
return *(u32*)&NDS::MainRAM[addr & NDS::MainRAMMask];
}

return NDS::ARM7Read32(addr);
Expand Down Expand Up @@ -2042,6 +2119,15 @@ void DSi::ARM7Write8(u32 addr, u8 val)
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u8*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u8*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
}

return NDS::ARM7Write8(addr, val);
Expand Down Expand Up @@ -2132,6 +2218,15 @@ void DSi::ARM7Write16(u32 addr, u16 val)
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u16*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u16*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
}

return NDS::ARM7Write16(addr, val);
Expand Down Expand Up @@ -2222,6 +2317,15 @@ void DSi::ARM7Write32(u32 addr, u32 val)
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u32*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
JIT.CheckAndInvalidate<1, ARMJIT_Memory::memregion_MainRAM>(addr);
*(u32*)&NDS::MainRAM[addr & NDS::MainRAMMask] = val;
return;
}

return NDS::ARM7Write32(addr, val);
Expand All @@ -2239,6 +2343,15 @@ bool DSi::ARM7GetMemRegion(u32 addr, bool write, MemRegion* region)
region->Mem = NDS::MainRAM;
region->Mask = NDS::MainRAMMask;
return true;
case 0x0D000000:
case 0x0D800000:
// open-bus behavior
if (NDS::MainRAMPresent<=0x1000000 && NDS::MainRAMMask>=0x1FFFFFF) {
break;
}
region->Mem = NDS::MainRAM;
region->Mask = NDS::MainRAMMask;
return true;
}

// BIOS. ARM7 PC has to be within range.
Expand Down
3 changes: 2 additions & 1 deletion src/MemConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

namespace melonDS
{
constexpr u32 MainRAMMaxSize = 0x1000000;
constexpr u32 MainRAMPrimaryMappingMaxSize = 0x1000000;
constexpr u32 MainRAMMaxSize = 0x2000000;
constexpr u32 SharedWRAMSize = 0x8000;
constexpr u32 ARM7WRAMSize = 0x10000;
constexpr u32 NWRAMSize = 0x40000;
Expand Down
9 changes: 6 additions & 3 deletions src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ NDS::NDS() noexcept :
{
}

NDS::NDS(NDSArgs&& args, int type, void* userdata) noexcept :
NDS::NDS(NDSArgs&& args, int type, int debugbc, void* userdata) noexcept :
ConsoleType(type),
DebugBoardConfig(debugbc),
UserData(userdata),
ARM7BIOS(*args.ARM7BIOS),
ARM9BIOS(*args.ARM9BIOS),
Expand Down Expand Up @@ -446,12 +447,14 @@ void NDS::Reset()
// BIOS files are now loaded by the frontend

ARM9ClockShift = 2;
MainRAMMask = 0xFFFFFF;
MainRAMMask = DebugBoardConfig ? 0x1FFFFFF : 0x1FFFFFF; // Intentional default
MainRAMPresent = DebugBoardConfig ? 0x2000000 : 0x1000000; // 32MiB and 16MiB
}
else
{
ARM9ClockShift = 1;
MainRAMMask = 0x3FFFFF;
MainRAMMask = DebugBoardConfig ? 0x7FFFFF : 0x3FFFFF;
MainRAMPresent = DebugBoardConfig ? 0x800000 : 0x400000; // 8MiB and 4MiB
}
// has to be called before InitTimings
// otherwise some PU settings are completely
Expand Down
8 changes: 4 additions & 4 deletions src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class NDS
void* UserData;

int ConsoleType;
int DebugBoardConfig;
int CurCPU;

SchedEvent SchedList[Event_MAX] {};
Expand Down Expand Up @@ -293,8 +294,7 @@ class NDS

u8* MainRAM;
u32 MainRAMMask;

const u32 MainRAMMaxSize = 0x1000000;
u32 MainRAMPresent;

const u32 SharedWRAMSize = 0x8000;
u8* SharedWRAM;
Expand Down Expand Up @@ -547,7 +547,7 @@ class NDS
u32 RunFrame();

public:
NDS(NDSArgs&& args, void* userdata = nullptr) noexcept : NDS(std::move(args), 0, userdata) {}
NDS(NDSArgs&& args, void* userdata = nullptr) noexcept : NDS(std::move(args), 0, 0, userdata) {}
NDS() noexcept;
virtual ~NDS() noexcept;
NDS(const NDS&) = delete;
Expand All @@ -557,7 +557,7 @@ class NDS

static thread_local NDS* Current;
protected:
explicit NDS(NDSArgs&& args, int type, void* userdata) noexcept;
explicit NDS(NDSArgs&& args, int type, int debugbc, void* userdata) noexcept;
virtual void DoSavestateExtra(Savestate* file) {}
};

Expand Down
1 change: 1 addition & 0 deletions src/frontend/qt_sdl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ DefaultList<int> DefaultInts =
RangeList IntRanges =
{
{"Emu.ConsoleType", {0, 1}},
{"Emu.DebugBoardConfig", {0, 1}},
{"3D.Renderer", {0, renderer3D_Max-1}},
{"Screen.VSyncInterval", {1, 20}},
{"3D.GL.ScaleFactor", {1, 16}},
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ EmuInstance::EmuInstance(int inst) : deleting(false),
localCfg(Config::GetLocalTable(inst))
{
consoleType = globalCfg.GetInt("Emu.ConsoleType");
debugBoardConfig = globalCfg.GetInt("Emu.DebugBoardConfig");

ndsSave = nullptr;
cartType = -1;
Expand Down Expand Up @@ -1240,6 +1241,7 @@ bool EmuInstance::updateConsole() noexcept
{
// update the console type
consoleType = globalCfg.GetInt("Emu.ConsoleType");
debugBoardConfig = globalCfg.GetInt("Emu.DebugBoardConfig");

// Let's get the cart we want to use;
// if we want to keep the cart, we'll eject it from the existing console first.
Expand Down Expand Up @@ -1353,7 +1355,7 @@ bool EmuInstance::updateConsole() noexcept
}

renderLock.lock();
if ((!nds) || (consoleType != nds->ConsoleType))
if ((!nds) || (consoleType != nds->ConsoleType) || (debugBoardConfig != nds->DebugBoardConfig))
{
if (nds)
{
Expand All @@ -1366,6 +1368,7 @@ bool EmuInstance::updateConsole() noexcept
else
nds = new NDS(std::move(ndsargs), this);

nds->DebugBoardConfig = debugBoardConfig;
nds->Reset();
loadRTCData();
//emuThread->updateVideoRenderer(); // not actually needed?
Expand Down
Loading
Loading