
	HP-41 Programming Environment & Bar Codes Generation

			HP41_ProgEnv.XLS
			HP41_BarCodes.XLS
			HP41_PRGM.DOC

		Author : Pierre HARDY
		Date :	 September 2006

	Copyright (c) Pierre Hardy, 2003-2006, GNU General Public License
	  
	E-mail author at: pierre.hardy@swing.be
	
	http://users.swing.be/id-phy

	===================================================================

* THIS FILE IS OUTDATED, REFER TO WEBSITE AND/OR TO INTRUCTIONs IN HP41_ProgEnv.XLS *
* UPDATED, CORRECTED AND ENHANCED IN 2006.  *



The purpose of HP41_ProgEnv.XLS spreadsheet and its associated macros and tool bar is to provide a kind of HP-41 programming environment. 

The main programming assistants are :
- a toolbar with most HP41 (and some periferals) instructions, reducing encoding/editing time
- export and import function to save the program as TExT file (for their later compipilation)
- compile and de-compile function (with prior/post export/import) using Leo DURAN HP41UC.EXE program
- launch the HP-41 emulator on successfull compile and load the the new code (V41.exe program)
- produce bar codes, using Dan McDonald's macro and sheet (this tool is in fact an "extension" of Dan's tool, thanks to him).

HP41_BarCodes.XLS contains a set of functions to produce almost any kind of Bar Codes

HP41_PRGM.DOC is a Word template to format the HP-41 code listing.

I build all this to make a "cash register" program (CAISSE in French) for my daugther, with the printer and WAND.  So the files provided as template do still have this program as example.

*** CHECK FIRST ON MY WEBSITE FOR LATEST VERSION AND INSTALLATION INSTRUCTION ***

http://users.swing.be/id-phy/HP41/HP41_ProgEnv.html

---------------------------------------------------------------------------------------------

Prerequisites
=============

- Specific fonts installed (both provided by Dan McDonald) :
	- 41C BarCode
	- LCD4
- HP-41 Compiler / De-compiler : HP41UC.EXE (provided by Leo DURAN)
- HP-41 emulator : V41.EXE (Release 8 : V41R8.ZIP or .EXE)

*** The compiler 'HP41UC.EXE' & emulator 'V41.EXE' are "hardcoded in macro.  Ensure they are present with this exact name, event if new release issued with other name ***


Programming Environment
=======================

Writing code
------------
The instructions must be in the column A, starting in A1 cell. There are no titles so the row number will correspond to the program line number (
Comment can be placed into column B (without any delimiter, the ';' being added on export).
Cells with labels (LBL) are automatically highlighted in yellow (conditional formatting).

To help program more efficently, I suggest to open two windows (window / new window, vertically arranged), one for the code itself (the left one) on HP41_PRGM tab, and horizontally splitted, and the right one on Reg&Notes tab (for more comment, use of labels, flags, register, ... a reminder). But up to you. 
There is no debugging tool, however, I wrote two macros (Go2LBL & GoBack) which allow an easier navigation.
You should also 'split' the HP41_PRGM windows, because those macro jump between them.

Go2LBL
As you would guess, Go2LBL will look for a Label and make it the active cell ... in the lower left pane (hence window split suggestion ;-) ).  If, when calling the macro, the cursor is on a XEQ or GTO instruction, it will go to the associated label, and otherwise, will ask for a label. Should be invoked from the upper part, and will show the Label in the lower part of the split windows.

GoBack
After a Go2LBL call, the GoBack will ... go back to the previous cell (the one active when calling Go2LBL), and this in the upper left pane. The macro can go back up to 7 levels (this is the maximum nested subroutine supported by HP-41). GoBack jumps back to the upper part.

The 'HP41 Intructions' toolbar present most HP-41 instructions, plus some added functions (added functions do have an associated icon). To add (insert) an instruction not in the toolbar, use the 'Add Instr.' button which will open a input popup window.
The 'Del' button delete the selected instruction(s) with the comments



Note : Some instructions (like 'LBL') have shortcut associated (ALT-L). To work properly, the corresponding shorcut must be de-activated on the Menu bar (using 'Customize ...' and  removing the '&' from the name).  But this is your customization choice.


INPUT
All input are first formatted as (including the suffix ones) :
- Close quotes : if a string contain only ONE quote ('"'), then a second one is added at the end of the string
- String are converted to uppercase, except the quoted '"' part and except for single character strings 'a' to 'e'
- String starting with '>' the APPEND character are automatically quoted (if not already so)

SUFFIX
For instruction with suffix (TONE, LBL, STO, XEQ, FS?, ...) :
- An input popup window is invoked
- The '.' as first character of the suffix string is converted to 'IND'
- Number below 10 are reformatted with one leading '0'
- If not already quoted, string are quoted except single characters refering to registers / numbers over 99 : A-J, L-Q, T, X-Z, a-e (I still miss one synthetic programming register).

STO
If the first character is an operator (+,-,*,/) the instruction is converted to ST+,... before processing the suffix.



