Class: Amaterasu::GameBoy::Ppu::Modes::Rendering::PixelFifo
- Inherits:
-
Object
- Object
- Amaterasu::GameBoy::Ppu::Modes::Rendering::PixelFifo
- Defined in:
- lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb
Overview
Models the PPU Pixel FIFO from the original Game Boy (DMG).
Constant Summary collapse
- MAX_PIXELS =
or 8?
16
Instance Attribute Summary collapse
-
#pixels ⇒ Object
readonly
Array of raw color indices (0 - 3).
Instance Method Summary collapse
-
#clear ⇒ Object
Removes all current elements of the FIFO.
-
#empty? ⇒ Boolean
Removes all current elements of the FIFO.
-
#initialize ⇒ PixelFifo
constructor
A new instance of PixelFifo.
-
#merge(sprite_pixels) ⇒ Object
This is specific for Sprites.
-
#pop_pixel ⇒ Integer
To follow the FIFO rules, elements need to be popped from left to right, that is why we need to use Array#shift.
-
#push?(pushed_pixels) ⇒ Boolean
The Pixel Fetcher is the pixel producer, it produces 8 color indices (1 for each pixel) and attempts to push all 8 at the same time until it succeeds.
Constructor Details
#initialize ⇒ PixelFifo
Returns a new instance of PixelFifo.
15 16 17 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 15 def initialize @pixel_buffer = Array.new end |
Instance Attribute Details
#pixels ⇒ Object (readonly)
Array of raw color indices (0 - 3).
13 14 15 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 13 def pixels @pixels end |
Instance Method Details
#clear ⇒ Object
Removes all current elements of the FIFO.
57 58 59 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 57 def clear @pixel_buffer.clear end |
#empty? ⇒ Boolean
Removes all current elements of the FIFO.
62 63 64 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 62 def empty? @pixel_buffer.empty? end |
#merge(sprite_pixels) ⇒ Object
This is specific for Sprites.
36 37 38 39 40 41 42 43 44 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 36 def merge(sprite_pixels) idx = 0 while idx <= 7 transparent = (@pixel_buffer[idx] & 0b11) == 0b00 @pixel_buffer[idx] = sprite_pixels[idx] if transparent || @pixel_buffer[idx].nil? idx += 1 end end |
#pop_pixel ⇒ Integer
To follow the FIFO rules, elements need to be popped from left to right, that is why we need to use Array#shift.
50 51 52 53 54 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 50 def pop_pixel return if @pixel_buffer.empty? @pixel_buffer.shift end |
#push?(pushed_pixels) ⇒ Boolean
The Pixel Fetcher is the pixel producer, it produces 8 color indices (1 for each pixel) and attempts to push all 8 at the same time until it succeeds.
It will only succeed if the FIFO is empty.
26 27 28 29 30 31 32 |
# File 'lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb', line 26 def push?(pushed_pixels) return false unless @pixel_buffer.empty? pushed_pixels.each { |pp| @pixel_buffer << pp } true end |