Commit graph

2134 commits

Author SHA1 Message Date
Christophe de Dinechin
c736e6a388 doc: Record performance data about unit conversion
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 14:14:04 +02:00
Christophe de Dinechin
650000a42d solver: Process units when not given in equation
Deal with units correctly in the solver when they are not supplied in
the equation itself. For example, for equation `'A^2+B^2=C^2'`,
process units correctly if `A=10_m`, `B=85_ft` and `C=1_cm`.

When solving for `C` in the above case, this gives a result in `cm`.

Fixes: #1049
Fixes: #1056

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 00:50:37 +02:00
Christophe de Dinechin
c5151f8ce8 menu: Add menu entries for solver imprecision and iterations
Add menu labels and entries for `SolverImprecision` and
`SolverIterations` settings.

Fixes: #1058

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-28 00:47:39 +02:00
Christophe de Dinechin
6b24aa4be6 units: Do not simplify while in unit mode
In order to accelerate conversions, do not run expression
simplifications while in unit mode. There is a dedicated factoring
step for units, so simplifications do not help much.

Fixes: #1055

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 17:34:02 +02:00
Christophe de Dinechin
d64fdb3452 config: Use config files only for user configuration
Switch to using the built-in data files by default, and extending them
with teh configuration file.

The `ShowBuiltinConstants`, `ShowBuiltinCharacters` and
`ShowBuiltinUnits` are not on by default. The size of the
corresponding `config/*.csv` files are reduced to a really simple
example.

Fixes: #1052

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 17:34:02 +02:00
Christophe de Dinechin
1ca1be761f characters: Display correct content for built-in menus
When the `ShowBuiltinCharacters` setting is active, the index of the
built-in menus was off by one.

That's because if we find a match, we exit the loop without
incrementing the `menu` variable, so we find a match for the builtin
that follows as well.

A similar problem exists for constants.

Fixes: #1054

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 14:50:57 +02:00
Christophe de Dinechin
384684cb83 build: Shorten the size of the version abbrev
We exceed the 16-byte limit with the existing format for
`0.7.11-12-42421Z`, which leads to a crash checking the QSPI.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:45 +02:00
Christophe de Dinechin
e060838398 lists: Add a setting to evaluate list as programs
When the `ListAsProgram` flag is set, lists evaluate as programs,
like on the HP48. The opposite (default) setting is `ListAsData`,
which keeps lists as data like on the HP28.

Fixes: #1051

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
2263a012d9 ui: Add settings to hide/show empty menus and clear menu on EXIT
By default, `EXIT` clears the current menu when not editing.
The `ExitDoesNotClearMenu` setting blocks this behaviour.

By default, empty menus are not shown, leaving more room for the
stack. The `ShowEmtyMenus` ensures that empty menus entries are shown
on the screen.

Fixes: #1046

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Suggested-by: spiff72 <mgobluevictor@gmail.com>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
e51a76a3ec rewrites: Avoid contradictory rules when reordering constants
There were contradictory rules trying to put constants last and trying
to regroup additions during simplification.

To avoid the problem, add a new class of patterns for letters `def`
which only matches non-real values, and use it so that the reordering
pattern does not match for constants.

Fixes: #1047

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
6ff3e844bb documentation: Add documentation for the equation library
Add some placeholder documentation for the equation library.

Fixes: #1048

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
9a646e09a3 tests: Increase wait time for tests with blinking cursor
When the cursor is showing, we need to wait longer for it to blink to
the "good" state of the image.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
b00a1c3154 help: Record position for history even without a \n
The `shown` variable should be set even without a `\n`, so that
history records position correctly.

Fixes: #1044

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 10:11:44 +02:00
Christophe de Dinechin
ee95439090 constants: Update some outdated values
Some constant values from the HP50G advanced reference manual do not match the
latest data from CODATA.

Fixes: #1045

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 02:01:47 +02:00
Christophe de Dinechin
dba8aad3fa blitter: Adjust the right margin
The right margin only needs to be rounded to the nearest byte.

Using the scanline is wrong for the hardware screens, where the value
is artificially inflated (416 for 400 actual pixels) because DMCP uses
the extra two bytes for its own internal processing. Swapping
coordinates with 416 instead of 400 ends up messing up that data.

