FC18: Moved write logic to steno grapher

This commit is contained in:
Willem Cazander 2025-08-24 20:17:40 +02:00
parent 586b5f9fe3
commit 4c7355b65d
8 changed files with 345 additions and 360 deletions

View file

@ -24,19 +24,13 @@ package org.x4o.fc18;
import java.math.BigInteger;
import java.util.ArrayList;
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.pie9c.FCDotPIE9CDash10;
import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash11;
import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash20;
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
import org.x4o.fc18.octal8.PrimordialOctal;
import org.x4o.fc18.zion7.FourCornerZion7SalahSequence;
/// Holds different lookup and conversion maps towards four corner int18 cake points.
///
@ -44,266 +38,9 @@ import org.x4o.fc18.zion7.FourCornerZion7SalahSequence;
/// @version 1.0 Jan 09, 2025
final public class FourCornerRecipe {
public static final BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF);
public static final BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
public static final List<Integer> SAND_WORM_SIGN = List.of(24,48,72,96,120,144,168,192);
private FourCornerRecipe() {
}
static public List<Integer> embedSalahSequenceX06(FourCornerZion7SalahSequence type, List<List<Integer>> arguments) {
return embedSalahSequence(new ArrayList<>(), type, arguments, true);
}
static public List<Integer> embedSalahSequenceX18(FourCornerZion7SalahSequence type, List<List<Integer>> arguments) {
return embedSalahSequence(new ArrayList<>(), type, arguments, false);
}
static public List<Integer> embedSalahSequenceX06(List<Integer> out, FourCornerZion7SalahSequence type, List<List<Integer>> arguments) {
return embedSalahSequence(out, type, arguments, true);
}
static public List<Integer> embedSalahSequenceX18(List<Integer> out, FourCornerZion7SalahSequence type, List<List<Integer>> arguments) {
return embedSalahSequence(out, type, arguments, false);
}
static private List<Integer> embedSalahSequence(List<Integer> out, FourCornerZion7SalahSequence type, List<List<Integer>> arguments, boolean isSixBit) {
Objects.requireNonNull(type);
Objects.requireNonNull(arguments);
if (FourCornerZion7SalahSequence.ESC_VT06.equals(type)) {
if (isSixBit) {
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.baklavaPointSequence());
} else {
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.cakePointSequence());
}
} else {
if (isSixBit) {
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).baklavaPointSequence());
} else {
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).cakePointSequence());
}
}
Iterator<List<Integer>> argu = arguments.iterator();
while (argu.hasNext()) {
List<Integer> arguValue = argu.next();
out.addAll(arguValue); // TODO: add range check
if (argu.hasNext()) {
out.add(FCDotCDC1604DashP6._RAKA_QUESTION.baklavaPointDotIndex());
}
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.baklavaPointDotIndex());
return out;
}
static public List<Integer> embedSandWalkerX06(List<PrimordialOctal> rhythm) {
return embedSandWalkerX06(new ArrayList<>(), rhythm);
}
static public List<Integer> embedSandWalkerX06(List<Integer> out, List<PrimordialOctal> rhythm) {
Objects.requireNonNull(rhythm);
if (!FourCornerRecipe.SAND_WORM_SIGN.contains(rhythm.size())) {
throw new IllegalArgumentException("Sand walker rhythm is not 72 bit aligned: " + rhythm.size());
}
out.add(FCDotDEC2701DashPX0.ESC_SAND_WALKER.cakePointDotIndex());
for (int i = 192 - 1; i >= 0; i--) {
if (rhythm.size() <= i) {
continue;
}
PrimordialOctal octal = rhythm.get(i);
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return out;
}
static public List<Integer> embedSandWormX06(List<PrimordialOctal> spice) {
return embedSandWormX06(new ArrayList<>(), spice);
}
static public List<Integer> embedSandWormX06(List<Integer> out, List<PrimordialOctal> spice) {
Objects.requireNonNull(spice);
out.add(FCDotDEC2701DashPX0.ESC68_SAND_WORM.cakePointDotIndex());
for (int i = spice.size(); i >= 0; i--) {
PrimordialOctal octal = spice.get(i);
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return out;
}
static public List<Integer> embedSandWormX18(List<PrimordialOctal> spice) {
return embedSandWormX18(new ArrayList<>(), spice);
}
static public List<Integer> embedSandWormX18(List<Integer> out, List<PrimordialOctal> spice) {
Objects.requireNonNull(spice);
Iterator<PrimordialOctal> spiceItr = spice.iterator();
while (spiceItr.hasNext()) {
PrimordialOctal octal4 = spiceItr.next();
PrimordialOctal octal3 = spiceItr.next();
PrimordialOctal octal2 = spiceItr.next();
PrimordialOctal octal1 = spiceItr.next();
PrimordialOctal octal0 = spiceItr.next();
int bitValue15 = 0;
bitValue15 += (octal4.ordinal() << 12);
bitValue15 += (octal3.ordinal() << 9);
bitValue15 += (octal2.ordinal() << 6);
bitValue15 += (octal1.ordinal() << 3);
bitValue15 += (octal0.ordinal() << 0);
out.add(FourCornerDotCake.FC_SANDWORM_15.getStart() + bitValue15);
}
return out;
}
static public List<Integer> embedNCR1632FractionX06(BigInteger denominator, BigInteger numerator) {
return embedNCR1632FractionX18(new ArrayList<>(), denominator, numerator);
}
static public List<Integer> embedNCR1632FractionX06(List<Integer> out, BigInteger denominator, BigInteger numerator) {
if (denominator.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The denominator value ZERO is not allowed.");
}
if (numerator.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The numerator value ZERO is not allowed.");
}
//if (denominator.signum() == -1) {
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
//}
if (denominator.compareTo(NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value denominator is larger than 576 bit: " + denominator);
}
if (numerator.compareTo(NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value numerator is larger than 576 bit: " + numerator);
}
out.addAll(FCDotDEC2701DashPX0.ESC68_NCR.baklavaPointSequence());
// NX01-NX08 are octals
// DEN: NY01 = page MSB, NY02 = page LSB, NY03 = value MSB, NY04 = value CSB, NY05 = value LSB
// NUM: NY06 = page MSB, NY07 = page LSB, NY08 = value MSB, NY09 = value CSB, NY10 = value LSB
BigInteger denominatorZero = denominator.subtract(BigInteger.ONE);
BigInteger numeratorZero = numerator.subtract(BigInteger.ONE);
if (denominatorZero.equals(BigInteger.ZERO)) {
out.add(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = denominatorZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int pageMSB = (i >> 3) & 0b111;
int pageLSB = (i >> 0) & 0b111;
int valueMSB = (bankValue >> 6) & 0b111;
int valueCSB = (bankValue >> 3) & 0b111;
int valueLSB = (bankValue >> 0) & 0b111;
if (pageMSB > 0) {
out.add(FCDotCDC1604DashP6.NY01_AT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
}
if (pageLSB > 0) {
out.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
}
if (valueMSB > 0) {
out.add(FCDotCDC1604DashP6.NY03_BAR_V_LEFT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
}
if (valueCSB > 0) {
out.add(FCDotCDC1604DashP6.NY04_BAR_UNDER.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
}
out.add(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
}
}
if (numeratorZero.equals(BigInteger.ZERO)) {
out.add(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = numeratorZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int pageMSB = (i >> 3) & 0b111;
int pageLSB = (i >> 0) & 0b111;
int valueMSB = (bankValue >> 6) & 0b111;
int valueCSB = (bankValue >> 3) & 0b111;
int valueLSB = (bankValue >> 0) & 0b111;
if (pageMSB > 0) {
out.add(FCDotCDC1604DashP6.NY06_PERCENT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
}
if (pageLSB > 0) {
out.add(FCDotCDC1604DashP6.NY07_DOLLAR.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
}
if (valueMSB > 0) {
out.add(FCDotCDC1604DashP6.NY08_HASH.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
}
if (valueCSB > 0) {
out.add(FCDotCDC1604DashP6.NY09_EQUALS.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
}
out.add(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
}
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return out;
}
static public List<Integer> embedNCR1632FractionX18(BigInteger denominator, BigInteger numerator) {
return embedNCR1632FractionX18(new ArrayList<>(), denominator, numerator);
}
static public List<Integer> embedNCR1632FractionX18(List<Integer> out, BigInteger denominator, BigInteger numerator) {
if (denominator.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The denominator value ZERO is not allowed.");
}
if (numerator.equals(BigInteger.ZERO)) { // TODO: rm this and make both zero based, 0/1 = zero
throw new IllegalArgumentException("The numerator value ZERO is not allowed.");
}
//if (denominator.signum() == -1) {
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
//}
if (denominator.compareTo(NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value denominator is larger than 576 bit: " + denominator);
}
if (numerator.compareTo(NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value numerator is larger than 576 bit: " + numerator);
}
BigInteger denominatorZero = denominator.subtract(BigInteger.ONE);
BigInteger numeratorZero = numerator.subtract(BigInteger.ONE);
if (denominatorZero.equals(BigInteger.ZERO)) {
out.add(FourCornerDotCake.FC_NCR1632_DEN.getStart());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = denominatorZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int cakePoint = FourCornerDotCake.FC_NCR1632_DEN.getStart() + bankValue + (i * 512);
out.add(cakePoint);
}
}
if (numeratorZero.equals(BigInteger.ZERO)) {
out.add(FourCornerDotCake.FC_NCR1632_NUM.getStart());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = numeratorZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int cakePoint = FourCornerDotCake.FC_NCR1632_NUM.getStart() + bankValue + (i * 512);
out.add(cakePoint);
}
}
return out;
}
static public List<Integer> toScriptSuperX06(int value) {
return toScript(new ArrayList<>(), Integer.toString(value), 0, true);
}
@ -439,9 +176,10 @@ final public class FourCornerRecipe {
}
}
}
if (isSixBit) {
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex()); // fixme improve: see FourCornerDotCollePie9.baklavaPointsPIE9C
}
// fixme
//if (isSixBit) {
// out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex()); // fixme improve: see FourCornerDotCollePie9.baklavaPointsPIE9C
//}
return out;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2004-2014, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.fc18.zion7;
import java.math.BigInteger;
import java.util.List;
/// Rock carvings of special variables.
///
/// @author Willem Cazander
/// @version 1.0 Aug 24, 2025
public final class FourCornerZion7Petroglyphs {
public static final BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF);
public static final BigInteger NCR1632_VALUE_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
public static final List<Integer> SAND_WORM_SIGN = List.of(24,48,72,96,120,144,168,192);
private FourCornerZion7Petroglyphs() {
}
}

View file

@ -23,10 +23,13 @@
package org.x4o.fc18.zion7;
import java.math.BigInteger;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import org.x4o.fc18.FourCornerRecipe;
import org.x4o.fc18.cake2.FourCornerDotCake;
import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
import org.x4o.fc18.octal8.PrimordialOctal;
import org.x4o.fc18.octal8.PrimordialOctalOrangeJuice;
@ -43,7 +46,7 @@ public class FourCornerZionStenoGrapher {
static public FourCornerZion7TempleScrolls writerX18(List<Integer> out) {
return new FourCornerWriter(out, false);
}
static public final class FourCornerWriter implements FourCornerZion7Candlelier,FourCornerZion7TempleScrolls {
private final List<Integer> out;
@ -83,40 +86,201 @@ public class FourCornerZionStenoGrapher {
@Override
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
if (denominator.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The denominator value ZERO is not allowed.");
}
if (numerator.equals(BigInteger.ZERO)) { // TODO: rm this and make both zero based, 0/1 = zero
throw new IllegalArgumentException("The numerator value ZERO is not allowed.");
}
//if (denominator.signum() == -1) {
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
//}
if (denominator.compareTo(FourCornerZion7Petroglyphs.NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value denominator is larger than 576 bit: " + denominator);
}
if (numerator.compareTo(FourCornerZion7Petroglyphs.NCR1632_VALUE_MAX) > 0) { // fixme: this is still one off...
throw new IllegalArgumentException("Value numerator is larger than 576 bit: " + numerator);
}
BigInteger denominatorZero = denominator.subtract(BigInteger.ONE);
BigInteger numeratorZero = numerator.subtract(BigInteger.ONE);
if (isSixBit) {
FourCornerRecipe.embedNCR1632FractionX06(out, denominator, numerator);
out.addAll(FCDotDEC2701DashPX0.ESC68_NCR.baklavaPointSequence());
if (denominatorZero.equals(BigInteger.ZERO)) {
out.add(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = denominatorZero.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int pageMSB = (i >> 3) & 0b111;
int pageLSB = (i >> 0) & 0b111;
int valueMSB = (bankValue >> 6) & 0b111;
int valueCSB = (bankValue >> 3) & 0b111;
int valueLSB = (bankValue >> 0) & 0b111;
if (pageMSB > 0) {
out.add(FCDotCDC1604DashP6.NY01_AT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
}
if (pageLSB > 0) {
out.add(FCDotCDC1604DashP6.NY02_BAR_V_RIGHT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
}
if (valueMSB > 0) {
out.add(FCDotCDC1604DashP6.NY03_BAR_V_LEFT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
}
if (valueCSB > 0) {
out.add(FCDotCDC1604DashP6.NY04_BAR_UNDER.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
}
out.add(FCDotCDC1604DashP6.NY05_BAR_VERTICAL.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
}
}
if (numeratorZero.equals(BigInteger.ZERO)) {
out.add(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = numeratorZero.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int pageMSB = (i >> 3) & 0b111;
int pageLSB = (i >> 0) & 0b111;
int valueMSB = (bankValue >> 6) & 0b111;
int valueCSB = (bankValue >> 3) & 0b111;
int valueLSB = (bankValue >> 0) & 0b111;
if (pageMSB > 0) {
out.add(FCDotCDC1604DashP6.NY06_PERCENT.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageMSB);
}
if (pageLSB > 0) {
out.add(FCDotCDC1604DashP6.NY07_DOLLAR.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + pageLSB);
}
if (valueMSB > 0) {
out.add(FCDotCDC1604DashP6.NY08_HASH.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueMSB);
}
if (valueCSB > 0) {
out.add(FCDotCDC1604DashP6.NY09_EQUALS.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueCSB);
}
out.add(FCDotCDC1604DashP6.NY10_CARET.baklavaPointDotIndex());
out.add(FCDotCDC1604DashP6.NX01_A.baklavaPointDotIndex() + valueLSB);
}
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return;
}
if (denominatorZero.equals(BigInteger.ZERO)) {
out.add(FourCornerDotCake.FC_NCR1632_DEN.getStart());
} else {
FourCornerRecipe.embedNCR1632FractionX18(out, denominator, numerator);
for (int i = 63; i >= 0; i--) {
int bankValue = denominatorZero.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int cakePoint = FourCornerDotCake.FC_NCR1632_DEN.getStart() + bankValue + (i * 512);
out.add(cakePoint);
}
}
if (numeratorZero.equals(BigInteger.ZERO)) {
out.add(FourCornerDotCake.FC_NCR1632_NUM.getStart());
} else {
for (int i = 63; i >= 0; i--) {
int bankValue = numeratorZero.shiftRight(i * 9).and(FourCornerZion7Petroglyphs.NCR1632_MASK_PAGE).intValue();
if (bankValue == 0) {
continue;
}
int cakePoint = FourCornerDotCake.FC_NCR1632_NUM.getStart() + bankValue + (i * 512);
out.add(cakePoint);
}
}
}
@Override
public void strobeSandWalker(List<PrimordialOctal> rhythm) {
Objects.requireNonNull(rhythm);
//if (isSixBit) {
FourCornerRecipe.embedSandWalkerX06(out, rhythm);
//} else {
// FourCornerRecipe.embedSandWalkerX18(out, rhythm); // mmm bring back...
if (!FourCornerZion7Petroglyphs.SAND_WORM_SIGN.contains(rhythm.size())) {
throw new IllegalArgumentException("Sand walker rhythm is not 72 bit aligned: " + rhythm.size());
}
out.add(FCDotDEC2701DashPX0.ESC_SAND_WALKER.cakePointDotIndex());
for (int i = 192 - 1; i >= 0; i--) {
if (rhythm.size() <= i) {
continue;
}
PrimordialOctal octal = rhythm.get(i);
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return;
//}
// todo bring back native 18 bit sand walking if space allow (for adult rule)
}
@Override
public void strobeSandWorm(List<PrimordialOctal> spice) {
Objects.requireNonNull(spice);
if (isSixBit) {
FourCornerRecipe.embedSandWormX06(out, spice);
} else {
FourCornerRecipe.embedSandWormX18(out, spice);
out.add(FCDotDEC2701DashPX0.ESC68_SAND_WORM.cakePointDotIndex());
for (int i = spice.size(); i >= 0; i--) {
PrimordialOctal octal = spice.get(i);
out.add(FCDotCDC1604DashP6.NX01_A.cakePointDotIndex() + octal.ordinal());
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.cakePointDotIndex());
return;
}
Iterator<PrimordialOctal> spiceItr = spice.iterator();
while (spiceItr.hasNext()) {
PrimordialOctal octal4 = spiceItr.next();
PrimordialOctal octal3 = spiceItr.next();
PrimordialOctal octal2 = spiceItr.next();
PrimordialOctal octal1 = spiceItr.next();
PrimordialOctal octal0 = spiceItr.next();
int bitValue15 = 0;
bitValue15 += (octal4.ordinal() << 12);
bitValue15 += (octal3.ordinal() << 9);
bitValue15 += (octal2.ordinal() << 6);
bitValue15 += (octal1.ordinal() << 3);
bitValue15 += (octal0.ordinal() << 0);
out.add(FourCornerDotCake.FC_SANDWORM_15.getStart() + bitValue15);
}
}
@Override
public void strobeSalahSequence(FourCornerZion7SalahSequence type, List<List<Integer>> arguments) {
if (isSixBit) {
FourCornerRecipe.embedSalahSequenceX06(out, type, arguments);
Objects.requireNonNull(type);
Objects.requireNonNull(arguments);
if (FourCornerZion7SalahSequence.ESC_VT06.equals(type)) {
if (isSixBit) {
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.baklavaPointSequence());
} else {
out.addAll(FCDotDEC2701DashPX0.ESC_VT06.cakePointSequence());
}
} else {
FourCornerRecipe.embedSalahSequenceX18(out, type, arguments);
if (isSixBit) {
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).baklavaPointSequence());
} else {
out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).cakePointSequence());
}
}
Iterator<List<Integer>> argu = arguments.iterator();
while (argu.hasNext()) {
List<Integer> arguValue = argu.next();
out.addAll(arguValue); // TODO: add range check
if (argu.hasNext()) {
out.add(FCDotCDC1604DashP6._RAKA_QUESTION.baklavaPointDotIndex());
}
}
out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.baklavaPointDotIndex());
}
}
}

View file

@ -764,7 +764,7 @@ public class FourCornerZionStenoLexer {
return true;
}
if (FCDotCDC1604DashP6._SALAH_EXCLAMATION.ordinal() == cdcPoint) {
if (!FourCornerRecipe.SAND_WORM_SIGN.contains(rhythm.size())) {
if (!FourCornerZion7Petroglyphs.SAND_WORM_SIGN.contains(rhythm.size())) {
lexer.smokeSignals.burnSandWalkerStepUnaligned(lexer.currLine, lexer.currCol, cdcPoint);
} else {
lexer.handler.strobeSandWalker(rhythm);

View file

@ -22,14 +22,6 @@
*/
package org.x4o.fc18;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.x4o.fc18.octal8.PrimordialOctal;
/**
* Tests FourCornerRecipe methods.
*
@ -38,73 +30,4 @@ import org.x4o.fc18.octal8.PrimordialOctal;
*/
public class FourCornerRecipeTest {
@Test
public void testSandWalker() throws Exception {
List<Integer> cdc = new ArrayList<>();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedSandWalkerX06(cdc, List.of(PrimordialOctal.PART_1));
});
List<PrimordialOctal> octalMine = new ArrayList<>();
for (int i=0;i<24;i++) {
octalMine.add(PrimordialOctal.PART_1);
}
FourCornerRecipe.embedSandWalkerX06(cdc, octalMine);
String res = FourCornerUnicodeDisplay.text().renderFromInt18(cdc);
Assertions.assertTrue(res.endsWith("PART_1PART_1"), "missing " + res);
}
@Test
public void testNCRValues() throws Exception {
List<Integer> cdcX06 = new ArrayList<>();
List<Integer> cdcX18 = new ArrayList<>();
BigInteger v1 = BigInteger.valueOf(123);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v1, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v1, BigInteger.ONE);
BigInteger v2 = BigInteger.valueOf(12345);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v2, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v2, BigInteger.ONE);
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertEquals("¹/₁₂₃¹/₁₂₃₄₅", resX06);
}
@Test
public void testNCRCount1024() throws Exception {
List<Integer> cdcX06 = new ArrayList<>();
List<Integer> cdcX18 = new ArrayList<>();
for (int x = 1; x <= 1025; x++) {
BigInteger v = BigInteger.valueOf(x);
FourCornerRecipe.embedNCR1632FractionX06(cdcX06, v, BigInteger.ONE);
FourCornerRecipe.embedNCR1632FractionX18(cdcX18, v, BigInteger.ONE);
}
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(cdcX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertTrue(resX06.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX06);
Assertions.assertTrue(resX06.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX06);
Assertions.assertTrue(resX06.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX06);
Assertions.assertTrue(resX18.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX18);
Assertions.assertTrue(resX18.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX18);
Assertions.assertTrue(resX18.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX18);
}
@Test
public void testNCRMaxValue() throws Exception {
BigInteger maxValue = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
FourCornerRecipe.embedNCR1632FractionX06(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX06(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX06(maxValue, maxValue.add(BigInteger.ONE));
});
FourCornerRecipe.embedNCR1632FractionX18(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX18(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
FourCornerRecipe.embedNCR1632FractionX18(maxValue, maxValue.add(BigInteger.ONE));
});
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2004-2014, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.fc18.zion7;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.x4o.fc18.FourCornerUnicodeDisplay;
import org.x4o.fc18.octal8.PrimordialOctal;
/**
* Tests four corner grapher parts.
*
* @author Willem Cazander
* @version 1.0 Aug 24, 2025
*/
public class StenoGrapherTest {
@Test
public void testSandWalker() throws Exception {
List<Integer> out = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(out);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeSandWalker(List.of(PrimordialOctal.PART_1));
});
List<PrimordialOctal> octalMine = new ArrayList<>();
for (int i=0;i<24;i++) {
octalMine.add(PrimordialOctal.PART_1);
}
writerX06.strobeSandWalker(octalMine);
String res = FourCornerUnicodeDisplay.text().renderFromInt18(out);
Assertions.assertTrue(res.endsWith("PART_1PART_1"), "missing " + res);
}
@Test
public void testNCRValues() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
BigInteger v1 = BigInteger.valueOf(123);
writerX06.strobeNCR1632(v1, BigInteger.ONE);
writerX18.strobeNCR1632(v1, BigInteger.ONE);
BigInteger v2 = BigInteger.valueOf(12345);
writerX06.strobeNCR1632(v2, BigInteger.ONE);
writerX18.strobeNCR1632(v2, BigInteger.ONE);
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(outX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(outX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertEquals("¹/₁₂₃¹/₁₂₃₄₅", resX06);
}
@Test
public void testNCRCount1024() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
for (int x = 1; x <= 1025; x++) {
BigInteger v = BigInteger.valueOf(x);
writerX06.strobeNCR1632(v, BigInteger.ONE);
writerX18.strobeNCR1632(v, BigInteger.ONE);
}
String resX06 = FourCornerUnicodeDisplay.text().renderFromInt18(outX06);
String resX18 = FourCornerUnicodeDisplay.text().renderFromInt18(outX18);
Assertions.assertEquals(resX18, resX06);
Assertions.assertTrue(resX06.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX06);
Assertions.assertTrue(resX06.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX06);
Assertions.assertTrue(resX06.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX06);
Assertions.assertTrue(resX18.startsWith("¹/₁¹/₂¹/₃"), "missing " + resX18);
Assertions.assertTrue(resX18.contains("¹/₅₁₂¹/₅₁₃¹/₅₁₄"), "missing " + resX18);
Assertions.assertTrue(resX18.endsWith("¹/₁₀₂₃¹/₁₀₂₄¹/₁₀₂₅"), "missing " + resX18);
}
@Test
public void testNCRMaxValue() throws Exception {
List<Integer> outX06 = new ArrayList<>();
List<Integer> outX18 = new ArrayList<>();
FourCornerZion7Candlelier writerX06 = FourCornerZionStenoGrapher.writerX06(outX06);
FourCornerZion7Candlelier writerX18 = FourCornerZionStenoGrapher.writerX18(outX18);
BigInteger maxValue = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
writerX06.strobeNCR1632(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeNCR1632(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX06.strobeNCR1632(maxValue, maxValue.add(BigInteger.ONE));
});
writerX18.strobeNCR1632(maxValue, maxValue);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX18.strobeNCR1632(maxValue.add(BigInteger.ONE), maxValue);
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
writerX18.strobeNCR1632(maxValue, maxValue.add(BigInteger.ONE));
});
}
}

View file

@ -36,7 +36,7 @@ import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6;
* @author Willem Cazander
* @version 1.0 Aug 4, 2025
*/
public class LexerInvalidTest {
public class StenoLexerInvalidTest {
@Test
public void testInvalid18Plus() throws Exception {

View file

@ -38,7 +38,7 @@ import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
* @author Willem Cazander
* @version 1.0 Jan 14, 2025
*/
public class LexerNCRTest {
public class StenoLexerNCRTest {
@Test
public void testNCRSmokeSignals() throws Exception {