Module: Rubygb

Defined in:
lib/rubygb.rb,
lib/rubygb/cli.rb,
lib/rubygb/rubygb.rb,
lib/rubygb/version.rb,
lib/rubygb/template/template.rb

Defined Under Namespace

Classes: CLI, Template

Constant Summary collapse

VERSION =
"0.2.2".freeze

Class Method Summary collapse

Class Method Details

.build(filename, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubygb/rubygb.rb', line 2

def self.build filename, options={}
  unless File.exists? filename
    raise "Fatal: can't find #{filename}"
  end

  if options[:output]
    Dir.mkdir(options[:output]) unless Dir.exists? options[:output]
  end

  base = File.basename(filename, ".*")
  exe_path = File.expand_path(File.join(File.dirname(__FILE__),"..","rgbds"))

  obj_file, map_file, sym_file, rom_file = %w(.obj .map .sym .gb).map do |ext|
    options[:output] ? File.join(options[:output], "#{base}#{ext}") : "#{base}#{ext}"
  end

  raise "Assembly failed!" unless system("#{exe_path}/rgbasm -v -o#{obj_file} #{filename}")

  raise "Link failed!" unless system("#{exe_path}/rgblink -m#{map_file} -n#{sym_file} -o#{rom_file} #{obj_file}")

  unless options[:no_fix]
    raise "Header fix failed!" unless system("#{exe_path}/rgbfix -p0 -v #{rom_file}")
  end
end