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: #1049Fixes: #1056
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
Add menu labels and entries for `SolverImprecision` and
`SolverIterations` settings.
Fixes: #1058
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Commands like `if then else` should not evaluate from the menu, but
always insert in the text editor.
Fixes: #1014Fixes: #1015
Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
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>
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>
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>
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>
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>