forked from archshift/Decrypt9
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly osilloscorpion's (deleted account) work with a couple touches from @idgrepthat.
- Loading branch information
Showing
13 changed files
with
710 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/*--------------------------------------------------------------------------------- | ||
Copyright (C) 2005 | ||
Michael Noland (joat) | ||
Jason Rogers (dovoto) | ||
Dave Murphy (WinterMute) | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any | ||
damages arising from the use of this software. | ||
Permission is granted to anyone to use this software for any | ||
purpose, including commercial applications, and to alter it and | ||
redistribute it freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; you | ||
must not claim that you wrote the original software. If you use | ||
this software in a product, an acknowledgment in the product | ||
documentation would be appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and | ||
must not be misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source | ||
distribution. | ||
---------------------------------------------------------------------------------*/ | ||
#include "nds/card.h" | ||
#include "nds/dma.h" | ||
#include "nds/memory.h" | ||
#include "nds/bios.h" | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
void cardWriteCommand(const u8 *command) { | ||
//--------------------------------------------------------------------------------- | ||
int index; | ||
|
||
REG_AUXSPICNTH = CARD_CR1_ENABLE | CARD_CR1_IRQ; | ||
|
||
for (index = 0; index < 8; index++) { | ||
CARD_COMMAND[7-index] = command[index]; | ||
} | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
void cardPolledTransfer(u32 flags, u32 *destination, u32 length, const u8 *command) { | ||
//--------------------------------------------------------------------------------- | ||
u32 data; | ||
cardWriteCommand(command); | ||
REG_ROMCTRL = flags; | ||
u32 * target = destination + length; | ||
do { | ||
// Read data if available | ||
if (REG_ROMCTRL & CARD_DATA_READY) { | ||
data=CARD_DATA_RD; | ||
if (destination < target) | ||
*destination = data; | ||
destination++; | ||
} | ||
} while (REG_ROMCTRL & CARD_BUSY); | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
void cardStartTransfer(const u8 *command, u32 *destination, int channel, u32 flags) { | ||
//--------------------------------------------------------------------------------- | ||
cardWriteCommand(command); | ||
|
||
// Set up a DMA channel to transfer a word every time the card makes one | ||
DMA_SRC(channel) = (u32)&CARD_DATA_RD; | ||
DMA_DEST(channel) = (u32)destination; | ||
DMA_CR(channel) = DMA_ENABLE | DMA_START_CARD | DMA_32_BIT | DMA_REPEAT | DMA_SRC_FIX | 0x0001; | ||
|
||
REG_ROMCTRL = flags; | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
u32 cardWriteAndRead(const u8 *command, u32 flags) { | ||
//--------------------------------------------------------------------------------- | ||
cardWriteCommand(command); | ||
REG_ROMCTRL = flags | CARD_ACTIVATE | CARD_nRESET | CARD_BLK_SIZE(7); | ||
while (!(REG_ROMCTRL & CARD_DATA_READY)) ; | ||
return CARD_DATA_RD; | ||
} | ||
|
||
//--------------------------------------------------------------------------------- | ||
void cardParamCommand (u8 command, u32 parameter, u32 flags, u32 *destination, u32 length) { | ||
//--------------------------------------------------------------------------------- | ||
u8 cmdData[8]; | ||
|
||
cmdData[7] = (u8) command; | ||
cmdData[6] = (u8) (parameter >> 24); | ||
cmdData[5] = (u8) (parameter >> 16); | ||
cmdData[4] = (u8) (parameter >> 8); | ||
cmdData[3] = (u8) (parameter >> 0); | ||
cmdData[2] = 0; | ||
cmdData[1] = 0; | ||
cmdData[0] = 0; | ||
|
||
cardPolledTransfer(flags, destination, length, cmdData); | ||
} | ||
|
||
//--------------------------------------------------------------------------------- | ||
void cardReadHeader(u8 *header) { | ||
//--------------------------------------------------------------------------------- | ||
REG_ROMCTRL=0; | ||
REG_AUXSPICNTH=0; | ||
swiDelay(167550); | ||
REG_AUXSPICNTH=CARD_CR1_ENABLE|CARD_CR1_IRQ; | ||
REG_ROMCTRL=CARD_nRESET|CARD_SEC_SEED; | ||
while(REG_ROMCTRL&CARD_BUSY) ; | ||
cardReset(); | ||
while(REG_ROMCTRL&CARD_BUSY) ; | ||
|
||
cardParamCommand(CARD_CMD_HEADER_READ,0,CARD_ACTIVATE|CARD_nRESET|CARD_CLK_SLOW|CARD_BLK_SIZE(1)|CARD_DELAY1(0x1FFF)|CARD_DELAY2(0x3F),(u32*)header,512/4); | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
u32 cardReadID(u32 flags) { | ||
//--------------------------------------------------------------------------------- | ||
const u8 command[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, CARD_CMD_HEADER_CHIPID}; | ||
return cardWriteAndRead(command, flags); | ||
} | ||
|
||
|
||
//--------------------------------------------------------------------------------- | ||
void cardReset() { | ||
//--------------------------------------------------------------------------------- | ||
const u8 cmdData[8]={0,0,0,0,0,0,0,CARD_CMD_DUMMY}; | ||
cardWriteCommand(cmdData); | ||
REG_ROMCTRL=CARD_ACTIVATE|CARD_nRESET|CARD_CLK_SLOW|CARD_BLK_SIZE(5)|CARD_DELAY2(0x18); | ||
u32 read=0; | ||
|
||
do { | ||
if(REG_ROMCTRL&CARD_DATA_READY) { | ||
if(read<0x2000) { | ||
u32 data=CARD_DATA_RD; | ||
(void)data; | ||
read+=4; | ||
} | ||
} | ||
} while(REG_ROMCTRL&CARD_BUSY); | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
#pragma once | ||
|
||
void cardWriteCommand(const u8 *command); | ||
void cardPolledTransfer(u32 flags, u32 *destination, u32 length, const u8 *command); | ||
void cardStartTransfer(const u8 *command, u32 *destination, int channel, u32 flags); | ||
u32 cardWriteAndRead(const u8 *command, u32 flags); | ||
void cardParamCommand (u8 command, u32 parameter, u32 flags, u32 *destination, u32 length); | ||
void cardReadHeader(u8 *header); | ||
u32 cardReadID(u32 flags); | ||
void cardReset(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
// Copyright 2014 Normmatt | ||
// Licensed under GPLv2 or any later version | ||
// Refer to the license.txt file included. | ||
// | ||
// modifyed by osilloscopion (2 Jul 2016) | ||
// | ||
|
||
#include "command_ntr.h" | ||
|
||
#include "protocol_ntr.h" | ||
#include "card_ntr.h" | ||
#include "delay.h" | ||
|
||
|
||
u32 ReadDataFlags = 0; | ||
|
||
void NTR_CmdReset(void) | ||
{ | ||
static const u32 reset_cmd[2] = { 0x9F000000, 0x00000000 }; | ||
NTR_SendCommand(reset_cmd, 0x2000, NTRCARD_CLK_SLOW | NTRCARD_DELAY1(0x1FFF) | NTRCARD_DELAY2(0x18), NULL); | ||
cardReset (); | ||
ioDelay(0xF000); | ||
} | ||
|
||
u32 NTR_CmdGetCartId(void) | ||
{ | ||
u32 id; | ||
static const u32 getid_cmd[2] = { 0x90000000, 0x00000000 }; | ||
NTR_SendCommand(getid_cmd, 0x4, NTRCARD_CLK_SLOW | NTRCARD_DELAY1(0x1FFF) | NTRCARD_DELAY2(0x18), &id); | ||
return id; | ||
return cardReadID (0); | ||
} | ||
|
||
void NTR_CmdEnter16ByteMode(void) | ||
{ | ||
static const u32 enter16bytemode_cmd[2] = { 0x3E000000, 0x00000000 }; | ||
NTR_SendCommand(enter16bytemode_cmd, 0x0, 0, NULL); | ||
} | ||
|
||
void NTR_CmdReadHeader (void* buffer) | ||
{ | ||
cardReadHeader (buffer); | ||
} | ||
|
||
void NTR_CmdReadData (u32 offset, void* buffer) | ||
{ | ||
cardParamCommand (NTRCARD_CMD_DATA_READ, offset, ReadDataFlags | NTRCARD_ACTIVATE | NTRCARD_nRESET | NTRCARD_BLK_SIZE(1), (u32*)buffer, 0x200 / 4); | ||
} | ||
|
||
|
Oops, something went wrong.