Example #1
0
void ndsloadstub()
{
	void (*func_ptr)(void) = (void*)ARM9STUBVMA;
	#ifndef BOOTHB
	swiDecompressLZSSWram((void*)ndsloader_lz, (void*)BOOTLDR_NDS);
	*((u32*)(BOOTLDR_NDS-8)) = *((u32*)ndsloader_lz) >> 8;
	#endif
	DC_FlushAll();
	DC_InvalidateAll();
	IC_InvalidateAll();

	BOOTFLAG = 0;
	VRAM_C_CR = VRAM_ENABLE | VRAM_C_LCD;
	#ifndef BOOTHB
	NDSHEADER->arm7executeAddress = 0x06000000;
	#endif
	memcpy16((void*)ARM9STUBVMA, arm9stub_bin, arm9stub_bin_size);
	memcpy16(VRAM_C, arm7stub_bin, arm7stub_bin_size);
	VRAM_C_CR = VRAM_ENABLE | VRAM_C_ARM7_0x06000000;

	DC_FlushAll();
	DC_InvalidateAll();
	IC_InvalidateAll();
	#ifdef BOOTHB
	resetARM7(0x06000000);
	#endif
	func_ptr();
}
Example #2
0
void PlayState::refreshed()
{
	memcpy16(&se_mem[24], g_demo_starsMap, SBB_SIZE/2);
	
	REG_BG0VOFS = starsBG_Pos.x;
	REG_BG0HOFS = starsBG_Pos.y;

	// Get sprites from the OAM Manager
	//	- 1 for player
	//	- 10 for enemies
	//	- 32 for bullets
	//  - 32 for enemy bullets
	//	- 1 for R_triggered indicator
	//  - 9 for "lives"
	//  - 1 for power up
	sprites = g_oamMan->allocSprites(NUM_SPRITES);

	// Init display sprites at bottom
	lifeIndic.useImg(LIFE_DISP_SPRITE_POS);
	lifeIndic.setSize(LIFE_DISP_SPRITE_SIZE);
	lifeIndic.setTileIndex(g_extraLife_TilesPos);
	lifeIndic.setPalette(4);
	lifeIndic.setPos(0, 152);
	lifeIndic.setVisible(true);
	
	bombIndic.useImg(BOMB_DISP_SPRITE_POS);
	bombIndic.setSize(BOMB_DISP_SPRITE_SIZE);
	bombIndic.setTileIndex(g_extraBomb_TilesPos);
	bombIndic.setPalette(4);
	bombIndic.setPos(128, 152);
	bombIndic.setVisible(true);

	// Init player
	player.useImg(PLAYER_SPRITE_POS);
	player.setPalette(PLAYER_BASE_PALETTE);
	player.setTileIndex(g_playerSpriteTilesPos);
	player.setVisible(true);
	player.setParent(this);

	// Give the objects in allocators sprites
	playerBullets.spriteInit(PLAYER_BULLETS_SPRITE_POS);
	enemyBullets.spriteInit(ENEMY_BULLETS_SPRITE_POS);
	enemies.spriteInit(ENEMY_SPRITE_POS);

	// Init the R_triggered indicator
	R_triggered_indicator.useImg(R_TRIG_INDIC_SPRITE_POS);
	R_triggered_indicator.setPalette(R_TRIG_INDIC_BASE_PALETTE);
	R_triggered_indicator.setTileIndex(g_bullet_selection1TilesPos);
	R_triggered_indicator.setSize(R_TRIG_INDIC_SPRITE_SIZE);
	R_triggered_indicator.setVisible(true);

	// Power ups
	powerUp.useImg(POWER_UP_SPRITE_POS);
	powerUp.setSize(POWER_UP_SPRITE_SIZE);
	powerUp.setTileIndex(g_shield_TilesPos);

}
/*******************************************************************************
 * Setup secondary CPU vectors
 ******************************************************************************/
