Updated index naming and moved NCR bank reset to state level

This commit is contained in:
Willem Cazander 2025-01-16 22:37:43 +01:00
parent 4454a4d322
commit 3c4adb03df

View file

@ -204,6 +204,25 @@ public class FourCornerZionStenoLexer {
return true; return true;
} }
private void ncrBankReset() {
for (int i = 0; i < denominatorBank.length; i++) {
denominatorBank[i] = 0;
numeratorBank[i] = 0;
}
}
private void ncrBankFire() {
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);
}
abstract static private class StenoScanner { abstract static private class StenoScanner {
protected final int blockStart; protected final int blockStart;
@ -223,29 +242,29 @@ public class FourCornerZionStenoLexer {
if (cakePoint < blockStart || cakePoint > blockStop) { if (cakePoint < blockStart || cakePoint > blockStop) {
return ScanResult.NEXT; return ScanResult.NEXT;
} }
lexer.fireSignals.fireStateScanner(blockStart, blockStop, cakePoint); // TODO: move below and add idxStart/stop + next lexer.fireSignals.fireStateScanner(blockStart, blockStop, cakePoint); // TODO: move below and add idxFirst/stop + next
ScanResult result = ScanResult.DONE; ScanResult result = ScanResult.DONE;
int idxStart = lexer.inputIndex; int idxFirst = lexer.inputIndex;
int idxStop = lexer.inputIndex; int idxLast = lexer.inputIndex;
while (true) { while (true) {
cakePoint = lexer.input.get(lexer.inputIndex); cakePoint = lexer.input.get(lexer.inputIndex);
if (cakePoint < blockStart || cakePoint > blockStop) { if (cakePoint < blockStart || cakePoint > blockStop) {
break; break;
} }
idxStop = lexer.inputIndex; idxLast = lexer.inputIndex;
if (lexer.safeNext() == false) { if (lexer.safeNext() == false) {
result = ScanResult.EOF; result = ScanResult.EOF;
break; break;
} }
} }
//System.out.println("PROCESS: " + lexer.input.size() + " start: " + idxStart + " stop: " + idxStop + " currenId: " + lexer.inputIndex); //System.out.println("PROCESS: " + lexer.input.size() + " start: " + idxFirst + " stop: " + idxLast + " currenId: " + lexer.inputIndex);
process(lexer, idxStart, idxStop); process(lexer, idxFirst, idxLast);
return result; return result;
} }
abstract void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop); abstract void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast);
} }
static class StenoScannerWordCakeSlice extends StenoScanner { static class StenoScannerWordCakeSlice extends StenoScanner {
@ -258,8 +277,8 @@ public class FourCornerZionStenoLexer {
} }
@Override @Override
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) { public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
List<Integer> offsets = lexer.input.subList(idxStart, idxStop + 1); List<Integer> offsets = lexer.input.subList(idxFirst, idxLast + 1); // List.subList is an exclusive "indexTo" argument
for (int i = 0; i < offsets.size(); i++) { for (int i = 0; i < offsets.size(); i++) {
offsets.set(i, offsets.get(i) - blockStart); offsets.set(i, offsets.get(i) - blockStart);
} }
@ -274,7 +293,7 @@ public class FourCornerZionStenoLexer {
} }
@Override @Override
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) { public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
} }
private void handlePoints(FourCornerZionStenoLexer lexer, List<Integer> slicedPoints) { private void handlePoints(FourCornerZionStenoLexer lexer, List<Integer> slicedPoints) {
@ -290,11 +309,11 @@ public class FourCornerZionStenoLexer {
} }
@Override @Override
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) { public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
bankReset(lexer); lexer.ncrBankReset();
boolean magicSparkler = true; boolean magicSparkler = true;
boolean requestBankReset = false; boolean requestBankReset = false;
for (int i = idxStart; i <= idxStop; i++) { for (int i = idxFirst; i <= idxLast; i++) {
int cakePoint = lexer.input.get(i); int cakePoint = lexer.input.get(i);
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();
@ -310,7 +329,7 @@ public class FourCornerZionStenoLexer {
if (requestBankReset) { if (requestBankReset) {
requestBankReset = false; requestBankReset = false;
lexer.fireSignals.fireStateNCR1632BankReset(); lexer.fireSignals.fireStateNCR1632BankReset();
bankReset(lexer); lexer.ncrBankReset();
magicSparkler = false; // if block ends with bank reset, don't leak a sparkler magicSparkler = false; // if block ends with bank reset, don't leak a sparkler
continue; continue;
} }
@ -323,33 +342,14 @@ public class FourCornerZionStenoLexer {
magicSparkler = true; magicSparkler = true;
continue; // Only fire fraction on lowest value select continue; // Only fire fraction on lowest value select
} else } else
bankFire(lexer); lexer.ncrBankFire();
magicSparkler = false; magicSparkler = false;
} }
if (magicSparkler) { if (magicSparkler) {
lexer.fireSignals.fireStateNCR1632BankSparkler(); lexer.fireSignals.fireStateNCR1632BankSparkler();
bankFire(lexer); lexer.ncrBankFire();
} }
} }
private void bankReset(FourCornerZionStenoLexer lexer) {
for (int i = 0; i < lexer.denominatorBank.length; i++) {
lexer.denominatorBank[i] = 0;
lexer.numeratorBank[i] = 0;
}
}
private void bankFire(FourCornerZionStenoLexer lexer) {
BigInteger denominator = BigInteger.ONE;
for (int i = 0; i < lexer.denominatorBank.length; i++) {
denominator = denominator.add(BigInteger.valueOf(lexer.denominatorBank[i]).shiftLeft(i * 9));
}
BigInteger numerator = BigInteger.ONE;
for (int i = 0; i < lexer.numeratorBank.length; i++) {
numerator = numerator.add(BigInteger.valueOf(lexer.numeratorBank[i]).shiftLeft(i * 9));
}
lexer.handler.strobeNCR1632(denominator, numerator);
}
} }
static class StenoScannerUNI21 extends StenoScanner { static class StenoScannerUNI21 extends StenoScanner {
@ -359,11 +359,11 @@ public class FourCornerZionStenoLexer {
} }
@Override @Override
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) { public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
boolean errorUnusedBigIndian = false; // are optional boolean errorUnusedBigIndian = false; // are optional
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
int codePoint22 = 0; int codePoint22 = 0;
for (int i = idxStart; i <= idxStop; i++) { for (int i = idxFirst; i <= idxLast; i++) {
int cakePoint = lexer.input.get(i); int cakePoint = lexer.input.get(i);
if (cakePoint >= FourCornerDotCake.FC_UNI2K_22.getStart() && cakePoint <= FourCornerDotCake.FC_UNI2K_22.getStop()) { if (cakePoint >= FourCornerDotCake.FC_UNI2K_22.getStart() && cakePoint <= FourCornerDotCake.FC_UNI2K_22.getStop()) {
codePoint22 = cakePoint - FourCornerDotCake.FC_UNI2K_22.getStart(); codePoint22 = cakePoint - FourCornerDotCake.FC_UNI2K_22.getStart();
@ -398,12 +398,12 @@ public class FourCornerZionStenoLexer {
} }
@Override @Override
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) { public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
numberMode = null; numberMode = null;
numberPIE = true; numberPIE = true;
scanIndex = idxStart; scanIndex = idxFirst;
scanIndexEnd = idxStop; scanIndexEnd = idxLast;
for (scanIndex = idxStart; scanIndex <= idxStop; scanIndex++) { for (scanIndex = idxFirst; scanIndex <= idxLast; scanIndex++) {
int cdcDECPoint = lexer.input.get(scanIndex); int cdcDECPoint = lexer.input.get(scanIndex);
// Log state changes // Log state changes
if (FCDotCDC1604DashP6._NEWLINE.ordinal() == cdcDECPoint) { if (FCDotCDC1604DashP6._NEWLINE.ordinal() == cdcDECPoint) {
@ -422,7 +422,7 @@ public class FourCornerZionStenoLexer {
continue; continue;
} }
// Handle 6 bit CDC and DEC codes // Handle 6 bit CDC and 6/8/18 bit DEC codes
handleCDCDEC(lexer, cdcDECPoint, null); handleCDCDEC(lexer, cdcDECPoint, null);
} }
} }
@ -430,10 +430,9 @@ public class FourCornerZionStenoLexer {
private FCDotDEC0127DashPX0 readEscape6(FourCornerZionStenoLexer lexer, int cdcPoint1) { private FCDotDEC0127DashPX0 readEscape6(FourCornerZionStenoLexer lexer, int cdcPoint1) {
// Read 8 or 18 bit Direct Escape Code // Read 8 or 18 bit Direct Escape Code
if (FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint1)) { if (FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint1)) {
System.out.println("readEscape6 upper : " + cdcPoint1);
return FCDotDEC0127DashPX0.valueOfCakePoint(cdcPoint1); return FCDotDEC0127DashPX0.valueOfCakePoint(cdcPoint1);
} }
// Read 6 bit escape code // Read 6 bit escape sequence
FCDotCDC1604DashP6 x1 = FCDotCDC1604DashP6.valueOf(cdcPoint1); FCDotCDC1604DashP6 x1 = FCDotCDC1604DashP6.valueOf(cdcPoint1);
FCDotCDC1604DashP6 x2 = null; FCDotCDC1604DashP6 x2 = null;
FCDotCDC1604DashP6 x3 = null; FCDotCDC1604DashP6 x3 = null;
@ -460,7 +459,6 @@ public class FourCornerZionStenoLexer {
return FCDotDEC0127DashPX0.valueOf(x1, x2, x3); return FCDotDEC0127DashPX0.valueOf(x1, x2, x3);
} }
/// note; cdcPoint is always CDC or direct DEC escape code
private void handleCDCDEC(FourCornerZionStenoLexer lexer, int cdcPoint, FCDotDEC0127DashPX0 startMode) { private void handleCDCDEC(FourCornerZionStenoLexer lexer, int cdcPoint, FCDotDEC0127DashPX0 startMode) {
// TODO: make simple // TODO: make simple
@ -555,7 +553,6 @@ public class FourCornerZionStenoLexer {
if (numberMode == null) { if (numberMode == null) {
Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint); Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint);
if (slice.isEmpty()) { if (slice.isEmpty()) {
System.out.println("No slice for point: " + Integer.toHexString(cdcPoint));
lexer.smokeSignals.burnUnsupported(lexer.currLine, lexer.currCol, cdcPoint); lexer.smokeSignals.burnUnsupported(lexer.currLine, lexer.currCol, cdcPoint);
return; return;
} }