⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 嵌入式开发库文件
💻 CPP
字号:
/*---------------------------------------------------------------------------------	$Id: main.cpp,v 1.7 2006/06/18 21:32:41 wntrmute Exp $	Simple console print demo	-- dovoto	$Log: main.cpp,v $	Revision 1.7  2006/06/18 21:32:41  wntrmute	tidy up examples		Revision 1.6  2005/09/16 12:20:32  wntrmute	corrected iprintfs		Revision 1.5  2005/09/12 18:32:38  wntrmute	removed *printAt replaced with ansi escape sequences		Revision 1.4  2005/09/05 00:32:19  wntrmute	removed references to IPC struct	replaced with API functions		Revision 1.3  2005/08/31 03:02:39  wntrmute	updated for new stdio support		Revision 1.2  2005/08/03 06:36:30  wntrmute	added logging	added display of pixel co-ords	---------------------------------------------------------------------------------*/#include <nds.h>#include "ShakeMe.h"#include "math.h"#include <stdio.h>//---------------------------------------------------------------------------------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);			}			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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -