Switched synchronization to use a semaphore when reconfiguring memory banks

This commit is contained in:
Brendan Robert 2015-03-29 00:27:30 -05:00
parent 4c073cca6a
commit 98fd203305

View File

@ -26,6 +26,9 @@ import jace.core.RAM;
import jace.state.Stateful;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Implementation of a 128k memory space and the MMU found in an Apple //e. The
@ -35,6 +38,7 @@ import java.io.InputStream;
*/
@Stateful
abstract public class RAM128k extends RAM {
@Stateful
public PagedMemory mainMemory;
@Stateful
@ -73,13 +77,16 @@ abstract public class RAM128k extends RAM {
}
}
private final Semaphore configurationSemaphone = new Semaphore(1, true);
/**
*
*/
@Override
public void configureActiveMemory() {
try {
log("MMU Switches");
synchronized (this) {
configurationSemaphone.acquire();
// First off, set up read/write for main memory (might get changed later on)
activeRead.fillBanks(SoftSwitches.RAMRD.getState() ? getAuxMemory() : mainMemory);
activeWrite.fillBanks(SoftSwitches.RAMWRT.getState() ? getAuxMemory() : mainMemory);
@ -168,7 +175,7 @@ abstract public class RAM128k extends RAM {
activeRead.set(i, blank.get(0));
}
} else {
getCard(getActiveSlot()).ifPresent(c -> activeRead.setBanks(0,8,0x0c8, c.getC8Rom()));
getCard(getActiveSlot()).ifPresent(c -> activeRead.setBanks(0, 8, 0x0c8, c.getC8Rom()));
}
if (SoftSwitches.SLOTC3ROM.isOff()) {
// Enable C3 to point to internal ROM
@ -179,9 +186,12 @@ abstract public class RAM128k extends RAM {
activeRead.setBanks(7, 8, 0x0C8, cPageRom);
}
}
}
// All ROM reads not intecepted will return 0xFF! (TODO: floating bus)
activeRead.set(0x0c0, blank.get(0));
configurationSemaphone.release();
} catch (InterruptedException ex) {
Logger.getLogger(RAM128k.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void log(String message) {
@ -234,8 +244,11 @@ abstract public class RAM128k extends RAM {
}
abstract public PagedMemory getAuxVideoMemory();
abstract public PagedMemory getAuxMemory();
abstract public PagedMemory getAuxLanguageCard();
abstract public PagedMemory getAuxLanguageCard2();
/**