Class: N65::DW
- Inherits:
-
InstructionBase
- Object
- InstructionBase
- N65::DW
- Defined in:
- lib/n65/directives/dw.rb
Overview
This directive instruction can include a binary file
Class Method Summary collapse
-
.parse(line) ⇒ Object
Try to parse a dw directive.
Instance Method Summary collapse
-
#exec(assembler) ⇒ Object
Execute on the assembler, now in this case value may be a symbol that needs to be resolved, if so we return a lambda which can be executed later, with the promise that that symbol will have then be defined This is a little complicated, I admit.
-
#initialize(value) ⇒ DW
constructor
Initialize with filename.
-
#to_s ⇒ Object
Display.
Methods inherited from InstructionBase
Constructor Details
#initialize(value) ⇒ DW
Initialize with filename
27 28 29 |
# File 'lib/n65/directives/dw.rb', line 27 def initialize(value) @value = value end |
Class Method Details
.parse(line) ⇒ Object
Try to parse a dw directive
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/n65/directives/dw.rb', line 9 def self.parse(line) # Maybe it is a straight up bit of hex match_data = line.match(/^\.dw\s+\$([0-9A-F]{1,4})$/) unless match_data.nil? word = match_data[1].to_i(16) return DW.new(word) end # Or maybe it points to a symbol match_data = line.match(/^\.dw\s+([A-Za-z_][A-Za-z0-9_.]+)/) unless match_data.nil? symbol = match_data[1] return DW.new(symbol) end nil end |
Instance Method Details
#exec(assembler) ⇒ Object
Execute on the assembler, now in this case value may be a symbol that needs to be resolved, if so we return a lambda which can be executed later, with the promise that that symbol will have then be defined This is a little complicated, I admit.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/n65/directives/dw.rb', line 36 def exec(assembler) promise = assembler.with_saved_state do |saved_assembler| value = saved_assembler.symbol_table.resolve_symbol(@value) bytes = [value & 0xFFFF].pack('S').bytes saved_assembler.write_memory(bytes) end # Try to execute it now, or setup the promise to return case @value when Integer bytes = [@value & 0xFFFF].pack('S').bytes assembler.write_memory(bytes) when String begin promise.call rescue SymbolTable::UndefinedSymbol # Must still advance PC before returning promise, so we'll write # a place holder value of 0xDEAD assembler.write_memory([0xDE, 0xAD]) promise end else raise('Uknown argument in .dw directive') end end |
#to_s ⇒ Object
Display
63 64 65 66 67 68 69 70 |
# File 'lib/n65/directives/dw.rb', line 63 def to_s case @value when String ".dw #{@value}" when Integer '.dw $%4.X' % @value end end |