package com.droidquest.chipstuff; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Vector; import com.droidquest.devices.SmallChip; public class Gate implements Serializable { public transient PortSignal[] portSignals = new PortSignal[8]; public boolean state; public String type; public int speed; public Vector mySignals = new Vector(); public Vector myGates = new Vector(); public Gate(String t) { // Called whenever a non-chip gate is created. type = t; speed = 1; for (int a=0; a<8; a++) portSignals[a] = new PortSignal(); } public Gate(SmallChip sc) { // Called by ChipCompiler to put a nested chip into a gate speed = sc.speed; type = "Chip"; Signal dummySignal; portSignals = new PortSignal[8]; for (int a=0; a<8; a++) portSignals[a] = new PortSignal(); for (int a=0; a=0) portSignals[a].internalSignal = (Signal) mySignals.elementAt(portIndex); } for (int a=0; a=0) gate.portSignals[b].externalSignal = (Signal) mySignals.elementAt(sigIndex); gate.portSignals[b].type = s.readInt(); } gate.readRef(s); } } public void Function() { if (type.equalsIgnoreCase("AND")) portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get() & portSignals[1].externalSignal.Get()); if (type.equalsIgnoreCase("OR")) portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get() | portSignals[1].externalSignal.Get()); if (type.equalsIgnoreCase("NOT")) portSignals[1].externalSignal.Set(!portSignals[0].externalSignal.Get()); if (type.equalsIgnoreCase("XOR")) portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get() ^ portSignals[1].externalSignal.Get()); if (type.equalsIgnoreCase("FF")) { if (portSignals[0].externalSignal.Get() ^ portSignals[1].externalSignal.Get()) state = portSignals[0].externalSignal.Get(); portSignals[2].externalSignal.Set(state); portSignals[3].externalSignal.Set(!state); } if (type.equalsIgnoreCase("NODE")) { portSignals[1].externalSignal.Set(portSignals[0].externalSignal.Get()); portSignals[2].externalSignal.Set(portSignals[0].externalSignal.Get()); if (portSignals[3].externalSignal!=null) portSignals[3].externalSignal.Set(portSignals[0].externalSignal.Get()); } if (type.equalsIgnoreCase("Chip")) { for (int s=0; s=0) portSignals[a].internalSignal = (Signal) mySignals.elementAt(sigIndex); portSignals[a].type = s.readInt(); } int numGates = s.readInt(); for (int a=0; a=0) newGate.portSignals[b].externalSignal = (Signal) mySignals.elementAt(sigIndex); } if (newGate.type.equalsIgnoreCase("Chip")) newGate.LoadSubGate(s); } speed = s.readInt(); } public void DebugReport(int indent) { // String ind = ""; // for (int a=0; a