1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-29 00:29:34 +00:00

Reformulate to allow addition of write tests, momentarily.

This commit is contained in:
Thomas Harte 2022-06-28 16:22:41 -04:00
parent 94fcc90886
commit ef322dc705

View File

@ -257,28 +257,31 @@ namespace {
_memoryMap.set_state_register(state); _memoryMap.set_state_register(state);
// Test results. // Test results.
for(NSArray<NSNumber *> *region in test[@"read"]) { auto testMemory =
const auto logicalStart = [region[0] intValue]; ^(NSString *type, void (^ applyTest)(int logical, int physical)) {
const auto logicalEnd = [region[1] intValue]; for(NSArray<NSNumber *> *region in test[type]) {
const auto physicalStart = [region[2] intValue]; const auto logicalStart = [region[0] intValue];
const auto physicalEnd = [region[3] intValue]; const auto logicalEnd = [region[1] intValue];
const auto physicalStart = [region[2] intValue];
const auto physicalEnd = [region[3] intValue];
if(physicalEnd == physicalStart && physicalStart == 0) { if(physicalEnd == physicalStart && physicalStart == 0) {
continue; continue;
} }
// Test read pointers. int physical = physicalStart;
int physical = physicalStart; for(int logical = logicalStart; logical < logicalEnd; logical++) {
for(int logical = logicalStart; logical < logicalEnd; logical++) { applyTest(logical, physical);
const auto &region = _memoryMap.regions[_memoryMap.region_map[logical]]; if(physical != physicalEnd) ++physical;
XCTAssert(region.read != nullptr); }
}
int foundPhysical = -1; };
const uint8_t *const read_ptr = &region.read[logical << 8];
auto physicalOffset =
^(const uint8_t *pointer) {
// Check for a mapping to RAM. // Check for a mapping to RAM.
if(read_ptr >= _ram.data() && read_ptr < &(*_ram.end())) { if(pointer >= self->_ram.data() && pointer < &(*self->_ram.end())) {
foundPhysical = int(&region.read[logical << 8] - _ram.data()) >> 8; int foundPhysical = int(pointer - self->_ram.data()) >> 8;
// This emulator maps a contiguous 8mb + 128kb of RAM such that the // This emulator maps a contiguous 8mb + 128kb of RAM such that the
// first 8mb resides up to physical location 0x8000, and the final // first 8mb resides up to physical location 0x8000, and the final
@ -286,30 +289,44 @@ namespace {
if(foundPhysical >= 0x8000) { if(foundPhysical >= 0x8000) {
foundPhysical += 0xe000 - 0x8000; foundPhysical += 0xe000 - 0x8000;
} }
return foundPhysical;
} }
// Check for a mapping to ROM. // Check for a mapping to ROM.
if(read_ptr >= _rom.data() && read_ptr < &(*_rom.end())) { if(pointer >= self->_rom.data() && pointer < &(*self->_rom.end())) {
// This emulator uses a separate store for ROM, which sholud appear in // This emulator uses a separate store for ROM, which sholud appear in
// the memory map from locatio 0xfc00. // the memory map from locatio 0xfc00.
foundPhysical = 0xfc00 + (int(&region.read[logical << 8] - _rom.data()) >> 8); return 0xfc00 + (int(pointer - self->_rom.data()) >> 8);
} }
// Compare to correct value. return -1;
XCTAssert(physical == foundPhysical, };
@"Logical page %04x should be mapped to physical %04x; is instead %04x",
logical,
physical,
foundPhysical);
if(physical != foundPhysical) { // Test read pointers.
NSLog(@"Stopping after first failure"); testMemory(@"read", ^(int logical, int physical) {
*stop = YES; const auto &region = self->_memoryMap.regions[self->_memoryMap.region_map[logical]];
return; XCTAssert(region.read != nullptr);
}
if(physical != physicalEnd) ++physical; // Don't worry about IO pages here; they'll be compared shortly.
if(region.flags & MemoryMap::Region::IsIO) {
return;
} }
}
const int foundPhysical = physicalOffset(&region.read[logical << 8]);
// Compare to correct value.
XCTAssert(physical == foundPhysical,
@"Logical page %04x should be mapped to physical %04x; is instead %04x",
logical,
physical,
foundPhysical);
if(physical != foundPhysical) {
NSLog(@"Stopping after first failure");
*stop = YES;
}
});
}]; }];
} }