-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIV42-001.c
2793 lines (2475 loc) · 101 KB
/
IV42-001.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
/*
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
This software is protected by the BSD 3-Clause License and
copyright (c) 2015-2021, SwissMicros. All rights reserved.
Changes and additions are protected by the BSD 3-Clause License
and made by deetee, (c) 2022. All rights reserved.
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
```
Welcome to IV42 - A Programable Calculator for the DM42 Hardware based on FORTH
____________________
PREAMBLE
____________________
The DM42 calculator is a genuine device. A brilliant LCD display, good keys, a
USB disk and a powerful processor - all low powered by a single battery cell.
On the very stable operating system (DMCP) runs Free42 - a perfect simulator of
the legendary HP42 calculator. Using an 128-bit floating point library makes it
the "most precise calculator in the world".
As the DM42 is an "open system" it is possible to run other software on top of
the operating system (DMCP). And that is, where IV42 comes in. IV42 is a small,
fast, simple, convenient and powerful calculator that integrates to the DM42
hardware (primarily the keyboard layout) in an optimal way. There is no need for
particular key labels or stencils!
IV42 has a slightly different approach to operate a scientific RPN calculator:
First - IV42 is FORTH orientated. It operates a big stack (actual 26 registers
from A to Z). Main part of FORTH is the dictionary, an alphabetical sorted
list of all commands and user programs. By the way the name IV or IVEE stands
for the roman number 4, which was also a reason for naming FORTH (4th
generation of programming languages).
The second and most obvious difference is the (very) big number display. IV42
shows the top of the stack (TOS) in an unusual big design. So it is possible
to operate the calculator under very bad light conditions.
The third difference are the 18 (!) function keys (3 rows of 6 top keys). So
you can fast and easy access commands, physical constants, unit conversions,
user programs or even ascii characters.
The fourth difference is, that IV42 always calculates with complex numbers.
Aside from all functions it is even possible to handle complex matrices or
complex hexadecimal numbers.
The fifth mentionable difference is the use of an exclusive ON/OFF key (EXIT)
like HP used it for the voyager series.
In addition IV42 offers of course many features like the original calculator:
* Programming (edit or load/save user programs from/to USB disk)
* Calculus (value, slope, root, integral and plot of a function)
* Physical constants (CODATA)
* Useful conversion functions
* Assignable function keys
* Hexadecimal numbers
* Matrices
* Statistics, line best fit, probabilities, normal distribution
* ...
Have fun!
deetee
____________________
INSTALLATION
____________________
Please note that you will loose all user data of your DM42 (ie. user programs or
settings) - make a backup!
Install IV42:
* First load IV42-xxx.pgm and (for desired later back switch to DM42)
DM42-x.xx.pgm (technical.swissmicros.com/dm42/firmware/) to the root directory
of the USB disk.
* In your DM42 calculator goto SETUP (SHIFT-0)
* Enter menu point [5. System >]
* Goto system menu with [2. Enter System Menu]
* Leave DM42 and switch back to the operating system (DMCP) with
[3. Reset to DMCP menu]
* Load another program with [3. Load Program]
* Select the IV42 program [IV42-xxx.pgm]
* [Confirm with ENTER]
* [Press any key to start]
* [Press EXIT to continue ...]
* You are running IV42 - have fun!
Reinstall DM42:
* Switch back to the operating system (DMCP) with SETUP (SHIFT-0)
* Load another program with [3. Load Program]
* Select the DM42 program [DM42-x.xx.pgm]
* [Confirm with ENTER]
* [Press any key to start]
* [Press EXIT to continue ...]
* You are running DM42 - thanks for trying IV42
____________________
HELP FILE
____________________
To view the HTML help file (iv42help.htm) execute the command HELP or press the
button [CUSTOM]. To view a help image (iv42help.bmp) execute the command IMG or
press the button [v]. Please note that both files have to be on the USB disk in
the folder IV42.
____________________
DISPLAY
____________________
In general the display consists of three sections (status line, TOS and F-keys).
Please note that you can invert the display for each section by using the
command DISP or pressing the button [DISP].
The status line shows on the left side text/error messages (see chapter
messages), titles or the alpha stack and on the right side system annunciators
(see chapter annunciators).
The TOS section shows the number on the top of the stack in big digits. Please
note that you can view the TOS with all available digits (double format) in the
status line by selecting SHOW or [SHOW].
In the F-key section you can see the labels for all 18 (3 rows with 6 keys)
function keys.
Finally there are specific display structures for plotting functions (see
chapter plotting) or editing programs (see chapter programming).
____________________
MESSAGES
____________________
ERROR Infinite operation
FILE ERROR File loading error
HOLD Program on hold
LOADED File loaded
LOOP ERROR Loop, nest or condition error
NO PROGRAM Desired program not loaded
NO SPACE No space to insert
RUNNING Running (solve, integrate, plot calculation)
SAVED File saved
STOPPED Program stopped
____________________
ANNUNCIATORS
____________________
Annunciators (6 most right characters of status line): AxCR09
A Stack level (A-Z, ! stack floated)
x HEX view
C Complex number
R Complex number input mode (Rectangular or Polar)
0 HYP-flag (h), menu level or complex view (real, imaginary, absolute, °angle)
9 Battery level (9...>=3V, 0...<=2.5V)
Note: At level 0 you get serious problems accessing the USB disk.
____________________
DICTIONARY
____________________
The most important part of a FORTH system is the dictionary where all commands
(words) and user program names are listed in an alphabetical order. You can
call the dictionary with the command DICT, the button [CATALOG] or simply by
pressing the key [^]. To select the demanded command press the appropriate
F-key.
Please note that you can assign every command or user program to the top
F-keys to execute it with one (with SHIFT at least two) keypress(es).
____________________
REALLY SUPER KEY
____________________
Because of the good position on the keyboard the R/S key ('Really Super Key') is
used multifunctional.
Per default it works as DUP or [ENTER] key to optimize fast 'number crunching'.
But if TOS is a complex number (note the C annunciator) the R/S key enters (and
leaves) the complex view mode (see chapter Complex Numbers).
In any menu (ie dictionary) the R/S key works like DROP or [<=] to exit the menu.
If an user program interrupts (HOLD) (for intermediate calculations) the R/S key
continues the execution of the user program.
Last, but not least - if you prepare a screenshot (with [SHIFT] and [DISP]
simultaneously) - the next pressed R/S key makes a screenshot.
____________________
BROWSING MENUS
____________________
Menus (dictionary, constants, selecting ascii character) use the 18 function
keys to choose the appropriate selection. For navigation use special keys:
[^] prev [7] 2 x prev [8] home [<=] exit menu
[v] next [4] 2 x next [5] end
[1] 2 x prev [2] 2 x next
[0] prev [.] next [R/S] exit menu
Every other key exits the menu.
____________________
COMPLEX NUMBERS
____________________
IV42 calculates always with complex numbers (in rectangular form).
The desired complex number input mode (Rectangular or Polar) can be selected
with Cmod or [MODES] - have also a look to the R or P annunciator.
If a complex number is on the TOS the C annunciator will be shown.
To enter a complex number enter the real part (R mode) respectively absolute
value (P mode) and the imaginary part (R mode) respectively angle (P mode) to
the stack and press CPLX or [COMPLEX]. This works vice versa.
Please note that only the real part (R mode) or absolute value (P mode) will be
shown on the display.
To view all parts of a complex number switch with R/S or [R/S] to the complex
number viewing mode. Another annunciator (real, imaginary, absolute, °angle)
appears. In this menu the following keys have special functions:
[ENTER] push value to stack and exit mode
[^] prev part [7] real part [8] imaginary part [<=] exit mode
[v] next part [4] absolute part [5] angle part
[0] prev part [.] next [R/S] exit mode
____________________
PROGRAMMING
____________________
IV42 offers 18 slots to manage user programs. You can save every user program to
USB disk or load a program from USB disk to a slot.
To select a program slot press Psel or [GTO] and choose a slot. The following
operations can be done with a selected program:
Pdel Delete the selected program
Pedt [PRGM] Edit the selected program (see below)
Pfcn [PGM.FCN] Top f key menu for programs (see below)
Plod [SST] Load a program from USB disk to the selected slot
Pren Rename the selected program (must be exactly 4 characters)
Psav [BST] Save the selected program to USB disk
With Pfcn or [PGM.FCN] you can open a special top f-key menu for editing (EDIT),
renaming (REN) deleting (DEL), loading (LOAD) or saving (SAVE) a program.
The program editor lists up to 6 steps of the user program. In addition it shows
the line number, the name and size of the program. Also the current position
(cursor) and the 'byte-position' are apparent. On the bottom of the screen
special top f-keys are offered to insert a command from the dictionary (INS), to
move the cursor fast (PG^, PGv, HOME, END) and to delete a step (DEL).
Of course you can use the cursor keys ([^] or [v]) to move the cursor up or down.
Please note that there is a fast way to insert numbers and some commands by
pressing the appropriate key or shifted key directly.
Drop [<=] or R/S [R/S] exits the editor.
____________________
CALCULUS
____________________
To examine a mathematical function y=f(x) write a program to calculate this
function (see chapter programming).
If this program is selected (Psel or [GTO]) you can calculate a function value
(execute the program name or [XEQ]), find a root (Fslv or[SOLVER]), integrate
(Fint or [INTEGRAL]), calculate the slope (Fslp) or plot the function (Fplt or
[PRINT]).
Please note that you have to prepare initial values to the stack first (a
x-value for calculating a function value, a start value for solving, a lower and
upper limit for integrating, an x-value for calculating the slope or a lower and
upper limit for plotting).
____________________
PLOTTING
____________________
When plotting a function (see chapter Calculus) the following keys have special
functions:
[^] zoom in
[v] zoom out [0] leftshift x-limits [.] rightshift x-limits
Every other key exits plotting.
Please note that leaving a function plot pushes the current values of the
lower/upper x-limit and minimum/maximum function value (y) to the stack.
____________________
MATRICES
____________________
IV42 can handle 3x3 matrices (+, -, *, /, det, transpose, invert, load
elements from the stack, save elements to the stack).
Open the matrix menu with MAT od [MATRIX]. In the status line you see the name
of the main matrix A or the supporting matrix B (switch with [SHIFT]), the
number of the row and column and the ASSIGN- or VIEW-mode (switch with [E]).
The top f-keys did change to supporting matrix functions:
DET Push the determinant of A to the stack
TRANS Transpose the selected (A or B) matrix
COPY Copy the selected matrix (A or B) to the other (B or A)
LOAD Pop 9 values from the stack to the matrix (TOS => 3|3)
SAVE Push all 9 matrix values to the stack (3|3 => TOS)
MCLR Clears matrix A and B
In addition the following keys are available:
[SHIFT] Toggle matrix A and B
[E] Toggle ASSIGN and VIEW mode
[^][v] Up/down one row
[0][.] Left/right one col
[/] Invert matrix A
[*] A*B
[-] A-B
[+] A+B
[x><y] Swap matrix A and B
[ENTER] Pushes viewed (VIEW mode) matrix element to stack
[<=][R/S] Exit matrix mode
PLease note that the matrix elements can be acessed by the cursor keys up or
down ([^] or [v]), left or right ([0] or [.]) respectively the corresponding
number keys 1-9 in a direct way.
For example to assign a number to A(1|3) enter the number, open the matrix menu
([MATRIX]), select matrix A ([SHIFT]) and ASSIGN ([E]) and push [9] (row 1,
column 3). To view the matrix element A(1|3) select matrix A ([SHIFT]) and VIEW
([E]) and push [9].
____________________
CONVERSIONS
____________________
IV42 is able to convert common units (see commands starting with '>').
But there is also a comfortable menu to choose the desired conversion:
Enter the number to convert to the TOS and press [CONVERT] (or execute CONV) and
select one of the following 18 function keys (convert to ...):
km mi m ft cm in
kg lbs l gal °F °C
deg rad h hms kW HP
____________________
COMMANDS AND KEYS
____________________
Please note the abbreviations TOS (Top Of Stack) and TOS-1 (next element on
the stack), TOS-2, ...
CMD KEY EXPLANATION
--------------------------------------------------------------------------------
[EXIT] ... Exclusive ON/OFF key
[SHIFT] ... Shift key or toggle matrix A<=>B (see chapter matrices)
0-9. ... Digits and decimal point
+ - * / ... Basic operations
% [%] ... Percent (TOS / TOS-1 * 100%)
%C ... Percent change ((TOS - TOS-1) / TOS-1 *100%)
<>? <? =? >? ... Conditions (not equal, less then, equal, greater then)
>KM >MI ... Convert Kilometer an Miles
>M >FT ... Convert Meter and Feet
>CM >IN ... Convert Centimeter and Inches
>KG >LBS ... Convert Kilogram and Pounds
>L >GAL ... Convert Liter and Gallons
>C >F ... Convert Celsius and Fahrenheit
>DEG >RAD ... Convert Degrees and Radians
>H >HMS ... Convert Hours and Hours.MinutesSeconds
>KW >HP ... Convert Kilowatt and Horsepowers
ABS ... Absolute value of TOS
ACOS [ACOS] ... Arcus cosine (inverse)
AND ... Logical AND
ASGN [ASSIGN] ... Assign command to top F-Key (TOS, 1-12)
ASIN [ASIN] ... Arcus sine (inverse)
ATAN [ATAN] ... Arcus tangent (inverse)
BEG ... Begin a BEGIN-UNTIL-loop
CHS [+/-] ... Change sign (negate)
CLK ... Runs TIME until break ([R/S] or [<=])
CLR [CLEAR] ... Clear stack
CONS [FLAGS] ... Physical constants (CODATA)
CONV [CONVERT] ... Unit conversions
COS [COS] ... Cosine (of angle in degrees)
CPLX [COMPLEX] ... Enter/deenter complex number (TOS-1, TOS)(see Cmod, R/S)
Cmod [MODES] ... Toggle complex number input mode (Rectangular or Polar)
DICT [CATALOG] ... Dictionary
DISP [DISP] ... Change display color or screenshot (hold SHIFT)
DROP [<=] ... Drop TOS
DUP [ENTER] ... Enter number input or duplicate TOS
E [E] ... Scientific notation
ELSE ... Execute following code if IF failed
EXP [e^x] ... Exponential value
F1-F12 ... Top F-keys (2x6)
FRAC ... Fractional value of TOS
Fint [INTGRT] ... Integrate selected user program (from TOS-1 to TOS)
Fplt [PRINT] ... Plot selected user program (from TOS-1 to TOS)
Fslp ... Slope of selected user program at TOS
Fslv [SOLVE] ... Solve selected user program (close to start value TOS)
HELP [CUSTOM] ... Browse html file /IV42/iv42help.htm
HEX ... Toggle HEX DEC view
HOLD ... Interrupt program execution (R/S key continues)
HYP ... Switch trigonometic to hyperbolic functions (and vice versa)
IF ... Execute following code if true
INT ... Integer value of TOS
INV [1/x] ... Inverse
IMG [v] ... View help image /IV42/iv42help.bmp
KEY? ... Interrupt program execution until keypress
LN [LN] ... Natural logarithm
LN! ... Natural logarithm of gamma of TOS
LOG [LOG] ... 10 based logarithm
L.R. ... Linear regression (line best fit: y = TOS * x + TOS-1)
LSTx [LASTx] ... Pushe last popped number to stack
MAT [MATRIX] ... Matrix menu
MOD ... Modulo
NAND ... Logical NAND
ND ... Normal Distribution (PDF and CDF)
NOT ... Logical NOT
OR ... Logical OR
OVER ... Copy TOS-1 to TOP
P/C [PROB] ... Permutations (nPr, TOS-1) and Combinations (nCr, TOS)
PAUS ... Pause program execution for TOS * 250 ms and print screen
PI [PI] ... PI
PICK ... Copy TOS-th stack element to stack
POL? ... Check if complex mode is polar (1) or rectangular (0)
PVAL ... Present value of given interest rate and periods
PW10 [10^x] ... 10 raised to the power or TOS
PWR [y^x] ... TOS-1 raised to the power of TOS
Pdel ... Delete selected user program
Pedt [PRGM] ... Edit selected user program
Plod [SST] ... Load user program from USB disk to selected program slot
Pfcn [PGM.FCN] ... Fade in top F-keys for treating selected programs
(EDIT, REN, DEL, LOAD, SAVE)
Pren ... Rename selected user program (4 characters exactly)
Psav [BST] ... Save selected user program to USB disk
Psel [GTO] ... Select user program for further treatment
QEQN ... Quadratic equation (xx + TOS-1 * x + TOS = 0)
R/S [R/S] ... 'Really Super Key'
RE? ... Check if TOS is real (1) or complex (0)
RCL [RCL] ... Recall value from register TOS to stack
ROT [Rv] ... Rotate/move TOS-2 to TOS
SHFT [SHIFT] ... Shift key or swap matrices A and B
SHOW [SHOW] ... Show TOS in status line
SIN [SIN] ... Sine (of angle in degrees)
SQR [x^2] ... Square
SQRT [SQRT] ... Square root
STAT [STAT] ... Statistics: Mean value (TOS) and standard deviation (TOS-1)
STKS ... Sum of all stack elements
STO [STO] ... Store TOS-1 to register TOS (0-9)
SUM+ [SUM+] ... Enter X- or YX-data (STAT, LR)
(uses registers 5-9: 5XX, 6XY, 7n, 8X, 9Y)
SUM- [SUM-] ... Remove X- or YX-data (STAT, LR)
SUMc ... Clear statistic registers (register 5-9)
SWAP [x><y] ... Swap TOS and TOS-1
TAN [TAN] ... Tangent (of angle in degrees)
THEN ... Terminate IF/ELSE condition
TIME ... Push time of RTC to stack (24h format)
Tclr ... Clear alpha stack (see Tput)
Tput [ALPHA] ... Push ascii character (TOS) to alpha stack (status line)
UNTL ... Continue executing a BEGIN-UNTIL-loop until TOS is true
UP [^] ... Up (menu navigation) and [v] (down)
XEQ [XEQ] ... Execute selected user program
____________________
PHYSICAL CONSTANTS
____________________
To enter the constants menu press [FLAGS] (or CONS).
c 299792458 Speed of light
g 9.80665 Acceleration of gravity
G 6.67430e-11 Newton constant of gravity
Vm 0.02271095464 Molar volume of ideal gas
NA 6.02214076e23 Avogadro constant
Rinf 10973731.568160 Rydberg constant
e 1.602176634e-19 Elementary charge
me 9.1093837015e-31 Electron mass
mp 1.67262192369e-27 Proton mass
mn 1.67492749804e-27 Neutron mass
mmu 1.883531627e-28 Muon mass
k 1.380649e-23 Boltzmann constant
h 6.62607015e-34 Planck constant
Phi0 2.067833848e-15 Magnetic flux quantum
a0 5.29177210903e-11 Bohr radius
eps0 8.8541878128e-12 Vacuum electric permittivity
R 8.314462618 Molar gas constant
F 96485.33212 Faraday constant
mU 1.6605390666e-27 Atomic mass constant
mu0 1.25663706212e-6 Vacuum magnetic permeability
muB 9.2740100783e-24 Bohr magneton
muN 5.0507837461e-27 Nuclear magneton
mup 1.41060679736e-26 Proton magnetic moment
mue -9.2847647043e-24 Electron magnetic moment
mun -9.6623651e-27 Neutron magnetic moment
mumu -4.4904483e-26 Muon magnetic moment
re 2.8179403262e-15 Electron radius
Z0 376.730313668 Impedance of vacuum
alph 7.2973525693e-3 Fine structure constant
sigm 5.670374419e-8 Stefan-Boltzmann constant
t 273.15 Celsius temperature
atm 101325 Standard atmosphere
gamp 2.6752218744e8 Proton gyromagnetic ratio
C1 3.741771852e-16 First radiation constant
C2 1.438776877e-2 Second radiation constant
G0 7.748091729 Conductance quantum
____________________
ASCII TABLE
____________________
DEC | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
HEX | 0 1 2 3 4 5 6 7 8 9 a b c d e f
------------------------------------------
032 20 | ! " # $ % & ' ( ) * + , - . /
048 30 | 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
064 40 | @ A B C D E F G H I J K L M N O
080 50 | P Q R S T U V W X Y Z [ \ ] ^ _
096 60 | ` a b c d e f g h i j k l m n o
112 70 | p q r s t u v w x y z { | } ~
Special font characters:
[] ... Up and down arrow
` ... Degree character '°'
{} ... Left and right arrow
~ ... Small/narrow dot separator
```
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
____________________
FONT, CMD, MP
____________________
6x7-font: S_12x28 (scale 2|4), M_18x42 (scale 3|6), L_36x84 (scale 6|12)
MAXCMDI
v
CMD 0...144 145 ... 163
0 ... 17
|--MAXPRG-|
sizeof(mem)
v
MP |--- mem ---|-MAXPRGLEN-|-MAXPRGLEN-| ... |
prgnr 0 prgnr 1 ...
*/
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// I N C L U D E S & P R O T O T Y P E S
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <dmcp.h>
#define TRUE 1
#define FALSE 0
#define byte uint8_t // Define type byte
static void _cdseek(void);
static void _dup(void);
static void _inv(void);
static void _mult(void);
static void _negate(void);
static void _storcl(byte);
static void loadprg(void);
static void saveprg(void);
static void execute(byte);
static void _swap(void);
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// D E F I N E S & C O N V E R S I O N S
#define BLACK 0xff // Color black
#define WHITE 0x00 // Color white
#define MAXSTRLEN 37 // Maximal size of string
#define STACKSIZE 26 // Stack size
#define REGISTER 10 // Number of registers for STO/RCL
#define ADDRSTACKSIZE 64 // ADDRESS STACK
#define FKEYNR 18 // Number of (virtual) F-Keys
#define MAXCMDK 86 // Number functions reachable with keys
#define MAXCMDI 144 // Number of intrinsic functions (multiple of 18)
#define TOSY1 49 // TOS y-coordinate 1
#define TOSY2 144 // TOS y-coordinate 2
#define MAXPRG 18 // Number of user programs
#define MAXPRGLEN 100 // Size of user program
#define NLEN 4 // Length of program names
#define PI 3.1415926535897932384626
#define RAD ((180.0)/(PI)) // 180/PI
#define ALMOSTZERO 1e-10 // Needed to determine 0 values (isreal())
#define VIEWMAX 4 // Maximal number of complex views
#define VIEWRE 1 // Complex view - rectangular
#define VIEWIM 2 // Complex view - imaginary
#define VIEWABS 3 // Complex view - absolute
#define VIEWANGLE 4 // Complex view - angle
#define _MA 0 // Matrix A
#define _MB 1 // Matrix B
#define _MC 2 // Matrix C
#define DELTAX 1E-4 // Delta for solver or slope
#define INTSTRIPES 10 // Number of Simpson stripes for integrating
#define PLTPIX 8 // Pixel size of plot spot
#define PLTX 50 //400/PLTPIX // Plot spots - x
#define PLTY 29 //240/PLTPIX // Plot spots - y
// --Key------------------ --Key Code------- --Function-------
// F1 F2 F3 F4 F5 F6 38 39 40 41 42 43 25 26 27 28 29 30
// SUM 1/X SQR LOG LN XEQ 1 2 3 4 5 6 31 32 33 34 35 36
// STO RCL ROT SIN COS TAN 7 8 9 10 11 12 37 38 39 40 41 42
// ETR SWP CHS E BSP 13 14 15 16 17 20 19 18 17 16
// UP 7 8 9 / 18 19 20 21 22 21 7 8 9 15
// DN 4 5 6 * 23 24 25 26 27 22 4 5 6 14
// SH 1 2 3 - 28 29 30 31 32 23 1 2 3 13
// EXT 0 . RS + 33 34 35 36 37 24 0 10 11 12
static const byte key2fn[]={0, //0 (not used) - Convert key to function
31, 32, 33, 34, 35, 36, // 1(SUM) ... 6(XEQ)
37, 38, 39, 40, 41, 42, // 7(STO) ... 12(TAN)
20, 19, 18, 17, 16, // 13(ENTER) ... 17(BACKSPACE)
21, 7, 8, 9, 15, // 18(UP) ... 22(/)
22, 4, 5, 6, 14, // 23(DOWN) ... 27(*)
23, 1, 2, 3, 13, // 28(SHIFT) ... 32(-)
24, 0, 10, 11, 12, // 33(EXIT) ... 38(+)
25, 26, 27, 28, 29, 30 // 38(F1) ... 43(F6)
};
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// U T I L S
#define ones(x) ((x)%10) // Ones digit of integer
#define tens(x) (((x)/10)%10) // Tens digit of integer
#define huns(x) (((x)/100)%10) // Huns digit of integer
#define _min(a,b) (((a)<(b)) ? (a) : (b)) // Minimum
#define _max(a,b) (((a)>(b)) ? (a) : (b)) // Maximum
#define i2c(x) ((x)+'0') // Converts int-digit (0-9) to char (+'0')
static double _abs(double f) { // Returns absolute
return(f<0.0 ? -f : f);
}
static void beep(){ // Single beep
start_buzzer_freq(1000*1000); sys_delay(10); stop_buzzer();
}
static void make_screenshot(){ // Make screenshot
beep();
if(create_screenshot(1)==2) wait_for_key_press(); // Wait if error
}
static byte isdig(char n){ // True, if n = 0...9
return((n>='0' && n<='9') ? TRUE : FALSE);
}
static void strfill(char * s, char c, byte n){ // Fill string with n chars
for(byte i=0; i<n; i++) s[i]=c;
s[n]='\0';
}
static void strdelpos(char * s, byte n){ // Delete n-th char from string
memcpy(s+n, s+n+1, strlen(s)-n);
}
static void strstrat(char * s, char * s1, byte pos){ // Write s1 to s at pos
memcpy(s+pos, s1, strlen(s1));
}
static void strintat(char * s, byte n, byte pos){ // Int (<100) to s at pos
s[pos+1]=i2c(ones(n)); if(n>9) s[pos]=i2c(tens(n));
}
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// G L O B A L V A R I A B L E S
static byte color=0x04; // Color flags of STATUS (0x01), TOS (0x02), FKEY (0x04)
static byte isprintscreen=TRUE; // Print screen if TRUE
static byte isshift; // Shift status
static byte isedit; // True, if number ist edited
static byte isshow=FALSE; // Shows TOS isn status line id true
static byte isfloated=FALSE; // True, if stack was floated
static byte ispolar=FALSE; // Show imaginary number in polar format
static byte isdict=FALSE; // True, if dictionary is demanded
static byte sel=0; // Menu selection number
static byte isassign=FALSE; // True, if a F-key should be assigned
static byte ishyp=FALSE; // True, if TRIG is interpreted as HYP
static byte isconvert=FALSE; // True for conversion menu
static byte isphys=FALSE; // True for physical constants menu (flags-key)
static byte isprg=FALSE; // True if program should be treated
static byte isprgsel=FALSE, isprgedit=FALSE, isprgins=FALSE; // Select, edit or insertstep
static byte isselasc=FALSE; // True when selecting an ascii character
static byte ishex=FALSE; // True when working with hex numbers
static byte isprintalpha=FALSE; // Print alpha if true
static int holdmp=0; // Holds mp, while user prg stops (continue with R/S)
static byte isscreen=FALSE; // Next R/S makes screenshot
static byte isimgview=FALSE; // View image
static char ed[MAXSTRLEN]; // Number editor string
static byte dotchar='.', expchar='E'; // Character of dot and exponent
static char sline[MAXSTRLEN+1]; // Line buffer string
static int mp=0; // Mempointer for builtin functions
static byte view=0; // Complex number view (1=re 2=im 3=abs 4=angle)
static byte fkeys[12]; // F-key commands
static byte cmdsort[MAXCMDI+MAXPRG]; // Alphabetically sorted commands for DICT
static char alpha[MAXSTRLEN]=""; // String for user text output
static byte pause=0; // Pause
static byte msgnr=0; // Message number
#define MSGASK 0
#define MSGSHIFT 1
#define MSGERROR 2
#define MSGNEST 3
#define MSGSPACE 4
#define MSGFILE 5
#define MSGSAVED 6
#define MSGLOADED 7
#define MSGSTOP 8
#define MSGHOLD 9
#define MSGPRG 10
#define MSGRUN 11
char * const msg[]={ // Message text
"?","SHIFT","ERROR","LOOP ERROR", "NO SPACE",
"FILE ERROR", "SAVED", "LOADED", "STOPPED", "HOLD",
"NO PROGRAM", "RUNNING"
};
struct data {double r,i;}; // Structure for numbers
struct data lastx=(struct data){0.0, 0.0}; // LASTx
struct data reg[REGISTER]; // Register to STO and RCL
struct data ds[STACKSIZE]; // Data stack
static byte dp=0; // Data stack pointer
static int as[ADDRSTACKSIZE]; // Address stack
static byte ap = 0; // Address stack pointer
static byte cl=0; // Condition level
static double m[6][3][3]; // Matrices A:0/1 B:2/3 C:4/5
static byte ismat=FALSE, ismatview=FALSE; // Matrix and view mode
static byte msel=_MA; // Selected matrix (A or B)
static double mdet, mdeti; // Determinant of matrix
static byte matr=0, matc=0; // Row and col of selected matrix slot
static byte prg[MAXPRG][MAXPRGLEN]; // User programs
static char prgname[MAXPRG+1][NLEN]; // Program names (+1 to enable acces to last)
static byte psel=0; // Selected program
static byte pstart, pp, pend; // Program listing
static byte isprgloaded=FALSE; // Needed to evaluate if prg was loaded
static byte issolve=FALSE, isint=FALSE, isslope=FALSE; // SOLV/INT/SLOPE
static byte runs; // Solver/integrator cycle runs
static double inta, intb, intdelta, fx, fres; // INT (SLOPE) variables
static double plot[PLTX]; // Y-values of plot graph
static double plota, plotb, plotd, ymax, ymin; // Variables used for plotting
static byte isplot=FALSE, isplotcalc=FALSE; // Plotting or plot calculation
double const pc[]={ // Physical constants
299792458, 9.80665, 6.67430e-11, 0.02271095464, 6.02214076e23, 10973731.568160,
1.602176634e-19, 9.1093837015e-31, 1.67262192369e-27, 1.67492749804e-27, 1.883531627e-28, 1.380649e-23,
6.62607015e-34, 2.067833848e-15, 5.29177210903e-11, 8.8541878128e-12, 8.314462618, 96485.33212,
1.6605390666e-27, 1.25663706212e-6, 9.2740100783e-24, 5.0507837461e-27, 1.41060679736e-26, -9.2847647043e-24,
-9.6623651e-27, -4.4904483e-26, 2.8179403262e-15, 376.730313668, 7.2973525693e-3, 5.670374419e-8,
273.15, 101325, 2.6752218744e8, 3.741771852e-16, 1.438776877e-2, 7.748091729
};
char * const pcname[]={
"c", "g", "G", "Vm", "NA", "Rinf",
// Speed of light, Acceleration of gravity, Newton constant of gravity,
// Molar volume of ideal gas, Avogadro constant, Rydberg constant
"e", "me", "mp", "mn", "mmu", "k",
// Elementary charge, Electron mass, Proton mass,
// Neutron mass, Muon mass, Boltzmann constant
"h", "Phi0", "a0", "eps0", "R", "F",
// Planck constant, Magnetic flux quantum, Bohr radius,
// Vacuum electric permittivity, Molar gas constant, Faraday constant
"mU", "mu0", "muB", "muN", "mup", "mue",
// Atomic mass constant, Vacuum magnetic permeability, Bohr magneton,
// Nuclear magneton, Proton magnetic moment, Electron magnetic moment
"mun", "mumu", "re", "Z0", "alph", "sigm",
// Neutron magnetic moment, Muon magnetic moment, Electron radius,
// Impedance of vacuum, Fine structure constant, Stefan-Boltzmann constant,
"t", "atm", "gamp", "C1", "C2", "G0"
// Celsius temperature, Standard atmosphere, Proton gyromagnetic ratio
// First radiation constant, Second radiation constant, Conductance quantum
};
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// S T A C K S U B R O U T I N E S
static void dpush(struct data c){ // Push number to data stack
if(dp>=STACKSIZE){ // Float stack if full
memmove(ds, ds+1, (STACKSIZE-1)*sizeof(struct data));
dp--; isfloated=TRUE;
}
ds[dp++]=c;
}
static double dpushr(double f){ // Push real number to data stack
dpush((struct data){f, 0});
return(f);
}
static struct data dpop(void){ // Pop value from data stack
if(dp){lastx=ds[dp-1]; return(ds[--dp]);}
return((struct data){0.0, 0.0});
}
static double dpopr(void) { // Pop real number from data stack
return(dp ? dpop().r : 0.0);
}
static void apush(int addr) { // Push address (int) to address stack
if(ap>=ADDRSTACKSIZE) msgnr=MSGNEST; else as[ap++]=addr;
}
static int apop(void) { // Pop address (int) from address stack
return(ap ? as[--ap] : 0);
}
static byte isreal(void) { // True, if TOS is real
if(dp && _abs(ds[dp-1].i)>ALMOSTZERO) return(FALSE); // Imaginary part almost 0
return(TRUE);
}
static double absolute(double a, double b) { // Returns abs value of complex
a=_abs(a); b=_abs(b);
if(a==0.0) return (b);
else if(b==0.0) return (a);
return(exp(0.5 * (log(a)+log(a+b/a*b))));
}
static double angle(double a, double b) { // Returns the angle of complex
double tmp=atan(b/a)*RAD;
if(a==0.0) return ((b<0.0) ? -90.0 : 90.0); // Special case imaginary
else if(a<0.0) {
return((b<0.0) ? (tmp-180.0) : (tmp+180.0)); // Quadrant 2 or 3
}
else return(tmp); // Quadrant 1 or 4
}
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// E D I T I N P U T S T R I N G
static void editfinish(void){ // Finish input edit string
isedit=FALSE;
if(ishex) dpushr(strtol(ed, NULL, 16)); // Hex-String to float
else dpushr(atof(ed)); // String to float
}
static int editcat(char c, int len){ // Append character to edit string
if(len<MAXSTRLEN){ed[len++]=c; ed[len]='\0';}
return len;
}
static int editdel(char * at, int len){ // Delete first character
memmove(at, at+1, len);
return(len-1);
}
static int editins(char * at, char c, int len){ // Insert first character
if(len<MAXSTRLEN){memmove(at+1, at, ++len); at[0]=c;}
return len;
}
static void editadd(int key){ // Add key to editstring
if(!isedit){ // Start editing
ed[0]='\0';
if(key==KEY_E) strcpy(ed,"1"); else if(!ishex) strcpy(ed,"0");
isedit=TRUE;
}
int len=strlen(ed);
char * dot=strchr(ed, dotchar), * exp=strchr(ed, expchar);
switch(key){
case KEY_DOT:
if(dot || exp) return; // It has already dot or no dots in exponents
len=editcat(dotchar, len);
break;
case KEY_E:
if(!exp && !ishex) len=editcat(expchar, len); // Hex or it has already exponent
return;
case KEY_CHS:
if(exp) // Change exp sign
len=(exp[1]=='-') ? editdel(exp+1, len) : editins(exp+1, '-', len);
else // Change mantissa sign
len=(ed[0]=='-') ? editdel(ed, len) : editins(ed, '-', len);
break;
case KEY_BSP:
ed[--len]=0;
if(len==0){isedit=FALSE;} // Leave edit (last char was removed)
break;
default: // Numbers
if(!dot &&
( (len==1 && ed[0]=='0') || (ed[len-1]=='0' && !isdig(ed[len-2])) ) )
ed[--len]=0; // Remove redundant 0
editcat(key2fn[key]+'0', len); // NonHEX
if(ishex){ // HEX
if(len){ // String long enough
if(ed[len-1]=='.'){ // >9 found
if(ed[len]>='1' && ed[len]<='6') ed[len-1]=ed[len]-'1'+'a'; // a-f
ed[len--]='\0';
}
}
}
break;
}
}
//--v----1----v----2----v----3----v----4----v----5----v----6----v----7----v----8
// B U I L T I N F U N C T I O N S
#define _0 0 // Intrinsic commands
#define _1 1
#define _2 2
#define _3 3
#define _4 4
#define _5 5
#define _6 6
#define _7 7
#define _8 8
#define _9 9
#define _DOT 10
#define _ADD 12
#define _SUB 13
#define _MULT 14
#define _DIV 15
#define _DROP 16
#define _NEG 18
#define _SWAP 19
#define _DUP 20
#define _INV 32
#define _LN 35
#define _STO 37
#define _RCL 38
#define _ROT 39
#define _SIN 40
#define _EXP 78
#define _CMPLX 80
#define _PI 82
#define _ISREAL 86
#define _IF 87
#define _ELSE 88
#define _THEN 89
#define _EQ 90
#define _NE 91
#define _LT 92
#define _BEGIN 94