Fixes: #1053

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-27 02:01:43 +02:00
Christophe de Dinechin
4fe509691c blitter: Base horizontal adjust on scanline, not width
When we draw a BMP that has a width that is not a multiple of 8, some
black pixels show up on the right, and the left part is truncated.

The root cause is that the horizontal adjustment uses the width and
not the scanline, so we don't get the correct range of pixels.

Code inspection also showed that there was an error in the size of the
datalen being returned from `grob::pixels`, because it returnes the
size of the object, not the size of the data bitmap.

Fixes: #1043

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-24 14:33:54 +02:00
Christophe de Dinechin
928210d80e help: Add documentation for the various constants
Add some basic documentation for many of the basic constants

Fixes: #1039

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-24 14:33:54 +02:00
Christophe de Dinechin
a05288f272 help: Avoid slowing down when scrolling through pages of help
When we read a lot of help, we tend to scroll down a lot of text, and
occasionally back up a little. Allow for two screenfulls worth of
backing up.

Record the vertical offset as pixels to avoid the skips we had by
counting text lines.

Fixes: #1038

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 22:53:43 +02:00
Christophe de Dinechin
0aa93d8e21 help: Do not exit help when opening URLs or missing topics
When we open a missing topic, we should not exit the help.
Additionally, when the topic is not found because it's an URL, we
should not present this as an error.

Fixes: #1037

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 22:53:43 +02:00
Christophe de Dinechin
1c1f0b8235 help: Do not try to load PNG images
While reading the documentation, we should only load BMP files.
Only test for lowercase `bmp` extension, in case we want to be able to
easily skip particular BMP images (e.g. because they are too big).

Fixes: #1036

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 22:20:30 +02:00
Christophe de Dinechin
c18a9975aa Release 0.7.11 "Rest" - Refine interactive stack, graphics in help
This release is a refinement minor release. The primary focus is the interactive
stack, which now lets you edit items, sort either according to memory
representation or by value, display information about objects, and jump directly
to a given stack level using digits.

The simple random number generator implemented in 0.7.10 was replaced with an
additive congruential random number generator (ACORN), which can be configured
in number of bits and number of iterations. A side effect is that there is now
regression testing for single-variable statistics.

The history feature was also improved by automatically enabling the `EditMenu`
when selecting history, and then having the (unshifted) word left and word right
commands automatically cycle through history if used at beginning or end of the
editing buffer.

**Features**

* help: Add ability to display BMP images in help files
* images: Convert help images to BMP
* ui: Add `Edit` feature to interactive stack
* ui: Add history menu entries to `EditMenu`
* ui: Accept `UNDO` while in interactive stack mode
* ui: Have word previous/next cycle through history
* ui: Accept digits to select stack level in interactive stack
* random: ACORN random number generator

**Bug fixes**

* editor: Fix spacing after number followed by `-` sign
* ui: Do not set the `editing` field from interactive stack
* ui: Replace interactive stack "Edit" with "Echo"
* ui: Block user input while using interactive stack
* ui: Do not draw menu markers when displaying interactive stack
* runtime: Avoid crash running above allocated memory in `move_globals`

**Enhancements**

* ui: Reorganize code handling interactive stack keys
* help: Adjust help area to new height for menus

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 02:27:41 +02:00
Christophe de Dinechin
6d5af00a8c help: Add ability to display BMP images in help files
Add code to load BMP images from disk and show them in help files.

Fixes: #1033

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 01:57:32 +02:00
Christophe de Dinechin
28dac54c64 images: Convert help images to BMP
Convert the image files to BMP so that we can display them on the
target calculators.

This will be needed for #1033 (displaying BMP files in help file).

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-22 01:19:41 +02:00
Christophe de Dinechin
9b1ba38d31 editor: Fix spacing after number followed by - sign\
When we insert something like `'1000-1'`, we should not count the `-`
character as being part of the first number, otherwise spacing is all
messed up.

Fixes: #1032

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-21 01:41:01 +02:00
Christophe de Dinechin
c9c770b981 ui: Add Edit feature to interactive stack
Add the `Edit` feature to the interactive stack.
When editing an object and replacing it with multiple objects, the
objects are inserted at the interactive stack location.

