Make Z80 profile output conditional on the availability of data.

This commit is contained in:
Adrian Conlon 2021-12-30 12:32:34 +00:00
parent 3b01c639fd
commit 91df9ea48b
2 changed files with 36 additions and 11 deletions

View File

@ -24,6 +24,27 @@ namespace EightBit {
Z80& m_cpu;
Disassembler& m_disassembler;
[[nodiscard]] constexpr const auto& instructions() const { return m_instructions; }
[[nodiscard]] constexpr const auto& addresses() const { return m_addresses; }
[[nodiscard]] constexpr auto instructions_available() const noexcept {
const auto found = std::find_if(
instructions().begin(), instructions().end(),
[](const auto& value) { return value != 0; });
return found != instructions().end();
}
[[nodiscard]] constexpr auto addresses_available() const noexcept {
const auto found = std::find_if(
addresses().begin(), addresses().end(),
[](const auto& value) { return value != 0; });
return found != addresses().end();
}
[[nodiscard]] constexpr auto available() const noexcept {
return instructions_available() || addresses_available();
}
void dumpInstructionProfiles() const;
void dumpAddressProfiles() const;
};

View File

@ -27,28 +27,32 @@ void EightBit::Profiler::dump() const {
}
void EightBit::Profiler::dumpInstructionProfiles() const {
std::cout << "** instructions" << std::endl;
for (int i = 0; i < 0x100; ++i) {
auto count = m_instructions[i];
if (count > 0)
std::cout << Disassembler::hex((uint8_t)i) << "\t" << count << std::endl;
if (instructions_available()) {
std::cout << "** instructions" << std::endl;
for (int i = 0; i < 0x100; ++i) {
auto count = m_instructions[i];
if (count > 0)
std::cout << Disassembler::hex((uint8_t)i) << "\t" << count << std::endl;
}
}
}
void EightBit::Profiler::dumpAddressProfiles() const {
std::cout << "** addresses" << std::endl;
for (int i = 0; i < 0x10000; ++i) {
auto count = m_addresses[i];
if (addresses_available()) {
std::cout << "** addresses" << std::endl;
for (int i = 0; i < 0x10000; ++i) {
auto count = m_addresses[i];
m_cpu.PC().word = i;
m_cpu.PC().word = i;
if (count > 0)
std::cout
if (count > 0)
std::cout
<< Disassembler::hex((uint16_t)i)
<< "\t"
<< count
<< "\t"
<< m_disassembler.disassemble(m_cpu)
<< std::endl;
}
}
}