コード例 #1
0
ファイル: example2.cpp プロジェクト: imclab/pimpmobile
int main()
{
//	REG_WAITCNT = 0x46d6; // lets set some cool waitstates...
	REG_WAITCNT = 0x46da; // lets set some cool waitstates...
	
	irqInit();
	irqEnable(IRQ_VBLANK);
	consoleInit(0, 4, 0, NULL, 0, 15);

	BG_COLORS[0] = RGB5(0, 0, 0);
	BG_COLORS[241] = RGB5(31, 31, 31);
	REG_DISPCNT = MODE_0 | BG0_ON;

	gbfs_init(1);
	
	pimp_sample_bank sb;
	FILE *fp = fopen("dxn-oopk.xm", "rb");
	if (!fp)
	{
		fprintf(stderr, "file not found\n");
		return 1;
	}
	pimp_module *mod = load_module_xm(fp, &sb);
	fclose(fp);
	fp = NULL;
	
	if (NULL == mod)
	{
		fprintf(stderr, "failed to load module\n");
		return 1;
	}

	pimp_gba_init(mod, sb.data);
	pimp_gba_set_callback(callback);

	irqSet(IRQ_TIMER3, timer3);
	irqEnable(IRQ_TIMER3);
	REG_TM3CNT_L = 0;
	REG_TM3CNT_H = TIMER_START | TIMER_IRQ | 2;
	
	irqSet(IRQ_VBLANK, vblank);
	irqEnable(IRQ_VBLANK);
	
	while (1)
	{
		VBlankIntrWait();
		scanKeys();
		int keys = keysDown();
		if (keys & KEY_UP)    pimp_gba_set_pos(0, pimp_gba_get_order() - 1);
		if (keys & KEY_DOWN)  pimp_gba_set_pos(0, pimp_gba_get_order() + 1);
		if (keys & KEY_RIGHT) pimp_gba_set_pos(pimp_gba_get_row() + 8, pimp_gba_get_order());
		if (keys & KEY_LEFT)  pimp_gba_set_pos(pimp_gba_get_row() - 8, pimp_gba_get_order());
		iprintf("%d %d\n", pimp_gba_get_order(), pimp_gba_get_row());
	}
	
	pimp_gba_close();
	return 0;
}
コード例 #2
0
ファイル: overlay.c プロジェクト: kusma/nds
int main()
{
	irqInit();
	irqEnable(IRQ_VBLANK);
	consoleInit(0, 4, 0, NULL, 0, 15);
	BG_COLORS[0]=RGB8(58,110,165);
	BG_COLORS[241]=RGB5(31,31,31);

	SetMode(MODE_0 | BG0_ON);

	/* verify that the overlays are indeed overlapping */
	printf("overlay1_test: %p\noverlay2_test: %p\n", overlay1_test, overlay2_test);
	
	/* set overlay 1 and run code from it */
	memcpy(__iwram_overlay_start, __load_start_iwram1, (int)__load_stop_iwram1 - (int)__load_start_iwram1);
	overlay1_test();
	
	/* set overlay 2 and run code from it */
	memcpy(__iwram_overlay_start, __load_start_iwram2, (int)__load_stop_iwram2 - (int)__load_start_iwram2);
	overlay2_test();
	
	/* back to normal */
	memcpy(__iwram_overlay_start, __load_start_iwram0, (int)__load_stop_iwram0 - (int)__load_start_iwram0);
	while(1);
}
コード例 #3
0
ファイル: font.c プロジェクト: ArtemioUrbina/240pTestSuite
void InitTextColor(u8 layer, u8 palette, u16 front, u16 back)
{
	consoleInitTextMine(layer, palette, &fontback);
	setPaletteColor(palette * 0x10, RGB5(31, 0, 31));
	setPaletteColor(palette * 0x10 + 1, front);
	setPaletteColor(palette * 0x10 + 2, back);
}
コード例 #4
0
ファイル: gba_assert.c プロジェクト: imclab/newton
void __assert(const char *file, const int line, const char *msg)
{
#if 1
	irqInit();
	irqEnable(IRQ_VBLANK);
	consoleInit(0, 4, 0, NULL, 0, 15);

	BG_COLORS[0] = RGB5(0, 0, 0);
	BG_COLORS[241] = RGB5(31, 31, 31);
	REG_DISPCNT = MODE_0 | BG0_ON;
	
	printf("assertation failed \"%s\" (%s:%d)\n", msg, file, line);
	
	while (1);
	
#else

	/* give vba a nice log-message */
	dprintf("assertation failed \"%s\" (%s:%d)\n", msg, file, line);

	/* make sure we're in the right mode */
	SetMode(MODE_4 | BG2_ENABLE);

	/* clear the front buffer to color 0, in case it has been modified */
	u32 col = 0;
	CpuFastSet(&col, MODE5_FB, DMA_SRC_FIXED | ((240 * 160) / 4));

	while (1)
	{
		/* wait for vsync, clear screen to pink, wait for the end of vsync */
		while (REG_VCOUNT != 160);
		BG_COLORS[0] = RGB5(31, 0, 31);
		while (REG_VCOUNT != 0);

		/* wait for vsync, clear screen to green, wait for the end of vsync */
		while (REG_VCOUNT != 160);
		BG_COLORS[0] = RGB5(0, 31, 0);
		while (REG_VCOUNT != 0);
	}
#endif
}
コード例 #5
0
ファイル: main.c プロジェクト: tastytentacles/GBA_Project
void code_init() {
	unsigned short* videopointer = (unsigned short*) 0x4000000;
	videopointer[0] = ((1 << 8));

	unsigned short* bg0pointer = (unsigned short*) 0x4000008;

	unsigned short* palatte = (unsigned short*) 0x05000000;
	palatte[0] = RGB5(1, 1, 1);

	videopointer = NULL; free(videopointer);
	bg0pointer = NULL; free(bg0pointer);
	palatte = NULL; free(palatte);
}
コード例 #6
0
ファイル: console.c プロジェクト: devkitPro/libgba
//---------------------------------------------------------------------------------
void consoleDemoInit() {
//---------------------------------------------------------------------------------
	// initialise the console
	// setting NULL & 0 for the font address & size uses the default font
	// The font should be a complete 1bit 8x8 ASCII font
	consoleInit(	0,		// charbase
					4,		// mapbase
					0,		// background number
					NULL,	// font
					0, 		// font size
					15		// 16 color palette
	);

	// set the screen colors, color 0 is the background color
	// the foreground color is index 1 of the selected 16 color palette
	BG_COLORS[0]=RGB8(58,110,165);
	BG_COLORS[241]=RGB5(31,31,31);

	SetMode(MODE_0 | BG0_ON);

}
コード例 #7
0
ファイル: functions.c プロジェクト: josepllberral/libjam
//------------------------------------------------------------------------------
// Graphic Functions MODE_0
//------------------------------------------------------------------------------
void InitJAM ()
{
	irqInit();
	irqEnable(IRQ_VBLANK);

	// setting NULL & 0 for the font address & size uses the default font
	consoleInit(	0,		// charbase
					4,		// mapbase
					0,		// background number
					NULL,	// font (should be a complete 1bit 8x8 ASCII font)
					0, 		// font size
					15		// 16 color palette
				);
	//consoleDemoInit();

	// set the screen colors, color 0 is the background color
	// the foreground color is index 1 of the selected 16 color palette
	BG_COLORS[0] = RGB8(58,110,165);
	BG_COLORS[241] = RGB5(31,31,31);

	SetMode(MODE_0 | BG0_ON);

	return;
}
コード例 #8
0
ファイル: TextureFormat.cpp プロジェクト: sidch/Thea
TextureFormat const *
TextureFormat::fromCode(Code code)
{
  switch (code)
  {
    case Code::L8:
      return L8();

    case Code::L16:
      return L16();

    case Code::L16F:
      return L16F();

    case Code::L32F:
      return L32F();

    case Code::A8:
      return A8();

    case Code::A16:
      return A16();

    case Code::A16F:
      return A16F();

    case Code::A32F:
      return A32F();

    case Code::LA4:
      return LA4();

    case Code::LA8:
      return LA8();

    case Code::LA16:
      return LA16();

    case Code::LA16F:
      return LA16F();
      break;

    case Code::LA32F:
      return LA32F();

    case Code::RGB5:
      return RGB5();

    case Code::RGB5A1:
      return RGB5A1();

    case Code::RGB8:
      return RGB8();

    case Code::RGB10:
      return RGB10();

    case Code::RGB10A2:
      return RGB10A2();

    case Code::RGB16:
      return RGB16();

    case Code::RGB32F:
      return RGB32F();

    case Code::R11G11B10F:
      return R11G11B10F();

    case Code::RGB9E5F:
      return RGB9E5F();

    case Code::RGB8I:
      return RGB8I();

    case Code::RGB8UI:
      return RGB8UI();

    case Code::ARGB8:
      return NULL;

    case Code::BGR8:
      return BGR8();

    case Code::BGRA8:
      return BGRA8();

    case Code::BGR16:
      return BGR16();

    case Code::BGRA16:
      return BGRA16();

    case Code::BGR32F:
      return BGR32F();

    case Code::BGRA32F:
      return BGRA32F();

    case Code::R8:
      return R8();

    case Code::RG8:
      return RG8();

    case Code::RG8I:
      return RG8I();

    case Code::RG8UI:
      return RG8UI();

    case Code::RG16F:
      return RG16F();

    case Code::RGBA8:
      return RGBA8();

    case Code::RGBA16:
      return RGBA16();

    case Code::RGBA16F:
      return RGBA16F();

    case Code::RGBA32F:
      return RGBA32F();

    case Code::RGBA32UI:
      return RGBA32UI();

    case Code::BAYER_RGGB8:

      // TODO
    case Code::BAYER_GRBG8:

      // TODO
    case Code::BAYER_GBRG8:

      // TODO
    case Code::BAYER_BGGR8:

      // TODO
    case Code::BAYER_RGGB32F:

      // TODO
    case Code::BAYER_GRBG32F:

      // TODO
    case Code::BAYER_GBRG32F:

      // TODO
    case Code::BAYER_BGGR32F:

      // TODO
    case Code::HSV8:

      // TODO
    case Code::HSV32F:
      // TODO
      return NULL;
      break;

    case Code::RGB_DXT1:
      return RGB_DXT1();
      break;

    case Code::RGBA_DXT1:
      return RGBA_DXT1();
      break;

    case Code::RGBA_DXT3:
      return RGBA_DXT3();
      break;

    case Code::RGBA_DXT5:
      return RGBA_DXT5();
      break;

    case Code::SRGB8:
      return SRGB8();
      break;

    case Code::SRGBA8:
      return SRGBA8();
      break;

    case Code::SL8:
      return SL8();
      break;

    case Code::SLA8:
      return SLA8();
      break;

    case Code::SRGB_DXT1:
      return SRGB_DXT1();
      break;

    case Code::SRGBA_DXT1:
      return SRGBA_DXT1();
      break;

    case Code::SRGBA_DXT3:
      return SRGBA_DXT3();
      break;

    case Code::SRGBA_DXT5:
      return SRGBA_DXT5();
      break;

    case Code::DEPTH16:
      return DEPTH16();
      break;

    case Code::DEPTH24:
      return DEPTH24();
      break;

    case Code::DEPTH32:
      return DEPTH32();
      break;

    case Code::DEPTH32F:
      return DEPTH32F();
      break;

    case Code::STENCIL1:
      return STENCIL1();
      break;

    case Code::STENCIL4:
      return STENCIL4();
      break;

    case Code::STENCIL8:
      return STENCIL8();
      break;

    case Code::STENCIL16:
      return STENCIL16();
      break;

    case Code::DEPTH24_STENCIL8:
      return DEPTH24_STENCIL8();
      break;

    case Code::YUV420_PLANAR:
      return YUV420_PLANAR();
      break;

    case Code::YUV422:
      return YUV422();
      break;

    case Code::YUV444:
      return YUV444();
      break;

    default:
      return NULL;
  }
}
コード例 #9
0
ファイル: console.c プロジェクト: gwicks/craps-gba
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------

	// the vblank interrupt must be enabled for VBlankIntrWait() to work
	// since the default dispatcher handles the bios flags no vblank handler
	// is required
	int gamecount = 1;
	
	
	irqInit();
	irqEnable(IRQ_VBLANK);

	//consoleDemoInit();
	consoleInit(	0,		/* charbase */
					4,		/* mapbase */
					0,		/* background number */
					NULL,	/* font */
					0, 		/* font size */
					15		/* 16 color palette */);
					
	BG_COLORS[0]=RGB8(0,0,0);
	BG_COLORS[241]=RGB5(31,31,31);

	SetMode(MODE_0 | BG0_ON);


	// ansi escape sequence to clear screen and home cursor
	// /x1b[line;columnH
	iprintf("\x1b[2J");

	// ansi escape sequence to set print co-ordinates
	// /x1b[line;columnH


	// ansi escape sequence to move cursor up
	// /x1b[linesA


	// ansi escape sequence to move cursor left
	// /x1b[columnsD


	// ansi escape sequence to move cursor down
	// /x1b[linesB
	

	// ansi escape sequence to move cursor right
	// /x1b[columnsC
	
	
	iprintf("\x1b[0;0HGames: %d",gamecount);

	while (1) {
		VBlankIntrWait();
		scanKeys();

		int keys_pressed = keysDown();
		int keys_released = keysUp();
		
		if (keys_pressed & KEY_UP)
		{
			gamecount = gamecount + 1;
			iprintf("\x1b[0;0H             ");
			iprintf("\x1b[0;0HGames: %d",gamecount);
		}
		if (keys_pressed & KEY_DOWN)
		{
			if (gamecount > 1)
			{
			gamecount = gamecount - 1;
			iprintf("\x1b[0;0H             ");
			iprintf("\x1b[0;0HGames: %d",gamecount);
			}
		}
		if (keys_pressed & KEY_A)
		{
			wincount = 0;
			rollstats[0] = 0;
			rollstats[1] = 0;
			rollstats[2] = 0;
			rollstats[3] = 0;
			rollstats[4] = 0;
			rollstats[5] = 0;
			simulateCraps(gamecount);
			iprintf("\x1b[1;0HWe simulated %d games",gamecount);
			iprintf("\x1b[2;0HYou won %d games",wincount);
			printStats();
		}
		
		
	}
}
コード例 #10
0
ファイル: main.cpp プロジェクト: yewton/jumpingdroid
int main() {
    /* ドロイド君の x, y 座標 */
    s16 dx = 120, dy = 120;
    /* りんごの x, y 座標 */
    const s16 ax = 160, ay = 120;
    /* 窓の x, y 座標 */
    const s16 wx = 40, wy = 40;
    /* タイルのベースアドレス */
    u16* tile = (u16*)TILE_BASE_ADR(0);
    /*
     * ドロイド君の状態。
     * 0 => 待機
     * 1 => ジャンプ準備中
     * 2 => ジャンプ中
     */
    int state = 0;
    /* 歩き状態 (0, 1, 2) */
    int wstate = 0;
    /* ドロイド君の y 方向の速度 */
    float vy = 0;
    /* フレーム数用の変数 */
    u16 f = 0;
    /* 表示するキャラクタ */
    u16 ch = 0;
    /* キー状態取得用変数 */
    u16 kd = 0;
    u16 kdr = 0;
    u16 ku = 0;
    u16 kh = 0;
    /* 汎用変数 */
    u16 i, xx, yy;

    /* フレーム数初期化 */
    frame = 0;

    /* 割り込みの初期化 */
    irqInit();
    /*
     * VBLANK 割り込みを有効化
     * これによって VBlankIntrWait() が使えるようになる
     */
    irqEnable(IRQ_VBLANK);

    /*
     * モードの設定。
     * MODE 0、スプライト有効化、BG0 有効化
     */
    SetMode(MODE_0 | OBJ_ENABLE | BG0_ON);

    /* スプライトのメモリ領域(OAM)にスプライトデータをコピー */
    GbaGraphics::setSpriteData(spritesTiles, spritesTilesLen / 2);

    /* スプライトと BG のパレットのメモリ領域にパレットデータをコピー */
    GbaGraphics::setSpritePalette(spritesPal, 16);
    GbaGraphics::setBGPalette(spritesPal, 16);
    GbaGraphics::setBGColor(RGB5(15,15,31));

    /* スプライトの初期化 */
    GbaGraphics::initSprites();

    /* ドロイド君の準備 */
    GbaGraphics::Sprite droid(0, 0, Sprite_16x16);
    droid.setPosition(dx, dy);
    droid.draw();

    /* りんごの準備 */
    GbaGraphics::Sprite apple(1, (2 * 32), Sprite_16x16);
    apple.setPosition(ax, ay);
    apple.draw();

    /* 窓の準備 */
    GbaGraphics::Sprite window(2, 2 + (2 * 32), Sprite_16x16);
    window.setPosition(wx, wy);
    window.draw();

    /* BG 0 の設定 */
    BGCTRL[0] = BG_MAP_BASE(31) | BG_16_COLOR | BG_SIZE_0 | TILE_BASE(0) | BG_PRIORITY(0);

    /* BG0 を初期化 */
    for ( xx = 0; xx < 32; xx++ ) {
        for ( yy = 0; yy < 32; yy++ ) {
            MAP[31][yy][xx] = 6 * 32;
        }
    }

    /* 画像をタイルにコピー */
    for ( i = 0; i < spritesTilesLen / 2; i++ ) {
        tile[i] = spritesTiles[i];
    }

    /* BG0 をセット */
    MAP[31][17][0] = 5 * 32;
    MAP[31][17][29] = 2 + 5 * 32;
    for ( i = 1; i < 29; i++ ) {
        MAP[31][17][i] = 1 + 5 * 32;
    }
    for ( xx = 0; xx < 30; xx++ ) {
        for ( yy = 18; yy < 32; yy++ ) {
            MAP[31][yy][xx] = 3 + 5 * 32;
        }
    }

    // コンソール出力のテスト
    cprintf("droid(%d, %d), apple(%d, %d), window(%d, %d), %s", dx, dy, ax, ay, wx, wy, "console test.");

    /* メインループ */
    while (1) {
        /* VBLANK 割り込み待ち */
        VBlankIntrWait();
        /* フレーム数カウント */
        frame += 1;
        /* キー状態取得 */
        scanKeys();
        kd = keysDown();
        kdr = keysDownRepeat();
        ku = keysUp();
        kh = keysHeld();

        switch(state) {
        case 0:
            /* 待機中 */
            if( (kd & KEY_UP) ) {
                state = 1;
                f = 0;
                ch = 0;
                break;
            }
            if( (kh & KEY_LEFT)  ) {
                dx--;
                droid.setHFlip(true);
            }
            if( (kh & KEY_RIGHT) ) {
                dx++;
                droid.setHFlip(false);
            }
            if( dx < -16 ) {
                dx = SCREEN_WIDTH;
            }
            if( kd & ( KEY_LEFT | KEY_RIGHT ) ) {
                wstate = 0;
                f = 0;
            }
            if( ku & ( KEY_LEFT | KEY_RIGHT ) ) {
                ch = 0;
            }
            if ( SCREEN_WIDTH < dx ) {
                dx = -16;
            }

            if ( kh & ( KEY_LEFT | KEY_RIGHT ) ) {
                /* 歩きモーション */
                if ( 5 < f++ ) {
                    switch ( wstate ) {
                    case 0:
                        wstate = 1;
                        ch = 2;
                        break;
                    case 1:
                        wstate = 2;
                        ch = 0;
                        break;
                    case 2:
                        wstate = 3;
                        ch = 4;
                        break;
                    default:
                        wstate = 0;
                        ch = 0;
                        break;
                    }
                    f = 0;
                }
            }

            if ( dy == (ay - 13) ) {
                if ( !(((ax - 11) < dx) &&
                       (dx < (ax + 11))) ) {
                    /* りんごから落ちる */
                    vy = -0.;
                    state = 2;
                    wstate = 0;
                    break;
                }
            }
            droid.setCharacter(ch);
            droid.setPosition(dx, dy);
            break;
        case 1:
        case 3:
            /* ジャンプ準備 */
            droid.setCharacter(6);
            if( 3 < f++ ) {
                vy = 4.;
                if ( 1 == state ) state = 2;
                else state = 4;
            }
            break;
        case 2:
        case 4:
            /* ジャンプ中 */
            if( (kd & KEY_UP) ) {
                /* 二段ジャンプ */
                if ( state == 2 ) {
                    state = 3;
                    f = 0;
                    break;
                }
            }
            if( kh & KEY_LEFT ) {
                dx--;
                droid.setHFlip(true);
            }
            if( kh & KEY_RIGHT ) {
                dx++;
                droid.setHFlip(false);
            }
            if( dx < -16 ) {
                dx = SCREEN_WIDTH;
            }
            if ( SCREEN_WIDTH < dx ) {
                dx = -16;
            }
            if( (0.5 < vy) && ( kh & KEY_UP ) ) {
                vy += 0.2;
            }
            dy -= (s16)vy;
            if(vy < 0) {
                droid.setCharacter(10);
            } else {
                droid.setCharacter(8);
            }
            if ( dy < 0 ) {
                dy = 0;
                vy = -0.;
            }

            if ( (vy < 0) &&
                 ((ax - 11) < dx) &&
                 (dx < (ax + 11)) ) {
                if ( ay - 13 < dy ) {
                    /* りんごに乗る */
                    dy = ay - 13;
                    state = 0;
                }
            }

            if ( 120 < dy ) {
                /* 着地 */
                dy = 120;
                state = 0;
            }
            droid.setPosition(dx, dy);
            vy = vy - 0.3;
            break;
        }
        droid.draw();
    }
}
コード例 #11
0
ファイル: main.cpp プロジェクト: kusma/nds
int main()
{
	irqInit();
	SetMode((LCDC_BITS)(MODE_1 | BG0_ON | BG2_ON | OBJ_ENABLE));
	
	irqSet(IRQ_VBLANK, vblank);
	irqEnable(IRQ_VBLANK);
	
	float xpos = 0;
	float ypos = 0;
	
	float xdir = 0;
	float ydir = 0;
	int dir = 0;
	
	BG_COLORS[0] = RGB5(31, 0, 31);
	CpuFastSet(tileset_img, OBJ_BASE_ADR, COPY32 | (256 * 16) / 4);
	CpuFastSet(tileset_pal, OBJ_COLORS, COPY32 | (256 / 4));
	
	CpuFastSet(tileset_img, PATRAM4(0, 0), COPY32 | (256 * 16) / 4);
	CpuFastSet(tileset_pal, BG_COLORS, COPY32 | (256 / 4));
	
	// mock up a map
/*	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[0] = 0;
	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[1] = 1;
	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[32] = 32;
	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[33] = 33;
	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[64] = 64;
	((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK))[65] = 65; */
	
	for (int y = 0; y < 32; ++y)
	{
		for (int x = 0; x < 32; ++x)
		{
			((vu16*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[x + y * 32] = 5;
		}
	}
	for (int x = 0; x < 32; ++x) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[x] = 16;
	for (int x = 0; x < 32; ++x) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[31 * 32 + x] = 16;
	for (int y = 0; y < 32; ++y) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[y * 32] = 16;
	for (int y = 0; y < 32; ++y) ((vu8*)MAP_BASE_ADR(MAP_BASE_BLOCK + 1))[y * 32 + 31] = 16;
	
	BGCTRL[0] = SCREEN_BASE(MAP_BASE_BLOCK + 0) | CHAR_BASE(0) | BG_SIZE_0 | BG_16_COLOR | BG_PRIORITY(1); // | CHAR_PALETTE(1);
	BGCTRL[2] = SCREEN_BASE(MAP_BASE_BLOCK + 1) | CHAR_BASE(0) | BG_SIZE_1 | BG_16_COLOR | BG_PRIORITY(0); // | CHAR_PALETTE(1);
	
	float rot = 0.0f;
	float last_rot = rot;
	float bg_scroll = 0;
	
	int frame = 0;
	while (1)
	{
		int sprite_frame = (int(floor(bg_scroll)) >> 3) & 1;
		if (fabs(xdir) < 1e-1) sprite_frame = 0;
//		if (ypos > 0) sprite_frame = 2;
		int tile_start = sprite_frame * 2;
		int pal = 0;
		
		for (int i = 0; i < 128; ++i)
		{
			sprites[i].attr0 = ATTR0_DISABLED;
		}
		
		int sprite = 0;
//		sprites[sprite].attr0 = OBJ_Y(int(ypos) + 80 - 8) | ATTR0_COLOR_16 | ATTR0_WIDE;
//		sprites[sprite].attr1 = OBJ_X(int(xpos) + 120) | OBJ_SIZE(Sprite_16x8) | (dir ? ATTR1_FLIP_X : 0);
		sprites[sprite].attr0 = OBJ_Y(int(0) + 80 - 16) | ATTR0_COLOR_16 | ATTR0_WIDE;
		sprites[sprite].attr1 = OBJ_X(int(0) + 120 - 8) | OBJ_SIZE(Sprite_16x8) | (dir ? ATTR1_FLIP_X : 0);
		sprites[sprite].attr2 = OBJ_CHAR(tile_start) | ATTR2_PALETTE(pal); // | OBJ_TRANSLUCENT;
		sprite++;

//		sprites[sprite].attr0 = OBJ_Y(int(ypos) + 80)  | ATTR0_COLOR_16 | ATTR0_SQUARE;
//		sprites[sprite].attr1 = OBJ_X(int(xpos) + 120) | OBJ_SIZE(Sprite_16x16) | (dir ? ATTR1_FLIP_X : 0);
		sprites[sprite].attr0 = OBJ_Y(int(0) + 80 - 8)  | ATTR0_COLOR_16 | ATTR0_SQUARE;
		sprites[sprite].attr1 = OBJ_X(int(0) + 120 - 8) | OBJ_SIZE(Sprite_16x16) | (dir ? ATTR1_FLIP_X : 0);
		sprites[sprite].attr2 = OBJ_CHAR(tile_start + 32)   | ATTR2_PALETTE(pal); // | OBJ_TRANSLUCENT;
		sprite++;

		float st = sin(last_rot);
		float ct = cos(last_rot);
		
		last_rot = last_rot + (rot - last_rot) * 0.1;
		
		int pa = int(0x100 * ct);
		int pb =-int(0x100 * st);
		int pc = int(0x100 * st);
		int pd = int(0x100 * ct);
		
		// don't setup any hw-regs until vblank
		VBlankIntrWait();
		
		// setup bg0 scroll
		REG_BG0HOFS = int(bg_scroll) & 0xFFFF;
		
		// setup bg2 transform
		REG_BG2PA = pa;
		REG_BG2PB = pb;
		REG_BG2PC = pc;
		REG_BG2PD = pd;
		REG_BG2X = (int(xpos) << 8) - (pa * 120 + pb * 80);
		REG_BG2Y = (int(ypos) << 8) - (pc * 120 + pd * 80);		
		
		++frame;
		CpuSet(sprites,  OAM, (128 * sizeof(OAM[0])) / 2);
		
		scanKeys();
		u32 held = keysHeld();
		u32 down = keysDown();
		u32 up = keysUp();
		
		float upx =  sin(rot);
		float upy = -cos(rot);
		float leftx =  upy;
		float lefty = -upx;
		
		if (KEY_UP    & down) { xdir = upx * 5; ydir = upy * 5; }
		if (KEY_L     & down) { rot += M_PI / 2; }
		if (KEY_R     & down) { rot -= M_PI / 2; }
/*		if (KEY_L     & up) { rot += M_PI / 4; }
		if (KEY_R     & up) { rot -= M_PI / 4; } */
		
		// external forces
#if 0
		xdir *= 0.95; // friction
		ydir *= 0.95; // friction
#else
		float a = leftx * xdir + lefty * ydir; // dot(dir, left)
		float b = upx   * xdir +   upy * ydir; // dot(dir, up)
		float new_xdir = upx * b + 0.85 * leftx * a;
		float new_ydir = upy * b + 0.85 * lefty * a;
		xdir = new_xdir;
		ydir = new_ydir;
#endif	
		if (fabs(xdir) < 1e-1) xdir = 0;
		if (fabs(ydir) < 1e-1) ydir = 0;
		
		if (KEY_RIGHT & held) { xdir -= leftx * 0.5f; ydir -= lefty * 0.5f; dir = 0; }
		if (KEY_LEFT  & held) { xdir += leftx * 0.5f; ydir += lefty * 0.5f; dir = 1; }
		
		xdir -= upx * 0.25;   // gravity
		ydir -= upy * 0.25;   // gravity
		
		float last_xpos = xpos;
		float last_ypos = ypos;
		
		// apply forces
		xpos += xdir;
		ypos += ydir;
		
		// resolve constraints
		if (xpos < 0)   xpos = 0;
		if (xpos > 255) xpos = 255;
		if (ypos < 0)   ypos = 0;
		if (ypos > 255) ypos = 255;
		
		float delta_xpos = last_xpos - xpos;
		float delta_ypos = last_ypos - ypos;
		
		bg_scroll += (delta_xpos * leftx + delta_ypos * lefty) * 0.5f;
	}
	return 0;
}
コード例 #12
0
ファイル: font.c プロジェクト: ArtemioUrbina/240pTestSuite
void AddTextColor(u8 palette, u16 front, u16 back)
{
	setPaletteColor(palette * 0x10, RGB5(31, 0, 31));
	setPaletteColor(palette * 0x10 + 1, front);
	setPaletteColor(palette * 0x10 + 2, back);
}