Class: Amaterasu::Emulator
- Inherits:
-
Object
- Object
- Amaterasu::Emulator
- Defined in:
- lib/amaterasu/emulator.rb,
sig/akane/emulator.rbs
Overview
Handles the core emulation loop.
Constant Summary collapse
- CYCLES_PER_FRAME =
17_556
Instance Method Summary collapse
-
#advance_cycle ⇒ void
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 ⇒ void
- #stop ⇒ void
Constructor Details
#initialize(audio:, cycles:, profiling:, steps:, trace:, renderer:, rom_path:) ⇒ 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 ⇒ void
This method returns an undefined value.
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 ⇒ void
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 |
#stop ⇒ void
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/amaterasu/emulator.rb', line 108 def stop @elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start_time frames = @cycles.to_f / 17_556 fps = frames / @elapsed_time puts "#{@steps} steps / #{@cycles} cycles in #{@elapsed_time.round(2)}s" puts "#{fps.round(2)} FPS (Target: 59.73)" puts "#{(fps / 59.73).round(2)}x real-time Game Boy" exit end |