Added NCR use the magic sparkler if block end unused.

This commit is contained in:
Willem Cazander 2025-01-16 15:22:19 +01:00
parent efc932a7d4
commit 62bdf94435
6 changed files with 125 additions and 60 deletions

View file

@ -284,6 +284,9 @@ public class FourCornerZionStenoLexer {
class StenoScannerNCR18 extends StenoScanner { class StenoScannerNCR18 extends StenoScanner {
private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group
private final int numeratorBank[] = new int[64];
public StenoScannerNCR18() { public StenoScannerNCR18() {
super(FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop()); super(FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop());
} }
@ -299,42 +302,51 @@ public class FourCornerZionStenoLexer {
} }
private void handlePoints(List<Integer> slicedPoints) { private void handlePoints(List<Integer> slicedPoints) {
int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group bankReset();
int numeratorBank[] = new int[64]; boolean magicSparkler = true;
boolean errorZeroSparks = true;
boolean errorUnusedSparks = true;
for (Integer cakePoint : slicedPoints) { for (Integer cakePoint : slicedPoints) {
if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) { if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) {
int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart(); int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart();
denominatorBank[denominatorX / 512] = denominatorX % 512; denominatorBank[denominatorX / 512] = denominatorX % 512;
errorUnusedSparks = true; magicSparkler = true;
continue; continue;
} }
int numeratorX = cakePoint - FourCornerDotCake.FC_NCR1632_XN.getStart(); int numeratorX = cakePoint - FourCornerDotCake.FC_NCR1632_XN.getStart();
numeratorBank[numeratorX / 512] = numeratorX % 512; numeratorBank[numeratorX / 512] = numeratorX % 512;
if (cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStart() + 512) { if (cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStart() + 512) {
errorUnusedSparks = true; magicSparkler = true;
continue; // Only fire fraction on lowest value select continue; // Only fire fraction on lowest value select
} }
BigInteger denominator = BigInteger.ONE; bankFire();
for (int i=0; i<denominatorBank.length;i++) { magicSparkler = false;
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i*9));
}
BigInteger numerator = BigInteger.ONE;
for (int i=0; i<numeratorBank.length;i++) {
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9));
}
handler.strobeNCR1632(denominator, numerator);
errorZeroSparks = false;
errorUnusedSparks = false;
} }
if (errorZeroSparks) { if (magicSparkler) {
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol); fireSignals.fireStateNCR1632Sparkler();
} else if (errorUnusedSparks) { bankFire();
smokeSignals.burnNCR1632UnusedSparks(currLine, currCol);
} }
} }
private void bankReset() {
for (int i=0;i<denominatorBank.length;i++) {
denominatorBank[i] = 0;
}
for (int i=0;i<numeratorBank.length;i++) {
numeratorBank[i] = 0;
}
}
private void bankFire() {
BigInteger denominator = BigInteger.ONE;
for (int i=0; i<denominatorBank.length;i++) {
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i*9));
}
BigInteger numerator = BigInteger.ONE;
for (int i=0; i<numeratorBank.length;i++) {
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9));
}
handler.strobeNCR1632(denominator, numerator);
}
} }
class StenoScannerUNI21 extends StenoScanner { class StenoScannerUNI21 extends StenoScanner {

View file

@ -34,6 +34,8 @@ public interface FourCornerZionStenoLexerFire {
void fireStateScanner(int blockStart, int blockStop, int cakePoint); void fireStateScanner(int blockStart, int blockStop, int cakePoint);
void fireStateNCR1632Sparkler();
interface Adapter extends FourCornerZionStenoLexerFire { interface Adapter extends FourCornerZionStenoLexerFire {
@Override @Override
@ -47,5 +49,9 @@ public interface FourCornerZionStenoLexerFire {
@Override @Override
default void fireStateScanner(int blockStart, int blockStop, int cakePoint) { default void fireStateScanner(int blockStart, int blockStop, int cakePoint) {
} }
@Override
default void fireStateNCR1632Sparkler() {
}
} }
} }

View file

@ -49,11 +49,6 @@ public interface FourCornerZionStenoLexerSmoke {
void burnUNI21UnusedBigIndian(int line, int col); void burnUNI21UnusedBigIndian(int line, int col);
void burnNCR1632ZeroSparks(int line, int col);
void burnNCR1632UnusedSparks(int line, int col);
interface Adapter extends FourCornerZionStenoLexerSmoke { interface Adapter extends FourCornerZionStenoLexerSmoke {
@Override @Override
@ -87,13 +82,5 @@ public interface FourCornerZionStenoLexerSmoke {
@Override @Override
default void burnUNI21UnusedBigIndian(int line, int col) { default void burnUNI21UnusedBigIndian(int line, int col) {
} }
@Override
default void burnNCR1632ZeroSparks(int line, int col) {
}
@Override
default void burnNCR1632UnusedSparks(int line, int col) {
}
} }
} }

View file

@ -42,24 +42,26 @@ import org.x4o.fc18.cake2.zero33.FCDotDEC0127DashPX0;
public class LexerNCRTest { public class LexerNCRTest {
@Test @Test
public void testNCRInvalid() throws Exception { public void testNCRMagicSparkler() throws Exception {
TestSmokeReader smokeReader = new TestSmokeReader(); TestFireWalker fireWalker = new TestFireWalker();
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true); FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
lexer.withSmokeSignals(smokeReader); lexer.withFireSignals(fireWalker);
List<Integer> cdc = new ArrayList<>(); List<Integer> cdc = new ArrayList<>();
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1); cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*3) + 1); /// auto NXX_001
cdc.addAll(FCDotDEC0127DashPX0.ESC_STOP.toInt18BaklavaPoints());
Assertions.assertEquals(0, fireWalker.ncrMagicSparks);
lexer.read(cdc); lexer.read(cdc);
Assertions.assertEquals(-1, smokeReader.errorNCRUnusedSparks); Assertions.assertEquals(1, fireWalker.ncrMagicSparks);
Assertions.assertEquals(0, smokeReader.errorNCRZeroSparks);
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // normal NXX_123
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2); cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() + (512*4) + 2); /// auto NXX_123 + this
smokeReader.reset(); fireWalker.reset();
lexer.read(cdc); lexer.read(cdc);
Assertions.assertEquals(0, smokeReader.errorNCRUnusedSparks); Assertions.assertEquals(2, fireWalker.ncrMagicSparks);
Assertions.assertEquals(-1, smokeReader.errorNCRZeroSparks);
Assertions.assertEquals("¹/₁₃₄₂₁₇₇₂₉¹²³/₁¹³⁷⁴³⁸⁹⁵³⁵⁹⁵/₁", FourCornerUnicodeDisplay.text().renderFromInt18(cdc));
} }
@Test @Test