void plat_secondary_setup(void)
{
	uint32_t addr_low, addr_high;
	plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
	uint64_t cpu_reset_handler_base;

	INFO("Setting up secondary CPU boot\n");

	if ((tegra_bl31_phys_base >= TEGRA_TZRAM_BASE) &&
	    (tegra_bl31_phys_base <= (TEGRA_TZRAM_BASE + TEGRA_TZRAM_SIZE))) {

		/*
		 * The BL31 code resides in the TZSRAM which loses state
		 * when we enter System Suspend. Copy the wakeup trampoline
		 * code to TZDRAM to help us exit from System Suspend.
		 */
		cpu_reset_handler_base = params_from_bl2->tzdram_base;
		memcpy16((void *)((uintptr_t)cpu_reset_handler_base),
			 (void *)(uintptr_t)tegra186_cpu_reset_handler,
			 (uintptr_t)&__tegra186_cpu_reset_handler_end -
			 (uintptr_t)tegra186_cpu_reset_handler);

	} else {
		cpu_reset_handler_base = (uintptr_t)tegra_secure_entrypoint;
	}

	addr_low = (uint32_t)cpu_reset_handler_base | CPU_RESET_MODE_AA64;
	addr_high = (uint32_t)((cpu_reset_handler_base >> 32) & 0x7ff);

	/* write lower 32 bits first, then the upper 11 bits */
	mmio_write_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_LOW, addr_low);
	mmio_write_32(TEGRA_MISC_BASE + MISCREG_AA64_RST_HIGH, addr_high);

	/* save reset vector to be used during SYSTEM_SUSPEND exit */
	mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_SECURE_RSV1_SCRATCH_0,
			addr_low);
	mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_SECURE_RSV1_SCRATCH_1,
			addr_high);

	/* update reset vector address to the CCPLEX */
	mce_update_reset_vector();
}
Example #4
0
/*
 * Read the contents of a file into a given memory location.  Since
 * this can be used for populating VRAM (in fact, right now, that's
 * all it's for), we do 16-bit copies from a work buffer, rather
 * than reading into memory directly.
 */
