1
0
mirror of https://github.com/safiire/n65.git synced 2024-12-12 00:29:03 +00:00
n65/lib/directives/ines_header.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

54 lines
1.2 KiB
Ruby

require 'json'
require_relative '../instruction_base'
module Assembler6502
####
## This directive instruction can setup an ines header
class INESHeader < InstructionBase
attr_reader :prog, :char, :mapper, :mirror
####
## Implementation of the parser for this directive
def self.parse(line)
match_data = line.match(/^\.ines (.+)$/)
return nil if match_data.nil?
header = JSON.parse(match_data[1])
INESHeader.new(header['prog'], header['char'], header['mapper'], header['mirror'])
end
####
## Construct a header
def initialize(prog, char, mapper, mirror)
@prog, @char, @mapper, @mirror = prog, char, mapper, mirror
end
####
## Exec function the assembler will call
def exec(assembler)
assembler.set_ines_header(self)
end
####
## Emit the header bytes, this is not exactly right, but it works for now.
def emit_bytes
[0x4E, 0x45, 0x53, 0x1a, @prog, @char, @mapper, @mirror, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
end
####
## Display
def to_s
".ines {\"prog\": #{@prog}, \"char\": #{@char}, \"mapper\": #{@mapper}, \"mirror\": #{@mirror}}"
end
end
end