Class: N65::IncBin

Inherits:
InstructionBase show all
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

Instance Method Summary collapse

Methods inherited from InstructionBase

#unresolved_symbols?

Constructor Details

#initialize(filename) ⇒ IncBin

Returns a new instance of IncBin.



18
19
20
# File 'lib/n65/directives/incbin.rb', line 18

def initialize(filename)
  @filename = filename
end

Class Method Details

.parse(line) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/n65/directives/incbin.rb', line 10

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

Raises:



22
23
24
25
26
27
# File 'lib/n65/directives/incbin.rb', line 22

def exec(assembler)
  raise(FileNotFound, ".incbin can't find #{@filename}") unless File.exist?(@filename)

  data = File.read(@filename).unpack('C*')
  assembler.write_memory(data)
end

#to_sObject



29
30
31
# File 'lib/n65/directives/incbin.rb', line 29

def to_s
  ".incbin \"#{@filename}\""
end