BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
Object busVal = state.getAttributeValue(ATTR_BUS);
boolean asynch = busVal == null ? false : busVal.equals(BUS_ASYNCH);
boolean separate = busVal == null ? false : busVal.equals(BUS_SEPARATE);
Value addrValue = state.getPort(ADDR);
boolean chipSelect = state.getPort(CS) != Value.FALSE;
boolean triggered = asynch || myState.setClock(state.getPort(CLK), StdAttr.TRIG_RISING);
boolean outputEnabled = state.getPort(OE) != Value.FALSE;
boolean shouldClear = state.getPort(CLR) == Value.TRUE;
if (shouldClear) {
myState.getContents().clear();
}
if (!chipSelect) {
myState.setCurrent(-1);
state.setPort(DATA, Value.createUnknown(dataBits), DELAY);
return;
}
int addr = addrValue.toIntValue();
if (!addrValue.isFullyDefined() || addr < 0)
return;
if (addr != myState.getCurrent()) {
myState.setCurrent(addr);
myState.scrollToShow(addr);
}
if (!shouldClear && triggered) {
boolean shouldStore;
if (separate) {
shouldStore = state.getPort(WE) != Value.FALSE;
} else {
shouldStore = !outputEnabled;
}
if (shouldStore) {
Value dataValue = state.getPort(separate ? DIN : DATA);
myState.getContents().set(addr, dataValue.toIntValue());
}
}
if (outputEnabled) {
int val = myState.getContents().get(addr);