© 2023 Torsten Manz mail_logo.gif 20x14

Programs

PRGM mode

Writing Programs

To write a program on the HP-15C, you must switch to PRGM mode. To enter PRGM mode, click g P/R or press F9 on the keyboard. The display format will change and the word "PRGM" appears in the lower right corner of the display:

prgm_step_000.gif 310x70

You can now start to key in operations, as you would do in Run mode. The HP-15C will record the keys as you type them in but does not execute any function. HP-15C programs are more like macros than like `real´ programs.

All programs in this documentation use decimal comma style, i.e. the decimal separator is a comma and the thousands separator is a period.

Each program must begin with a label; valid labels are the letters "A" to "E" and the numbers "0" to "9" and ".0" to ".9". As an example, we will write a program that starts with label "A". Click f LBL A or key in F8 Q. This is the first program step and it is displayed like this:

prgm_step_001.gif 310x70

Each key on the HP-15C is identified by a two-digit code that is derived from its position on the keypad. The first digit gives the row (starting at 1) and the second digit gives the column (where 0 means 10). For example, LBL is on the first key in the second row and therefore has the key code "21". Digit keys differ from that rule; the (single) digit itself identifies them.

The codes in a three-key sequence are separated by a digit separator. Codes in a two-key sequence are separated by blanks. There are also four-key sequences like STO + . 5, which adds the contents of the X-register to register 15. This sequence is displayed like this:

prgm_step_021.gif 310x70

To complete the program, key in the following key sequence:

2 × 9 . 8 ÷ √x̅ g RTN

This little program computes the time it takes for an object to fall from a given height to the ground in the earth's gravity field. The gravitational acceleration is approximately 9.8 m/s2.

In PRGM mode you can right-click the display to display the program popup menu. The full description of this popup menu can be found in the Pop-up Menu section.

prgm_mnemonics_col.gif 164x204

To run the program you must switch back to Run mode. Click g P/R, or press F9, again.

In PRGM mode code in the Program File Format can be pasted from the system clipboard into the simulator using CtrlV or B3. The Mnemonic Converter also generates the correct format.

Running a Program

To run a program you click the GSB key followed by the program label. Thus, GSB A will run the program that begins with LBL A. While a program is running, the display flashes "running":

prgm_step_run.gif 310x70

On the Simulator, programs with an alpha label can also be run by clicking on the gold labels A through E, when Access 'f' and 'g' functions directly is activated in the preferences. Programs with numeric labels can only be run using the GSB key. In addition to that, the Simulator provides several shortcuts to run programs. See the Program (Run mode) section in the keyboard chapter for a complete list.

Any keystroke and any mouse click on a simulator key interrupts a running program. Mouse clicks outside of the keyboard area do not interrupt a program. You can for example move the simulator window on the screen while a program is running without interrupting it.

The GTO key can not be used to run a program. When the simualator is in Run mode, GTO A only positions the program pointer on the step with label "A", but does not run the program. To now run the program, click R/S or press F5.

◀ PRGM Mode ▲ Top

Program Documentation

With the Simulator, you can add documentation to your programs, a feature not available on the real HP-15C. The documentation has no impact on the program itself. Documented programs are fully compatible with the real HP-15C.

The Description Dialogue

To document a program, press F12 or select "Program description…" from the ON popup menu to open the program description dialogue box. The dialogue has the following elements:

Changes to the documentation are indicated by a * in the windo title bar.

The elements in the dialogue box, i.e. labels, data storage registers and flags, are displayed in

Documentation Life Cycle

When you start documenting a program, the documentation is only in the simulator memory. To include it in the program, you must save the program file. This also applies to changes to the documentation: You must always save the program manually. When you open a documented program file, the documentation is copied to the simulator memory. Any existing documentation is overwritten.

If you delete a label or flag or if you no longer use a data storage register, its description is not deleted until you close the Simulator or save the program file. In these cases, the documentation is cleaned up, that is, descriptions that are no longer used are deleted and not saved.

If you reuse an element that was previously deleted before you close the Simulator or save the program, the program description dialog displays the previous description of that element.

◀ Documentation ▲ Top

Program Files

Saving and Opening Programs

The current program is always part of the memory file and is therefore saved automatically every time you save the memory. In addition, programs can also be saved separately: Pressing CtrlS opens the operating system's "Save file" dialogue box. The default file name for new programs is "New.15c" or, if available, the first 40 characters of the "Program title". The Simulator supports the file extensions ".15c" and ".txt"; the default is ".15c".

To open a program file press CtrlO. The operating system's "Open file" dialogue box opens. If a program is read in, all currently loaded programs are deleted. If the new program is larger than the available memory, the display shows   ERROR  4  and the program is not loaded. There is no possibility to merge programs while reading in. For information on how to do this manually, see the next section on file format.

The Simulator remembers the last directory that was used for writing or reading a program file. This directory is used as the start directory the next time you open a dialogue box.

Program File Format

Simulator program files are simple text files. The following figure shows the program file for the little program used in the previous sections:

HP-15C Simulator program

 # --------------------------------------------
 # HEWLETT·PACKARD 15C Simulator program
 # Created with version 3.0.00
 # --------------------------------------------

    000 {             }
    001 {    42 21 11 } f LBL A
    002 {           2 } 2
    003 {          20 } ×
    004 {           9 } 9
    005 {          48 } .
    006 {           8 } 8
    007 {          10 } ÷
    008 {          11 } √x̅
    009 {       43 32 } g RTN

 # --------------------------------------------
        

As on the real HP-15C, step "000" is always empty.

Each line in a program file must be of one of the following types:

Program files are encoded in UTF-16 (LE) by default to preserve all special characters used in mnemonics. You can change the encoding to the system default encoding (see Files), but then mnemonics with special characters may not be stored correctly. Key sequences are not affected because key codes contain only digits.

When a file is read, only the key sequences are used. Line numbers and mnemonics are stored for documentation purposes only.

The Simulator uses the previously described file format when writing a program file. Since the files are simple text files, you can edit them with any text editor that supports UTF-16 (LE). When editing the files, you only need to address the key sequences.
For example, you can increase the precision of the acceleration due to gravity from 9.8 m/s2 to 9.81 m/s2 in the program example. To do this, you only need to insert a new program step with the key code for the number 1 behind the line "006":

HP-15C Simulator program

    ...
    003 {          20 } ×  
    004 {           9 } 9
    005 {          48 } .
    006 {           8 } 8
                  { 1 }
    007 {          10 } ÷
    ...
      

Neither the line number nor the mnemonic need be specified. Program steps are automatically renumbered when the file is read. When you write back the program with the Simulator, the full file format is used. Missing information, like the mnemonics, are added by the Simulator.

Omitting all optional information brings us to the simplest form of the example program file.

Simplified file format

 {42 21 11}  
 {2}
 {20}
 {9}
 {48}
 {8}
 {10}
 {11}
 {43 32}
       

HTML Export

The program code together with the documentation can be exported to an HTML-file. HTML exports can not be loaded back into the Simulator! They are for documentation purposes only.

To export a progam to HTML, open the "Save program…" dialogue box and choose "HTML Files (*.htm, *.html)" as the file type. The HTML files are UTF-8 encoded.

macOS:
Current releases of Tcl/Tk don't call the save dialogue box with the file type listbox activated. Therefore you must call the save dialogue box either by "File | Export program to HTML…" or by the short-cut E to select "HTML Files (*.htm, *.html)" as the file type. You can also manually add ".htm" to the filename, to force the HTML export.

If one the following elements is empty, you are asked if you want to save the file anyway:

The warning message can be disabled in the Preferences dialogue.

If you press CtrlF1 or ShiftF1 on the Simulator it searches the directory from where you loaded the program for an HTML-file with the same name as the program file and the extension ".htm" or ".html". If a program help file is found, it is opened in the help file browser.

All programs in the Program Examples package come with an HTML help file.

◀ Program Files ▲ Top

Menus ▶