Class: Amaterasu::GameBoy::Vram::TileData

Inherits:
Object
  • Object
show all
Defined in:
lib/amaterasu/game_boy/vram/tile_data.rb

Overview

Models the Tile Data that lives in the VRAM.

Constant Summary collapse

TILE_SIZE =
16
TILE_ENTRIES =
384

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vram_data:) ⇒ TileData

Returns a new instance of TileData.

Parameters:

  • vram_data (Array)

    Original VRAM @data array object.



14
15
16
17
18
19
20
21
# File 'lib/amaterasu/game_boy/vram/tile_data.rb', line 14

def initialize(vram_data:)
  @addressing_mode = :unsigned
  @base_offset     = 0x0000

  @tiles = Array.new(TILE_ENTRIES) do |index|
    Tile.new(vram_data: vram_data, tile_index: index)
  end
end

Instance Attribute Details

#addressing_modeObject

Returns the value of attribute addressing_mode.



11
12
13
# File 'lib/amaterasu/game_boy/vram/tile_data.rb', line 11

def addressing_mode
  @addressing_mode
end

#base_offsetObject (readonly)

Returns the value of attribute base_offset.



11
12
13
# File 'lib/amaterasu/game_boy/vram/tile_data.rb', line 11

def base_offset
  @base_offset
end

#tilesObject (readonly)

Returns the value of attribute tiles.



11
12
13
# File 'lib/amaterasu/game_boy/vram/tile_data.rb', line 11

def tiles
  @tiles
end

Instance Method Details

#tile_at(tile_index) ⇒ Vram::Tile

Fetches a Tile based on a given index, if the addressing mode is set to :signed, we need to sign the value before fetching the tile.

Parameters:

  • tile_index (Integer)

    8-bit value representing the tile index.

Returns:



35
36
37
38
39
40
# File 'lib/amaterasu/game_boy/vram/tile_data.rb', line 35

def tile_at(tile_index)
  tile_index = sign_value(tile_index) if @addressing_mode == :signed
  tile_offset = @base_offset / Tile::SIZE_IN_BYTES

  @tiles[tile_offset + tile_index]
end