Skip to content

Commit f5cc543

Browse files
committed
automate "full BIOS boot" based on BIOS checksums
1 parent 8104a20 commit f5cc543

8 files changed

Lines changed: 113 additions & 125 deletions

File tree

src/Args.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ struct DSiArgs final : public NDSArgs
135135
/// Defaults to std::nullopt, which means no SD card.
136136
std::optional<FATStorage> DSiSDCard;
137137

138-
bool FullBIOSBoot = false;
139138
bool DSPHLE = false;
140139
};
141140
}

src/DSi.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ DSi::DSi(DSiArgs&& args, void* userdata) noexcept :
116116
NWRAM_B = JIT.Memory.GetNWRAM_B();
117117
NWRAM_C = JIT.Memory.GetNWRAM_C();
118118

119-
SetFullBIOSBoot(args.FullBIOSBoot);
120119
SetDSPHLE(args.DSPHLE);
121120
}
122121

@@ -130,6 +129,20 @@ DSi::~DSi() noexcept
130129

131130
void DSi::Reset()
132131
{
132+
// determine if we can do a full BIOS boot
133+
// if we have incomplete BIOS dumps, we need to manually load boot2 from NAND
134+
135+
u32 crc_low[2], crc_full[2];
136+
crc_low[0] = CRC32(ARM9iBIOS.data(), 0x8000);
137+
crc_low[1] = CRC32(ARM7iBIOS.data(), 0x8000);
138+
crc_full[0] = CRC32(ARM9iBIOS.data(), 0x10000);
139+
crc_full[1] = CRC32(ARM7iBIOS.data(), 0x10000);
140+
141+
bool bios9full = (crc_low[0] != ARM9iBIOSLowCRC32) || (crc_full[0] == ARM9iBIOSCRC32);
142+
bool bios7full = (crc_low[1] != ARM7iBIOSLowCRC32) || (crc_full[1] == ARM7iBIOSCRC32);
143+
FullBIOSBoot = bios9full && bios7full;
144+
Log(LogLevel::Debug, "DSi: full BIOS boot = %d\n", FullBIOSBoot);
145+
133146
//ARM9.CP15Write(0x910, 0x0D00000A);
134147
//ARM9.CP15Write(0x911, 0x00000020);
135148
//ARM9.CP15Write(0x100, ARM9.CP15Read(0x100) | 0x00050000);
@@ -165,6 +178,7 @@ void DSi::Reset()
165178
SCFG_BIOS = 0x0101;
166179
ARM7BIOSProt = 0x20;
167180
}
181+
168182
SCFG_Clock9 = 0x0187; // CHECKME
169183
SCFG_Clock7 = 0x0187;
170184
SCFG_EXT[0] = 0x8307F100;
@@ -739,6 +753,7 @@ void DSi::SoftReset()
739753
{
740754
SCFG_BIOS = 0x0101;
741755
}
756+
742757
SCFG_Clock9 = 0x0187; // CHECKME
743758
SCFG_Clock7 = 0x0187;
744759
SCFG_EXT[0] = 0x8307F100;

src/DSi.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,11 @@ class DSi final : public NDS
183183
u8 GPIO_IE;
184184
u8 GPIO_WiFi;
185185

186-
bool GetFullBIOSBoot() const noexcept { return FullBIOSBoot; }
187-
void SetFullBIOSBoot(bool full) noexcept { FullBIOSBoot = full; }
188-
189186
void SetDSPHLE(bool hle);
187+
190188
private:
191189
bool FullBIOSBoot;
190+
192191
void Set_SCFG_Clock9(u16 val);
193192
void Set_SCFG_MC(u32 val);
194193
void DecryptModcryptArea(u32 offset, u32 size, const u8* iv);

src/MemConstants.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ constexpr u32 ARM7BIOSSize = 0x4000;
3232
constexpr u32 DSiBIOSSize = 0x10000;
3333
constexpr u32 ITCMPhysicalSize = 0x8000;
3434
constexpr u32 DTCMPhysicalSize = 0x4000;
35+
3536
constexpr u32 ARM7BIOSCRC32 = 0x1280f0d5;
3637
constexpr u32 ARM9BIOSCRC32 = 0x2ab23573;
38+
39+
// CRC's for the low 32K BIOS regions
40+
constexpr u32 ARM7iBIOSLowCRC32 = 0x5434691D;
41+
constexpr u32 ARM9iBIOSLowCRC32 = 0x11E7C1EA;
42+
43+
// CRC's for the full BIOS
44+
constexpr u32 ARM7iBIOSCRC32 = 0x4316CC42;
45+
constexpr u32 ARM9iBIOSCRC32 = 0xBAE84F6C;
3746
}
3847

