diff --git a/champ.rb b/champ.rb index 2189aed..ee64881 100755 --- a/champ.rb +++ b/champ.rb @@ -63,6 +63,7 @@ class Champ @execution_log_size = 20 @code_for_pc = {} @source_for_file = {} + @pc_for_file_and_line = {} args = ARGV.dup while args.size > 1 item = args.shift @@ -788,25 +789,33 @@ class Champ # write error dump if @error io = StringIO.new - io.puts "
" - io.puts "

Error log

" + io.puts "
" + io.puts "

Source code

" io.puts "
"
                 source_code = @code_for_pc[@error[:pc]]
-                STDERR.puts source_code.to_yaml
                 offset = source_code[:line] - 1
                 this_filename = source_code[:file]
-                io.puts "#{sprintf('%-83s', this_filename)}"
+                io.puts " Line |   PC   | #{sprintf('%-75s', this_filename)}"
                 ((offset - 16)..(offset + 16)).each do |i|
                     next if i < 0 || i >= @source_for_file[this_filename].size
                     io.print ""
-                    io.print sprintf('%5d | %-75s', i + 1, @source_for_file[this_filename][i])
+                    line_pc = nil
+                    if @pc_for_file_and_line[this_filename]
+                        if @pc_for_file_and_line[this_filename][i]
+                            line_pc = sprintf('0x%04x', @pc_for_file_and_line[this_filename][i + 1])
+                        end
+                    end
+                    line_pc ||= ''
+                    io.print sprintf('%5d | %6s | %-75s', i + 1, line_pc, @source_for_file[this_filename][i])
                     io.print "" if i == offset
                     io.puts
                 end
                 io.puts "
" + io.puts "
" - io.puts "

Debug log

" + io.puts "
" + io.puts "

Execution log

" io.puts "
"
                 io.puts sprintf("   PC    |    A     X     Y     PC      SP  Flags ")
                 @execution_log.each do |item|
@@ -817,6 +826,8 @@ class Champ
                 
                 io.puts "
" + io.puts "
" + report.sub!('#{error}', io.string) else report.sub!('#{error}', '') @@ -843,6 +854,7 @@ class Champ @source_line = -3 File.open(path, 'r') do |f| f.each_line do |line| + @pc_for_file_and_line[input_file] ||= {} @source_line += 1 parts = line.split('|') next unless parts.size > 2 @@ -855,15 +867,13 @@ class Champ code_parts = code.split(/\s+/) line_number = parts[1].split(' ').map { |x| x.strip }.reject { |x| x.empty? }.last.to_i -# unless (@pc_code_lines.last || 0) == pc - STDERR.puts line_number - @code_for_pc[pc] = { - :file => input_file, - :line => line_number, - } -# @pc_code_lines << pc -# end + @code_for_pc[pc] = { + :file => input_file, + :line => line_number, + } + @pc_for_file_and_line[input_file][line_number] = pc + next if code_parts.empty? label = nil