// Example from http://www.fampennings.nl/maarten/nds #include "nds.h" void memcpy16( u16 *dst, u16 *src, int numbytes ) { int i= numbytes / 2; while( i>0 ) { *dst= *src; dst++; src++; i--; } } u16 palette[]= { /*0*/ RGB15( 0, 0, 0), // index 0 is transparant /*1*/ RGB15(31,31,31), // white background /*2*/ RGB15( 0, 0,31), // blue for cell borders /*3*/ RGB15(31, 0, 0) // red for dot }; u8 tiles[] = { // completely white 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, // blue border 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 0,0,0,0,0,0,0,2, 2,2,2,2,2,2,2,2, // red dot 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,3,3,3,0,0,0, 0,0,3,3,3,0,0,0, 0,0,3,3,3,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }; int main(void) { int i; // Enable both screens and both 2D cores REG_POWERCNT= POWER_ALL_2D; // Set up main core DISPLAY_CR= MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE; BG0_CR= BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY_3; // back BG1_CR= BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(1) | BG_PRIORITY_2; VRAM_A_CR= VRAM_ENABLE | VRAM_A_MAIN_BG; memcpy16( BG_PALETTE, palette, sizeof(palette) ); memcpy16( (u16*)BG_TILE_RAM(1), (u16*)tiles, sizeof(tiles) ); for( i=0; i<32*32; i++ ) ((u16*)BG_MAP_RAM(0))[i]= 0; // 0 is tile white for( i=0; i<32*32; i++ ) ((u16*)BG_MAP_RAM(1))[i]= 1; // 1 is tile cell // Set up sub core SUB_DISPLAY_CR= MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE; SUB_BG0_CR= BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1) | BG_PRIORITY_3; // back SUB_BG1_CR= BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(1) | BG_PRIORITY_2; VRAM_C_CR= VRAM_ENABLE | VRAM_C_SUB_BG; memcpy16( BG_PALETTE_SUB, palette, sizeof(palette) ); memcpy16( (u16*)BG_TILE_RAM_SUB(1), (u16*)tiles, sizeof(tiles) ); for( i=0; i<32*32; i++ ) ((u16*)BG_MAP_RAM_SUB(0))[i]= 0; // 0 is tile white for( i=0; i<32*32; i++ ) ((u16*)BG_MAP_RAM_SUB(1))[i]= 2; // 2 is tile dot // Flush key buffer scanKeys(); while( keysDown() ) scanKeys(); int bg1_x= 0; int bg1_y= 0; while(1) { scanKeys(); if( keysDown() & KEY_R ) REG_POWERCNT^= POWER_SWAP_LCDS; if( keysDown() & KEY_L ) REG_POWERCNT^= POWER_LCD; if( keysDown() & KEY_X ) DISPLAY_CR^= DISPLAY_BG0_ACTIVE; if( keysDown() & KEY_Y ) DISPLAY_CR^= DISPLAY_BG1_ACTIVE; if( keysDown() & KEY_A ) SUB_DISPLAY_CR^= DISPLAY_BG0_ACTIVE; if( keysDown() & KEY_B ) SUB_DISPLAY_CR^= DISPLAY_BG1_ACTIVE; if( keysDown() & KEY_DOWN ) { bg1_y--; BG1_Y0=bg1_y; SUB_BG1_Y0=bg1_y; } if( keysDown() & KEY_UP ) { bg1_y++; BG1_Y0=bg1_y; SUB_BG1_Y0=bg1_y; } if( keysDown() & KEY_RIGHT ) { bg1_x--; BG1_X0=bg1_x; SUB_BG1_X0=bg1_x; } if( keysDown() & KEY_LEFT ) { bg1_x++; BG1_X0=bg1_x; SUB_BG1_X0=bg1_x; } } return 0; }