Class: N65::INESHeader

Inherits:
InstructionBase show all
Defined in:
lib/n65/directives/ines_header.rb

Overview

This directive instruction can setup an ines header

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InstructionBase

#unresolved_symbols?

Constructor Details

#initialize(prog, char, mapper, mirror) ⇒ INESHeader

Construct a header



26
27
28
# File 'lib/n65/directives/ines_header.rb', line 26

def initialize(prog, char, mapper, mirror)
  @prog, @char, @mapper, @mirror = prog, char, mapper, mirror
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



10
11
12
# File 'lib/n65/directives/ines_header.rb', line 10

def char
  @char
end

#mapperObject (readonly)

Returns the value of attribute mapper.



10
11
12
# File 'lib/n65/directives/ines_header.rb', line 10

def mapper
  @mapper
end

#mirrorObject (readonly)

Returns the value of attribute mirror.



10
11
12
# File 'lib/n65/directives/ines_header.rb', line 10

def mirror
  @mirror
end

#progObject (readonly)

Returns the value of attribute prog.



10
11
12
# File 'lib/n65/directives/ines_header.rb', line 10

def prog
  @prog
end

Class Method Details

.parse(line) ⇒ Object

Implementation of the parser for this directive



15
16
17
18
19
20
21
# File 'lib/n65/directives/ines_header.rb', line 15

def self.parse(line)
  match_data = line.match(/^\.ines (.+)$/)
  return nil if match_data.nil?

  header = JSON.parse(match_data[1])
  INESHeader.new(header['prog'], header['char'], header['mapper'], header['mirror'])
end

Instance Method Details

#emit_bytesObject

Emit the header bytes, this is not exactly right, but it works for now.



40
41
42
# File 'lib/n65/directives/ines_header.rb', line 40

def emit_bytes
  [0x4E, 0x45, 0x53, 0x1a, @prog, @char, @mapper, @mirror, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
end

#exec(assembler) ⇒ Object

Exec function the assembler will call



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

def exec(assembler)
  assembler.set_ines_header(self)
end

#to_sObject

Display



47
48
49
# File 'lib/n65/directives/ines_header.rb', line 47

def to_s
  ".ines {\"prog\": #{@prog}, \"char\": #{@char}, \"mapper\": #{@mapper}, \"mirror\": #{@mirror}}"
end