Skip to content

Commit

Permalink
Several small improvements to Octo. Fixed a bug in register name deco…
Browse files Browse the repository at this point in the history
…ding, added a simple jump construct and modified Octo to print out rom size/remaining space.
  • Loading branch information
JohnEarnest committed Apr 18, 2013
1 parent 6b7e651 commit 035dea8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions demos/Chip8/Octo.java
Expand Up @@ -39,6 +39,7 @@ public static void main(String[] args) throws IOException {
out.write(rom.get(x+1));
}
System.out.println();
System.out.format("%d bytes, %d free.%n", rom.size(), 3584-rom.size());
out.close();
}

Expand All @@ -60,7 +61,7 @@ static boolean isReg(String n) {
}
static int reg(String n) {
if (!isReg(n)) { throw new Error("Register expected, got '"+n+"'"); }
return n.charAt(1) - '0';
return "0123456789abcdef".indexOf(n.charAt(1));
}

static void jump(int a, int b) {
Expand Down Expand Up @@ -112,6 +113,7 @@ static void compile(String token) {
else if ("loop".equals(token)) { loops.push(here()); whiles.push(null); }
else if ("while".equals(token)) { cond(true); whiles.push(here()); imm(0x10, 0); }
else if ("jump0".equals(token)) { imm(0xB0, value()); }
else if ("jump".equals(token)) { imm(0x10, value()); }
else if ("draw".equals(token)) { inst(0xD0 | reg(), (reg() << 4) | value()); }
else if ("again".equals(token)) {
imm(0x10, loops.pop());
Expand Down Expand Up @@ -189,4 +191,4 @@ else if (Character.isWhitespace(c)) {
parseToken(t, ret);
return ret;
}
}
}

0 comments on commit 035dea8

Please sign in to comment.