GCCのDS環境への移植です。
サンプルのビルド方法
コマンドラインから、
cd C:\devkitPro\examples\nds
make
すると、
C:\devkitPro\examples\nds\[[bin]]
フォルダにサンプル.ndsが沢山出てきます。
処理が終わるまで数分かかります。
ビルドの流れ
- ARM9用のコードを書く(必須)
- ARM7用のコードを別ファイルに書く(オプション)
- ARM9・7用のコードをGCCでコンパイル
- コンパイルされたオブジェクトファイルをGCCでELF形式に変換
- objcopyコマンドでELFからバイナリ形式に変換
- ndstoolコマンドでARM9とARM7のバイナリを結合
Hello World
#include <nds.h> // our NDS library
#include <nds/arm9/console.h> //basic print funcionality
#include <stdio.h> //Standard Input Output library
int main(void) { // this is the start of our main function.
videoSetMode(0); //not using the main screen (remember the touch screen is the main screen and the top screen is the sub screen).
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text
vramSetBankC(VRAM_C_SUB_BG); // this says use block of memory C for this display
SUB_BG0_CR = BG_MAP_BASE(31); //set the background to black.
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); // defines the layout of the screen. More later.
iprintf("Hello World!"); // At last! print Hello World on the screen.
while(1) { // We have printed what we wnated; we now need to wait forever (or until you switch off)
swiWaitForVBlank(); // The DS screens refresh 60 times a second. This command says wait for the next screen refresh.
} // this is the end of our while loop
return 0; // this says if we ever get here, return the value 0 (but we never do get here...)
} // this is the end of our main function
Hello Worldのビルド (ファイル名を main.c としてコンパイルしています)
"C:\devkitPro\devkitARM\bin\arm-eabi-g++.exe" -g \
-Wall -O2 -mcpu=arm9tdmi -mtune=arm9tdmi \
-fomit-frame-pointer -ffast-math -mthumb-interwork \
-IC:\devkitPro\libnds\include -DARM9 \
-c main.c -omain.o
- コンパイルされたオブジェクトファイルをGCCでELF形式に変換
"C:\devkitPro\devkitARM\bin\arm-eabi-g++.exe" -g \
-mthumb-interwork -mno-fpu -specs=ds_arm9.specs \
main.o -LC:\devkitPro\[[libnds]]\lib -lnds9 -o main.elf
- objcopyコマンドでELFからバイナリ形式に変換
"C:\devkitPro\devkitARM\bin\arm-eabi-objcopy.exe" -O \
binary main.elf main.bin
ndstool -c hello.nds -9 main.bin
最終更新:2007年06月18日 10:40