This commit is contained in:
simon 2017-12-28 22:35:49 -05:00
parent 2fb7d2f73e
commit 0fee35baec
2 changed files with 51 additions and 1 deletions

View File

@ -14,6 +14,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public static final int ID = 1;
private char hologram = 0;
private String hologramString = "";
private HologramMode hologramMode = HologramMode.CLEARED;
private char lastHologram = 0;
/**
@ -86,6 +89,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
json.put("hp", hp);
json.put("action", lastAction.ordinal());
json.put("holo", (int) lastHologram);
json.put("holoStr", hologramString);
json.put("holoMode", hologramMode.ordinal());
json.put("energy", energy);
if (parent != null) {
@ -161,6 +166,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
return lastHologram;
}
public void setHologramString(String hologramString) {
this.hologramString = hologramString;
}
public int getEnergy() {
return energy;
@ -210,4 +218,14 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public boolean isAt(int x, int y) {
return false;
}
public void setHologramMode(HologramMode hologramMode) {
this.hologramMode = hologramMode;
}
public enum HologramMode {
CLEARED,
HEX,
STRING
}
}

View File

@ -17,6 +17,12 @@ public class CubotHologram extends CpuHardware {
private Cubot cubot;
private static final int CLEAR = 0;
private static final int DISPLAY_HEX = 1;
private static final int DISPLAY_STRING = 2;
private static final int STR_MAX_LEN = 8;
public CubotHologram(Cubot cubot) {
this.cubot = cubot;
}
@ -25,7 +31,33 @@ public class CubotHologram extends CpuHardware {
public void handleInterrupt(Status status) {
char a = getCpu().getRegisterSet().getRegister("A").getValue();
cubot.setHologram(a);
if (a == CLEAR) {
cubot.setHologramMode(Cubot.HologramMode.CLEARED);
} else if (a == DISPLAY_HEX) {
char b = getCpu().getRegisterSet().getRegister("B").getValue();
cubot.setHologram(b);
cubot.setHologramMode(Cubot.HologramMode.HEX);
} else if (a == DISPLAY_STRING) {
char x = getCpu().getRegisterSet().getRegister("X").getValue();
//Display zero-terminated string starting at X (max 8 chars)
StringBuilder holoString = new StringBuilder();
for (int i = 0; i < STR_MAX_LEN; i++) {
char nextChar = (char) getCpu().getMemory().get(x + i);
if (nextChar != 0) {
holoString.append((char) getCpu().getMemory().get(x + i));
} else {
break;
}
}
cubot.setHologramString(holoString.toString());
cubot.setHologramMode(Cubot.HologramMode.STRING);
}
}