Loading
Everything HP200LX: Knowledge, Products, Service

 Archives
9 years, 100's of pages of HP Palmtop Paper, jammed with tips, reviews and how-to's

Links
Most useful, up-to-date Web sites devoted to the HP 200LX

Downloads
Direct link into 1000's of pieces of Palmtop software

Tips from Our Techs

2008 Catalog
(PDF, 2.6 MB)

Contact Us/About Us

 
Weekly Palmtop Paper Newsletter
(Palmtop tips, latest happenings, and HP Palmtop Paper Store information)


 

 

Privacy Policy

Programmer's Corner Create Interactive Batch Files with ECHONL

Programmer's Corner Create Interactive Batch Files with ECHONL

Ed shows how to create a variation of DOS's "ECHO" command that will let you create interactive DOS batch programs that ask for input and display menus.

By Ed Keefe

This is one of those "rainy day" columns. Something to skim now and dive into later when you have time on your hands. We'll look at a short program, ECHONL.COM , and show how it can be used in batch files to open up all kinds of possibilities for the HP Palmtops or any MS-DOS computer.

ECHONL is a simple little program that mimics the ECHO command in DOS but doesn't move to the next line when it ends. (Hence its name, ECHO + No blank Line, pronounced "echanol".) In PGM.BAT you'll see a how ECHONL is used to create a simple interactive batch file that loads a program and asks for command line input. Then, in FM.BAT , you'll see how to create a "Fast Menu" batch file to select and run DOS programs.

ECHONL: Some Assembly Required

The batch files in this article use ECHONL to create a temporary batch file. This approach lets you append parameters to a single command line that will be executed when the temporary batch file is run.

ECHONL is found on this issue of The HP Palmtop Paper ON DISK. You can also create the program from scratch using the following instructions. You'll need a text editor (MEMO will do) and the DEBUG program (built into the HP Palmtops).

Carefully key the following assembler code into your editor. You may omit typing the semicolon and the following comments, but be sure there is a blank line before the RCX command and another blank line after the final Q.

N ECHONL.COM
A 100
MOV BX,0081 ; point at commandline+1byte
MOV DL,BYTE [BX] ; is it d hex?
CMP DL,0D ; if yes then
JZ 11A ; jump to bye otherwise..
; loop
INC BX ; increment the pointer.
MOV DL,BYTE [BX] ; put what's pointed at
; by bx into dl
CMP DL,0D ; is it d hex?
JZ 011A ; yes: then jump to bye
MOV AH,02 ; else invoke function #2
MOV DH,0
INT 21 ; of the dos interrupt
JMP 010A ; repeat from loop onward
; bye
MOV AH,4C ; quit to dos
INT 21
; write 1eh (30) bytes
RCX

1E
W
Q

Check your typing for any mistakes and save the file as ECHONL.SCR .

To be on the safe side, close all open applications, and back up your disk drives, C: and A: (if you have a RAM card). When working with any new program this is good advice. When working with DEBUG, this is absolutely the best advice.

At the DOS prompt, type the command:

DEBUG < ECHONL.SCR

and press (ENTER).

Watch for any "^Error" messages. If no errors appear, you'll be rewarded with a 30 byte file called ECHONL.COM .

To check the program file at the DOS prompt type in the command:

DEBUG ECHONL.COM

and when the DEBUG prompt appears, type U and press (ENTER). Compare the Unassembled version of the program with the printed listing. If they match, you're in business: if not, look for any more typos. (The unassembled version may show some extra code after the INT 21 line. You may ignore this. Also, you won't see any of the comments you typed.) Press Q and (ENTER) to quit DEBUG.

Here's a quick way to test the ECHONL program. At the DOS prompt, type the following set of commands, pressing (ENTER) after each command.

ECHONL Hello, > TEST1

ECHONL world! >> TEST1

ECHO Hello, > TEST2

ECHO world! >> TEST2

TYPE TEST1

TYPE TEST2

The last two commands cause the words "Hello world!" to be displayed on screen. Compare the results. TEST1 shows how ECHONL works, and should display:

