The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]

HP41 - How to mix and match UCODE and MCODE in a module

Posted by PeterP on 13 Feb 2009, 7:37 p.m.


I had a few times the wish to combine normal usercode programs and MCODE functions in a custom module. The procedure below works yet I wonder if there is a more efficient way to accomplish this.

Building MCODE functions is most easily done via the SDK41 package from WF. It allows the use of a normal text-editor on a PC to write the code and comment it. Additionally it provides a rapid testing environment where the newly written code can be immediately checked for errors and tested (in single step mode if wanted). AFAIK there is no faster MCODE development environment around. However, sometimes the need arises to add a user-code program to the MCODE functions in the same module and there is no fast way to convert a user-code program into the correct MCODE bytes that have to be loaded that I know of. So I am using emu41 and then SDK41 or M2k to generate the dissasembled code that can then be easily meshed with the MCODE to create one annotated text-file for the whole module.

Prepare EMU41

Create a EMU41.ini file which includes the WWOS as well as a standard 8k MLDL RAM that is provided with EMU41. My .ini files looks like this
; emu41.ini        emu41 init file

[MODULES] ; page size filename 0 12 rom41cx.bin 3 4 cxfcn2d.bin 5 8 cxtime2c.bin 7 4 hpil1h.bin ; ------------ 8 4 WWOSa.bin 10 8 mldlram.dat 15 4 CCD_osx.bin

[DEVICES] DISPLAY HDRIVE1 ;----------------------------------------------------------------

It has the W&W Rambox OS on page 8, the 2 pages of free MLDL Ram on pages A&B and the CCD-OSX for convenience on page 15 (Thank you Raymond…)
Save your .ini file in the same directory as you have your emu41.exe file and run emu41.exe.

Enter your PGM

Now you can enter your program that you want as part of your MCODE module. If it is just a short module, I suggest to just type it in with emu41. If it is longer and you do have a HP-IL card you can also load it in from another PC via the HDRIVE1. (In short: Load the program into a physical HP via finger, Wand, cards, etc – save it to the HDRIVE1 via the HP-IL card – turn off the physical HP41 – load it into memory from HDRIVE1 with emu41).

Store the program in the MLDL Ram

Using the functions of the W&W OS we can easily prepare a page and store the program on it. The steps below assume you have the same emu41.ini file as above and the MLDL ram is at page 10 & 11 (A&B)
  1. 10, xeq CLPG ------------------> this clears page 10
  2. alpha UCODEMOD alpha --------> the name of the module
  3. 8,enter,10 xew INITPG ------------> this initializes the module with XROM number 08
  4. alpha NAME_OF_PGM alpha
  5. 10; xeq LDPGM ---------------------> this compiles and stores your program in the MLDL
  6. alpha UCODEMOD,RE-01 alpha ---> to add revision number and chksum at end of module
  7. 10 xeq ENDPG, xeq PGSUM, xeq PGSUM, xeq ENDPG -----> this ensures that we have a valid module just in case

Convert MLDL Ram to .ROM

  1. exit emu41
  2. copy MLDLram.dat to MLDLRAM.bin
  3. clbin41 MLDLRam.bin MLDLRAM.rom /b ;this converts the .bin file into a .rom file

Disassemble the .ROM file

There are two ways to disassemble the .rom file to get simple text that you can include into your other MCODE source text.
  1. Use D41 from the SDK41 to get a .src file which has the exact hex codes needed to have the UCODE program in the MLDL-ram. The first two bytes are the header for the UCODE followed directly by the bytes for the global Label of your program.
  2. Use M2K Manager’s disassembly function to also generate a text file which has additionally the UCODE steps in it as well. However one needs to do some post-processing to use this file as an input in the SDK41. Alpha-strings and Alpha labels show their hex-codes to the right in the listing. This needs to be corrected by making them separate lines.
Personally I like the UCODE description from M2K and so I post-process them using the D41 assembly as a guideline. This gives me a nice code like the example below.
06BD 013			#013		;UserCode: 137 bytes (19 regs + 4 bytes) NONPRIVATE
 06BE 240			#240
 06BF 1CC	[LDRSU]		#1CC		;*LBL  "LDRSU"         ; 4C 44 52 53 55 
 06C0 000			#000
 06C1 0F6			#0F6
 06C2 000			#000
 06C3 04C			#04C
 06C4 044			#044
 06C5 052			#052
 06C6 053			#053
 06C7 055			#055
 06C8 1F9			#1F9		;... 002  "RSU1-FL:?"          ; 
 06C9 052			#52
 06CA 053			#53
 06CB 055			#55
 06CC 031			#31
 06CD 02D			#2D
 06CE 046			#46
 06CF 04C			#4C
 06D0 03A			#3A
 06D1 03F			#3F
 06D2 18C			#18C		;... 003  AON    
 06D3 18E			#18E		;... 004  PROMPT 
 06D4 18B			#18B		;... 005  AOFF   
 06D5 111			#111		;... 006  1
 06D6 1A8			#1A8
 06D7 000			#000		;... 007  SF   00
 06D8 1A1			#1A1
 06D9 003			#003		;... 008  XROM 04,03 - SETBANK
 06DA 111			#111		;... 009  14
 06DB 1A1			#1A1
 06DC 011			#011		;... 010  XROM 04,17 – GETROM

This code can now easily be combined with the rest of your MCODE source file that you can compile with A41 & L41. Just remember that with the M2K Manager you can easily convert .ROM files into .MOD files in case you need them (for your iPhone for example or V41)

Please let me know of any improvements to this process.



Edited: 17 Feb 2009, 12:29 p.m.


[ Return to the Message Index ]

Go back to the main exhibit hall