class Rnes::Logger
Public Class Methods
new(cpu:, path:, ppu:)
click to toggle source
@param [Rnes::Cpu] cpu @param [String] path @param [Rnes::Ppu] ppu
# File lib/rnes/logger.rb, line 8 def initialize(cpu:, path:, ppu:) @cpu = cpu @path = path @ppu = ppu end
Public Instance Methods
puts()
click to toggle source
# File lib/rnes/logger.rb, line 14 def puts file.puts(line) end
Private Instance Methods
file()
click to toggle source
@return [File]
# File lib/rnes/logger.rb, line 21 def file @file ||= ::File.open(@path, 'w') end
line()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 26 def line [ segment_cpu_program_counter, '', segment_operation_code, segment_operand, '', segment_operation_full_name, segment_operand_humanized, '', segment_cpu_accumulator, segment_cpu_index_x, segment_cpu_index_y, segment_cpu_status, segment_cpu_stack_pointer, segment_cycle, segment_ppu_line, ].join(' ') end
segment_cpu_accumulator()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 47 def segment_cpu_accumulator format('A:%02X', @cpu.registers.accumulator) end
segment_cpu_index_x()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 52 def segment_cpu_index_x format('X:%02X', @cpu.registers.index_x) end
segment_cpu_index_y()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 57 def segment_cpu_index_y format('Y:%02X', @cpu.registers.index_y) end
segment_cpu_program_counter()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 62 def segment_cpu_program_counter format('%04X', @cpu.registers.program_counter) end
segment_cpu_stack_pointer()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 67 def segment_cpu_stack_pointer format('SP:%02X', @cpu.registers.stack_pointer - 0x100) end
segment_cpu_status()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 72 def segment_cpu_status format('P:%02X', @cpu.registers.status) end
segment_cycle()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 77 def segment_cycle format('CYC:%3d', @ppu.cycle) end
segment_operand()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 82 def segment_operand program_counter = @cpu.registers.program_counter operation = @cpu.read_operation case operation.addressing_mode when :absolute, :absolute_x, :absolute_y, :indirect_absolute format('%02X %02X', @cpu.bus.read(program_counter + 1), @cpu.bus.read(program_counter + 2)) when :immediate, :relative, :zero_page, :zero_page_x, :zero_page_y, :pre_indexed_indirect, :post_indexed_indirect format('%02X ', @cpu.bus.read(program_counter + 1)) else ' ' * 5 end end
segment_operand_humanized()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 96 def segment_operand_humanized operation = @cpu.read_operation program_counter = @cpu.registers.program_counter string = begin case operation.addressing_mode when :absolute, :absolute_x, :absolute_y, :indirect_absolute, :pre_indexed_absolute, :post_indexed_absolute format('$%02X%02X', @cpu.bus.read(program_counter + 2), @cpu.bus.read(program_counter + 1)) when :immediate, :relative, :zero_page, :zero_page_x, :zero_oage_y format('#$%02X', @cpu.bus.read(program_counter + 1)) else '' end end format('%-19s', string) end
segment_operation_code()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 113 def segment_operation_code operation = @cpu.read_operation operation_code = ::Rnes::Operation::RECORDS.find_index(operation.to_hash) format('%02X', operation_code) end
segment_operation_full_name()
click to toggle source
@return [String]
# File lib/rnes/logger.rb, line 120 def segment_operation_full_name operation = @cpu.read_operation format('%-10s', operation.full_name) end
segment_ppu_line()
click to toggle source
@note SL means “Scan Line”. @return [String]
# File lib/rnes/logger.rb, line 127 def segment_ppu_line format('SL:%03d', @ppu.line) end