Class: Rubyboy::Lcd

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyboy/lcd.rb

Constant Summary collapse

SCREEN_WIDTH =
160
SCREEN_HEIGHT =
144
SCALE =
3

Instance Method Summary collapse

Constructor Details

#initializeLcd

Returns a new instance of Lcd.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubyboy/lcd.rb', line 11

def initialize
  raise SDL.GetError() if SDL.InitSubSystem(SDL::INIT_VIDEO) != 0

  @buffer = FFI::MemoryPointer.new(:uint8, SCREEN_WIDTH * SCREEN_HEIGHT * 3)
  @window = SDL.CreateWindow('RUBY BOY', 0, 0, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE, SDL::SDL_WINDOW_RESIZABLE)

  raise SDL.GetError() if @window.null?

  @renderer = SDL.CreateRenderer(@window, -1, 0)
  SDL.SetHint('SDL_HINT_RENDER_SCALE_QUALITY', '2')
  SDL.RenderSetLogicalSize(@renderer, SCREEN_WIDTH * SCALE, SCREEN_HEIGHT * SCALE)
  @texture = SDL.CreateTexture(@renderer, SDL::PIXELFORMAT_RGB24, 1, SCREEN_WIDTH, SCREEN_HEIGHT)
  @event = FFI::MemoryPointer.new(:pointer)
end

Instance Method Details

#close_windowObject



43
44
45
46
# File 'lib/rubyboy/lcd.rb', line 43

def close_window
  SDL.DestroyWindow(@window)
  SDL.Quit
end

#draw(framebuffer) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rubyboy/lcd.rb', line 26

def draw(framebuffer)
  @buffer.write_array_of_uint8(framebuffer)
  SDL.UpdateTexture(@texture, nil, @buffer, SCREEN_WIDTH * 3)
  SDL.RenderClear(@renderer)
  SDL.RenderCopy(@renderer, @texture, nil, nil)
  SDL.RenderPresent(@renderer)
end

#window_should_close?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
# File 'lib/rubyboy/lcd.rb', line 34

def window_should_close?
  while SDL.PollEvent(@event) != 0
    event_type = @event.read_int
    return true if event_type == SDL::QUIT
  end

  false
end