| 1 |
------------------------------------------------------------------------------- |
| 2 |
Free42 is a software clone of the Hewlett-Packard 42S calculator. If you know |
| 3 |
how to use an HP-42S, you know how to use Free42. |
| 4 |
If you're new to the HP-42S and its clones, you may want to take a peek at the |
| 5 |
manual. You can find documentation at https://thomasokken.com/free42/#doc |
| 6 |
|
| 7 |
The remainder of this README file covers some miscellaneous tidbits that I had |
| 8 |
no other decent place to put. |
| 9 |
|
| 10 |
|
| 11 |
------------------------------------------------------------------------------- |
| 12 |
Binary vs. Decimal |
| 13 |
Free42 can be built with binary or with decimal floating point. The Windows, |
| 14 |
MacOS, iOS, and Android projects all contain separate targets for Decimal and |
| 15 |
Binary builds; for the Linux version, the selection is made using the BCD_MATH |
| 16 |
environment variable. |
| 17 |
When switching between building the decimal and binary version for Linux, be |
| 18 |
sure to do "make clean", to avoid linking the wrong objects. |
| 19 |
|
| 20 |
|
| 21 |
------------------------------------------------------------------------------- |
| 22 |
Building on Raspbian 10 |
| 23 |
|
| 24 |
# apt install libgtk-3-dev |
| 25 |
# apt install libasound2-dev |
| 26 |
$ git clone https://codeberg.org/thomasokken/free42.git |
| 27 |
$ cd free42/gtk |
| 28 |
$ make BCD_MATH=1 AUDIO_ALSA=1 |
| 29 |
|
| 30 |
|
| 31 |
------------------------------------------------------------------------------- |
| 32 |
Creating Free42 build environment in FreeBSD |
| 33 |
|
| 34 |
Create VirtualBox VM (using VirtualBox 5.2.22) |
| 35 |
Install FreeBSD-12.0-RELEASE-amd64-dvd1.iso |
| 36 |
|
| 37 |
then: |
| 38 |
|
| 39 |
pkg install gnome3 |
| 40 |
pkg install xorg |
| 41 |
pkg install virtualbox-ose-additions |
| 42 |
|
| 43 |
in /etc/fstab, added: |
| 44 |
proc /proc procfs rw 0 0 |
| 45 |
|
| 46 |
in /etc/rc.conf, added: |
| 47 |
vboxguest_enable="YES" |
| 48 |
vboxservice_enable="YES" |
| 49 |
dbus_enable="YES" |
| 50 |
hald_enable="YES" |
| 51 |
gdm_enable="YES" |
| 52 |
gnome_enable="YES" |
| 53 |
|
| 54 |
That brings up the desktop. |
| 55 |
Now, some more stuff: |
| 56 |
|
| 57 |
pkg install devel/pkgconf |
| 58 |
pkg install devel/gmake |
| 59 |
|
| 60 |
|
| 61 |
------------------------------------------------------------------------------- |
| 62 |
Creating Free42 build environment in Solaris |
| 63 |
|
| 64 |
Create VirtualBox VM (using VirtualBox 7.0.24) |
| 65 |
Install Solaris 11.4 using sol-11_4-vbox.ova from Oracle, and configure it |
| 66 |
per the instructions at |
| 67 |
https://www.oracle.com/it-infrastructure/technologies/handsonlab-solaris11-on-vm-virtualbox.html |
| 68 |
|
| 69 |
then: |
| 70 |
|
| 71 |
# pkgadd -d http://get.opencsw.org/now |
| 72 |
# /opt/csw/bin/pkgutil -U |
| 73 |
# /opt/csw/bin/pkgutil -y -i git |
| 74 |
# /opt/csw/bin/pkgutil -y -i pkgconfig |
| 75 |
# pkg install gcc |
| 76 |
|
| 77 |
Add this to your .profile: |
| 78 |
|
| 79 |
export PATH=$PATH:/opt/csw/bin |
| 80 |
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/amd64/pkgconfig:/usr/share/pkgconfig |
| 81 |
|
| 82 |
|
| 83 |
------------------------------------------------------------------------------- |
| 84 |
Adding types: |
| 85 |
|
| 86 |
When adding a type 'foo', you need to define an appropriate vartype_foo struct, |
| 87 |
create a new_foo() function (constructor), and add support for the new type in |
| 88 |
* dup_vartype() |
| 89 |
* free_vartype() |
| 90 |
* vartype2string() |
| 91 |
* persist_vartype() |
| 92 |
* unpersist_vartype() |
| 93 |
* vartype_equals() |
| 94 |
* core_copy() and core_paste() |
| 95 |
(Note that even if you choose not to support copying and pasting objects of |
| 96 |
the new type by themselves, you should always support copying and pasting |
| 97 |
them as part of a list, by adding the appropriate code in serialize_list() |
| 98 |
and deserialize_list().) |
| 99 |
|
| 100 |
|
| 101 |
------------------------------------------------------------------------------- |
| 102 |
clang optimizer weirdness |
| 103 |
|
| 104 |
In recent versions of clang (not sure starting when; I noticed it in early |
| 105 |
April 2023), the compiler pursues an aggressive optimization strategy that can |
| 106 |
cause it to emit provably incorrect code. Specifically: |
| 107 |
|
| 108 |
In tb_print_current_program() (core_display.cc), the 'if (line > 0) { ... }' |
| 109 |
block is executed even the first time through the loop, when line is still 0. |
| 110 |
Why? Apple tech support explained it like this: when line == 0, the local |
| 111 |
variable orig_num is uninitialized when it is passed to prgmline2buf(). The |
| 112 |
compiler considers this an error, but instead of emitting an error or a |
| 113 |
warning, it jumps to the conclusion that line > 0 must always be true, since |
| 114 |
that is the only way orig_num would always be initialized. |
| 115 |
|
| 116 |
I find this explanation completely idiotic. You're taking code that is legal C, |
| 117 |
and because of a point of arguably poor coding style, you generate clearly |
| 118 |
incorrect code, by executing the 'if (line > 0)' block even when line == 0. I |
| 119 |
could understand making the compiler emit a warning, or even an error, for this |
| 120 |
kind of code, although I would also expect there to be an option to disable |
| 121 |
this check, since this is legal C code. But as it is, the compiler insists on |
| 122 |
generating bad code. Rather than do the Apple-recommended fix of adding an |
| 123 |
initializer to the declaration of orig_num, and then hope that no other |
| 124 |
undiscovered problems like this exist elsewhere (remember: NO WARNING!), I |
| 125 |
chose to use a less aggressive optimization level. The option -O1 is the |
| 126 |
highest optimization level that avoids the problem, so that's what I'll stick |
| 127 |
with until the issue is resolved, either by Apple removing this moronic |
| 128 |
behavior from their compiler, or by them adding a warning so at least I'll know |
| 129 |
exactly *what* to fix. |
| 130 |
|
| 131 |
Note: the same code pattern exists in several places in core_display.cc, |
| 132 |
specifically, all places where orig_num is used. |
| 133 |
Also note: it's not even clear what is the exact condition when the compiler |
| 134 |
goes nuts like this. The 'cmd' variable is also passed without being |
| 135 |
initialized, but apparently, that is not a problem. |
| 136 |
Finally note: this appears to be specific to Apple's clang, affecting the iOS |
| 137 |
and MacOS versions. If this brain-damage should spread to other compilers, you |
| 138 |
can tell when Copy in PRGM mode skips line 01. |
| 139 |
|
| 140 |
UPDATE: I ran into another clang optimizer bug; this one causes ASSIGN "" |
| 141 |
(Shift 1 ENTER ENTER) to fail, when building with -O1. The second ENTER isn't |
| 142 |
handled correctly. I can't be bothered to find out where exactly the optimizer |
| 143 |
messes up; this is the third time I've had a buggy release thanks to Apple's |
| 144 |
clang. I've had it. I'm going with -O0 for all MacOS and iOS builds from now |
| 145 |
on. |
| 146 |
|
| 147 |
|
| 148 |
------------------------------------------------------------------------------- |
| 149 |
About the character sets: |
| 150 |
('bigchars' and 'smallchars' arrays in core_display.c) |
| 151 |
|
| 152 |
The top half of the 256 character codes are like the bottom half, |
| 153 |
with these exceptions: |
| 154 |
0x80: thin colon (':') (looks different than regular colon), |
| 155 |
while 0x00 is a calculator-style divide sign (superposition |
| 156 |
of ':' and '-') |
| 157 |
0x81: small 'Y'; 0x01: multiply sign |
| 158 |
0x8a: displays 'LF' character (small 'L' and small 'F', |
| 159 |
slightly offset, squeezed into one character cell); |
| 160 |
0x0a: actual linefeed (move to next line of display). |
| 161 |
|
| 162 |
The bigchars array contains 130 characters, in 5x8 pixel cells, |
| 163 |
corresponding to codes 0-129. Char 10 is the 'LF' ligature. |
| 164 |
|
| 165 |
Note: the 'x:' and 'y:' legends for the standard X and Y register display |
| 166 |
are built from 0x78 (lowercase x), 0x81 (small 'Y'), and 0x80 (thin ':'). |
| 167 |
Note: 0x01 (multiply) is different than 0x78 (lowercase x) (it is 1 pixel |
| 168 |
higher). |
| 169 |
|
| 170 |
|
| 171 |
------------------------------------------------------------------------------- |
| 172 |
HP-42S bugs that I found: |
| 173 |
|
| 174 |
If you activate the CUSTOM menu in KEYASN mode, go to its third row, and then |
| 175 |
switch to LCLBL mode, you get a menu row with labels "L", "M", "N", "O", "@", |
| 176 |
"XEQ"; these keys activate the commands XEQ ST Z, XEQ ST Y, XEQ ST X, XEQ ST L, |
| 177 |
XEQ 117, XEQ 118. |
| 178 |
These commands do actually work, but entering the corresponding labels into a |
| 179 |
program is a bit tricky... |
| 180 |
|
| 181 |
→POL and →REC with a real number in X reject a string in Y (good), accept a |
| 182 |
real number in Y (good), accept a complex number in Y but only use its real |
| 183 |
part (undocumented and not very useful), and accept real and complex matrices |
| 184 |
in Y with weird results. I'd say the complex and matrix cases are all bugs, |
| 185 |
resulting from a missing parameter type check. |
| 186 |
|
| 187 |
If MATA, MATB, or MATX is the indexed matrix, and SIMQ resizes it to a smaller |
| 188 |
size, IJ aren't set to (1, 1) as they usually are when the indexed matrix is |
| 189 |
resized (though DIM or SIZE). As a result, IJ can end up pointing outside the |
| 190 |
allocated elements, and RCLEL and STOEL can then produce wacky results. |
| 191 |
|
| 192 |
HP-42S bugs that others have found: |
| 193 |
|
| 194 |
When COMB or PERM are invoked with bad arguments (e.g. X > Y), "Invalid Data" |
| 195 |
is returned (good), but all subsequent invocations of those two functions also |
| 196 |
yield that message, even if the parameters are now correct (bad). This |
| 197 |
condition can be cleared up by performing an operation that affects LASTx (but |
| 198 |
not STO ST L). Apparently some rev. B models do not have this bug; I have read |
| 199 |
that the original problem was a hardware bug, for which rev. B introduced a |
| 200 |
software workaround; somewhere in the rev. B production run the hardware bug |
| 201 |
was fixed, but now the software workaround would *cause* the bug. The bug also |
| 202 |
exists in all rev. C models, apparently (it does in mine, and in Emu42 when run |
| 203 |
with a rev. C ROM!). |
| 204 |
I'm curious as to why a couple of basic, straightforward instructions like COMB |
| 205 |
and PERM would be sensitive to a hardware bug (and *only* they, apparently), |
| 206 |
but who am I to question what I've heard others report? I'm not about to spend |
| 207 |
weeks poring over ROM disassemblies to make sure... |
| 208 |
|
| 209 |
In LINΣ mode, summing a matrix is buggy. I have seen it sum only the first row, |
| 210 |
and report a bogus value back in X (8.47216900137e-489), and also seen it say |
| 211 |
Insufficient Memory when that clearly wasn't true; I have heard a report from |
| 212 |
someone else about the machine even locking up to the point where it needs a |
| 213 |
hard reset. |
| 214 |
|
| 215 |
In some versions, in LINΣ mode, Σ+ and Σ- do not update LASTx. I read about |
| 216 |
this in a manual addendum from HP; however, I cannot reproduce this, neither on |
| 217 |
my real HP-42S nor on Emu42 (both rev. C ROM). |
| 218 |
|
| 219 |
I have also heard a report that FCSTX is buggy in PWRF mode; I have not been |
| 220 |
able to confirm this yet but there appears to be more I have to read about it. |
| 221 |
Probably depends on your ROM version; I tested with rev. C but it seemed fine. |
| 222 |
|
| 223 |
Not sure if this is a bug or not: |
| 224 |
|
| 225 |
When KEYX or KEYG are used to reprogram the ▲ and ▼ keys, it would be nice if |
| 226 |
the user would be alerted to this by the ▼▲ annunciator in the display turning |
| 227 |
on. The manual does not mention this behavior, but older editions of the |
| 228 |
Programming Examples and Techniques book do (page 34, bottom). It doesn't work |
| 229 |
on the actual calculator, at least not on any that I've heard of. |
| 230 |
Free42 does turn on the ▼▲ annunciator. Although my general rule is to mimic |
| 231 |
the HP-42S as closely as possible, I felt that this was a nice feature and that |
| 232 |
it's pretty unlikely to break anything. :-) |
| 233 |
|
| 234 |
|
| 235 |
------------------------------------------------------------------------------- |
| 236 |
[MIN], [MAX], and [FIND]: undocumented HP-42S matrix functions |
| 237 |
|
| 238 |
[MIN] finds the lowest element of the current column, starting at the current |
| 239 |
row, of the indexed matrix, and returns the element to X and the row where it |
| 240 |
was found to Y; [MAX] is like [MIN] except it finds the highest element; if the |
| 241 |
minimum or maximum is not unique (it is found in more than one row), the |
| 242 |
highest matching row is returned. [MIN] and [MAX] require the indexed matrix to |
| 243 |
be a real matrix, and they do not allow string elements in the column being |
| 244 |
searched. |
| 245 |
|
| 246 |
[FIND] locates a specific value, searching the indexed matrix left to right and |
| 247 |
top to bottom. The function works as a conditional: when a program is running, |
| 248 |
the following instruction is executed if a match is found, and skipped if a |
| 249 |
match is not found; when executed interactively, the display shows "Yes" if a |
| 250 |
match is found and "No" if not. |
| 251 |
Also, if a match is found, I and J are set to point to it. |
| 252 |
The indexed matrix may be real or complex, and the search value may be real, |
| 253 |
complex, or string; real or string values are only found in real matrices, and |
| 254 |
complex values are only found in complex matrices; in other words, 5 is not |
| 255 |
considered equal to 5 + 0i -- mathematically speaking this is wrong, but on the |
| 256 |
other hand it is consistent with the behavior of the X=Y? and X≠Y? functions. |
| 257 |
|
| 258 |
|
| 259 |
------------------------------------------------------------------------------- |
| 260 |
Differences between the Free42 printer emulation and the HP-42S/82240 |
| 261 |
|
| 262 |
Free42 prints programs differently in NORM or TRACE modes: in NORM mode, the |
| 263 |
listing is right-justified, and in TRACE mode, the listing is compact (multiple |
| 264 |
commands per line). The HP42S does not do this; Free42 "inherited" this |
| 265 |
behavior from the HP-82143 printer, which the author remembers fondly. :-) |