00 NDS 홈브루 프로젝트 생성
원문 : http://kkamagui.springnote.com/pages/415865
들어가기 전에...
1.필수 파일
NDS 홈브루 프로젝트를 만들고 NDS 롬 파일을 생성하기위해서는 최소 2개의 파일과 1개의 폴더가 필요하다.
필요한 파일은 Makefile과 Main.cpp 이고 필요한 폴더는 Source 폴더이다. 폴더 이름을 Source 말고 다른 것으로 하면 컴파일이 안된다. 그 이유는 makefile에 포함된 아래와 같은 내용 때문이다.
- ......
- TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := gfx source data
INCLUDES := include build
- ......
- CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))
- ......
위에서 보는 것과 같이 gfx, source, data 폴더 아래에 있는 전체 폴더를 돌면서 폴더가 아닌 *.c *.cpp *.s *.bin 파일을 찾도록 되어있기 때문이다. makefile에 대한 자세한 내용은 00 NDS makefile 분석 파일을 참조하도록 하자.
만약 NDS 홈브루 개발을 위한 최소한의 파일과 폴더만을 이용해서 구성한다면 아래와 같을 것이다.

<홈브루 생성을 위한 최소한의 파일 및 폴더>
2.main.cpp 및 기타 파일 구성
main.cpp에 있는 내용은 examples 폴더에있는 Helloworld 예제로 복사해넣었다. 만약 다수의 프로젝트 파일이 있다면 위에서 언급한 폴더에 넣거나 그 하위 폴더를 생성해서 넣으면 된다.
- /*---------------------------------------------------------------------------------
- $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 <stdio.h>
- volatile int frame = 0;
- //---------------------------------------------------------------------------------
void Vblank() {
//---------------------------------------------------------------------------------
frame++;
}
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
touchPosition touchXY;
- 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(31,31,31); //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);
- iprintf(" Hello DS dev'rs\n");
iprintf(" www.devkitpro.org\n");
iprintf(" www.drunkencoders.com");
- while(1) {
swiWaitForVBlank();
touchXY=touchReadXY();
- // print at using ansi escape sequence \x1b[line;columnH
iprintf("\x1b[10;0HFrame = %d",frame);
iprintf("\x1b[16;0HTouch x = %04X, %04X\n", touchXY.x, touchXY.px);
iprintf("Touch y = %04X, %04X\n", touchXY.y, touchXY.py);
}
- return 0;
}
3.실행
00 NDS 개발 킷(Devkit Pro) 설치 에 나와있는 컴파일 및 링크 방법을 이용해서 NDS 롬파일을 만들고 iDeaS에서 실행한 결과이다.

4.마치며...
makefile이 상당히 편리하게 되어있는 관계로 그리 어렵지않게 새 프로젝트를 생성할 수 있었다. 이제 홈브루의 세계로 빠져보자. @0@)/~