3948
#endif // MELONDS_MEMCONSTANTS_H

src/frontend/qt_sdl/Config.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ LegacyEntry LegacyFile[] =
316316
{"DSiBatteryLevel", 0, "DSi.Battery.Level", true},
317317
{"DSiBatteryCharging", 1, "DSi.Battery.Charging", true},
318318

319-
{"DSiFullBIOSBoot", 1, "DSi.FullBIOSBoot", true},
320-
321319
#ifdef GDBSTUB_ENABLED
322320
{"GdbEnabled", 1, "Gdb.Enabled", false},
323321
{"GdbPortARM7", 0, "Gdb.ARM7.Port", true},

src/frontend/qt_sdl/EmuInstance.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -921,15 +921,6 @@ std::unique_ptr<DSiBIOSImage> EmuInstance::loadDSiARM9BIOS() noexcept
921921
FileRead(bios->data(), bios->size(), 1, f);
922922
CloseFile(f);
923923

924-
if (!globalCfg.GetBool("DSi.FullBIOSBoot"))
925-
{
926-
// herp
927-
*(u32*)bios->data() = 0xEAFFFFFE; // overwrites the reset vector
928-
929-
// TODO!!!!
930-
// hax the upper 32K out of the goddamn DSi
931-
// done that :) -pcy
932-
}
933924
Log(Info, "ARM9i BIOS loaded from %s\n", path.c_str());
934925
return bios;
935926
}
@@ -948,15 +939,6 @@ std::unique_ptr<DSiBIOSImage> EmuInstance::loadDSiARM7BIOS() noexcept
948939
FileRead(bios->data(), bios->size(), 1, f);
949940
CloseFile(f);
950941

951-
if (!globalCfg.GetBool("DSi.FullBIOSBoot"))
952-
{
953-
// herp
954-
*(u32*)bios->data() = 0xEAFFFFFE; // overwrites the reset vector
955-
956-
// TODO!!!!
957-
// hax the upper 32K out of the goddamn DSi
958-
// done that :) -pcy
959-
}
960942
Log(Info, "ARM7i BIOS loaded from %s\n", path.c_str());
961943
return bios;
962944
}
@@ -1348,7 +1330,6 @@ bool EmuInstance::updateConsole() noexcept
13481330
std::move(arm7ibios),
13491331
std::move(*nand),
13501332
std::move(sdcard),
1351-
globalCfg.GetBool("DSi.FullBIOSBoot"),
13521333
globalCfg.GetBool("DSi.DSP.HLE")
13531334
};
13541335

@@ -1389,7 +1370,6 @@ bool EmuInstance::updateConsole() noexcept
13891370
DSi* dsi = (DSi*)nds;
13901371
DSiArgs& _dsiargs = *dsiargs;
13911372

1392-
dsi->SetFullBIOSBoot(_dsiargs.FullBIOSBoot);
13931373
dsi->SetDSPHLE(_dsiargs.DSPHLE);
13941374
dsi->ARM7iBIOS = *_dsiargs.ARM7iBIOS;
13951375
dsi->ARM9iBIOS = *_dsiargs.ARM9iBIOS;

src/frontend/qt_sdl/EmuSettingsDialog.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
140140
ui->txtDLDIFolder->setText(cfg.GetQString("DLDI.FolderPath"));
141141
on_cbDLDIEnable_toggled();
142142

143-
ui->cbDSiFullBIOSBoot->setChecked(cfg.GetBool("DSi.FullBIOSBoot"));
144143
ui->cbDSPHLE->setChecked(cfg.GetBool("DSi.DSP.HLE"));
145144

146145
ui->cbDSiSDEnable->setChecked(cfg.GetBool("DSi.SD.Enable"));
@@ -275,7 +274,6 @@ void EmuSettingsDialog::done(int r)
275274
cfg.SetQString("DSi.FirmwarePath", ui->txtDSiFirmwarePath->text());
276275
cfg.SetQString("DSi.NANDPath", ui->txtDSiNANDPath->text());
277276

278-
cfg.SetBool("DSi.FullBIOSBoot", ui->cbDSiFullBIOSBoot->isChecked());
279277
cfg.SetBool("DSi.DSP.HLE", ui->cbDSPHLE->isChecked());
280278

281279
cfg.SetBool("DSi.SD.Enable", ui->cbDSiSDEnable->isChecked());

0 commit comments

Comments
 (0)