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
- SystemInclude =
System include directory
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
41 42 43 |
# File 'lib/n65/directives/inc.rb', line 41 def initialize(filename) @filename = filename end |
Class Method Details
.parse(line) ⇒ Object
Try to parse an incbin directive
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/n65/directives/inc.rb', line 19 def self.parse(line) ## Do We have a system directory include? match_data = line.match(/^\.inc <([^>]+)>$/) unless match_data.nil? filename = File.join(SystemInclude, 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
48 49 50 51 52 53 54 55 |
# File 'lib/n65/directives/inc.rb', line 48 def exec(assembler) unless File.exists?(@filename) fail(FileNotFound, ".inc can't find #{@filename}") end File.read(@filename).split(/\n/).each do |line| assembler.assemble_one_line(line) end end |
#to_s ⇒ Object
Display
60 61 62 |
# File 'lib/n65/directives/inc.rb', line 60 def to_s ".inc \"#{@filename}\"" end |