タイルマップ上下画面描画サンプル。


昼寝してました。
でも鼻が止まらないのは変わらず。
気を取り直して。


昨日作りたかった上下画面へのBGタイル描画サンプルを作成しました。
後は…BG 重ね合わせ、PCM 再生くらいでしょうか。

int bgInit(int layer, BgType type, BgSize size, int mapBase, int tileBase)
int bgInitSub(int layer, BgType type, BgSize size, int mapBase, int tileBase)
int layer			BG レイヤを 0〜3 で指定します。
BgType type		描画タイプを BgType 定義にある定数名で指定します。
BgSize size		描画データサイズを BgSize 定義にある定数名で指定します。
int mapBase		マップデータ読込先を 0〜15 の範囲から指定します。
int tileBase		タイルデータ読込先を 0〜31 の範囲から指定します。

int			設定のなされた BG レイヤ番号が返ります。


引数的には consoleInit 関数の第2〜第6引数まで全く同じですので
どちらか先に理解していればもう一方の理解にもそう時間は掛からないかと思います。


VRAMバンクの割り当てに関しては単純に割り当てれば
後は勝手に NDS が表示してくれるというような簡単なものではないので
技術資料を見て(何となくでも)理解しておくことをお勧めします。


BG Tile Map Main/Sub screen draw sample
Boot NDS v0.02


main.c

/*---------------------------------------------------------------------------------

	BG Tile Map Main/Sub screen draw sample
	Boot NDS  v0.02
	
	Version 1.00
	Oct 31, 2009
	
	By.REGEKATSU

---------------------------------------------------------------------------------*/

#include <nds.h>

#include "topBg.h"
#include "bottomBg.h"


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	
	int top_bg3, bottom_bg3;
	
	
	//initVideoMode
	videoSetMode(MODE_0_2D);
	videoSetModeSub(MODE_0_2D);
	
	//initVRAMBank
	vramSetBankA(VRAM_A_MAIN_BG);
	vramSetBankC(VRAM_C_SUB_BG);
	
	//initBG
	top_bg3 = bgInit(3, BgType_Text4bpp, BgSize_T_256x256, 0, 1);
	bottom_bg3 = bgInitSub(3, BgType_Text4bpp, BgSize_T_256x256, 0, 1);
	
	//initBGTiles
	swiCopy(topBgTiles, bgGetGfxPtr(top_bg3), topBgTilesLen / 2);
	swiCopy(bottomBgTiles, bgGetGfxPtr(bottom_bg3), bottomBgTilesLen / 2);
	
	//initBGMap
	swiCopy(topBgMap, bgGetMapPtr(top_bg3), topBgMapLen / 2);
	swiCopy(bottomBgMap, bgGetMapPtr(bottom_bg3), bottomBgMapLen / 2);
	
	//initBGPalette
	swiCopy(topBgPal, BG_PALETTE, topBgPalLen / 2);
	swiCopy(bottomBgPal, BG_PALETTE_SUB, bottomBgPalLen / 2);
	
	
	//infinityLoop
	while(1) {
		swiWaitForVBlank();
	}
	
}

//---------------------------------------------------------------------------------


topBg.grit

-gt
-gB4
-fts
-gu16
-mu16


bottomBg.grit

-gt
-gB4
-fts
-gu16
-mu16


プロジェクト一式は下記 URL からダウンロードすることができます。
ttp://page.freett.com/ntr/example/tilempds.zip