aboutsummaryrefslogtreecommitdiff
path: root/src/SPI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SPI.cpp')
-rw-r--r--src/SPI.cpp94
1 files changed, 18 insertions, 76 deletions
diff --git a/src/SPI.cpp b/src/SPI.cpp
index b3e5b4e..3974e31 100644
--- a/src/SPI.cpp
+++ b/src/SPI.cpp
@@ -59,31 +59,22 @@ u16 CRC16(const u8* data, u32 len, u32 start)
bool FirmwareMem::VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset)
{
- u16 crc_stored = *(u16*)&Firmware->Buffer()[crcoffset];
- u16 crc_calced = CRC16(&Firmware->Buffer()[offset], len, start);
+ u16 crc_stored = *(u16*)&FirmwareData.Buffer()[crcoffset];
+ u16 crc_calced = CRC16(&FirmwareData.Buffer()[offset], len, start);
return (crc_stored == crc_calced);
}
-FirmwareMem::FirmwareMem(melonDS::NDS& nds) : SPIDevice(nds)
+FirmwareMem::FirmwareMem(melonDS::NDS& nds, melonDS::Firmware&& firmware) : SPIDevice(nds), FirmwareData(std::move(firmware))
{
}
-FirmwareMem::~FirmwareMem()
-{
- RemoveFirmware();
-}
+FirmwareMem::~FirmwareMem() = default;
void FirmwareMem::Reset()
{
- if (!Firmware)
- {
- Log(LogLevel::Warn, "SPI firmware: no firmware loaded! Using default\n");
- Firmware = std::make_unique<class Firmware>(NDS.ConsoleType);
- }
-
// fix touchscreen coords
- for (auto& u : Firmware->GetUserData())
+ for (auto& u : FirmwareData.GetUserData())
{
u.TouchCalibrationADC1[0] = 0;
u.TouchCalibrationADC1[1] = 0;
@@ -95,17 +86,17 @@ void FirmwareMem::Reset()
u.TouchCalibrationPixel2[1] = 191;
}
- Firmware->UpdateChecksums();
+ FirmwareData.UpdateChecksums();
// disable autoboot
//Firmware[userdata+0x64] &= 0xBF;
- MacAddress mac = Firmware->GetHeader().MacAddr;
+ MacAddress mac = FirmwareData.GetHeader().MacAddr;
Log(LogLevel::Info, "MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
// verify shit
- u32 mask = Firmware->Mask();
- Log(LogLevel::Debug, "FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware->Buffer()[0x2C], 0x2A)?"GOOD":"BAD");
+ u32 mask = FirmwareData.Mask();
+ Log(LogLevel::Debug, "FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&FirmwareData.Buffer()[0x2C], 0x2A)?"GOOD":"BAD");
Log(LogLevel::Debug, "FW: AP1 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FA00&mask, 0xFE, 0x7FAFE&mask)?"GOOD":"BAD");
Log(LogLevel::Debug, "FW: AP2 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FB00&mask, 0xFE, 0x7FBFE&mask)?"GOOD":"BAD");
Log(LogLevel::Debug, "FW: AP3 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FC00&mask, 0xFE, 0x7FCFE&mask)?"GOOD":"BAD");
@@ -136,8 +127,8 @@ void FirmwareMem::DoSavestate(Savestate* file)
void FirmwareMem::SetupDirectBoot()
{
- const auto& header = Firmware->GetHeader();
- const auto& userdata = Firmware->GetEffectiveUserData();
+ const auto& header = FirmwareData.GetHeader();
+ const auto& userdata = FirmwareData.GetEffectiveUserData();
if (NDS.ConsoleType == 1)
{
// The ARMWrite methods are virtual, they'll delegate to DSi if necessary
@@ -163,58 +154,9 @@ void FirmwareMem::SetupDirectBoot()
}
}
-const class Firmware* FirmwareMem::GetFirmware()
-{
- return Firmware.get();
-}
-
bool FirmwareMem::IsLoadedFirmwareBuiltIn()
{
- return Firmware->GetHeader().Identifier == GENERATED_FIRMWARE_IDENTIFIER;
-}
-
-bool FirmwareMem::InstallFirmware(class Firmware&& firmware)
-{
- if (!firmware.Buffer())
- {
- Log(LogLevel::Error, "SPI firmware: firmware buffer is null!\n");
- return false;
- }
-
- Firmware = std::make_unique<class Firmware>(std::move(firmware));
-
- FirmwareIdentifier id = Firmware->GetHeader().Identifier;
- Log(LogLevel::Debug, "Installed firmware (Identifier: %c%c%c%c)\n", id[0], id[1], id[2], id[3]);
-
- return true;
-}
-
-bool FirmwareMem::InstallFirmware(std::unique_ptr<class Firmware>&& firmware)
-{
- if (!firmware)
- {
- Log(LogLevel::Error, "SPI firmware: firmware is null!\n");
- return false;
- }
-
- if (!firmware->Buffer())
- {
- Log(LogLevel::Error, "SPI firmware: firmware buffer is null!\n");
- return false;
- }
-
- Firmware = std::move(firmware);
-
- FirmwareIdentifier id = Firmware->GetHeader().Identifier;
- Log(LogLevel::Debug, "Installed firmware (Identifier: %c%c%c%c)\n", id[0], id[1], id[2], id[3]);
-
- return true;
-}
-
-void FirmwareMem::RemoveFirmware()
-{
- Firmware.reset();
- Log(LogLevel::Debug, "Removed installed firmware (if any)\n");
+ return FirmwareData.GetHeader().Identifier == GENERATED_FIRMWARE_IDENTIFIER;
}
void FirmwareMem::Write(u8 val)
@@ -256,7 +198,7 @@ void FirmwareMem::Write(u8 val)
}
else
{
- Data = Firmware->Buffer()[Addr & Firmware->Mask()];
+ Data = FirmwareData.Buffer()[Addr & FirmwareData.Mask()];
Addr++;
}
@@ -279,7 +221,7 @@ void FirmwareMem::Write(u8 val)
}
else
{
- Firmware->Buffer()[Addr & Firmware->Mask()] = val;
+ FirmwareData.Buffer()[Addr & FirmwareData.Mask()] = val;
Data = val;
Addr++;
}
@@ -314,11 +256,11 @@ void FirmwareMem::Release()
{ // If the SPI firmware chip just finished a write...
// We only notify the frontend of changes to the Wi-fi/userdata settings region
// (although it might still decide to flush the whole thing)
- u32 wifioffset = Firmware->GetWifiAccessPointOffset();
+ u32 wifioffset = FirmwareData.GetWifiAccessPointOffset();
// Request that the start of the Wi-fi/userdata settings region
// through the end of the firmware blob be flushed to disk
- Platform::WriteFirmware(*Firmware, wifioffset, Firmware->Length() - wifioffset);
+ Platform::WriteFirmware(FirmwareData, wifioffset, FirmwareData.Length() - wifioffset);
}
SPIDevice::Release();
@@ -530,11 +472,11 @@ void TSC::Write(u8 val)
-SPIHost::SPIHost(melonDS::NDS& nds) : NDS(nds)
+SPIHost::SPIHost(melonDS::NDS& nds, Firmware&& firmware) : NDS(nds)
{
NDS.RegisterEventFunc(Event_SPITransfer, 0, MemberEventFunc(SPIHost, TransferDone));
- Devices[SPIDevice_FirmwareMem] = new FirmwareMem(NDS);
+ Devices[SPIDevice_FirmwareMem] = new FirmwareMem(NDS, std::move(firmware));
Devices[SPIDevice_PowerMan] = new PowerMan(NDS);
if (NDS.ConsoleType == 1)