+ship: Iscratch
+
+== Ports ===========================================================
+data in: write_addr
+data in: write_data
+token out: write_done
+
+data in: cbd
+
+== Fleeterpreter ====================================================
+
+ private long[] mem = new long[0];
+ public long readMem(int addr) { return mem[addr]; }
+ public void writeMem(int addr, long val) {
+ if (addr >= mem.length) {
+ long[] newmem = new long[addr * 2 + 1];
+ System.arraycopy(mem, 0, newmem, 0, mem.length);
+ mem = newmem;
+ }
+ mem[addr] = val;
+ }
+
+ public void dispatch(int addr, int size) {
+ for(int i=addr; i<addr+size; i++) {
+ Instruction instr = ((Interpreter)getFleet()).readInstruction(readMem(i));
+ ((Interpreter)getFleet()).dispatch(instr, i);
+ }
+ }
+
+ public void service() {
+ if (box_cbd.dataReadyForShip()) {
+ int val = box_cbd.removeDataForShip();
+ int addr = val >> 6;
+ int size = val & 0x3f;
+ dispatch(addr, size);
+ }
+
+ if (box_write_addr.dataReadyForShip() &&
+ box_write_data.dataReadyForShip() &&
+ box_write_done.readyForItemFromShip()) {
+ Interpreter f = (Interpreter)getFleet();
+ f.writeMem(box_write_addr.removeDataForShip(),
+ box_write_data.removeDataForShip());
+ box_write_done.addTokenFromShip();
+ }
+ }
+
+ public void boot(byte[] instructions) {
+ Interpreter fleet = (Interpreter)getFleet();
+ // load the iscratch and take note of the 0-address CBD
+ long launch = 0;
+ for(int i=0; i<instructions.length; i+=6) {
+ long word = 0;
+ for(int j=0; j<6; j++)
+ word = (word << 8) | (instructions[i+j] & 0xff);
+ writeMem(i/6, word);
+ if (i==0) launch = word;
+ }
+
+ // dispatch the 0-address CBD
+ int base = (int)(launch >> 6);
+ base = base & ~(0xffffffff << 18);
+ int size = (int)launch;
+ size = size & ~(0xffffffff << 6);
+ dispatch(base, size);
+ }
+
+== Constants ========================================================
+== TeX ==============================================================
+== ArchSim ==============================================================
+== FPGA ==============================================================
+
+== Contributors =========================================================
+Adam Megacz <megacz@cs.berkeley.edu>