Hello, world!

TEST2 shows how ECHO works, and should show:

Hello,

world!

Notice that ECHONL lets you append text to a line in a file rather than starting a new line.

PGM.BAT: Using ECHONL to create an interactive batch file

Now, let's see what you can do with this simple little program in the PGM.BAT batch file.

When you start a program from FILER on the HP 95LX or the 100/ 200LX, you cannot add any command line parameters. Many DOS commands (e.g. DEL, COPY, TYPE) require one or more parameters in order to run. Others (e.g. DIR, CHKDSK) will use default parameters if none are listed.

For example, CHKDSK assumes you want it to check the current directory if you do not supply parameters. So if you use FILER to run CHKDSK from drive D:\DOS on the 100/200LX, or run it from the DOS D:\DOS> prompt with no parameters, it always checks the D: drive. CHKDSK is found on the 95LX's C: drive. If you run it from FILER or from DOS without a parameter, you always check that drive.

In order to check drive A: you have to exit to DOS and type: CHKDSK a: at the DOS prompt. Or you can run the batch file described below, which uses ECHONL and lets you enter a command line parameter before it will run the DOS program. PGM.BAT will start from FILER, wait for a command line parameter, combine the parameter with the batch file name, run the batch file again, and run the DOS program using the parameter.

In this instance, PGM.BAT runs the CHKDSK program. However it could run any DOS command or program.

Creating PGM.BAT

In MEMO, or any text editor, key in the following batch file. Omit the line numbers. They're only there for reference. The double colons at the start of three lines are used in place of REM statements to speed up the program's execution. The batch file ignores those lines:

