Importing and Exporting Programs into and from Free42

Home > Free42 > Import & Export
If you're familiar with the original HP-42S calculator, you will remember what a chore it could be to enter long programs using the keyboard. Since typing was the only way to get programs into the calculator, you just had to put up with this.
Free42, on the other hand, can save programs to files, so you can create back-up copies, load them on another computer, or share them with other Free42 users. The process of saving programs to files (exporting) and loading programs from files (importing) is explained in detail in the following sections.

The program files used by Free42 are compatible with several other HP calculator emulators, including Emu42 and V41. These files usually have names ending in ".raw". However, note that not all programs will actually work in all emulators, since those emulators don't all support the same instruction set; e.g. the HP-41 (and V41) does not have named variables, so instructions like STO "Q" will not work, and Emu42 does not provide printer and Time Module support, so instructions like PRX or DATE will not work.
Generally speaking, programs that stick to the basic HP-41C instruction set and that do not depend on the 24-character ALPHA register length nor any plug-in modules or peripherals, will work on the HP-42S, and in Emu42 and Free42, and of course on all the HP-41 series calculators and V41. Programs that stick to the basic HP-42S instruction set, and do not rely on any of the Free42 extensions, will work on the HP-42S, in Emu42 and, of course, in Free42.


The Basics
Common Functionality in All Versions
iOS: Built-In Web Server
Android and iOS: Sharing

The Basics

First of all, we need to clarify just what is meant by "a program". On the HP-42S, just like its predecessor, the HP-41 series, there can be multiple programs in the calculator's memory, and each program ends with an END instruction. A program starts just after the previous program's END (except, of course, for the first program), and ends with its own END (except for the last program, which ends with .END., but that is really also just an END; it just looks different, so you can tell where program memory ends).
Thus, every program has exactly one END instruction, which is always the last instruction in the program.

Programs also usually include one or more "global labels", that is, LBL instructions like LBL "HELLO". There are also "local labels", LBL 00 through LBL 99, LBL A through LBL J, and LBL a through LBL e; these are different in that they can only be called from within the same program.
The global labels and the END instructions are shown in the PGM catalog. You can see the PGM catalog by pressing CATALOG (Shift +) and then pressing the PGM menu key. You will also see the PGM catalog when you press XEQ.
Note that the PGM catalog will not show any END (or .END.) instructions for programs that contain one or more global labels. Also note that the order in which the global labels and END instructions appear in the PGM catalog is the reverse of the order in which they appear in program memory.

When you tell Free42 to export a program, by selecting its END or any of its global labels, it will always export the entire program, from just after the previous program's END (or, in the case of the first program, from the start of program memory) until its own END.
If you select multiple programs for export, they will all be written to one file, in the same order that they are in in program memory; when you import that file later, all those programs will be imported, still in the same order, and they will appear at the end of program memory, after any programs that were already there.

Common Functionality in All Versions

To export: select "Export Programs" from the "File" menu:

A dialog box will appear that shows all the programs that currently exist in Free42's program memory. There will be exactly one line per program; if a program contains multiple global labels, they will all appear together on one line. If a program contains no global labels, you will see an END (or .END.). You can tell a global label named "END" or ".END." from an END or .END. instruction because label names are always in double quotes, while END and .END. instructions are not.

You can select multiple programs; the exact way in which to do this depends on which version you're using. In the Windows version, you can use dragging, shift-clicking, or control-clicking, for example, which is the usual behavior of list boxes on that platform; in the Mac version, you will see check boxes, which you select or deselect by clicking, etc.
When you've selected the programs you want to export, click OK. A standard file selection dialog will then appear:

Select the name and location where you want the file to be saved, and click Save... and you're done.

To import: select "Import Programs" from the "File" menu. A standard file selection dialog will appear; select the *.raw file you want to import, and click Open... and you're done.
(Sorry, no illustrations -- this is just like opening a file in any other application. You know how to do this.)

