Commit graph

178 commits

Author SHA1 Message Date
Christophe de Dinechin
1c21767890 Refresh the main loop to match DM42 PGM structure
There are some slight differences between the structure of the DM42
program and the structure implemented here. Not sure whether the
differences matter, but better follow a known-good model.

Also add missing DMCP critical section functions that appear used
in the DM42 code: `sys_critical_start()` and `sys_critical_end()`.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-30 20:46:01 +02:00
Christophe de Dinechin
7d6b6e6e6c Add object->debug() function for debugger use
This makes it easier to inspect RPL objects from debugger

For example, in `lldb`, you can use:

```
p obj->debug()
```

And this will show the content of the object as rendererd by the runtime.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-29 23:21:55 +02:00
Christophe de Dinechin
a34aef0574 Build fixes for Fedora Linux
Various portability fixes to help building on Linux.

This includes a pre-build Intel binary library for Linux x86_64.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-28 15:16:42 +02:00
Christophe de Dinechin
3cfa86fbd5 Add support for %t to print RPL objects in the recorder
To ease debugging, add a %t format turning RPL object pointers into their text
rendering while tracing.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-27 06:25:32 +02:00
Christophe de Dinechin
bb983d1ac5 Add option to slow-down automated tests
The `-w` command-line option takes a delay in millisecond between keystrokes.
Running slower minimizes the chances of a sync issue between the RPL thread and
the test thread. However, this mechanism is still not robust. I need to find a
reliable way to identify when the RPL thread is done processing the input from
the test thread.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-24 12:31:22 +02:00
Christophe de Dinechin
042461e98c Rate limiting of the warning messages about pixels out of range
It really slows down the rendering when they are being output in Emacs

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-24 00:35:50 +02:00
Christophe de Dinechin
f99a933586 More robust mechanism for saving state on exit on the simulator
The RPL thread now sends a -1 key repeatedly until the main loop exits and saves
the state.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-24 00:19:49 +02:00
Christophe de Dinechin
bdefd10f38 Force exit of DMCP menus when application exits
The application dialog is in a loop processing keys, so send a special "exit"
keycopde (-1) to force it out.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 23:58:38 +02:00
Christophe de Dinechin
ca9fcbe3a6 Switch to using QT File dialog and settings to save state
The `QSettings` class is only used to store the path to the actual state.
The use of the file dialog seems to cause some trouble with the current working
directory, and this impacts the display of the help file.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 22:53:37 +02:00
Christophe de Dinechin
a6110717be Implement a basic DMCP file selector
This makes it possible to test and debug the state load/save code on the
simulator.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 20:26:34 +02:00
Christophe de Dinechin
f13cd0c6dc Some hare-brained simulation of the DMCP menu system
This makes it possible to handle DMCP menus, including load/save state.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 19:50:21 +02:00
Christophe de Dinechin
c187d3f6a8 Add some stubs for missing DMCP commands
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 18:31:57 +02:00
Christophe de Dinechin
6e39474f3b Infrastructure and DMCP menus to load/save programs and state
This is heavily lifted from the DMCP code examples

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-23 10:18:16 +02:00
Christophe de Dinechin
39be6cc0c2 Move DMCP file operations to separate file.h / file.cc
This will be useful if we want to do more than just reading the on-line help.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-22 18:51:21 +02:00
Christophe de Dinechin
1d58abd64c Add the ability to use the DB48X keyboard mapping
This makes it possible to check on simulator what things would look like.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-22 18:30:38 +02:00
Christophe de Dinechin
094ad834f1 Emit signals for widget resize / repaint
The MainWindow::pushKey() method can be called from the test thread.
Therefore, we need to use emit to update the window, otherwise we end up with a
crash in the long run.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-20 19:06:56 +02:00
Christophe de Dinechin
2a8a0ae7a3 Add sanitizer option on macOS
Add the -fsanitizer=address option to macOS simulator builds

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-20 19:06:56 +02:00
Christophe de Dinechin
9e8444e6c3 Implement a fraction type for both integer and bignum
Two representations for fractions, one for small value of numerator and
denominator, one when both values are larger.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-20 19:06:56 +02:00
Christophe de Dinechin
6d8964ea92 Move the rendering logic into the renderer class
Various pieces of code, essentially equivalent to one another, were implemented
at various places to write into rendering buffers. Replaced all this ad-hoc code
with a single implementation in the renderer, which not only simplifies things
quite a bit, but also allows us to write in the scratchpad without a risk.

Also fixed a problem with the runtime::scratchpad() function returning the
beginning of the scratchpad instead of its current position, which was
inconsistent with a usage that assumed it moved with runtime::allocate(). This
enables a called function to use the scratchpad itself, while its caller also
holds something in it. This is necessary for the rendering of bignums, which
relies on long-division of bignums, and therefore can cause garbage collection,
while we may have the previous set of digits in an earlier part of the
scratchpad.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-20 18:48:51 +02:00
Christophe de Dinechin
77bc37c58a Reimplement bignum as a separate type
Having a sized type for bignum is more efficient both at runtime and in terms of
memory usage:

