Created
November 6, 2010 13:28
-
-
Save aont/665424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************/ | |
/* Sprite */ | |
/************************************/ | |
#include <gba.h> | |
void SpriteMove(u16 num, s16 x, s16 y) | |
{ | |
OBJATTR* sp = (OBJATTR*)OAM + num; | |
if(x<0) x += 512; | |
if(y<0) y += 256; | |
sp->attr1 &= 0xfe00; | |
sp->attr0 &= 0xff00; | |
sp->attr1 |= (x & 0x01ff); | |
sp->attr0 |= (y & 0x00ff); | |
} | |
//--------------------------------------------------------------------------- | |
void SpriteSetSize(u16 num, u16 size, u16 form, u16 col) | |
{ | |
OBJATTR* sp = (OBJATTR*)OAM + num; | |
sp->attr0 &= 0x1fff; | |
sp->attr1 &= 0x3fff; | |
sp->attr0 |= col | form | (160); | |
sp->attr1 |= size | (240); | |
} | |
//--------------------------------------------------------------------------- | |
void SpriteSetChr(u16 num, u16 ch) | |
{ | |
OBJATTR* sp = (OBJATTR*)OAM + num; | |
sp->attr2 &= 0xfc00; | |
sp->attr2 |= ch; | |
} | |
//--------------------------------------------------------------------------- | |
void SpriteInit() | |
{ | |
u16 i; | |
for(i=0; i<128; i++) | |
{ | |
SpriteMove(i, 240, 160); | |
} | |
} | |
//--------------------------------------------------------------------------- | |
int main() | |
{ | |
// モード設定 | |
SetMode(MODE_0 | OBJ_ENABLE | OBJ_1D_MAP); | |
u16* oam = OBJ_BASE_ADR; // スプライトデータ | |
u16* pal = OBJ_COLORS; // スプライトパレット | |
u16 i; | |
// データの格納 | |
for(i=0; i<4*4*4; i++) | |
{ | |
oam[i] = i%16 + ((i%16)<<4) + ((i%16)<<8) + ((15-i%16)<<12); | |
} | |
// パレットの格納 | |
for(i=0; i<16; i++) | |
{ | |
pal[i] = RGB5(i*2,i*2,i*2); | |
} | |
SpriteInit(); | |
SpriteSetSize(0, OBJ_SIZE(1), OBJ_SQUARE, OBJ_16_COLOR); | |
SpriteSetChr (0, 0); | |
// 割り込み初期化 | |
irqInit(); | |
// VBlankIntrWait()を使用可能にする | |
irqEnable(IRQ_VBLANK); | |
int x; | |
for(x=0;;x++) | |
{ | |
SpriteMove (0, x, 0); | |
// 垂直同期を待つ。 | |
VBlankIntrWait(); | |
x%=240; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment