From 74f9f6ad3b2ecf3dec200e6f48f5e0d64d78c526 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 27 Oct 2020 19:02:15 -0400 Subject: [PATCH] Tests and corrects ROM access beyond bank $00. --- Machines/Apple/AppleIIgs/MemoryMap.hpp | 7 ++++--- .../Clock SignalTests/IIgsMemoryMapTests.mm | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Machines/Apple/AppleIIgs/MemoryMap.hpp b/Machines/Apple/AppleIIgs/MemoryMap.hpp index 26eb63be2..0cfc11bd3 100644 --- a/Machines/Apple/AppleIIgs/MemoryMap.hpp +++ b/Machines/Apple/AppleIIgs/MemoryMap.hpp @@ -217,15 +217,16 @@ class MemoryMap { const auto zero_state = auxiliary_switches_.zero_state(); const bool inhibit_banks0001 = shadow_register_ & 0x40; - // Crib the ROM pointer from a page it's always visible on. - const uint8_t *const rom = ®ions[region_map[0xffd0]].read[0xffd000] - 0xd000; - auto apply = [&language_state, &zero_state, rom, this](uint32_t bank_base, uint8_t *ram) { + auto apply = [&language_state, &zero_state, this](uint32_t bank_base, uint8_t *ram) { // All references below are to 0xc000, 0xd000 and 0xe000 but should // work regardless of bank. // TODO: verify order of ternary here — on the plain Apple II it was arbitrary. uint8_t *const lower_ram_bank = ram - (language_state.bank1 ? 0x0000 : 0x1000); + // Crib the ROM pointer from a page it's always visible on. + const uint8_t *const rom = ®ions[region_map[0xffd0]].read[0xffd000] - ((bank_base << 8) + 0xd000); + auto &d0_region = regions[region_map[bank_base | 0xd0]]; d0_region.read = language_state.read ? lower_ram_bank : rom; d0_region.write = language_state.write ? nullptr : lower_ram_bank; diff --git a/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm b/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm index 3a87008d6..9d2e4ff79 100644 --- a/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm +++ b/OSBindings/Mac/Clock SignalTests/IIgsMemoryMapTests.mm @@ -62,16 +62,21 @@ namespace { XCTAssertEqual(_rom[0], 0xc0); } -- (void)testROMInBank0 { +- (void)testROM { _rom.back() = 0xa8; + auto test_bank = [self](uint32_t bank) { + const uint32_t address = bank | 0x00ffff; + const auto ®ion = MemoryMapRegion(_memoryMap, address); + uint8_t value; + MemoryMapRead(region, address, &value); + XCTAssertEqual(value, 0xa8); - // Test that ROM is properly visible in bank 0. - const uint32_t address = 0x00ffff; - const auto ®ion = MemoryMapRegion(_memoryMap, address); - uint8_t value; - MemoryMapRead(region, address, &value); + }; - XCTAssertEqual(value, 0xa8); + test_bank(0x000000); + test_bank(0x010000); + test_bank(0xe00000); + test_bank(0xe10000); } @end