free42 Programming Tools
Author: | Mitch Richling |
Updated: | 2024-11-21 16:49:22 |
Copyright 2024 Mitch Richling. All rights reserved.
Table of Contents
1. Metadata
The home for this HTML file is: https://richmit.github.io/hp42/hp42s-meta.html
Files related to this document may be found on github: https://github.com/richmit/hp42
Directory contents:
src |
- | The org-mode file that generated this HTML document |
src_42s |
- | Ready to convert source listings for 42s code in this document |
docs |
- | This html document and associated PDF |
bin |
- | Importable RAW program files |
2. Introduction
This org-mode document contains various tools (mostly for Emacs) that help me write programs for the 42s:
- Elisp function to generate 42s menu programs
- A tool to insert free42 utf-8 characters given a list of character numbers
- Elisp function to generate custom menus (menus of built-in functions and global labels)
- yasnippet templates to help type code
- ElISP Code to translate my code listings into code for free42 & MD42
- 42s notes
- free42 utf-8 characters with character numbers
4. Emacs Helper Stuff
The elisp file hp42s-mode.el
provides few things:
- A language mode for free42 code – mostly just provides syntax highlighting
MJR-ins42char
: Lisp function to insert characters given a list of character codesMJR-dired-org-export
: Lisp function to export to HTML and tangle all marked files in a dired bufferMJR-process-buffer-as-42s-code
: Lisp function to process all free42 code in a buffer for pasting into free42MJR-target-free42-version
: Variable used byMJR-process-buffer-as-42s-code
&MJR-copy-42s-code-in-region
to control version of free42MJR-copy-42s-code-in-region
: Lisp function that process marked region for pasting into free42 and puts the test on the kill ring – likeMJR-process-buffer-as-42s-code
but for a region.
To activate the functionality, simply load
the hp42s-mode.el
file into emacs. You can evaluate teh folloing block to do that:
(load-file "../emacs/hp42s-mode.el")
4.1. Prepare Code For Conversion
I include comments like @@##
that I use like compiler directives in C. They provide a way to remove lines of code that are incompatible or unnecessary for
the target version of free42. It's a bit of a hack, but it lets me maintain one program for diff-rent versions of free42. When I "tangle" an org-mode
buffer, the code is automatically filtered for the selected version of free42 (set via MJR-target-free42-version
).
DM42 Version | Target Free42 |
---|---|
DMCP 3.22 / DM42 v3.20 | 3.0.5 |
DMCP 3.21 / DM42 v3.18 | 3.0.2 |
DMCP-3.20 / DM42-3.17 | 2.5.20 |
DMCP-3.20 / DM42-3.16 | 2.5.20 |
DMCP 3.18 / DM42 v3.15 | 2.5.16 |
4.2. Automatically processing tangled code
By adding MJR-process-buffer-as-42s-code
to the org-babel-post-tangle-hook
, you can automatically process tangled code. You can do that by evaluating
the next block:
(add-hook 'org-babel-post-tangle-hook 'MJR-process-buffer-as-42s-code)
A handy way to tangle a file, or files in dired, is the MJR-org-export-der
in my .emacs
file.
4.3. Tangle & Load Tangled File
(defun MJR-tangle-and-load () "Tangles current file and attempts to load the tangled file. The tangled file is determiend by looking backward for a :tangle argument." (interactive) (save-excursion (org-babel-tangle) (if (re-search-backward ":tangle[[:blank:]]+\\([^[:blank:]]+.hp42s\\)$" nil t) (let ((file-name (match-string 1))) (if (or (string-equal "yes" file-name) (string-equal "no" file-name)) (message "No explicit tangle file specified") (find-file file-name))))))
4.4. yas templates
echo '' for f in ~/core/yasnippet/hp42s-mode/*; do cat $f; echo ''; done
5. free42 Notes
5.1. Character Set
0 ÷ 1 × 2 √ 3 ∫ 4 ▒ 5 Σ 6 ▸ 7 π 8 ¿ 9 ≤ 10 [LF] 11 ≥ 12 ≠ 13 ↵ 14 ↓ 15 → 16 ← 17 μ 18 £ 19 ° 20 Å 21 Ñ 22 Ä 23 ∡ 24 ᴇ 25 Æ 26 … 27 [ESC] 28 Ö 29 Ü 30 ▒ 31 • 32 [SPACE] 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ↑ 95 _ 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 ├ 128 : 129 ʏ
5.2. Date format
Flag 67 | Flag 31 | Mode |
---|---|---|
Set | N/A | Y.MD |
Clear | Clear | M.DY |
Clear | Set | D.MY |
5.3. Stats registers
Register | Contents |
---|---|
ΣREG? + 0 | Σx |
ΣREG? + 1 | Σx^2 |
ΣREG? + 2 | Σy |
ΣREG? + 3 | Σy^2 |
ΣREG? + 4 | Σxy |
ΣREG? + 5 | n |
ΣREG? + 6 | Σlnx |
ΣREG? + 7 | Σ(lnx)^2 |
ΣREG? + 8 | Σlny |
ΣREG? + 9 | Σ(lny)^2 |
ΣREG? + 10 | Σlnxlny |
ΣREG? + 11 | Σxlny |
ΣREG? + 12 | Σylnx |
6. DM 42 Notes
6.1. Display
GrMod is a read write variable.
- 0 = standard HP-42S resolution 131x16
- 2 = DM42 full resolution 200x120
- 3 = DM42 full resolution 400x240
ResX & ResY are read only variables that have the display resolution