Class: Amaterasu::Emulator
- Inherits:
-
Object
- Object
- Amaterasu::Emulator
- Defined in:
- lib/amaterasu/emulator.rb
Overview
Handles the core emulation loop.
Constant Summary collapse
- CYCLES_PER_FRAME =
17_556
Instance Method Summary collapse
-
#advance_cycle ⇒ Object
This method is called every time the CPU spends exactly 1 M-cycle to advance other components.
-
#initialize(audio:, cycles:, profiling:, steps:, trace:, renderer:, rom_path:) ⇒ Emulator
constructor
A new instance of Emulator.
- #start ⇒ Object
Constructor Details
#initialize(audio:, cycles:, profiling:, steps:, trace:, renderer:, rom_path:) ⇒ Emulator
Returns a new instance of Emulator.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/amaterasu/emulator.rb', line 8 def initialize( audio:, cycles:, profiling:, steps:, trace:, renderer:, rom_path: ) @audio = audio @renderer = renderer @stop_cycles = cycles @stop_steps = steps @profiling_mode = profiling @trace = trace @rom_path = rom_path @cycles = 0 @steps = 0 end |
Instance Method Details
#advance_cycle ⇒ Object
This method is called every time the CPU spends exactly 1 M-cycle to advance other components.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/amaterasu/emulator.rb', line 46 def advance_cycle stop if @stop_cycles && @cycles == @stop_cycles @timer.tick @apu.tick @dma.tick i = 0 while i < 4 @ppu.tick i += 1 end @cycles += 1 end |
#start ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/amaterasu/emulator.rb', line 29 def start @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) load_cartridge load_memory load_components Kernel.loop do stop if @stop_steps && @steps == @stop_steps @cpu.step @steps += 1 end end |