Skip to main content

Unicode to DM41 FOCAL Converter

·

Unicode to DM41 FOCAL Converter #

Step into the retro brilliance of the HP-41CX with hp41cx_tools-unicode_to_dm41, a clever tool that converts Unicode-encoded FOCAL source code (.utf8.focal) to DM41 format (.dm41.focal). Built in Ada 2022 for rock-solid reliability, this filter masterfully handles special characters (Σ, , ) with context-sensitive conversions and double-comments XROM key assignments (e.g., ;; KEY = XOR -81) to ensure DM41 compatibility. Part of the work-in-progress hp41cx_tools suite, it’s tested with Make (make test) and runs flawlessly on macOS, Linux, and Windows, surpassing Windows-only tools.

Features #

  • Smart Conversion: Transforms .utf8.focal (Unicode, HP-style quotes) to .dm41.focal (ASCII, double quotes), with precise handling of special characters and XROM commands.
  • Context-Sensitive Handling:
    • In ALPHA Strings:
      • Σ~
      • ^
      • \x1D
    • In Commands:
      • ENTER↑ENTER
      • ^
      • ΣS
      • #
  • XROM Handling: Double-comments XROM key assignments (e.g., ;; KEY = XOR -81) to prevent detection by the DM41 encoder, preserving standard key assignments (e.g., ; KEY = TONE 42).
  • Pipe-Friendly: Reads from standard input and writes to standard output, ideal for scripting and pipelines.
  • Cross-Platform: Works on macOS, Linux, and Windows, perfect for any retro computing setup.
  • Open Source: Explore the code on SourceForge.
  • Robust Testing: Backed by AUnit tests via make test for reliable performance.

Usage #

No command-line options—just pipe Unicode FOCAL code in and get DM41 code out:

hp41cx_tools-unicode_to_dm41 < in_program.utf8.focal > out_program.dm41.focal

Example Output #

; STACK =  6.000000000E00  6.000000000E00  3.600000000E03  0.000000000E00  6.000000000E00
; ALPHA = ""
; SIZE =  100
; ΣREG =  624
; KEY = TONE  42
; KEY = FRC -15
; KEY = INT  15
;; KEY = XOR -81
;; KEY = NOT -51
;; KEY = AND -71
;; KEY = OR -61
;; KEY = HEXVIEW -13
;; KEY = OCTVIEW -12
;; KEY = BINVIEW -11
;; KEY = HEXIN  13
;; KEY = OCTIN  12
;; KEY = BININ  11
; A: 099999999994f0  B: 0000002c0480fd  C: 000000002c00fd
; S: 00101010000000
; M: 000018a9ff82fb  N: 016919418e049f  G: 19
LBL "LBLTEST"       ; c000f8004c424c54455354
STO 00              ; 30
LBL 00              ; 01
STO 01              ; 31
LBL 99              ; cf63
STO 02              ; 32
LBL A               ; cf66
STO 03              ; 33
LBL "Z"             ; cc02f2005a
STO 04              ; 34
LBL "T"             ; cc00f20054
STO 05              ; 35
LBL "TE"            ; Key:  81
STO 06              ; 36
LBL "TES"           ; c001f400544553
STO 06              ; 36
LBL "TEST"          ; c201f50054455354
STO 07              ; 37
LBL "TEST5"         ; Key:  43
STO 09              ; 39
LBL "TEST 6"        ; Key:  44
STO 00              ; 30
LBL "TEST--7"       ; Key: -44
RTN                 ; 85
.END.               ; ca0109
                    ; 000000cc002
; MEM = 040 000000000000bf 00000000000000 00000000000000 00000000000000
; MEM = 0bc 00000000000000 00000000000000 00000000000000 ffffffffffffff
; MEM = 200 00000000000000 03ef0010bf0201 00000000000000 00000000000000
; MEM = 300 00000000000000 00000000000301 00000000000000 00000000000000

Notes

  • Input/Output: Reads .utf8.focal (Unicode, HP-style quotes) and outputs .dm41.focal (ASCII, double quotes).
  • Character Handling: Uses AdaCL.Wide_Strings.Spitbol.Patterns for context-sensitive substitutions, as regular expressions fall short for distinguishing ALPHA strings, commands, and XROM assignments.
  • Work in Progress: Part of the evolving hp41cx_tools suite, with more features planned.

Relive the HP-41CX’s golden era with this sharp converter, transforming Unicode elegance into DM41-ready code with the precision of a vintage calculator!