- public void writeInstruction(DataOutputStream os, Instruction d) throws IOException {
- if (d instanceof Instruction.Executable) {
- Instruction.Executable inst = (Instruction.Executable)d;
-
- InterpreterBenkoBox dest = resolve(inst.dest);
- long instr = dest==null ? 0 : (dest.addr << 1);
-
- instr |= (((long)inst.count) << (11+1));
- if (inst.tokenIn) instr |= (1L << (11+1+7+0));
- if (inst.dataOut) instr |= (1L << (11+1+7+1));
- if (inst.latch) instr |= (1L << (11+1+7+2));
- if (inst.dataIn) instr |= (1L << (11+1+7+3));
- if (inst.tokenOut) instr |= (1L << (11+1+7+4));
- instr |= ((long)resolve(inst.benkoBox).instr_addr) << (11+5+7+1);
- long out = 0;
- out |= ((InterpreterBenkoBox)ships.get("command").getBenkoBox("data")).addr;
- out |= instr << 11;
- dump(os, (out >> (5*8)) & 0xff);
- dump(os, (out >> (4*8)) & 0xff);
- dump(os, (out >> (3*8)) & 0xff);
- dump(os, (out >> (2*8)) & 0xff);
- dump(os, (out >> (1*8)) & 0xff);
- dump(os, (out >> (0*8)) & 0xff);
- } else if (d instanceof Instruction.Literal.Absolute) {
- Instruction.Literal.Absolute ld = (Instruction.Literal.Absolute)d;
- long out = 0;
- out |= resolve(ld.dest).addr;
- out |= ((long)ld.value) << 11;
- dump(os, (out >> (5*8)) & 0xff);
- dump(os, (out >> (4*8)) & 0xff);
- dump(os, (out >> (3*8)) & 0xff);
- dump(os, (out >> (2*8)) & 0xff);
- dump(os, (out >> (1*8)) & 0xff);
- dump(os, (out >> (0*8)) & 0xff);
- }
- }
- public void dump(OutputStream os, long data_) throws IOException {
- int data = (int)data_;
- os.write((byte)data);
- System.out.println(data);
- }
-
- public Iterator<Ship> iterator() {
- return (Iterator<Ship>)(Object)shiplist.iterator();
- }
-
- public void go() {
- while(!halt)
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
-
- // run the ships a bit longer for good measure
- for(int i=0; i<100; i++)
- for(InterpreterShip ship : ships.values())
- for(int j=0; j<10; j++)
- ship._service();
-
- // check the state of the ships
- for(InterpreterShip ship : ships.values())
- ship.shutdown();
-
- Log.println(Log.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
- }
-
- public void dumpMem() {
- Log.print(Log.cyan(" MEMORY: "));
- for(int i=0; i<mem.length; i++) {
- if ((i%10)==0 && i!=0) Log.print(Log.cyan(" "));
- Log.print(Log.cyan(mem[i] + " "));
- if ((i%10)==9 && i!=mem.length-1) Log.println("");
- }
- Log.println();