1 ::PGM.BAT
2 @echo off
3 If not "%1" == "" goto start
4 echonl %0 > tmp
5 echonl %0
6 ::echo {esc}[13;26;13p
7 copy tmp+con tmp.bat > nul
8 ::echo {esc}[13;13p
9 cls
10 tmp
11 :start
12 CHKDSK %1
13 if exist tmp.* del tmp.*

Now let's see how this batch file works. Save the file as PGM.BAT and make sure that the PGM.BAT and ECHONL.COM files are in the same directory.

PGM.BAT is what I call a "shirt and tie" batch file. Since it reminds me of some restaurants that require that you wear a tie to be seated. Sometimes the maitre de will lend you a tie, but you have to step outside and come back in with the tie on. The "tie" in this case is a command line parameter. Line 3 above is where the batch file checks for a parameter (i.e. the maitre de checks for the "tie"). Line 4, 5 and 7, the ECHONL and COPY CON commands, get the parameter from the keyboard and put it in TMP.BAT (i.e., you get the tie from the maitre de). Line 10 steps outside of the current batch file and runs a second batch file, TMP.BAT. TMP.BAT in turn runs PGM.BAT again but this time with the parameter, A:. (i.e., you step back in with the tie on.)

You come back to line 3 where batch file checks again, sees the parameter and passes control to Line 11. This allows the CHKDSK program to run with the parameter.

Let's look at this batch file line by line to see how it works:

Line 1 - is the (::) REMarked out title of this program.

Line 2 - stops batch file commands from echoing to the screen.

Line 3 - checks to see if PGM has a command line parameter. (It won't, if you're running the PGM.BAT from within FILER.) If there is NO such parameter, lines 4-11 are run. If there is a parameter it jumps to line 11, :start, and runs CHKDSK with the parameter.

Line 4 - contains the first ECHONL command, which sends the name of the batch file, PGM.BAT, to a file called TMP. MS-DOS fills in the name of the batch file in use wherever it sees %0.

Line 5 - the second ECHONL command sends the .BAT file name to the screen, in this case PGM, and waits on the same line for the next command (Line 7) to be completed.

Line 6 and 8 - is REMarked out. It is used only if you have ANSI.SYS or NANSI.SYS installed. It eliminates the need to use F6 (CTRL-Z) and is explained later in this column.

Line 7 - the result of this command is that whatever you type on the console is appended to whatever is on the screen from Line 6 (PGM in this case) and stored in a file called TMP.BAT.

For example, when you type, A: and press (F6)-(ENTER), the command line pgm a: will be completed and copied to TMP.BAT.

CON stands for "console" (the keyboard in this case) and copy con filename copies whatever you type on the console to a file on the disk. Copy file1+file2 file3 is another variation on the COPY command. It combines FILE1 and FILE2 and stores the result in FILE3.

You need to press (F6) (ENTER) or (CTRL)-(Z) (ENTER) at the end of a COPY CON command. The > nul statement tells DOS to discard the "1 file(s) copied" message that usually follows copying a file.

Line 9 - clears the screen.

Line 10 - runs the newly created TMP.BAT file (containing the single line pgm a: in our example). This runs the PGM.BAT file again, this time with the command line parameter A:, so that line 3 will execute a jump to the :start label.

Line 11 - is a label, "start," that is used by the goto statement in line 3.

Line 12 - runs the DOS program, in this case CHKDSK. The %1 is the variable that holds the command line parameter (A:). You can modify this batch file to run another command or program by replacing CHKDSK with the name of the command or program you want to run, DIR, VDE , FREYJA , etc.

Line 13 - deletes all the TMP files that were created by running PGM.BAT.

FastMenu batch file

Now, let's see how ECHONL can be used to perform some major magic by creating a DOS FastMenu program. In this example the FM.BAT file will create a menu for DIR, CHKDSK, and DEBUG. However, any DOS commands or programs could be run from this menu using FM.BAT.

In MEMO, or any text editor, carefully key in the following batch file. Omit the line numbers. They're only there for reference.

1 :: FastMenu.BAT
2 @echo off
3 cls
4 if exist tmp.* del tmp.*
5 if not "%1"=="" goto %1
6 echo ----------------------
7 echo Press Uppercase Letter
8 echo and Enter
9 echo Dir DEbug
10 echo Chkdsk Quit
11 echo ----------------------
12 ::===Check for Menu Item========::
13 ::This part is "reusable code". It
14 ::will make any batch file inter-
15 ::active. Take :: from the next
16 ::line, if you use it elsewhere.
17 ::if not "%1"=="" goto %1
18 echonl %0 > tmp
19 echonl %0 choice:
20 ::echo {esc}[13;26;13p
21 copy tmp+con tmp.bat >nul
22 ::echo {esc}[13;13p
23 cls
24 tmp
25 ::===========================::
26 ::next part contains labels and
27 ::DOS commands. Use %2 where you'd
28 ::typically use %1. The labels can
29 ::be single letters or full words.
30 ::--------------------------------
31 :D
32 ::--------------------------------
33 ::"reuse" the code, above,
34 :: ask for more commandline args.
35 ::
36 if not "%2"=="" goto D2
37 echonl %0 %1 > tmp
38 echonl %0 %1 choice:
39 ::echo {esc}[13;26;13p
40 copy tmp+con tmp.bat >nul
41 ::echo {esc}[13;13p
42 cls
43 tmp
44 ::--------------------------------
45 :D2
46 DIR %2 %3 %4
47 pause
48 %0
49 :DE
50 DEBUG %2 %3
51 %0
52 :C
53 chkdsk %2
54 pause
55 %0
56 :Q
57 cls

Save the file as FM.BAT and make sure that FM.BAT and ECHONL .COM files are in the same directory.

You'll notice that FM.BAT is the same type of "shirt and tie" batch file as PGM.BAT. In fact lines 17 - 24 in FM.BAT are the same as lines 3 - 10 in PGM.BAT. Below is a summary description of the important lines:

Line 5 - checks to see if the command, FM has a command line parameter (it won't if you run FM.BAT from FILER). If there is NO parameter, lines 6-11 display a menu.

Line 18 -- ECHONL sends the name of the batch file, FM, to the TMP file. Remember MS-DOS fills in the name of the file wherever it sees %0. One advantage to using %0 is that you can change the name of FM.BAT to whatever you want. The program will still work!

Line 19 -- puts the prompt FM choice:, on the screen.

Line 21 -- the command copy tmp+con tmp.bat causes whatever you type on the console to be appended to whatever is on the screen from Line 18 (FM in this example). When the FM menu is displayed you'll need to enter one of the uppercase letters from the menu, for example D (for Dir) and then press (F6) (or (CTRL)-(Z) and then (ENTER).

Line 24 -- runs the newly created TMP.BAT file which (thanks to the ECHONL command) contains the single command line FM D in our example. FM.BAT is run again, this time with the command line parameter D. This time, line 5 will goto the :D label in line 31.

Lines 25 and on -- contain labels and DOS commands corresponding to the options in the menu. For example, the :D2 label is followed by the DIR %2 %3 %4 command. The extra variables are there just in case you want to use more than one command line parameter.

Lines 33 through 47 -- show how you could modify the code from lines 17-24 to get the batch file to ask you not once, but twice, for input.

You don't need to restrict yourself to one-letter choices, which would limit the total number of menu selections to the 26 letters of the alphabet. For example, both Dir and Debug start with the letter "D". So to distinguish between them, I use "D" for Dir and "DE" for Debug. Using more than one character means that you can have many more than 26 menu options!

A COUPLE OF LIMITATIONS

Once you get this sample batch file working, you'll discover a couple of limitations.

If you key in a wrong choice, the program will quit with the message "Label not found." I have not found a simple way to prevent this from happening.

Also, if you press only (F6) and (ENTER) at the "FM choice:" prompt, the program will keep asking for input. The best way out of this infinite loop is to take advantage of the first limitation: key in an incorrect response and you'll get dumped out of the program.

ENHANCEMENTS TO THE PROGRAM

  1. 1. Run it once -- If you want the FM.BAT program to run just one time and quit, rather than start over change the %0 in lines 48, 51, and 55 to GOTO Q.
  2. 2. Eliminate F6 (CRTL-Z) -- If you're like me, you may forget to press (F6) before pressing (ENTER) to terminate input. Nothing happens!

  3.  

     

You can eliminate this inconvenience by using another program (NANSI.SYS ) to redefine the ENTER key so that pressing it activates F6 and ENTER together. This is accomplished by the lines that were remarked out (lines 4 and 8 in PGM.BAT; lines 20, 22, 39 and 41 in FM.BAT). These pairs of command lines

echo {esc}[13;26;13p

echo {esc}[13;13p

are escape commands recognized by NANSI.SYS. The first line redefines the ENTER key (ASCII code 13) to F6 (CTRL-Z, ASCII code 26) and ENTER (ASCII code 13). The second line redefines the ENTER key as ENTER only.

For these two lines to work, you'll need to install NANSI.SYS by copying it to your C: drive and in MEMO adding the following line to your CONFIG.SYS file:

device=c:\nansi.sys

Once you have NANSI.SYS installed you will have to edit the batch file. Delete the double colons in lines 4 and 8 in PGM.BAT and lines 20, 22, 39 and 41 in FM.BAT. Then change the word "{esc}" in each line to ASCII character 27. (You can make this character in 100/200LX MEMO by pressing (<Shift>)-(Fn)-(ESC). You cannot create this character in MEMO on the 95LX, but you can make it with VDE by pressing (CTRL)-(P) (ESC). It will be displayed as an arrow, .

I recommend using NANSI.SYS (3K bytes) instead of ANSI.SYS (9K bytes, DOS 5.0 version). ANSI.SYS may cause problems with the display in both Palmtops. NANSI.SYS is freeware that does not come with a documentation file. Refer to any good DOS book on how to use ANSI.SYS.

Until next time, Happy Programming!

iPhone Life magazine


Notice about Palmtop.net
The Palmtop Network with its S.U.P.E.R. (Simply Unbeatable Palmtop Essentials Repository) software is now available under the domain name of hp200lx.net.  

 
We Buy
We buy used palmtops, working or broken: HP 200LX, HP 100LX and 1000CX.
 

Copyright 2010 Thaddeus Computing Inc