© 2017 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 will change and the word "PRGM" appears in the bottom 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.

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 some 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 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 pop-up menu. The full description of this pop-up 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. Press g P/R again.

Running a Program

To run a program you press the GSB key followed by the program label. Thus, GSB A will run the program 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 labels A through E, as long as Access 'f' and 'g' functions directly is checked in 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 or any mouse click interrupts a running program.

The GTO key can not be used to run a program. In Run mode GTO A positions the program pointer on the step with label "A", but does not run the program.

◀ 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 pop-up menu to open the program description dialogue box. The dialogue has the following elements:

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

The elements in the dialogue box (labels, data storage registers and flags) are displayed in

Documentation Life Cycle

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

When you delete a label or a flag, or if you do not use a data storage register any more, its description is not deleted until you close the Simulator or save the program file. In this cases the documentation is purged, i.e. unused descriptions are deleted and not saved.

If you reuse a previously deleted element prior to closing the Simulator or saving the program, the program description dialogue shows the previous description of that element.

The "Usage" field is a free text field and you can add any text you like, but you should be aware of the following behaviour:

◀ 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. Moreover, programs can also be saved separately: If you press CtrlS, the operating system's "Save file" dialogue box opens. The file name for new programs is preset to "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 option to merge programs upon reading. See the next section on the file format for how to do this manually.

The Simulator remembers the last directory used for writing or reading a program file. This directory is used as the initial 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 Preferences), but then mnemonics with special characters may not be saved correctly. Key sequences are not affected because key codes contain only digits.

If a file is read in, only the key sequences are used. Line numbers and mnemonics are saved for documentation purposes only.

The Simulator uses the file format described so far when it writes a program file. Since the files are simple text files, you can use any text editor that supports UTF-16 (LE) to edit them. When you edit files, the only thing you must address are the key sequences.
For example, you may want to increase the gravitational acceleration precision in the program example from 9.8 m/s2 to 9.81 m/s2. You just have to insert a new program step with the key code for digit 1 after 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 in. When you write back the program with the Simulator, the full file format will be 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 reloaded 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.

Mac OS X:
Current releases of Tcl/Tk don't call the save dialogue box with an activated file type listbox. 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 or all of the following elements are empty, you will be 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 last loaded a program for an HTML-file with the same name as the program file, but the extension ".htm" or ".html". If a program help file is found, it is displayed in the help file browser.

All programs in the "progs" directory of this distribution come with a help file.

◀ Program Files ▲ Top

Menus ▶