updated to AM14, AM15
[fleet.git] / src / edu / berkeley / fleet / ships / Mux.java
1 package edu.berkeley.fleet.ships;
2 import edu.berkeley.fleet.interpreter.*;
3 import edu.berkeley.fleet.*;
4
5 import java.util.*;
6 import java.io.*;
7
8 public class Mux extends InterpreterShip {
9
10     DataInbox   ap      = new DataInbox(this,  "a");
11     DataInbox   bp      = new DataInbox(this,  "b");
12     DataInbox   choicep = new DataInbox(this, "select");
13     DataOutbox  out     = new DataOutbox(this, "out");
14
15     public Mux(Interpreter fleet, String name) { super(fleet, name); }
16
17     public String getBalsaName() { return "mux"; }
18
19     public void service() {
20         if (ap.dataReadyForShip() && bp.dataReadyForShip() && choicep.dataReadyForShip()) {
21             int a      = ap.removeDataForShip();
22             int b      = bp.removeDataForShip();
23             int choice = choicep.removeDataForShip();
24             out.addDataFromShip(choice==0 ? a : b);
25         }
26     }
27
28 }