Skip to content

Instantly share code, notes, and snippets.

@cacciatc
Last active September 24, 2015 00:05
Show Gist options
  • Save cacciatc/ad9c759e78e265675192 to your computer and use it in GitHub Desktop.
Save cacciatc/ad9c759e78e265675192 to your computer and use it in GitHub Desktop.
Scans source for comment annotations and create a Lua script to be used with FCEUX
debug_prints = []
# scan all source files for ;! annotations
(Dir.glob("src/**/*.h") + Dir.glob("src/**/*.s")).each do |file|
File.open(file, "r") do |file|
capture_next_line = false
file.readlines.each do |line|
if capture_next_line
debug_prints[-1][:name] = line.strip.split(":").first
capture_next_line = false
end
if line =~ /\;\!(\s)*debug_printb/
debug_prints.push({:message => line.split('debug_printb').last.strip, :size => "byte"})
capture_next_line = true
elsif line =~ /\;\!(\s)*debug_printw/
debug_prints.push({:message => line.split('debug_printw').last.strip, :size => "word"})
capture_next_line = true
end
end
end
end
# now open the vice file and match each debug_print
File.open("bin/main.vice", "r") do |file|
file.readlines.each do |line|
debug_prints.each do |p|
if line.split(" ").last.strip[1..-1] == p[:name]
p[:address] = line.split(" ")[1]
end
end
end
end
print_statements = ""
y = 8
debug_prints.each do |d|
if d[:size] == "word"
print_statements += "\tgui.text(0, #{y}, \"#{d[:message]}: \" .. string.format(\"%X\", memory.readword(0x#{d[:address]})));\n"
elsif
print_statements += "\tgui.text(0, #{y}, \"#{d[:message]}: \" .. string.format(\"%X\", memory.readbyte(0x#{d[:address]})));\n"
end
y += 8
end
# create a debug.lua file
File.open("bin/debug.lua", "w") do |file|
file.write %(
while (true) do
emu.frameadvance();
#{print_statements}
end;
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment