Class: Amaterasu::GameBoy::Vram
- Defined in:
- lib/amaterasu/game_boy/vram.rb,
lib/amaterasu/game_boy/vram/tile.rb,
lib/amaterasu/game_boy/vram/tile_map.rb,
lib/amaterasu/game_boy/vram/tile_data.rb
Overview
Models the VRAM (Video RAM) from the DMG Game Boy.
The VRAM address range can be divided into 2 main parts.
-
Tile Data:
- Lives in 0x8000 -> 0x97FF (6144 bytes)
- Each tile is composed of 8 x 8 = 64 pixels
- Each pixel is encoded as 2 bits in the DMG Game Boy
- So each tile has 64 * 2 = 128 bits (16 bytes)
-
Tile Maps:
- Has a total of 2 Tile Maps (0x9800 -> 0x9BFF) / (0x9C00 -> 0x9FFF)
- Each Tile Map is a 32 x 32 grid of Tile indices (each index is 1 byte)
- So each Tile Map has exactly 1024 bytes (1 KiB)
Defined Under Namespace
Classes: Tile, TileData, TileMap
Constant Summary collapse
- START_ADDRESS =
VRAM Start Address in the Memory Map
0x8000- END_ADDRESS =
VRAM End Address in the Memory Map
0x9FFF- SIZE_IN_BYTES =
VRAM Size in bytes: 8192 bytes (8 KiB)
(END_ADDRESS - START_ADDRESS) + 1
Instance Attribute Summary collapse
-
#tile_data ⇒ Object
readonly
Exposes the tile data and maps to the PPU.
-
#tile_map_high ⇒ Object
readonly
Exposes the tile data and maps to the PPU.
-
#tile_map_low ⇒ Object
readonly
Exposes the tile data and maps to the PPU.
Attributes inherited from Ram
Instance Method Summary collapse
-
#initialize ⇒ Vram
constructor
Creates “lens objects” passing the original VRAM @data Array, when a value is written into VRAM it will be correctly read by all the Tile Data and Tile Maps.
- #inspect ⇒ Object
Methods inherited from Ram
#disk_size, #read_backup, #read_byte, #restore_data, #save_data, #wipe_backup, #wipe_data, #write_byte
Constructor Details
#initialize ⇒ Vram
Creates “lens objects” passing the original VRAM @data Array, when a value is written into VRAM it will be correctly read by all the Tile Data and Tile Maps.
35 36 37 38 39 40 41 |
# File 'lib/amaterasu/game_boy/vram.rb', line 35 def initialize super(size: SIZE_IN_BYTES, offset: START_ADDRESS) @tile_data = TileData.new(vram_data: @data) @tile_map_low = TileMap.new(vram_data: @data, base_offset: 0x1800) @tile_map_high = TileMap.new(vram_data: @data, base_offset: 0x1C00) end |
Instance Attribute Details
#tile_data ⇒ Object (readonly)
Exposes the tile data and maps to the PPU
28 29 30 |
# File 'lib/amaterasu/game_boy/vram.rb', line 28 def tile_data @tile_data end |
#tile_map_high ⇒ Object (readonly)
Exposes the tile data and maps to the PPU
28 29 30 |
# File 'lib/amaterasu/game_boy/vram.rb', line 28 def tile_map_high @tile_map_high end |
#tile_map_low ⇒ Object (readonly)
Exposes the tile data and maps to the PPU
28 29 30 |
# File 'lib/amaterasu/game_boy/vram.rb', line 28 def tile_map_low @tile_map_low end |
Instance Method Details
#inspect ⇒ Object
43 44 45 46 47 48 |
# File 'lib/amaterasu/game_boy/vram.rb', line 43 def inspect '#<Vram ' \ "@tile_data=#{@tile_data} " \ "@tile_map_low=#{@tile_map_low} " \ "@tile_map_high=#{@tile_map_high}>" end |