Commit graph

1900 commits

Author SHA1 Message Date
Christophe de Dinechin
0c1abf2689 simulator: Separate db50x and db48x builds
Put the object files in different locations, since they use different
configuration parameters that widely impact the generated code.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-11 13:05:30 +02:00
Christophe de Dinechin
80e94a38d4 tests: Add colorized images to testing
Add a color-images directory to record color reference images

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-11 13:05:30 +02:00
Christophe de Dinechin
88009cc619 ui: Add colorization parameters for the user interface
Add configuration parameters that lets you choose the color for the
various elements in the user interface.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-11 13:05:30 +02:00
Christophe de Dinechin
2bc70413f2 ui: Define cursor position in SelfInsert with \t
The `\t` character inside a label menu or `SelfInsert` command marks
the position for the cursor.

Fixes: #881

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-10 11:59:18 +02:00
Christophe de Dinechin
acb067b8ef ui: Add some colorization
Draw the battery voltage with a different color based on level.
Draw a red line around error messages.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-09 19:21:00 +02:00
Christophe de Dinechin
879e1fef28 help: Do not display command name while editing
When editing on the command line, it's not helpful to have `exp` or
other command names show up as you enter them.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-09 19:21:00 +02:00
Christophe de Dinechin
898bf33c11 graphics: Separate color conversion step
Split the color conversion step away from the blitop function.
This makes the `Walkman` demo work in color mode.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-09 13:00:14 +02:00
Christophe de Dinechin
6a490db880 renderer: Make sure printf respects target buffer size
When `printf` was involved in any kind of target buffer rendering, it
could overflow the buffer.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-09 13:00:14 +02:00
Christophe de Dinechin
927cb623d2 simulator: Convert simulator code to support color
Use the blitter code to manage the LCD buffer instead of ad-hoc
bit-manipulation.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:16 +02:00
Christophe de Dinechin
1092619edd graphics: Fix bug drawing a line of width 0
When the line width is set to 0, we were incorrectly taking
`(width-1)/2` for the negative offset, resulting in a huge box being
drawn instead of a thin line.

Arguably, a line width of 0 should maybe not be drawn at all?
But this makes it more likely that someone will run the test, see a
blank screen and think this is buggy.

Fixes: #880

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:16 +02:00
Christophe de Dinechin
00a4a25869 files: Convert all file names to lowercase
For case-sensitive filesystems like on Linux, avoid file errors
when the case does not match.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:16 +02:00
Christophe de Dinechin
d794d986c4 locals: Document the absence of compiled local variables
Compiled local variables is a rather obscure feature with a weird
syntax. It is documented on page 1-10 of the HP50G advanced reference
manual as follows:

  Global variables use up memory, and local variables can’t be used
  outside of the program they were created in. Compiled local
  variables bridge the gap between these two variable types. To
  programs, compiled local variables look like global variables, but
  to the calculator they act like local variables. This means you can
  create a compiled local variable in a local variable structure, use
  it in any other program that is called within that structure, and
  when the program finishes, the variable is gone.

  Compiled local variables have a special naming convention: they must
  begin with a `←`. For example,

    « → ←y 'IFTE(←y<0,BELOW,ABOVE)' »

  The variable `←y` is a compiled local variable that can be used in
  the two programs `BELOW` and `ABOVE`.

There does not seem to be any mention of the feature in the HP48 user
manual.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:16 +02:00
Christophe de Dinechin
bdd8e53987 demo: Modernize the code a little
We can now take advantage of:
* The `Gray` command to set patterns
* Redrawing text with a different foreground color

Also change the lines demo to have a progressive fade-out

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
ea326ae38f demo: Modify performance benchmarks to use TEval
Use `TEval` to benchmark the code, remove the benchmark helper.
Also rename the two sum benchmarks to add clarity in the name

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
552740e53b demo: Add HP-48 style slow walk to Walk demo
Make the program mimic the HP48 program behavior

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
8c9858b84e demo: Replace imaginary unit constant
The `ImaginaryUnit` and `Pi` commands no longer exist.
Replace them with the constants from the constant library.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
d8633f6695 constants: Report parse error location for invalid constants
If a constant is invalid, make sure we show the source location.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
3e59f5febe graphics: ToGrob command
Also reorganize the graphics menu to add a few missing commands.

