Permalink
Browse files

add rcpu-as executable

  • Loading branch information...
1 parent d3f1316 commit 372118ca5839bb8f9d4f74cf366b4334c7480bc2 @rlane rlane committed Apr 7, 2012
Showing with 40 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +39 −0 bin/rcpu-as
View
@@ -0,0 +1 @@
+gem "trollop", "~> 1.16.2"
View
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
+require 'trollop'
+require 'rcpu'
+
+opts = Trollop.options do
+ banner <<-EOS
+rcpu-as - a DCPU-16 assembler
+
+Usage:
+ rcpu-as [options] [file]
+
+where [options] are:
+EOS
+
+ opt :output, "Output filename", :short => 'o', :type => :string
+ opt :help, "Show this message", :short => 'h'
+
+ text <<-EOS
+
+If no output filename is given the output will be written to filename.bin.
+ EOS
+end
+
+input_filename = ARGV[0]
+
+if opts[:output]
+ output_io = File.open(opts[:output], 'w')
+else
+ filename = File.join(File.dirname(input_filename),
+ File.basename(input_filename, '.rcpu') + '.bin')
+ output_io = File.open(filename, 'w')
+end
+
+linker = RCPU::Linker.new
+lib = linker.find(input_filename, Dir.pwd)
+linker.compile(lib)
+data = linker.finalize
+output_io.write data.pack('v*')

0 comments on commit 372118c

Please sign in to comment.