Class: N65::Inc
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::Inc
- Defined in:
- lib/n65/directives/inc.rb
Overview
This directive instruction can include another asm file
Defined Under Namespace
Classes: FileNotFound
Constant Summary collapse
- SYSTEM_INCLUDE =
"#{File.dirname(__FILE__)}/../../../nes_lib"
Class Method Summary collapse
-
.parse(line) ⇒ Object
Try to parse an incbin directive.
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
Execute on the assembler.
-
#initialize(filename) ⇒ Inc
constructor
Initialize with filename.
-
#to_s ⇒ Object
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(filename) ⇒ Inc
Initialize with filename
33 34 35 |
# File 'lib/n65/directives/inc.rb', line 33 def initialize(filename) @filename = filename end |
Class Method Details
.parse(line) ⇒ Object
Try to parse an incbin directive
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/n65/directives/inc.rb', line 13 def self.parse(line) # Do We have a system directory include? match_data = line.match(/^\.inc <([^>]+)>$/) unless match_data.nil? filename = File.join(SYSTEM_INCLUDE, match_data[1]) return Inc.new(filename) end # Do We have a project relative directory include? match_data = line.match(/^\.inc "([^"]+)"$/) unless match_data.nil? filename = File.join(Dir.pwd, match_data[1]) return Inc.new(filename) end # Nope, not an inc directive nil end |
Instance Method Details
#exec(assembler) ⇒ Object
Execute on the assembler
38 39 40 41 42 43 44 |
# File 'lib/n65/directives/inc.rb', line 38 def exec(assembler) raise(FileNotFound, ".inc can't find #{@filename}") unless File.exist?(@filename) File.read(@filename).split(/\n/).each do |line| assembler.assemble_one_line(line) end end |
#to_s ⇒ Object
Display
47 48 49 |
# File 'lib/n65/directives/inc.rb', line 47 def to_s ".inc \"#{@filename}\"" end |