From 50f4dad58c1fef1a9087a9a80038efdf96a5d2b7 Mon Sep 17 00:00:00 2001 From: Michael Specht Date: Mon, 12 Feb 2018 21:15:03 +0100 Subject: [PATCH] yay --- champ.c | 38 +++++++++++++++++++++++++++++++++++--- parse.rb | 29 +++++++++++++++++++++++++++++ parse_watches.rb | 19 ++++++++++++++----- watches.h | 22 ++++++++++++++++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/champ.c b/champ.c index 038c04d..72d6780 100644 --- a/champ.c +++ b/champ.c @@ -171,6 +171,7 @@ uint16_t read16(uint16_t address) void refresh_watches(uint16_t address) { + // refresh global variable watches after write at address for (int i = 0; i < WATCH_COUNT; i++) { if ((WATCH_ADDRESSES[i] == address) || @@ -193,7 +194,7 @@ void refresh_watches(uint16_t address) value = (int16_t)read16(WATCH_ADDRESSES[i]); break; } - fprintf(watches_file, "0x%04x %s %d\n", cpu.ip, WATCH_LABELS[i], value); + fprintf(watches_file, "~ 0x%04x %s %d\n", cpu.ip, WATCH_LABELS[i], value); } } } @@ -1144,8 +1145,39 @@ int main(int argc, char** argv) uint32_t next_display_refresh = 0; uint8_t old_screen_number = 0; while (1) { -// if (cpu.ip >= 0xf5b2) -// printf("*** "); + if (watches_file) + { + // handle register watches for certain IP locations + uint8_t printed_reg_watches = 0; + for (int i = 0; i < ARG_WATCH_COUNT; i++) + { + if (cpu.ip == ARG_WATCH_ADDRESSES[i]) + { + int32_t value = 0; + uint8_t reg = 0; + if (ARG_WATCH_REGISTERS[i] == WATCH_A) + reg = cpu.a; + else if (ARG_WATCH_REGISTERS[i] == WATCH_X) + reg = cpu.x; + else if (ARG_WATCH_REGISTERS[i] == WATCH_Y) + reg = cpu.y; + if (ARG_WATCH_TYPES[i] == WATCH_S8) + value = (int8_t)reg; + else + value = (uint8_t)reg; + if (!printed_reg_watches) + fprintf(watches_file, "@ 0x%04x ", cpu.ip); + else + fprintf(watches_file, ", "); + fprintf(watches_file, "%s %d", + WATCH_REGISTER_LABELS[ARG_WATCH_REGISTERS[i]], + value); + printed_reg_watches = 1; + } + } + if (printed_reg_watches) + fprintf(watches_file, "\n"); + } handle_next_opcode(); if ((start_frame_pc != 0xffff) && (cpu.ip == start_frame_pc)) { diff --git a/parse.rb b/parse.rb index 62619b9..0ac810a 100755 --- a/parse.rb +++ b/parse.rb @@ -1,8 +1,11 @@ #!/usr/bin/env ruby +require 'yaml' + label_for_address = {} symbols = [] watches = [] +arg_watches = [] File::open('plot3d20_Output.txt') do |f| f.each_line do |line| @@ -18,6 +21,7 @@ File::open('plot3d20_Output.txt') do |f| address = $1 end watch_this = symbol.match(/~(u8|s8|u16|s16)/) + watch_args = symbol.scan(/(@(u8|s8|u16|s16)[AXY])/).map { |x| x.first } symbol = symbol.strip.split(' ').first next if address.nil? label_for_address[address.to_i(16)] = symbol @@ -29,6 +33,11 @@ File::open('plot3d20_Output.txt') do |f| :type => watch_this[1] } end + watch_args.each do |watch_arg| + arg_watches << {:register => watch_arg[watch_arg.size - 1], + :type => watch_arg.sub('@', '')[0, watch_arg.size - 2], + :address => address.to_i(16)} + end end end @@ -86,6 +95,26 @@ File::open('watches.h', 'w') do |f| f.puts "const uint8_t WATCH_TYPES[] = {"; f.puts watches.map { |x| " #{types.index(x[:type]) + 1}" }.join(",\n"); f.puts "};" + + f.puts "const uint16_t ARG_WATCH_COUNT = #{arg_watches.size};" + types = ['u8', 'u16', 's8', 's16']; + f.puts "const uint16_t ARG_WATCH_ADDRESSES[] = {"; + f.puts arg_watches.map { |x| " #{sprintf('0x%04x', x[:address])}" }.join(",\n"); + f.puts "};" + f.puts "const uint8_t ARG_WATCH_TYPES[] = {"; + f.puts arg_watches.map { |x| " #{types.index(x[:type]) + 1}" }.join(",\n"); + f.puts "};" + registers = ['A', 'X', 'Y'] + registers.each.with_index do |x, _| + f.puts "#define WATCH_#{x} #{_ + 1}" + end + f.puts "const uint8_t ARG_WATCH_REGISTERS[] = {"; + f.puts arg_watches.map { |x| " #{registers.index(x[:register]) + 1}" }.join(",\n"); + f.puts "};" + f.puts "const char* WATCH_REGISTER_LABELS[] = {"; + f.puts " \"\"," + f.puts registers.map { |x| " \"#{x}\"" }.join(",\n"); + f.puts "};" end puts "Found #{symbols.size} labels and #{watches.size} watches." diff --git a/parse_watches.rb b/parse_watches.rb index 54f0872..7ad3315 100755 --- a/parse_watches.rb +++ b/parse_watches.rb @@ -4,11 +4,20 @@ vars = {} File::open(ARGV.first) do |f| f.each_line do |line| - parts = line.split(' ') - name = parts[1] - value = parts[2].to_i - vars[name] ||= [] - vars[name] << value + if line[0] == '~' + parts = line.split(' ') + name = parts[2] + value = parts[3].to_i + vars[name] ||= [] + vars[name] << value + elsif line[0] == '@' + address = line.split(' ')[1].sub('0x', '').to_i(16) + rest = line[line.index(' ', 2), line.size].strip + rest.split(',').each do |part| + part.strip! +# puts part + end + end end end diff --git a/watches.h b/watches.h index 1028a66..9942f6a 100644 --- a/watches.h +++ b/watches.h @@ -36,3 +36,25 @@ const uint8_t WATCH_TYPES[] = { 4, 4 }; +const uint16_t ARG_WATCH_COUNT = 2; +const uint16_t ARG_WATCH_ADDRESSES[] = { + 0x7c92, + 0x7c92 +}; +const uint8_t ARG_WATCH_TYPES[] = { + 3, + 3 +}; +#define WATCH_A 1 +#define WATCH_X 2 +#define WATCH_Y 3 +const uint8_t ARG_WATCH_REGISTERS[] = { + 3, + 1 +}; +const char* WATCH_REGISTER_LABELS[] = { + "", + "A", + "X", + "Y" +};