- At runtime, we don't need all the 7-bit masking and modulo-7 arithmetic
- In terms of memory, there is a cross-over at 63 bits, which is almost exactly
  where it becomes uninteresting to do in-CPU arithmetic

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 22:08:33 +02:00
Christophe de Dinechin
0b771b1993 Add comparison and logic operators
Also add the missing 'abs' function

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 22:05:30 +02:00
Christophe de Dinechin
a10c8b1779 Implement various kinds of loops
Implement do..until..end, while..repeat..end, start..next, start..step,
for..next, for..step. The latter two are not correct yet because we don't have
local variable lookup creation and lookup yet.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 22:05:30 +02:00
Christophe de Dinechin
08638f7ef8 Remove debug menu, allocate more memory
Experimentally, we need to leave about 4K free for "other stuff"

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:33 +02:00
Christophe de Dinechin
303ac0ff17 Add Catalog feature
Add catalog and auto-completion

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:33 +02:00
Christophe de Dinechin
7eb144db2a Avoid having a noisy warning on the simulator
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:33 +02:00
Christophe de Dinechin
a1deadedb7 Add ability to run "current" tests
These tests are for example to setup an environment for testing

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:33 +02:00
Christophe de Dinechin
f789158ea5 First pass at RPL-based menus
Added an RPL menu object and connected it to the input class

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
97399d8fbd Move DM42-specific code under the dm42/ directory
This frees 'menu.h' and 'menu.c' for RPL menus

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
5a730fb549 Management of global variables
Also added more details on the description of the memory map, including planned
organization for local variables.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
30ef056ec1 Replace 'string' with 'text
A recurring pet peeve of mine: 'string' is an implementation detail.
We care that it's used to represent text

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
0280891dfb Parsing and evaluation of programs
A simple program now evaluates, but a bit too early

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
f29d405b71 Parsing and rendering of list objects
List syntax is { ABC DEF { 12 34 "Hello world" } }

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
9588917e88 Connect the most common scientific functions
Connect functions like sin, cos, tan, log, etc.

The bad news is that the bid128 functions take _a lot_ of space.

I thought that all of the Intel decimal floating point library was put in the
QSPI, but apparently, only some tables are. The total of the Intel
floating-point code is roughly 1.49M, the code in the calculator roughly 423K.

The code is rather on the large-ish side, with some large chunks of code that
are really hard to explain, like bid128_pow taking a whopping 42K, which is over
5% of my total memory budget (unless I want to take over the QSPI).

    00000004 T __bid128_rem
    00000024 T __bid128_from_uint64
    00000048 T __bid128_from_int64
    00000062 T __bid128_isInf
    00000082 T __bid128_copySign
    00000104 T __bid128_fma
    00000108 T __bid128_sub
    00000180 T __bid128_isZero
    00000348 T __bid128_atan
    00000348 T __bid128_tanh
    00000352 T __bid128_erf
    00000376 T __bid32_to_bid128
    00000404 T __bid128_expm1
    00000516 T __bid128_asin
    00000544 T __bid128_log1p
    00000572 T __bid64_to_bid128
    00000576 T __bid128_acos
    00000604 T __bid128_cbrt
    00000608 T __bid128_mul
    00000608 T __bid128_tgamma
    00000640 T __bid128_exp
    00000648 T __bid128_asinh
    00000656 T __bid128_log
    00000668 T __bid128_log2
    00000676 T __bid128_exp2
    00000684 T __bid128_log10
    00000768 T __bid128_cosh
    00000784 T __bid128_atanh
    00000784 r bid_coefflimits_bid128
    00000880 T __bid128_sinh
    00000900 T __bid128_acosh
    00000968 T __bid128_exp10
    00001016 T __bid128_lgamma
    00001048 T __bid128_erfc
    00001628 T __bid128_class
    00001752 T __bid128_round_integral_zero
    00002004 T __bid128_quiet_equal
    00002176 T __bid128_round_integral_nearest_even
    00002740 T __bid128_to_string
    00003208 T __bid128_to_int32_rnint
    00003680 T __bid128_tan
    00003708 T __bid128_cos
    00003728 T __bid128_to_int32_xrnint
    00003736 T __bid128_quiet_greater
    00003740 T __bid128_sin
    00003748 T __bid128_quiet_less
    00003748 T __bid128_quiet_less_equal
    00004400 T __bid128_hypot
    00004440 T __bid128_to_binary128
    00004700 T bid128_to_binary128_2part
    00004864 T __bid128_to_bid32
    00005484 T __bid128_to_bid64
    00005876 T __bid128_fmod
    00008430 T __bid128_sqrt
    00008592 T __bid128_from_string
    00010140 T __binary128_to_bid128
    00017348 T __bid128_div
    00024390 T __bid128_add
    00029524 t bid128_ext_fma
    00042058 T __bid128_pow

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
fa5fe5ad5e Switch to a new font for help
Also use the same font for stack and editor.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
390a79a870 Batter voltage reading
Not sure I got this right, but better to see some voltage reading on the actual machine.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
7b4eda3578 Fix a problem shutting down the test thread
This was blocking the simulator on exit

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:32 +02:00
Christophe de Dinechin
ad439196e3 Add lcd_toggleFontT emulation
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
ecf939ae05 Build fonts for editor and stack
Add references to the UI fonts from font.h
Also add font::height() to compute the height of the font

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
13abd5c7f3 Build C43S TTF font and integrate that into the build and simulator
This will be the next interesting font to use...

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
6e3557ace4 Add some basic code for font objects
This parses the font object to return the address of the bitmap data.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
a8e0a48f5d Use the new graphics to clear the screen
This is a simple small-scale test that uses the new graphics routine to clear
the screen with a gray-scale pattern.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
18c1fb3d84 Highlight key positions when a key is pressed
This makes it plain which key is being pressed in the simulator

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
70a919ec4f Testing framework
A simple testing framework that enters keys and observes the calculator

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
c3b6cebb32 Increment screen update to make it easier to detect changes
If multiple consumers need to check if the screen has changed, a simple flag
does not do it. Instead, increment a counter that each client will be able to
check indepdendently.

