UP | HOME

free42 Custom Menus

Author: Mitch Richling
Updated: 2024-02-12 12:55:47

Copyright 2024 Mitch Richling. All rights reserved.

Table of Contents

1. Metadata

The home for this HTML file is: https://richmit.github.io/hp42/custom.html

A PDF version of this file may be found here: https://richmit.github.io/hp42/custom.pdf

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

The custom menu on the 42s is a wonderful thing, but it is also very limited. It's just too small!! And it is only one level deep!! So instead of simply assigning functions to the menu keys, how about assigning programs to the keys which present a hierarchical menu of functions? Coding up such programs is tedious. So this org-mode document has a Little bit of Emacs lisp that will consume a table, and generate a 42s program implementing a hierarchical menu.

The flow to create your custom CUST program:

  • Evaluate the "Generic menu generator" babel block in the hp42s-meta.org file. This will define the function MJR-generate-42-menu-code
  • Evaluate the "For CUSTOM-type Menus" babel block in the hp42s-meta.org file. This will define the function MJR-custom-x-gen
  • Define your menu in the Menu Contents section.
  • Evaluate the babel block in the Menu Code section below.
  • Load the program on your calculator

2.1. Customizing Custom Menu Table

The first column (which I labeled Menu) describes the menu keys. Colons are used to define a menu hierarchy. For example "top:mid:thingy" means we have a top level menu "top" containing a menu "mid" containing a function/program "thingy". Another entry like "top:thingy2" would add a function/program key "thingy2"to the "top" menu – yes menus can contain a mix of functions/programs and menus.

The only limitation on menu hierarchy depth or size comes from the use of two digit local labels in the generated code. A label is consume for each function/program and for each menu page.

The second column is the function/program name/label to call. If this is empty, then the menu name will be used. For example "SFUN:HYP:SINH" will call the SINH function if no Program is specified.

The other columns of the table are not used.

3. Custom Menus

3.2. Menu Code

The menu program is generated via the following bit of elisp. You must first define the MJR-generate-42-menu-code and MJR-custom-x-gen by evaluating the code blocks in the hp42s-meta.org file.

(MJR-generate-42-menu-code "CUST" 0 tbl 0 1 'stay 'up 'auto #'MJR-custom-gen-lab #'MJR-custom-gen-sub)

4. Create system CUSTOM Menu

Sometimes our carefully built in CUSTOM menu is lost – an errant program or system memory clear. What to do? How about a program that will recreate your CUSTOM menu when you need it? In the table below we have the definition of our custom menu, and a bit of lisp that will write a 42s program to ASSIGN each key.

KEY# ASSIGNment Only On
1 CUST  
2    
3    
4    
5 EEPFX  
6 ¦¦  
7 VirtV DM42
8    
9    
10    
11    
12    
13 SST  
14 SST↑  
15 SST→  
16 GTO  
17 XEQ  
18 VIEW DM42
18 PRV !DM42

Simply evaluate the followign lisp block, and the 42s program will be created.

;; The generated code uses the existance of GrMod to guess if we are on a DM42
(princ (message "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ (ref:%s)\n" "MKCM"))
(princ "@@@@ DSC: Autogenerated menu program\n")
(princ "LBL \"MKCM\"\n")
(princ "CLKEYS\n")
(cl-loop for (da-key da-assignment da-pform) in tbl
         for da-assignment-fixed = (replace-regexp-in-string "¦" "|" da-assignment 't 't)
         for have-key = (not (zerop (length da-assignment-fixed)))
         when (and have-key (string-equal da-pform "DM42"))
         do (princ "SF 25\nRCL \"GrMod\"\nFS?C 25\n")
         when (and have-key (string-equal da-pform "!DM42"))
         do (princ "SF 25\nRCL \"GrMod\"\nFC?C 25\n")
         when have-key
         do (princ (message "ASSIGN \"%s\" TO %02d\n" da-assignment-fixed da-key))))
(princ "RTN\n")

5. SPREF: Set some of my personal prefrences

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ (SPREF)
@@@@ DSC: Set some of my personal prefrences
@@@@ IN:  N/A
@@@@ OUT: N/A
@@@@ TST: free42_3.0.2
@@@@ BUG: This sets some of *my* favorite prefrences.  You might not like them. ;)
@@@@ UPD: 2021-04-05
LBL "SPREF"
FUNC 00
ALL     @@@@ Display all digits
RECT    @@@@ Complex number format
RAD     @@@@ Angle mode
CPXRES  @@@@ Complex results
RDX.    @@@@ Use periods
KEYASN  @@@@ Custom menu
DECM    @@@@ Make sure we are in decimal mode
64      @@@@ WSIZE
FS? 78
BSIGNED @@@@ Unsigned integer mode
FS? 79
BWRAP   @@@@ Don't wrap integers
DMY     @@@@ D.MY mode
CLK12   @@@@ AM/PM mode
4STK    @@@@ Four level stack
EXITALL @@@@ Exit menus
RTN

6. END

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
END

7. EOF