int nds_load_file(char *fname, void *dest)
{
  u8 *d = (u8 *)dest; /* Makes our pointer arithmetic cleaner... */

  FILE *file = fopen(fname, "r");
  u8 buf[1024];
  int pos, read;

  if (file == NULL) {
    return -1;
  }

  pos = 0;

  while ((read = fread(buf, 1, sizeof(buf), file)) > 0) {
    memcpy16(d + pos, buf, read);
    pos += read;
  }

  fclose(file);

  return 0;
}
int tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
{
	const plat_local_state_t *pwr_domain_state =
		target_state->pwr_domain_state;
	plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
	unsigned int stateid_afflvl2 = pwr_domain_state[PLAT_MAX_PWR_LVL] &
		TEGRA186_STATE_ID_MASK;
	uint64_t val;

	if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
		/*
		 * The TZRAM loses power when we enter system suspend. To
		 * allow graceful exit from system suspend, we need to copy
		 * BL3-1 over to TZDRAM.
		 */
		val = params_from_bl2->tzdram_base +
			((uintptr_t)&__tegra186_cpu_reset_handler_end -
			 (uintptr_t)tegra186_cpu_reset_handler);
		memcpy16((void *)(uintptr_t)val, (void *)(uintptr_t)BL31_BASE,
			 (uintptr_t)&__BL31_END__ - (uintptr_t)BL31_BASE);
	}

	return PSCI_E_SUCCESS;
}
Example #6
0
_bitmap _imageFile::readBitmap( _optValue<_u32> page )
{
    // Check if not-existing
    if( !this->isExisting() )
        return _bitmap();

    _mimeType mimeType = this->getRealMime();

    if( mimeType == _mime::image_png )
    {
        if( this->bufferedImage )
            return *bufferedImage;

        _bitmap result;

        YsRawPngDecoder* pngDecoder = new YsRawPngDecoder;

        pngDecoder->Decode( this->filename.c_str() );

        if( pngDecoder->wid > 0 && pngDecoder->hei > 0 && pngDecoder->rgba != NULL )
        {
            // Allocate bitmap
            result = _bitmap( pngDecoder->wid , pngDecoder->hei );

            // Get size of Data (in bytes)(every pixel consists of u8 red, u8 green, u8 blue, u8 alpha)
            _u32		size = pngDecoder->wid * pngDecoder->hei;
            _pixelArray	base = result.getBitmap();
            _u8*		source = pngDecoder->rgba;

            do {
                _u8 r = *source++;
                _u8 g = *source++;
                _u8 b = *source++;
                bool a = *source++ > 127;
                *base++ = _color::fromRGB8(r,g,b,a);
            } while( --size > 0 );
        }

        // Delete the decoder
        delete pngDecoder;

        if( this->buffer ) {
            this->bufferedImage = new _bitmap( move(result) );
            return *this->bufferedImage;
        }
        return move(result);
    }
    else if( mimeType == _mime::image_jpeg )
    {
        if( this->bufferedImage )
            return *bufferedImage;

        _bitmap result;

        _u32 size = this->getSize();
        _byte* data = new _byte[size];
        this->read( data , size );

        Jpeg::Decoder* jpgDecoder = new Jpeg::Decoder( data , size );

        if ( jpgDecoder->GetResult() == Jpeg::Decoder::OK )
        {
            result = _bitmap( jpgDecoder->GetWidth() , jpgDecoder->GetHeight() );

            if( jpgDecoder->IsColor() )
            {
                _u32 size = jpgDecoder->GetImageSize();
                _u8* rgb = jpgDecoder->GetImage();
                _pixelArray dest = result.getBitmap();

                do {
                    _u8 r = *rgb++;
                    _u8 g = *rgb++;
                    _u8 b = *rgb++;
                    *dest++ = _color::fromRGB8(r,g,b);
                    size -= 3;
                } while( size > 0 );
            }
            else
            {
                _u32 size = jpgDecoder->GetImageSize();
                _u8* rgb = jpgDecoder->GetImage();
                _pixelArray dest = result.getBitmap();

                do {
                    *dest++ = _color::fromBW8( *rgb++ );
                } while( --size > 0 );
            }
        }
        delete[] data;
        delete jpgDecoder;

        if( this->buffer ) {
            this->bufferedImage = new _bitmap( move(result) );
            return *this->bufferedImage;
        }
        return move(result);
    }
    else if( mimeType == _mime::image_bmp )
    {
        if( this->bufferedImage )
            return *bufferedImage;

        _bitmap result;

        _u32 size = this->getSize();
        _byte* data = new _byte[size];
        this->read( data , size );

        _u32 width;
        _u32 height;

        _pixelArray pixeldata = GenericBMPDecoder::decode( data , size , width , height );

        if ( pixeldata != nullptr ) {
            result = _bitmap( width , height );
            memcpy16( result.getBitmap() , pixeldata , width * height );
            delete[] pixeldata;
        }

        delete[] data;

        if( this->buffer ) {
            this->bufferedImage = new _bitmap( move(result) );
            return *this->bufferedImage;
        }
        return move(result);
    }
    else if( mimeType == _mime::image_ico )
    {
        _byte* data;
        if( this->bufferedData )
            data = this->bufferedData;
        else
        {
            _u32 size = this->getSize();
            data = new _byte[size];
            this->read( data , size );
        }

        _u32 width;
        _u32 height;

        _bitmap result;

        _u8* pixeldata = GenericIcoDecoder::decode( data , width , height , page );

        if ( pixeldata != nullptr )
        {
            // Allocate bitmap
            result = _bitmap( width , height );

            // Get size of Data (in bytes)(every pixel consists of u8 red, u8 green, u8 blue, u8 alpha)
            _u32		size = width * height;
            _pixelArray	base = result.getBitmap();
            _u8*		source = pixeldata;

            do {
                _u8 r = *source++;
                _u8 g = *source++;
                _u8 b = *source++;
                bool a = *source++ > 127;
                *base++ = _color::fromRGB8(r,g,b,a);
            } while( --size > 0 );

            delete[] pixeldata;
        }

        if( !this->buffer )
            delete[] data;
        else
            this->bufferedData = data;
        return result;
    }
    else if( mimeType == _mime::image_gif )
    {
        gif_animation* gifAnim;
        gif_result statusCode = GIF_OK;

        // Allocate Decoder
        if( this->bufferedGif )
            gifAnim = this->bufferedGif;
        else
        {
            // Read file content to buffer
            _u32 size = this->getSize();
            _byte* data = new _byte[size];
            this->read( data , size );

            // Allocate Decoder
            gifAnim = new gif_animation;

            // Initialize Decoder
            gif_create( gifAnim );

            // Partly Decode the gif
            do {
                statusCode = gif_initialise( gifAnim , size , data );
                if (statusCode != GIF_OK && statusCode != GIF_WORKING) {
                    _imageFile::outputGifWarning( "gif_initialise" , statusCode);
                    break;
                }
            } while( statusCode != GIF_OK );
        }

        if( !this->bufferedGifBitmap )
            this->bufferedGifBitmap = new _bitmap( gifAnim->width , gifAnim->height , _color::transparent );

        // Limit Page Number
        if( gifAnim->frame_count <= page )
            page = gifAnim->frame_count -1;


        // Decode...
        statusCode = gif_decode_frame(gifAnim, page);

        // ... and Check if everything went ok
        if (statusCode != GIF_OK)
            _imageFile::outputGifWarning( "gif_decode_frame" , statusCode );

        // Get destination bitmap
        _pixelArray dest = this->bufferedGifBitmap->getBitmap();

        // Get Source bitmap
        _u8* source = (_u8*)gifAnim->frame_image;

        // Copy source bitmap to destination
        _length numPixels = gifAnim->height * gifAnim->width;
        do {
            *dest++ = _color::fromRGB8( source[0] , source[1] , source[2] , source[3] );
            source += 4;
        } while( --numPixels > 0 );

        // Clean temps
        if( this->buffer )
            this->bufferedGif = gifAnim;
        else
        {
            delete[] gifAnim->gif_data;
            delete gifAnim;
        }

        return *this->bufferedGifBitmap;
    }

    return _bitmap();
}
Example #7
0
void PlayState::init()
{
	// Reset the GameState
	g_playerScore = 0;
	g_playerHitThisStage = false;
	g_playerStageBulletsHit = 0;
	g_playerStageBulletsTotal = 0;
	R_triggered = false;
	currentStage->reset();
	bombShakeCounter = 0;
	bombAnimationCount = 0;
	bgMoveCounter = 0;

	player.setBombCount(1);

	starsBG_Pos = Vec2(0, 0);
	REG_BG0VOFS = starsBG_Pos.y;
	REG_BG0HOFS = starsBG_Pos.x;

	// Init background
	memcpy16(&se_mem[24], g_demo_starsMap, (SBB_SIZE/2));

	// Get sprites from the OAM Manager
	//	- 1 for player
	//	- 10 for enemies
	//	- 32 for bullets
	//  - 32 for enemy bullets
	//	- 1 for R_triggered indicator
	//  - 1 for power up
	//  - 2 for displaying lives/bombs at bottom of screen
	sprites = g_oamMan->allocSprites(NUM_SPRITES);

	// Initialize the first stage
	currentStage = g_stage1;
	currentStage->reset();
	stageCount = 1;

	// Init player
	player.useImg(PLAYER_SPRITE_POS);
	player.setPos(PLAYER_ORIGIN);
	player.setPalette(PLAYER_BASE_PALETTE);
	player.setTileIndex(g_playerSpriteTilesPos);
	player.setSize(PLAYER_SPRITE_SIZE);
	player.setVisible(true);
	player.setParent(this);
	player.hitBox.left = player.X() + PLAYER_LEFT_OFFSET;
	player.hitBox.right = player.X() + PLAYER_RIGHT_OFFSET;
	player.hitBox.top = player.Y() + PLAYER_TOP_OFFSET;
	player.hitBox.bottom = player.Y() + PLAYER_BOTTOM_OFFSET;
	player.reset();

	// Give the objects in allocators sprites
	playerBullets.spriteInit(PLAYER_BULLETS_SPRITE_POS);
	enemyBullets.spriteInit(ENEMY_BULLETS_SPRITE_POS);
	enemies.spriteInit(ENEMY_SPRITE_POS);

	// Init the R_triggered indicator
	R_triggered_indicator.useImg(R_TRIG_INDIC_SPRITE_POS);
	R_triggered_indicator.setPos(R_TRIG_INDIC_ORIGIN);
	R_triggered_indicator.setPalette(R_TRIG_INDIC_BASE_PALETTE);
	R_triggered_indicator.setTileIndex(g_bullet_selection1TilesPos);
	R_triggered_indicator.setSize(R_TRIG_INDIC_SPRITE_SIZE);
	R_triggered_indicator.setVisible(true);

	bombAnimation = false;
	bombAnimationCount = 0;

	// Init display sprites at bottom
	lifeIndic.useImg(LIFE_DISP_SPRITE_POS);
	lifeIndic.setSize(LIFE_DISP_SPRITE_SIZE);
	lifeIndic.setTileIndex(g_extraLife_TilesPos);
	lifeIndic.setPalette(4);
	lifeIndic.setPos(0, 152);
	lifeIndic.setVisible(true);
	
	bombIndic.useImg(BOMB_DISP_SPRITE_POS);
	bombIndic.setSize(BOMB_DISP_SPRITE_SIZE);
	bombIndic.setTileIndex(g_extraBomb_TilesPos);
	bombIndic.setPalette(4);
	bombIndic.setPos(128, 152);
	bombIndic.setVisible(true);

	// Set up the PowerUp constants
	powerUpExists = false;
	poweredUp = false;

	// Power ups
	powerUp.useImg(POWER_UP_SPRITE_POS);
	powerUp.setVisible(false);
	powerUp.setSize(POWER_UP_SPRITE_SIZE);
	powerUp.setTileIndex(g_shield_TilesPos);

	//Set up store state
	g_storeState->setPlayerPointer(&player);
}
Example #8
0
//! Copy \a count colors from \a src's palette to \a dst's palette.
void srf_pal_copy(const TSurface *dst, const TSurface *src, uint count)
{
	if(dst && src && count)
		memcpy16(dst->palData, src->palData, count);
}
Example #9
0
void MemCopyCompressor::decompressBytes(byte* in, byte* out, size_t count) {
	memcpy16(out, in, count);
}
Example #10
0
size_t MemCopyCompressor::compressBytes(byte* in, byte* out, size_t count) {
	memcpy16(out, in, count);
	return count;
}
Example #11
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
  }
}
/*******************************************************************************
 * Perform any BL31 specific platform actions. Populate the BL33 and BL32 image
 * info.
 ******************************************************************************/
