1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-15 05:31:30 +00:00

Adds some very basic actual tests.

This commit is contained in:
Thomas Harte 2020-10-25 21:40:50 -04:00
parent ed510409c4
commit 82c733c68c
2 changed files with 41 additions and 8 deletions

View File

@ -228,12 +228,14 @@ class MemoryMap {
}; };
#define MemoryMapRegion(map, address) map.regions[map.region_map[address >> 8]] #define MemoryMapRegion(map, address) map.regions[map.region_map[address >> 8]]
#define MemoryMapRead(region, address, value) *value = region.read ? region.read[address] : 0xff; #define MemoryMapRead(region, address, value) *value = region.read ? region.read[address] : 0xff
#define MemoryMapWrite(map, region, address, value) \ #define MemoryMapWrite(map, region, address, value) \
region.write[address] = *value; \ if(region.write) { \
if(region.flags & (MemoryMap::Region::IsShadowed)) { \ region.write[address] = *value; \
const uint32_t shadowed_address = (address & 0xffff) + (uint32_t(0xe1 - (region.flags & MemoryMap::Region::IsShadowedE0)) << 16); \ if(region.flags & (MemoryMap::Region::IsShadowed)) { \
map.regions[map.region_map[shadowed_address >> 8]].write[shadowed_address] = *value; \ const uint32_t shadowed_address = (address & 0xffff) + (uint32_t(0xe1 - (region.flags & MemoryMap::Region::IsShadowedE0)) << 16); \
map.regions[map.region_map[shadowed_address >> 8]].write[shadowed_address] = *value; \
} \
} }
} }

View File

@ -10,11 +10,15 @@
#include "../../../Machines/Apple/AppleIIgs/MemoryMap.hpp" #include "../../../Machines/Apple/AppleIIgs/MemoryMap.hpp"
namespace {
using MemoryMap = Apple::IIgs::MemoryMap;
}
@interface IIgsMemoryMapTests : XCTestCase @interface IIgsMemoryMapTests : XCTestCase
@end @end
@implementation IIgsMemoryMapTests { @implementation IIgsMemoryMapTests {
Apple::IIgs::MemoryMap _memoryMap; MemoryMap _memoryMap;
std::vector<uint8_t> _ram; std::vector<uint8_t> _ram;
std::vector<uint8_t> _rom; std::vector<uint8_t> _rom;
} }
@ -25,10 +29,37 @@
_memoryMap.set_storage(_ram, _rom); _memoryMap.set_storage(_ram, _rom);
} }
- (void)testNothing { - (void)testHigherRAM {
// Fill memory via the map.
for(int address = 0x020000; address < 0x800000; ++address) {
const auto &region = MemoryMapRegion(_memoryMap, address);
const uint8_t value = uint8_t(address ^ (address >> 8));
MemoryMapWrite(_memoryMap, region, address, &value);
}
// Test by direct access.
for(int address = 0x020000; address < 0x800000; ++address) {
const uint8_t value = uint8_t(address ^ (address >> 8));
XCTAssertEqual(_ram[address], value);
}
} }
- (void)testSomeOtherNothing { - (void)testROMReadonly {
_rom[0] = 0xc0;
// Test that ROM can be read in the correct location.
const uint32_t address = 0xfc0000;
const auto &region = MemoryMapRegion(_memoryMap, address);
uint8_t value;
MemoryMapRead(region, address, &value);
XCTAssertEqual(value, 0xc0);
// Try writing to it, and check that nothing happened.
value = 0xfc;
MemoryMapWrite(_memoryMap, region, address, &value);
XCTAssertEqual(_rom[0], 0xc0);
} }
@end @end