This will be useful for an upcoming test framework

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
d6fa249301 Remove unused thread_yield function
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
82e30ecf7b The simulator has no "OFF mode
Clear the corresponding bits, otherwise the RPL thread goes into infinite loop

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
35c4c46f65 Implement arithmetic operations
This is made a bit complicated by the fact that numbers can be represented in 6
integer types and 3 decimal floating-point types. So every operation must deal
with promotion.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
bdf017e40f Add algebraics, the base class for algebraic operations
All the to-be-created-shortly operations like addition, etc, are not just
commands, but algebraic operations in RPL, so prepare for that

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
89a774ba5f Add RPL symbols (names)
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
1622e03145 Basic infrastructure for RPL commands
Implemented three basic commands: dup, drop and swap

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
ea710d247d Indicate location of bad character
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
f29743061f Record menu content in lcd_draw_menu_keys
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
4a492b31fb Add recorder for simulator keys
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
db47cd69ca Put the primary makefile rules at the top
If not, then recorder/config.h gets picked by default for 'make'

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
1b1e2c7ec7 Enable traces for all warnings and errors
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
4c5143e62c Pass debug config to simulator
Also define DEBUG define for DEBUG builds

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
d6ccfcaf83 Integrate the recorder into object operations
Record information about run, parse and render

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
e85b1fd79c Add the recorder library on the simulator
We can't really use it on the DM42 itself, because it has so
little memory (70K) that using it for recorders is a waste.
But for debugging on the simulator, it's really handy.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
0e800f1a68 Implement basic stack rendering
Show objects on the stack, calling the appropriate renderer

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
9840da59d3 Fix bad error message
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:31 +02:00
Christophe de Dinechin
62baa7d25e Super-dumb implementation of timers
I wanted to do something smart with QTimer, but it fails because they interact
with QT's event loop, making timers across threads annoyingly difficult.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
3accd9d15d Revert the display to match what the calculator displays
Had one and zeroes backwards.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
be3591b822 Add an display class, finish some cleanup on editor
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
884b3d164e Some progress towards having a real editor
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
56a7689d2b Deal with unused parameters in a more scalable way
The two compilers disagree on how to disable a parameter.
Putting it as an attribute requires less typing anyway.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
644e7954b7 Decimal128 objects and related
This uses the Intel library for 3 classes of precision

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
ec89310a8b Silence warnings
Remove "unused parameters" in dmcp.cpp, since most functions are only half-there
Remove format security warning on printf utility

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
23d69a0531 Refactoring of main.cc
Move utilities away, elimination of type warnings, a lot of other minor changes

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
c9fd0514ad Add a simple benchmark to check FP capabilities
Results for 1000 iterations:
- BID+USB: 3667ms   (bid128)
- BID+Bat: 10091ms
- DBL+USB: 668ms    (double)
- DBL+Bat: 1963ms
- FPU+USB: 43ms     (float)
- FPU+Bat: 96ms

So we have close to two orders of magnitude between hardware FP and BID,
and a factor of 15 between double and float.

For 1M iterations on simulator:
- BID: 9847ms
- FPU: 172ms
- DBL: 240ms

So here, the ratio is ~50. And the simulator is roughly 370x faster than the
calculator, which we will need to remember as we implement complicated
or expensive algorithms.

Also, we will need to really prefer float wherever possible, since this is
processed in hardware, whereas I suspect that double is only software on that
CPU.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
bc90e50a53 Fix key mapping error in target.h
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
126642cd74 Must terminate a thread before destroying it
Qt crashes otherwise

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
53a6f1384c Minor visual adjustments to make it look closer to the real thing
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
189d1baeb8 Select black background for the screen
Match the calculator's appearance

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
daf8e0c384 Working simulator, good enough for initial debugging
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
e8b97fb81d Add some code to save the calculator fonts
Get the calculator fonts for the simulator

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
027da1f9cc Use the correct version of Intel's decimal FP library
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
eeacaf6646 Simulated sdb must be in regular memory
The original sdb is somewhere in the DMCP

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00
Christophe de Dinechin
6399a1556a Prototype simulator for the DM42
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2023-06-19 21:56:30 +02:00