Class: N65::FrontEnd

Inherits:
Object
  • Object
show all
Defined in:
lib/n65/front_end.rb

Overview

This class handles the front end aspects, parsing the commandline options and running the assembler

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ FrontEnd

Returns a new instance of FrontEnd.



10
11
12
13
# File 'lib/n65/front_end.rb', line 10

def initialize(argv)
  @options = { output_file: nil, write_symbol_table: false, quiet: false, cycle_count: false }
  @argv = argv.dup
end

Instance Method Details

#runObject

Run the assembler



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/n65/front_end.rb', line 16

def run
  parser = create_option_parser
  parser.parse!(@argv)

  if @argv.size.zero?
    warn('No input files')
    exit(1)
  end

  # Only can assemble one file at once for now
  if @argv.size != 1
    warn('Can only assemble one input file at once, but you can use .inc and .incbin directives')
    exit(1)
  end

  input_file = @argv.shift

  # Make sure the input file exists
  unless File.exist?(input_file)
    warn("Input file #{input_file} does not exist")
    exit(1)
  end

  # Maybe they didn't provide an output file name, so we'll guess
  if @options[:output_file].nil?
    ext = File.extname(input_file)
    @options[:output_file] = "#{input_file.gsub(ext, '')}.nes"
  end

  if @options.values.any?(&:nil?)
    warn('Missing options try --help')
    exit(1)
  end

  N65::Assembler.from_file(input_file, @options)
end