Class: PSX::BIOS
- Inherits:
-
Object
- Object
- PSX::BIOS
- Defined in:
- lib/psx/bios.rb
Constant Summary collapse
- SIZE =
512 KB
512 * 1024
Instance Method Summary collapse
-
#initialize(path) ⇒ BIOS
constructor
A new instance of BIOS.
- #read16(offset) ⇒ Object
- #read32(offset) ⇒ Object
- #read8(offset) ⇒ Object
Constructor Details
#initialize(path) ⇒ BIOS
Returns a new instance of BIOS.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/psx/bios.rb', line 7 def initialize(path) @data = File.binread(path) if @data.bytesize != SIZE raise ArgumentError, "Invalid BIOS size: expected #{SIZE} bytes, got #{@data.bytesize}" end # Pre-compute 32-bit word array for fast read32 access # This trades memory for speed (512KB -> 512KB + 128K integers) @words = Array.new(SIZE / 4) do |i| offset = i * 4 @data.getbyte(offset) | (@data.getbyte(offset + 1) << 8) | (@data.getbyte(offset + 2) << 16) | (@data.getbyte(offset + 3) << 24) end end |
Instance Method Details
#read16(offset) ⇒ Object
29 30 31 |
# File 'lib/psx/bios.rb', line 29 def read16(offset) @data.getbyte(offset) | (@data.getbyte(offset + 1) << 8) end |
#read32(offset) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/psx/bios.rb', line 33 def read32(offset) # Fast path: aligned access from pre-computed array if (offset & 3) == 0 @words[offset >> 2] else # Unaligned access (rare) @data.getbyte(offset) | (@data.getbyte(offset + 1) << 8) | (@data.getbyte(offset + 2) << 16) | (@data.getbyte(offset + 3) << 24) end end |
#read8(offset) ⇒ Object
25 26 27 |
# File 'lib/psx/bios.rb', line 25 def read8(offset) @data.getbyte(offset) end |