diff --git a/OSBindings/Mac/Clock SignalTests/MSXStaticAnalyserTests.mm b/OSBindings/Mac/Clock SignalTests/MSXStaticAnalyserTests.mm index 2d0fe3c77..2e31fcfb2 100644 --- a/OSBindings/Mac/Clock SignalTests/MSXStaticAnalyserTests.mm +++ b/OSBindings/Mac/Clock SignalTests/MSXStaticAnalyserTests.mm @@ -199,12 +199,8 @@ static NSDictionary *romRecordsBySHA1 = @{ @implementation MSXStaticAnalyserTests - (void)testROMs { - int errorBuckets[6] = {0, 0, 0, 0, 0, 0}; NSString *basePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"MSX ROMs"]; for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) { - if([testFile rangeOfString:@"Animal Land"].location != NSNotFound) { - NSLog(@""); - } NSString *fullPath = [basePath stringByAppendingPathComponent:testFile]; // get a SHA1 for the file @@ -222,23 +218,13 @@ static NSDictionary *romRecordsBySHA1 = @{ if(!romRecord) { continue; } - if(romRecord.cartridgeType != StaticAnalyser::MSXCartridgeType::Konami) { - continue; - } // assert equality - XCTAssert(!targets.empty(), "%@ should be recognised as an MSX file"); + XCTAssert(!targets.empty(), "%@ should be recognised as an MSX file", testFile); if(!targets.empty()) { XCTAssert(targets.front().msx.paging_model == romRecord.cartridgeType, @"%@; should be %d, is %d", testFile, romRecord.cartridgeType, targets.front().msx.paging_model); - if(targets.front().msx.paging_model != romRecord.cartridgeType) { - errorBuckets[(int)romRecord.cartridgeType]++; - } } } - - for(int c = 0; c < 6; ++c) { - if(errorBuckets[c]) NSLog(@"%d errors for %d", errorBuckets[c], c); - } } @end diff --git a/StaticAnalyser/MSX/StaticAnalyser.cpp b/StaticAnalyser/MSX/StaticAnalyser.cpp index 22b39de94..97e0b2aae 100644 --- a/StaticAnalyser/MSX/StaticAnalyser.cpp +++ b/StaticAnalyser/MSX/StaticAnalyser.cpp @@ -60,11 +60,11 @@ static std::list> // If this ROM is greater than 48kb in size then some sort of MegaROM scheme must // be at play; disassemble to try to figure it out. if(data_size > 0xc000) { - std::vector first_segment; - first_segment.insert(first_segment.begin(), segment.data.begin(), segment.data.begin() + 32768); + std::vector first_8k; + first_8k.insert(first_8k.begin(), segment.data.begin(), segment.data.begin() + 8192); StaticAnalyser::Z80::Disassembly disassembly = StaticAnalyser::Z80::Disassemble( - first_segment, + first_8k, StaticAnalyser::Disassembler::OffsetMapper(start_address), { init_address } ); @@ -83,12 +83,15 @@ static std::list> // Sort possible cartridge types. using Possibility = std::pair; std::vector possibilities; + // Add to list in order of declining probability, so that stable_sort below prefers the more likely option + // in a tie. + possibilities.push_back(std::make_pair(StaticAnalyser::MSXCartridgeType::ASCII8kb, address_counts[0x6000] + address_counts[0x6800] + address_counts[0x7000] + address_counts[0x7800])); possibilities.push_back(std::make_pair(StaticAnalyser::MSXCartridgeType::Konami, address_counts[0x6000] + address_counts[0x8000] + address_counts[0xa000])); possibilities.push_back(std::make_pair(StaticAnalyser::MSXCartridgeType::KonamiWithSCC, address_counts[0x5000] + address_counts[0x7000] + address_counts[0x9000] + address_counts[0xb000])); - possibilities.push_back(std::make_pair(StaticAnalyser::MSXCartridgeType::ASCII8kb, address_counts[0x6000] + address_counts[0x6800] + address_counts[0x7000] + address_counts[0x7800])); possibilities.push_back(std::make_pair(StaticAnalyser::MSXCartridgeType::ASCII16kb, address_counts[0x6000] + address_counts[0x7000] + address_counts[0x77ff])); - std::sort(possibilities.begin(), possibilities.end(), [](const Possibility &a, const Possibility &b) { - return a.second > b.second; + std::stable_sort(possibilities.begin(), possibilities.end(), [](const Possibility &a, const Possibility &b) { + if(a.second != b.second) return a.second > b.second; + return a.first > b.first; }); target.msx.paging_model = possibilities[0].first;