DS T050049. PSP DS DS DS RPG DS OS Windows XP DevkiPro OS DS CPU ARM devkitarm MSYS MinGW MSYS MinGW Unix OS C++ C++ make nds nds DS DS micro SD Card nds DS DS DS nds C Java C++ nds nds DS
2008 DS T050049
1 1 2 1 2.1 devkitpro.................................... 1 2.2 MinGW MSYS................................ 2 2.3 Emulator.................................... 4 3 DS 5 3.1 BG-MAP................................ 5 3.2........................ 5 4 6 4.1.......................... 6 4.2.......................... 7 5 8 5.1................................ 9 5.2.................................. 9 5.3.............................. 10 5.4 main..................................... 11 6 13 I 1
1 DS DS DS DS C++ DS DS 2 OS Windows XP DS C++ DS CPU ARM ARM devkitpro cpp nds MinGW MSYS cpp make nds NO$GBA Windows Vista make vista 2.1 devkitpro devkitpro DS PSP DS SOUCEFORGE.NET devkitpro 2.1 devkitpro devkitpro devkitproupdater-1.4.9.exe 1
2.1: devkitpro nds.h 2.2 2.2: 2.3: 2.3 Path C:devkitPro\devkitProARM\bin; nds.h nds.h 2.2 MinGW MSYS MinGW Windows GNU MSYS devkitpro 2
2.4: MinGW SOUCFORGE.NET MinGW 2.4 MinGW 2.5: MSYS devkitpro MinGW 5.1.4 MinGW MSYS MSYS MinGW Windows CUI MinGW Unix CUI 2.5 MSYS 3
devkitpro Path C:\MinGW\bin; C:\msys\1.0\bin; make 2.3 Emulator OS CPU OS(CPU) DS DS NO$GBA ( GBA) GBA GBA DS DS http://nocash.emubase.de/ NO$GBA NO$GBA 2.7: NO$GBA 2.6: Freeware 4
windows version devkitpro MinGW MSYS NO$GBA 3 DS 3.1 BG-MAP DS BG BG 1 Text Affine Extended Mode BG0 BG1 BG2 BG3 0 Text/3D Text Text Text 1 Text/3D Text Text Affine 2 Text/3D Text Affine Affine 3 Text/3D Text Text Extended 4 Text/3D Text Affine Extended 5 Text/3D Text Extended Extended 6 3D - Large - 1: BG Text 8x8 32x32 BG-Map Affine Text 8x8 16x16 128x128 Extended 32,768 Extendet Bitmap 3.2 DS grit bmp png DS devkitpro 5
devkitpro grit [4].grit sample.bmp 0 grit.exe sample.bmp -gt -gb8 build sample.grit # bitmap format -gt # 16 bit bitmap -gb8 data make 4 4.1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <nds.h> #include <stdio.h> volatile int frame = 0; void vblank() { frame++; int main(void) { irqinit(); irqset(irq VBLANK, vblank); irqenable(irq VBLANK); videosetmode(0); videosetmodesub(mode 0 2D DISPLAY BG0 ACTIVE); vramsetbankc(vram C MAIN BG); 6
18 BG0 CR = BG MAP BASE(31); 19 20 21 22 23 24 25 26 27 28 SUB BG0 CR = BG MAP BASE(31); BG PALETTE SUB[255] = RGB15(31,31,31); consoleinitdefault((u16 )SCREEN BASE BLOCK(31), (u16 )CHAR BASE BLOCK(0), 16); for(;;) swiwaitforvblank(); 12 13 14 irqinit(); irqset(irq_vblank,vblank); irqenable(irq_vblank); 15 16 17 videosetmode(0); videosetmodesub(mode_0_2d) DISPLAY_BG0_ACTIVE); vramsetbankc(fram_c_main_bg); 3-1 15 16 (0) 4.2 #include <nds.h> #include <stdio.h> #include "othelloboard.h" int main(void) { irqinit(); irqset(irq VBLANK, 0); 7
videosetmode(mode 5 2D DISPLAY BG3 ACTIVE); vramsetbanka(vram A MAIN BG 0x06000000); lcdmainonbottom(); BG3 CR = BG BMP16 256x256 BG BMP BASE(0); BG3 YDX = 0; BG3 XDX = 1 8; BG3 XDY = 0; BG3 YDY = 1 8; BG3 CX = 0; BG3 CY = 0; for(int i = 0; i < 256 192; i++) { ((u16 )BG BMP RAM(0))[i] = ((u16 )othelloboardbitmap)[i] BIT(15);; while(1) { swiwaitforvblank(); return 0; lcdmainonbottom(); BG3_CR = BG_BMP16_256x256 BG_BMP_BASE(0); VRAM DS BG3_YDX = 0; BG3_CY = 0; for 5 DS 8
27 5.1 char levelmap[max_level][80] = { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 3, 8, 13, 18, 23, 1, 1, 0, 0, 1, 4, 9, 14, 19, 24, 1, 1, 0, 0, 1, 5, 10, 15, 20, 25, 1, 1, 0, 0, 1, 6, 11, 16, 21, 26, 1, 1, 0, 0, 1, 7, 12, 17, 22, 27, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 17, 3, 16, 21, 10, 1, 1, 0, 0, 1, 26, 13, 22, 9, 5, 1, 1, 0, 0, 1, 15, 8, 4, 14, 18, 1, 1, 0, 0, 1, 20, 24, 12, 11, 6, 1, 1, 0, 0, 1, 25, 19, 7, 23, 27, 2, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ; 27 5.2 void setvramfrommap(u16* mapmemory, char* map) { for(int y = 0; y < 8; y++) { for(int x = 0; x < 10; x++) { char c = (*map++) * 9; mapmemory[x * 3 + y * 3 * 32] = c; 9
mapmemory[x * 3 + y * 3 * 32 + 1] = c + 1; mapmemory[x * 3 + y * 3* 32 + 2] = c + 2; mapmemory[x * 3 + (y * 3 + 1) * 32] = c + 3; mapmemory[x * 3 + (y * 3 + 1) * 32 + 1] = c + 4; mapmemory[x * 3 + (y * 3 + 1) * 32 + 2] = c + 5; mapmemory[x * 3 + (y * 3 + 2) * 32] = c + 6; mapmemory[x * 3 + (y * 3 + 2) * 32 + 1] = c + 7; mapmemory[x * 3 + (y * 3 + 2) * 32 + 2] = c + 8; VRAM DS 8x8 24 24 *9 5.3 void move(int dx, int dy, char*map) { int pos = 0; int a, b, c, d, e, Q; Q = 2; while(map[pos]!= Q) { pos++; int dp = dx + dy * 10; a = map[pos + dp]; b = map[pos + dp + dp]; c = map[pos + dp + dp + dp]; d = map[pos + dp + dp + dp + dp]; e = map[pos + dp + dp + dp + dp + dp]; if(a == 1) { count--; return; 10
if(b == 1 (b > 2 && b <= 27) (c > 2 && c <= 27) (d > 2 && d <= 27) e == 1) { map[pos] = a; map[pos + dp] = Q; return; pos map Q = 2 while Q pos pos + dp a = map[pos + dp] b c d e if if (a == 1) count main if b e b, c, d pos + dp 5.4 main 5.1 5.2 5.3 main int main(void) { /* */ swicopy(soukobanpal, BG_PALETTE 256); /* */ swicopy(soukobantiles, tilememory, 24 * 24 * 28 / 2); char map[80]; swicopy(levelmap[0], map, 40); (1) scankeys(); if(kesdown()) { if(keysdown() & KEY_A) { (2) swicopy(levelmap[1], 40); 11
while(1) { iprintf("\x1b[10;0h count = %04d\n", count); scankeys(); if(keysdown()) { if(keyscown() & KEY_RIGHT){ count++; move(-1, 0, map); else if(keyscown() & KEY_LEFT){ count++; move(1, 0, map); else if(keyscown() & KEY_UP){ count++; move(0, -1, map); else if(keyscown() & KEY_DOWN){ count++; move(0, 1, map); else if(keyscown() & KEY_START){ swicopy(levelmap[stage],map, 40); count = 0; setbramfrommap(mapmemory, map); swiwaitforvblank(); return 0; (1) (2) DS A ( ) levelmap[1] While if count++; 5.3 count ; main count count 5.3 main count ; if else if(keysdown() & KEY_START) count 0 12
6 DS DS C++ [1] DS DS DS 13
[1] http://void-main.org/dsprogram/ Nintendo DS [2] http://meraman.dip.jp/index.php?frontpage [3] http://akkera102.sakura.ne.jp/gbadev/ GBA develop Wiki [4] http://www.coranac.com/man/grit/html/grit.htm i. Grit 0.8.3 : Table of Contents 14
I #include <nds.h> #include <stdio.h> #include "souko.h" #define MAX LEVEL (4) char levelmap[max LEVEL][80] = { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 2, 9, 6, 1, 1, 1, 0, 0, 1, 1, 5, 8, 7, 1, 1, 1, 0, 0, 1, 1, 3, 4, 10, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 ; void setvramfrommap(u16 mapmemory, char map) { for(int y = 0; y < 8; y++) { for(int x = 0; x < 10; x++) { char c = ( map++) 9; mapmemory[x 3 + y 3 32] = c; mapmemory[x 3 + y 3 32 + 1] = c + 1; mapmemory[x 3 + y 3 32 + 2] = c + 2; mapmemory[x 3 + (y 3 + 1) 32] = c + 3; mapmemory[x 3 + (y 3 + 1) 32 + 1] = c + 4; mapmemory[x 3 + (y 3 + 1) 32 + 2] = c + 5; mapmemory[x 3 + (y 3 + 2) 32] = c + 6; mapmemory[x 3 + (y 3 + 2) 32 + 1] = c + 7; mapmemory[x 3 + (y 3 + 2) 32 + 2] = c + 8; int checkclear(char map) { for(int i = 0; i < 80; i++) { 1
if(map[i] == 2) { return false; return true; void move(int dx, int dy, char map) { int pos = 0; int a,b, Q; Q = 10; while(map[pos] Q) { pos++; int dp = dx + dy 10; a = map[pos + dp]; b = map[pos + dp + dp]; if(a == 1) { return; if(b 9) { map[pos] = a; map[pos + dp] = Q; return; int main(void) { irqinit(); irqenable(irq VBLANK); videosetmode(mode 0 2D DISPLAY BG0 ACTIVE); videosetmodesub(mode 0 2D DISPLAY BG0 ACTIVE); vramsetmainbanks(vram A MAIN BG 0x06000000, VRAM B LCD, VRAM C SUB BG, VRAM D LCD); SUB BG0 CR = BG MAP BASE(31); BG PALETTE SUB[255] = RGB15(0,31,0); consoleinitdefault((u16 )SCREEN BASE BLOCK SUB(31), 2
(u16 )CHAR BASE BLOCK SUB(0), 16); lcdmainonbottom(); BG0 CR = BG 32x32 BG COLOR 256 BG MAP BASE(0) BG TILE BASE(1); swicopy(soukopal, BG PALETTE, 256); u8 tilememory = (u8 )BG TILE RAM(1); u16 mapmemory = (u16 )BG MAP RAM(0); swicopy(soukotiles, tilememory, 24 24 11 / 2); int stage = 0; int clear = 0; char map[80]; swicopy(levelmap[0], map, 40); while(1) { iprintf("\x1b[10;0h Stage %04d\n", stage + 1); scankeys(); if(keysdown()) { if(clear) { clear = 0; stage++; swicopy(levelmap[stage], map, 40); else if(keysdown() & KEY RIGHT) { move(1, 0, map); else if(keysdown() & KEY LEFT) { move( 1, 0, map); else if(keysdown() & KEY UP) { move(0, 1, map); else if(keysdown() & KEY DOWN) { move(0, 1, map); else if(keysdown() & KEY START) { swicopy(levelmap[stage], map, 40); setvramfrommap(mapmemory, map); swiwaitforvblank(); 3
return 0; 4