From 8fb4409ebb2b88ca52af23402c50a2e5188466e9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 22 Jan 2018 21:50:56 -0500 Subject: [PATCH] Adds hasty attempt at dynamic analysis to the MSX ROM handlers. Logging for now, for further experimentation. --- Machines/MSX/Cartridges/ASCII16kb.hpp | 6 +++++- Machines/MSX/Cartridges/ASCII8kb.hpp | 8 +++++++- Machines/MSX/Cartridges/Konami.hpp | 7 ++++++- Machines/MSX/Cartridges/KonamiWithSCC.hpp | 17 +++++++++++++++-- Machines/MSX/MSX.cpp | 4 ++++ Machines/MSX/ROMSlotHandler.hpp | 14 +++++++++++--- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Machines/MSX/Cartridges/ASCII16kb.hpp b/Machines/MSX/Cartridges/ASCII16kb.hpp index 37aa6a70b..cc2175423 100644 --- a/Machines/MSX/Cartridges/ASCII16kb.hpp +++ b/Machines/MSX/Cartridges/ASCII16kb.hpp @@ -21,11 +21,15 @@ class ASCII16kbROMSlotHandler: public ROMSlotHandler { void write(uint16_t address, uint8_t value) { switch(address >> 11) { - default: break; + default: + confidence_counter_.add_miss(); + break; case 0xc: + if(address == 0x6000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x4000, 0x4000); break; case 0xe: + if(address == 0x7000 || address == 0x77ff) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x8000, 0x4000); break; } diff --git a/Machines/MSX/Cartridges/ASCII8kb.hpp b/Machines/MSX/Cartridges/ASCII8kb.hpp index ab5c515e2..dfc76f4ab 100644 --- a/Machines/MSX/Cartridges/ASCII8kb.hpp +++ b/Machines/MSX/Cartridges/ASCII8kb.hpp @@ -21,17 +21,23 @@ class ASCII8kbROMSlotHandler: public ROMSlotHandler { void write(uint16_t address, uint8_t value) { switch(address >> 11) { - default: break; + default: + confidence_counter_.add_miss(); + break; case 0xc: + if(address == 0x6000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x4000, 0x2000); break; case 0xd: + if(address == 0x6800) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x6000, 0x2000); break; case 0xe: + if(address == 0x7000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x8000, 0x2000); break; case 0xf: + if(address == 0x7800) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0xa000, 0x2000); break; } diff --git a/Machines/MSX/Cartridges/Konami.hpp b/Machines/MSX/Cartridges/Konami.hpp index 296f00a97..1fff998ae 100644 --- a/Machines/MSX/Cartridges/Konami.hpp +++ b/Machines/MSX/Cartridges/Konami.hpp @@ -21,14 +21,19 @@ class KonamiROMSlotHandler: public ROMSlotHandler { void write(uint16_t address, uint8_t value) { switch(address >> 13) { - default: break; + default: + confidence_counter_.add_miss(); + break; case 3: + if(address == 0x6000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x6000, 0x2000); break; case 4: + if(address == 0x8000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x8000, 0x2000); break; case 5: + if(address == 0xa000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0xa000, 0x2000); break; } diff --git a/Machines/MSX/Cartridges/KonamiWithSCC.hpp b/Machines/MSX/Cartridges/KonamiWithSCC.hpp index d640b4d70..6133b5f12 100644 --- a/Machines/MSX/Cartridges/KonamiWithSCC.hpp +++ b/Machines/MSX/Cartridges/KonamiWithSCC.hpp @@ -22,14 +22,19 @@ class KonamiWithSCCROMSlotHandler: public ROMSlotHandler { void write(uint16_t address, uint8_t value) override { switch(address >> 11) { - default: break; + default: + confidence_counter_.add_miss(); + break; case 0x0a: + if(address == 0x5000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x4000, 0x2000); break; case 0x0e: + if(address == 0x7000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0x6000, 0x2000); break; case 0x12: + if(address == 0x9000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); if((value&0x3f) == 0x3f) { scc_is_visible_ = true; map_.unmap(slot_, 0x8000, 0x2000); @@ -39,9 +44,15 @@ class KonamiWithSCCROMSlotHandler: public ROMSlotHandler { } break; case 0x13: - if(scc_is_visible_) scc_.write(address, value); + if(scc_is_visible_) { + confidence_counter_.add_hit(); + scc_.write(address, value); + } else { + confidence_counter_.add_miss(); + } break; case 0x16: + if(address == 0xb000) confidence_counter_.add_hit(); else confidence_counter_.add_equivocal(); map_.map(slot_, value * 8192, 0xa000, 0x2000); break; } @@ -49,8 +60,10 @@ class KonamiWithSCCROMSlotHandler: public ROMSlotHandler { uint8_t read(uint16_t address) override { if(scc_is_visible_ && address >= 0x9800 && address < 0xa000) { + confidence_counter_.add_hit(); return scc_.read(address); } + confidence_counter_.add_miss(); return 0xff; } diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index ccdbb52f9..ed926a5f0 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -154,6 +154,10 @@ class ConcreteMachine: void run_for(const Cycles cycles) override { z80_.run_for(cycles); + + if(memory_slots_[1].handler) { + printf("%0.2f\n", memory_slots_[1].handler->get_confidence()); + } } void configure_as_target(const StaticAnalyser::Target &target) override { diff --git a/Machines/MSX/ROMSlotHandler.hpp b/Machines/MSX/ROMSlotHandler.hpp index 857d1a6aa..ba62db932 100644 --- a/Machines/MSX/ROMSlotHandler.hpp +++ b/Machines/MSX/ROMSlotHandler.hpp @@ -10,6 +10,7 @@ #define ROMSlotHandler_hpp #include "../../ClockReceiver/ClockReceiver.hpp" +#include "../../DynamicAnalyser/ConfidenceCounter.hpp" #include #include @@ -57,12 +58,19 @@ class ROMSlotHandler { /// Empty causes all out-of-bounds accesses to read a vacant bus. Empty }; - /*! - Returns the wrapping strategy to apply to mapping requests from this ROM slot. - */ + + /*! @returns The wrapping strategy to apply to mapping requests from this ROM slot. */ virtual WrappingStrategy wrapping_strategy() const { return WrappingStrategy::Repeat; } + + /*! @returns The probability that this handler is correct for the data it owns. */ + float get_confidence() { + return confidence_counter_.get_probability(); + } + + protected: + DynamicAnalyser::ConfidenceCounter confidence_counter_; }; }