-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.c
2468 lines (2256 loc) · 55.1 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file is part of 34S.
*
* 34S is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 34S is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 34S. If not, see <http://www.gnu.org/licenses/>.
*/
#include "features.h"
#include "xeq.h"
#include "storage.h"
#include "display.h"
#include "lcd.h"
#include "int.h"
#include "consts.h"
#include "alpha.h"
#include "stats.h"
#include "decn.h"
#include "revision.h"
//#include "printer.h"
#include "serial.h"
static enum separator_modes { SEP_NONE, SEP_COMMA, SEP_DOT } SeparatorMode;
static enum decimal_modes { DECIMAL_DOT, DECIMAL_COMMA } DecimalMode;
static void set_status_sized(const char *, int);
static void set_status(const char *);
static void set_status_right(const char *);
static void set_status_graphic(const unsigned char *);
const char *DispMsg; // What to display in message area
short int DispPlot;
#ifndef REALBUILD
char LastDisplayedText[NUMALPHA + 1]; // For clipboard export
char LastDisplayedNumber[NUMBER_LENGTH + 1];
char LastDisplayedExponent[EXPONENT_LENGTH + 1];
char forceDispPlot;
#endif
FLAG ShowRPN; // controls visibility of RPN annunciator
FLAG JustDisplayed; // Avoid duplicate calls to display()
SMALL_INT IntMaxWindow; // Number of windows for integer display
FLAG IoAnnunciator; // Status of the little "=" sign
/* Message strings
* Strings starting S7_ are for the lower 7 segment line. Strings starting S_
* are for the upper dot matrix line.
*/
static const char S_SURE[] = "Sure?";
static const char S7_ERROR[] = "Error"; /* Default lower line error display */
static const char S7_NaN[] = "not nuMmEric"; /* Displaying NaN in lower line */
#ifndef REALBUILD
static const char S7_NaN_Text[] = " N o t n u m e r i c ";
#endif
static const char S7_INF[] = "Infinity"; /* Displaying infinity in lower line */
#ifndef REALBUILD
static const char S7_INF_Text[] = " I n f i n i t y ";
static const char S7_NEG_INF_Text[] = "-I n f i n i t y ";
#endif
static const char S7_STEP[] = "StEP "; /* Step marker in program mode (lower line) */
#ifndef REALBUILD
static const char S7_STEP_ShortText[] = "STEP";
#endif
static const char S7_fract_EQ[] = " = "; /* Exponent in fraction mode indicates low, equal or high */
static const char S7_fract_LT[] = " Lt";
static const char S7_fract_GT[] = " Gt";
static const char libname[][5] = {
"rAMm", "Lib ", "Bup ",
#ifndef REALBUILD
"roMm"
#endif
};
#ifndef REALBUILD
static const char libname_text[][10] = {
" R a m ", " L i b ", " B u p ", " R o m "
};
static const char libname_shorttext[][5] = {
"Ram", "Lib", "Bup", "Rom"
};
#endif
/* Set the separator and decimal mode globals
*/
static void set_separator_decimal_modes(void) {
// Separators used by various modes
if (UState.fraccomma) {
SeparatorMode = SEP_DOT;
DecimalMode = DECIMAL_COMMA;
}
else {
SeparatorMode = SEP_COMMA;
DecimalMode = DECIMAL_DOT;
}
if ((UState.intm && UState.nointseparator) || (!UState.intm && UState.nothousands))
SeparatorMode = SEP_NONE;
}
/* Table of error messages.
* These consist of a double string. The first is displayed in the
* top line, the second in the bottom. If the second is empty, "Error"
* is displayed instead. To get a blank lower line, include a space.
*/
void error_message(const unsigned int e)
{
#define MSG1(top) top "\0"
#define MSG2(top,bottom) top "\0" bottom
// NB: this MUST be in the same order as the error #defines in errors.h
static const char *const error_table[] =
{
// manually get the order correct!
MSG2("Running", "ProGraMm"),
MSG1("Domain"),
MSG2("Bad time", "or dAtE"),
MSG2("Undefined", "Op-COdE"),
MSG1("+\237"),
MSG1("-\237"),
MSG2("No such", "LAbEL"),
MSG2("Illegal", "OPErAtion"),
MSG1("Out of range"),
MSG1("Bad digit"),
MSG1("Too long"),
MSG2("RAM is", "FuLL"),
MSG2("Stack", "CLASH"),
MSG1("Bad mode"),
MSG2("Word\006\006\006size", "too SMmALL"),
MSG2("Too few", "dAtA PointS"),
MSG2("Invalid", "ParaMmEtEr"),
MSG1("I/O"),
MSG2("Invalid", "dAtA"),
MSG2("Write", "ProtEctEd"),
MSG2("No root", "Found"),
MSG2("Matrix", "MmISMmAtCH"),
MSG1("Singular"),
MSG2("Flash is", "FuLL"),
MSG2("No crystal", "InStaLLEd"),
MSG2("\004 \035", "X"), // Integral ~
};
#undef MSG1
#undef MSG2
#ifndef REALBUILD
static const char *const error_table_text[] =
{
" P r o g r a m ",
"",
" o r d a t e ",
" O p - c o d e ",
"",
"",
" L a b e l ",
" O p e r a t i o n ",
"",
"",
"",
" F u l l ",
" C l a s h ",
"",
" T o o s m a l l ",
" D a t a p o i n t s ",
" P a r a m e t e r ",
"",
" D a t a ",
" P r o t e c t e d ",
" F o u n d ",
" M i s m a t c h ",
"",
" F u l l ",
" I n s t a l l e d ",
"",
};
#endif
if (e != ERR_NONE || Running) {
const char *p = error_table[e];
const char *q = find_char(p, '\0') + 1;
if (*q == '\0')
q = S7_ERROR;
if (*q == 'X') {
DispMsg = p;
frozen_display();
}
else {
message(p, q);
State2.disp_freeze = (e != ERR_NONE);
#ifndef REALBUILD
scopy(LastDisplayedNumber, error_table_text[e]);
#endif
}
#ifdef INFRARED
if (Tracing) {
if (*q == 'X')
print_reg(regX_idx, p, 0);
else {
print_tab(0);
print_line(p, 0);
print(' ');
while (*q != '\0') {
int c = *q;
if (c >= 'A')
c |= 0x60; // ASCII lower case
print(c);
if (c == 'm' /* || c == 'w' */)
++q;
++q;
}
print_advance( 0 );
}
}
#endif
}
}
/* Define a limited character set for the 7-segment portion of the
* display.
*/
#define D_TOP 64
#define D_TL 32
#define D_TR 8
#define D_MIDDLE 16
#define D_BL 4
#define D_BR 1
#define D_BOTTOM 2
#include "charset7.h"
#ifndef REALBUILD
#define SET_MANT_SIGN set_mant_sign_dot()
#define CLR_MANT_SIGN clr_mant_sign_dot()
#define SET_EXP_SIGN set_exp_sign_dot()
#define CLR_EXP_SIGN clr_exp_sign_dot()
static void set_mant_sign_dot()
{
LastDisplayedNumber[0]='-';
set_dot(MANT_SIGN);
}
static void clr_mant_sign_dot()
{
LastDisplayedNumber[0]=' ';
clr_dot(MANT_SIGN);
}
static void set_exp_sign_dot()
{
LastDisplayedExponent[0]='-';
set_dot(EXP_SIGN);
}
static void clr_exp_sign_dot()
{
LastDisplayedExponent[0]=' ';
clr_dot(EXP_SIGN);
}
#else
#define SET_MANT_SIGN set_dot(MANT_SIGN)
#define CLR_MANT_SIGN clr_dot(MANT_SIGN)
#define SET_EXP_SIGN set_dot(EXP_SIGN)
#define CLR_EXP_SIGN clr_dot(EXP_SIGN)
#endif
#ifndef REALBUILD
int getdig(int ch)
#else
static int getdig(int ch)
#endif
{
// perform index lookup
return digtbl[ch&0xff];
}
void dot(int n, int on) {
if (on) set_dot(n);
else clr_dot(n);
}
/* Set the decimal point *after* the indicated digit
* The marker can be either a comma or a dot depending on the value
* of decimal.
*/
static char *set_decimal(const int posn, const enum decimal_modes decimal, char *res) {
if (res) {
*res++ = (decimal == DECIMAL_DOT)?'.':',';
} else {
set_dot(posn+7);
if (decimal != DECIMAL_DOT)
set_dot(posn+8);
#ifndef REALBUILD
LastDisplayedNumber[(posn/9)*2+2]= decimal == DECIMAL_DOT?'.':',';
#endif
}
return res;
}
/* Set the digit group separator *before* the specified digit.
* This can be nothing, a comma or a dot depending on the state of the
* sep argument.
*/
static char *set_separator(int posn, const enum separator_modes sep, char *res) {
if (sep == SEP_NONE)
return res;
if (res) {
if (sep == SEP_COMMA) *res++ = ',';
else *res++ = '.';
} else {
posn -= SEGS_PER_DIGIT;
set_dot(posn+7);
if (sep == SEP_COMMA)
set_dot(posn+8);
#ifndef REALBUILD
LastDisplayedNumber[(posn/9)*2+2] = sep == SEP_COMMA?',':'.';
#endif
}
return res;
}
/* Set a digit in positions [base, base+6] */
static void set_dig(int base, int ch)
{
int i;
int c = getdig(ch);
#ifndef REALBUILD
if(base<SEGS_EXP_BASE)
LastDisplayedNumber[(base/9)*2+1] = ch==0?' ':ch;
else
LastDisplayedExponent[(base-SEGS_EXP_BASE)/7+1] = ch;
#endif
for (i=6; i>=0; i--)
{
// dot(base, c & (1 << i));
if (c & (1 << i))
set_dot(base);
else
clr_dot(base);
base++;
}
}
static char *set_dig_s(int base, int ch, char *res) {
if (res) *res++ = ch;
else set_dig(base, ch);
return res;
}
static void set_digits_string(const char *msg, int j) {
for (; *msg != '\0'; msg++) {
if (*msg == '.' || *msg == ',')
set_decimal(j - SEGS_PER_DIGIT, *msg == '.' ? DECIMAL_DOT : DECIMAL_COMMA, CNULL);
else {
set_dig_s(j, *msg, CNULL);
j += SEGS_PER_DIGIT;
}
}
}
static void set_exp_digits_string(const char *msg, char *res) {
int i;
const int n = res == NULL ? 3 : 4;
for (i=0; i<n && msg[i] != '\0'; i++)
res = set_dig_s(SEGS_EXP_BASE + i * SEGS_PER_EXP_DIGIT, msg[i], res);
}
/* Force the exponent display */
static void set_exp(int exp, int zerop, char *res) {
char buf[6];
#if defined(INCLUDE_YREG_CODE)
if (res) { // this code chooses different exponent separators depending on the number of digits to squash more in!
if ( exp < -999 ) {
// No exponent separator for large -ve exponents;
}
else if ( exp > 999 ) {
*res++ = ':'; // separator for large +ve exponents;
}
else {
*res++ = 'e'; // normal separator;
}
}
#else
if (res) *res++ = 'e';
#endif
if (exp < 0) {
if (res) *res++ = '-';
else SET_EXP_SIGN;
exp = -exp;
}
if (res == NULL && exp > 999)
scopy(buf, "HIG");
else {
xset(buf, '\0', sizeof(buf));
if (zerop)
num_arg_0(buf, exp, 3);
else
num_arg(buf, exp);
}
set_exp_digits_string(buf, res);
}
static void carry_overflow(void) {
const int base = SEGS_EXP_BASE;
int c;
unsigned int b;
// Figure out the base
switch (State2.smode) {
case SDISP_BIN: b = 2; break;
case SDISP_OCT: b = 8; break;
case SDISP_DEC: b = 10; break;
case SDISP_HEX: b = 16; break;
default: b = UState.int_base+1; break;
}
// Display the base as the first exponent digit
if (b > 10 && b < 16)
SET_EXP_SIGN;
c = "B34567o9D12345h"[b-2];
set_dig(base, c);
// Carry and overflow are the next two exponent digits if they are set
if (get_carry())
set_dig(base + SEGS_PER_EXP_DIGIT, 'c');
if (get_overflow())
set_dig(base + 2*SEGS_PER_EXP_DIGIT, 'o');
}
static int set_x_fract(const decNumber *rgx, char *res);
static void set_x_hms(const decNumber *rgx, char *res);
#if !(defined INCLUDE_YREG_CODE && defined INCLUDE_YREG_HMS)
// replace_char() isn't used or implemented unless HMS Y register display is enabled
static void replace_char(char *a, char b, char c) { }
#endif
/* Display the annunicator text line.
* Care needs to be taken to keep things aligned.
* Spaces are 5 pixels wide, \006 is a single pixel space.
*/
static void annunciators(void) {
// We initialize q here to avoid uninitialized error messages by very strict compilers
char buf[42], *p = buf, *q="";
int n;
static const char shift_chars[4] = " \021\022\023";
const char shift_char = shift_chars[cur_shift()];
// Constant variables and code branches depending on a constant variable
// that's set to 0 will be optimized away. This way it's easier to make a
// feature run-time configurable if needed.
#ifdef INCLUDE_YREG_CODE
const int yreg_enabled = UState.show_y;
# ifdef INCLUDE_YREG_HMS
const int yreg_hms = 1;
# else
const int yreg_hms = 0;
# endif
# ifdef INCLUDE_YREG_FRACT
const int yreg_fract = 1;
# else
const int yreg_fract = 0;
# endif
#else
const int yreg_enabled = 0;
const int yreg_hms = 0;
const int yreg_fract = 0;
#endif
#ifdef RP_PREFIX
const int rp_prefix = 1;
#else
const int rp_prefix = 0;
const int RectPolConv = -1; // This variable doesn't exist without RP_PREFIX
#endif
// Indicates whether font escape code is compiled in.
// This variable will always be set at compile time.
#ifdef INCLUDE_FONT_ESCAPE
const int has_FONT_ESCAPE = 1;
#else
const int has_FONT_ESCAPE = 0;
#endif
xset(buf, '\0', sizeof(buf));
if (is_intmode()) {
#ifdef SHOW_STACK_SIZE
if (shift_char == ' ') {
*p++ = '\007';
*p++ = '\346';
*p++ = (UState.stack_depth ? ':' : '.');
}
else
#endif
{
*p++ = shift_char;
*p++ = '\006';
}
switch(int_mode()) {
default:
case MODE_2COMP: q = "2c\006"; break;
case MODE_UNSIGNED: q = "un\006"; break;
case MODE_1COMP: q = "\0061c\006\006"; break;
case MODE_SGNMANT: q = "sm"; break;
}
q = scopy(p, q);
*q++ = '\006';
p = num_arg_0(q, word_size(), 2);
if (IntMaxWindow > 0) {
n = 4 + 2 * (5 - IntMaxWindow);
if (*q == '1')
n += 2;
if (q[1] == '1')
n += 2;
while (n-- > 0)
*p++ = '\006';
for (n = IntMaxWindow; n >= 0; n--)
*p++ = State2.window == n ? '|' : '\'';
}
}
else if (!yreg_enabled
#ifdef SHIFT_AND_CMPLX_SUPPRESS_YREG
|| shift_char != ' ' || State2.cmplx
#endif
) {
// The stack size indicator is displayed on the right if date mode indication is enabled
// because the 'D' in small font doesn't look good next to the date mode indicator.
#if defined SHOW_STACK_SIZE && defined NO_DATEMODE_INDICATION
if (shift_char == ' ') {
*p++ = '\007';
*p++ = '\342';
*p++ = (UState.stack_depth ? ':' : '.');
*p++ = '\007';
*p++ = '\344';
*p++ = (is_dblmode() ? 'D' : ' ');
}
else
#endif
if (shift_char != ' ' || !is_dblmode()) {
*p++ = shift_char;
*p++ = '\006';
}
else {
*p++ = 'D';
}
if (State2.cmplx) {
*p++ = ' ';
*p = '\024';
goto skip;
}
if (State2.arrow) {
*p++ = ' ';
*p = '\015';
goto skip;
}
if (shift_char == ' ' && (State2.wascomplex || (rp_prefix && RectPolConv != 0))) {
if (State2.wascomplex) {
q = (has_FONT_ESCAPE ? "\007\207i" : "i\006");
}
else if (rp_prefix) {
if (RectPolConv == 1) {
q = "\007\306<";
}
else {
q = "\007\306y";
}
}
p = scopy(buf, q);
goto display_yreg;
}
switch (UState.date_mode) {
#ifndef NO_DATEMODE_INDICATION
#if defined(DEFAULT_DATEMODE) && (DEFAULT_DATEMODE != 0)
case DATE_DMY: q = "d.my\006\006"; break;
#endif
#if ! defined(DEFAULT_DATEMODE) || (DEFAULT_DATEMODE != 1)
case DATE_YMD: q = "y.md\006\006"; break;
#endif
#if ! defined(DEFAULT_DATEMODE) || (DEFAULT_DATEMODE != 2)
case DATE_MDY: q = "m.dy\006\006"; break;
#endif
#endif
default: q = (has_FONT_ESCAPE ? "\007\225\006" : " \006"); break; // 21 pixels
}
p = scopy(p, q);
#if !defined SHOW_STACK_SIZE || defined NO_DATEMODE_INDICATION
if (get_trig_mode() == TRIG_GRAD) {
scopy(p, (has_FONT_ESCAPE ? "\006\006\007\210\007" : "\006\006\007" ));
}
#else
p = scopy(p, (get_trig_mode() == TRIG_GRAD ? "\006\006\007\210\007" : " "));
*p++ = '\007';
*p++ = '\342';
*p = (UState.stack_depth ? ':' : '.');
#endif
}
else { // yreg_enabled
#ifndef SHIFT_AND_CMPLX_SUPPRESS_YREG
if (State2.cmplx) {
*p++ = '\007';
*p++ = '\344';
*p++ = shift_char;
q = "\024";
}
else if (shift_char != ' ') {
*p++ = '\007';
*p++ = '\307';
*p++ = shift_char;
goto no_copy;
}
else
#endif
if (State2.wascomplex) {
q = "\007\207i";
}
else if (rp_prefix && RectPolConv == 1) {
q = "\007\307<";
}
else if (rp_prefix && RectPolConv == 2) {
q = "\007\307y";
}
#ifdef SHOW_GRADIAN_PREFIX
else if (get_trig_mode() == TRIG_GRAD) {
q = "\007\207\007";
}
#endif
else {
#ifndef SHOW_STACK_SIZE
q = (is_dblmode() ? "\007\307D" : "\007\207 ");
#else
if (is_dblmode()) {
*p++ = '\007';
*p++ = '\342';
*p++ = (UState.stack_depth ? ':' : '.');
q = "\007\345D";
}
else {
q = (UState.stack_depth ? "\007\347:" : "\007\347.");
}
#endif
}
p = scopy(p, q);
#ifndef SHIFT_AND_CMPLX_SUPPRESS_YREG
no_copy:
#endif
if (State2.arrow) {
scopy(p, "\007\204\006\015");
} else if (State2.runmode) {
decNumber y;
display_yreg:
/* This is a bit convoluted. ShowRegister is the real portion being shown. Normally
* ShowRegister+1 would contain the complex component, however if the register being
* examined is on the stack and there is a command line present, the stack will be lifted
* after we execute so we need to show ShowRegister instead.
*/
getRegister(&y, (ShowRegister >= regX_idx && ShowRegister < regX_idx + stack_size() && get_cmdline()
&& !(yreg_enabled && !State2.state_lift) // unless stack lift is disabled...
) ? ShowRegister : ShowRegister+1);
if ((yreg_hms || yreg_fract) && !decNumberIsSpecial(&y)) {
if (yreg_hms && State2.hms) {
const int saved_nothousands = UState.nothousands;
xset(buf, '\0', sizeof(buf));
UState.nothousands = 1;
set_x_hms(&y, buf); // no prefix or alignment for HMS display
UState.nothousands = saved_nothousands;
// First replace the '@' character with the degree symbol
// Then, if the string doesn't fit in the dot matrix display, replace spaces with narrow spaces,
// then remove the second symbol (") and the overflow or underflow signs,
// then remove the fractional part of the seconds.
p = "@\005 \006\"\0.\0";
while (*p) {
replace_char(buf, p[0], p[1]);
if (pixel_length(buf, 1) <= BITMAP_WIDTH + 1) {
goto skip;
}
p += 2;
}
goto skip;
}
if (yreg_fract && UState.fract
#ifndef SHIFT_AND_CMPLX_SUPPRESS_YREG
&& !State2.cmplx
#endif
#ifdef ANGLES_NOT_SHOWN_AS_FRACTIONS
&& !(rp_prefix && RectPolConv == 1)
#endif
&& set_x_fract(&y, p)) {
char ltgteq;
q = find_char(buf, '\0') - 2;
// Replace Lt/Gt/= with </>/= in small font
ltgteq = *q;
switch (ltgteq) {
case 'G': ltgteq = '>'; break;
case 'L': ltgteq = '<'; break;
}
scopy(q, "\007\344?");
q[2] = ltgteq;
if (pixel_length(buf, 1) <= BITMAP_WIDTH + 1) {
goto skip;
}
q[-1] = '\0'; // Remove </>/= if string doesn't fit in the dot matrix display
if (pixel_length(buf, 1) <= BITMAP_WIDTH + 1) {
goto skip;
}
xset(p, '\0', sizeof(buf) - (p - buf));
}
}
for (n=DISPLAY_DIGITS; n>1; ) {
int extra_pixels;
set_x_dn(&y, p, &n);
extra_pixels = pixel_length(buf, 1) - (BITMAP_WIDTH + 1);
if (extra_pixels <= 0)
break;
xset(p, '\0', n+10);
n -= (extra_pixels + 3) / 4; // The maximum width of digits in the small font is 4 pixels.
}
}
}
skip: set_status(buf);
}
static void disp_x(const char *p) {
int i;
int gotdot = -1;
#if defined(PRETTY_FRACTION_ENTRY)
int twodot = 0; // ND change
const char *q; // ND change
#endif
if (*p == '-') {
SET_MANT_SIGN;
p++;
}
if (is_intmode()) {
for (i=0; *p != '\0'; p++) {
set_dig(i, *p);
i += SEGS_PER_DIGIT;
}
carry_overflow();
} else {
set_separator_decimal_modes();
#if defined(PRETTY_FRACTION_ENTRY)
q = p; // ND change; scan ahead to count dots;
for (i=0; *q != '\0' && *q != 'E'; q++) {
if (*q == '.') twodot++;
}
#endif
for (i=0; *p != '\0' && *p != 'E'; p++) {
if (*p == '.') {
if (gotdot == -1)
gotdot = i;
#if defined(PRETTY_FRACTION_ENTRY)
if ( ( *(p+1) == '.' ) || ( i != gotdot ) ) {
set_dig(i, '/'); // put in a fraction separator
i += SEGS_PER_DIGIT;
if ( *(p+1) == '.' ) {
p++;
}
}
else {
if ( twodot > 1 ) {
i += SEGS_PER_DIGIT;
}
else {
set_decimal(i - SEGS_PER_DIGIT, DecimalMode, CNULL);
// i += SEGS_PER_DIGIT;
}
}
#else
if (i > 0)
set_decimal(i - SEGS_PER_DIGIT, DecimalMode, CNULL);
else {
set_dig(i, '0');
set_decimal(i, DecimalMode, CNULL);
i += SEGS_PER_DIGIT;
}
#endif
} else {
set_dig(i, *p);
i += SEGS_PER_DIGIT;
}
}
/* Implement a floating comma */
if (gotdot < 0)
gotdot = i;
for (;;) {
gotdot -= 3 * SEGS_PER_DIGIT;
if (gotdot <= 0) // MvC: was '<', caused crash
break;
set_separator(gotdot, SeparatorMode, CNULL);
}
if (*p == 'E') {
p++;
if (*p != '\0') {
if (*p == '-') {
SET_EXP_SIGN;
p++;
}
}
set_exp(s_to_i(p), 1, CNULL);
}
}
}
static const char DIGITS[] = "0123456789ABCDEF";
static void set_int_x(const long long int value, char *res) {
const int ws = word_size();
unsigned int b;
long long int vs = value;
unsigned long long int v;
char buf[MAX_WORD_SIZE + 1];
int i, j, k;
int sign = 0;
int dig = SEGS_PER_DIGIT * 11;
switch (State2.smode) {
case SDISP_BIN: b = 2; break;
case SDISP_OCT: b = 8; break;
case SDISP_DEC: b = 10; break;
case SDISP_HEX: b = 16; break;
default: b = int_base(); break;
}
if (!res) {
IntMaxWindow = 0;
carry_overflow();
}
if ((0x7f75 & (1 << (b-1))) != 0) {
v = extract_value(value, &sign);
if (int_mode() == MODE_2COMP && sign == 1 && v == 0)
v = value;
if (v == 0) {
if (sign)
set_dig_s(dig-SEGS_PER_DIGIT, '-', res);
set_dig_s(dig, '0', res);
return;
} else
for (i=0; v != 0; i++) {
const int r = v % b;
v /= b;
buf[i] = DIGITS[r];
}
} else {
// Truncate down to the current word size and then sign extend it back
if (ws < 64) {
const long long int mask = (1LL << ws) - 1;
vs &= mask;
if (b == 10 && (vs & (1LL << (ws-1))))
vs |= ~mask;
}
if (!UState.leadzero && vs == 0) {
set_dig_s(dig, '0', res);
return;
} else if (!UState.leadzero) {
v = (unsigned long long int)vs;
for (i=0; v != 0; i++) {
const int r = v % b;
v /= b;
buf[i] = DIGITS[r];
}
} else {
int n;
const unsigned int b1 = b >> 1;
const unsigned int fac = ((b1 & 0xa) != 0) | (((b1 & 0xc) != 0) << 1);
v = (unsigned long long int)vs;
n = (ws + fac) / (fac+1);
for (i=0; i<n; i++) {
const int r = v % b;
v /= b;
buf[i] = DIGITS[r];
}
}
}
/* At this point i is the number of digits in the output */
if (res) {
if (sign) *res++ = '-';
while (--i >= 0)
*res++ = buf[i];
} else {
#if 0
set_separator_decimal_modes();
// Allows configuration of digit grouping per base
static const char grouping[] =
{ 0x84, 0xb3, 0xb4, 0xb3, 0xb3, 0xb3, 0xb3,
// 2 3 4 5 6 7 8
0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb2 };
// 9 10 11 12 13 14 15 16
const int shift = SeparatorMode == SEP_NONE ? 12
: grouping[b - 2] >> 4;
const int group = SeparatorMode == SEP_NONE ? 16
: (grouping[b - 2] & 0xf);
#else
// Less flexible but shorter
const int shift = b == 2 ? 8 : 12;
const int group = (b == 2 || b == 4) ? 4
: b == 16 ? 2 : 3;
set_separator_decimal_modes();
#endif
IntMaxWindow = (i - 1) / shift;
if ((SMALL_INT) State2.window > IntMaxWindow)
State2.window = 0;
buf[i] = '\0';
j = State2.window * shift; // digits at a time
for (k = 0; k < 12; k++)
if (buf[j + k] == '\0')
break;
for (i=0; --k >= 0; i++) {
int ch = buf[j++];
if (i >= shift)
ch -= 030;
set_dig(dig, ch);
if ((j % group) == 0 && k != 0)
set_separator(dig, SeparatorMode, CNULL);
dig -= SEGS_PER_DIGIT;
}
if (sign) {
if (dig >= 0)
set_dig(dig, '-');
else SET_MANT_SIGN;
}
}
}
/* Handle special cases.
* return non-zero if the number is special.
*/
static int check_special_dn(const decNumber *x, char *res) {
if (decNumberIsSpecial(x)) {
if (decNumberIsNaN(x)) {
if (res) {
scopy(res, "NaN");
} else {
set_digits_string(S7_NaN, 0);
#ifndef REALBUILD
scopy(LastDisplayedNumber, S7_NaN_Text);
forceDispPlot=0;
#endif
}
return 1;
} else {
if (decNumberIsNegative(x)) {
if (res) *res++ = '-';
else set_dig(SEGS_PER_DIGIT, '-');
}
if (res)
*res++ = '\237';
else {
set_digits_string(S7_INF, SEGS_PER_DIGIT * 2);
#ifndef REALBUILD
if (decNumberIsNegative(x)) {
scopy(LastDisplayedNumber, S7_NEG_INF_Text);
}
else {
scopy(LastDisplayedNumber, S7_INF_Text);
}
forceDispPlot=0;
#endif