MaxZ80 - Chapter 12

I'd like to tie up a few loose ends before getting into shells, our new
topic.

The link script for SKUNK (see the previous Chapter) includes CMD. If SKUNK
is run under CP/M, it displays:

A1>SKUNK
If not ZCPR3 version ZCPR33+ you must use Z3INS
ZCPR33+ was not found.
Strike Any Key ...
Usage: SKUNK {/}o
o may be K or R, for Kaypro or Royal

Since we can't get the Terminal Capabilities from a Z-System environment, we
need to tell it some computer name so it can use the cursor positioning
strings that are hard-coded in SKUNK for that computer. To be able to grab
the K or the R above, we need CMD.

CMD is used in the current version of LEE (see Chapters 1 and 2) as well. Its
usage display

Usage : LEE11H [[I=input file] [O=output file] [P=prefix]] or
        LEE11H no command tail to be prompted

shows that it can get input, output and prefix values from the command tail.
CMD does the needed work. The line CALL CMD(COMMAND$) is followed by a few
lines that parse what COMMAND$ contains. A DOS version has the CALL(COMMAND$)
line commented out. This is because the DOS compiler supports the keyword
COMMAND$ which holds what you enter at the terminal.

On to shells! Shells are programs that sit "on top of" the command prompt and
provide a new look and feel to your screen. In the case of LSH, the Log
Shell, the change is subtle. In the case of MENU, the change is dramatic.
Shells let you run programs and when they are done, the shell program is
automatically reloaded. Z-System lets you have up to four shells. The names
of the shell programs and the data files these shells use are stored in a
"shell stack." The address of this stack is kept in the environment segment.
This address is at offset 1E hex, just past the self-reference environment
descriptor address, which is at offset 1B hex.

;
; Offset 1Bh - Environment descriptor
;
Z3ENV:  DW      0F600H  ; Load address of this file
Z3ENVS: DB      2       ; Size in records (including Z3TCAP)
;
; Offset 1Eh - Shell stack
;
SHSTK:  DW      0F580H  ; Address
SHSTKS: DB      4       ; Number of shell stack entries
SHSIZE: DB      32      ; Entry size in bytes

The SHOW utility may be run to tell you what you've got in your shell stack.
SHOW tells you many things but if you invoke it with menu choice S (for
Shell) you'll see something like this:

                         >>>> SHOW Version 1.4 <<<<

                               Shell Stack Data


    Element 1  Command line: MENU     A04:MENU.MNU
      4D 45 4E 55  20 20 20 20  20 41 30 34  3A 4D 45 4E | MENU     A04:MEN
      55 2E 4D 4E  55 00 20 20  20 56 41 52  01 67 00 46 | U.MNU.   VAR.g.F

    Element 2  Command line: A1:LSH
      41 31 3A 4C  53 48 20 20  20 20 20 00  00 15 20 00 | A1:LSH     ... .
      01 4C 53 48  20 20 20 20  20 56 41 52  01 67 00 46 | .LSH     VAR.g.F

    Element 3  NOT USED
      00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00 | ................
      00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00 | ................

    Element 4  NOT USED
      00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00 | ................
      00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00 | ................


    SHOW Command:

In this example, we are running two shells. MENU is the active shell, and LSH
is waiting for us to exit MENU, at which time MENU will get popped off the
stack and LSH will be what's left on the stack (and will become active).
Let's take a look now at what our screen looks like. To get this screen, I
was in A4: and typed

MENU

                           Menu 1

              Show me a [D]irectory of the files on this drive

                      [N]ame file #1 (currently)  LEE11H.BAS
                      [E]dit file #1
                      [V]iew file #1


                      Run [F]ATCAT cataloguer
                      [H]elp System

                      Think of an [A]nimal
                      Play Quatris (like Tetris)

                      Issue [Z]-System command


                Press ^C to exit MENU


A4:BASIC> (CR=Menu, ^C=Z3, >=Next Menu) Command?

MENU, if given no command tail, looks for a file named MENU.MNU on the
current drive and if it doesn't find it, looks along the search path.

The old command prompt is gone and is replaced by a full screen, "pick and
run" front end. If you type D, for example, you'll get a Directory of the
files on A4:. There'll be a Strike Any Key message after the DIR command (for
that is what the D choice actually runs, see below) is done, giving you a
chance to look at the results. As soon as you hit Enter, or any other key,
MENU will reload and you'll be back to the original screen. MENU.MNU files
are text files that have a well-defined structure. They usually start with a
line like

-dx

(to be explained shortly)

and then there's a series of one or more pairs of sections that look like so

#

text that controls what the screen looks like

#

a series of lines that look like

character definition of the command(s) to run if this character is typed

and finally,

##

For example, the definition of the command to run if D is typed is

d !dir

The leading ! is the way you say you want that Strike Any Key feature.

The leading line in the .MNU file is a "global options" line and in our
example, the dx means, yes, I want the menu to Display and I also want to
permit eXiting the menu system with a Ctrl-C. You may override this global
option in any menu by putting an x immediately after the # that precedes the
displayed text section for that menu.

The prompt line at the bottom of the menu says the > key will get you to
another menu page. If you type >, this is what you'll see:

                     Menu 2

             System file 1 : LEE11H.BAS   System file 2 : ALIAS.CMD
             System file 3 : .   System file 4 : .

                      ~ or ` - Scroll files

                      E. EDIT LEE11H.BAS with ZDE

                      D. DOS directory
                      M. MBASIC
                      B. BASCOM =LEE11H/o/e
                      L. L80 z3hdr,cmd,LEE11H,LEE11H/n/e
                      S. Establish System file n
                      P. EXPORT LEE11H.BAS

                      Z. Issue Z-System command


A4:BASIC> (CR=Menu, ^C=Z3, *=1st Menu, <=Prev Menu) Command?