Fixed a big bug in softswitch handling of hires switch (was not triggering memory layout updates!); Got Aux memory tests working

This commit is contained in:
Badvision 2024-08-16 01:26:55 -05:00
parent afebe4d56f
commit 5444f40bd4
5 changed files with 107 additions and 21 deletions

View File

@ -194,9 +194,9 @@ abstract public class RAM128k extends RAM {
public String getReadConfiguration() { public String getReadConfiguration() {
String rstate = ""; String rstate = "";
if (SoftSwitches.RAMRD.getState()) { if (SoftSwitches.RAMRD.getState()) {
rstate += "Ra"; rstate += "Ra_";
} else { } else {
rstate += "R0"; rstate += "R0_";
} }
String LCR = "L0R"; String LCR = "L0R";
if (SoftSwitches.LCRAM.isOn()) { if (SoftSwitches.LCRAM.isOn()) {
@ -214,16 +214,16 @@ abstract public class RAM128k extends RAM {
} }
rstate += LCR; rstate += LCR;
if (SoftSwitches.CXROM.getState()) { if (SoftSwitches.CXROM.getState()) {
rstate += "CXROM"; rstate += "_CXROM";
} else { } else {
rstate += "!CX"; rstate += "_!CX";
if (SoftSwitches.SLOTC3ROM.isOff()) { if (SoftSwitches.SLOTC3ROM.isOff()) {
rstate += "C3"; rstate += "_C3";
} }
if (SoftSwitches.INTC8ROM.isOn()) { if (SoftSwitches.INTC8ROM.isOn()) {
rstate += "C8"; rstate += "_C8";
} else { } else {
rstate += "C8"+getActiveSlot(); rstate += "_C8"+getActiveSlot();
} }
} }
@ -233,9 +233,9 @@ abstract public class RAM128k extends RAM {
public String getWriteConfiguration() { public String getWriteConfiguration() {
String wstate = ""; String wstate = "";
if (SoftSwitches.RAMWRT.getState()) { if (SoftSwitches.RAMWRT.getState()) {
wstate += "Wa"; wstate += "Wa_";
} else { } else {
wstate += "W0"; wstate += "W0_";
} }
String LCW = "L0W"; String LCW = "L0W";
if (SoftSwitches.LCWRITE.isOn()) { if (SoftSwitches.LCWRITE.isOn()) {
@ -256,22 +256,26 @@ abstract public class RAM128k extends RAM {
} }
public String getAuxZPConfiguration() { public String getAuxZPConfiguration() {
String astate = ""; String astate = "__";
if (SoftSwitches._80STORE.isOn()) { if (SoftSwitches._80STORE.isOn()) {
astate += "80S"; astate += "80S_";
if (SoftSwitches.PAGE2.isOn()) { if (SoftSwitches.PAGE2.isOn()) {
astate += "2"; astate += "P2_";
} else {
astate += "P1_";
} }
if (SoftSwitches.HIRES.isOn()) { if (SoftSwitches.HIRES.isOn()) {
astate += "H"; astate += "H1_";
} else {
astate += "H0_";
} }
} }
// Handle zero-page bankswitching // Handle zero-page bankswitching
if (SoftSwitches.AUXZP.getState()) { if (SoftSwitches.AUXZP.getState()) {
astate += "Za"; astate += "Za_";
} else { } else {
astate += "Z0"; astate += "Z0_";
} }
return astate; return astate;
} }
@ -417,7 +421,8 @@ abstract public class RAM128k extends RAM {
state = newState; state = newState;
log("MMU Switches"); log("MMU Switches");
// System.out.println("read: " + readConfiguration);
// System.out.println("write: " + writeConfiguration);
if (memoryConfigurations.containsKey(readConfiguration)) { if (memoryConfigurations.containsKey(readConfiguration)) {
activeRead = memoryConfigurations.get(readConfiguration); activeRead = memoryConfigurations.get(readConfiguration);
} else { } else {

View File

@ -74,11 +74,20 @@ public enum SoftSwitches {
if (_80STORE.isOn()) { if (_80STORE.isOn()) {
Emulator.withMemory(m->m.configureActiveMemory()); Emulator.withMemory(m->m.configureActiveMemory());
} else { } else {
Emulator.withVideo(v->v.configureVideoMode()); super.stateChanged();
} }
} }
}), }),
HIRES(new VideoSoftSwitch("Hires", 0x0c056, 0x0c057, 0x0c01d, RAMEvent.TYPE.ANY, false)), HIRES(new VideoSoftSwitch("Hires", 0x0c056, 0x0c057, 0x0c01d, RAMEvent.TYPE.ANY, false) {
@Override
public void stateChanged() {
// PAGE2 is a hybrid switch; 80STORE ? memory : video
if (_80STORE.isOn()) {
Emulator.withMemory(m->m.configureActiveMemory());
}
super.stateChanged();
}
}),
DHIRES(new VideoSoftSwitch("Double-hires", 0x0c05f, 0x0c05e, 0x0c07f, RAMEvent.TYPE.ANY, false)), DHIRES(new VideoSoftSwitch("Double-hires", 0x0c05f, 0x0c05e, 0x0c07f, RAMEvent.TYPE.ANY, false)),
PB0(new MemorySoftSwitch("Pushbutton0", -1, -1, 0x0c061, RAMEvent.TYPE.ANY, null)), PB0(new MemorySoftSwitch("Pushbutton0", -1, -1, 0x0c061, RAMEvent.TYPE.ANY, null)),
PB1(new MemorySoftSwitch("Pushbutton1", -1, -1, 0x0c062, RAMEvent.TYPE.ANY, null)), PB1(new MemorySoftSwitch("Pushbutton1", -1, -1, 0x0c062, RAMEvent.TYPE.ANY, null)),

View File

@ -38,7 +38,7 @@ public class MemorySoftSwitch extends SoftSwitch {
@Override @Override
public void stateChanged() { public void stateChanged() {
// System.out.println(getName()+ " was switched to "+getState()); // System.out.println(getName()+ " was switched to "+getState());
Emulator.withMemory(m->m.configureActiveMemory()); Emulator.withMemory(m->m.configureActiveMemory());
} }

View File

@ -140,6 +140,9 @@ public class CardMockingboard extends Card {
@Override @Override
protected void handleFirmwareAccess(int register, TYPE type, int value, RAMEvent e) { protected void handleFirmwareAccess(int register, TYPE type, int value, RAMEvent e) {
if (type == TYPE.READ_FAKE) {
return;
}
if (chips == null) { if (chips == null) {
reconfigure(); reconfigure();
} }

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before; import org.junit.Before;
@ -36,6 +37,7 @@ import jace.TestProgram;
import jace.apple2e.MOS65C02; import jace.apple2e.MOS65C02;
import jace.apple2e.RAM128k; import jace.apple2e.RAM128k;
import jace.apple2e.SoftSwitches; import jace.apple2e.SoftSwitches;
import jace.core.RAMEvent.TYPE;
/** /**
* Test that memory listeners fire appropriately. * Test that memory listeners fire appropriately.
@ -68,9 +70,13 @@ public class MemoryTest {
} }
@Before @Before
public void setup() { public void resetEmulator() {
computer.pause(); computer.pause();
cpu.clearState(); cpu.clearState();
}
@Before
public void resetSoftSwitches() {
// Reset softswitches // Reset softswitches
for (SoftSwitches softswitch : SoftSwitches.values()) { for (SoftSwitches softswitch : SoftSwitches.values()) {
softswitch.getSwitch().reset(); softswitch.getSwitch().reset();
@ -229,7 +235,6 @@ public class MemoryTest {
sta $FE1F ; FE1F is $60 in Apple II/plus/e/enhanced sta $FE1F ; FE1F is $60 in Apple II/plus/e/enhanced
cmp $FE1F cmp $FE1F
""") """)
//
.assertEquals("E0005: We tried to put the language card into read RAM, write RAM, but failed to write.") .assertEquals("E0005: We tried to put the language card into read RAM, write RAM, but failed to write.")
.add(""" .add("""
lda $C083 ; Read and write bank 2 lda $C083 ; Read and write bank 2
@ -513,4 +518,68 @@ public class MemoryTest {
SoftSwitches._80STORE.getSwitch().setState(true); SoftSwitches._80STORE.getSwitch().setState(true);
languageCardBankswitchTest(); languageCardBankswitchTest();
} }
public record MemoryTestCase(int[] softswitches, byte... expected) {}
int[] testLocations = {
0x0FF, 0x100, 0x200, 0x3FF, 0x427, 0x7FF, 0x800, 0x1FFF,
0x2000, 0x3FFF, 0x4000, 0x5FFF, 0xBFFF
};
private void assertMemoryTest(MemoryTestCase testCase) {
// Set the values in memory in main and aux banks
// This is done directly to ensure the values are exactly as expected
// The next tests will try to read these values using the softswitches
for (int location : testLocations) {
((RAM128k) ram).getMainMemory().writeByte(location, (byte) 1);
((RAM128k) ram).getAuxMemory().writeByte(location, (byte) 3);
}
resetSoftSwitches();
for (int softswitch : testCase.softswitches) {
System.out.println("Setting softswitch " + Integer.toHexString(softswitch));
ram.write(softswitch, (byte) 0, true, false);
}
for (int i=0; i < testLocations.length; i++) {
int address = testLocations[i];
byte current = ram.read(address, TYPE.READ_DATA, false, false);
ram.write(address, (byte) (current+1), false, false);
byte expected = testCase.expected[i];
try {
assertEquals("Unexpected value at " + Integer.toHexString(address), expected, ram.read(address, TYPE.READ_DATA, false, false));
} catch (AssertionError err) {
for (SoftSwitches softswitch : SoftSwitches.values()) {
System.out.println(MessageFormat.format("{0}\t{1}", softswitch.name(), (softswitch.isOn() ? "on" : "off")));
}
throw err;
}
}
}
@Test
public void auxBankSwitchTest() throws ProgramException {
byte M1 = (byte) 1; // Main + no change
byte M2 = (byte) 2; // Main + 1
byte A1 = (byte) 3; // Aux + no change
byte A2 = (byte) 4; // Aux + 1
// 80 STORE + RAMWRT + HIRES / Page 1 (Main mem)
assertMemoryTest(new MemoryTestCase(new int[] {0x0C005, 0x0C001, 0x0C057},
M2, M2, M1, M1, M2, M2, M1, M1, M2, M2, M1, M1, M1));
// RAMRD + AUXZP
assertMemoryTest(new MemoryTestCase(new int[] {0xC003, 0xC009},
A2, A2, A1, A1, A1, A1, A1, A1, A1, A1, A1, A1, A1));
// RAMRD + MAINZP
assertMemoryTest(new MemoryTestCase(new int[] {0xC003, 0xC008},
M2, M2, A1, A1, A1, A1, A1, A1, A1, A1, A1, A1, A1));
// 80 STORE + HIRES' + Page 2
assertMemoryTest(new MemoryTestCase(new int[] {0x0C001, 0x0C056, 0x0C055},
M2, M2, M2, M2, A2, A2, M2, M2, M2, M2, M2, M2, M2));
// 80 STORE + HIRES + Page 2
assertMemoryTest(new MemoryTestCase(new int[] {0x0C001, 0x0C057, 0x0C055},
M2, M2, M2, M2, A2, A2, M2, M2, A2, A2, M2, M2, M2));
}
} }