From 0fee35baec45706a5e44bd63e882b4dbd8668573 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 28 Dec 2017 22:35:49 -0500 Subject: [PATCH] Fixes #53 --- .../java/net/simon987/cubotplugin/Cubot.java | 18 ++++++++++ .../simon987/cubotplugin/CubotHologram.java | 34 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index 4fbb1fe..c2d871f 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -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 + } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java index d5172c4..7e07839 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java @@ -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); + } }