#include
#include "ShakeMe.h"
#include "math.h"
#include
#include
//---------------------------------------------------------------------------------
void Vblank() {
//---------------------------------------------------------------------------------
// frame++;
}
void WaitForKeyA()
{
scanKeys();
while(!(keysDown() & KEY_A))scanKeys();
}
//---------------------------------------------------------------------------------
int main(void)
{
powerON(POWER_ALL_2D);
irqInit();
irqSet(IRQ_VBLANK, Vblank);
irqEnable(IRQ_VBLANK);
videoSetMode(0); //not using the main screen
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
vramSetBankC(VRAM_C_SUB_BG);
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(0,31,0); //by default font will be rendered with color 255
//consoleInit() is a lot more flexible but this gets you up and running quick
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
bool start = false;
bool FastMode = false;
int32 x,y,z;
int32 scalex, scaley;
int32 rotatex, rotatey;
u32 r;
SMPowerOn(SMHOST_ARM9);
if(!SMInserted())
iprintf("\x1b[0;0HShakeMe NOT detected! \n");
r = SMSetCtrlREG(SM_12BIT | SM_6G | SM_DR_640| SM_POWER_ON | SM_X_ENA |
SM_Y_ENA | SM_Z_ENA);
if(r != 0)
iprintf("\x1b[1;0HSet CtrlREG error! %02D \n", r);
scanKeys();
while(1)
{
swiWaitForVBlank();
scanKeys();
if(keysDown() & KEY_A)
{
if(SMIsFastMode())
iprintf("\x1b[2;0HIn Fast Mode \n");
else
iprintf("\x1b[2;0HIn Normal Mode \n");
}
else if(keysDown() & KEY_B)
{
SMEnterFastMode();
FastMode = true;
}
else if(keysDown() & KEY_X)
{
SMLeaveFastMode();
FastMode = false;
}
else if(keysDown() & KEY_Y)
{
iprintf("\x1b[1;0HREG1: %08X\n", SMGetCtrlREG());
}
else if(keysDown() & KEY_L)
{
start = true;
}
else if(keysDown() & KEY_R)
{
start = false;
}
if(start)
{
if(FastMode)
{
x = (int32)*(vs16 *)0x08000002;
y = (int32)*(vs16 *)0x08000004;
z = (int32)*(vs16 *)0x08000006;
scalex = 0.03125 * divf32(x, sqrtf32(mulf32(x,x) + mulf32(z,z)));
scaley = 0.03125 * divf32(y, sqrtf32(mulf32(y,y) + mulf32(z,z)));
// rotatex = (x < 0)? scalex : 180 - scalex;
// rotatey = (y < 0)? scaley : 180 - scaley;
iprintf("\x1b[18;0HrotateX = %05D", (s32)scalex);
iprintf("\x1b[19;0HrotateY = %05D", (s32)scaley);
iprintf("\x1b[20;0HState = %04X", *(vu16 *)0x08000000);
iprintf("\x1b[21;0HX = %05D", *(vs16 *)0x08000002);
iprintf("\x1b[22;0HY = %05D", *(vs16 *)0x08000004);
iprintf("\x1b[23;0HZ = %05D", *(vs16 *)0x08000006);
FILE* testWrite = fopen ("FATTest.txt", "wb"); //wb = create/truncate & write
fwrite("*(vs16 *)0x08000002", 16, 1, testWrite);
fwrite("*(vs16 *)0x08000004", 16, 1, testWrite);
fwrite("*(vs16 *)0x08000006", 16, 1, testWrite);
fclose(testWrite);
}
else
{
iprintf("\x1b[20;0HState = %04X", SMReadREG(0x27));
iprintf("\x1b[21;0HX = %05D", (s16)(SMReadREG(0x28) | (SMReadREG(0x29)<<8)));
iprintf("\x1b[22;0HY = %05D", (s16)(SMReadREG(0x2A) | (SMReadREG(0x2B)<<8)));
iprintf("\x1b[23;0HZ = %05D", (s16)(SMReadREG(0x2C) | (SMReadREG(0x2D)<<8)));
}
}
}
return 0;
黄色部分是将内容写入文本文件的,程序可以编译执行,但无法创建和写入文件,请高手分析!~