Class: Executor
- Inherits:
-
Object
- Object
- Executor
- Defined in:
- lib/executor.rb
Constant Summary collapse
- ALLOWED_ROMS =
['tobu.gb', 'bgbtest.gb'].freeze
Instance Method Summary collapse
- #exec(direction_key = 0b1111, action_key = 0b1111) ⇒ Object
-
#initialize ⇒ Executor
constructor
A new instance of Executor.
- #read_pre_installed_rom(rom_name) ⇒ Object
- #read_rom_from_virtual_fs ⇒ Object
Constructor Details
#initialize ⇒ Executor
Returns a new instance of Executor.
11 12 13 14 |
# File 'lib/executor.rb', line 11 def initialize rom_data = File.open('lib/roms/tobu.gb', 'r') { _1.read.bytes } @emulator = Rubyboy::EmulatorWasm.new(rom_data) end |
Instance Method Details
#exec(direction_key = 0b1111, action_key = 0b1111) ⇒ Object
16 17 18 19 |
# File 'lib/executor.rb', line 16 def exec(direction_key = 0b1111, action_key = 0b1111) bin = @emulator.step(direction_key, action_key).pack('C*') File.binwrite(File.join('/RUBYBOY_TMP', 'video.data'), bin) end |
#read_pre_installed_rom(rom_name) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/executor.rb', line 29 def read_pre_installed_rom(rom_name) raise 'ROM not found in allowed ROMs' unless ALLOWED_ROMS.include?(rom_name) rom_path = File.join('lib/roms', rom_name) rom_data = File.open(rom_path, 'r') { _1.read.bytes } @emulator = Rubyboy::EmulatorWasm.new(rom_data) end |
#read_rom_from_virtual_fs ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/executor.rb', line 21 def read_rom_from_virtual_fs rom_path = '/RUBYBOY_TMP/rom.data' raise "ROM file not found in virtual filesystem at #{rom_path}" unless File.exist?(rom_path) rom_data = File.open(rom_path, 'rb') { |file| file.read.bytes } @emulator = Rubyboy::EmulatorWasm.new(rom_data) end |