void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
				u_register_t arg2, u_register_t arg3)
{
	struct tegra_bl31_params *arg_from_bl2 = (struct tegra_bl31_params *) arg0;
	plat_params_from_bl2_t *plat_params = (plat_params_from_bl2_t *)arg1;
	image_info_t bl32_img_info = { {0} };
	uint64_t tzdram_start, tzdram_end, bl32_start, bl32_end;
	uint32_t console_clock;
	int32_t ret;

	/*
	 * For RESET_TO_BL31 systems, BL31 is the first bootloader to run so
	 * there's no argument to relay from a previous bootloader. Platforms
	 * might use custom ways to get arguments, so provide handlers which
	 * they can override.
	 */
	if (arg_from_bl2 == NULL) {
		arg_from_bl2 = plat_get_bl31_params();
	}
	if (plat_params == NULL) {
		plat_params = plat_get_bl31_plat_params();
	}

	/*
	 * Copy BL3-3, BL3-2 entry point information.
	 * They are stored in Secure RAM, in BL2's address space.
	 */
	assert(arg_from_bl2 != NULL);
	assert(arg_from_bl2->bl33_ep_info != NULL);
	bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;

	if (arg_from_bl2->bl32_ep_info != NULL) {
		bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
		bl32_mem_size = arg_from_bl2->bl32_ep_info->args.arg0;
		bl32_boot_params = arg_from_bl2->bl32_ep_info->args.arg2;
	}

	/*
	 * Parse platform specific parameters - TZDRAM aperture base and size
	 */
	assert(plat_params != NULL);
	plat_bl31_params_from_bl2.tzdram_base = plat_params->tzdram_base;
	plat_bl31_params_from_bl2.tzdram_size = plat_params->tzdram_size;
	plat_bl31_params_from_bl2.uart_id = plat_params->uart_id;
	plat_bl31_params_from_bl2.l2_ecc_parity_prot_dis = plat_params->l2_ecc_parity_prot_dis;

	/*
	 * It is very important that we run either from TZDRAM or TZSRAM base.
	 * Add an explicit check here.
	 */
	if ((plat_bl31_params_from_bl2.tzdram_base != (uint64_t)BL31_BASE) &&
	    (TEGRA_TZRAM_BASE != BL31_BASE)) {
		panic();
	}

	/*
	 * Reference clock used by the FPGAs is a lot slower.
	 */
	if (tegra_platform_is_fpga()) {
		console_clock = TEGRA_BOOT_UART_CLK_13_MHZ;
	} else {
		console_clock = TEGRA_BOOT_UART_CLK_408_MHZ;
	}

	/*
	 * Get the base address of the UART controller to be used for the
	 * console
	 */
	tegra_console_base = plat_get_console_from_id(plat_params->uart_id);

	if (tegra_console_base != 0U) {
		/*
		 * Configure the UART port to be used as the console
		 */
		(void)console_init(tegra_console_base, console_clock,
			     TEGRA_CONSOLE_BAUDRATE);
	}

	/*
	 * The previous bootloader passes the base address of the shared memory
	 * location to store the boot profiler logs. Sanity check the
	 * address and initilise the profiler library, if it looks ok.
	 */
	if (plat_params->boot_profiler_shmem_base != 0ULL) {

		ret = bl31_check_ns_address(plat_params->boot_profiler_shmem_base,
				PROFILER_SIZE_BYTES);
		if (ret == (int32_t)0) {

			/* store the membase for the profiler lib */
			plat_bl31_params_from_bl2.boot_profiler_shmem_base =
				plat_params->boot_profiler_shmem_base;

			/* initialise the profiler library */
			boot_profiler_init(plat_params->boot_profiler_shmem_base,
					   TEGRA_TMRUS_BASE);
		}
	}

	/*
	 * Add timestamp for platform early setup entry.
	 */
	boot_profiler_add_record("[TF] early setup entry");

	/*
	 * Initialize delay timer
	 */
	tegra_delay_timer_init();

	/* Early platform setup for Tegra SoCs */
	plat_early_platform_setup();

	/*
	 * Do initial security configuration to allow DRAM/device access.
	 */
	tegra_memctrl_tzdram_setup(plat_bl31_params_from_bl2.tzdram_base,
			(uint32_t)plat_bl31_params_from_bl2.tzdram_size);

	/*
	 * The previous bootloader might not have placed the BL32 image
	 * inside the TZDRAM. We check the BL32 image info to find out
	 * the base/PC values and relocate the image if necessary.
	 */
	if (arg_from_bl2->bl32_image_info != NULL) {

		bl32_img_info = *arg_from_bl2->bl32_image_info;

		/* Relocate BL32 if it resides outside of the TZDRAM */
		tzdram_start = plat_bl31_params_from_bl2.tzdram_base;
		tzdram_end = plat_bl31_params_from_bl2.tzdram_base +
				plat_bl31_params_from_bl2.tzdram_size;
		bl32_start = bl32_img_info.image_base;
		bl32_end = bl32_img_info.image_base + bl32_img_info.image_size;

		assert(tzdram_end > tzdram_start);
		assert(bl32_end > bl32_start);
		assert(bl32_image_ep_info.pc > tzdram_start);
		assert(bl32_image_ep_info.pc < tzdram_end);

		/* relocate BL32 */
		if ((bl32_start >= tzdram_end) || (bl32_end <= tzdram_start)) {

			INFO("Relocate BL32 to TZDRAM\n");

			(void)memcpy16((void *)(uintptr_t)bl32_image_ep_info.pc,
				 (void *)(uintptr_t)bl32_start,
				 bl32_img_info.image_size);

			/* clean up non-secure intermediate buffer */
			zeromem((void *)(uintptr_t)bl32_start,
				bl32_img_info.image_size);
		}
	}

	/*
	 * Add timestamp for platform early setup exit.
	 */
	boot_profiler_add_record("[TF] early setup exit");

	INFO("BL3-1: Boot CPU: %s Processor [%lx]\n",
	     (((read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK)
	      == DENVER_IMPL) ? "Denver" : "ARM", read_mpidr());
}
Example #13
0
void arm_memcpy( void* dst, void* src, int size )
{
	memcpy16( dst, src, size );
}