aboutsummaryrefslogtreecommitdiff
path: root/src/SPI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SPI.cpp')
-rw-r--r--src/SPI.cpp52
1 files changed, 42 insertions, 10 deletions
diff --git a/src/SPI.cpp b/src/SPI.cpp
index 1a5873e..ac40707 100644
--- a/src/SPI.cpp
+++ b/src/SPI.cpp
@@ -22,12 +22,14 @@
#include "Config.h"
#include "NDS.h"
#include "SPI.h"
+#include "DSi_SPI_TSC.h"
#include "Platform.h"
namespace SPI_Firmware
{
+char FirmwarePath[1024];
u8* Firmware;
u32 FirmwareLength;
u32 FirmwareMask;
@@ -76,6 +78,7 @@ bool VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset)
bool Init()
{
+ memset(FirmwarePath, 0, sizeof(FirmwarePath));
Firmware = NULL;
return true;
}
@@ -90,10 +93,15 @@ void Reset()
if (Firmware) delete[] Firmware;
Firmware = NULL;
- FILE* f = Platform::OpenLocalFile("firmware.bin", "rb");
+ if (NDS::ConsoleType == 1)
+ strncpy(FirmwarePath, Config::DSiFirmwarePath, 1023);
+ else
+ strncpy(FirmwarePath, Config::FirmwarePath, 1023);
+
+ FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb");
if (!f)
{
- printf("firmware.bin not found\n");
+ printf("Firmware not found\n");
// TODO: generate default firmware
return;
@@ -129,7 +137,11 @@ void Reset()
fclose(f);
// take a backup
- const char* firmbkp = "firmware.bin.bak";
+ char firmbkp[1028];
+ int fplen = strlen(FirmwarePath);
+ strncpy(&firmbkp[0], FirmwarePath, fplen);
+ strncpy(&firmbkp[fplen], ".bak", 1028-fplen);
+ firmbkp[fplen+4] = '\0';
f = Platform::OpenLocalFile(firmbkp, "rb");
if (f) fclose(f);
else
@@ -151,6 +163,7 @@ void Reset()
UserSettings = userdata;
// fix touchscreen coords
+ #if 0
*(u16*)&Firmware[userdata+0x58] = 0;
*(u16*)&Firmware[userdata+0x5A] = 0;
Firmware[userdata+0x5C] = 0;
@@ -173,12 +186,12 @@ void Reset()
Firmware[0x39] = rand()&0xFF;
Firmware[0x3A] = rand()&0xFF;
Firmware[0x3B] = rand()&0xFF;
-
+#endif
printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
Firmware[0x36], Firmware[0x37], Firmware[0x38],
Firmware[0x39], Firmware[0x3A], Firmware[0x3B]);
- *(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000);
+ //*(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000);
// verify shit
printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD");
@@ -225,6 +238,7 @@ void SetupDirectBoot()
u8 GetConsoleType() { return Firmware[0x1D]; }
u8 GetWifiVersion() { return Firmware[0x2F]; }
u8 GetRFVersion() { return Firmware[0x40]; }
+u8* GetWifiMAC() { return &Firmware[0x36]; }
u8 Read()
{
@@ -325,7 +339,7 @@ void Write(u8 val, u32 hold)
if (!hold && (CurCmd == 0x02 || CurCmd == 0x0A))
{
- FILE* f = Platform::OpenLocalFile("firmware.bin", "r+b");
+ FILE* f = Platform::OpenLocalFile(FirmwarePath, "r+b");
if (f)
{
u32 cutoff = 0x7FA00 & FirmwareMask;
@@ -581,7 +595,7 @@ namespace SPI
u16 Cnt;
-u32 CurDevice;
+u32 CurDevice; // remove me
bool Init()
@@ -589,6 +603,7 @@ bool Init()
if (!SPI_Firmware::Init()) return false;
if (!SPI_Powerman::Init()) return false;
if (!SPI_TSC::Init()) return false;
+ if (!DSi_SPI_TSC::Init()) return false;
return true;
}
@@ -598,6 +613,7 @@ void DeInit()
SPI_Firmware::DeInit();
SPI_Powerman::DeInit();
SPI_TSC::DeInit();
+ DSi_SPI_TSC::DeInit();
}
void Reset()
@@ -607,6 +623,7 @@ void Reset()
SPI_Firmware::Reset();
SPI_Powerman::Reset();
SPI_TSC::Reset();
+ if (NDS::ConsoleType == 1) DSi_SPI_TSC::Reset();
}
void DoSavestate(Savestate* file)
@@ -619,6 +636,7 @@ void DoSavestate(Savestate* file)
SPI_Firmware::DoSavestate(file);
SPI_Powerman::DoSavestate(file);
SPI_TSC::DoSavestate(file);
+ if (NDS::ConsoleType == 1) DSi_SPI_TSC::DoSavestate(file);
}
@@ -632,7 +650,12 @@ void WriteCnt(u16 val)
{
case 0x0000: SPI_Powerman::Hold = 0; break;
case 0x0100: SPI_Firmware::Hold = 0; break;
- case 0x0200: SPI_TSC::DataPos = 0; break;
+ case 0x0200:
+ if (NDS::ConsoleType == 1)
+ DSi_SPI_TSC::DataPos = 0;
+ else
+ SPI_TSC::DataPos = 0;
+ break;
}
}
@@ -658,7 +681,11 @@ u8 ReadData()
{
case 0x0000: return SPI_Powerman::Read();
case 0x0100: return SPI_Firmware::Read();
- case 0x0200: return SPI_TSC::Read();
+ case 0x0200:
+ if (NDS::ConsoleType == 1)
+ return DSi_SPI_TSC::Read();
+ else
+ return SPI_TSC::Read();
default: return 0;
}
}
@@ -674,7 +701,12 @@ void WriteData(u8 val)
{
case 0x0000: SPI_Powerman::Write(val, Cnt&(1<<11)); break;
case 0x0100: SPI_Firmware::Write(val, Cnt&(1<<11)); break;
- case 0x0200: SPI_TSC::Write(val, Cnt&(1<<11)); break;
+ case 0x0200:
+ if (NDS::ConsoleType == 1)
+ DSi_SPI_TSC::Write(val, Cnt&(1<<11));
+ else
+ SPI_TSC::Write(val, Cnt&(1<<11));
+ break;
default: printf("SPI to unknown device %04X %02X\n", Cnt, val); break;
}