| 1 |
/*--------------------------------------------------------------------------------- |
| 2 |
|
| 3 |
once upon a time, this was: default ARM7 core |
| 4 |
|
| 5 |
Copyright (C) 2005 |
| 6 |
Michael Noland (joat) |
| 7 |
Jason Rogers (dovoto) |
| 8 |
Dave Murphy (WinterMute) |
| 9 |
|
| 10 |
This software is provided 'as-is', without any express or implied |
| 11 |
warranty. In no event will the authors be held liable for any |
| 12 |
damages arising from the use of this software. |
| 13 |
|
| 14 |
Permission is granted to anyone to use this software for any |
| 15 |
purpose, including commercial applications, and to alter it and |
| 16 |
redistribute it freely, subject to the following restrictions: |
| 17 |
|
| 18 |
1. The origin of this software must not be misrepresented; you |
| 19 |
must not claim that you wrote the original software. If you use |
| 20 |
this software in a product, an acknowledgment in the product |
| 21 |
documentation would be appreciated but is not required. |
| 22 |
2. Altered source versions must be plainly marked as such, and |
| 23 |
must not be misrepresented as being the original software. |
| 24 |
3. This notice may not be removed or altered from any source |
| 25 |
distribution. |
| 26 |
|
| 27 |
---------------------------------------------------------------------------------*/ |
| 28 |
#include <nds.h> |
| 29 |
#include <dswifi7.h> |
| 30 |
#include <maxmod7.h> |
| 31 |
#include "../../regstest.h" |
| 32 |
#include <nds/arm7/serial.h> |
| 33 |
|
| 34 |
arm7comm_t *arm7comm; |
| 35 |
|
| 36 |
//--------------------------------------------------------------------------------- |
| 37 |
void VcountHandler() { |
| 38 |
//--------------------------------------------------------------------------------- |
| 39 |
inputGetAndSend(); |
| 40 |
} |
| 41 |
|
| 42 |
//--------------------------------------------------------------------------------- |
| 43 |
void VblankHandler(void) { |
| 44 |
//--------------------------------------------------------------------------------- |
| 45 |
Wifi_Update(); |
| 46 |
} |
| 47 |
|
| 48 |
//modified from: http://www.bottledlight.com/ds/index.php/Main/Firmware |
| 49 |
#define FW_READ_ID 0x9F |
| 50 |
#define FW_READ 0x03 |
| 51 |
#define FW_READ_STATUS 0x05 |
| 52 |
u32 getFirmwareType() |
| 53 |
{ |
| 54 |
u32 result; |
| 55 |
|
| 56 |
// Get ID |
| 57 |
while (REG_SPICNT & SPI_BUSY); |
| 58 |
REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_FIRMWARE; |
| 59 |
REG_SPIDATA = FW_READ_ID; |
| 60 |
while (REG_SPICNT & SPI_BUSY); |
| 61 |
|
| 62 |
result = 0; |
| 63 |
for (int i = 0; i < 3; i++) { |
| 64 |
REG_SPIDATA = 0; |
| 65 |
while (REG_SPICNT & SPI_BUSY); |
| 66 |
result = (REG_SPIDATA & 0xFF) | (result<<8); |
| 67 |
} |
| 68 |
|
| 69 |
// Get status |
| 70 |
//zeromus note: this is broken. not only does it put the byte in a different spot than the docs said it does, |
| 71 |
//it is coded otherwise glitchily and just returns bytes of the 3-Byte flash ID |
| 72 |
//(desmume shows five reads during the ID command; apparently this code fails to reset correctly) |
| 73 |
while (REG_SPICNT & SPI_BUSY); |
| 74 |
REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_FIRMWARE; |
| 75 |
REG_SPIDATA = FW_READ_STATUS; |
| 76 |
while (REG_SPICNT & SPI_BUSY); |
| 77 |
|
| 78 |
REG_SPIDATA = 0; |
| 79 |
while (REG_SPICNT & SPI_BUSY); |
| 80 |
result = ((REG_SPIDATA & 0xFF) << 24) | result; |
| 81 |
|
| 82 |
return result; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
void pokeMessage(const char* msg) |
| 88 |
{ |
| 89 |
const char* cp = msg; |
| 90 |
int i=0; |
| 91 |
while(*cp) |
| 92 |
arm7comm->message[i++] = *cp++; |
| 93 |
arm7comm->message[i] = 0; |
| 94 |
} |
| 95 |
|
| 96 |
void fail(const char* msg, u32 offender=0) |
| 97 |
{ |
| 98 |
arm7comm->code = 1; |
| 99 |
arm7comm->offender = offender; |
| 100 |
pokeMessage(msg); |
| 101 |
|
| 102 |
fifoSendValue32(FIFO_USER_01,0); |
| 103 |
while (1) swiWaitForVBlank(); |
| 104 |
} |
| 105 |
|
| 106 |
//--------------------------------------------------------------------------------- |
| 107 |
int main() { |
| 108 |
//--------------------------------------------------------------------------------- |
| 109 |
irqInit(); |
| 110 |
fifoInit(); |
| 111 |
|
| 112 |
// read User Settings from firmware |
| 113 |
readUserSettings(); |
| 114 |
|
| 115 |
// Start the RTC tracking IRQ |
| 116 |
initClockIRQ(); |
| 117 |
|
| 118 |
SetYtrigger(80); |
| 119 |
|
| 120 |
installWifiFIFO(); |
| 121 |
installSoundFIFO(); |
| 122 |
|
| 123 |
mmInstall(FIFO_MAXMOD); |
| 124 |
|
| 125 |
installSystemFIFO(); |
| 126 |
|
| 127 |
irqSet(IRQ_VCOUNT, VcountHandler); |
| 128 |
irqSet(IRQ_VBLANK, VblankHandler); |
| 129 |
|
| 130 |
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK); |
| 131 |
|
| 132 |
//find out where the arm9 wants us to stash our info |
| 133 |
while(!fifoCheckAddress(FIFO_USER_01)) swiWaitForVBlank(); |
| 134 |
arm7comm = (arm7comm_t*)fifoGetAddress(FIFO_USER_01); |
| 135 |
|
| 136 |
|
| 137 |
//spu source reg should only be 27bit |
| 138 |
//but it is not readable so what does it matter |
| 139 |
for(int i=0;i<16;i++) |
| 140 |
{ |
| 141 |
vu32* reg = (vu32*)(0x04000404 + (i<<4)); |
| 142 |
*reg = 0xFFFFFFFF; |
| 143 |
//if(*reg != 0x07FFFFFF) fail("spu source reg is only 27bit.\nshould be 0x07FFFFFF",*reg); |
| 144 |
if(*reg != 0x00000000) fail("spu source reg is not readable!",*reg); |
| 145 |
} |
| 146 |
|
| 147 |
//spu length reg should only be 22bit |
| 148 |
for(int i=0;i<16;i++) |
| 149 |
{ |
| 150 |
vu32* reg = (vu32*)(0x0400040C + (i<<4)); |
| 151 |
*reg = 0xFFFFFFFF; |
| 152 |
//if(*reg != 0x003FFFFF) fail("spu length reg is only 22bit.\nshould be 0x003FFFFF",*reg); |
| 153 |
if(*reg != 0x00000000) fail("spu length reg is not readable!",*reg); |
| 154 |
} |
| 155 |
|
| 156 |
arm7comm->firmwareId = getFirmwareType(); |
| 157 |
arm7comm->code = 2; |
| 158 |
fifoSendValue32(FIFO_USER_01,0); |
| 159 |
while (1) swiWaitForVBlank(); |
| 160 |
} |
| 161 |
|
| 162 |
|