public class Outbox extends InstructionBenkoBox {
/** are we ready to accept another item from the ship? */
- private boolean readyForItemFromShip = true;
+ private boolean readyForDataFromShip = false;
+ private boolean haveDataFromShip = false;
/** data which has been presented by the ship and is waiting to depart */
private long itemPresentedByShip;
// check firing conditions
if (instruction.tokenIn && triggersReceived <= 0) return false;
- if (instruction.dataIn && readyForItemFromShip) return false;
+ if (instruction.dataIn) {
+ if (!haveDataFromShip) { readyForDataFromShip = true; return false; }
+ }
// consume trigger
if (instruction.tokenIn) triggersReceived--;
// consume item
if (instruction.dataIn) {
- readyForItemFromShip = true;
+ haveDataFromShip = false;
if (instruction.latch)
register = itemPresentedByShip;
}
return true;
}
- public final boolean readyForItemFromShip() { return readyForItemFromShip; }
+ public final boolean readyForDataFromShip() { return readyForDataFromShip; }
public void addDataFromShip(long data) { addItemFromShip(data); }
- public boolean readyForDataFromShip() { return readyForItemFromShip(); }
public void addDataFromFabric(Packet packet) { triggersReceived++; }
/** subclass invokes this to add an item from the ship */
protected final void addItemFromShip(long data) {
- if (!readyForItemFromShip)
+ if (!readyForDataFromShip)
throw new RuntimeException("tried to add an item to an outbox which was not ready! you have a buggy ship!");
- readyForItemFromShip = false;
+ readyForDataFromShip = false;
+ haveDataFromShip = true;
itemPresentedByShip = data;
}
void shutdown() {
- if (!readyForItemFromShip)
+ if (haveDataFromShip)
Log.println(ANSI.red(" WARNING: you left a value ("+itemPresentedByShip+") on outbox port " + this));
if (triggersReceived > 0)
Log.println(ANSI.red(" WARNING: you left a token on the trigger input to port " + this));