Fixes: #876

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
08aa0ab5a2 graphics: Use foreground color for parenthese and ratio
Parentheses and ratio were rendered in black irrespective of the
foreground pattern.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
6218993e11 variables: Store and recall BMP files
Store files and objects as BMP files.
Recall BMP files as graphical objects.

Also adjust `Show` to not add a border to input graphical objects.

Fixes: #867

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
198fb94c15 memory: Implement the Clone (NewOb) function
The `Clone` command creates a clone of the object on top of stack.
This is useful for example to be able to garbage-collect an object
that the subobject was extracted from.

The hardest part was to actually come up with a test that reliably
shows the memory being saved.

Fixes: #871

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
26042c9487 variables: Implement Increment and Decrement
`Increment` increments a variable and returns its value.
`Decrement` decrements a variable and returns its value.

Fixes: #872

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
e33a9accff tests: Change the height of ignored header
We need to ignore a few additional rows of pixels at the top,
otherwise the test images depend on the month name, e.g. "April",
which has a descender for "p", modifies pixesl at the top.

Fixes: #873

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
f001a3e11c variables: Add Sto+, Rcl+ and other variable arithmetic
Implement `Sto+`, `Sto-`, `Sto*` and `Sto/` like on the HP48.
Implmeent `Rcl+`, `Rcl-`, `Rcl*` and `Rcl/` like on the HP42
(even if for RPL, there is not much to gain compared to separate
operation)

Fixes: #866

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:15 +02:00
Christophe de Dinechin
595a8f247f ui: Improve Show for large equations
For equations, it's often the case that they render horizontally.
Have `Show` automatically switch between horizontal and vertical mode.

The `MaxW` value has been increased to 1280 to match this new
behaviour, and the `MaxH` value has been decreased to 1280 because a
1280x1280 bitmap is already about 204K, so it is unlikely to work well
in the DM32 memory constraints.

Fixes: #869

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
439abfd9cf editor: Implement configurable word wrapping
Add a word wrapping in the editor at a position defined by
`EditorWrapColumn`. This makes editing of moderately large programs
more practical.

Fixes: #870

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
09aec8597d program: Add vertical program rendering mode
The vertical rendering mode renders one RPL instruction per line while
editing. This makes the program look a bit more like RPN programs.

Fixes: #868

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
33ff5befbb logical: Add SetBit, ClearBit and FlipBit commands
The `SetBit` command sets a bit in the value,
e.g. `2 4 SETBIT` is `18`

The `ClearBit` command clears a bit in the value,
e.g. `16#2A 3 CLEARBIT` is `16#22`.

the `FlipBit` command flips a bit in the value,
e.g. `3 18 FLIPBIT` is `262147`.

Fixes: #850

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
b8d1f2c429 graphics: Add pixon, pixoff and pix? commands
Also add a `PixColor` command that returns the RGB values for the pixel.

Fixes: #849

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
013304b1cf command: Factor out arity for all commands
For all commands, put the arity check in the top-level evaluator.
This factors out all that code in a single (source-code) location.

This also makes it possible to use arity reliably during parsing of
expressions, and fixes a number of cases where it wqas set wrong, like
for the `det` command and many others.

Finally, it fixes missing calls to `rt.args` for a number of commands,
while explicitly removing it (`nargs < 0`) for a few cases where it
was harful, like `LastArgs` or `Undo`.

Fixes: #865

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 21:28:14 +02:00
Christophe de Dinechin
d1e6f008cb readme: Remove reference to DM42 from top-level readme
The project now supports the DM32 just as well as the DM42, so it's better to
not have the DM42 so prominently in the title.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:53:00 +02:00
Christophe de Dinechin
5b3d1b9ce6 expressions: Ensure funcall objects are evaluated immediately
They are part of an outer expression, and must be evaluated right
away.

Fixes: #863

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:53:00 +02:00
Christophe de Dinechin
cf073e4a5a expressions: Parse user-function calls
In an expression, parse `Foo(1;2;3;4)` as a function call invoking
`Foo` with arguments `1 2 3 4`.

