From 5adc656066b6efb9f877dff20072840bbf8757b9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 25 Jun 2022 21:41:37 -0400 Subject: [PATCH] Make some attempt to use the JSON tests. --- .../Clock Signal.xcodeproj/project.pbxproj | 4 ++ .../Clock SignalTests/IIgsMemoryMapTests.mm | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 1744ac269..65b123b00 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -946,6 +946,7 @@ 4BBB70A5202011C2002FE009 /* MultiMediaTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBB70A3202011C2002FE009 /* MultiMediaTarget.cpp */; }; 4BBB70A8202014E2002FE009 /* MultiProducer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBB70A6202014E2002FE009 /* MultiProducer.cpp */; }; 4BBB70A9202014E2002FE009 /* MultiProducer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBB70A6202014E2002FE009 /* MultiProducer.cpp */; }; + 4BBB77DD2867EBB300D335A1 /* IIgs Memory Map in Resources */ = {isa = PBXBuildFile; fileRef = 4BBB77DC2867EBB300D335A1 /* IIgs Memory Map */; }; 4BBC951E1F368D83008F4C34 /* i8272.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBC951C1F368D83008F4C34 /* i8272.cpp */; }; 4BBF49AF1ED2880200AB3669 /* FUSETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BBF49AE1ED2880200AB3669 /* FUSETests.swift */; }; 4BBFBB6C1EE8401E00C01E7A /* ZX8081.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BBFBB6A1EE8401E00C01E7A /* ZX8081.cpp */; }; @@ -2009,6 +2010,7 @@ 4BBB70A3202011C2002FE009 /* MultiMediaTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MultiMediaTarget.cpp; sourceTree = ""; }; 4BBB70A6202014E2002FE009 /* MultiProducer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MultiProducer.cpp; sourceTree = ""; }; 4BBB70A7202014E2002FE009 /* MultiProducer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = MultiProducer.hpp; sourceTree = ""; }; + 4BBB77DC2867EBB300D335A1 /* IIgs Memory Map */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "IIgs Memory Map"; sourceTree = ""; }; 4BBC951C1F368D83008F4C34 /* i8272.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = i8272.cpp; sourceTree = ""; }; 4BBC951D1F368D83008F4C34 /* i8272.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = i8272.hpp; sourceTree = ""; }; 4BBF49AE1ED2880200AB3669 /* FUSETests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FUSETests.swift; sourceTree = ""; }; @@ -2462,6 +2464,7 @@ 4B1414631B588A1100E04248 /* Test Binaries */ = { isa = PBXGroup; children = ( + 4BBB77DC2867EBB300D335A1 /* IIgs Memory Map */, 4B7C7A06282C3DED002D6C0B /* flamewing 68000 BCD tests */, 4B680CE323A555CA00451D43 /* 68000 Comparative Tests */, 4B75F97A280D7C7700121055 /* 68000 Decoding */, @@ -5401,6 +5404,7 @@ 4B8DF62F2550D91600F3433C /* CPUCMP-trace_compare.log in Resources */, 4B8DF6412550D91600F3433C /* CPUROR.sfc in Resources */, 4BB299691B587D8400A49093 /* irq in Resources */, + 4BBB77DD2867EBB300D335A1 /* IIgs Memory Map in Resources */, 4B8DF6962550D91700F3433C /* CPUJMP.sfc in Resources */, 4BB299851B587D8400A49093 /* ldyzx in Resources */, 4BB299F31B587D8400A49093 /* trap7 in Resources */, diff --git a/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm b/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm index 9daac89fc..c0fcc2058 100644 --- a/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm +++ b/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm @@ -228,4 +228,62 @@ namespace { } } +- (void)testJSONExamples { + NSArray *const tests = + [NSJSONSerialization JSONObjectWithData: + [NSData dataWithContentsOfURL: + [[NSBundle bundleForClass:[self class]] + URLForResource:@"mm" + withExtension:@"json" + subdirectory:@"IIgs Memory Map"]] + options:0 + error:nil]; + + int testNumber = 1; + for(NSDictionary *test in tests) { + NSLog(@"Test %d", testNumber); + ++testNumber; + + // Apply state. + const bool highRes = [test[@"hires"] boolValue]; + const bool lcw = [test[@"lcw"] boolValue]; + const bool store80 = [test[@"80store"] boolValue]; + const uint8_t shadow = [test[@"shadow"] integerValue]; + const uint8_t state = [test[@"state"] integerValue]; + + _memoryMap.access(0x56 + highRes, false); + _memoryMap.access(0x80 + lcw, false); + _memoryMap.access(0x00 + store80, false); + _memoryMap.set_shadow_register(shadow); + _memoryMap.set_state_register(state); + + // Test results. + for(NSArray *region in test[@"read"]) { + const auto logicalStart = [region[0] intValue]; + const auto logicalEnd = [region[1] intValue]; + const auto physicalStart = [region[2] intValue]; + const auto physicalEnd = [region[3] intValue]; + + if(physicalEnd == physicalStart && physicalStart == 0) { + continue; + } + + // Test read pointers. + int physical = physicalStart; + for(int logical = logicalStart; logical < logicalEnd; logical++) { + const auto ®ion = _memoryMap.regions[_memoryMap.region_map[logical]]; + + XCTAssert(region.read != nullptr); + XCTAssert(®ion.read[logical << 8] == &_ram[physical << 8], + @"Physical page %04x should be mapped to logical %04x; is instead %04x", + physical, + logical, + int(®ion.read[logical << 8] - _ram.data()) >> 8); + + if(physical != physicalEnd) ++physical; + } + } + } +} + @end