mirror of
https://github.com/suloku/savegame-manager.git
synced 2026-04-20 14:07:38 -05:00
- move more global variables to global.h/.cpp
- add some parts aimed towards a "download play" mode, which does not rely on launching from a flash card, but from different exploits. It does not work yet (you will get a "missing ini file" error message), but if I ever finish it, it should be possible to run using download play on a DSi/3DS. (Lacking the hardware to test it, it is unlikely it will be finished anytime soon, sorry.) - eliminate many warnings during the build process - modify auxspi.h/.cpp so that it no longer depends on global variables (I hope)
This commit is contained in:
parent
429c4c60c9
commit
863aa2e05d
|
|
@ -82,7 +82,7 @@ int main() {
|
|||
|
||||
setPowerButtonCB(powerButtonCB);
|
||||
|
||||
u32 ime = 0;
|
||||
//u32 ime = 0;
|
||||
// Keep the ARM7 mostly idle
|
||||
while (!exitflag) {
|
||||
if ( 0 == (REG_KEYINPUT & (KEY_SELECT | KEY_START | KEY_L | KEY_R))) {
|
||||
|
|
|
|||
|
|
@ -25,15 +25,14 @@
|
|||
*/
|
||||
|
||||
#include "auxspi.h"
|
||||
#include "auxspi_core.cpp"
|
||||
#include "hardware.h"
|
||||
#include "globals.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using std::max;
|
||||
|
||||
extern u8 *data;
|
||||
extern u32 size_buf;
|
||||
#include "auxspi_core.inc"
|
||||
|
||||
|
||||
// ========================================================
|
||||
|
|
@ -82,10 +81,10 @@ uint8 type2_size()
|
|||
|
||||
// ========================================================
|
||||
|
||||
uint8 auxspi_save_type()
|
||||
uint8 auxspi_save_type(bool ir)
|
||||
{
|
||||
uint32 jedec = auxspi_save_jedec_id(); // 9f
|
||||
int8 sr = auxspi_save_status_register(); // 05
|
||||
uint32 jedec = auxspi_save_jedec_id(ir); // 9f
|
||||
int8 sr = auxspi_save_status_register(ir); // 05
|
||||
|
||||
if ((sr & 0xfd) == 0xF0 && (jedec == 0x00ffffff)) return 1;
|
||||
if ((sr & 0xfd) == 0x00 && (jedec == 0x00ffffff)) return 2;
|
||||
|
|
@ -94,12 +93,12 @@ uint8 auxspi_save_type()
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32 auxspi_save_size()
|
||||
uint32 auxspi_save_size(bool ir)
|
||||
{
|
||||
return 1 << auxspi_save_size_log_2();
|
||||
return 1 << auxspi_save_size_log_2(ir);
|
||||
}
|
||||
|
||||
uint8 auxspi_save_size_log_2()
|
||||
uint8 auxspi_save_size_log_2(bool ir)
|
||||
{
|
||||
uint8 type = auxspi_save_type();
|
||||
switch (type) {
|
||||
|
|
@ -110,17 +109,18 @@ uint8 auxspi_save_size_log_2()
|
|||
return type2_size();
|
||||
break;
|
||||
case 3:
|
||||
return jedec_table(auxspi_save_jedec_id());
|
||||
return jedec_table(auxspi_save_jedec_id(ir));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 auxspi_save_jedec_id()
|
||||
uint32 auxspi_save_jedec_id(bool ir)
|
||||
{
|
||||
uint32 id = 0;
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(0x9f);
|
||||
id |= auxspi_read() << 16;
|
||||
|
|
@ -130,10 +130,11 @@ uint32 auxspi_save_jedec_id()
|
|||
return id;
|
||||
}
|
||||
|
||||
uint8 auxspi_save_status_register()
|
||||
uint8 auxspi_save_status_register(bool ir)
|
||||
{
|
||||
uint8 sr = 0;
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(0x05);
|
||||
sr = auxspi_read();
|
||||
|
|
@ -141,14 +142,15 @@ uint8 auxspi_save_status_register()
|
|||
return sr;
|
||||
}
|
||||
|
||||
void auxspi_read_data(uint32 addr, uint8* buf, uint16 cnt, uint8 type)
|
||||
void auxspi_read_data(uint32 addr, uint8* buf, uint16 cnt, uint8 type, bool ir)
|
||||
{
|
||||
if (type == 0)
|
||||
type = auxspi_save_type();
|
||||
type = auxspi_save_type(ir);
|
||||
if (type == 0)
|
||||
return;
|
||||
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(0x03 | ((type == 1) ? addr>>8<<3 : 0));
|
||||
|
||||
|
|
@ -170,7 +172,7 @@ void auxspi_read_data(uint32 addr, uint8* buf, uint16 cnt, uint8 type)
|
|||
auxspi_close();
|
||||
}
|
||||
|
||||
void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type)
|
||||
void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type, bool ir)
|
||||
{
|
||||
/*
|
||||
if (type == 0)
|
||||
|
|
@ -189,13 +191,15 @@ void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type)
|
|||
// we can only write a finite amount of data at once, so we need a separate loop
|
||||
// for multiple passes.
|
||||
while (addr < addr_end) {
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
// set WEL (Write Enable Latch)
|
||||
auxspi_write(0x06);
|
||||
auxspi_close_lite();
|
||||
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
// send initial "write" command
|
||||
if(type == 1) {
|
||||
|
|
@ -222,7 +226,8 @@ void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type)
|
|||
// wait for programming to finish
|
||||
//auxspi_wait_wip();
|
||||
// wait programming to finish
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(5);
|
||||
do { REG_AUXSPIDATA = 0; auxspi_wait_busy(); } while (REG_AUXSPIDATA & 0x01); // WIP (Write In Progress) ?
|
||||
|
|
@ -233,29 +238,30 @@ void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type)
|
|||
|
||||
void auxspi_disable_infrared()
|
||||
{
|
||||
if (with_infrared)
|
||||
auxspi_disable_infrared_core();
|
||||
auxspi_disable_infrared_core();
|
||||
}
|
||||
|
||||
bool auxspi_has_infrared()
|
||||
{
|
||||
return with_infrared;
|
||||
return (slot_1_type == 1);
|
||||
}
|
||||
|
||||
void auxspi_erase()
|
||||
void auxspi_erase(bool ir)
|
||||
{
|
||||
uint8 type = auxspi_save_type();
|
||||
if (type == 3) {
|
||||
uint8 size;
|
||||
size = 1 << (auxspi_save_size_log_2() - 16);
|
||||
for (int i = 0; i < size; i++) {
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
// set WEL (Write Enable Latch)
|
||||
auxspi_write(0x06);
|
||||
auxspi_close_lite();
|
||||
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(0xd8);
|
||||
auxspi_write(i);
|
||||
|
|
@ -265,7 +271,8 @@ void auxspi_erase()
|
|||
|
||||
// wait for programming to finish
|
||||
//auxspi_wait_wip();
|
||||
auxspi_disable_infrared();
|
||||
if (ir)
|
||||
auxspi_disable_infrared();
|
||||
auxspi_open(0);
|
||||
auxspi_write(5);
|
||||
do { REG_AUXSPIDATA = 0; auxspi_wait_busy(); } while (REG_AUXSPIDATA & 0x01); // WIP (Write In Progress) ?
|
||||
|
|
@ -281,6 +288,7 @@ void auxspi_erase()
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void auxspi_wait_wip()
|
||||
{
|
||||
auxspi_disable_infrared();
|
||||
|
|
@ -292,3 +300,4 @@ void auxspi_wait_wip()
|
|||
} while (sr & 0x01);
|
||||
auxspi_close();
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@
|
|||
|
||||
extern bool with_infrared;
|
||||
|
||||
uint8 auxspi_save_type();
|
||||
uint32 auxspi_save_size();
|
||||
uint8 auxspi_save_size_log_2();
|
||||
uint32 auxspi_save_jedec_id();
|
||||
uint8 auxspi_save_status_register();
|
||||
void auxspi_read_data(uint32 addr, uint8* buf, uint16 cnt, uint8 type = 0);
|
||||
void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type = 0);
|
||||
uint8 auxspi_save_type(bool ir = false);
|
||||
uint32 auxspi_save_size(bool ir = false);
|
||||
uint8 auxspi_save_size_log_2(bool ir = false);
|
||||
uint32 auxspi_save_jedec_id(bool ir = false);
|
||||
uint8 auxspi_save_status_register(bool ir = false);
|
||||
void auxspi_read_data(uint32 addr, uint8* buf, uint16 cnt, uint8 type = 0, bool ir = false);
|
||||
void auxspi_write_data(uint32 addr, uint8 *buf, uint16 cnt, uint8 type = 0, bool ir = false);
|
||||
void auxspi_disable_infrared();
|
||||
void auxspi_erase();
|
||||
void auxspi_wait_wip();
|
||||
void auxspi_erase(bool ir = false);
|
||||
//void auxspi_wait_wip();
|
||||
|
||||
bool auxspi_has_infrared();
|
||||
//void auxspi_gpio_init_save();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* DS cartridges. Nintendo DS and all derivative names are trademarks
|
||||
* by Nintendo. EZFlash 3-in-1 is a trademark by EZFlash.
|
||||
*
|
||||
* auxspi.cpp: A thin reimplementation of the AUXSPI protocol
|
||||
* auxspi_core.inc: A thin reimplementation of the AUXSPI protocol
|
||||
* (low level functions)
|
||||
*
|
||||
* Copyright (C) Pokedoc (2010)
|
||||
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
#include <nds.h>
|
||||
|
||||
extern int ir_delay;
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
inline void auxspi_wait_busy()
|
||||
{
|
||||
|
|
@ -34,12 +34,12 @@
|
|||
#include "hardware.h"
|
||||
#include "fileselect.h"
|
||||
#include "gba.h"
|
||||
|
||||
#include "auxspi_core.cpp"
|
||||
|
||||
#include "globals.h"
|
||||
#include "strings.h"
|
||||
|
||||
#include "auxspi_core.inc"
|
||||
|
||||
|
||||
PrintConsole upperScreen;
|
||||
PrintConsole lowerScreen;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ void displayInit()
|
|||
consoleInit(&lowerScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
|
||||
|
||||
consoleSelect(&upperScreen);
|
||||
iprintf("\n\n\n\n\nDS savegame manager\nVersion 0.2.4 Beta\nBy Pokedoc");
|
||||
iprintf("\n\n\n\n\nDS savegame manager\nVersion 0.2.5 semi-stable\nBy Pokedoc");
|
||||
|
||||
displayPrintState("Press (B) to continue");
|
||||
while (!(keysCurrent() & KEY_B));
|
||||
|
|
@ -100,10 +100,10 @@ void displayPrintUpper()
|
|||
consoleClear();
|
||||
|
||||
// fetch cartridge header (maybe, calling "cardReadHeader" on a FC messes with libfat!)
|
||||
bool flash_card = is_flash_card();
|
||||
bool ir = auxspi_has_infrared();
|
||||
//bool flash_card = is_flash_card();
|
||||
//bool ir = auxspi_has_infrared();
|
||||
sNDSHeader nds;
|
||||
if (!flash_card)
|
||||
if (slot_1_type != 2)
|
||||
cardReadHeader((uint8*)&nds);
|
||||
// search for the correct header
|
||||
/*
|
||||
|
|
@ -143,6 +143,12 @@ void displayPrintUpper()
|
|||
case 4:
|
||||
sprintf(&name[0], "Slot 2");
|
||||
break;
|
||||
case 5:
|
||||
sprintf(&name[0], "Download Play");
|
||||
break;
|
||||
default:
|
||||
sprintf(&name[0], "* Unknown *");
|
||||
break;
|
||||
}
|
||||
consoleClear();
|
||||
iprintf("%s", name);
|
||||
|
|
@ -150,7 +156,7 @@ void displayPrintUpper()
|
|||
// 1) The cart id.
|
||||
consoleSetWindow(&upperScreen, 10, 2, 22, 1);
|
||||
sprintf(&name[0], "----");
|
||||
if (flash_card) {
|
||||
if (slot_1_type == 2) {
|
||||
sprintf(&name[0], "Flash Card");
|
||||
} else /*if (nds.gameCode[0])*/ {
|
||||
memcpy(&name[0], &nds.gameCode[0], 4);
|
||||
|
|
@ -162,7 +168,7 @@ void displayPrintUpper()
|
|||
// 2) The cart name.
|
||||
consoleSetWindow(&upperScreen, 10, 3, 22, 1);
|
||||
sprintf(&name[0], "----");
|
||||
if (flash_card) {
|
||||
if (slot_1_type == 2) {
|
||||
sprintf(&name[0], "Flash Card");
|
||||
} else /*if (nds.gameTitle[0])*/ {
|
||||
memcpy(&name[0], &nds.gameTitle[0], 12);
|
||||
|
|
@ -174,7 +180,7 @@ void displayPrintUpper()
|
|||
// 3) The save type
|
||||
consoleSetWindow(&upperScreen, 10, 4, 22, 1);
|
||||
sprintf(&name[0], "----");
|
||||
if (flash_card) {
|
||||
if (slot_1_type == 2) {
|
||||
sprintf(&name[0], "Flash Card");
|
||||
} else {
|
||||
uint8 type = auxspi_save_type();
|
||||
|
|
@ -202,7 +208,7 @@ void displayPrintUpper()
|
|||
consoleClear();
|
||||
memset(&name[0], 0, MAXPATHLEN);
|
||||
//if (auxspi_has_infrared()) {
|
||||
if (ir) {
|
||||
if (slot_1_type == 1) {
|
||||
sprintf(&name[0], "Infrared");
|
||||
} else {
|
||||
sprintf(&name[0], "----");
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ extern u8 *data;
|
|||
extern u32 size_buf;
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
void ftpGetFileList(const char *dir, netbuf *ctrl, uint32 &num)
|
||||
void ftpGetFileList(const char *dir, netbuf *ctrl, int &num)
|
||||
{
|
||||
char *buf = (char*)data;
|
||||
memset(buf, 0, size_buf);
|
||||
|
|
@ -78,7 +78,7 @@ void ftpGetFileList(const char *dir, netbuf *ctrl, uint32 &num)
|
|||
}
|
||||
}
|
||||
|
||||
void fileGetFileList(const char *dir, uint32 &num)
|
||||
void fileGetFileList(const char *dir, int num)
|
||||
{
|
||||
char *buf = (char*)data;
|
||||
int idx = 0;
|
||||
|
|
@ -88,7 +88,6 @@ void fileGetFileList(const char *dir, uint32 &num)
|
|||
struct dirent *pent;
|
||||
num = 0;
|
||||
pdir=opendir(dir);
|
||||
char name[128];
|
||||
if (pdir) {
|
||||
while ((pent=readdir(pdir)) !=NULL) {
|
||||
char fullname[256];
|
||||
|
|
@ -118,7 +117,7 @@ void fileGetFileList(const char *dir, uint32 &num)
|
|||
closedir(pdir);
|
||||
}
|
||||
|
||||
void filePrintFileList(const char *dir, uint32 first, uint32 select, uint32 count, bool cancel = false)
|
||||
void filePrintFileList(const char *dir, int first, int select, int count, bool cancel = false)
|
||||
{
|
||||
if (select < first)
|
||||
select = first;
|
||||
|
|
@ -128,18 +127,11 @@ void filePrintFileList(const char *dir, uint32 first, uint32 select, uint32 coun
|
|||
consoleClear();
|
||||
|
||||
char *buf = (char*)data;
|
||||
int idx = 0;
|
||||
int len = strlen(buf);
|
||||
for (int i = 0; i < first; i++) {
|
||||
buf = strchr(buf, '\n') + 1;
|
||||
}
|
||||
|
||||
for (uint32 i = first; (i < first + 18) && (i < count); i++) {
|
||||
struct stat statbuf;
|
||||
char dir;
|
||||
u32 size;
|
||||
char fname[128];
|
||||
char fname2[128];
|
||||
for (int i = first; (i < first + 18) && (i < count); i++) {
|
||||
char *newline = strchr(buf, '\n');
|
||||
int linelen = newline - buf;
|
||||
|
||||
|
|
@ -177,9 +169,9 @@ void fileSelect(const char *startdir, char *out_dir, char *out_fname, netbuf *bu
|
|||
bool select = false;
|
||||
static int size_list = 18;
|
||||
|
||||
uint32 num_files = 0;
|
||||
uint32 sel_file = 0;
|
||||
uint32 first_file = 0;
|
||||
int num_files = 0;
|
||||
int sel_file = 0;
|
||||
int first_file = 0;
|
||||
|
||||
// get list of files in current dir
|
||||
if (buf)
|
||||
|
|
@ -210,8 +202,6 @@ void fileSelect(const char *startdir, char *out_dir, char *out_fname, netbuf *bu
|
|||
} else if (keys & KEY_A) {
|
||||
// get selected file name
|
||||
char *buf2 = (char*)data;
|
||||
int idx = 0;
|
||||
int len = strlen(buf2);
|
||||
char fname[128];
|
||||
for (int i = 0; i < sel_file; i++) {
|
||||
buf2 = strchr(buf2, '\n') + 1;
|
||||
|
|
|
|||
|
|
@ -541,7 +541,7 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
|
|||
*
|
||||
* return 1 if proper response received, 0 otherwise
|
||||
*/
|
||||
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
|
||||
GLOBALDEF int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
|
||||
{
|
||||
char buf[256];
|
||||
if (nControl->dir != FTPLIB_CONTROL)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ GLOBALREF int FtpRename(const char *src, const char *dst, netbuf *nControl);
|
|||
GLOBALREF int FtpDelete(const char *fnm, netbuf *nControl);
|
||||
GLOBALREF void FtpQuit(netbuf *nControl);
|
||||
|
||||
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl);
|
||||
GLOBALREF int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl);
|
||||
|
||||
GLOBALREF int FtpAccessBuf(const char *path, int typ, int mode, netbuf *nControl,
|
||||
netbuf **nData);
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ uint32 gbaGetSaveSize(uint8 type)
|
|||
}
|
||||
|
||||
// local function
|
||||
#define E_DEBUG
|
||||
//#define E_DEBUG
|
||||
void gbaEepromRead8Bytes(u8 *out, u32 addr, bool short_addr = false)
|
||||
{
|
||||
// waitstates
|
||||
|
|
@ -318,7 +318,7 @@ bool gbaReadSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
switch (type) {
|
||||
case 1: {
|
||||
// FIXME: this does not work yet...
|
||||
u32 start, end;
|
||||
int start, end;
|
||||
start = src >> 3;
|
||||
end = (src + len - 1) >> 3;
|
||||
u8 *tmp = (u8*)malloc((end-start+1) << 3);
|
||||
|
|
@ -337,10 +337,10 @@ bool gbaReadSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
}
|
||||
case 3: {
|
||||
// SRAM: blind copy
|
||||
u32 start = 0x0a000000 + src;
|
||||
int start = 0x0a000000 + src;
|
||||
u8 *tmpsrc = (u8*)start;
|
||||
sysSetBusOwners(true, true);
|
||||
for (int i = 0; i < len; i++, tmpsrc++, dst++)
|
||||
for (u32 i = 0; i < len; i++, tmpsrc++, dst++)
|
||||
*dst = *tmpsrc;
|
||||
break;
|
||||
}
|
||||
|
|
@ -369,11 +369,12 @@ bool gbaReadSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
}
|
||||
u8 *tmpsrc = (u8*)start;
|
||||
sysSetBusOwners(true, true);
|
||||
for (int i = 0; i < sublen; i++, tmpsrc++, dst++)
|
||||
for (u32 i = 0; i < sublen; i++, tmpsrc++, dst++)
|
||||
*dst = *tmpsrc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gbaIsAtmel()
|
||||
|
|
@ -418,7 +419,7 @@ bool gbaWriteSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
u32 start = 0x0a000000 + src;
|
||||
u8 *tmpsrc = (u8*)start;
|
||||
sysSetBusOwners(true, true);
|
||||
for (int i = 0; i < len; i++, tmpsrc++, dst++)
|
||||
for (u32 i = 0; i < len; i++, tmpsrc++, dst++)
|
||||
*tmpsrc = *dst;
|
||||
swiDelay(10); // mabe we don't need this, but better safe than sorry
|
||||
break;
|
||||
|
|
@ -429,7 +430,7 @@ bool gbaWriteSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
// only 64k, no bank switching required
|
||||
u32 len7 = len >> 7;
|
||||
u8 *tmpsrc = (u8*)(0x0a000000+src);
|
||||
for (int j = 0; j < len7; j++) {
|
||||
for (u32 j = 0; j < len7; j++) {
|
||||
u32 ime = enterCriticalSection();
|
||||
*(u8*)0x0a005555 = 0xaa;
|
||||
swiDelay(10);
|
||||
|
|
@ -473,7 +474,7 @@ bool gbaWriteSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
}
|
||||
u8 *tmpsrc = (u8*)start;
|
||||
sysSetBusOwners(true, true);
|
||||
for (int i = 0; i < sublen; i++, tmpsrc++, dst++) {
|
||||
for (u32 i = 0; i < sublen; i++, tmpsrc++, dst++) {
|
||||
// we need to wait a few cycles before the hardware reacts!
|
||||
*(u8*)0x0a005555 = 0xaa;
|
||||
swiDelay(10);
|
||||
|
|
@ -490,6 +491,7 @@ bool gbaWriteSave(u8 *dst, u8 src, u32 len, u8 type)
|
|||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gbaFormatSave(u8 type)
|
||||
|
|
|
|||
38
arm9/source/globals.cpp
Normal file
38
arm9/source/globals.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* savegame_manager: a tool to backup and restore savegames from Nintendo
|
||||
* DS cartridges. Nintendo DS and all derivative names are trademarks
|
||||
* by Nintendo. EZFlash 3-in-1 is a trademark by EZFlash.
|
||||
*
|
||||
* globals.cpp: global varibles, defines etc.
|
||||
*
|
||||
* Copyright (C) Pokedoc (2011)
|
||||
*/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
u8 *data;
|
||||
u32 size_buf;
|
||||
|
||||
u32 slot_1_type = ~0;
|
||||
|
||||
char ftp_ip[16] = "ftp_ip";
|
||||
char ftp_user[64] = "ftp_user";
|
||||
char ftp_pass[64] = "ftp_pass";
|
||||
int ftp_port = 0;
|
||||
|
||||
int ir_delay = 1000;
|
||||
|
|
@ -26,10 +26,18 @@
|
|||
#ifndef GLOBALS_H
|
||||
#define GLOBALS_H
|
||||
|
||||
// TODO
|
||||
//#define NDS_HEADER *(sNDSHeader*) 0x023ffe00
|
||||
#include <nds.h>
|
||||
|
||||
extern u8 *data;
|
||||
extern u32 size_buf;
|
||||
|
||||
extern u32 slot_1_type;
|
||||
|
||||
extern char ftp_ip[16];
|
||||
extern char ftp_user[64];
|
||||
extern char ftp_pass[64];
|
||||
extern int ftp_port;
|
||||
|
||||
extern int ir_delay;
|
||||
|
||||
#endif // GLOBALS_H
|
||||
|
|
@ -50,17 +50,8 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
uint32 boot;
|
||||
|
||||
static u32 pitch = 0x40000;
|
||||
|
||||
bool flash_card = true; // the homebrew will always start with a FC inserted
|
||||
bool with_infrared = false; // ... which does not have an IR device
|
||||
|
||||
extern char ftp_ip[16];
|
||||
extern char ftp_user[64];
|
||||
extern char ftp_pass[64];
|
||||
extern int ftp_port;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
bool swap_cart()
|
||||
|
|
@ -75,34 +66,14 @@ bool swap_cart()
|
|||
while (!swap) {
|
||||
if (keysCurrent() & KEY_A) {
|
||||
// identify hardware
|
||||
slot_1_type = get_slot1_type();
|
||||
sysSetBusOwners(true, true);
|
||||
cardReadHeader((u8*)&nds);
|
||||
flash_card = false;
|
||||
//flash_card = false;
|
||||
displayPrintUpper();
|
||||
if (!nds.gameTitle[0])
|
||||
continue;
|
||||
|
||||
// Look for an IR-enabled game cart first. If the save size returns something
|
||||
// nonzero, we hae found an IR-enabled game and we are done. If there is no
|
||||
// IR device present, "size2" is always zero.
|
||||
with_infrared = true;
|
||||
uint32 size2 = auxspi_save_size_log_2();
|
||||
if (size2) {
|
||||
flash_card = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Second, test if this is a Flash Card, which has no save chip. Therefore,
|
||||
// trying to identify this without IR-specific functions again returns zero.
|
||||
with_infrared = false;
|
||||
uint32 size1 = auxspi_save_size_log_2();
|
||||
if (!size1) {
|
||||
flash_card = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// No special hardware found, so it must be a regular game.
|
||||
flash_card = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,9 +82,18 @@ bool swap_cart()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool is_flash_card()
|
||||
u32 get_slot1_type()
|
||||
{
|
||||
return flash_card;
|
||||
u8 size1 = auxspi_save_size_log_2(false);
|
||||
u8 size2 = auxspi_save_size_log_2(true);
|
||||
|
||||
if (size1 == size2)
|
||||
return 2; // flash card
|
||||
|
||||
if ((size1 == 0) && (size2 != 0))
|
||||
return 1; // ir device
|
||||
|
||||
return 0; // regular game
|
||||
}
|
||||
|
||||
bool swap_card_game(uint32 size)
|
||||
|
|
@ -344,7 +324,7 @@ void hwRestore3in1_b(uint32 size_file)
|
|||
{
|
||||
// Third, swap in a new game
|
||||
uint32 size = auxspi_save_size_log_2();
|
||||
while ((size_file < size) || flash_card) {
|
||||
while ((size_file < size) || (slot_1_type == 2)) {
|
||||
// TODO: make THIS error message more meaningful!
|
||||
displayPrintState("File too small or no save chip!");
|
||||
swap_cart();
|
||||
|
|
@ -403,7 +383,7 @@ void hwErase()
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
void hwBackupFTP()
|
||||
void hwBackupFTP(bool dlp)
|
||||
{
|
||||
netbuf *buf, *ndata;
|
||||
int j;
|
||||
|
|
@ -411,7 +391,8 @@ void hwBackupFTP()
|
|||
|
||||
// Dump save and write it to FTP server
|
||||
// First: swap card
|
||||
swap_cart();
|
||||
if (!dlp)
|
||||
swap_cart();
|
||||
displayPrintUpper();
|
||||
uint8 size = auxspi_save_size_log_2();
|
||||
int size_blocks = 1 << max(0, (int8(size) - 18)); // ... in units of 0x40000 bytes - that's 256 kB
|
||||
|
|
@ -497,7 +478,6 @@ void hwBackupFTP()
|
|||
displayProgressBar(i+1, (size_blocks << 6));
|
||||
auxspi_read_data(i << 9, (u8*)&data[0], length, type);
|
||||
int out = 0;
|
||||
int debug = 0;
|
||||
while (out < 512) {
|
||||
out += FtpWrite((u8*)&data[out], 512-out, ndata);
|
||||
if (out < 512) {
|
||||
|
|
@ -519,11 +499,13 @@ void hwBackupFTP()
|
|||
|
||||
Wifi_DisconnectAP();
|
||||
|
||||
//displayMessage("Done! Please turn off your DS.");
|
||||
//while(1);
|
||||
if (dlp) {
|
||||
displayMessage("Done! Please turn off your DS.");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
void hwRestoreFTP()
|
||||
void hwRestoreFTP(bool dlp)
|
||||
{
|
||||
netbuf *buf, *ndata;
|
||||
int j;
|
||||
|
|
@ -568,10 +550,10 @@ void hwRestoreFTP()
|
|||
fileSelect("/", fdir, fname, buf, true, false);
|
||||
|
||||
// Third: swap card
|
||||
swap_cart();
|
||||
if (!dlp)
|
||||
swap_cart();
|
||||
displayPrintUpper();
|
||||
uint8 size = auxspi_save_size_log_2();
|
||||
int size_blocks = 1 << (size - 9); // ... in units of 512 bytes
|
||||
uint8 type = auxspi_save_type();
|
||||
|
||||
// Fourth: read file
|
||||
|
|
@ -661,9 +643,10 @@ void hwRestoreFTP()
|
|||
|
||||
Wifi_DisconnectAP();
|
||||
|
||||
// TODO: return to main procedure, so we can do more stuff
|
||||
displayMessage("Done! Please turn off your DS.");
|
||||
while(1);
|
||||
if (dlp) {
|
||||
displayMessage("Done! Please turn off your DS.");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
|
@ -722,14 +705,10 @@ void hwRestoreGBA()
|
|||
return;
|
||||
}
|
||||
|
||||
//char fullname[512];
|
||||
|
||||
uint32 size = gbaGetSaveSize(type);
|
||||
u8 nbanks = 2;
|
||||
|
||||
char path[256];
|
||||
char fname[256] = "";
|
||||
char *gamename = (char*)0x080000a0;
|
||||
fileSelect("/", path, fname, 0);
|
||||
char fullpath[512];
|
||||
sprintf(fullpath, "%s/%s", path, fname);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ void do_dump_nds_save_stage_2(int size);
|
|||
void do_restore_nds_save();
|
||||
|
||||
bool swap_cart();
|
||||
bool is_flash_card();
|
||||
u32 get_slot1_type();
|
||||
//bool is_flash_card();
|
||||
|
||||
void hwBackup3in1();
|
||||
void hwDump3in1(uint32 size, const char *gamename);
|
||||
|
|
@ -57,8 +58,8 @@ void hwErase();
|
|||
void hwBackupDSi();
|
||||
void hwRestoreDSi();
|
||||
|
||||
void hwBackupFTP();
|
||||
void hwRestoreFTP();
|
||||
void hwBackupFTP(bool dlp = false);
|
||||
void hwRestoreFTP(bool dlp = false);
|
||||
|
||||
void hwBackupGBA(u8 type);
|
||||
void hwRestoreGBA();
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@
|
|||
|
||||
#include "libini.h"
|
||||
|
||||
u8 *data;
|
||||
u32 size_buf;
|
||||
#include "globals.h"
|
||||
|
||||
using std::max;
|
||||
|
||||
|
|
@ -61,12 +60,6 @@ uint32 mode = 0;
|
|||
bool slot2 = false;
|
||||
u8 gbatype = 0;
|
||||
|
||||
char ftp_ip[16] = "ftp_ip";
|
||||
char ftp_user[64] = "ftp_user";
|
||||
char ftp_pass[64] = "ftp_pass";
|
||||
int ftp_port = 0;
|
||||
int ir_delay = 1000;
|
||||
|
||||
char bootdir[256] = "/";
|
||||
|
||||
|
||||
|
|
@ -80,6 +73,11 @@ void mode_dsi()
|
|||
displayPrintUpper();
|
||||
displayPrintLower();
|
||||
|
||||
|
||||
// DSi mode, does nothing at the moment
|
||||
displayPrintState("DSi mode - still unsupported!");
|
||||
while (1);
|
||||
|
||||
touchPosition touchXY;
|
||||
while(1) {
|
||||
swiWaitForVBlank();
|
||||
|
|
@ -102,10 +100,6 @@ void mode_dsi()
|
|||
hwErase();
|
||||
}
|
||||
}
|
||||
|
||||
// DSi mode, does nothing at the moment
|
||||
displayPrintState("DSi mode - still unsupported!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
void mode_slot2()
|
||||
|
|
@ -255,6 +249,38 @@ void mode_wifi()
|
|||
}
|
||||
}
|
||||
|
||||
void mode_dlp()
|
||||
{
|
||||
// use 3in1 to buffer data
|
||||
displayPrintState("");
|
||||
displayPrintUpper();
|
||||
displayPrintLower();
|
||||
|
||||
touchPosition touchXY;
|
||||
while(1) {
|
||||
swiWaitForVBlank();
|
||||
touchRead(&touchXY);
|
||||
|
||||
// backup
|
||||
if ((touchXY.py > 8*0) && (touchXY.py < 8*8)) {
|
||||
hwBackupFTP(true);
|
||||
}
|
||||
|
||||
// restore
|
||||
if ((touchXY.py > 8*8) && (touchXY.py < 8*16)) {
|
||||
hwRestoreFTP(true);
|
||||
}
|
||||
|
||||
// erase
|
||||
if ((touchXY.py > 8*16) && (touchXY.py < 8*24)) {
|
||||
displayPrintUpper();
|
||||
hwErase();
|
||||
displayMessage("Done! Please turn off your DS.");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
sysSetBusOwners(true, true);
|
||||
|
|
@ -263,6 +289,7 @@ int main(int argc, char* argv[])
|
|||
displayInit();
|
||||
|
||||
// Init DLDI (file system driver)
|
||||
// TODO: find some way to skip this when loading from a different exploit/download play/not a flash card
|
||||
int fat = fatInitDefault();
|
||||
if (fat == 0) {
|
||||
displayPrintState("DLDI error\n");
|
||||
|
|
@ -334,6 +361,9 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
data = (u8*)malloc(size_buf);
|
||||
|
||||
// is there a game card in slot-1? if so, we have been starten with download-play or a new exploit
|
||||
slot_1_type = get_slot1_type();
|
||||
|
||||
// don't try to identify Slot-2 in DSi mode.
|
||||
if (dstype == 0) {
|
||||
//displayPrintState("ID: Slot 2");
|
||||
|
|
@ -351,8 +381,13 @@ int main(int argc, char* argv[])
|
|||
// Try to identify slot-2 device. Try opening slot-2 root directory
|
||||
if (argv[0][3] == '2')
|
||||
slot2 = true;
|
||||
|
||||
if (dstype == 1) {
|
||||
|
||||
// okay, we got our HW identified; now branch to the corresponding main function/event handler
|
||||
if (slot_1_type != 2) {
|
||||
// running from download play, NOR, or a different exploit. enter dlp mode.
|
||||
mode = 5;
|
||||
mode_dlp();
|
||||
} else if (dstype == 1) {
|
||||
// DSi/DSiXL, branch to SD-card mode when cracked.
|
||||
mode = 3;
|
||||
mode_dsi();
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.cpp"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File></MagicFolder><File path="Makefile"></File></Project>
|
||||
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="auxspi.d"></File><File path="auxspi.o"></File><File path="display.d"></File><File path="display.o"></File><File path="dsCard.d"></File><File path="dsCard.o"></File><File path="dsi.d"></File><File path="dsi.o"></File><File path="fileselect.d"></File><File path="fileselect.o"></File><File path="ftplib.d"></File><File path="ftplib.o"></File><File path="gba.d"></File><File path="gba.o"></File><File path="globals.d"></File><File path="globals.o"></File><File path="hardware.d"></File><File path="hardware.o"></File><File path="ini.d"></File><File path="ini.o"></File><File path="main.d"></File><File path="main.o"></File><File path="strings.d"></File><File path="strings.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.inc"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.cpp"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File><File path="savegame_manager.elf"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="arm7.d"></File><File path="arm7.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File><File path="savegame_manager.elf"></File></MagicFolder><File path="Makefile"></File></Project>
|
||||
|
|
@ -1 +1 @@
|
|||
<pd><ViewState><e p="Savegame Manager\arm7" x="true"></e><e p="Savegame Manager\arm9" x="true"></e><e p="Savegame Manager" x="true"></e><e p="Savegame Manager\arm7\source" x="true"></e><e p="Savegame Manager\arm9\source" x="true"></e></ViewState></pd>
|
||||
<pd><ViewState><e p="Savegame Manager\arm7" x="true"></e><e p="Savegame Manager\arm9" x="true"></e><e p="Savegame Manager" x="true"></e><e p="Savegame Manager\arm7\build" x="false"></e><e p="Savegame Manager\arm7\source" x="true"></e><e p="Savegame Manager\arm9\build" x="false"></e><e p="Savegame Manager\arm9\source" x="true"></e></ViewState></pd>
|
||||
Loading…
Reference in New Issue
Block a user