Skip to content

Instantly share code, notes, and snippets.

@hawkw
Last active December 16, 2015 08:39
Show Gist options
  • Save hawkw/5407014 to your computer and use it in GitHub Desktop.
Save hawkw/5407014 to your computer and use it in GitHub Desktop.
awful gross method got awfuller and grosser
/**
* Evaluates the command at the program counter.
*/
public void eval() {
int currentInstruction = ram[counter.getModule()][counter.getIndex()];
int tempA = 0x00000000;
int tempB = 0x00000000;
short address = 0x0000;
switch (currentInstruction) {
case 0x01: // STORE
address = Byte.parseByte(Integer.toString(currentInstruction)
.substring(3, 7));
counter.increment();
currentInstruction = ram[counter.getModule()][counter.getIndex()];
writeToRAM(currentInstruction, parseHex(address));
break;
case 0x02: // ADD
DataStack.push(DataStack.pop() + DataStack.pop());
break;
case 0x03: // SUBTRACT
DataStack.push(DataStack.pop() - DataStack.pop());
break;
case 0x04: // RSTORE
ReturnStack.push(DataStack.pop());
break;
case 0x05: // FETCH
address = Byte.parseByte(Integer.toString(currentInstruction)
.substring(3, 7));
DataStack.push(readFromRAM(parseHex(address)));
break;
case 0x06: // AND
DataStack.push(DataStack.pop() & DataStack.pop());
break;
case 0x07: // DROP
DataStack.pop();
break;
case 0x08: // DUP
DataStack.push(DataStack.pop());
DataStack.push(DataStack.pop());
break;
case 0x09: // OR
DataStack.push(DataStack.pop() ^ DataStack.pop());
break;
case 0x0A: // OVER
break;
case 0x0B: // RFETCH
DataStack.push(ReturnStack.pop());
break;
case 0x0C: // SWAP
tempA = DataStack.pop();
tempB = DataStack.pop();
DataStack.push(tempB);
DataStack.push(tempA);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment