1212// this whole file compiles to less than 1KB of code
1313//
1414
15-
1615//
1716// A0 = D14
1817// A1 = D15
@@ -332,35 +331,6 @@ void selectDigit(byte digit) {
332331 }
333332}
334333
335- // this function is called by the display routines to show a digit for 2ms before moving to the next one.
336- // can do useful work here... instead of delay();
337-
338- void backgroundWork () {
339-
340- }
341-
342- void display () {
343-
344- bool dp = false ;
345-
346- for (byte i = 0 ; i < 9 ; i++) {
347-
348- // SINCLAIR behavior: turn decimal point on automatically at fixed position
349- if (i == 1 ) {
350- dp = true ;
351- }
352- else
353- {
354- dp = false ;
355- }
356-
357- outputDigit (digits[i], dp);
358- selectDigit (i);
359-
360- backgroundWork ();
361- }
362- }
363-
364334void displaySelfTest (bool longtest = false ) {
365335 char c = 0 ;
366336
@@ -457,13 +427,17 @@ void displaySelfTest(bool longtest = false) {
457427
458428// const char PrintableKeys[19] = "12+E0v-378X654/9^C";
459429
430+ const char KeysKN[10 ] = " 156789234" ;
431+ const char KeysKO[10 ] = " C/*^E0v+-" ;
432+
460433byte readKey () {
461434
462435 byte key = 0 ;
463436
464437 if (analogRead (7 ) > 100 )
465438 {
466439 SinclairData.keyStrobeKN = 1 ;
440+ key = KeysKN[lastSelectDigit - 1 ];
467441 }
468442 else
469443 {
@@ -473,21 +447,49 @@ byte readKey() {
473447 if (analogRead (6 ) > 100 )
474448 {
475449 SinclairData.keyStrobeKO = 1 ;
450+ key = KeysKO[lastSelectDigit - 1 ];
476451 }
477452 else
478453 {
479454 SinclairData.keyStrobeKO = 0 ;
480455 }
481456
482- if ((lastSelectDigit == 2 ) && (SinclairData.keyStrobeKO ))
457+ // ensure C has priority
458+ if ((lastSelectDigit == 1 ) && (SinclairData.keyStrobeKO ))
483459 {
484460 key = ' C' ;
485461 }
486462
487- // Serial.print(SinclairData.dActive);
488- // Serial.print(SinclairData.keyStrobeKN);
489- // Serial.print(SinclairData.keyStrobeKO);
490- // Serial.println("");
463+ /*
464+ Serial.print(lastSelectDigit);
465+ Serial.print(SinclairData.dActive);
466+ Serial.print(SinclairData.keyStrobeKN);
467+ Serial.print(SinclairData.keyStrobeKO);
468+ Serial.print(key);
469+ Serial.println("");
470+ */
471+
472+ return key;
473+ }
474+
475+ // since reakKey only reads the active column, this function sweeps through all columns and calls readKey
476+ byte readKeys ()
477+ {
478+ byte k;
479+ byte key = 0 ;
480+
481+ outputDigit (99 );
482+ for (byte i = 1 ; i < 10 ; i++)
483+ {
484+ selectDigit (i);
485+ k = readKey ();
486+
487+ if (k)
488+ {
489+ key = k;
490+ }
491+
492+ }
491493
492494 return key;
493495}
0 commit comments