iOS: Built-In Web Server

Free42 for iOS contains a built-in web server. In the early days of iOS, this was necessary because there was no straightforward way to copy files between iOS devices and PCs or Macs; iTunes didn't support file transfer yet, and the iOS Files app and Share Sheets did not exist, either. In order to meet the need for file transfer, building a basic web server into Free42 was a reasonable solution.

Nowadays, it's not really needed any more, but since it adds very little to the size of Free42, and some people may actually prefer it to the more modern means of file transfer, it remains part of Free42 for iOS even today.

How to use it: When the server is running, you can connect to it using a web browser on your Mac or PC, and upload and download programs just like you would in any other web site. To start the server, tap in the top part of the screen, just below the status bar:

This brings up the main menu. Tap "Program Import & Export":

This brings up the Import & Export menu. Tap "HTTP Server":

This starts the web server; your screen should now look like this:

NOTE: While the web server is active, the idle timer, which normally turns off your iPhone after some period of inactivity, is disabled. Be sure to stop the web server by pressing Done when you no longer need it, to prevent accidentally running down the battery.

Next, point a web browser on your PC or Mac at the URL shown in the HTTP Server screen (see above):

You will see the top-level directory of Free42's private file area. It contains three directories: config, where the emulator stores its persistent state; memory, where you can see the emulator's program memory; and skins, where Free42 looks for additional skins.

Note: if you do not see this directory listing, but instead get an error message from your browser about the hostname not being found, or something similar, try this: Tap on the URL in the HTTP Server view on your iPhone. It will change into a different URL, this one containing an IP address instead of a hostname. Use this URL instead of the previous one, and you should be able to see the directory listing, even if the phone's hostname isn't recognized by the PC.

You can upload files into the currently selected directory by clicking Browse, selecting the file, and then clicking Upload, and you can download files simply by clicking on them.

When you select memory, you will see a view like this:

The file listing shows one line per program. You may notice that the program sizes shown in this listing are always 3 bytes larger than the sizes shown in Free42 itself; the reason for this is that I wanted the program size shown in the web server to match the sizes of the files that are created when you download programs; the byte count shown in Free42 (and the HP-42S) does not include the 3 bytes for the END instruction, but since that instruction is included in *.raw files, they are always 3 bytes larger.

Note that memory isn't really a directory, it just looks like one. Free42 fakes it to allow you to load programs directly from program memory to files on your PC and vice versa, without needing the intermediate step of creating files on the iPhone first.

To import and export programs to local files on the iPhone, you use the Import Programs and Export Programs commands in the Import & Export Menu. Read the instructions for the other versions to learn how this works.
You will still need to use to use the HTTP Server to get the local files onto or off the device, but having programs in local files can be useful if you want to be able to have local backups that you can restore after CLALL, or when you have made modifications to a program and want to roll them back.

Android and iOS: Sharing

Free42 for Android and iOS support sharing and receiving, for programs (raw) and state files (f42). The following shows how to use email for sharing programs, and uses screen shots taken on an iPhone, but the procedure is similar in Android.

(To share a State File, start with Main Menu → States → (select the state you want to share) → More → Share, and then continue from the Share Sheet in the steps below.)

Start by activating the Main Menu, by tapping in the top part of the screen, anywhere below the status bar and above the center of the display:

Select Program Import & Export:

From the Import & Export Menu, select Share Programs:

Select the programs you want to share, and tap OK:

In the Share Sheet, select Mail:

You will see a blank email with a raw file containing the selected programs attached. Complete the email and send it:

The recipient will be able to load the attachment by tapping it:

Depending on whether or not there are other apps on their phone that are registered to handle the attachment file type, this next screen may or may not appear; if it does, tap the share button in the top right corner:

In the Share Sheet, select Copy to Free42.

That's it! Free42 will load the program or state file. Programs are loaded straight into program memory; state files will appear in the States window, but will not be loaded into memory automatically.

Go to Free42 home page