Add the `Info` button to show information about the stack level.

Separate the `Sort` feature into `MemSort` (sort by memory
representation) and `ValSort` (sort by value).

Add the `EchoNSp` to echo without spaces the way the HP48 does.

Fixes: #1031

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 23:57:42 +02:00
Christophe de Dinechin
d5c88faa4f ui: Have word previous/next cycle through history
In order to make it easier and faster to cycle through editor history,
change the `←Word` and `Word→` entries of the `EditMenu` so that they
select the previous or next history entry if used at beginning or end
of the editor buffer.

Fixes: #1028

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 04:28:29 +02:00
Christophe de Dinechin
4febac76d7 ui: Add history menu entries to EditMenu
Add commands to the `EditMenu` to go both up and down in the history,
and to enter the interactive stack.

Switch to the `EditMenu` automatically when we use the history command.

Fixes: #1028

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 04:28:29 +02:00
Christophe de Dinechin
912487ac0f ui: Accept UNDO while in interactive stack mode
When editing the stack using the interactive stack feature, accept the
`UNDO` key to restore the state before starting interactive stack mode.

Fixes: #1030

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 02:58:21 +02:00
Christophe de Dinechin
841047befe ui: Accept digits to select stack level in interactive stack
When entering digits in interactive stack mode, jump to the
corresponding level. If the stack is big enough, you can use sequences
of digits, e.g. type `1` `2` then `3` to go to level 123. If you type
`0` and the number becomes big, then it goes to the highest level of
the stack.

Fixes: #1029

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 02:48:51 +02:00
Christophe de Dinechin
22a7ac8bb2 ui: Reorganize code handling interactive stack keys
The code has often pieces shared between shifted states.
Take advantage of that to factor out common code.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 02:38:05 +02:00
Christophe de Dinechin
0a775a2d0a ui: Do not set the editing field from interactive stack
The `editing` field is used during editing of the top of stack,
because the object being edited has been _removed_ from the stack.
When we use the `Echo` feature of the interactive stack, the object is
not removed, so the `editing` field should not be set.

Fixes: #1021

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 02:36:35 +02:00
Christophe de Dinechin
3c1dd5afd2 ui: Replace interactive stack "Edit" with "Echo"
This is more consistent with the HP user interfaces.

Fixes: #1027

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 02:36:35 +02:00
Christophe de Dinechin
9a0655a63c ui: Block user input while using interactive stack
While using the interactive stack, we don't want a key like `sin` to
activate the corresponding function. We also don't need to activate
built-in help.

Fixes: #1022

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 01:17:40 +02:00
Christophe de Dinechin
7234b918c5 help: Adjust help area to new height for menus
The menus are now 3 pixels higher than before.
Adjust the help display area to match.

Fixes: #1026

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-20 00:55:27 +02:00
Christophe de Dinechin
4876991a33 ui: Do not draw menu markers when displaying interactive stack
The interactive stack has a special menu, and like the help menu, it
should not show the menu markers.

Fixes: #1024

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-19 23:08:25 +02:00
Christophe de Dinechin
3695a716cb runtime: Avoid crash running above allocated memory in move_globals
The `runtime::move_globals` function must not try to move data above
the RPL allocated space, otherwise it may end up accessing memory
outside of what was allocated by the simulator, or outside of physical
memory on the calculator.

Fixes: #1025

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-19 22:08:35 +02:00
Christophe de Dinechin
196f2ee754 random: ACORN random number generator
Implement an additive congruential random number generator (ACORN),
which is a very simple implementation that can be configured to have
an arbitrary number of random bits.

https://en.wikipedia.org/wiki/ACORN_(random_number_generator)

Fixes: #1019

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-19 22:08:35 +02:00
Christophe de Dinechin
c2235e6045 Release 0.7.10 "Hospitality" - Interactive stack
This release primarily adds the "interactive stack" feature of HP calculators.

**Features**

* stack: Interactive stack and associated menu
* functions: Very basic random number generator
* demo: Add `CountPrimes` and `RandomPlot` examples

**Bug fixes**

* menus: Do not execute if-then-else and similar
* expressions: Avoid error testing for zero/one in power operator
* condidionals: Avoid infinite loop evaluating condition
* menu: Insert `iferr-then-else` correctly from menu
* constants: Skip menu entries

