Class: Rubyboy::EmulatorWasm

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

Constant Summary collapse

CPU_CLOCK_HZ =
4_194_304
CYCLE_NANOSEC =
1_000_000_000 / CPU_CLOCK_HZ

Instance Method Summary collapse

Constructor Details

#initialize(rom_data) ⇒ EmulatorWasm

Returns a new instance of EmulatorWasm.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubyboy/emulator_wasm.rb', line 20

def initialize(rom_data)
  rom = Rom.new(rom_data)
  ram = Ram.new
  mbc = Cartridge::Factory.create(rom, ram)
  interrupt = Interrupt.new
  @ppu = PpuWasm.new(interrupt)
  @timer = Timer.new(interrupt)
  @joypad = Joypad.new(interrupt)
  @apu = ApuWasm.new
  @bus = Bus.new(@ppu, rom, ram, mbc, @timer, interrupt, @joypad, @apu)
  @cpu = Cpu.new(@bus, interrupt)
end

Instance Method Details

#step(direction_key, action_key) ⇒ Object



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

def step(direction_key, action_key)
  @joypad.direction_button(direction_key)
  @joypad.action_button(action_key)
  loop do
    cycles = @cpu.exec
    @timer.step(cycles)
    return @ppu.buffer if @ppu.step(cycles)
  end
end