Ejemplo n.º 1
0
Archivo: main.c Proyecto: Alanh168/test
int main()
{
	// Init interrupts and VBlank irq.
	irq_init(NULL);
	irq_add(II_VBLANK, NULL);
	
	// Video mode 0, enable bg 0.
	REG_DISPCNT= DCNT_MODE0 | DCNT_BG0;
	
	// Init 4bpp vwf text on bg 0.
	tte_init_chr4c(0, 			// BG 0
		BG_CBB(0)|BG_SBB(31),	// Charblock 0; screenblock 31
		0xF000,					// Screen-entry offset
		bytes2word(1,2,0,0),	// Color attributes.
		CLR_YELLOW, 			// Yellow text
		&verdana9Font,			// Verdana 9 font
		NULL					// Use default chr4 renderer
		);
	
	// Initialize use of stdio.
	tte_init_con();
	
	// Printf something at 96,72
	tte_printf("#{P:96,72}Hello World!");
	
	while(1)
	{
		VBlankIntrWait();
	}
	
	return 0;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static void init()
{
	VBlankIntrWait();
	CpuFastSet(poelse_pal, BG_COLORS, (512 / 4));
	fb::setMode(MODE_4 | BG2_ON | OBJ_ON);
	
	noise::setup();
	REG_BLDCNT = BIT(10) | BIT(6) | BIT(4) | BIT(13);
	REG_BLDALPHA = (3) | (16<<8);
}
Ejemplo n.º 4
0
void prof_draws(TProfiler *prof, const char *str)
{
	tte_set_pos(0, 0);
	tte_write(prof->str);
	tte_write(": \n");
	VBlankIntrWait();

	profile_start();
	tte_write(str);

	prof->time=  profile_stop();
}
Ejemplo n.º 5
0
void videoInitMode0() {
	VBlankIntrWait();
	
	// Create palette
	BG_COLORS[0] = RGB8(0xFF, 0xFF, 0xFF);
	BG_COLORS[1] = RGB8(0x00, 0x00, 0x00);
	BG_COLORS[2] = RGB8(0xFF, 0x00, 0x00);
	BG_COLORS[3] = RGB8(0x00, 0xFF, 0x00);
	BG_COLORS[4] = RGB8(0x00, 0x00, 0xFF);
	BG_COLORS[5] = RGB8(0xFF, 0x00, 0xFF);
	BG_COLORS[6] = RGB8(0xFF, 0xFF, 0x00);
	// Create tiles
	for(int i = 0; i< 64; i+=4) {
		*((s32 *)(TILE_BASE_ADR(0)+64*0+i)) = 0x00000000;
		*((s32 *)(TILE_BASE_ADR(0)+64*1+i)) = 0x01010101;
		*((s32 *)(TILE_BASE_ADR(0)+64*2+i)) = 0x02020202;
		*((s32 *)(TILE_BASE_ADR(0)+64*3+i)) = 0x03030303;
		*((s32 *)(TILE_BASE_ADR(0)+64*4+i)) = 0x04040404;
		*((s32 *)(TILE_BASE_ADR(0)+64*5+i)) = 0x05050505;
		*((s32 *)(TILE_BASE_ADR(0)+64*6+i)) = 0x06060606;
	}
	// create maps
	for(int y = 0; y < 32; y++) {
		for(int x = 0; x < 32; x++) {		
			// Checkerboard
			if(((x ^ y) & 1) != 0) {
				MAP[8][y][x] = 0x0002;
			} else {
				MAP[8][y][x] = 0x0001;
			}
			// 32x32 block
			if(x < 4 && y < 4) {
				MAP[12][y][x] = 0x0004;
			} else {
				MAP[12][y][x] = 0x0000;
			}
		}
	}
	
	REG_BG3CNT = BG_256_COLOR | BG_SIZE_0 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_PRIORITY(2);
	REG_BG2CNT = BG_256_COLOR | BG_SIZE_0 | BG_TILE_BASE(0) | BG_MAP_BASE(12) | BG_PRIORITY(1);
	
	REG_BG3HOFS = 0;
	REG_BG3VOFS = 0;
	REG_BG2HOFS = 0;
	REG_BG2VOFS = 0;
	
	REG_DISPCNT = MODE_0 | BG2_ON | BG3_ON;
	
}
Ejemplo n.º 6
0
int main(void)
{
	irqInit();
	irqEnable(IRQ_VBLANK);

	consoleDemoInit();

	iprintf("\x1b[10;10HHello World!\n");

	while (1)
	{
		VBlankIntrWait();
	}
}
Ejemplo n.º 7
0
/***************************************************
 エントリ
 ***************************************************/
int
main (void)
{
  // ゲームパックウェイト&キャッシュ
  *((vu16 *) 0x04000204) = 0x4317;

  // BG初期化
  init_bg ();
  // スプライト初期化
  init_sprite ();
  // キー初期化
  init_key ();
  // サウンド初期化
  DirectSoundInitialize ();

  // キャラクタ初期化
  init_sprite_chr ();

  // ハイスコア初期化
  init_hiscore ();

  // ゲーム初期化
  init_game ();

  // タイトル
  init_title ();

  // 割り込み初期化
  irqInit ();
  // サウンド用ハンドラ MUSIC / SE
  irqSet (IRQ_TIMER0, IRQ_Music);
  irqSet (IRQ_TIMER1, IRQ_Sound);
  irqEnable (IRQ_VBLANK | IRQ_TIMER0 | IRQ_TIMER1);

  // タイトル
  PlayMusic (MUSIC_TITLE, PLAY_LOOP_ON);

  // メインループ
  while (1)
  {
    // キー入力
    scanKeys ();

    // ゲーム本体
    game ();

    // 割り込み待ち
    VBlankIntrWait ();
  }
}
Ejemplo n.º 8
0
int main(void) {
	irqInit();
	irqEnable(IRQ_VBLANK);
	code_init();

	AgbMain();

	// SoundDriverInit();
	// SoundDriverMode();

	while (1) {
		VBlankIntrWait();
		// SoundDriverVsync();
	}
}
Ejemplo n.º 9
0
int main(void)
{
    libgba_init();

    int selection = 0;
    bool needs_init = true;

    // this is how the demo selection will be laid out on screen
    const demo demos[NUM_DEMOS] =
    {
            demo1_main, demo2_main,
            demo3_main, demo4_main,
            demo5_main, demo6_main,
            demo7_main, demo8_main
    };

    for (;;)    // main loop; loop forever
    {
        if (needs_init)
        {
            main_init();
            needs_init = false;
        }

        u16 key_state = get_curr_keys();
        int tribool_horz = tribool_dpad_horz(key_state);
        int tribool_vert = tribool_dpad_vert(key_state);

        int horz = (selection + tribool_horz) & 1;
        int vert = (((selection >> 1) + tribool_vert) << 1) & (NUM_DEMOS - 1);

        selection = horz + vert;

        if (key_state & KEY_A)
        {
            demos[selection]();
            needs_init = true;
        }

        VBlankIntrWait();
    }

    // never actually get here; behavior after main returns is undefined on GBA
    return 0;
}
Ejemplo n.º 10
0
int main()
{
	// Init interrupts and VBlank irq.

	irq_init(NULL);
	irq_add(II_VBLANK, mmVBlank);
	mmInitDefault( (mm_addr)soundbank_bin, 8 );
	
	CreditDevkitArmandtonc();

MainMenu();
	
	while(1)
	{
		VBlankIntrWait();
	}
	
	return 0;
}
Ejemplo n.º 11
0
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	RegisterRamReset(RESET_PALETTE | RESET_VRAM | RESET_OAM);

	// the vblank interrupt must be enabled for VBlankIntrWait() to work
	// since the default dispatcher handles the bios flags no vblank handler
	// is required
	irqInit();
	irqEnable(IRQ_VBLANK);
	irqEnable(IRQ_HBLANK);
	irqSet(IRQ_HBLANK, hblankHandler);
	

	videoInitMode0();
	

	while (1) {
		VBlankIntrWait();
	}
}
Ejemplo n.º 12
0
//---------------------------------------------------------------------------------
// 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
	irqInit();
	irqEnable(IRQ_VBLANK);

	// set mode 0, 1D mapping
	REG_DISPCNT = MODE_0 | OBJ_1D_MAP;

    init_oam(obj_buffer, 128);

	// copy sprites to appropriate memory spots
	u16 *palette_end = SPRITE_PALETTE;
	u16 *tiles_end =SPRITE_GFX;
	// blue slime
	memcpy(palette_end, blueslimePal, blueslimePalLen);
	memcpy(tiles_end, blueslimeTiles, blueslimeTilesLen);
	palette_end += blueslimePalLen/2;
	tiles_end += blueslimeTilesLen/2;
	// drakee
	memcpy(palette_end, drakeePal, drakeePalLen);
	memcpy(tiles_end, drakeeTiles, drakeeTilesLen);
	palette_end += drakeePalLen/2;
	tiles_end += drakeeTilesLen/2;
	// orange slime
	memcpy(palette_end, orangeslimePal, orangeslimePalLen);
	memcpy(tiles_end, orangeslimeTiles, orangeslimeTilesLen);
	palette_end += orangeslimePalLen/2;
	tiles_end += orangeslimeTilesLen/2;

	// enable sprites
	REG_DISPCNT |= OBJ_ON | OBJ_WIN_ENABLE;

	u16 x = 0;
	u16 y = 0;
	s8 sprite = 1;
	u16 status = ATTR0_NORMAL;


	obj_buffer[0].attr0 = (y & 0x00ff) | ATTR0_NORMAL | ATTR0_COLOR_16 | ATTR0_SQUARE;
	obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32;
    obj_buffer[0].attr2 = OBJ_CHAR(0);
	
	oam_copy(OAM, obj_buffer, 1);

	setRepeat(1,1);

	while (1)
	{
		// check keypad
		scanKeys();
		u16 keystate = keysDownRepeat();
		u16 keydown = keysDown();
		// directional pad
		// move sprite
		if (keystate & KEY_LEFT)
			x -= 1;
		else if (keystate & KEY_RIGHT)
			x += 1;
		if (keystate & KEY_UP)
			y -= 1;
		else if (keystate & KEY_DOWN)
			y += 1;
		// A
		// enable/disable sprite
		if (keydown & KEY_A)
		{
			if (status == ATTR0_NORMAL)
				status = ATTR0_DISABLED;
			else
				status = ATTR0_NORMAL;
		}
		// L + R
		// rotate sprites
        if (keydown & KEY_R)
		{
			sprite++;
			if (sprite > 2) sprite = 0;
		}
        else if (keydown & KEY_L)
		{
            sprite--;
			if (sprite < 0) sprite = 2;
		}
			
		// set current sprite attributes
        obj_buffer[0].attr0 = (y & 0x00ff) | status | ATTR0_COLOR_16 | ATTR0_SQUARE;
        obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32;
        obj_buffer[0].attr2 = OBJ_CHAR(sprite*16) | OBJ_PALETTE(sprite);

        oam_copy(OAM, obj_buffer, 1);

		VBlankIntrWait();
	}

	return 0;
}
Ejemplo n.º 13
0
int playPuzzle(int NUR_ROWS, int NUR_COLS, int puzzle[NUR_ROWS][NUR_COLS], int puzzle_index) {

  int cursor_r = 0;
  int cursor_c = 0;

  // Load palette
  memcpy16(pal_bg_mem, SharedPal, SharedPalLen / 2);

  // Load tiles into CBB 0 (16x16) and 1 (8x8)
  // Each charblock is 0x4000, an 8x8 tile is 0x20 bytes,
  // so there are 512 8x8 tiles or 128 16x16 tiles in each charblock.
  memcpy16(tile_mem[0], tiles16Tiles, tiles16TilesLen / 2);
  memcpy16(tile_mem[1], tiles8Tiles, tiles8TilesLen / 2);

  // Load the 16x16 puzzle map into screenblocks 28-31
  for (int r = 0; r < 32; r++) {
    for (int c = 0; c < 32; c++) {
      set_tile(28, r, c, OUTSIDE);
    }
  }
  for (int c = 0; c < NUR_COLS; c++) set_tile(28, NUR_ROWS, c, BOTTOM_EDGE);
  for (int r = 0; r < NUR_ROWS; r++) set_tile(28, r, NUR_COLS, RIGHT_EDGE);
  set_tile(28, NUR_ROWS, NUR_COLS, BOTTOM_RIGHT_CORNER);
  for (int r = 0; r < NUR_ROWS; r++) {
    for (int c = 0; c < NUR_COLS; c++) {
      set_tile(28, r, c, puzzle[r][c]);
    }
  }

  // Load the 16x16 cursor map into screenblocks 24-27
  for (int r = 0; r < 32; r++) {
    for (int c = 0; c < 32; c++) {
      set_tile(24, r, c, TRANSPARENT);
    }
  }
  set_tile(24, cursor_r, cursor_c, CURSOR);

  // 8x8 tiles:
  // set up BG2 for a 4bpp 32x32t map, using charblock 1 and screenblock 22 (cursor)
  REG_BG2CNT = BG_CBB(1) | BG_SBB(22) | BG_4BPP | BG_REG_32x32;
  // set up BG3 for a 4bpp 32x32t map, using charblock 1 and screenblock 23 (puzzle squares)
  REG_BG3CNT = BG_CBB(1) | BG_SBB(23) | BG_4BPP | BG_REG_32x32;
  // 16x16 tiles:
  // set up BG0 for a 4bpp 64x64t map, using charblock 0 and screenblocks 24-27 (cursor)
  REG_BG0CNT = BG_CBB(0) | BG_SBB(24) | BG_4BPP | BG_REG_64x64;
  // set up BG1 for a 4bpp 64x64t map, using charblock 0 and screenblocks 28-31 (puzzle squares)
  REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x64;
  if (small_tiles) {
    REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3;
  }
  else {
    REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1;
  }

  int max_horiz_offset_16 = NUR_COLS * 16 - 240;
  if (max_horiz_offset_16 < 0) max_horiz_offset_16 = 0;
  int max_vert_offset_16  = NUR_ROWS * 16 - 160;
  if (max_vert_offset_16 < 0) max_vert_offset_16 = 0;

  int max_horiz_offset_8 = NUR_COLS * 8 - 240;
  if (max_horiz_offset_8 < 0) max_horiz_offset_8 = 0;
  int max_vert_offset_8  = NUR_ROWS * 8 - 160;
  if (max_vert_offset_8 < 0) max_vert_offset_8 = 0;

  REG_BG0HOFS = REG_BG1HOFS = REG_BG2HOFS = REG_BG3HOFS = 0;
  REG_BG0VOFS = REG_BG1VOFS = REG_BG2VOFS = REG_BG3VOFS = 0;

  irq_init(NULL);
  irq_add(II_VBLANK, NULL);

  int key_repeat = 0;
  bool clearing = false;
  while (1) {
    VBlankIntrWait();
    key_poll();
    set_tile(24, cursor_r, cursor_c, TRANSPARENT); // remove the cursor
    if (key_hit(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) {
      key_repeat = 0; // reset the key repeat timer
    }
#define START_REPEAT 20
#define REPEAT_SPEED 2
    if (key_is_down(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) {
      if (key_repeat < START_REPEAT) key_repeat++;
      else key_repeat = START_REPEAT - REPEAT_SPEED;
    }
    bool virtual_left  = key_hit(1 << KI_LEFT ) || (key_is_down(1 << KI_LEFT ) && key_repeat == START_REPEAT);
    bool virtual_right = key_hit(1 << KI_RIGHT) || (key_is_down(1 << KI_RIGHT) && key_repeat == START_REPEAT);
    bool virtual_up    = key_hit(1 << KI_UP   ) || (key_is_down(1 << KI_UP   ) && key_repeat == START_REPEAT);
    bool virtual_down  = key_hit(1 << KI_DOWN ) || (key_is_down(1 << KI_DOWN ) && key_repeat == START_REPEAT);
    bool moved_cursor = false;
    if (virtual_left  && cursor_c > 0           ) {
      cursor_c--;
      REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1);
      REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1);
      moved_cursor = true;
    }
    if (virtual_right && cursor_c < NUR_COLS - 1) {
      cursor_c++;
      REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1);
      REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1);
      moved_cursor = true;
    }
    if (virtual_up    && cursor_r > 0           ) {
      cursor_r--;
      REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1);
      REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1);
      moved_cursor = true;
    }
    if (virtual_down  && cursor_r < NUR_ROWS - 1) {
      cursor_r++;
      REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1);
      REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1);
      moved_cursor = true;
    }

    if (key_hit(1 << KI_A)) {
      switch (puzzle[cursor_r][cursor_c]) {
        case WHITE:
        case BLACK:
          puzzle[cursor_r][cursor_c] = DOT;
          sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT;
          set_tile(28, cursor_r, cursor_c, DOT);
          clearing = false;
          break;
        case DOT:
          puzzle[cursor_r][cursor_c] = WHITE;
          sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE;
          set_tile(28, cursor_r, cursor_c, WHITE);
          clearing = true;
          break;
        default:
          clearing = false;
          break;
      }
    }
    else if (key_is_down(1 << KI_A) && moved_cursor) {
      switch (puzzle[cursor_r][cursor_c]) {
        case WHITE:
        case BLACK:
        case DOT:
          if (clearing) {
            puzzle[cursor_r][cursor_c] = WHITE;
            sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE;
            set_tile(28, cursor_r, cursor_c, WHITE);
          }
          else {
            puzzle[cursor_r][cursor_c] = DOT;
            sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT;
            set_tile(28, cursor_r, cursor_c, DOT);
          }
          break;
      }
    }

    if (key_hit(1 << KI_B)) {
      switch (puzzle[cursor_r][cursor_c]) {
        case WHITE:
        case DOT:
          puzzle[cursor_r][cursor_c] = BLACK;
          sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK;
          set_tile(28, cursor_r, cursor_c, BLACK);
          clearing = false;
          break;
        case BLACK:
          puzzle[cursor_r][cursor_c] = WHITE;
          sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE;
          set_tile(28, cursor_r, cursor_c, WHITE);
          clearing = true;
          break;
        default:
          clearing = false;
          break;
      }
    }
    else if (key_is_down(1 << KI_B) && moved_cursor) {
      switch (puzzle[cursor_r][cursor_c]) {
        case WHITE:
        case BLACK:
        case DOT:
          if (clearing) {
            puzzle[cursor_r][cursor_c] = WHITE;
            sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE;
            set_tile(28, cursor_r, cursor_c, WHITE);
          }
          else {
            puzzle[cursor_r][cursor_c] = BLACK;
            sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK;
            set_tile(28, cursor_r, cursor_c, BLACK);
          }
          break;
      }
    }

    if (key_hit(1 << KI_SELECT)) {
      small_tiles = !small_tiles;
      if (small_tiles) {
        REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3;
      }
      else {
        REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1;
      }
    }

    if (key_hit(1 << KI_L)) {
      return -1; // move 1 puzzle to the left
    }

    if (key_hit(1 << KI_R)) {
      return 1; // move 1 puzzle to the right
    }

    set_tile(24, cursor_r, cursor_c, CURSOR); // readd the cursor
  }
}
Ejemplo n.º 14
0
int main()
{
	// initialize IRQ (interrupts)
	// this must come before everything else
	IRQ_INIT();

	// Initialize global pointers
	GameStateManager gameStateMan;
	OamManager oamMan;
	AudioManager audioMan;
	PlayState playState(&gameStateMan);
	TitleScreenState titleState(&gameStateMan);
	PauseState pauseState(&gameStateMan);
	GameOverState gameOverState(&gameStateMan);
	StoreState storeState(&gameStateMan);
	StageEndState stageEndState(&gameStateMan);
	
	g_gameStateMan = &gameStateMan;
	g_oamMan = &oamMan;
	g_playState = &playState;
	g_titleState = &titleState;
	g_pauseState = &pauseState;
	g_gameOverState = &gameOverState;
	g_storeState = &storeState;
	g_stageEndState = &stageEndState;
	g_audioMan = &audioMan;

	// create stage events
	StageEvent endEvent;
	StageEvent event1;
	StageEvent event2;
	StageEvent event3;
	StageEvent event4;
	StageEvent event5;
	StageEvent event6;
	StageEvent firePowerPowerUpEvent;
	StageEvent invinciblePowerUpEvent;
	StageEvent bombPowerUpEvent;
	g_endEvent = &endEvent;
	g_event1 = &event1;
	g_event2 = &event2;
	g_event3 = &event3;
	g_event4 = &event4;
	g_event5 = &event5;
	g_event6 = &event6;
	g_firePowerPowerUpEvent = &firePowerPowerUpEvent;
	g_invinciblePowerUpEvent = &invinciblePowerUpEvent;
	g_bombPowerUpEvent = &bombPowerUpEvent;

	initializeEvents();

	StageEvent * stage1Events[24];
	int stage1Timing[24];
	int stage1yOffset[24];
	fillEventsStage1(stage1Events, stage1Timing, stage1yOffset);
	Stage stage1(&playState, stage1Events, stage1Timing, stage1yOffset, 24);
	g_stage1 = &stage1;

	StageEvent * stage2Events[20];
	int stage2Timing[20];
	int stage2yOffset[20];
	fillEventsStage2(stage2Events, stage2Timing, stage2yOffset);
	Stage stage2(&playState, stage2Events, stage2Timing, stage2yOffset, 20);
	g_stage2 = &stage2;
	
	StageEvent * stage3Events[20];
	int stage3Timing[20];
	int stage3yOffset[20];
	fillEventsStage3(stage3Events, stage3Timing, stage3yOffset);
	Stage stage3(&playState, stage3Events, stage3Timing, stage3yOffset, 20);
	g_stage3 = &stage3;

	videoInit();

	g_gameStateMan->pushState(g_titleState);

#ifdef DEBUG
	// timers used for debug display
	REG_TM1D = 0x10000 - 2808; // overflow into timer 2 every 2808 cycles, approx. 1% of a screen refresh
	REG_TM2D = 0;
	REG_TM2CNT = TM_CASCADE | TM_ENABLE;
	REG_TM1CNT = TM_FREQ_1 | TM_ENABLE;
	int oldPercent, diffPercent, oldFrac, diffFrac;
	char buf[15];
#endif // DEBUG

	while(true)
	{
		// wait until next VBlank
		// prefer this over vid_vsync() - it's
		// better for power consumption
		VBlankIntrWait();

#ifdef DEBUG
		// grab current percentage
		oldPercent = REG_TM2D;
		oldFrac = REG_TM1D;
#endif // DEBUG

		// update shadow OAM to real OAM
		g_oamMan->update();

		// mix the next frame's audio
		g_audioMan->sndMix();
		
		// poll keys - do not do this in other places
		key_poll();

		// update the game state
		g_gameStateMan->update();

#ifdef DEBUG
		// grab current percentage, and write it out
		diffPercent = REG_TM2D - oldPercent;
		diffFrac = REG_TM1D - oldFrac;

		// round the percent based on the fractional amount
		if (diffFrac > 1404)
		{
			diffPercent++;
		}
		else if (diffFrac < -1404)
		{
			diffPercent--;
		}

		gba_itoa(diffPercent, buf);

		// clear out characters from the last write
		write("  ", Vec2(0, 0));
		write(buf, Vec2(0, 0));

		// reset timer 2 to 0
		REG_TM2CNT = 0; // disable timer
		REG_TM2D = 0; // set new value to 0
		REG_TM2CNT = TM_CASCADE | TM_ENABLE; // reenable timer
#endif // DEBUG
	}
}
Ejemplo n.º 15
0
//---------------------------------------------------------------------------------
// 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();
		}
		
		
	}
}
Ejemplo n.º 16
0
Archivo: main.cpp Proyecto: 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;
}
Ejemplo n.º 17
0
int main() {
	// Set up the interrupt handlers
	irqInit();
	// Enable Vblank Interrupt to allow VblankIntrWait
	irqEnable(IRQ_VBLANK);

	// Allow Interrupts
	REG_IME = 1;

	u32 i, scrollx, scrolldelay, textindex;
	u16 *temppointer;


	// load the palette for the background, 7 colors
	temppointer = BG_COLORS;
	for(i=0; i<7; i++) {
		*temppointer++ = palette[i];
	}

	// load the font into gba video mem (48 characters, 4bit tiles)

	CpuFastSet(r6502_portfont_bin, (u16*)VRAM,(r6502_portfont_bin_size/4) | COPY32);

	// clear screen map with tile 0 ('space' tile) (256x256 halfwords)

	*((u32 *)MAP_BASE_ADR(31)) =0;
	CpuFastSet( MAP_BASE_ADR(31), MAP_BASE_ADR(31), FILL | COPY32 | (0x800/4));

	// set screen H and V scroll positions
	BG_OFFSET[0].x = 0; BG_OFFSET[0].y = 0;

	// initialize our variables
	scrollx = 0;
	textindex = 0;
	scrolldelay = 0;

	// put the '@' symbol on the top of the screen to show how
	// the screen is only scrolling 7 pixels - to reveal the
	// illusion of how the scroller works
	*((u16 *)MAPADDRESS + 1) = 0x20;	// 0x20 == '@'

	// draw a row of text from beginning of message
	updatescrolltext(0);

	// set the screen base to 31 (0x600F800) and char base to 0 (0x6000000)
	BGCTRL[0] = SCREEN_BASE(31);

	// screen mode & background to display
	SetMode( MODE_0 | BG0_ON );

	while(1) {
		VBlankIntrWait();

		// check if we reached our delay
		if(scrolldelay == DELAY) {
			// yes, the delay is complete, so let's reset it
			scrolldelay = 0;

			// check if we reached our scrollcount
			if(scrollx == (TILEWIDTH-1)) {
				// yes, we've scrolled enough, so let's reset the count
				scrollx = 0;

				// check if we reached the end of our scrolltext
				// and if so we need to restart our index
				if(message[textindex] == 0) textindex = 0;
				else textindex++;

				// finally, let's update the scrolltext with the current text index
				updatescrolltext(textindex);
			}
			else scrollx++;
		}
		else scrolldelay++;

		// update the hardware horizontal scroll register
		BG_OFFSET[0].x = scrollx;
	}

}
Ejemplo n.º 18
0
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();
    }
}