// 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; // All four backgrounds are text/tiles (mode 0), but only use bg0, bg1, bg2 DISPLAY_CR= MODE_0_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE; // BGs are 32x32, 256 colors 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; BG2_CR= BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(2) | BG_TILE_BASE(1) | BG_PRIORITY_1; // front // Allocate VRAM_A to the main core for BGs VRAM_A_CR= VRAM_ENABLE | VRAM_A_MAIN_BG; // Copying palette memcpy16( BG_PALETTE, palette, sizeof(palette) ); // Copy down-slash tile memcpy16( (u16*)BG_TILE_RAM(1), (u16*)tiles, sizeof(tiles) ); // Fill tile map 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 for( i=0; i<32*32; i++ ) ((u16*)BG_MAP_RAM(2))[i]= 2; // 2 is tile_dot // Flush key buffer scanKeys(); while( keysDown() ) scanKeys(); int bg2_x= 0; int bg2_y= 0; while(1) { scanKeys(); if( keysDown() & KEY_R ) REG_POWERCNT^= POWER_SWAP_LCDS; // =lcdSwap() if( keysDown() & KEY_L ) REG_POWERCNT^= POWER_LCD; if( keysDown() & KEY_X ) DISPLAY_CR^= DISPLAY_BG0_ACTIVE; if( keysDown() & KEY_A ) DISPLAY_CR^= DISPLAY_BG1_ACTIVE; if( keysDown() & KEY_B ) DISPLAY_CR^= DISPLAY_BG2_ACTIVE; if( keysDown() & KEY_Y ) { int p1=BG1_CR&3; int p2=BG2_CR&3; BG1_CR=(BG1_CR&~3)|p2; BG2_CR=(BG2_CR&~3)|p1; } if( keysDown() & KEY_DOWN ) { bg2_y--; BG2_Y0=bg2_y; } if( keysDown() & KEY_UP ) { bg2_y++; BG2_Y0=bg2_y; } if( keysDown() & KEY_RIGHT ) { bg2_x--; BG2_X0=bg2_x; } if( keysDown() & KEY_LEFT ) { bg2_x++; BG2_X0=bg2_x; } } return 0; }