Class: N65::IncBin
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::IncBin
- Defined in:
- lib/n65/directives/incbin.rb
Overview
This directive instruction can include a binary file
Defined Under Namespace
Classes: FileNotFound
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) ⇒ IncBin
constructor
Initialize with filename.
-
#to_s ⇒ Object
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(filename) ⇒ IncBin
Initialize with filename
26 27 28 |
# File 'lib/n65/directives/incbin.rb', line 26 def initialize(filename) @filename = filename end |
Class Method Details
.parse(line) ⇒ Object
Try to parse an incbin directive
16 17 18 19 20 21 |
# File 'lib/n65/directives/incbin.rb', line 16 def self.parse(line) match_data = line.match(/^\.incbin "([^"]+)"$/) return nil if match_data.nil? filename = match_data[1] IncBin.new(filename) end |
Instance Method Details
#exec(assembler) ⇒ Object
Execute on the assembler
33 34 35 36 37 38 39 |
# File 'lib/n65/directives/incbin.rb', line 33 def exec(assembler) unless File.exists?(@filename) fail(FileNotFound, ".incbin can't find #{@filename}") end data = File.read(@filename).unpack('C*') assembler.write_memory(data) end |
#to_s ⇒ Object
Display
44 45 46 |
# File 'lib/n65/directives/incbin.rb', line 44 def to_s ".incbin \"#{@filename}\"" end |