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 ef1ceb3..d8a0042 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 @@ -24,8 +24,11 @@ package org.x4o.fc18.zion7; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.PrimitiveIterator; import org.x4o.fc18.cake2.FourCornerDotCake; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; @@ -52,6 +55,10 @@ public class FourCornerZionStenoLexer { private final List scanners = new ArrayList<>(); // TODO: make static is WIP private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group private final int numeratorBank[] = new int[denominatorBank.length]; + private final List sandwormHead = new ArrayList<>(); + private boolean sandwormSign = false; + private int sandwormSignLine = 0; + private int sandwormSignColumn = 0; private List input; private int inputIndex = 0; private int currLine = 0; @@ -163,6 +170,9 @@ public class FourCornerZionStenoLexer { smokeSignals.burnUnsupported(currLine, currCol, input.get(inputIndex)); } } + if (sandwormSign) { + smokeSignals.burnSandWormSignUnused(sandwormSignLine, sandwormSignColumn); + } handlerDocument.strobeDocumentOmega(); } @@ -283,12 +293,54 @@ public class FourCornerZionStenoLexer { static class StenoScannerSandOlgoi extends StenoScanner { + private static final List WORM_SIGN = List.of(24,48,96,192);// TODO: add missing here + cake doc as it grows per 72 bit slug + public StenoScannerSandOlgoi() { super(FourCornerDotCake.FC_SAND_OLGOI); } @Override public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) { + if (lexer.sandwormSign) { + lexer.smokeSignals.burnSandWormSignUnused(lexer.sandwormSignLine, lexer.sandwormSignColumn); + } + int bitIdxLast = 0; + int[] sandWalking = new int[576]; + for (int i = idxFirst; i <= idxLast; i++) { + int bitIdx = lexer.input.get(i); + if (bitIdx < bitIdxLast) { + lexer.smokeSignals.burnSandWormSignOutOfOrder(lexer.currLine, lexer.currCol); + return; + } + bitIdxLast = bitIdx; + int bitOff = bitIdx - FourCornerDotCake.FC_SAND_OLGOI.getStart(); + sandWalking[bitOff] = 1; + } + lexer.sandwormHead.clear(); + PrimitiveIterator.OfInt i = Arrays.stream(sandWalking).iterator(); + int octalIdx = 2; + int octalValue = 0; + while (i.hasNext()) { + int bitValue = i.nextInt(); + octalValue += bitValue << octalIdx; + if (octalIdx > 0) { + octalIdx--; + continue; + } + lexer.sandwormHead.add(octalValue); + octalIdx = 2; + octalValue = 0; + } + int wormHeadSize = lexer.sandwormHead.size(); + if (WORM_SIGN.contains(wormHeadSize)) { + lexer.sandwormSign = true; + lexer.sandwormSignLine = lexer.currLine; + lexer.sandwormSignColumn = lexer.currCol; + lexer.fireSignals.fireStateSandWormSign(wormHeadSize); + return; // Sand walking signal pulses have been stamped correctly to call the worm + } + lexer.sandwormHead.clear(); + lexer.smokeSignals.burnSandWormSignIncorrect(lexer.currLine, lexer.currCol, wormHeadSize); } } @@ -300,11 +352,42 @@ public class FourCornerZionStenoLexer { @Override public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) { - } - - private void handlePoints(FourCornerZionStenoLexer lexer, List slicedPoints) { - // TODO: convert from 15 bit to 3 bit - lexer.handler.strobeSandWorm(null, slicedPoints); + lexer.sandwormSign = false; + List wormBody15 = new ArrayList<>(); + for (int i = idxFirst; i <= idxLast; i++) { + wormBody15.add(lexer.input.get(i)); + } + List wormBody = new ArrayList<>(); + Iterator i15 = wormBody15.iterator(); + while (i15.hasNext()) { + int bitValue15 = i15.next(); + int octal4 = 0; + int octal3 = 0; + 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; + wormBody.add(octal4); + wormBody.add(octal3); + wormBody.add(octal2); + wormBody.add(octal1); + wormBody.add(octal0); + } + lexer.handler.strobeSandWorm(lexer.sandwormHead, wormBody); } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerFire.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerFire.java index cb6ea6d..7ee8805 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerFire.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerFire.java @@ -38,6 +38,8 @@ public interface FourCornerZionStenoLexerFire { void fireStateNCR1632BankReset(boolean magic); + void fireStateSandWormSign(int size); + interface Adapter extends FourCornerZionStenoLexerFire { @Override @@ -59,5 +61,9 @@ public interface FourCornerZionStenoLexerFire { @Override default void fireStateNCR1632BankReset(boolean magic) { } + + @Override + default void fireStateSandWormSign(int size) { + } } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java index 4bd9d68..abe5e95 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java @@ -41,6 +41,13 @@ public interface FourCornerZionStenoLexerSmoke { void burnUNI21UnusedBigIndian(int line, int col); + void burnSandWormSignOutOfOrder(int line, int col); + + void burnSandWormSignIncorrect(int line, int col, int size); + + void burnSandWormSignUnused(int line, int col); + + interface Adapter extends FourCornerZionStenoLexerSmoke { @Override @@ -62,5 +69,17 @@ public interface FourCornerZionStenoLexerSmoke { @Override default void burnUNI21UnusedBigIndian(int line, int col) { } + + @Override + default void burnSandWormSignOutOfOrder(int line, int col) { + } + + @Override + default void burnSandWormSignIncorrect(int line, int col, int size) { + } + + @Override + default void burnSandWormSignUnused(int line, int col) { + } } }