Post Reply 
Transferring programs to and from a HP41
04-12-2024, 12:43 PM (This post was last modified: 04-12-2024 12:45 PM by ThomasF.)
Post: #1
Transferring programs to and from a HP41
Hi all,

Long story in short format: I can now send a program from my 41 that is saved as a RAW file on my PC - ready to be used in an emulator or in the DM41X without any translation - in shorter time then it takes to read this line!

Just as a teaser and because it could be done ...

I have always been looking for a simple way to down- and up-load programs to my 41.
As can be found in other posts I have e.g. implemented the Wand in my Tiny41 board, so I can "scan" any barcode on my PC and directly download it to the 41 by emulating the Wand (i.e. I don't need a Wand - i just transfer the bytes in the same format as from the real 82153A into the 41).

I got inspired by another thread dealing with the 41CL and started to look into the other way, ie. how to save programs from the 41 into the PC?

Well, printing can't be used, since some information is lost in the process (i.e. synthetic string etc).

Then I thought of making the Tiny41 as a new peripheral to the 41, and send data to it.
So I implemented some new instructions to handle the bytes in the Pico and a program to save the file on the PC.

To receive the file on my PC I start the program stating a file name to save the program into:
Code:
$ getraw my_prog.raw

Then on the 41 I execute the new command SENDP:
Code:
XEQ ALPHA SENDP ALPHA
SENDP _
ALPHA PROG ALPHA
Then the program PROG is sent to the PC ending up in the file my_prog.raw ready to be used.
Done - that's it! The file is transferred!

For anyone interested, below is the complete MCODE program in the 41 to send the file.
It finds the start and length of the given program, then sends all bytes to the Tiny41 board.
In the Tiny41 the bytes are extracted and just sent over USB to a virtual COM-port on the PC, which the getraw program reads and then stores the bytes in the named raw file.

The IR-led on the board could also be used so that the program could be transmitted that way instead, having a program looking at the IR-receiver on the PC instead - or another 41 with a similar board (with an IR-receiver) receiving the file - and voila: easy file-transfer between two 41's!

The trick I use is some new instructions which are interpreted by the Tiny41 board, right now I use 3 instructions:
  • 000 - Init transfer (with program size in C[3:0])
  • 002 - Send next byte to be sent in C[1:0]
  • 00E - Send end-of-transfer to close the connection
(Note that bit 0 in the command is used to deselect the peripheral).

In this example I use command 002 to init the transfer (program size is in M):
Code:
          C=0    ALL
          RAMSLCT
          PRPHSLCT
          C=M
          SELPF   8               ; Select the Tiny41 board
          #003                    ; Send byte using instruction 002 (with stop bit) ...


Sending a complete program to the PC is now as easy as printing it and it just takes a second or two ... Wink

Happy coding!

Cheers,
Thomas

Note - this is just a proof of concept and there are room for improvements, e.g. I have not dealt with FOCAL code in ROM.
But it works as an example for the flexibility and the power of the Tiny41 (Pico) module and what could be done with it!

Code:
          #090              ; "P"
          #004              ; "D"
          #00E              ; "N"
          #005              ; "E"
          #113              ; "S" - prompt for alpha label
[SENDP]   NOP               ; Non programmable
          READ  9           ; Get the alpha string (program name)
          M=C
          ?C#0    ALL       ; Null?
          JNC     [SNDP10]  ; Send current program
          ?NCXQ   [ASRCH]   ; Do the alpha search
          A=C     ALL
          ?C#0    ALL       ; Found it?
          JNC     [SNPERR]  ; Nope ...
          ?FSET   9         ; MCode?
          JC      [SNPERR]  ; Yes, can't send it ...
          SETF    10        ; Clear ROM flag
          ?FSET   2         ; ROM?
          JC      [SNPERR]  ; Yes, can't send ...
          R=      3
          JNC     [SNDP16]

[SNDP10]  ?NCXQ   [GETPC]
[SNDP16]  ?NCXQ   [FLINKA]  ; In RAM, find end of program
          RCR     4
          A=C     ALL       ; A[7:4] Program end addr
          RCR     4
          A=C     R<        ; A[3:0] Program end addr
[SNDP20]  ?NCXQ   [CPGM10]  ; Get prog head addr
          C=A     ALL
          RCR     8
          B=C     ALL       ; Save in B[13:6]
          RCR     10
          B<>C    R<        ; B[3:0] = Prog end addr
          ?NCXQREL [CNTBYT] ; Compute prog length in bytes
          B<>C    ALL       ; C[9:6] = Start addr
          RCR     6         ; C[3:0] = Start addr
          A<>C    R<        ; A[3:0] = Start addr
                            ; C[3:0] = Program length in bytes
          C=C+1   R<        ; Increment to handle END
          M=C
          C=0  ALL
          RAMSLCT
          PRPHSLCT
          C=M
          SELPF   8         ; Select Tiny41
          #001              ; Init transfer and send size ...
[SNDP25]  B<>C    R<        ; Save length in B
          ?NCXQ   [NXBYTA]  ; Get the next byte
          M=C
          C=0  ALL
          RAMSLCT
          PRPHSLCT
          C=M
          SELPF   8         ; Select Tiny41
          #003              ; Send the byte ...
          B<>C    R<
          C=C-1   R<
          JNC     [SNDP25]  ; Done with all bytes?
          C=0  ALL
          RAMSLCT
          PRPHSLCT
          SELPF   8         ; Select Tiny41
          #00F              ; End transfer ...
          RTN               ; That's it - done!

; Routine to calculate the size of a program given
; start and end in MM format
[CNTBYT]  R=    3
          C=0   ALL
          A=A-B @R
          JNC   [CBYT10]
          A=A-1 S&X
          A=A-1 @R
[CBYT05]  A=A-1 @R
[CBYT10]  A=A-1 @R
          JC    [CBYT20]
          C=C+1 S&X
          JNC   [CBYT05]
[CBYT20]  A=A-B S&X
          B<>C  R<
          A=0   @R
          C=A   R<
          C=C+C R<
          C=C+C R<
          C=C+C R<
          A<>C  R<
          A=A-C R<
          A=A+B R<
          RTN

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
04-12-2024, 01:55 PM
Post: #2
RE: Transferring programs to and from a HP41
Thomas, amazing stuff!

I just searched but was not able to find a description for building the Tiny41 etc - will you release that at some point maybe? Or should I look under a different thread name than Tiny41?

What would be great is to extend this to send a full module / page to the PC and back (SaveMod GetMod) for those 41Cs that have a RamBox/Clonix/NovD/etc installed. I think that would be quite cool.

Cheers,

PeterP
Find all posts by this user
Quote this message in a reply
04-12-2024, 02:08 PM
Post: #3
RE: Transferring programs to and from a HP41
(04-12-2024 01:55 PM)PeterP Wrote:  Thomas, amazing stuff!

I just searched but was not able to find a description for building the Tiny41 etc - will you release that at some point maybe? Or should I look under a different thread name than Tiny41?

What would be great is to extend this to send a full module / page to the PC and back (SaveMod GetMod) for those 41Cs that have a RamBox/Clonix/NovD/etc installed. I think that would be quite cool.

Hi Peter,

Start here: https://www.hpmuseum.org/forum/thread-20...light=pico
(Or just search for Pico or RP2040 in the forum.)

The Tiny already have all modules and Extended memory in it's flash memory, so these can be copied back and forth already. But a program that reads other modules should already be available I think (for other ramboxes or Clonix modules etc) and should be easy to adopt.

Tiny41 is my own device, which is a development board I made, which I could share info about, but nothing I'm producing.
But, maybe there will be something coming ...

Cheers,
Thomas

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
Find all posts by this user
Quote this message in a reply
04-13-2024, 11:30 AM
Post: #4
RE: Transferring programs to and from a HP41
(04-12-2024 02:08 PM)ThomasF Wrote:  But, maybe there will be something coming ...
Not a maybe, something will be coming for sure

Regards, Meindert
Find all posts by this user
Quote this message in a reply
04-13-2024, 05:42 PM
Post: #5
RE: Transferring programs to and from a HP41
(04-13-2024 11:30 AM)MeindertKuipers Wrote:  
(04-12-2024 02:08 PM)ThomasF Wrote:  But, maybe there will be something coming ...
Not a maybe, something will be coming for sure

Looking forward to it!

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)