View file

@ -0,0 +1,72 @@
/*
* 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;
/**
* Walks four corner lexer fire signals.
*
* @author Willem Cazander
* @version 1.0 Jan 16, 2025
*/
public class TestFireWalker implements FourCornerZionStenoLexerFire.Adapter {
int currentLine;
int currentColumn;
int scanBlockStart;
int scanBlockStop;
int scanCakePoint;
int ncrMagicSparks;
public TestFireWalker() {
reset();
}
public void reset() {
currentLine = 0;
currentColumn = 0;
scanBlockStart = 0;
ncrMagicSparks = 0;
}
@Override
public void fireStateLine(int line) {
currentLine = line;
}
@Override
public void fireStateColumn(int column) {
currentColumn = column;
}
@Override
public void fireStateScanner(int blockStart, int blockStop, int cakePoint) {
scanBlockStart = blockStart;
scanBlockStop = blockStop;
scanCakePoint = cakePoint;
}
@Override
public void fireStateNCR1632Sparkler() {
ncrMagicSparks++;
}
}

View file

@ -23,15 +23,13 @@
package org.x4o.fc18.zion7; package org.x4o.fc18.zion7;
/** /**
* Tests four corner lexer parts. * Reads four corner lexer smoke signals.
* *
* @author Willem Cazander * @author Willem Cazander
* @version 1.0 Jan 14, 2025 * @version 1.0 Jan 14, 2025
*/ */
public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter { public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter {
int errorNCRZeroSparks;
int errorNCRUnusedSparks;
int errorUNI21UnusedBigIndian; int errorUNI21UnusedBigIndian;
int errorUnsupport; int errorUnsupport;
int errorRecursive; int errorRecursive;
@ -41,23 +39,11 @@ public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter {
} }
public void reset() { public void reset() {
errorNCRZeroSparks = -1;
errorNCRUnusedSparks = -1;
errorUNI21UnusedBigIndian = -1; errorUNI21UnusedBigIndian = -1;
errorUnsupport = -1; errorUnsupport = -1;
errorRecursive = -1; errorRecursive = -1;
} }
@Override
public void burnNCR1632ZeroSparks(int line, int col) {
errorNCRZeroSparks = line;
}
@Override
public void burnNCR1632UnusedSparks(int line, int col) {
errorNCRUnusedSparks = line;
}
@Override @Override
public void burnUNI21UnusedBigIndian(int line, int col) { public void burnUNI21UnusedBigIndian(int line, int col) {
errorUNI21UnusedBigIndian = line; errorUNI21UnusedBigIndian = line;