Skip to content
Merged
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
2 changes: 1 addition & 1 deletion arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SOURCE_PATH := ../arm9
# all directories are relative to this makefile
#---------------------------------------------------------------------------------
BUILD := build
SOURCES := $(SOURCE_PATH)/source $(SOURCE_PATH)/source/ui $(SOURCE_PATH)/source/font $(SOURCE_PATH)/source/launcher $(SOURCE_PATH)/source/saves
SOURCES := $(SOURCE_PATH)/source $(SOURCE_PATH)/source/ui $(SOURCE_PATH)/source/font $(SOURCE_PATH)/source/launcher/slot2 $(SOURCE_PATH)/source/launcher $(SOURCE_PATH)/source/saves
INCLUDES := $(SOURCE_PATH)/include ../share $(SOURCES)
DATA := $(SOURCE_PATH)/data ../data
GRAPHICS :=
Expand Down
35 changes: 34 additions & 1 deletion arm9/source/launcher/NdsBootstrapLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "nds_loader_arm9.h"
#include "fsmngr.h"

#include "slot2/io_g6_common.h"
#include "slot2/io_m3_common.h"
#include "slot2/io_sc_common.h"

void smoothProgress(u8 start, u8 end) {
for(u8 p = start; p <= end; p += 5) {
progressWnd().setPercent(p);
Expand All @@ -37,6 +41,30 @@ void smoothProgress(u8 start, u8 end) {
progressWnd().setPercent(end);
}

void slot2RamAccess(){
// if running from NDS slot
if (io_dldi_data->ioInterface.features & FEATURE_SLOT_NDS) {
sysSetCartOwner(BUS_OWNER_ARM9);

*(vu16*)0x08000000 = 0x1111; // write data to GBA ROM area
// if data wasn't written, try enabling RAM access for various slot 2 carts and write again
if (*(vu16*)0x08000000 != 0x1111) {
_SC_changeMode(SC_MODE_RAM);
*(vu16*)0x08000000 = 0x1111;
}
if (*(vu16*)0x08000000 != 0x1111) {
_G6_SelectOperation(G6_MODE_RAM);
*(vu16*)0x08000000 = 0x1111;
}
if (*(vu16*)0x08000000 != 0x1111) {
_M3_changeMode(M3_MODE_RAM);
*(vu16*)0x08000000 = 0x1111;
}

sysSetCartOwner(BUS_OWNER_ARM7);
}
}

bool NdsBootstrapLauncher::prepareCheats() {
u32 gameCode, crc32;

Expand Down Expand Up @@ -336,8 +364,13 @@ bool NdsBootstrapLauncher::launchRom(std::string romPath, std::string savePath,
smoothProgress(90, 100);
}

// enable slot2 ram access if available
if(!isDSiMode()){
slot2RamAccess();
}

// Launch
eRunNdsRetCode rc = runNdsFile(argv[0], argv.size(), &argv[0]);
if (rc == RUN_NDS_OK) return true;
return false;
}
}
114 changes: 114 additions & 0 deletions arm9/source/launcher/slot2/io_g6_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
iointerface.c for G6 flash card

Written by Viruseb (viruseb@hotmail.com)
Many thanks to Puyo for his help in the reading code and ecc generation
and Theli for remote debbuging.

Copyright (c) 2006 Michael "Chishm" Chisholm

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

If you wish to understand how the code works, I encourage you reading
the datasheet of K9K4G08U0M nand flash device from Samsung before.

Just some figures to keep in mind :
1 page = 4 sectors + 64byte
1 block = 64 pages = 256 sectors
1 4G device = 4096 blocks

The spare 64byte in page are use :
- to store the ECC. There is 3bytes ecc per 256bytes (bytes 8...15+numsector*16).
- to store lookuptable values (bytes 4..7).

04/12/06 : Version 0.10
Just freshly written. Not tested on real G6L thought.
Extreme caution have to be taken when testing WriteBlockFunction
since it may brick your G6L or more likely corrupt your data
and formating can be necessary.

05/12/06 : Version 0.11
Thank to Theli, a lot of stupid mistakes removed, a lot of debugging done.
Reading code checked against Puyo's code.
Device and FAT table is recognised by Fat_InitFiles()
Known issues : DMA read (G6_ReadDMA) is malfunctionning
Strange things append when trying to read more than 1 sectors at a time
Have to check LookUpTable values against Puyo's LookUpTable they seems differents after 512values

19/12/06 : Version 0.12
Reading code ok

20/12/06 : Version 0.13
Some reading bugs corrected

07/01/07 : Version 0.14
Writing code finaly working. Need some optimizations.

10/01/07 : Version 0.15
Code cleaning. Need to add DMA R/W and use of cache programming in later version.

03/02/07 : Version 0.16
Unaligned R/W supported.
Write code rewritten, using cache programming now.

04/03/07 : Version 0.17
VerifyBlockFunc corrected (no more in use now)

23/03/07 : Version 0.18
a bug corrected in make_ecc_256

25/03/07 : Version 0.19
Improved writing speed
*/

#include "io_g6_common.h"

static u16 _G6_readHalfword (u32 addr) {
return *((vu16*)addr);
}

/*-----------------------------------------------------------------
SelectOperation
??
u16 op IN : Operation to select
-----------------------------------------------------------------*/
void _G6_SelectOperation(u16 op)
{
_G6_readHalfword (0x09000000);
_G6_readHalfword (0x09FFFFE0);

_G6_readHalfword (0x09FFFFEC);
_G6_readHalfword (0x09FFFFEC);
_G6_readHalfword (0x09FFFFEC);

_G6_readHalfword (0x09FFFFFC);
_G6_readHalfword (0x09FFFFFC);
_G6_readHalfword (0x09FFFFFC);

_G6_readHalfword (0x09FFFF4A);
_G6_readHalfword (0x09FFFF4A);
_G6_readHalfword (0x09FFFF4A);

_G6_readHalfword (0x09200000 + (op<<1));
_G6_readHalfword (0x09FFFFF0);
_G6_readHalfword (0x09FFFFE8);
}
103 changes: 103 additions & 0 deletions arm9/source/launcher/slot2/io_g6_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
iointerface.c for G6 flash card

Written by Viruseb (viruseb@hotmail.com)
Many thanks to Puyo for his help in the reading code and ecc generation
and Theli for remote debbuging.

Copyright (c) 2006 Michael "Chishm" Chisholm

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

If you wish to understand how the code works, I encourage you reading
the datasheet of K9K4G08U0M nand flash device from Samsung before.

Just some figures to keep in mind :
1 page = 4 sectors + 64byte
1 block = 64 pages = 256 sectors
1 4G device = 4096 blocks

The spare 64byte in page are use :
- to store the ECC. There is 3bytes ecc per 256bytes (bytes 8...15+numsector*16).
- to store lookuptable values (bytes 4..7).

04/12/06 : Version 0.10
Just freshly written. Not tested on real G6L thought.
Extreme caution have to be taken when testing WriteBlockFunction
since it may brick your G6L or more likely corrupt your data
and formating can be necessary.

05/12/06 : Version 0.11
Thank to Theli, a lot of stupid mistakes removed, a lot of debugging done.
Reading code checked against Puyo's code.
Device and FAT table is recognised by Fat_InitFiles()
Known issues : DMA read (G6_ReadDMA) is malfunctionning
Strange things append when trying to read more than 1 sectors at a time
Have to check LookUpTable values against Puyo's LookUpTable they seems differents after 512values

19/12/06 : Version 0.12
Reading code ok

20/12/06 : Version 0.13
Some reading bugs corrected

07/01/07 : Version 0.14
Writing code finaly working. Need some optimizations.

10/01/07 : Version 0.15
Code cleaning. Need to add DMA R/W and use of cache programming in later version.

03/02/07 : Version 0.16
Unaligned R/W supported.
Write code rewritten, using cache programming now.

04/03/07 : Version 0.17
VerifyBlockFunc corrected (no more in use now)

23/03/07 : Version 0.18
a bug corrected in make_ecc_256

25/03/07 : Version 0.19
Improved writing speed
*/

#ifndef IO_G6_COMMON_H
#define IO_G6_COMMON_H

#include <nds/ndstypes.h>

#ifdef __cplusplus
extern "C" {
#endif

// Values for changing mode
#define G6_MODE_RAM 6
#define G6_MODE_MEDIA 3

extern void _G6_SelectOperation(u16 op);

#ifdef __cplusplus
}
#endif

#endif // IO_G6_COMMON_H

60 changes: 60 additions & 0 deletions arm9/source/launcher/slot2/io_m3_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
io_m3_common.c

Routines common to all version of the M3

Some code based on M3 SD drivers supplied by M3Adapter.
Some code written by SaTa may have been unknowingly used.

Copyright (c) 2006 Michael "Chishm" Chisholm

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "io_m3_common.h"

static u16 _M3_readHalfword (u32 addr) {
return *((vu16*)addr);
}

void _M3_changeMode (u32 mode) {
_M3_readHalfword (0x08e00002);
_M3_readHalfword (0x0800000e);
_M3_readHalfword (0x08801ffc);
_M3_readHalfword (0x0800104a);
_M3_readHalfword (0x08800612);
_M3_readHalfword (0x08000000);
_M3_readHalfword (0x08801b66);
_M3_readHalfword (0x08000000 + (mode << 1));
_M3_readHalfword (0x0800080e);
_M3_readHalfword (0x08000000);

if ((mode & 0x0f) != 4) {
_M3_readHalfword (0x09000000);
} else {
_M3_readHalfword (0x080001e4);
_M3_readHalfword (0x080001e4);
_M3_readHalfword (0x08000188);
_M3_readHalfword (0x08000188);
}
}

Loading
Loading