Class: Rnes::InesHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/rnes/ines_header.rb

Constant Summary collapse

BYTESIZE =
16
PREFIX_BYTES =
[
  0x4E, # N
  0x45, # E
  0x53, # S
  0x1A, # end-of-file in MS-DOS
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ InesHeader

Returns a new instance of InesHeader.

Parameters:

  • bytes (Array<Integer>)


13
14
15
# File 'lib/rnes/ines_header.rb', line 13

def initialize(bytes)
  @bytes = bytes
end

Instance Method Details

#bytesizeInteger

Returns:

  • (Integer)


18
19
20
# File 'lib/rnes/ines_header.rb', line 18

def bytesize
  BYTESIZE
end

#character_ram_bytesizeInteger

Returns:

  • (Integer)


23
24
25
# File 'lib/rnes/ines_header.rb', line 23

def character_ram_bytesize
  @bytes[8]
end

#character_rom_bytesizeInteger

Returns:

  • (Integer)


28
29
30
# File 'lib/rnes/ines_header.rb', line 28

def character_rom_bytesize
  @bytes[5] * 8 * 2**10
end

#has_battery_backed_program_rom_bit?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rnes/ines_header.rb', line 33

def has_battery_backed_program_rom_bit?
  flags1[1] == 1
end

#has_mirror_ignoring_bit?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rnes/ines_header.rb', line 38

def has_mirror_ignoring_bit?
  flags1[3] == 1
end

#has_trainer_bit?Boolean

Note:

Trainers are 512 bytes of code which is loaded into $7000 before the game starts for hacker use.

Returns:

  • (Boolean)


44
45
46
# File 'lib/rnes/ines_header.rb', line 44

def has_trainer_bit?
  flags1[2] == 1
end

#has_vertical_mirroring_bit?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rnes/ines_header.rb', line 49

def has_vertical_mirroring_bit?
  flags1[0] == 1
end

#mapper_numberInteger

Returns:

  • (Integer)


54
55
56
# File 'lib/rnes/ines_header.rb', line 54

def mapper_number
  flags2 & 0b11110000 | flags1 >> 4
end

#program_rom_bytesizeInteger

Returns:

  • (Integer)


59
60
61
# File 'lib/rnes/ines_header.rb', line 59

def program_rom_bytesize
  @bytes[4] * 16 * 2**10
end

#trainer_bytesizeInteger

Returns:

  • (Integer)


64
65
66
67
68
69
70
# File 'lib/rnes/ines_header.rb', line 64

def trainer_bytesize
  if has_trainer_bit?
    512
  else
    0
  end
end

#valid?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/rnes/ines_header.rb', line 73

def valid?
  @bytes[0..3] == PREFIX_BYTES
end