Export/Import and Compile/De-compile
-------------------------------------
Those tools work with intermediate files, written/read from the same directory as the spreadsheet.  The used file name is taken from "FileName" cell (D2).
The file name, without extension, must complie to "native" DOS naming convention (MAX 8 chars, ...).
Following extensions are used :
- .TXT for text file 
- .RAW for compiled file
- .LOG for compiler log (standard output redirected)
- .BIN for compiled file in binary format
- .LST for bar codes listin (with hexadecimal strings, as per Dan McDonald's macro)
For (de-)compile function to run properly, the Leo DURAN program (HP41UC.EXE)  and the HP emulator (V41.EXE) must be in the same directory as this worksheet.

*** NOTE THAT THOSE FILES WILL BE OVERRIDDEN / DELETED AT EACH OPERATION ***

EXPORT
Instructions in column A, with comments in column B are exported into the Text file : 
- The .TXT file is overridden
- When a comment is present next to the instruction in column B, it is added with 2 TAB and ';' comment separator in front
- If last instruction is not 'END', this one is automatically added.

IMPORT
Read the Text file into columns A and B (comments)
*** CONTENT OF COLUMNS A AND B ARE CLEAR BEFORE THE IMPORT ***

COMPILE
The compile function do the following :
- First EXPORT instructions
- Run Leo DURAN compiler (HP41UC.EXE) with the .TXT file as input, and the .RAW as output
- The compiler result is written in .LOG (with DOS stantard output redirection) and then read into a message box for acknowledgement.
- If acknowledged, the HP-41 emulator (V41.EXE) is launched and the .RAW file is loaded.
It is recommended to uncheck the 'Auto Save on Exit' option in the V41 settings so that at each start you start with a "virgen" calculator (prevent the "reload" of the same program each time, thus having multiple instances in memory).

DE-COMPILE
If modifications/corrections are made directly within the emulator, you can export them in a .RAW file (using 'Put User Code ...'). The de-compile function will then :
- Run Leo DURAN compiler (HP41UC.EXE) with the .RAW file as input, and the .TXT as output
- The compiler result is written in .LOG (with DOS stantard output redirection) and then read into a message box for acknowledgement.
- If acknowledged, the .TXT file is imported in the spreadsheet. 

WRITE BAR CODES
The BarCodes macro produces the bar codes in Bar_Codes sheet based on intructions in HP41_PRGM sheet.
Therefore, the instructions are first exported into a .TXT file, then compiled in .BIN format before re-importing it as bar codes using Dan MacDonald's macro (a little adapted to separate data input (file names, ...) from processing itself). A list (.LST) file is also produced (as per Dan's macro) with the bar codes hexadecimal strings.


Bar Codes Generation
====================

HP41_BarCodes.XLS contains a set of 'User Defined' functions to generate Bar Codes for HP-41 Wand (bar code reader).  Bar codes generated are actually their hexadecimal string code, with leading and trailing (orientation) codes, X and Y respectively.  When selecting '41C BarCode' as font type, the string is then display as true bar codes, which can be printed (and read by the WAND !).

Refer to "Creating Your Own HP-41 Bar Codes Manual, March 1981, Hewlett-Packard" original book for detailed information, algorithms, ...

This file also contains "ready to use" information and bar codes sheets :
- HP-41 function list
- HP-41 character set, with name, display on HP-41, on printer, and its associated bar code
- HP-41 & XROM function sets with bar code
- ...

User defined functions :
------------------------

Function		Bar codes string generated	Argument(s)
++++++++		++++++++++++++++++++++++++	+++++++++++
Char_BC(Char_code)	Character			Character number (integer from 0 to 127)
Single_BC(code)		Single byte (number,...)	Code (from 0 to 15)	
Funct_BC(Func_code)	Programmable function		Function number (integer from 0 to 255)
NP_Funct_BC(Func_code)	Non Programmable function	Function number (integer from 0 to 15)
XROM_BC(XROM_ID, Fct)	XROM function			XROM ID (integer), XROM function number (integer)
NumData_BC(Number)	Numeric data			Number (integer, long, single, double, decimal, byte,
							or string)
AlphaStr_BC(Str,App)	Alpha string			String, Append mode (boolean : TRUE to append)
AlphaRge_BC(Str,App)	Alpha string			Range of characters (integer) making the alpha string,
							Append mode (boolean : TRUE to append)
DirectXEQ_BC(Func_str)	Direct execution code		Function string to be directly executed 
			(Complete functions)			Supported functions : GTO, XEQ, STO, RCL
								Ex: GTO ABC; XEQ IND 05; RCL d
Build_BC(); D2Hex()	*** for intern use ***


Usage examples are provided in this file, and also in "Caisse_BarCodes.XLS".



Get a "Formatted" listing
=========================
As the code can became quite long, printing it under Excell would lead to pages and pages of listing, with only one thin left column.  To solve this, I made a Word "template" with 3 columns, in which you can import the .TXT file, and then format it for easier reading/debugging.

This is not fully automated, so here how to proceed :
- Open the Word "template" 'HP41_PRGM.doc' and 'Enable Macro'.
- Clear its content : [Ctrl-a] (select all) then [Delete]
- Insert the .TXT file : Insert / File ... / ... (find the .TXT file : output of EXPORT macro) / Insert
- Run FormatListing macro : Tools / Macros / Macros... (or [Alt-F8]) / Select 'FormatListing' / Run
- Print and Save it as usual ...

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    HP-41 Programming Environment & Bar Codes Generation		
    Copyright  2003-2006 Pierre Hardy		

    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.		

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.		

    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

				=*=*=  Have Fun =*=*=