mirror of
https://github.com/specht/champ.git
synced 2024-12-22 03:30:47 +00:00
watches
This commit is contained in:
parent
cd07c0120a
commit
f2071473b7
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
champ: champ.c labels.h
|
champ: champ.c labels.h watches.h
|
||||||
gcc -o champ champ.c -lX11
|
gcc -o champ champ.c -lX11
|
||||||
|
|
||||||
labels.h: parse.rb plot3d20_Output.txt
|
labels.h: parse.rb plot3d20_Output.txt
|
||||||
|
50
champ.c
50
champ.c
@ -4,7 +4,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "labels.h"
|
#include "labels.h"
|
||||||
|
#include "watches.h"
|
||||||
|
|
||||||
#define SCALE 4
|
#define SCALE 4
|
||||||
#define SCREEN_WIDTH 280
|
#define SCREEN_WIDTH 280
|
||||||
@ -43,6 +45,7 @@ uint64_t frame_count = 0;
|
|||||||
uint16_t start_pc = 0x6000;
|
uint16_t start_pc = 0x6000;
|
||||||
uint16_t start_frame_pc = 0xffff;
|
uint16_t start_frame_pc = 0xffff;
|
||||||
uint64_t max_frames = 0;
|
uint64_t max_frames = 0;
|
||||||
|
FILE *watches_file = 0;
|
||||||
|
|
||||||
int init_display()
|
int init_display()
|
||||||
{
|
{
|
||||||
@ -166,15 +169,48 @@ uint16_t read16(uint16_t address)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh_watches(uint16_t address)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < WATCH_COUNT; i++)
|
||||||
|
{
|
||||||
|
if ((WATCH_ADDRESSES[i] == address) ||
|
||||||
|
((WATCH_TYPES[i] == WATCH_U16 || WATCH_TYPES[i] == WATCH_S16) &&
|
||||||
|
(WATCH_ADDRESSES[i] == address + 1)))
|
||||||
|
{
|
||||||
|
int32_t value = 0;
|
||||||
|
switch (WATCH_TYPES[i])
|
||||||
|
{
|
||||||
|
case WATCH_U8:
|
||||||
|
value = (uint8_t)ram[address];
|
||||||
|
break;
|
||||||
|
case WATCH_S8:
|
||||||
|
value = (int8_t)ram[address];
|
||||||
|
break;
|
||||||
|
case WATCH_U16:
|
||||||
|
value = (uint16_t)ram[address];
|
||||||
|
break;
|
||||||
|
case WATCH_S16:
|
||||||
|
value = (int16_t)ram[address];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(watches_file, "0x%04x %s %d\n", cpu.ip, WATCH_LABELS[i], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void write8(uint16_t address, uint8_t value)
|
void write8(uint16_t address, uint8_t value)
|
||||||
{
|
{
|
||||||
ram[address] = value;
|
ram[address] = value;
|
||||||
|
if (watches_file)
|
||||||
|
refresh_watches(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write16(uint16_t address, uint16_t value)
|
void write16(uint16_t address, uint16_t value)
|
||||||
{
|
{
|
||||||
ram[address] = value & 0xff;
|
ram[address] = value & 0xff;
|
||||||
ram[address + 1] = (value >> 8) & 0xff;
|
ram[address + 1] = (value >> 8) & 0xff;
|
||||||
|
if (watches_file)
|
||||||
|
refresh_watches(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(uint8_t value)
|
void push(uint8_t value)
|
||||||
@ -1045,6 +1081,7 @@ int main(int argc, char** argv)
|
|||||||
printf(" --start-pc <address or label>\n");
|
printf(" --start-pc <address or label>\n");
|
||||||
printf(" --frame-start <address or label>\n");
|
printf(" --frame-start <address or label>\n");
|
||||||
printf(" --max-frames <n>\n");
|
printf(" --max-frames <n>\n");
|
||||||
|
printf(" --watches <output filename>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1081,6 +1118,17 @@ int main(int argc, char** argv)
|
|||||||
max_frames = find_address_for_label(temp);
|
max_frames = find_address_for_label(temp);
|
||||||
fprintf(stderr, "Max frames: %d\n", max_frames);
|
fprintf(stderr, "Max frames: %d\n", max_frames);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(argv[i], "--watches") == 0)
|
||||||
|
{
|
||||||
|
const char* filename = argv[++i];
|
||||||
|
if (access(filename, F_OK) != -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Watch output file exists: %s, exiting...\n", filename);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
watches_file = fopen(filename, "w");
|
||||||
|
fprintf(stderr, "Writing watches to %s.\n", filename);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
|
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
|
||||||
@ -1178,5 +1226,7 @@ int main(int argc, char** argv)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (watches_file)
|
||||||
|
fclose(watches_file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
30
parse.rb
30
parse.rb
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
label_for_address = {}
|
label_for_address = {}
|
||||||
symbols = []
|
symbols = []
|
||||||
|
watches = []
|
||||||
|
|
||||||
File::open('plot3d20_Output.txt') do |f|
|
File::open('plot3d20_Output.txt') do |f|
|
||||||
f.each_line do |line|
|
f.each_line do |line|
|
||||||
@ -13,13 +14,21 @@ File::open('plot3d20_Output.txt') do |f|
|
|||||||
next if symbol[0] == '*'
|
next if symbol[0] == '*'
|
||||||
next if symbol[0] == ';'
|
next if symbol[0] == ';'
|
||||||
next if symbol[0] == ' '
|
next if symbol[0] == ' '
|
||||||
if symbol =~ /^\w+\s+EQU\s+\$([0-9A-F]{4})/
|
if symbol =~ /^\w+\s+EQU\s+\$([0-9A-F]{2,4})/
|
||||||
address = $1
|
address = $1
|
||||||
end
|
end
|
||||||
|
watch_this = symbol.match(/~(u8|s8|u16|s16)/)
|
||||||
symbol = symbol.strip.split(' ').first
|
symbol = symbol.strip.split(' ').first
|
||||||
next if address.nil?
|
next if address.nil?
|
||||||
label_for_address[address.to_i(16)] = symbol
|
label_for_address[address.to_i(16)] = symbol
|
||||||
symbols << symbol
|
symbols << symbol
|
||||||
|
if watch_this
|
||||||
|
watches << {
|
||||||
|
:address => address.to_i(16),
|
||||||
|
:label => symbol,
|
||||||
|
:type => watch_this[1]
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -62,7 +71,24 @@ File::open('labels.h', 'w') do |f|
|
|||||||
f.puts "};";
|
f.puts "};";
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Found #{symbols.size} labels."
|
File::open('watches.h', 'w') do |f|
|
||||||
|
f.puts "const uint16_t WATCH_COUNT = #{watches.size};"
|
||||||
|
types = ['u8', 'u16', 's8', 's16'];
|
||||||
|
types.each.with_index do |x, _|
|
||||||
|
f.puts "#define WATCH_#{x.upcase} #{_ + 1}"
|
||||||
|
end
|
||||||
|
f.puts "const char* WATCH_LABELS[] = {";
|
||||||
|
f.puts watches.map { |x| " \"#{x[:label]}\"" }.join(",\n");
|
||||||
|
f.puts "};"
|
||||||
|
f.puts "const uint16_t WATCH_ADDRESSES[] = {";
|
||||||
|
f.puts watches.map { |x| " #{sprintf('0x%04x', x[:address])}" }.join(",\n");
|
||||||
|
f.puts "};"
|
||||||
|
f.puts "const uint8_t WATCH_TYPES[] = {";
|
||||||
|
f.puts watches.map { |x| " #{types.index(x[:type]) + 1}" }.join(",\n");
|
||||||
|
f.puts "};"
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Found #{symbols.size} labels and #{watches.size} watches."
|
||||||
|
|
||||||
# label_for_address.keys.sort.each do |address|
|
# label_for_address.keys.sort.each do |address|
|
||||||
# puts sprintf("%04x %s", address, label_for_address[address])
|
# puts sprintf("%04x %s", address, label_for_address[address])
|
||||||
|
20
watches.h
Normal file
20
watches.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const uint16_t WATCH_COUNT = 3;
|
||||||
|
#define WATCH_U8 1
|
||||||
|
#define WATCH_U16 2
|
||||||
|
#define WATCH_S8 3
|
||||||
|
#define WATCH_S16 4
|
||||||
|
const char* WATCH_LABELS[] = {
|
||||||
|
"RX",
|
||||||
|
"RY",
|
||||||
|
"RZ"
|
||||||
|
};
|
||||||
|
const uint16_t WATCH_ADDRESSES[] = {
|
||||||
|
0x008d,
|
||||||
|
0x008f,
|
||||||
|
0x0091
|
||||||
|
};
|
||||||
|
const uint8_t WATCH_TYPES[] = {
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
4
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user