mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-18 17:06:15 +00:00
Cleans up test and makes attempt to factor in cartridge type popularity.
This commit is contained in:
parent
344a12566b
commit
c8367a017f
@ -199,12 +199,8 @@ static NSDictionary<NSString *, MSXROMRecord *> *romRecordsBySHA1 = @{
|
|||||||
@implementation MSXStaticAnalyserTests
|
@implementation MSXStaticAnalyserTests
|
||||||
|
|
||||||
- (void)testROMs {
|
- (void)testROMs {
|
||||||
int errorBuckets[6] = {0, 0, 0, 0, 0, 0};
|
|
||||||
NSString *basePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"MSX ROMs"];
|
NSString *basePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"MSX ROMs"];
|
||||||
for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) {
|
for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) {
|
||||||
if([testFile rangeOfString:@"Animal Land"].location != NSNotFound) {
|
|
||||||
NSLog(@"");
|
|
||||||
}
|
|
||||||
NSString *fullPath = [basePath stringByAppendingPathComponent:testFile];
|
NSString *fullPath = [basePath stringByAppendingPathComponent:testFile];
|
||||||
|
|
||||||
// get a SHA1 for the file
|
// get a SHA1 for the file
|
||||||
@ -222,23 +218,13 @@ static NSDictionary<NSString *, MSXROMRecord *> *romRecordsBySHA1 = @{
|
|||||||
if(!romRecord) {
|
if(!romRecord) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(romRecord.cartridgeType != StaticAnalyser::MSXCartridgeType::Konami) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assert equality
|
// 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()) {
|
if(!targets.empty()) {
|
||||||
XCTAssert(targets.front().msx.paging_model == romRecord.cartridgeType, @"%@; should be %d, is %d", testFile, romRecord.cartridgeType, targets.front().msx.paging_model);
|
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
|
@end
|
||||||
|
@ -60,11 +60,11 @@ static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
|||||||
// If this ROM is greater than 48kb in size then some sort of MegaROM scheme must
|
// 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.
|
// be at play; disassemble to try to figure it out.
|
||||||
if(data_size > 0xc000) {
|
if(data_size > 0xc000) {
|
||||||
std::vector<uint8_t> first_segment;
|
std::vector<uint8_t> first_8k;
|
||||||
first_segment.insert(first_segment.begin(), segment.data.begin(), segment.data.begin() + 32768);
|
first_8k.insert(first_8k.begin(), segment.data.begin(), segment.data.begin() + 8192);
|
||||||
StaticAnalyser::Z80::Disassembly disassembly =
|
StaticAnalyser::Z80::Disassembly disassembly =
|
||||||
StaticAnalyser::Z80::Disassemble(
|
StaticAnalyser::Z80::Disassemble(
|
||||||
first_segment,
|
first_8k,
|
||||||
StaticAnalyser::Disassembler::OffsetMapper(start_address),
|
StaticAnalyser::Disassembler::OffsetMapper(start_address),
|
||||||
{ init_address }
|
{ init_address }
|
||||||
);
|
);
|
||||||
@ -83,12 +83,15 @@ static std::list<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
|||||||
// Sort possible cartridge types.
|
// Sort possible cartridge types.
|
||||||
using Possibility = std::pair<StaticAnalyser::MSXCartridgeType, int>;
|
using Possibility = std::pair<StaticAnalyser::MSXCartridgeType, int>;
|
||||||
std::vector<Possibility> possibilities;
|
std::vector<Possibility> 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::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::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]));
|
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) {
|
std::stable_sort(possibilities.begin(), possibilities.end(), [](const Possibility &a, const Possibility &b) {
|
||||||
return a.second > b.second;
|
if(a.second != b.second) return a.second > b.second;
|
||||||
|
return a.first > b.first;
|
||||||
});
|
});
|
||||||
|
|
||||||
target.msx.paging_model = possibilities[0].first;
|
target.msx.paging_model = possibilities[0].first;
|
||||||
|
Loading…
Reference in New Issue
Block a user