1 /* 	Matrix Stack test
2 
3 	Copyright 2010 DeSmuME team
4 
5     This file is part of DeSmuME
6 
7     DeSmuME is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     DeSmuME is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with DeSmuME; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
20 */
21 #include <nds.h>
22 #include <stdio.h>
23 
24 GL_MATRIX_MODE_ENUM modes[4] = {GL_PROJECTION, GL_POSITION, GL_MODELVIEW, GL_TEXTURE};
25 char	*modesTXT[4] = {"PROJECTION", "POSITION", "MODELVIEW", "TEXTURE"};
26 
27 PrintConsole *scr = consoleDemoInit();
28 
29 s32 POPstep = 0;
30 u32 mode = 0;
31 u32 POPs = 0, PUSHes = 0;
32 //---------------------------------------------------------------------------------
main(void)33 int main(void) {
34 //---------------------------------------------------------------------------------
35 	int keys;
36 	videoSetModeSub(MODE_0_2D);
37 	videoSetMode(MODE_0_3D);
38 
39 	vramSetBankA(VRAM_A_MAIN_BG);
40 	vramSetBankC(VRAM_C_SUB_BG);
41 
42 	consoleInit(scr, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
43 
44 	glInit();
45 	glMatrixMode(GL_PROJECTION);
46 	glFlush(0);
47 
48 	POPstep=0;
49 	mode = 0;
50 	POPs = 0;
51 	PUSHes = 0;
52 
53 	while(1) {
54 		scanKeys();
55 		keys = keysDown();
56 		if(keys & KEY_A)
57 		{
58 			glPushMatrix();
59 			PUSHes++;
60 		}
61 		if(keys & KEY_B)
62 		{
63 			glPopMatrix(POPstep);
64 			POPs++;
65 		}
66 		if(keys & KEY_X)
67 		{
68 			mode++;
69 			if (mode > 3) mode = 0;
70 			glMatrixMode(modes[mode]);
71 		}
72 
73 		if(keys & KEY_UP)
74 		{
75 			if (POPstep < 31) POPstep += 1;
76 		}
77 		if(keys & KEY_DOWN)
78 		{
79 			if (POPstep > -30) POPstep -= 1;
80 		}
81 
82 		consoleClear();
83 		iprintf("Matrix mode = %i:%s\n", mode, modesTXT[mode]);
84 		iprintf("\n");
85 		iprintf("GFX STATUS  = 0x%08X\n", GFX_STATUS);
86 		iprintf("\t - Pos&Vec level  = %i\n", (GFX_STATUS>>8)&0x1F);
87 		iprintf("\t - Proj.   level  = %i\n", (GFX_STATUS>>13)&0x01);
88 		iprintf("\t - Error %s\n", (GFX_STATUS>>15)&0x01?"YES":"no");
89 		iprintf("\n");
90 		iprintf("POP step    = %i\n", POPstep);
91 		iprintf("POP count    = %i\n", POPs);
92 		iprintf("PUSH count   = %i\n", PUSHes);
93 
94 		iprintf("\n");
95 		iprintf("A\t - PUSH\n");
96 		iprintf("B\t - POP\n");
97 		iprintf("UP\t- POP increment step\n");
98 		iprintf("DOWN - POP decrement step\n");
99 		iprintf("X\t - Change mode\n");
100 		swiWaitForVBlank();
101 	}
102 
103 	return 0;
104 }
105