From b3615832527c0479dbd15169f81e535cfd86416f Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 27 Nov 2018 13:52:00 -0500 Subject: [PATCH] Added memory location option for LiDAR GET_PATH. Fixes #140 --- .../main/java/net/simon987/cubotplugin/CubotLidar.java | 10 ++-------- .../java/net/simon987/server/assembly/Assembler.java | 6 +++--- Server/src/main/resources/config.properties | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java index 23ec707..04c1093 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java @@ -5,7 +5,6 @@ import net.simon987.server.assembly.Status; import net.simon987.server.game.objects.ControllableUnit; import net.simon987.server.game.pathfinding.Node; import net.simon987.server.game.pathfinding.Pathfinder; -import net.simon987.server.logging.LogManager; import org.bson.Document; import java.util.ArrayList; @@ -25,8 +24,6 @@ public class CubotLidar extends CubotHardwareModule { private static final int LIDAR_GET_WORLD_POS = 4; private static final int LIDAR_GET_WORLD_SIZE = 5; - private static final int MEMORY_PATH_START = 0x0000; - public CubotLidar(Cubot cubot) { super(cubot); } @@ -52,6 +49,7 @@ public class CubotLidar extends CubotHardwareModule { break; case LIDAR_GET_PATH: if (cubot.spendEnergy(50)) { + int c = getCpu().getRegisterSet().getRegister("C").getValue(); int b = getCpu().getRegisterSet().getRegister("B").getValue(); int destX = getCpu().getRegisterSet().getRegister("X").getValue(); int destY = getCpu().getRegisterSet().getRegister("Y").getValue(); @@ -63,7 +61,7 @@ public class CubotLidar extends CubotHardwareModule { //Write to memory Memory mem = getCpu().getMemory(); - int counter = MEMORY_PATH_START; + int counter = c; if (nodes != null) { @@ -71,7 +69,6 @@ public class CubotLidar extends CubotHardwareModule { for (Node n : nodes) { //Store the path as a sequence of directions - if (lastNode == null) { lastNode = n; continue; @@ -100,8 +97,6 @@ public class CubotLidar extends CubotHardwareModule { //Indicate invalid path 0xFFFF mem.set(counter, 0xFFFF); } - - LogManager.LOGGER.fine("DEBUG: path to" + destX + "," + destY); } break; @@ -118,7 +113,6 @@ public class CubotLidar extends CubotHardwareModule { } } } - break; case LIDAR_GET_WORLD_SIZE: diff --git a/Server/src/main/java/net/simon987/server/assembly/Assembler.java b/Server/src/main/java/net/simon987/server/assembly/Assembler.java index 922f0b9..e3d3941 100755 --- a/Server/src/main/java/net/simon987/server/assembly/Assembler.java +++ b/Server/src/main/java/net/simon987/server/assembly/Assembler.java @@ -540,9 +540,10 @@ public class Assembler { } //Check operands and encode instruction + final int beginIndex = line.indexOf(mnemonic) + mnemonic.length(); if (line.contains(",")) { //2 operands - String strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length(), line.indexOf(',')); + String strO1 = line.substring(beginIndex, line.indexOf(',')); String strO2 = line.substring(line.indexOf(',')); Operand o1, o2; @@ -562,7 +563,7 @@ public class Assembler { } else if (tokens.length > 1) { //1 operand - String strO1 = line.substring(line.indexOf(mnemonic) + mnemonic.length()); + String strO1 = line.substring(beginIndex); Operand o1; if (assumeLabels) { @@ -583,6 +584,5 @@ public class Assembler { } return out.toByteArray(); - } } diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 781ead3..d8d8818 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -9,7 +9,7 @@ keyStore_password= #Server mar_address=ws://localhost:4567/socket server_name=MAR dev -# ALLOW | TEMPORARY | BLOCK +# ALLOW | BLOCK guest_policy=ALLOW #Database