From 208c909fc217cda54e9bcb2c6ccaf0f601390aa5 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 12 Jan 2018 21:21:08 -0600 Subject: [PATCH] Memory is determined solely by BANK_ALTZP. Previously, we just used whatever the segment was that got passed in. But aside from switching the stack and zero page, ALTZP also changes where bank-switchable memory is read from and written to; it's either always aux memory (ALTZP is on) or always main memory (ALTZP is off). --- src/apple2.mem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/apple2.mem.c b/src/apple2.mem.c index 5c651bb..92a0716 100644 --- a/src/apple2.mem.c +++ b/src/apple2.mem.c @@ -16,6 +16,12 @@ SEGMENT_READER(apple2_mem_read_bank) mach = (apple2 *)_mach; + // In the case of bank-switchable memory, BANK_ALTZP is the ultimate + // arbitrator; if it's on, we have to use aux, and if not, we have + // to use main. Whatever the segment was that was passed in will + // turn out to be immaterial. + segment = (mach->bank_switch & BANK_ALTZP) ? mach->aux : mach->main; + if (~mach->bank_switch & BANK_RAM) { // We need to account for the difference in address location // before we can successfully get any data from ROM. @@ -52,6 +58,9 @@ SEGMENT_WRITER(apple2_mem_write_bank) return; } + // See my spiel in the read bank mapper; the same applies here. + segment = (mach->bank_switch & BANK_ALTZP) ? mach->aux : mach->main; + // You will note, if we've gotten here, that it's possible to write // to the bank-switch addresses even if the ROM flag is 1. It's // true! Except that writes never go to ROM. That is to say, it's