Class: N65::INESHeader
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::INESHeader
- Defined in:
- lib/n65/directives/ines_header.rb
Constant Summary collapse
- DEFAULTS =
{ prog: 1, char: 0, mapper: 0, mirror: 0, battery_backed: 0, fourscreen_vram: 0, prog_ram: 0, tv: 0 }.freeze
Instance Attribute Summary collapse
-
#battery_backed ⇒ Object
readonly
Returns the value of attribute battery_backed.
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#fourscreen_vram ⇒ Object
readonly
Returns the value of attribute fourscreen_vram.
-
#mapper ⇒ Object
readonly
Returns the value of attribute mapper.
-
#mirror ⇒ Object
readonly
Returns the value of attribute mirror.
-
#prog ⇒ Object
readonly
Returns the value of attribute prog.
-
#prog_ram ⇒ Object
readonly
Returns the value of attribute prog_ram.
-
#tv ⇒ Object
readonly
Returns the value of attribute tv.
Class Method Summary collapse
Instance Method Summary collapse
-
#emit_bytes ⇒ Object
Emit the header bytes.
-
#exec(assembler) ⇒ Object
Exec function the assembler will call.
-
#initialize(prog, char, mapper, mirror, battery_backed, fourscreen_vram, prog_ram, tv) ⇒ INESHeader
constructor
Construct a header.
-
#to_s ⇒ Object
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(prog, char, mapper, mirror, battery_backed, fourscreen_vram, prog_ram, tv) ⇒ INESHeader
Construct a header
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/n65/directives/ines_header.rb', line 45 def initialize(prog, char, mapper, mirror, battery_backed, fourscreen_vram, prog_ram, tv) @prog = prog @char = char @mapper = mapper @mirror = mirror @battery_backed = battery_backed @fourscreen_vram = fourscreen_vram @prog_ram = prog_ram @tv = tv end |
Instance Attribute Details
#battery_backed ⇒ Object (readonly)
Returns the value of attribute battery_backed.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def battery_backed @battery_backed end |
#char ⇒ Object (readonly)
Returns the value of attribute char.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def char @char end |
#fourscreen_vram ⇒ Object (readonly)
Returns the value of attribute fourscreen_vram.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def fourscreen_vram @fourscreen_vram end |
#mapper ⇒ Object (readonly)
Returns the value of attribute mapper.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def mapper @mapper end |
#mirror ⇒ Object (readonly)
Returns the value of attribute mirror.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def mirror @mirror end |
#prog ⇒ Object (readonly)
Returns the value of attribute prog.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def prog @prog end |
#prog_ram ⇒ Object (readonly)
Returns the value of attribute prog_ram.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def prog_ram @prog_ram end |
#tv ⇒ Object (readonly)
Returns the value of attribute tv.
8 9 10 |
# File 'lib/n65/directives/ines_header.rb', line 8 def tv @tv end |
Class Method Details
.parse(line) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/n65/directives/ines_header.rb', line 21 def self.parse(line) match_data = line.match(/^\.ines (.+)$/) return nil if match_data.nil? header = JSON.parse(match_data[1]) header = header.each_with_object({}) do |(key, val), hash| hash[key.to_sym] = val end header = DEFAULTS.merge(header) INESHeader.new( header[:prog], header[:char], header[:mapper], header[:mirror], header[:battery_backed], header[:fourscreen_vram], header[:prog_ram], header[:tv] ) end |
Instance Method Details
#emit_bytes ⇒ Object
Emit the header bytes
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/n65/directives/ines_header.rb', line 62 def emit_bytes mapper_lo_nybble = (@mapper & 0x0f) mapper_hi_nybble = (@mapper & 0xf0) >> 4 flag6 = 0 flag6 |= 0x1 if @mirror == 1 flag6 |= 0x2 if @battery_backed == 1 flag6 |= 0x8 if @fourscreen_vram == 1 flag6 |= (mapper_lo_nybble << 4) flag7 = 0 flag7 |= (mapper_hi_nybble << 4) [0x4E, 0x45, 0x53, 0x1a, @prog & 0xff, @char & 0xff, flag6 & 0xff, flag7 & 0xff, @prog_ram & 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0] end |
#exec(assembler) ⇒ Object
Exec function the assembler will call
57 58 59 |
# File 'lib/n65/directives/ines_header.rb', line 57 def exec(assembler) assembler.set_ines_header(self) end |
#to_s ⇒ Object
Display
85 86 87 88 89 90 |
# File 'lib/n65/directives/ines_header.rb', line 85 def to_s [".ines {\"prog\": #{@prog}, \"char\": #{@char}, \"mapper\": #{@mapper}, ", "\"mirror\": #{@mirror}}, \"battery_backed\": #{@battery_backed}, ", "\"fourscreen_vram\": #{@fourscreen_vram}, \"prog_ram\": #{@prog_ram}, ", "\"tv\": #{@tv}"].join end |