Skip to content

Instantly share code, notes, and snippets.

@aont
Created November 6, 2010 13:27
Show Gist options
  • Save aont/665422 to your computer and use it in GitHub Desktop.
Save aont/665422 to your computer and use it in GitHub Desktop.
#include "gba.h"
int main()
{
// 画面モード設定
SetMode(MODE_0 | BG0_ENABLE | 0x0);
REG_BG0CNT = (BG_SIZE_0 | BG_256_COLOR | CHAR_BASE(0) | MAP_BASE(28));
u16* chr = CHAR_BASE_ADR(0); // キャラクタデータ
u16* map = MAP_BASE_ADR(28); // マップデータ
u16* pal = BG_PALETTE; // BGパレット
// パレット設定
pal[0] = RGB5( 0, 0, 0);
pal[1] = RGB5(31, 31, 31);
pal[2] = RGB5(31, 0, 0);
pal[3] = RGB5(0, 0, 31);
u16 i,j;
i=0;
// キャラクタデータ
j=i;
for(; i-j<32; i++)
{
chr[i] = 1 + (1<<8);
}
j=i;
for(; i-j<32; i++)
{
chr[i] = 0 + (0<<8);
}
j=i;
for(; i-j<32; i++)
{
chr[i] = 2 + (2<<8);
}
j=i;
for(; i-j<32; i++)
{
chr[i] = 3 + (3<<8);
}
j=i;
for(; i-j<32; i++)
{
chr[i] = 3 + (2<<8);
}
// 現在位置など
u16 x = 0;
u16 y = 0;
map[0] = 1;
u16 col=1;
// 割り込み初期化
irqInit();
// VBlankIntrWait()を使用可能にする
irqEnable(IRQ_VBLANK);
for(;;)
{
if( !(REG_KEYINPUT & KEY_UP) )
{
if(y>0)
{
map[y*32+x] = 0;
y--;
map[y*32+x] = col;
}
}
if( !(REG_KEYINPUT & KEY_DOWN) )
{
if(y<19)
{
map[y*32+x] = 0;
y++;
map[y*32+x] = col;
}
}
if( !(REG_KEYINPUT & KEY_LEFT) )
{
if(x>0)
{
map[y*32+x] = 0;
x--;
map[y*32+x] = col;
}
}
if( !(REG_KEYINPUT & KEY_RIGHT) )
{
if(x<29)
{
map[y*32+x] = 0;
x++;
map[y*32+x] = col;
}
}
u16 a = !(REG_KEYINPUT & KEY_A);
u16 b = !(REG_KEYINPUT & KEY_B);
if( a & b )
{
col=4;
map[y*32+x] = col;
}
else if( a )
{
col=2;
map[y*32+x] = col;
}
else if( b )
{
col=3;
map[y*32+x] = col;
}
else
{
col=1;
map[y*32+x] = col;
}
// 垂直同期を待つ。
VBlankIntrWait();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment