From 4dcba6b3d24fb7f0d39c335b91e194e177c4edac Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 23 Jan 2025 15:33:46 +0100 Subject: [PATCH] Added untested worm bit size check and added missing octal shifts --- .../fc18/zion7/FourCornerZionStenoLexer.java | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java index d8a0042..6166e47 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java @@ -304,14 +304,16 @@ public class FourCornerZionStenoLexer { if (lexer.sandwormSign) { lexer.smokeSignals.burnSandWormSignUnused(lexer.sandwormSignLine, lexer.sandwormSignColumn); } + int bitSize = 0; int bitIdxLast = 0; int[] sandWalking = new int[576]; for (int i = idxFirst; i <= idxLast; i++) { int bitIdx = lexer.input.get(i); - if (bitIdx < bitIdxLast) { + if (bitIdx != 0 && bitIdx < bitIdxLast) { lexer.smokeSignals.burnSandWormSignOutOfOrder(lexer.currLine, lexer.currCol); return; } + bitSize++; bitIdxLast = bitIdx; int bitOff = bitIdx - FourCornerDotCake.FC_SAND_OLGOI.getStart(); sandWalking[bitOff] = 1; @@ -320,7 +322,12 @@ public class FourCornerZionStenoLexer { PrimitiveIterator.OfInt i = Arrays.stream(sandWalking).iterator(); int octalIdx = 2; int octalValue = 0; + int bitSizeCounter = 0; while (i.hasNext()) { + if (bitSizeCounter > bitSize) { + break; // the sand walk bit pulses are always full size + } + bitSizeCounter++; int bitValue = i.nextInt(); octalValue += bitValue << octalIdx; if (octalIdx > 0) { @@ -366,21 +373,21 @@ public class FourCornerZionStenoLexer { int octal2 = 0; int octal1 = 0; int octal0 = 0; - octal4 += (bitValue15 >> 14) & 0b1; - octal4 += (bitValue15 >> 13) & 0b1; - octal4 += (bitValue15 >> 12) & 0b1; - octal3 += (bitValue15 >> 11) & 0b1; - octal3 += (bitValue15 >> 10) & 0b1; - octal3 += (bitValue15 >> 9) & 0b1; - octal2 += (bitValue15 >> 8) & 0b1; - octal2 += (bitValue15 >> 7) & 0b1; - octal2 += (bitValue15 >> 6) & 0b1; - octal1 += (bitValue15 >> 5) & 0b1; - octal1 += (bitValue15 >> 4) & 0b1; - octal1 += (bitValue15 >> 3) & 0b1; - octal0 += (bitValue15 >> 2) & 0b1; - octal0 += (bitValue15 >> 1) & 0b1; - octal0 += (bitValue15 >> 0) & 0b1; + octal4 += ((bitValue15 >> 14) & 0b1) << 2; + octal4 += ((bitValue15 >> 13) & 0b1) << 1; + octal4 += ((bitValue15 >> 12) & 0b1) << 0; + octal3 += ((bitValue15 >> 11) & 0b1) << 2; + octal3 += ((bitValue15 >> 10) & 0b1) << 1; + octal3 += ((bitValue15 >> 9) & 0b1) << 0; + octal2 += ((bitValue15 >> 8) & 0b1) << 2; + octal2 += ((bitValue15 >> 7) & 0b1) << 1; + octal2 += ((bitValue15 >> 6) & 0b1) << 0; + octal1 += ((bitValue15 >> 5) & 0b1) << 2; + octal1 += ((bitValue15 >> 4) & 0b1) << 1; + octal1 += ((bitValue15 >> 3) & 0b1) << 0; + octal0 += ((bitValue15 >> 2) & 0b1) << 2; + octal0 += ((bitValue15 >> 1) & 0b1) << 1; + octal0 += ((bitValue15 >> 0) & 0b1) << 0; wormBody.add(octal4); wormBody.add(octal3); wormBody.add(octal2);