map-maker.rbIf you were curious as to how I generated the var/set instruction pairs for the world[] array in the map.asm example, then look no further, as the full source to this useful tool is listed below.
#!/usr/bin/env ruby
# map-maker.rb
# companion ruby script for map.asm
# this will generate the var/set pairs for the specified map
# the starting address can be specified
# written by Richard Marks <ccpsceo@gmail.com>
$STARTING_ADDRESS = 1000
$MAP_ROWS = 10
$MAP_COLUMNS = 10
$MAP_DATA = [
"##########",
"# # #",
"# ## ### #",
"# # # #",
"# # #### #",
"# # # #",
"# # # #",
"# ########",
"# #",
"##########"]
class MapMaker
def initialize
@world = []
self.read_map_data
#self.test_world
self.output_assembly
end
def read_map_data
$MAP_DATA.each do |row|
row.each_byte do |cell|
@world.push cell
end
end
end
def test_world
(0...$MAP_ROWS).each do |row|
(0...$MAP_COLUMNS).each do |column|
print "#{@world[column + (row * $MAP_COLUMNS)].chr}"
end
print "\n"
end
print "\n"
end
def output_assembly
counter = $STARTING_ADDRESS
@world.each do |value|
print "var #{counter}\nset #{value}\n"
counter += 1
end
end
end
if __FILE__ == $0 then
MapMaker.new
end