Skip to content

Instantly share code, notes, and snippets.

@mnaberez
Created February 10, 2012 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mnaberez/1784947 to your computer and use it in GitHub Desktop.
Save mnaberez/1784947 to your computer and use it in GitHub Desktop.
Generate VICE monitor labels from an XAsm listing file
#!/usr/bin/env ruby
# Ruby script to generate VICE monitor labels from
# an XAsm listing file.
filename = ARGV[0]
if filename
lines = File.readlines(filename)
else
abort "Usage: vice-labels.rb <filename>"
end
# Collect the lines containing the symbol table
symbol_lines = []
started = false
lines.each do |line|
if line.include?("***Symbol Listing")
started = true
elsif line.include?("error(s)")
break
elsif started && !line.strip.empty?
symbol_lines << line
end
end
# Parse the symbol table into a hash: {address => label}
addr_label={}
symbol_lines.each do |line|
line.scan(/(\w+)\s+(\w+)/).each do |label, addr|
addr_label[addr] = label
end
end
# Generate VICE monitor labels ordered by address
addr_label.keys.sort.each do |addr|
label = addr_label[addr]
puts "add_label $#{addr} .#{label}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment