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:
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:
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:
To complete the program key in the following sequence:
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.
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":
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.
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:- Program Title
A one-line description of the purpose of the program.
- Usage
A multi-line text field to describe how to use the program. Standard shortcuts Ctrl–X, C, V and Z (undo) / Y (redo) are supported.
The toolbar below the text field allows you to easily add HTML tags to the description. Activating "Preview" renders the text.
Note: You can not change the description while the "Preview" mode is active.
- Labels
One field for each label in a program step starting with f LBL, GTO or GSB.
It is possible to use a label more than once in a program, but you can have only one description for all occurrences.
- Data Storage Registers
A one-line field for each data storage register in a program step starting with STO or RCL.
- Flags
A one-line field for each Flag in a program step starting with SF, CF or F?.
- Show resources in tabs
If this option is checked, Labels, Data Storage Registers and Flags are displayed on individual tabs. This reduces the vertical space requirement to display the resources. This is helpful if you have a small monitor, e.g. on a laptop, or if you want to see more lines of the Usage field or both is true.
- Reload
When the button is pressed, the current program is analysed and the dialogue is redrawn with the current set of labels, data storage registers and flags. See the next section for more details.
- OK
Stores the documentation in the memory of the Simulator. The documentation is NOT written to the program file at that time.
- Cancel
The documentation in the memory of the Simulator remains unchanged.
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
- 1 column, when not more than 10 elements are used
- 2 columns, when more than 10 but not more than 40 elements are used
- 3 columns, when more than 40 elements are used or the vertical screen size is 800 pixels or less. This is the case on most notebook computers.
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:
- Hard returns should only be used to structure the text, e.g. to insert an empty line. The final text should be checked by resizing the documentation dialogue.
- A "\n" is replaced by an empty line when the documentation is saved.
- Empty lines at the end of the usage text are deleted when the documentation is saved. This is done after "\n"s are replaced by empty lines.
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
Ctrl–S, 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 Ctrl–O. 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 |
---|
|
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:
- Documentation
Documentation lines begin with a "
#
" immediated followed by one of the letters:
- T
- Program title.
- D
- Program description (the content of the "Usage" field).
- L
- Label description. Followed by "-1"…"-5" for labels "A"…"E" or a number between "1" and "19"
for labels "0"…".9".
- R
- Data storage register description. Followed by a number between "1" and "19" for registers "0"…".9".
- F
- Flag description. Followed by a digit between "1" and "9" for flag "0"…"9".
Editing the documentation manually is discouraged; use the program description dialogue box instead.
- Comment
Comment lines begin with a "
#
" not followed by one of the documentation letters. Leading white spaces are ignored.They are intended only for internal use. Use the documentation dialogue to describe your program.
- Blank line
A blank line is a line that contains only white spaces or is of zero length. Blank lines are skipped.
- Program step
Each line not recognised as a comment or a blank line is expected to contain a program step. The line must then have the form:
[line_number] "{" key_sequence "}" [mnemonic]
The "
key_sequence
" must be a valid HP-15C key sequence enclosed in curly braces; "line_number
" and "mnemonic
" are optional, and white space is ignored.
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 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 |
---|
|
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 |
---|
|
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:
- Program
- Program Title
- Usage
If you press Ctrl–F1 or Shift–F1
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.