1
0
mirror of https://github.com/safiire/n65.git synced 2024-12-12 00:29:03 +00:00
n65/lib/directives/bytes.rb
Safiire 2c938f7312 This is s a big rewrite including: A scoped symbol table, segment and
bank management, Use of promises to resolve symbols that are used before
they are defined.  A base class for all instructions and assembler
directives.  Hopefully my scoped symbols can be used to create C like
data structures in the zero page, ie sprite.x   New code to prodce the
final ROM.  Basically everything was rewritten.
2015-03-05 12:33:56 -08:00

50 lines
967 B
Ruby

require_relative '../instruction_base'
module Assembler6502
####
## This directive to include bytes
class Bytes < InstructionBase
####
## Try to parse an incbin directive
def self.parse(line)
match_data = line.match(/^\.bytes\s+(.+)$/)
return nil if match_data.nil?
bytes_array = match_data[1].split(',').map do |byte_string|
number = byte_string.gsub('$', '')
integer = number.to_i(16)
fail(SyntaxError, "#{integer} is too large for one byte") if integer > 0xff
integer
end
Bytes.new(bytes_array)
end
####
## Initialize with filename
def initialize(bytes_array)
@bytes_array = bytes_array
end
####
## Execute on the assembler
def exec(assembler)
assembler.write_memory(@bytes_array)
end
####
## Display, I don't want to write all these out
def to_s
".bytes (#{@bytes_array.length})"
end
end
end