mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -04:00
fixed a bug in the keyboard "av" signal, closes #341
This commit is contained in:
parent
8708a2fc06
commit
ef8add3ff9
@ -17,6 +17,7 @@ import de.neemann.digital.core.element.Keys;
|
|||||||
import static de.neemann.digital.core.element.PinInfo.input;
|
import static de.neemann.digital.core.element.PinInfo.input;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Keyboard component
|
||||||
*/
|
*/
|
||||||
public class Keyboard extends Node implements Element {
|
public class Keyboard extends Node implements Element {
|
||||||
|
|
||||||
@ -33,13 +34,12 @@ public class Keyboard extends Node implements Element {
|
|||||||
|
|
||||||
private final String label;
|
private final String label;
|
||||||
private final ObservableValue data;
|
private final ObservableValue data;
|
||||||
private final ObservableValue isKeyOut;
|
private final ObservableValue keyAvail;
|
||||||
private KeyboardInterface keyboardInterface;
|
private KeyboardInterface keyboardInterface;
|
||||||
private ObservableValue clock;
|
private ObservableValue clock;
|
||||||
private ObservableValue enable;
|
private ObservableValue enable;
|
||||||
private boolean enableVal;
|
private boolean enableVal;
|
||||||
private boolean lastClock = false;
|
private boolean lastClock = false;
|
||||||
private int nextChar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new terminal instance
|
* Creates a new terminal instance
|
||||||
@ -50,7 +50,7 @@ public class Keyboard extends Node implements Element {
|
|||||||
data = new ObservableValue("D", 16)
|
data = new ObservableValue("D", 16)
|
||||||
.setToHighZ()
|
.setToHighZ()
|
||||||
.setPinDescription(DESCRIPTION);
|
.setPinDescription(DESCRIPTION);
|
||||||
isKeyOut = new ObservableValue("av", 1)
|
keyAvail = new ObservableValue("av", 1)
|
||||||
.setPinDescription(DESCRIPTION);
|
.setPinDescription(DESCRIPTION);
|
||||||
label = attributes.getLabel();
|
label = attributes.getLabel();
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ public class Keyboard extends Node implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObservableValues getOutputs() {
|
public ObservableValues getOutputs() {
|
||||||
return new ObservableValues(data, isKeyOut);
|
return new ObservableValues(data, keyAvail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,8 +71,8 @@ public class Keyboard extends Node implements Element {
|
|||||||
enableVal = enable.getBool();
|
enableVal = enable.getBool();
|
||||||
boolean nowClock = clock.getBool();
|
boolean nowClock = clock.getBool();
|
||||||
|
|
||||||
if (keyboardInterface != null && nowClock && !lastClock && enableVal)
|
if (keyboardInterface != null && !nowClock && lastClock && enableVal)
|
||||||
nextChar = keyboardInterface.getChar();
|
keyboardInterface.deleteFirstChar();
|
||||||
|
|
||||||
lastClock = nowClock;
|
lastClock = nowClock;
|
||||||
}
|
}
|
||||||
@ -81,16 +81,16 @@ public class Keyboard extends Node implements Element {
|
|||||||
public void writeOutputs() throws NodeException {
|
public void writeOutputs() throws NodeException {
|
||||||
if (keyboardInterface != null) {
|
if (keyboardInterface != null) {
|
||||||
if (enableVal)
|
if (enableVal)
|
||||||
data.setValue(nextChar);
|
data.setValue(keyboardInterface.getChar());
|
||||||
else
|
else
|
||||||
data.setToHighZ();
|
data.setToHighZ();
|
||||||
isKeyOut.setBool(keyboardInterface.isChar() || nextChar != 0);
|
keyAvail.setBool(keyboardInterface.getChar() != 0);
|
||||||
} else {
|
} else {
|
||||||
if (enableVal)
|
if (enableVal)
|
||||||
data.setValue(0);
|
data.setValue(0);
|
||||||
else
|
else
|
||||||
data.setToHighZ();
|
data.setToHighZ();
|
||||||
isKeyOut.setBool(false);
|
keyAvail.setBool(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +115,14 @@ public class Keyboard extends Node implements Element {
|
|||||||
*/
|
*/
|
||||||
public interface KeyboardInterface {
|
public interface KeyboardInterface {
|
||||||
/**
|
/**
|
||||||
* @return a char or 0 if no char available
|
* @return a char or 0 if no char available, does not remove the char
|
||||||
*/
|
*/
|
||||||
int getChar();
|
int getChar();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if there is a char
|
* removes the first char
|
||||||
*/
|
*/
|
||||||
boolean isChar();
|
void deleteFirstChar();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,19 +64,19 @@ public class KeyboardDialog extends JDialog implements Keyboard.KeyboardInterfac
|
|||||||
if (text.length() == 0)
|
if (text.length() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else {
|
||||||
final char c = text.charAt(0);
|
return text.charAt(0);
|
||||||
text = text.substring(1);
|
|
||||||
final String t = text;
|
|
||||||
SwingUtilities.invokeLater(() -> textLabel.setText(t));
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChar() {
|
public void deleteFirstChar() {
|
||||||
synchronized (textLock) {
|
synchronized (textLock) {
|
||||||
return text.length() > 0;
|
if (text.length() > 0) {
|
||||||
|
text = text.substring(1);
|
||||||
|
final String t = text;
|
||||||
|
SwingUtilities.invokeLater(() -> textLabel.setText(t));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user