Fixes: #863

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:53:00 +02:00
Christophe de Dinechin
221795f308 ids: Make room for a few additional 1-byte commands
Move `nand`, `nor`, `implies`, `equiv` and `excludes` to the two-bytes
section of identifiers.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:52:59 +02:00
Christophe de Dinechin
4bad5f26b2 functions: Make it possible to interrupt a running sum/product
Add calls to `program::interrupted()` to make sure we can interrupt a
running sum or product function.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:52:59 +02:00
Christophe de Dinechin
c8289e8cff parsing: Make the error message for sub-expressions more local
Instead of only emitting the `Unterminated` error message for the
outermost expression, emit it for the innermost unterminated
expression, which gives a much better sub-range for the editor.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:52:59 +02:00
Christophe de Dinechin
0deab9cd99 parsing: Parse n-ary functions
Parse the `sum` and `product` functions, which take 4 arguments.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-04-08 14:52:59 +02:00
Christophe de Dinechin
0df86b131f simulator: Avoid crash rendering %t in recorder
If we print a really large value, we need to cut off what we print.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
2fad76ce6c graph: Sum and product graphical rendering
Render sum and product grpahically on the stack.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
55b7d4152e functions: Add sum and product functions
Add "real" n-ary functions for `sum` and `product`.

Note that the HP50G does symbolic pre-computation for sums, with the
interesting side effect that it may give "strange" results for empty
sums. For example, `I 10 1 'I^3' Σ` gives `-2024`, which is a bit
suprising.

The rationale, I believe, is that `I A B 'I^3' Σ` is first simplified
as `'(B^2+2*B^3+B^4-A^2+2*A^3-A^4)/4'`, which gives the negative
result when `A>B`.

This behaviour is not replicated in DB48X, which follows the HP48
model, where a sum between 10 and 1 returns 0, not a negative value.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
fb6c7b69e2 graph: Graphical rendering of combinations and permutations
Render `comb` and `perm` using the traditional mathematical notation.

Note that this is different from the way the HP48 and HP50G do it:

- The HP48 gives an `Undefined name` error for `N M COMB`

- The HP50 expands this to a factorial-based expression.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
838938336e menus: Place ListMenu as a keyboard-accesisble menu
Remove the `DataMenu`.

Replace `PrintMenu` with `ListMenu` as keyboard-accessible menu
(we can tuck the rarely used `PrintMenu` under `I/O`)

Add list product, sum, etc to `ListMenu`

Modify `ProgramMenu` to add special program entry characters.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
765a97c6e7 lists: Separate list sum/product from regular sum/product
For some reason, I used the `Sum` (`Σ`) and `Product` (`∏`) commands
for list sums and products. This is not the way the HP48/HP50 do it,
so it's better to have dedicated `ΣList` and `∏List` commands.

Also implemented the missing `∆List` command and added the missing
related tests for all these commands.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
5362dd634c graph: Improve rendering of exp, exp2, exp10
Use a smaller font for the argument of these functions.

Also add tests for `sqrt`, `cbrt` and `xroot`

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-28 23:51:08 +01:00
Christophe de Dinechin
fbae01c5f8 graph: Add graphical rendering for cbrt (cube root)
Make it look like the regular root.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-27 17:48:48 +01:00
Christophe de Dinechin
67871dd95f graph: Graphical rendering of xroot
Render xroot graphically in expressions.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-27 17:48:48 +01:00
Christophe de Dinechin
4db8bd0b2e expressions: Add code for n-ary functions
Add code that deals with n-ary expressions, such as `comb`, `perm` or
`xroot`.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-26 23:23:44 +01:00
Christophe de Dinechin
a2ce949b23 functions: Add combinations and permutations
Add combination and permutation functions, as well as tests for
probabilities.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-03-26 20:22:01 +01:00
Christophe de Dinechin
c4db7c3a44
Merge pull request #856 from kjellc/fix-simulator-missing-fast-mouse-clicks
Fixed problem in simulator missing quick mouse clicks
2024-03-25 19:03:28 +01:00
Christophe de Dinechin
22b2546336
Merge pull request #858 from vkadlcik/stable
Add a missing build dependency on Fedora
2024-03-25 19:00:26 +01:00