**Improvements**

* menus: Reorganize stack menu to put `Dup` and `Drop` on first page
* menu: Add error functions to `Debug` menu

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-15 01:09:57 +02:00
Christophe de Dinechin
edb3cf1e9f functions: Very basic random number generator
A very basic set of random-generation functions.

This implementation only generates 32-bit worth of randomness.
A later iteration will follow the `Precision` setting for decimals.

Fixes: #1019

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-15 00:57:53 +02:00
Christophe de Dinechin
e32f001ea2 tests: Add tests for interactive stack
The tests for the interactive stack involved a change in the code to
show an object, in order to process test commands correctly and to not
overwrite the screen content with the stack.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-13 00:28:19 +02:00
Christophe de Dinechin
45ef03c4e2 stack: Interactive stack menu
Add menu functions for the interactive stack.

Compared to the HP implementation, the interactive stack that was
implemented here adds stack sort and revert features.

Fixes: #1011

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-12 02:13:27 +02:00
Christophe de Dinechin
85d8599ccc stack: Interactive stack
Draw the interactive stack when using the 'up' arrow.

Fixes: #1011

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-11 23:35:15 +02:00
Christophe de Dinechin
3473ca0284 demo: Add CountPrimes example
The `CountPrimes` example is a simple program that is inspired by a
[speed test YouTube video](https://www.youtube.com/watch?v=vwI5xbqIM7g).

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-11 19:36:14 +02:00
Christophe de Dinechin
2c2cc46d74 menu: Reorganize stack menu to put Dup and Drop on first page
There are keyboard shortcuts for immediate mode (Enter for `Dup` and
Backspace for `Drop`), but they are not available while programming.

Add `Dup` and `Drop` to the first page, move less often features to
the second page.

Fixes: #1018

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-11 19:34:07 +02:00
Christophe de Dinechin
d2cccb096c menus: Do not execute if-then-else and similar
Commands like `if then else` should not evaluate from the menu, but
always insert in the text editor.

Fixes: #1014
Fixes: #1015

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-11 00:27:38 +02:00
Christophe de Dinechin
189694f6e5 expressions: Avoid error testing for zero/one in power operator
The power operator was calling `is_zero` and `is_one` with type
checking enabled. This would cause a failure for an expression such as
`e^(i*pi)` where the terms are constants.

Fixes: #1007

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-10 23:09:21 +02:00
Christophe de Dinechin
488e192f82 condidionals: Avoid infinite loop evaluating condition
When the condition was a program or expression, the `conditional`
opcode was deferred while the program was evaluated.

That could lead to a situation where an expression would evaluate as
itself, and we would never finish the evaluation of the expression. An
example was evaluating `'FAIL'` that would evaluate as `'FAIL'` and
never make forward progress.

The implemented solution adds a `need_conditional` opcode that is
deferred to evaluate just before the next evaluation of the original
conditional, and demands that the conditional after evaluation be a
truth value. If after evaluating `'FAIL'` we get `'FAIL'`, this ends
up with a `Bad argument type` error message.

Fixes: #1016

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-10 22:41:22 +02:00
Christophe de Dinechin
2c3e2df0fd menu: Insert iferr-then-else correctly from menu
In order to correctly insert the `iferr` statements, we need them to
be put outside of the range of immediates.

The rendering was also broken because `IfErrThenElse` is a two byte
opcode and the rendering code was using `payload(o)` (which optimizes
for the 1-byte opcodes) instead of `o->payload()` (which works for all
opcode sizes).

Added some tests, that triggered #1015 and #1016, to be dealt with.

Fixes: #1014

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-10 01:12:08 +02:00
Christophe de Dinechin
f43baebf15 menu: Add error functions to Debug menu
The various error functions were not present in any menu.
Add them to the `Debug` menu.

Fixes: #1013

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-09 22:23:36 +02:00
Christophe de Dinechin
3157b6739d constants: Skip menu entries
The menu entries do not have a definition.
This causes a crash on simulator when there is no config file,
and some kind of weird error on the real machine.

Fixes: #1006

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
2024-07-09 21:46:16 +02:00