home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / ZCNFG21.LBR / ZCNFG.ZZ0 / ZCNFG.Z8°
Text File  |  1991-11-05  |  73KB  |  2,632 lines

  1. ;Program name: ZCNFG
  2.  
  3. ;ZCNFG is copyright by A. E. Hawley January, 1988.
  4. ;It may be freely distributed, but it must not be sold 
  5. ;either separately or as part of a package without the 
  6. ;written consent of the author.
  7. ;The author may be reached via electronic mail at the 
  8. ;Ladera Znode (Znode 2) in Los Angeles, 213-670-9465
  9.  
  10. ;ZCNFG is released for distribution through the Z-system 
  11. ;users group, ZSIG. Many Znodes include ZSIG releases
  12. ;among their programs available for download.
  13. ;Several such nodes are:
  14. ;    Znode 3,  Newton Centre, MA    617-965-7259
  15. ;    Znode 32  S.Plainfield, NJ    908-754-9067
  16. ;    Znode 45  Houston, TX        713-937-8886
  17.  
  18. ;See ZCNFG.HST for previous version data and changes.
  19.  
  20. VERS    EQU    2
  21. REV    EQU    1
  22. ;version date
  23. MONTH    EQU    11
  24. DAY    EQU    01
  25. YEAR    EQU    91
  26.  
  27. ;Program Function:
  28. ;General purpose configuration program. Loads the first block
  29. ;of program code, displays current option values, accepts
  30. ;interactive user option selections, overwrites the program
  31. ;block to make the changes permanent. A configuration data
  32. ;file for the target program must be available for loading by
  33. ;ZCNFG to provide MENU and HELP screens. See ZCNFG.HLP, ZCFG.HLP,
  34. ;ZCNFGMDL.Z80, ZCNFGOVL.DOC, and ZCNFGCFG.LBR.
  35.  
  36. ;ASSEMBLY & LINK with ZMAC/ZML
  37. ;    ZMAC ZCNFG;ZMAC CFGSUBS
  38. ;    ZML ZCNFG,CFGSUBS
  39. ;link note: .request statements in ZCNFG cause the
  40. ; following REL libraries to be appended to the link
  41. ; list:        CFGLIB/, VLIB/, Z3LIB/, SYSLIB/
  42. ;If you are using a linker which does not support the
  43. ;.request statement, you must include these files in
  44. ;the link list as libraries to search in the above order.
  45.  
  46. ;References in CFGSUBS
  47.     EXT    B2BCD,CLSFIL,CIN,COUT,DEF_FT,DEF_DU
  48.     EXT    DEF_FN,OPNFIL,ISTXTF,ISFNC
  49.     EXT    RANGE,RDFILE,RDREC,STORDT,STRCPY
  50.     EXT    TYPLIN,WRREC,VCOUT,MOVE2Z,SKIP2Z
  51.  
  52. ;References in CFGLIB
  53.     .REQUEST CFGLIB
  54.     EXT    DUSCN,FILL,FNAME,INIFCB,MPY16,NTSPCS,PKGOFF
  55.     EXT    PUTZDU,PUTZFN,PUTZFS,RJIP,SDELM,SKSP,UCASE
  56.  
  57. ;from VLIB
  58.     .REQUEST VLIB
  59.     EXT    CLS,Z3VINIT,TINIT,DINIT,AT
  60.  
  61. ;from Z3LIB
  62.     .REQUEST Z3LIB
  63.     EXT    GETCRT,GETEFCB
  64.  
  65. ;from SYSLIB
  66.     .REQUEST SYSLIB
  67.     EXT    BBLINE,MA2HC,MADC,MAFDC,MHL4HC,MHLDC
  68.     EXT    PA2HC,PHL4HC,PHLFDC,ISPRINT,ISALNUM
  69.     EXT    RETUD,LOGUD,LUINIT,LUOPEN,LUREAD
  70.     EXT    SETDMA,COMPB,@FNCMP
  71.     EXT    ISDIGIT,EVAL10,EVAL16
  72.  
  73. ;For use by other modules
  74.     PUBLIC    Z3ENV,DEFDU,COLCNT,ROWCNT,QUIT
  75.     PUBLIC    UCFLAG
  76.  
  77. ;For use by the linker
  78.     PUBLIC    $MEMRY
  79.  
  80. ;For use during debug
  81.     public begin,signon,init,help,quit,pgmini,badfil
  82.     public filinit,exit,assist,menlst
  83.     public simage,castbl,hlpscr,offset,cfgd,s_addr,s_list
  84.     public ctsrch,ctlcs0,hlpmsg,stack
  85.     public mnuhlp,sndhlp,sndh_1,ps_eos
  86.     public gt_cfg,ovrlay,scr_ld,scr_l0
  87.     public tgtcfg,namchk,ovlusr,ovlfcb,ovlfn
  88.     public testid,TGTUSR,tgtbuf,tgtfcb,tmpusr,tmpfcb
  89.     public gotolm,gotonm,ldmenl,reloce,mnadj,mnumb,lmnumb
  90.     public in_fn0,in_fn1,in_fn2,in_fn3,in_fn4
  91.     public in_fn5,infn5,in_fn6,in_fn7,in_fn8
  92.     public ld_fn0,ld_fn1,ldfn1,ld_fn2,ld_fn3,ld_fn4
  93.     public ld_fn5,ld_fn6,ld_fn7,ld_fn8
  94.     public lud,ludfil,ludfcb,ludfn,lbrini
  95.     public xltadu,xlt1,xlt2,xlt3,xlt4,xlterr
  96.     public in_fn9,hotkey,hotmsg,ld_fn9,ldfn9,xascii
  97.     public deldat,spcdat,chrdat,ctldat
  98.  
  99. ;define program constants and data locations
  100.  
  101. ;----------------------
  102. ;system addresses
  103. FCB    EQU    5CH
  104. TBUF    EQU    80H        ;SYSTEM BUFFER
  105. CREC    EQU    20H        ;offset to Current Record in an FCB
  106.  
  107. ;----------------------
  108. ;offsets in the first page of the target program.
  109. ;A 256-byte page is read in from the program to a
  110. ;buffer which starts at TGTBUF:.
  111.  
  112. Z3MOFF    EQU    03H        ;'Z3ENV' identifies ZCPR3x Utility
  113. ENVTYP    EQU    08H        ;Z3 environment type byte
  114. Z3EOFF    EQU    09H        ;Z3 environment address
  115. FIDOFF    EQU    0DH        ;program identifier, like 'ZCNFG'
  116. ;Target program-specific offsets are defined in the programs
  117. ;overlay file.
  118.  
  119. IDLEN    EQU    5    ;length of 'Z3ENV' string (NOT an offset)
  120.  
  121. ;----------------------
  122. ;ASCII definitions
  123. CTLC    EQU    3
  124. BS    EQU    8        ;backspace
  125. HT    EQU    9        ;horizontal tab
  126. LF    EQU    10        ;line feed
  127. CR    EQU    13        ;carriage return
  128. ESC    EQU    1BH        ;escape key char
  129. SPC    EQU    20H        ;space char
  130. DEL    EQU    7FH        ;DEL char
  131. DIM    EQU    1        ;highlight on
  132. BRIGHT    EQU    2        ;highlight off
  133.  
  134. ;----------------------
  135. ;    MACROS
  136.  
  137. ;load bc indirect at hl
  138. LDBCHL    MACRO
  139.     LD    C,(HL)
  140.     INC    HL
  141.     LD    B,(HL)
  142.     INC    HL
  143.     ENDM
  144.  
  145. ;load de indirect at hl
  146. LDDEHL    MACRO
  147.     LD    E,(HL)
  148.     INC    HL
  149.     LD    D,(HL)
  150.     INC    HL
  151.     ENDM
  152.  
  153. ;load hl indirect at hl
  154. LDHLHL    MACRO
  155.     LD    A,(HL)
  156.     INC    HL
  157.     LD    H,(HL)
  158.     LD    L,A
  159.     ENDM
  160.  
  161.     .SBTTL MAIN ROUTINE
  162.     PAGE
  163. ;=========================================================
  164. ;    START OF PROGRAM CODE
  165. ;=========================================================
  166.  
  167. ZCNFG:    JP    BEGIN
  168. Z3MARK:    DB    'Z3ENV'        ;identifies program as ZCPR3x utility
  169.     DB    1        ;external environment
  170. Z3ENV:    DW    0        ;this address set by Z3INS or ZCPR33/4
  171.     DW    ZCNFG        ;compatible with type 4 enviroment
  172. ;configuration block for THIS program. ZCNFG can
  173. ;alter is own default parameters.
  174. CNFGID:    DB    'ZCNFG'        ;ID string, null terminated
  175.     DB    VERS+'0',REV+'0'
  176.     DS    2,0        ;total: 8 bytes + null terminator
  177.                 ; plus $ or null terminator
  178. VSNSTR:    DS    3        ;room for 3 ascii digit version number
  179. ALTUSR:    DB    -1        ;-1 = search default user
  180. ALTDRV:    DB    -1        ;-1 = search default drive
  181.  
  182. TGTTYP:    DB    'COM'        ;default tgt file type
  183. OVLTYP:    DB    'CFG'        ;default configuration data file type
  184.  
  185. SCRNLN:    DB    24        ;lines per screen
  186. Z3INST:    DB    0        ;install z3env in target if true
  187.  
  188. CLBRFN:    DB    'CONFIG  '    ;CFG library NAME
  189. CLBRFT:    DB    'LBR'        ;..and TYPE
  190. ZCOPT0:    DB    0FFh        ;default is target file DU if FALSE
  191.                 ;..and logged DU if TRUE
  192.  
  193. ;=========================================================
  194. ;not part of the configuration block.
  195.  
  196.     DSEG
  197.  
  198. VSNDAT:    DS    3        ;month,day,year - packed bcd
  199.  
  200. TIMSTR:    DS    6,0FFH        ;room for standard date/time,
  201.                 ;yy mm dd hr min sec
  202.  
  203. ;=========================================================
  204.  
  205.     CSEG
  206.  
  207. BEGIN:    LD    (STACK),SP    ;save system stack pointer
  208.     LD    SP,STACK    ;set up local stack
  209.     CALL    INIT        ;set current du, Test for Z3
  210.     LD    DE,SIGNON
  211.     CALL    TYPLIN
  212.     CALL    HELP        ;provide help if requested & quit
  213.     CALL    PGMINI        ;Get file spec from FCB, open file
  214.                 ;abort with message if bad file spec
  215.     CALL    FILINIT        ;identify & load the overlay file
  216.     CALL    SCR_LD        ;load screen image(s)
  217.     JP    C,BADCFG    ;first byte not RST 0 or RET
  218.  
  219. ;select & set options interactively
  220. ;display the screen and the user prompt
  221. ;This is a loop whose exit is one of the cases
  222. SETOPT:    CALL    Z3CLS        ;clear screen
  223.     LD    DE,(SIMAGE)    ;-> screen image
  224.     CALL    TYPLIN        ;display the screen
  225. DOPRMT:    LD    A,(Z3MSGF)
  226.     OR    A
  227.     JR    Z,NOT1Z3
  228.     CALL    AT
  229. ATPRPT:    DB    19,1        ;prompt near screen bottom
  230. NOT1Z3:    LD    DE,PRMPT0    ;-> prompt line(s)
  231.     CALL    TYPLIN
  232.  
  233. ;get user input. Make changes as requested, update the
  234. ;screen image and the configuration block.
  235. GETINP:    CALL    CIN        ;wait for & get user input
  236.     JR    Z,GETINP    ;z = no input yet
  237.     CALL    UCASE        ;make upper case
  238.     CALL    ISPRINT        ;printable character?
  239.     CALL    Z,COUT        ;echo it if so
  240.     LD    HL,(CASTBL)    ;->case table
  241.     CALL    MCASE        ;do case, ret to here if no exit
  242.     JR    NC,SETOPT    ;redisplay screen & prompt after update
  243. ;erase the prompt line
  244.     LD    A,CR
  245.     CALL    COUT
  246.     LD    B,75
  247. ..ERA:    LD    A,SPC
  248.     CALL    COUT
  249.     DJNZ    ..ERA
  250.     LD    A,CR
  251.     CALL    COUT
  252.     JR    DOPRMT        ;get a new prompt
  253.  
  254.     .SBTTL MENU MANAGEMENT
  255.     PAGE
  256. ;=========================================================
  257. ;    MENU MANAGEMENT
  258. ;=========================================================
  259.  
  260.     DSEG
  261. menlst:
  262. ;data which defines the current menu environment
  263. ;used by setopt. Changed by menu commands.
  264. ;Loaded initially by pgmini routine.
  265.  
  266. LASTM:    DS    2        ;->previous menu list
  267. NEXTM:    DS    2        ;->next menu list
  268. SIMAGE:    DS    2        ;->screen image
  269. CASTBL:    DS    2        ;->case table
  270. HLPSCR:    DS    2        ;->help screen
  271. EMENLST:        ;for calc list length
  272.  
  273. ;MENU Environments - lastm,nextm,simage,castbl,hlpscr
  274. ;An instance of this 10 byte data structure occurs in
  275. ;in the overlay for each menu data item. The objects
  276. ;addressed are all located in the overlay. There is an
  277. ;overlay for each configuration target (like ZFILER, e.g.)
  278.  
  279. ;=========================================================
  280.  
  281. ;standard data block holds parameters for the current
  282. ;menu item. This data is copied from the case table
  283. ;and relocated each time a menu item is selected.
  284.  
  285. OFFSET:    DS    2        ;->config block data to modify
  286. CFGD:    DS    1        ;data used by function routine
  287. S_ADDR:    DS    2        ;->screen location for this menu item
  288. S_LIST:    DS    2        ;->data structure (alt. screen data, e.g)
  289.  
  290. ;=========================================================
  291.  
  292.     CSEG
  293.  
  294. ;Table of function routines accessed via MCASE, MAPPER
  295. ;The function# is an entry in every record of the case table.
  296. ;The init entry points are indirectly referenced through
  297. ;their positional relation to the update entries.
  298.  
  299. ;        update    init    function#, name, & use
  300. FNTBLE:
  301.     DW    IN_FN0,    LD_FN0    ;0 switch, toggle a bit in a byte
  302.     DW    IN_FN1,    LD_FN1    ;1 text,   change text string, length n
  303.     DW    IN_FN2,    LD_FN2    ;2 duspec, change default drive/user
  304.     DW    IN_FN3,    LD_FN3    ;3 hexrad, change a byte or word,
  305.                 ; HEX radix
  306.     DW    IN_FN4,    LD_FN4    ;4 decrad, change a byte or word,
  307.                 ; DECimal radix
  308.     DW    IN_FN5,    LD_FN5    ;5 textlc, change text, LCase OK, length n
  309.     DW    IN_FN6, LD_FN6    ;6 filesp, change all or part
  310.                 ; of Z3-filespec
  311.     DW    IN_FN7,    LD_FN7    ;7 togl3,  toggle among 001B, 010B, 100B
  312.     DW    IN_FN8,    LD_FN8    ;8 togltf, toggle a byte true/false (-1/0)
  313.     DW    IN_FN9,    LD_FN9    ;9 asciic, change ascii byte from keyboard
  314. FNTBLX:        ;used for error checking on function # range
  315.                       
  316. ;=========================================================
  317.     PAGE
  318.  
  319. MCASE:
  320. ;searches a case table for a match with the byte in A
  321. ;If found, jumps to the associated function routine.
  322. ;if not found, searches the built-in menu/control case
  323. ;table, the last entry for which is a default routine which
  324. ;is unconditionally executed for an unrecognized command.
  325.  
  326. ;The case table structure is
  327. ;    db    n    ;n = number of entries in list
  328. ;    db    m    ;m = number of bytes per rcrd
  329. ;there are n records in the case table in addition to the default
  330. ;rcrd:    db    <srch char>
  331. ;    ds    2    ;target address for routine to execute
  332. ;    ds    m-3    ;data bytes passed to the routine
  333.  
  334. ;entry-
  335. ;    A  = char to match for case selection
  336. ;    HL -> 'case' table
  337. ;Jump to Target routine with
  338. ;    HL -> parameter list (if any)
  339. ;    DE = Number of bytes in parm list
  340. ;    BC = Target routine address
  341.  
  342.     CALL    CTSRCH        ;search the case table for identifier
  343.     JR    NC,RFND        ;jump if found,
  344.     LD    HL,CTLCS0    ;..else -> built in command table
  345.     CALL    CTSRCH        ;search for control command
  346. RFND:    INC    HL        ;->target address
  347.     DEC    DE        ;bytes remaining
  348.     LD    C,(HL)
  349.     INC    HL
  350.     DEC    DE        ;bytes remaining
  351.     LD    B,(HL)        ;bc contains target routine addr
  352.     INC    HL        ;->balance of parameter list
  353.     INC    B
  354.     DEC    B        ;if high byte is 0, this is a
  355.     CALL    Z,FNXLT        ;function number to translate
  356.     PUSH    BC        ;target address on stack
  357. ;if e=0, then there are no parameters, so avoid
  358. ;the parameter block load in that case.
  359.     DEC    E        ;bytes left in record (parameters)
  360.     RET    Z        ;really a jump to (BC)
  361. ;transfer case parameters to standard parameter block
  362.     PUSH    HL
  363.     PUSH    DE
  364.     LD    B,D
  365.     LD    C,E
  366.     LD    DE,OFFSET
  367.     LDIR
  368.     CALL    RELOC        ;add tgtbuf to offset, reloc addresses
  369.     POP    DE        ;do these need to be preserved????????
  370.     POP    HL
  371.     RET            ;jump to service routine
  372. ;=========================================================
  373.     PAGE
  374. ;=========================================================
  375.  
  376. ;search a case table for a match with the character
  377. ;in A. Return HL-> entry if found, and CY reset.
  378. ;If NOT found, HL-> NEXT entry and CY is SET. The
  379. ;last table searched must be followed with a record
  380. ;indicating the routine to execute as a default. In
  381. ;the present case, that routine is BADCMD.
  382. CTSRCH:    LD    B,(HL)        ;number of entries in table
  383.     INC    HL
  384.     LD    E,(HL)        ;entry length in de (>=2)
  385.     INC    HL        ;->first record
  386.     LD    D,0
  387.     LD    C,A
  388. TSLOOP:    LD    A,(HL)        ;is this the desired record?
  389.     CALL    UCASE
  390.     CP    C
  391.     RET    Z        ;..ret NC if so
  392.     ADD    HL,DE        ;->next record
  393.     DJNZ    TSLOOP        ;repeat up to B times
  394.     LD    A,C        ;recover search char
  395. CRNTRY:    SCF            ;nothing found if CY set
  396.     RET            ;hl -> addr AFTER last table entry
  397.  
  398. ;--------------------------------------------
  399.  
  400. ;Indexing routine to convert function numbers
  401. ;to subroutine addresses for MCASE and MAPPER
  402. ;MCASE uses the first address in each table entry,
  403. ;MAPPER uses the second for screen initialization.
  404.  
  405. ;entry-
  406. ;    BC = function number
  407. ;exit-
  408. ;    HL, DE are preserved
  409. ;    BC = routine address
  410.  
  411. FNXLTI:    PUSH    HL        ;entry for MAPPER
  412.     LD    HL,(FNTBLX-FNTBLE)/4 - 1
  413.     OR    A
  414.     SBC    HL,BC        ;function # out of range?
  415.     JP    C,BADOVL    ;oops, if so. CFG file error.
  416.  
  417.     LD    HL,FNTBLE+2    ;use second addr for init
  418.     JR    FNXLT0
  419.  
  420. FNXLT:    PUSH    HL        ;entry for MCASE
  421.     LD    HL,FNTBLE    ;uses first address
  422. FNXLT0:    ADD    HL,BC        ;index to proper function addr
  423.     ADD    HL,BC        ;..4 bytes per function
  424.     ADD    HL,BC
  425.     ADD    HL,BC
  426.     LD    C,(HL)
  427.     INC    HL
  428.     LD    B,(HL)        ;routine addr in BC
  429.     POP    HL
  430.     RET
  431.  
  432. ;--------------------------------------------
  433.  
  434. ;relocate data as required in the standard
  435. ;data block starting at OFFSET
  436. ;called by MCASE and MAPPER after the block
  437. ;is loaded from the case table.
  438.  
  439. RELOC:    LD    HL,(OFFSET)
  440. ;if (offset) > 0ffh then we are outside the configuration
  441. ;block. This must be an erroneous value in the CFG file.
  442.     LD    A,(NCRECS)
  443.     DEC    A
  444.     LD    BC,0        ;for 2 rcrd cfg block
  445.     JR    NZ,RELOC1
  446.     LD    BC,80H        ;for 1 rcrd file size!
  447. RELOC1:    LD    HL,(OFFSET)
  448.     ADD    HL,BC
  449.     INC    H
  450.     DEC    H        ;..in H if offset >0ffh
  451.     JP    NZ,BADOVL
  452.     SBC    HL,BC        ;recover (offset)
  453.  
  454.     LD    BC,TGTBUF
  455.     ADD    HL,BC
  456.     LD    (OFFSET),HL
  457. ;after target pgm data is present as overlay,
  458. ;relocate address data at s_addr, s_list.
  459.     LD    DE,(RELOCC)    ;relocation constant
  460.     LD    HL,(S_ADDR)
  461.     ADD    HL,DE
  462.     LD    (S_ADDR),HL
  463.     LD    HL,(S_LIST)
  464.     LD    A,H
  465.     OR    L
  466.     RET    Z        ;don't relocate 0
  467.     ADD    HL,DE
  468.     LD    (S_LIST),HL
  469.     RET
  470.  
  471. ;=========================================================
  472.  
  473.     .SBTTL CONTROL ROUTINES
  474.     PAGE
  475. ;=========================================================
  476. ;  CONTROL ROUTINES EXECUTED FROM MCASE CALLS
  477. ;=========================================================
  478.  
  479. GOTOLM:            ;get previous menu
  480.     LD    HL,(LASTM)
  481.     LD    E,-1    ;decrement menu number
  482.     CALL    MNADJ    ;track the menu number
  483.     JR    LDMENL
  484.  
  485. GOTONM:            ;Get next menu
  486.     LD    HL,(NEXTM)
  487.     LD    E,1    ;increment menu number
  488.     CALL    MNADJ    ;track the menu number
  489.  
  490. ;load the new menu descriptor at (HL)
  491. LDMENL:    LD    DE,MENLST
  492.     LD    BC,EMENLST-MENLST
  493.     LDIR
  494. ;relocate the words in menlst
  495.     LD    B,(EMENLST-MENLST)/2
  496.     LD    DE,(RELOCC)
  497.     DI            ;interupts could mess up data area!
  498.     LD    (RELOCE+1),SP
  499.     LD    SP,MENLST
  500.  
  501. RELOCL:    POP    HL        ;get an address
  502.     ADD    HL,DE        ;relocate
  503.     PUSH    HL        ;put it back
  504.     INC    SP
  505.     INC    SP        ;move to next one
  506.     DJNZ    RELOCL
  507.  
  508. RELOCE:    LD    SP,0        ;filled in above
  509.     EI            ;allow interupts again
  510.     RET
  511.  
  512. MNADJ:    LD    A,(LMNUMB)
  513.     LD    D,A
  514.     LD    A,(MNUMB)
  515.     ADD    E        ;inc or dec, depending on E
  516.     CP    -1        ;going from menu0 to last menu?
  517.     JR    Z,SETLMN
  518.     CP    D        ;going from last menu to menu0?
  519.     JR    Z,MNADJX    ;no, if z
  520.     JR    C,MNADJX    ;no, if c
  521.     LD    D,0        ;..else yes, set menu0
  522. SETLMN:    LD    A,D        ;d contains next menu number
  523. MNADJX:    LD    (MNUMB),A    ;new current menu number
  524.     RET
  525.  
  526. ;these are initialized at scr_ld
  527. MNUMB:    DS    1        ;current menu number, for error reports
  528. LMNUMB:    DS    1        ;last menu number (first is 0)
  529.  
  530. ;=========================================================
  531.  
  532. BADCMD:
  533. ;This is the default routine when mcase cannot
  534. ;find the command letter in its case table or
  535. ;in the built-in menu/control case table.
  536.  
  537.     LD    DE,BADMSG
  538.     CALL    TYPLIN
  539.     POP    HL        ;dump return addr
  540.     JP    GETINP        ;get new input
  541.  
  542. ;=========================================================
  543.  
  544. ;Normal exit after changes are made and need to be
  545. ;saved. Assumes that tgtbuf has been updated before 
  546. ;writing the first block back to the file.
  547.  
  548. EXIT:    LD    A,(Z3INST)
  549.     OR    A        ;allow Z3 installation?
  550.     JR    Z,EXIT1        ;no, if logical false
  551.     LD    HL,(Z3ENV)    ;install current ENV address
  552.     LD    (TGTBUF+Z3EOFF),HL
  553.  
  554. EXIT1:    LD    A,(FCB_CR)    ;set current record for writing
  555.     LD    (TGTFCB+CREC),A    ;back the configuration block
  556.     LD    HL,TGTBUF
  557.     CALL    SETDMA
  558.     LD    DE,TGTFCB    ;fcb pointer
  559.     CALL    WRREC
  560.     LD    HL,TGTBUF+80H
  561.     CALL    SETDMA
  562.     LD    A,(NCRECS)    ;length of config block, records
  563.     DEC    A
  564.     CALL    NZ,WRREC    ;write second record if present
  565.     CALL    CLSFIL        ;close the file
  566.     CALL    Z3CLS        ;clear the screen
  567.  
  568. ;=========================================================
  569.  
  570. QUIT:
  571. ;Here to exit without saving current changes. This is
  572. ;effectively an abort. Assumes that the saved stack pointer
  573. ;points to a safe execution address. This is the case when
  574. ;the program is executed as a normal .com file.
  575.     LD    A,(Z3MSGF)
  576.     OR    A
  577.     CALL    NZ,DINIT    ;deinit terminal
  578.     LD    SP,(STACK)
  579.     RET
  580.  
  581. ;=========================================================
  582.  
  583. CMDHLP:
  584. ;Display the internal command information screen.
  585.     CALL    Z3CLS        ;Start with clean screen
  586.     LD    HL,CMDMSG
  587.     JR    SNDH_3
  588.  
  589. ;=========================================================
  590.  
  591. MNUHLP:
  592. ;Display the information screen in response to '/'
  593. ;entered at the menu level.
  594.  
  595.     LD    DE,(HLPSCR)
  596.     LD    HL,(RELOCC)
  597.     OR    A        ;reset cy
  598.     SBC    HL,DE        ;a zero entry?
  599.     EX    DE,HL        ;hlpscr in hl
  600.     RET    Z        ;ret if help screen not there.
  601.  
  602.     CALL    Z3CLS        ;clear screen if possible
  603.  
  604. SNDHLP:
  605. ;send text to the screen with prompted pageing
  606. ;entry- HL-> null terminated message
  607.  
  608.     LD    A,(HL)
  609.     CP    ':'
  610.     JR    NZ,SNDH_3
  611.     INC    HL        ;ignore leading colon
  612.     JR    SNDH_3        ;at start of the block
  613.  
  614. ;sndh_1 sends a line of text, starting a
  615. ;new screen page if the first char is a
  616. ;colon or formfeed, or if the screen is full.
  617. SNDH_1:    LD    A,(HL)
  618.     INC    HL        ;ready for next
  619.     CALL    C,NEWPAGE    ;new screen required?
  620.     JR    C,SNDH_2    ;yes, if Cy set
  621.     OR    A        ;if terminator,
  622.     JR    Z,PS_EOS    ;..then quit
  623.     CALL    VCOUT        ;else send the byte
  624.     CP    LF
  625.     JR    NZ,SNDH_1    ;continue if not lf
  626.     SCF            ;show LF sent
  627.     DJNZ    SNDH_1        ;else count & continue if not eos
  628.  
  629. SNDH_2:    CALL    PS_EOS        ;pause at End Of Screen
  630.     CP    CTLC        ;control-c?
  631.     RET    Z        ;abort help if so
  632.  
  633. SNDH_3:    LD    A,(SCRNLN)    ;lines per screen
  634.     SUB    2        ;allow for prompt line
  635.     LD    B,A
  636.     JR    SNDH_1        ;do another screen until 0
  637.  
  638. PS_EOS:    LD    A,(Z3MSGF)
  639.     OR    A
  640.     JR    Z,HPAUSE    ;skip screen stuff if not Z3
  641.     CALL    AT        ;position cursor
  642. HLPAT:    DB    24,1        ;row,column (home=1,1)
  643.  
  644. HPAUSE:    LD    DE,PSEMSG    ;'SAK' message + CR
  645.     CALL    TYPLIN        ;send it
  646. HPAUSL:    CALL    CIN        ;wait for, get any char
  647.     JR    Z,HPAUSL    ;z = no char yet
  648.  
  649. Z3CLS:    PUSH    AF        ;save the char for caller
  650.     PUSH    HL        ;preserve source pointer
  651.     LD    A,(Z3MSGF)
  652.     OR    A
  653.     CALL    NZ,CLS        ;home & clear scren
  654.     LD    HL,ROWCNT
  655.     LD    (HL),0        ;reseet line counter
  656.     POP    HL
  657.     POP    AF
  658.     OR    A        ;clear flags
  659.     RET
  660.  
  661. NEWPAGE:
  662.     CP    ':'        ;leading colon?
  663.     JR    Z,NEWP_2    ;new page if so
  664.     CP    'L'-'@'        ;formfeed?
  665.     JR    Z,NEWP_2    ;new page if so
  666.     OR    A        ;reset carry
  667.     RET            ;NOT a new page
  668.  
  669. NEWP_2:    LD    A,(Z3MSGF)
  670.     OR    A        ;using ZCPR3?
  671.     SCF
  672.     RET    NZ        ;yes, cursor will be positioned,
  673.     LD    A,LF        ;else scroll to bottom of screen
  674. NEWP_3:    CALL    VCOUT
  675.     DJNZ    NEWP_3
  676.     SCF            ;signal for prompt
  677.     RET
  678.  
  679. ;=========================================================
  680.  
  681.     .SBTTL USER FUNCTION ROUTINES
  682.     PAGE
  683. ;=========================================================
  684. ;  FUNCTION ROUTINES EXECUTED FROM MCASE & MAPPER
  685. ;=========================================================
  686.  
  687. ;    FUNCTION 0 - TOGGLE A SINGLE BIT MAPPED OPTION
  688.  
  689. IN_FN0:
  690. ;toggles the bit defined by (cfgd) in the byte
  691. ;at (offset), then toggles the screen image at
  692. ;(s_addr) using the two member list at (s_list)
  693.  
  694. ;entry-    HL -> parameter list
  695. ;exit-    all registers undefined
  696.  
  697.     LD    HL,(OFFSET)    ;config byte address
  698.     LD    A,(CFGD)    ;bit mask
  699.     LD    C,A        ;save bit mask in c
  700.     XOR    A,(HL)        ;toggle config byte into A
  701.     LD    (HL),A        ;and put it back
  702.     AND    C        ;isolate new bit value in A
  703.     JR    TOGL0
  704.  
  705. LD_FN0:                ;entry for initial screen load
  706. ;deposit one of two strings in the screen image,
  707. ;The choice of string is based on the value of
  708. ;the bit specified by the bit mask.
  709.  
  710.     LD    HL,(S_LIST)
  711.     LD    A,H
  712.     OR    L
  713.     JP    Z,BADOVL    ;error if no list
  714.  
  715.     LD    HL,(OFFSET)    ;config byte address
  716.     LD    A,(CFGD)    ;bit mask
  717.     AND    (HL)        ;isolate configuration bit
  718.  
  719. TOGL0:                ;shared with initialization
  720. ;on entry, A is zero except for one bit position
  721. ;which is significant. Z flag is set according to
  722. ;the contents of that bit.
  723.     LD    DE,(S_ADDR)
  724.     LD    HL,(S_LIST)    ;hl -> screen data pair
  725.     CALL    Z,SKIP2Z    ;skip first data element if false
  726.     JP    MOVE2Z        ;copy to screen image
  727.  
  728. ;=========================================================
  729.  
  730. ;    FUNCTION 1 - PROCESS ASCII STRING
  731.  
  732. IN_FN1:
  733. ;get (cfgd) characters from the console. Deposit them in
  734. ;the configuration block at (offset) and in the screen image
  735. ;at (s_addr). If the entry is null (only a CR), then
  736. ;nothing is done.
  737. ;user input is capitalized (LC is lost)
  738.     LD    A,1        ;specify caps 
  739.  
  740. INFN5:    LD    HL,ERRCTL    ;->error test level byte
  741.     OR    (HL)
  742.     AND    81H        ;use bits 0 & 7
  743.     LD    (UCFLAG),A    ;save HBS & caps flags
  744.     LD    A,(CFGD)    ;put field size in prompt
  745.     LD    DE,FTMSG1
  746.     CALL    MAFDC
  747.     LD    DE,FTMSG
  748.     CALL    TYPLIN        ;ask for new string
  749.  
  750.     LD    A,(UCFLAG)    ;caps/nocaps flag
  751.     RRA            ;propagate bit 0
  752.     SBC    A,A        ;  through all 8 bits of A
  753.     CALL    BBLINE        ;get user string, RET HL->string
  754.     OR    A        ;A=string length, incl spaces
  755.     SCF
  756.     RET    Z        ;ignore empty string
  757. ;if string is longer than field, truncate it
  758.     LD    C,A        ;actual str length, incl leading spc
  759.     LD    A,(CFGD)    ;Max length allowed
  760.     SUB    C
  761.     JR    NC,INFN51    ;NC = .LE. max len
  762.     ADD    C        ;recover max len
  763.     LD    C,A        ;truncate the string
  764.     XOR    A        ;0 unused space
  765. ;copy string from bbline buffer to cnfg block
  766. INFN51:    LD    B,A        ;trailing unused space
  767.     PUSH    BC
  768.     LD    DE,(OFFSET)
  769.     LD    B,C
  770. INFN52:    LD    A,(DE)        ;get dest byte
  771.     AND    1 SHL 7        ;preserve high bit
  772.     OR    (HL)        ;add in low 7 bits of ASCII
  773.     LD    (DE),A        ;update destination
  774.     INC    HL
  775.     INC    DE
  776.     DJNZ    INFN52
  777.     POP    BC        ;B=unused, C=string length
  778.  
  779.     LD    hl,(S_LIST)    ;get current string terminator
  780.     LD    A,H
  781.     OR    L
  782.     LD    A,(HL)        ;possible terminator
  783.     JR    NZ,NOTERM    ;no terminator if Z
  784.     LD    A,SPC        ;use default space fill
  785. NOTERM:    LD    H,A        ;save for istxtf
  786.     PUSH    BC
  787.     INC    B
  788.     DEC    B        ;any empty space in field?
  789.     CALL    NZ,FILL        ;fill remainder of field
  790.     POP    BC
  791. STERM:    LD    A,C
  792.     ADD    B
  793.     LD    B,A        ;field length in B, and
  794.     LD    A,H        ;fill/terminator byte
  795.     LD    HL,(OFFSET)
  796.     CALL    ISTXTF        ; setup BC,DE for LDTXT
  797.     JR    LDTXT        ;copy string from
  798.                 ; CFG block to screen
  799. ;-------------------------
  800.  
  801. ;Initial error check of string in CFG block.
  802. ;If no error, then copy string to screen image.
  803. ;CALLed from MAPPER
  804.  
  805. LD_FN1:    LD    A,1        ;FN 1 - string is all caps
  806.     JR    LDFN1
  807.  
  808. LD_FN5:    XOR    A        ;FN 5 - both UC and LC
  809.  
  810. LDFN1:    LD    HL,ERRCTL    ;->error test level byte
  811.     OR    (HL)
  812.     AND    81H        ;use bits 0 & 7
  813.     LD    (UCFLAG),A
  814.     LD    A,(CFGD)    ;MAX number of bytes
  815.     OR    A
  816.     JP    Z,BADOVL    ;0 length field must be an error
  817.     BIT    7,A
  818.     JP    NZ,BADOVL    ;>128 byte field must be error
  819.     LD    B,A
  820.  
  821.     LD    HL,(S_LIST)
  822.     LD    A,H
  823.     OR    L
  824.     LD    A,(HL)        ;possible string terminator
  825.     JR    NZ,LDFN2    ;NZ = actual terminator
  826.     LD    A,SPC        ; else use space as default
  827. LDFN2:    LD    HL,(OFFSET)    ;HL ->config data
  828. ;compute string length, test for illegal characters
  829.     CALL    ISTXTF
  830.     JP    C,BADOVL    ;C = ERROR, nonprinting char found
  831.  
  832. ;transfer a string of text from the
  833. ;configuration block to the screen image.
  834. ;entry-    HL -> string in CFG block
  835. ;     B = trailing unused bytes in string field
  836. ;     C = length of the string, incl leading spc
  837. ;     D = number of leading spaces
  838. ;     E = trailing fill byte (terminator)
  839.  
  840. LDTXT:    LD    DE,(S_ADDR)    ;DE ->screen location
  841.     INC    C
  842.     DEC    C
  843.     JR    Z,LDTXT2    ;don't try to move 0 len str!
  844.     PUSH    BC        ;save for fill after string
  845.     LD    B,0
  846.     LDIR            ;transfer string to screen
  847.     POP    BC
  848.  
  849. LDTXT2:    INC    B        ;trailing spaces
  850.     DEC    B
  851.     LD    A,SPC
  852.     CALL    NZ,FILL        ;trailing spaces fill screen field
  853.     RET
  854.     
  855. ;=========================================================
  856. ;    FUNCTION 2 - UPDATE A DU SPEC WITH ALTDU WILDCARD
  857.  
  858. IN_FN2:
  859. ; Transfer a DU spec from bbline input to screen image, left
  860. ; justified in a field of 3. Error if illegal DU.
  861. ; Nothing done for a null string entry.
  862.  
  863. ;get the new DU from the user
  864.     LD    DE,DUMSG    ;-> prompt msg
  865.     CALL    TYPLIN        ;send user prompt
  866.     LD    DE,DUMSG1    ;include '?' if 1-based drive code
  867.     LD    A,(CFGD)    ;get flag byte
  868.     OR    A        ;is it 1-based?
  869.     CALL    NZ,TYPLIN    ;if so, send '?' default msg
  870.     LD    DE,PRMPT1
  871.     CALL    TYPLIN        ;finish the prompt
  872.  
  873.     LD    A,-1        ;capitalize user input
  874.     CALL    BBLINE        ;get DU token from user
  875.     OR    A
  876.     SCF
  877.     RET    Z        ;do nothing if null entry
  878.     CALL    XLTADU        ;translate ascii to D,U in BC
  879.     RET    C
  880. ;transfer the new DU to the config block
  881.     LD    HL,(OFFSET)    ;->user/drive in config block
  882.     LD    (HL),C        ;store User
  883.     INC    HL
  884.     LD    (HL),B        ;..and the Drive
  885.     DEC    HL        ;recover pointer
  886.     JR    LDFN2A
  887.  
  888. LD_FN2:
  889. ;get the alternate du from the configuration
  890. ;block. Translate from binary form to standard
  891. ;DU form in the screen. A 0ffh value for either
  892. ;D or U translates to '?' on the screen and means
  893. ;that the program being configured is to use the
  894. ;run-time current default DU. (NOT the Current
  895. ;default for ZCNFG!)
  896.     LD    A,(CFGD)    ;only 0 or 1 allowed
  897.     AND    0FEH        ;select bits 1..7
  898.     JP    NZ,BADOVL    ;bad, if any are set!
  899.  
  900.     LD    HL,(OFFSET)    ;->user/drive in config block
  901.     LDBCHL            ;drive in B, User in C
  902. LDFN2A:    LD    DE,(S_ADDR)    ;screen addr in DE
  903.  
  904. ;convert drive # in B to '?' or Drive letter
  905.     LD    A,(CFGD)    ;if data byte is 0...
  906.     XOR    41H        ;0->41, 1->40
  907.     ADD    B        ;0FFH+40H='?', (1..16)+40='A'..'P'
  908.  
  909.     LD    (DE),A        ;install in screen
  910.     INC    DE        ;->loc for User number
  911. ;convert the user number to decimal and store in screen
  912.     LD    A,SPC        ;fill with spaces to erase
  913.     LD    (DE),A        ;previous data
  914.     INC    DE
  915.     LD    (DE),A
  916.     DEC    DE        ;->user number area
  917.  
  918.     LD    A,C        ;bin user number
  919.     CP    0FFH        ;use default?
  920.     CALL    NZ,MAFDC    ;store in decimal if not
  921.     JR    NZ,REDRAW    ;done if not 0ffh
  922.     LD    A,"?"        ;indicate default
  923.     LD    (DE),A
  924.     INC    DE
  925.     LD    (DE),A
  926.     RET
  927.  
  928. REDRAW:    XOR    A
  929.     RET
  930.  
  931. ;=========================================================
  932. ;    FUNCTION 3 - UPDATE HEX ASCII BYTE/WORD
  933.  
  934. IN_FN3:
  935. ;Transfer either 2 max or 4 max characters from
  936. ;bbline input to 1 or 2 bytes in configuration
  937. ;block, interpreting the characters in HEXADECIMAL.
  938. ;Copy the input string to the screen image.
  939. ;(cfgd) specifies the number of bytes to be replaced
  940. ;in the configuration block, and is 1 or 2. When 2
  941. ;bytes are specified, they are interpreted as a WORD,
  942. ;and stored in the standard low-byte-first order. A
  943. ;word (2 byte) is accepted from the terminal and 
  944. ;displayed in the screen (at (s_addr)) in human-readable
  945. ;high-byte-first order.
  946.  
  947.     LD    HL,HMMOUT    ;set up routines to be called
  948.     LD    (ROUTE1+1),HL    ;during xmmout execution
  949.     LD    (ROUTE2+1),HL
  950.     LD    DE,PRMPH0    ;first part of prompt for HEX
  951.     CALL    TYPLIN        ;send it
  952.     CALL    XMMOUT        ;send min/max if specified in ovly
  953.     LD    DE,PRMPT1    ;stuff after min/max if present
  954.     CALL    TYPLIN
  955.  
  956.     LD    A,-1        ;capitalize
  957.     CALL    BBLINE        ;user input
  958.     OR    A        ;any input besides CR?
  959.     SCF
  960.     RET    Z        ;do nothing on empty argument
  961.     CALL    EVAL16        ;interpret as hexadecimal
  962.     CALL    RNGTST        ;test for within range if required
  963.     RET    C        ;do nothing on range error
  964.  
  965. ;binary value is in DE, asci hex is in tmpscr buffer
  966.     LD    A,(CFGD)    ;number of cfg bytes (1 or 2)
  967.     LD    B,A        ;in counter
  968.     LD    C,A        ;save for entry at LDFN3A
  969.     LD    HL,(OFFSET)    ;->1 or 2 cnfg bytes
  970.  
  971. HEXIN2:    LD    (HL),E        ;send one or two bytes
  972.     LD    E,D        ;to the cnfg block
  973.     INC    HL
  974.     DJNZ    HEXIN2
  975.  
  976.     JR    LDFN3A        ;do screen update, no error check
  977.  
  978. ;---------------------------------------------------------
  979.  
  980. LD_FN3:
  981. ; Get data from configuration block and store
  982. ; as ASCII HEX in the screen image.
  983. ;CALL  (from mapper -- indirect call)
  984.  
  985.     LD    A,(CFGD)    ;number of cnfg bytes
  986.     LD    C,A        ;save for dispatch use
  987.     DEC    A
  988.     AND    11111110B    ;remove lsb
  989.     JP    NZ,BADOVL
  990.  
  991. LDFN3A:    LD    HL,(OFFSET)    ;hl->config byte(s)
  992.     LD    DE,(S_ADDR)    ;get screen loc
  993.     DEC    C        ;make 0 or 1
  994.     JR    NZ,LD2HEX    ;dispatch to byte or word code
  995. ;here for byte data
  996.     LD    A,(HL)        ;get the data
  997.     CALL    MA2HC        ;store 2 hex ascii in screen
  998.     XOR    A        ;mark no error
  999.     RET
  1000.  
  1001. LD2HEX:        ;here for word data
  1002.     LDHLHL
  1003.     CALL    MHL4HC        ;store 4 hex ascii in screen
  1004.     XOR    A
  1005.     RET
  1006.  
  1007. ;=========================================================
  1008. ;    FUNCTION 4 - BYTE/WORD UPDATE WITH DECIMAL RADIX
  1009.  
  1010. IN_FN4:
  1011. ;get user ascii decimal input, convert to bin
  1012. ;and store in config block and screen.
  1013. ;The byte at cfgd: defines the number of bytes
  1014. ;referenced in the configuration block. The
  1015. ;pointer at s_list: identifies location of the
  1016. ;16 bit min and max values permitted for the entry. If
  1017. ;that pointers value is 0000 (before relocation)
  1018. ;then no range testing is done; any value is OK.
  1019. ;If the number entered by the user is outside the
  1020. ;range specified by the min/max word pair, then
  1021. ;nothing is done.
  1022.  
  1023. ;get user input
  1024.     LD    HL,PHLFDC    ;send up to 5 decimal digits
  1025.     LD    (ROUTE1+1),HL
  1026.     LD    (ROUTE2+1),HL
  1027.     LD    DE,PRMPD0    ;first part of prompt for DEC
  1028.     CALL    TYPLIN        ;send it
  1029.     CALL    XMMOUT        ;send min/max if specified in ovly
  1030.     LD    DE,PRMPT1    ;stuff after min/max if present
  1031.     CALL    TYPLIN        ;finish the prompt
  1032.  
  1033.     LD    A,-1
  1034.     CALL    BBLINE        ;get user input
  1035.     OR    A
  1036.     SCF
  1037.     RET    Z        ;ret if nothing entered
  1038.     CALL    EVAL10        ;convert to BIN in DE
  1039. ;decimal input converted to bin in A, BC, and DE
  1040.     CALL    RNGTST        ;test for within range if required
  1041.     RET    C        ;do nothing on range error
  1042.  
  1043. ;value in DE, HL->input string
  1044.     LD    A,(CFGD)    ;get number of bytes to update
  1045.     LD    B,A
  1046.  
  1047. ;update the config block entry
  1048.     LD    HL,(OFFSET)    ;config block destination
  1049. FN4_1:    LD    (HL),E        ;update it
  1050.     INC    HL        ;->next
  1051.     LD    E,D        ;in case high byte needed
  1052.     DJNZ    FN4_1
  1053.  
  1054. ;fall through to ld_fn4 for screen update
  1055. ;---------------------------------------------------------
  1056.  
  1057. LD_FN4:
  1058. ; Get data from configuration block and store
  1059. ; as ASCII decimal in the screen. BYTE configuration
  1060. ; data uses up to 3 screen bytes, WORD configuration
  1061. ; data ( a 2 at cfgd: ) uses up to 5 screen bytes.
  1062.  
  1063.     LD    HL,(OFFSET)    ;hl->config byte(s)
  1064.     LD    DE,(S_ADDR)    ;get screen loc
  1065.     LD    A,(CFGD)    ;number of cnfg bytes
  1066.     CP    1
  1067.     JR    Z,LD1DEC
  1068.     CP    2
  1069.     JR    Z,LD2DEC
  1070.     JP    NZ,BADOVL
  1071.  
  1072. LD1DEC:
  1073. ;here for byte data, stored in up to 3 bytes
  1074.     LD    A,(HL)        ;get the data
  1075.     CALL    MADC        ;store decimal ascii in screen
  1076.     XOR    A        ;mark no error
  1077.     RET
  1078.  
  1079. LD2DEC:
  1080. ;here for word data, stored in up to 5 bytes
  1081.     LDHLHL
  1082.     CALL    MHLDC        ;up to 5 digits, no space fill
  1083.     XOR    A
  1084.     RET
  1085.  
  1086. ;=========================================================
  1087.  
  1088. ;    FUNCTION 5 - PROCESS ASCII INCLUDING LC
  1089. ;same as function 1, except lower case allowed
  1090.  
  1091. IN_FN5:    XOR    A        ;specify both LC & UC
  1092.     JP    INFN5        ;(entry in LD_FN1: routine)
  1093.  
  1094. ;LD_FN5:    ;function 5 uses same load as function 1.
  1095.         ;and shares the LD_FN1 address
  1096.  
  1097. ;=========================================================
  1098.  
  1099. ;        FUNCTION 6
  1100. ;    PROCESS ALL OR PART OF A Z3 FILESPEC
  1101.  
  1102. IN_FN6:
  1103. ;The configuration block contains one of the forms:
  1104. ;    FN,FT        (FCB format, 11 bytes blank filled)
  1105. ;    Drive        (1 byte)
  1106. ;    user,drive    (2 bytes)
  1107. ;    User,Drive,FN,FT (User, standard FCB - total 13 bytes)
  1108. ;The cfgd byte contains 0..3 to identify these forms. This code
  1109. ;is used to control transfer of all or portions of the filespec
  1110. ;from user input to tmpfcb, and between tmpfcb and the cnfg block.
  1111. ;Data transfer from tmpfcb to the screen image is also controlled
  1112. ;by (cfgd) in the sense of selecting the appropriate PUTZ.. routine.
  1113. ;Both configuration data and user input are transferred to tmpfcb.
  1114. ;Transfer to and from the cnfg block is also controlled by bit 2 of
  1115. ;(cfgd) which specifies interpretation of Drive byte values. If the
  1116. ;bit is 1, then Drive A is represented by 1; bit 2 = 0 implies that
  1117. ;Drive A=0. Thus (cfgd) may have values from 0..3 for 0-based drive
  1118. ;specification and 4..7 for 1-based drive specs. (FNAME and the
  1119. ;tmpfcb buffer always use 1-based drive designation)
  1120.  
  1121.     LD    DE,FN6MSG    ;-> prompt message
  1122.     CALL    TYPLIN
  1123.     LD    A,-1
  1124.     CALL    BBLINE        ;get user input, capitalize
  1125.     OR    A
  1126.     SCF
  1127.     RET    Z        ;don't process empty string!
  1128.     LD    C,A        ;length of input string
  1129.     CALL    COLON        ;install terminating colon for fname parse
  1130.     LD    BC,100H        ;default DU=A0 for fname (1=A:)
  1131.     LD    DE,TMPFCB    ;full fcb preceded by user byte
  1132. ;a full fcb is required for fname to initialize
  1133.     CALL    FNAME        ;parse user input to tmpfcb
  1134.     SCF
  1135.     RET    NZ        ;on DU error
  1136. ;fname data uses the A=1 convention for the drive byte
  1137.     CALL    PUTFN6        ;update screen image, use A=1
  1138. ;convert to A=0 form unless A=1 is specified
  1139.     LD    A,(CFGD)
  1140.     BIT    2,A        ;A=1 specified
  1141.     JR    NZ,INN61    ;jump if A=1 specified
  1142.     LD    HL,TMPFCB
  1143.     DEC    (HL)        ;convert to A=0 form
  1144. ;copy the relevant portion of tmpfcb to cfg block
  1145. INN61:    CALL    SETUP6        ;get source, dest, byte count
  1146.     LDIR    
  1147.     RET
  1148.  
  1149. COLON:    LD    A,(CFGD)    ;check for colon required
  1150.     AND    3        ;remove drive range bit
  1151.     RET    Z        ;not required for fn.ft
  1152.     CP    3        ;..or for full filespec
  1153.     RET    Z
  1154.     PUSH    HL        ;save ptr to input string
  1155.     LD    B,0
  1156.     ADD    HL,BC        ;->terminating null
  1157.     DEC    HL        ;->last char
  1158.     LD    A,':'
  1159.     CP    (HL)        ;did user provide colon?
  1160.     JR    Z,COLONX    ;skip if so
  1161.     INC    HL        ;->terminator
  1162.     LD    (HL),A        ;provide colon
  1163.     INC    HL
  1164.     LD    (HL),0        ;..and new terminator
  1165. COLONX:    POP    HL        ;hl -> colon terminated D or DU
  1166.     RET
  1167.  
  1168. SETUP6:
  1169. ;perform lookup of field length and location
  1170. ;in tmpfcb structure for portions of Z3 filespec
  1171. ;specified by the value (0..3) in cfgd:.
  1172.     LD    A,(CFGD)
  1173.     CP    8        ;if >7, it's bad data
  1174.     JP    NC,BADOVL    ;error msg & abort if so
  1175.     AND    3        ;remove A=1 flag
  1176.     LD    C,A
  1177.     ADD    A
  1178.     ADD    C
  1179.     LD    C,A        ;for index to table of 3 byte records
  1180.     LD    B,0
  1181.     LD    HL,TBLI6
  1182.     ADD    HL,BC
  1183.     LD    C,(HL)        ;number of bytes to transfer
  1184.     INC    HL
  1185.     LD    A,(HL)        ;get tmpfcb location
  1186.     INC    HL
  1187.     LD    H,(HL)
  1188.     LD    L,A
  1189.     LD    DE,(OFFSET)    ;config block location
  1190.     RET
  1191.  
  1192. TBLI6:    DB    11        ;fn+ft
  1193.     DW    TMPFCB+1    ;source
  1194.     DB    1        ;Drive byte
  1195.     DW    TMPFCB        ;location
  1196.     DB    2        ;U+D
  1197.     DW    TMPFCB-1
  1198.     DB    13        ;U+D+FN+FT
  1199.     DW    TMPFCB-1
  1200.  
  1201. LD_FN6:
  1202. ;load tmpfcb from the cnfg block
  1203.     CALL    SETUP6        ;de=source,hl=dest,bc=count
  1204.     EX    DE,HL        ;hl=source, de=dest
  1205.     LDIR
  1206. ;convert to A=1 if necessary
  1207.     LD    A,(CFGD)
  1208.     BIT    2,A        ;A=1 specified?
  1209.     JR    NZ,PUTFN6    ;jump if so. It's already correct
  1210.     LD    HL,TMPFCB    ;..else..
  1211.     INC    (HL)        ;convert to A=1    for the screen load.
  1212. ;fall through to load the screen
  1213.  
  1214. ;load the screen image from tmpfcb
  1215. PUTFN6:    LD    HL,TMPFCB+1    ;->file name field of parsed input
  1216.     LD    DE,(S_ADDR)
  1217.     LD    A,(CFGD)
  1218.     AND    3        ;remove A=0/1 flag
  1219.     JR    Z,PUTFNFT    ;0 = display <fn>.<ft> only
  1220.     DEC    A
  1221.     JR    Z,PUTZDD    ;1 = display D: only
  1222.     DEC    A
  1223.     JR    NZ,PUTFSPEC    ;3 = display full filespec
  1224.     JP    PUTZDU        ;2 = display DU: only
  1225. ;PUTZDU returns CY set on DU error
  1226.  
  1227. PUTZDD:    DEC    HL        ;->drive byte
  1228.     LD    A,(HL)
  1229.     DEC    A
  1230.     CP    16        ;test for within range
  1231.     CCF
  1232.     RET    C        ;not in range A..P
  1233.     ADD    'A'        ;convert to ascii
  1234.     LD    (DE),A
  1235.     RET
  1236.  
  1237. PUTFNFT:
  1238.     CALL    PUTZFN        ;send FN.FT to screen dest,
  1239.     LD    B,12        ;field width.
  1240.     JR    RJUSTIFY    ; C contains # of trailing spaces
  1241.  
  1242. PUTFSPEC:
  1243.     CALL    PUTZFS        ;send full filespec to screen
  1244.     RET    C        ;DU range error
  1245.     LD    B,16        ;field width, C=trailing spaces
  1246. RJUSTIFY:
  1247.     LD    HL,(S_ADDR)
  1248.     CALL    RJIP
  1249.     XOR    A
  1250.     RET
  1251.  
  1252. ;=========================================================
  1253.  
  1254. ;        FUNCTION 7
  1255. ;    ROTATE A BIT WITHIN A FIELD IN A BYTE
  1256.  
  1257. IN_FN7:
  1258. ;entry-    (CFGD:) = mask defining the field
  1259. ;    (OFFSET:) = address of cfg data byte
  1260. ;exit-    byte at (OFFSET:) contains rotated field.
  1261. ;    Screen image is updated with a string
  1262. ;    corresponding to the new bit position.
  1263. ;    all registers used.
  1264.  
  1265.     LD    HL,(OFFSET)    ;->configurable data
  1266.     LD    A,(CFGD)    ;mask
  1267.     LD    E,(HL)        ;data byte in reg E
  1268.     LD    B,A        ;field mask in B
  1269.     CPL
  1270.     LD    C,A        ;.not. mask in C
  1271.     CPL            ;recover mask
  1272.     AND    E        ;isolate the bit field
  1273.     RLCA            ;left circular rotate
  1274.     LD    D,A        ;save rotated field
  1275.     INC    C
  1276.     DEC    C        ;8 bit field?
  1277.     JR    Z,INFN7X    ;..done if so
  1278.     AND    C        ;test for overflow beyond field
  1279.     JR    Z,INFN7X    ;z=no overflow
  1280. ;a bit has shifted out of the high position
  1281. ;of the field. The field is now all 0s and
  1282. ;the shifted bit belongs in the lsb of the field.
  1283.     LD    A,C        ;synthesize a new field
  1284.     RLCA            ; with lsb set
  1285.     AND    B        ;remove all other bits
  1286.     LD    D,A        ;save the initialized field
  1287.  
  1288. INFN7X:    LD    A,(HL)        ;data byte
  1289.     AND    C        ;remove bit field
  1290.     OR    D        ;and replace with rotated field
  1291.     LD    (HL),A        ;new data byte
  1292.     LD    A,D        ;new field in A
  1293.     JR    LDFN7A        ;..for screen update
  1294.  
  1295. LD_FN7:
  1296. ;This is the entry from MAPPER
  1297. ;Copy the string in the overlay corresponding
  1298. ;to the bit set in the field to the screen image.
  1299. ;entry- same as IN_FN7
  1300. ;    S_ADDR: & S_LIST: contain valid addresses
  1301. ;exit-    (normal) AF = 0,NZ,NC
  1302. ;    (error) program abort with message
  1303. ;        on bad CFGD byte.
  1304.  
  1305.     LD    HL,(S_LIST)
  1306.     LD    A,H
  1307.     OR    L
  1308.     JP    Z,BADOVL    ;list must be present!
  1309.  
  1310.     LD    A,(CFGD)
  1311. ;test for illogical mask with less than 2 bits set
  1312.     LD    B,A        ;save the byte
  1313.     DEC    A        ;invert low order 0s and
  1314.                 ;the first 1 encountered
  1315.     AND    B        ;restore 0's from original byte
  1316.                 ;and set Zflag (NZ if 1's remain)
  1317.     LD    A,B        ;restore original byte in A
  1318.     JP    Z,BADOVL    ;Z if < 2 bits in the mask
  1319.  
  1320.     LD    HL,(OFFSET)
  1321.     AND    (HL)        ;bit field only in A
  1322.  
  1323. LDFN7A:
  1324. ;This is the entry from IN_FN7.
  1325. ;shift bit field right to lsb position for indexing
  1326. ;entry-    A = field from cfg data, masked
  1327. ;    B = mask for field data
  1328. ;    HL -> cfg data byte
  1329.     BIT    0,B        ;mask & data right justified yet?
  1330.     JR    NZ,LDFN7B    ;yes, if nz
  1331.     RRCA            ;move bit field right
  1332.     RRC    B        ;and also the mask
  1333.     JR    LDFN7A        ;and repeat
  1334.  
  1335. LDFN7B:
  1336. ;index to the proper string in S_LIST
  1337.     LD    HL,(S_LIST)    ;->field data list for screen
  1338.     LD    C,A        ;cfg field in C
  1339. ..INDX:    BIT    0,C        ;lsb set?
  1340.     JR    NZ,LDFN7X    ;use current list item if so
  1341.     CALL    SKIP2Z        ;else skip to next list item
  1342.     RRC    C        ;and put next field bit in lsb
  1343.     JR    ..INDX        ;..and repeat
  1344.  
  1345. LDFN7X:
  1346. ;copy S_LIST string to screen image
  1347.     LD    DE,(S_ADDR)
  1348.     CALL    MOVE2Z        ;copy null terminated string
  1349.     XOR    A        ;no error
  1350.     RET
  1351.  
  1352. ;=========================================================
  1353.  
  1354. ;    FUNCTION 8 - TOGGLE BYTE BETWEEN TRUE & FALSE
  1355.  
  1356. IN_FN8:
  1357. ;Toggle a byte in the configuration block at (offset)
  1358. ;between 00 and 0ffh (=-1), then update the screen image
  1359. ;at (s_addr) with the appropriate one of two choices of
  1360. ;null terminated ascii strings at (s_list).
  1361.  
  1362.     LD    HL,(OFFSET)    ;->configuration byte
  1363.     LD    A,(HL)        ;get it
  1364.     OR    A        ;adjust flags
  1365.     JR    Z,BYTOG1    ;continue if zero
  1366.     LD    A,-1        ;else be sure it's 0ffh
  1367. BYTOG1:    CPL            ;toggle the byte
  1368.     LD    (HL),A        ;restore to config block
  1369.     OR    A        ;adjust flags
  1370.     JP    TOGL0        ;send ascii to screen
  1371.  
  1372. LD_FN8:
  1373. ;load the screen according to the logic
  1374. ;value in the configuration byte
  1375.     LD    HL,(S_LIST)
  1376.     LD    A,H
  1377.     OR    L
  1378.     JP    Z,BADOVL    ;list must be present!
  1379.     LD    A,(CFGD)    ;not used, but partially identifies
  1380.     DEC    A        ;proper function if its value is 1
  1381.     JP    NZ,BADOVL
  1382.     LD    HL,(OFFSET)    ;->configuration byte
  1383.     LD    A,(HL)        ;get it
  1384.     OR    A        ;adjust flags
  1385.     JP    TOGL0        ;send ascii to screen
  1386.  
  1387. ;=========================================================
  1388.  
  1389. ;    FUNCTION 9 - UPDATE A 7-BIT ASCII BYTE
  1390.  
  1391.     .comment ~
  1392. Function 9 configures a single ASCII byte in the target
  1393. configuration block. The screen display is in a right
  1394. justified field of 3 spaces. Printable characters are
  1395. displayed literally, control characters are converted to
  1396. the ^C type display, and unprintable characters are shown
  1397. with a 3 character mnemonic. The mnemonics are ASCII.
  1398.     end comment~
  1399.  
  1400. IN_FN9:
  1401. ;Gets a keyboard character from user.
  1402. ;Deposits the 7-bit character in the
  1403. ;configuration block.
  1404. ;Uses LDFN9 to update the screen image.
  1405.  
  1406.     LD    DE,HOTMSG    ;Send the prompt
  1407.     CALL    TYPLIN
  1408.  
  1409. HOTKEY:    CALL    CIN        ;Get user keypress
  1410.     JR    Z,HOTKEY    ;Repeat until keypress
  1411.  
  1412.     LD    C,A
  1413.     LD    HL,(OFFSET)    ;Store in CFG block
  1414.     LD    A,(HL)
  1415.     AND    1 SHL 7        ;preserve high bit
  1416.     OR    C        ;add new ASCII portion
  1417.     LD    (HL),A
  1418.     JR    LDFN9        ;Translate to screen
  1419.  
  1420. HOTMSG:    DB    ') Enter a keystroke:',0
  1421.  
  1422. ;Entry from initial screen load (SCR-LD:)
  1423. LD_FN9:
  1424.  
  1425. ;Get byte from CFG block
  1426.     LD    HL,(OFFSET)
  1427.     LD    A,(HL)
  1428.  
  1429. ;Entry from IN_FN9 bypasses error checking
  1430. LDFN9:
  1431. ;copy the character to the screen image, with
  1432. ;translation of non-printing bytes to ASCII or
  1433. ;"^C" format.
  1434.  
  1435.     CALL    XASCII        ;translate to mnemonic
  1436.                 ;HL-> 3 byte mnemonic
  1437.     LD    BC,300H        ;length in B for strcpy
  1438.     LD    DE,(S_ADDR)
  1439.     JP    STRCPY        ;Copy mnemonic to screen image
  1440.  
  1441. XASCII:
  1442. ;Translate an ASCII byte into a printable
  1443. ;3 character string with ^ notation for
  1444. ;control characters, SP, DEL, or the
  1445. ;printable char right justified in the field.
  1446.  
  1447. ;entry-     A = 7 bit ascii char
  1448. ;exit-    HL -> 3 byte translated string
  1449. ;    AF used
  1450.  
  1451.     LD    HL,DELDAT
  1452.     CP    DEL
  1453.     RET    Z        ;del char
  1454.     LD    HL,SPCDAT
  1455.     CP    SPC
  1456.     RET    Z        ;space
  1457.     LD    (CHRDAT+2),A
  1458.     LD    HL,CHRDAT
  1459.     RET    NC        ;printable character
  1460.     ADD    40H        ;cnvt to equivalent UC char
  1461.     LD    (CTLDAT+2),A
  1462.     LD    HL,CTLDAT
  1463.     RET            ;show '^char'
  1464.  
  1465. DELDAT:    DB    'DEL'
  1466. SPCDAT:    DB    ' SP'
  1467. CHRDAT:    DB    '   '
  1468. CTLDAT:    DB    ' ^ '
  1469.  
  1470. ;=========================================================
  1471.  
  1472.     .SBTTL SERVICE ROUTINES
  1473.     PAGE
  1474. ;=========================================================
  1475. ; MISC SERVICE ROUTINES
  1476. ;=========================================================
  1477.  
  1478. RNGTST:
  1479. ;Test current numeric user input against min/max values
  1480. ;pointed to by the address at s_list. If that pointer
  1481. ;is equal to the relocation constant, then its original
  1482. ;value was 0000h, and no range testing is required. i.e.,
  1483. ;any value is OK. Returns CY set if out of range, else NC.
  1484.  
  1485. ;entry-    DE = value to be tested
  1486. ;exit-    DE, HL preserved, BC is munched
  1487. ;    CY SET = DE > MAX or DE < MIN
  1488.  
  1489.     PUSH    HL
  1490.     LD    HL,(S_LIST)    ;->possible range data
  1491.     LD    A,H
  1492.     OR    L        ;test for presence
  1493.     JR    Z,RNGX        ;z = no range test
  1494.     LDBCHL            ;get min value in BC
  1495.     LDHLHL            ;get max value in HL
  1496.     CALL    RANGE        ;preserves DE (test value)
  1497. RNGX:    POP    HL
  1498.     RET
  1499.  
  1500. ;=========================================================
  1501.  
  1502. XLTADU:
  1503. ;parse token as DU spec with '?' wildcards to BC.
  1504. ;'?' becomes -1, default is at OFFSET:, used if
  1505. ;there is nothing present for D or U. '?' means
  1506. ;default is deferred until target run-time.
  1507.  
  1508. ;entry-    HL ->token, null terminated
  1509. ;    valid data structure at OFFSET
  1510. ;exit-    BC = D,U with deferred default
  1511. ;    AF, DE, HL used
  1512. ;    errors are simply ignored and
  1513. ;     cause default to return in B/C
  1514.  
  1515.     EX    DE,HL
  1516.     LD    HL,(OFFSET)
  1517.     LDBCHL            ;default DU
  1518.     EX    DE,HL
  1519.     LD    A,(HL)        ;first character
  1520.     CP    SPC
  1521.     JR    Z,XLT2        ;leave drive default alone
  1522.     CP    '?'        ;wild card drive?
  1523.     JR    NZ,XLT1        ;no, check for drive letter
  1524.     LD    B,-1        ;yes, use deferred default
  1525.     JR    XLT2        ;and goto next character
  1526.  
  1527. XLT1:    CALL    ISDIGIT        ;user number?
  1528.     JR    Z,XLT4        ;yes,do it and quit
  1529.     SUB    'A'        ;legal drive is 0..15
  1530.     RET    C        ;error, <'A'
  1531.     CP    16        ; > P?
  1532.     CCF
  1533.     RET    C        ;error if so
  1534.     LD    B,A        ;drive range 0..15
  1535.  
  1536.     LD    A,(CFGD)    ;0 or 1
  1537.     ADD    B        ;adjust range
  1538.     LD    B,A        ;1..16 if CFGD=1
  1539.  
  1540. XLT2:    INC    HL        ;->second character
  1541.     LD    A,(HL)
  1542.     OR    A
  1543.     RET    Z        ;done if terminator
  1544.     CP    SPC        ;leave default as is?
  1545.     RET    Z        ;yes, if space
  1546.     CP    '?'        ;deferred default?
  1547.     JR    NZ,XLT3
  1548.     LD    C,-1        ;use deferred default
  1549.     RET            ;done
  1550. XLT3:    CALL    ISDIGIT
  1551.     SCF
  1552.     RET    NZ        ;error if not a digit
  1553.  
  1554. XLT4:    CALL    EVAL10        ;get user number
  1555.     LD    C,E        ;user # in C
  1556. XLTERR:    XOR    A        ;ret with Z,NC
  1557.     RET
  1558.  
  1559. ;=========================================================
  1560.  
  1561. XMMOUT:
  1562.     LD    HL,(S_LIST)    ;-> possible min/max words
  1563.     LD    A,H
  1564.     OR    L        ;no data if 0
  1565.     RET    Z
  1566.  
  1567.     LD    DE,FROMP    ;'from ' part of prompt
  1568.     CALL    TYPLIN
  1569.  
  1570.     LDDEHL            ;min val in DE
  1571.     LDHLHL            ;max val in HL
  1572.     PUSH    HL        ;save for route2
  1573.     EX    DE,HL        ;min val in HL
  1574. ROUTE1:    CALL    0        ;filled in by xmmout caller
  1575.  
  1576.     LD    DE,TOMSG    ;' to ' part of prompt
  1577.     CALL    TYPLIN
  1578.  
  1579.     POP    HL        ;max value
  1580. ROUTE2:    CALL    0        ;filled in by xmmout caller
  1581.     RET
  1582.  
  1583. HMMOUT:
  1584. ;select the syslib routine to use for data transfer
  1585.     LD    A,(CFGD)    ;number of bytes
  1586.     DEC    A
  1587.     JP    NZ,PHL4HC    ;for hex word data
  1588.     LD    A,L
  1589.     JP    PA2HC        ;for hex byte data
  1590.  
  1591. ;=========================================================
  1592.     .SBTTL INITIALIZATION ROUTINES
  1593.     PAGE
  1594. ;=========================================================
  1595. ;    PROGRAM STARTUP & INITIALIZATION
  1596. ;=========================================================
  1597.  
  1598. INIT:
  1599. ;fill all uninitialized data with 0
  1600.     LD    HL,UDSTART
  1601.     LD    BC,UDLEN
  1602.     LD    D,H
  1603.     LD    E,L
  1604.     INC    DE
  1605.     LD    (HL),0
  1606.     LDIR
  1607.  
  1608. ;Install the version number in the signon message
  1609.     LD    HL,VERNUM
  1610.     LD    A,VERS
  1611.     ADD    '0'        ;convert to ascii
  1612.     LD    (HL),A
  1613.     INC    HL        ;skip the '.'
  1614.     INC    HL
  1615.     LD    A,REV
  1616.     ADD    '0'
  1617.     LD    (HL),A
  1618.  
  1619. ;Install the version Date at VSNDAT and in the signon msg
  1620.     LD    HL,VSNDAT+2    ;->year byte
  1621.     LD    A,YEAR
  1622.     CALL    B2BCD        ;convert to BCD
  1623.     LD    (HL),A        ;store vsndat field
  1624.     DEC    HL
  1625.     LD    A,DAY
  1626.     CALL    B2BCD
  1627.     LD    (HL),A
  1628.     DEC    HL
  1629.     LD    A,MONTH
  1630.     CALL    B2BCD
  1631.     LD    (HL),A
  1632.     LD    DE,SMON
  1633.     LD    B,3
  1634.     CALL    STORDT        ;send formatted m,d,yr to signon msg
  1635.  
  1636.     CALL    RETUD        ;get current DU
  1637.     INC    B        ;make drive 1..16
  1638.     LD    (DEFDU),BC    ;store the default
  1639.  
  1640. ;ZCNFG's Alternate DU may contain 0FFh for D and/or U,
  1641. ;marking a '?' entry during configuration.
  1642. ;Replace such wildcards with the corresponding D or
  1643. ;U in (DEFDU), the DU at invocation.
  1644. ;entry-    BC = default D/U
  1645.     LD    HL,PATH11
  1646.     LD    (PATH),HL    ;init path pointer
  1647.  
  1648.     LD    HL,(ALTUSR)
  1649.     CALL    DEF_DU        ;provide defaults from DEFDU
  1650.  
  1651.     LD    (PATH12),HL    ;install in the two
  1652.     LD    (PATH21),HL    ;alternate paths
  1653.     LD    (LBRDU),HL    ;save for finding a CFG LBR
  1654.  
  1655. ;install current configuration data in HELP screen
  1656.     LD    HL,LBRDU+2    ;Drv + 1 for PUTZDU
  1657.     LD    DE,HLP001    ;default ALT: field
  1658.     LD    A,SPC        ;fill character
  1659.     LD    B,3        ;field length
  1660.     PUSH    DE
  1661.     CALL    FILL        ;initialize alt: field
  1662.     POP    DE
  1663.     CALL    PUTZDU
  1664.     LD    HL,HLP001
  1665.     LD    BC,3
  1666.     CALL    NTSPCS
  1667.     CALL    RJIP
  1668.  
  1669.     LD    HL,CLBRFN    ;default LBR FN.FT
  1670.     LD    DE,HLP002
  1671.     CALL    PUTZFN
  1672.  
  1673. ;test for ZCPR3 or ZCPR33 availability
  1674.     LD    HL,(Z3ENV)    ;get env address into hl
  1675.     LD    A,H        ;see if environment implemented
  1676.     OR    L
  1677.     LD    (Z3MSGF),A    ;save as msg buffer flag
  1678.     RET    Z        ;NZ=Z3ENV available, Z=use CP/M only
  1679.     CALL    Z3VINIT        ;init for vlib functions
  1680.     CALL    TINIT        ;init terminal if required
  1681.     CALL    GETCRT
  1682.     INC    HL
  1683.     LD    A,(HL)        ;get screen length
  1684.     LD    (SCRNLN),A    ;use this length instead of cnfg.
  1685. ;install the program name in the help screen
  1686.     LD    DE,HLP000    ;->help screen name
  1687.     LD    A,(DE)
  1688.     CP    SPC
  1689.     RET    NZ        ;name already there
  1690.     CALL    GETEFCB        ;HL->EXTFCB
  1691.     RET    Z        ;quit if no EXTFCB
  1692.     INC    HL
  1693.     LD    BC,8
  1694.     LDIR
  1695.     RET
  1696.  
  1697. ;=========================================================
  1698.  
  1699. HELP:
  1700. ;provide the help screen if requested
  1701.     LD    A,(FCB+1)
  1702.     CALL    ISALNUM        ;alphanumeric char present?
  1703.     RET    Z        ; no help if so
  1704.  
  1705. DOHELP:    CALL    ASSIST        ;give help screen & quit
  1706.     JP    QUIT
  1707.  
  1708. ASSIST:    LD    DE,HLPMSG    ;print the Help screen
  1709.     CALL    TYPLIN        ; with no side effects
  1710.     XOR    A
  1711.     RET
  1712.  
  1713. ;=========================================================
  1714.  
  1715. PGMINI:
  1716.     LD    A,(SCRNLN)    ;install fixed screen addresses
  1717.     LD    (HLPAT),A    ;for the standard prompts
  1718.     SUB    5        ;depending on screen length
  1719.     LD    (ATPRPT),A    ;menu prompt location
  1720.  
  1721.     LD    DE,OVLFCB    ;initialize CFG file FCB
  1722.     CALL    INIFCB
  1723.     LD    DE,TGTFCB    ;..and target file FCB
  1724.     CALL    INIFCB
  1725.  
  1726. ;arg1:
  1727. ;Parse the first token in the command tail
  1728. ;into the target FCB.
  1729.     LD    DE,TGTFCB    ;fcb for target file
  1730.     LD    HL,TBUF+1    ;->command tail
  1731.     CALL    SKSP        ;skip spaces, tabs
  1732.     LD    BC,(DEFDU)
  1733.     CALL    FNAME        ;parse the filespec into TGTFCB
  1734.     JP    NZ,BADDU    ;jmp to error if bad d/u
  1735.  
  1736.     CALL    SKSP        ;->next non-space, non-tab byte
  1737.  
  1738. ;arg2:
  1739. ;parse a possible CFG file spec
  1740.     CALL    CPARSE
  1741.     JP    C,BADDU
  1742.  
  1743. ;arg3:
  1744. ;parse a possible configuration LBR filespec
  1745.     CALL    CPARSE
  1746.     JP    C,BADDU
  1747.  
  1748. ;select the default DU for the overlay file
  1749. ;and for the default DU in the path
  1750.     LD    BC,(TGTUSR)
  1751.     LD    A,(ZCOPT0)
  1752.     AND    1        ;use logged DU?
  1753.     JR    Z,SETPTH    ;no, if bit 0 reset
  1754.     LD    BC,(DEFDU)    ;..use logged du if set
  1755. SETPTH:    LD    (PATH11),BC    ;install elements in the
  1756.     LD    (PATH22),BC    ;two alternate paths
  1757.     
  1758. ;reinitialize the two search paths to
  1759. ;the directory defined for CFG file if
  1760. ;user specified a D or U for CFG file
  1761.     LD    HL,(OVLUSR)
  1762.     INC    HL        ;0FFFFH -> 0000
  1763.     LD    A,H
  1764.     OR    L        ;neither D nor U specified if 0
  1765.     JR    Z,LBRINI    ;use LBR if unspecified D|U
  1766.     DEC    HL        ;recover original DU spec
  1767.     CALL    DEF_DU        ;defaults from DEFDU | TGTDU
  1768.  
  1769.     LD    (PATH11),HL    ;redefine both paths to a
  1770.     LD    (PATH21),HL    ;single directory, (OVLUSR)
  1771.     SBC    HL,HL        ;make 0
  1772.     LD    (PATH12),HL    ;terminate the paths
  1773.     LD    (PATH22),HL
  1774.     OR    0FFH        ;install code to
  1775.     JR    LBRINX        ;turn off lbr access
  1776.  
  1777. LBRINI:
  1778. ;initialize the lbr LUD
  1779.     LD    HL,CLBRFN    ;configured default LBR FN
  1780.     LD    DE,LUDFCB
  1781.     CALL    DEF_FN        ;provide default FN if needed
  1782.     LD    HL,CLBRFT    ;default LBR FT
  1783.     CALL    DEF_FT        ;provide default FT if needed
  1784.  
  1785.     LD    BC,(LBRDU)    ;default LBR loc
  1786.     LD    HL,(LUDUSR)    ;ambiguous LBR DU
  1787.     CALL    DEF_DU        ;provide defaults
  1788.     LD    (LBRDU),HL    ;new DU for LBR file
  1789.     LD    B,H
  1790.     LD    C,L
  1791.     XOR    A        ;restore DU area used in LUD
  1792.     SBC    HL,HL        ;to 0000
  1793.     LD    (LUDUSR),HL
  1794.  
  1795.     DEC    B        ;make drive A=0 for LOGUD
  1796.     CALL    LOGUD
  1797.     LD    DE,LUD
  1798.     CALL    LUINIT
  1799. LBRINX:    LD    (LUSTAT),A    ;lbr status flags
  1800.     RET
  1801.  
  1802. ;=========================================================
  1803.  
  1804. CPARSE:
  1805. ;Parse a token into tmpfcb, then copy the full
  1806. ;FS into LBRFCB if there is a leading slash OR 
  1807. ;if the FT is LBR OR if a CFG file has already 
  1808. ;been parsed (ie if this is arg3). Else copy
  1809. ;the FS to OVLFCB.
  1810. ;entry-    HL -> token to parse
  1811. ;exit-    HL -> token terminator
  1812. ;    CY set on bad DU
  1813.  
  1814.     CALL    SKSP        ;skip spaces, return non-space in A
  1815.     XOR    '/'        ;LBR marker?
  1816.     JR    NZ,CPARS0    ;CY reset
  1817.     INC    HL        ;skip over the '/'
  1818.     SCF            ;show '/' present
  1819. CPARS0:    SBC    A,A        ;copy CY to all bits in A
  1820.     PUSH    AF        ;LBR marker, flags
  1821.  
  1822.     LD    DE,TMPFCB
  1823.     LD    BC,-1
  1824.     CALL    FNAME
  1825.     POP    BC        ;LBR marker in B, flags in C
  1826.     SCF            ;mark possible bad DU
  1827.     RET    NZ        ;and quit if Bad DU
  1828.  
  1829.     PUSH    HL        ;save token pointer
  1830.     LD    A,(CFGFLG)    ;if CFG has already been
  1831.     OR    B        ;parsed, then the current
  1832.     LD    (LBRFLG),A    ;will be declared a LBR FS
  1833.  
  1834.     LD    HL,TMPFT    ;test for .LBR FT
  1835.     LD    DE,CLBRFN+8    ;->'LBR'
  1836.     LD    B,3
  1837.     CALL    @FNCMP        ;string compare from SYSLIB
  1838.     SCF            ;show possible LBR file type
  1839.     JR    Z,CPARS2
  1840.     CCF            ;not LBR file type
  1841. CPARS2:    SBC    A,A        ;make -1 for LBR, else 0
  1842.  
  1843.     LD    HL,LBRFLG    ;if either is true, then this
  1844.     OR    (HL)        ;is a LBR specification
  1845.     LD    (HL),A        ;save for DU installation
  1846. ;set up OVLFCB for CFG file or LUDFCB for LBR file
  1847.     LD    DE,LUDUSR    ;assume LBR
  1848.     JR    NZ,CPARS3
  1849.     LD    DE,OVLUSR
  1850.     DEC    A        ;make FF
  1851.     LD    (CFGFLG),A    ;show CFG file declared
  1852.  
  1853. CPARS3:    LD    HL,TMPUSR    ;copy FS to destination FCB
  1854.     LD    BC,13        ;DU+FN+FT length
  1855.     LDIR
  1856.     POP    HL        ;restore token pointer
  1857.     XOR    A        ;reset CY, good return.
  1858.     RET
  1859.  
  1860. ;=========================================================
  1861.  
  1862. FILINIT:
  1863. ;Open the target file, read in the configuration page,
  1864. ;locate and load the configuration overlay.
  1865.     LD    DE,TGTFCB
  1866.     LD    HL,TGTTYP    ;->default FT in ZCNFG config block
  1867.     CALL    DEF_FT        ;set default file type if required
  1868.  
  1869.     CALL    OPNFIL        ;open the target file
  1870.     JP    Z,BADFIL    ;error exit, file not found
  1871.  
  1872.     CALL    RPAGE        ;get first 256 bytes of pgm
  1873.  
  1874. ;look for the 'Z3ENV' marker at relative location 003
  1875.     LD    DE,Z3MARK
  1876.     LD    HL,TGTBUF+3
  1877.     LD    B,IDLEN        ;length of strings
  1878.     CALL    COMPB        ;compare 2 strings
  1879.     JR    Z,ZUTIL        ;ok, check for env type
  1880.  
  1881. ;if not found, it's not a ZCPR3x utility
  1882.     XOR    A        ;logic false value
  1883.     LD    (Z3INST),A    ;prevent zcpr installation
  1884.     JP    GT_CFG
  1885.  
  1886. ;-------------------------------------------------------
  1887.  
  1888. ZUTIL:    LD    HL,TGTBUF
  1889.     LD    DE,ENVTYP    ;offset to env type byte
  1890.     ADD    HL,DE
  1891.     LD    A,4
  1892.     CP    (HL)        ;type four header?
  1893.     CALL    Z,RPAGE        ;skip the header if so, and
  1894.                 ;read in the first page of the pgm
  1895.     JR    GT_CFG
  1896.  
  1897. ;-------------------------------------------------------
  1898.  
  1899. RPAGE:
  1900. ;Read one page of 256 bytes from the target program
  1901. ;into the local configuration block buffer
  1902. ;save the Current Record byte in the FCB for restoration when
  1903. ;the updated configuration block is rewritten
  1904.  
  1905.     LD    A,(TGTFCB+CREC)    ;get Current Record byte
  1906.     LD    (FCB_CR),A    ;save it
  1907.     LD    HL,TGTBUF    ;cnfg block buffer
  1908.     CALL    SETDMA
  1909.     LD    DE,TGTFCB    ;fcb pointer for target program
  1910.     CALL    RDREC        ;get first 128 bytes in tgtbuf
  1911.     JP    C,BADFIL    ;premature EOF
  1912.     LD    HL,TGTBUF+80H
  1913.     CALL    SETDMA
  1914.     CALL    RDREC        ;get second 128 bytes and return
  1915.     LD    A,(FCB_CR)    ;starting record
  1916.     LD    B,A
  1917.     LD    A,(TGTFCB+CREC)    ;number of next record
  1918.     SUB    B
  1919.     LD    (NCRECS),A    ;may only be 1 rcrd if
  1920.                 ;the file is that short.
  1921.     RET
  1922.  
  1923. ;-------------------------------------------------------
  1924.  
  1925. GT_CFG:
  1926. ;This routine identifies the CFG file name, searches
  1927. ;in explicitly named or default directories for it,
  1928. ;and loads the file in free memory at OVRLAY:.
  1929. ;The name of the overlay is copied from one of three
  1930. ;sources, listed in order of priority:
  1931. ;    1. from the command line (argument 2).
  1932. ;    2. from offset 0DH in the configuration page.
  1933. ;    3. the target program name. (cmd line arg 1)
  1934. ;The highest priority is a command line name. The
  1935. ;first valid filename in this list is taken as the 
  1936. ;name of the overlay.
  1937. ;A one or two element directory search path has already
  1938. ;been defined. If a directory was explicitly declared for
  1939. ;the CFG file on the command line then that is the only
  1940. ;directory searched. Otherwise, the search path contains
  1941. ;three elements: ALT:CONFIG.LBR, the ALT: directory, and
  1942. ;a default directory which is configured as either the
  1943. ;directory at ZCNFG invocation (DEFDU) or the DU in which 
  1944. ;the target file resides (TGTUSR).
  1945.  
  1946. ;Path element order (search priority) 
  1947. ;If an explicit DIR form is present for the overlay file,
  1948. ;then that directory alone is accessed to load the overlay.
  1949.  
  1950. ;If NO dir form is present for the overlay file, then the
  1951. ;CONFIG.LBR is searched first, followed by a search of the
  1952. ;two directories in the search path, as follows..
  1953.  
  1954. ;If the CFG filename came from the Targets configuration 
  1955. ;page then the ALT ;directory is searched first. Otherwise, 
  1956. ;the configured default is searched first.
  1957.  
  1958. ;If the CFG file is not found, an error message is issued.
  1959.  
  1960.     LD    HL,OVLTYP
  1961.     LD    DE,OVLFCB
  1962.     CALL    DEF_FT        ;install default ovly FT if needed
  1963.  
  1964. ;OVLFN contains a FN from the command line
  1965. ;or is blank if FN was not specified.
  1966.     CALL    TGTCFG        ;install FN from overlay if needed
  1967.                 ;and if present.
  1968. ;OVLFN is still blank if there was no FN
  1969. ;in the command line or in the overlay.
  1970.     LD    HL,TGTFN
  1971.     LD    DE,OVLFCB
  1972.     CALL    DEF_FN        ;install Target FN if needed
  1973. ;The name of the CFG file and the 
  1974. ; search paths are now completely defined.
  1975.     INC    DE        ;->OVLFN
  1976.     LD    HL,TESTID    ;->possible FN from Target CFG area
  1977.     LD    B,8        ;FN field length
  1978.     CALL    @FNCMP        ;same as OVLFN?
  1979.     LD    HL,ERRCTL
  1980.     LD    A,(HL)        ;error test control byte
  1981.     SET    7,A        ;assume OVLFN same as in CFG block
  1982.     JR    Z,GTCFG1    ;same, so minimize error checking
  1983.     RES    7,A        ;not the same, increase error checking
  1984. GTCFG1:    LD    (HL),A
  1985. ;get the CFG file from the CFG LBR if it exists and
  1986. ;if the user did not specify an explicit D and/or U
  1987.     CALL    GET_LF
  1988.     RET    Z        ;Z = CFG file loaded
  1989.  
  1990. ;get the CFG file from one of the directories
  1991. ;on the search path.
  1992.     LD    DE,OVLFCB
  1993.     CALL    GETFIL        ;open first file found on the path
  1994.     JP    Z,BADFIL    ;file not found
  1995.  
  1996. ;load CFG overlay and return to FILINIT caller
  1997.     LD    HL,(OVRLAY)    ;place to load the file
  1998.     JP    RDFILE        ;read in the entire .CFG file
  1999.  
  2000. ;-------------------------------------------------------
  2001. ;    ROUTINES CALLED FROM FILINIT
  2002. ;-------------------------------------------------------
  2003.  
  2004. TGTCFG:
  2005. ;Verify a possible filename at offset 0Dh in the
  2006. ;targets configuration page. If found, copy the
  2007. ;name to the overlay FCB and adjust the path
  2008. ;pointer to change search priority so that the
  2009. ;alternate directory is searched first.
  2010.     LD    DE,TMPFCB
  2011.     CALL    INIFCB
  2012.     CALL    NAMCHK        ;check for up to 8 AN characters
  2013.     RET    C        ;quit if illegal filename string
  2014.     LD    DE,TMPFN
  2015.     LD    C,0
  2016.     CALL    STRCPY        ;copy FN to tmpfn
  2017.  
  2018.     LD    HL,TMPFN    ;->verified ID string
  2019.     LD    DE,OVLFCB
  2020.     CALL    DEF_FN        ;copy to OVLFN if needed
  2021. ;change paths only if replacement occurs
  2022.     JR    NZ,TCFGX
  2023.     LD    HL,PATH21    ;use the second path, which results
  2024.     LD    (PATH),HL    ; in search of the alternate du first
  2025. TCFGX:    OR    0FFH        ;ret NC,NZ=success
  2026.     RET
  2027.  
  2028. ;-------------------------------------------------------
  2029.  
  2030. GETFIL:
  2031. ;traverse the DIR path, using each entry
  2032. ;to attempt to open the file in FCB.
  2033. ;entry-    DE ->FCB for file to be opened
  2034. ;exit-    Z = file not found or can't open.
  2035. ;    NZ = file found and opened
  2036. ;    DE is preserved, others used
  2037.  
  2038.     LD    HL,(PATH)
  2039.     LDBCHL            ;get next dir on path
  2040.     LD    (PATH),HL
  2041.     LD    A,B        ;test for end of path
  2042.     OR    C
  2043.     RET    Z        ;Z = reached end of path
  2044.  
  2045.     EX    DE,HL
  2046.     LD    (HL),B        ;install new DU in FCB
  2047.     DEC    HL
  2048.     LD    (HL),C
  2049.     INC    HL
  2050.     LD    A,C        ;user number
  2051.     LD    BC,13        ;offset to FCB+13
  2052.     ADD    HL,BC
  2053.     LD    (HL),A        ;store user number like Z3
  2054.     SBC    HL,BC        ;recover FCB pointer
  2055.     EX    DE,HL        ;..in DE
  2056.     CALL    OPNFIL
  2057.     JR    Z,GETFIL    ;not found, try next DIR
  2058.     RET            ;found, return NZ
  2059.  
  2060. ;-------------------------------------------------------
  2061.  
  2062. GET_LF:
  2063. ;If the user has specified a DU/DIR
  2064. ;assume that the CFG file is in that
  2065. ;directory and don't bother looking in
  2066. ;a library.
  2067. ; otherwise....
  2068. ;Open the file from OVLFCB in the
  2069. ;LBR named in the LUD data structure.
  2070. ;After successful open, read the CFG
  2071. ;file into memory at (OVRLAY).
  2072. ;entry-    LUD is initialized
  2073. ;    LBR DIR has been logged in
  2074. ;exit-     Z = CFG file has been loaded
  2075. ;    NZ = CFG file not loaded because
  2076. ;      valid LBR or CFG file not found
  2077.  
  2078.     LD    A,(LUSTAT)
  2079.     OR    A
  2080.     RET    NZ        ;no valid LBR
  2081.     LD    BC,(LBRDU)
  2082.     DEC    B        ;make drive A=0 for LOGUD
  2083.     CALL    LOGUD        ;login for LBR access
  2084.     LD    HL,OVLFN
  2085.     LD    DE,LUD
  2086.     CALL    LUOPEN
  2087.     JR    NZ,GETLFE    ;CFG file not found
  2088. ;file open. Read it into memory
  2089.     LD    HL,(OVRLAY)
  2090. LREAD:    CALL    SETDMA
  2091.     CALL    LUREAD
  2092.     LD    BC,80H
  2093.     ADD    HL,BC        ;bump dma pointer
  2094.     JR    Z,LREAD
  2095. ;EOF encountered
  2096.     XOR    A        ;mark success
  2097.     RET
  2098.  
  2099. GETLFE:    LD    BC,(DEFDU)
  2100.     DEC    B        ;make 0...15
  2101.     CALL    LOGUD        ;restore default directory
  2102.     OR    0FFH        ;ensure NZ return
  2103.     RET
  2104.  
  2105. ;-------------------------------------------------------
  2106.  
  2107. NAMCHK:
  2108. ;Copy a possibly null,$,space, or High bit set
  2109. ;terminated FN from (HL) to a local buffer.
  2110. ;Return an error if illegal FN characters are
  2111. ;present.
  2112. ;entry-    HL-> possible FN
  2113. ;exit-    all used
  2114. ;    Cy set = not a FN
  2115. ;  else NC,
  2116. ;    HL -> FN in local buffer, space filled
  2117. ;     B = length
  2118.  
  2119.     LD    HL,FIDOFF+TGTBUF    ;->potential ID string
  2120.     LD    DE,TESTID    ;temporary buffer
  2121.     LD    BC,820H        ;B=maximum length,C=extra terminator
  2122.     PUSH    DE        ;for exit
  2123.  
  2124.     CALL    STRCPY
  2125.     LD    C,B        ;save for length calc.
  2126.     LD    A,SPC
  2127.     INC    B
  2128.     DEC    B        ;any to fill?
  2129.     CALL    NZ,FILL        ;trailing spaces
  2130.     LD    A,8        ;field length
  2131.     SUB    C        ;calc string length
  2132.     LD    B,A        ; in B
  2133.     POP    HL        ;->potential FN buffer
  2134.     CP    2        ;too short for a filename?
  2135.     RET    C        ;yes, if Cy set
  2136. ;test possible FN for illegal characters
  2137.     PUSH    HL
  2138.     PUSH    BC
  2139. FNTEST:    LD    A,(HL)        ;get next char
  2140.     INC    HL
  2141.     CALL    ISFNC        ;test it
  2142.     JR    C,FNTSTX    ;C = illegal FN char
  2143.     DJNZ    FNTEST
  2144. FNTSTX:    POP    BC        ;B=length, C=unused length
  2145.     POP    HL        ;-> FN buffer
  2146.     RET
  2147.  
  2148.     DSEG
  2149. TESTID:    DS    8        ;trial FN buffer
  2150.     CSEG
  2151.  
  2152. ;-------------------------------------------------------
  2153. ;    End of routines called from FILINIT
  2154. ;=========================================================
  2155.  
  2156. SCR_LD:
  2157. ;Called once during initialization at start
  2158. ; of the program to load config items to screen.
  2159. ;Traverses the circular que of menu lists,
  2160. ;loading the screen image for each menu
  2161. ;from data in the target configuration block.
  2162.  
  2163.     LD    HL,(OVRLAY)    ;->config data just loaded
  2164.     LD    A,(HL)
  2165.     CP    0C7H        ;Is first byte RST 0?
  2166.     JR    Z,SCRLD0
  2167.     CP    0C9H        ;..or RET?
  2168.     SCF            ;set error flag
  2169.     RET    NZ        ;and return if no RET or RST 0
  2170. SCRLD0:    INC    HL        ;skip over protective rst0
  2171.     LD    E,(HL)        ;get assembled menu0 addr
  2172.     INC    HL
  2173.     LD    D,(HL)        ;..in DE
  2174.     INC    HL        ;->first menu list
  2175.     LD    B,H        ;save in BC
  2176.     LD    C,L
  2177.     OR    A        ;clear carry flag
  2178.     SBC    HL,DE        ;relocation constant
  2179.     LD    (RELOCC),HL    ;save for RELOCL & RELOC routines
  2180.     LD    H,B        ;recover menu0 location
  2181.     LD    L,C
  2182.  
  2183. ;initialize the internal counter to track menu number
  2184.     XOR    A
  2185.     LD    (MNUMB),A    ;start with menu0
  2186.     DEC    A
  2187.     LD    (LMNUMB),A    ;count from -1 to allow for a
  2188.                 ;final count that is one too much
  2189. ;ldmenl will relocate the items in the menu list 
  2190. ;using the value in relocc.
  2191.     CALL    LDMENL        ;make first menu current
  2192.     LD    HL,(NEXTM)    ;mark head of circular que
  2193. SCR_L0:    PUSH    HL        ;save que head marker
  2194.     LD    HL,(CASTBL)    ;get current case table
  2195.     CALL    MAPPER        ;load the associated screen
  2196.     JP    C,CFGBAD    ;target data/cfg format mismatch
  2197.  
  2198.     LD    A,(LMNUMB)    ;bump last menu number
  2199.     INC    A
  2200.     LD    (LMNUMB),A
  2201.     CALL    GOTONM        ;next que member
  2202.     POP    DE        ;nextm from que head
  2203.     LD    HL,(NEXTM)    ;nextm from current member
  2204.     OR    A        ;reset cy for the sbc
  2205.     SBC    HL,DE        ;equal?
  2206.     EX    DE,HL        ;restore head of que marker
  2207.     JR    NZ,SCR_L0    ;if not, load the screen
  2208.     XOR    A        ;get zero
  2209.     LD    (MNUMB),A    ;reinitialize menu number
  2210.     RET            ;if yes, all menu screens have been
  2211.                 ;loaded and first one is current.
  2212.  
  2213. ;=========================================================
  2214.     .SBTTL SCREEN UPDATE FROM CFG BLOCK
  2215.     PAGE
  2216. ;=========================================================
  2217. ;ROUTINES TO TRANSFER CONFIGURATION BLOCK DATA TO THE
  2218. ;    SCREEN IMAGE
  2219. ;=========================================================
  2220.  
  2221. MAPPER:
  2222. ;MAPPER traverses a list of records each of
  2223. ;which contains the parameters required for
  2224. ;maintaining one menu item. For each record,
  2225. ;the maintenance routine is called after the
  2226. ;balance of the parameter list has been copied
  2227. ;to a standard location for use by the routine.
  2228. ;The routines load the screen image from data
  2229. ;in the configuration block.
  2230. ;entry- HL -> table of data made
  2231. ;with the BITMAP or VECTOR macros.
  2232.  
  2233.     LD    B,(HL)        ;number of entries
  2234.     INC    HL
  2235.     LD    E,(HL)        ;length of each entry
  2236.     INC    HL        ;->first record
  2237.     LD    D,0
  2238.     LD    (MAPER3+1),DE
  2239.     DEC    E        ;discount menu ID
  2240.     DEC    E        ;..and Function number
  2241.     DEC    E        ;de=length of parameter list
  2242.     LD    (MAPER1+1),DE
  2243.  
  2244. ;visit each record, calling the function required
  2245. ;to load the screen image for each menu item.
  2246. MAPER0:    PUSH    BC        ;save record counter
  2247.     PUSH    HL        ;..and start of current record
  2248.     LD    A,(HL)        ;get menu ID letter
  2249.     LD    (CURITM),A    ;save for possible error report
  2250.     INC    HL
  2251.     LD    C,(HL)        ;get function address
  2252.     INC    HL
  2253.     LD    B,(HL)        ;...in BC
  2254.     INC    HL        ;->start of parameter list
  2255.     INC    B
  2256.     DEC    B        ;if high byte is 0, this is a
  2257.     CALL    Z,FNXLTI    ;function number to translate
  2258.  
  2259. ;transfer the parameter list at HL to the standard block
  2260.     PUSH    BC
  2261.     LD    DE,OFFSET
  2262. MAPER1:    LD    BC,0        ;parm list length entered above
  2263.     LDIR            ;copy to standard parm list
  2264.     CALL    RELOC        ;add tgtbuf to offset, reloc addresses
  2265.     POP    DE
  2266.  
  2267.     LD    HL,MAPPRET    ;prepare for indirect call
  2268.     PUSH    HL        ;ret addr on stack
  2269.     PUSH    DE        ;routine addr
  2270.     RET            ;make an indirect call
  2271.  
  2272. ;The called routine uses data in the standard block
  2273. ;as required, then returns to the following address.
  2274.  
  2275. MAPPRET:            ;..and return to here
  2276.     POP    HL        ;recover the record pointer
  2277.     POP    BC
  2278.     RET    C        ;quit on error from LD function
  2279. MAPER3:    LD    DE,0        ;filled at run time
  2280.     ADD    HL,DE        ;-> next table entry
  2281.     DJNZ    MAPER0
  2282.     RET
  2283.  
  2284. ;=========================================================
  2285.  
  2286.     .SBTTL ERROR HANDLING
  2287.     PAGE
  2288. ;=========================================================
  2289. ;    ERROR HANDLERS
  2290. ;=========================================================
  2291.  
  2292. BADDU:
  2293. ;here if FNAME finds a bad DU in cmd tail
  2294.     LD    DE,BDUMSG
  2295.     CALL    TYPLIN
  2296.     JP    DOHELP        ;show help and abort
  2297.  
  2298. ;=========================================================
  2299.  
  2300. BADCFG:
  2301. ;The overlay file does not start with
  2302. ;RST 0 or RET code. Must be damaged.
  2303.     LD    DE,ERMSG0
  2304.     JR    EABORT
  2305.  
  2306. ;=========================================================
  2307.  
  2308. CFGBAD:
  2309. ;Data in the target is inappropriate for
  2310. ;the screen format specified by the overlay.
  2311.     LD    DE,ERMSG2
  2312.     JR    EABORT
  2313.  
  2314. ;=========================================================
  2315.  
  2316. BADOVL:    LD    HL,OVLFN
  2317.     LD    DE,OVFNAM
  2318.     CALL    PUTZFS        ;send ovl filename to msg
  2319.     LD    A,(MNUMB)
  2320.     LD    DE,BADMNU
  2321.     CALL    MAFDC        ;send menu number to msg
  2322.     LD    DE,OVLMSG
  2323.     JR    EABORT
  2324.  
  2325. ;=========================================================
  2326.  
  2327. BADFIL:
  2328. ;Here if a file cannot be opened. Usually a bad filename.
  2329. ;entry- DE->fcb for the attempted operation
  2330.  
  2331.     INC    DE        ;->file name
  2332.     LD    B,8
  2333.     CALL    BADLOP        ;send filename to console
  2334.     LD    A,'.'
  2335.     CALL    COUT        ;send '.' in FN.FT
  2336.     LD    B,3
  2337.     CALL    BADLOP        ;send file type
  2338.     LD    DE,ERMSG1    ;report not found
  2339.     JR    EABORT
  2340.  
  2341. ;send up to B characters to console, skipping spaces
  2342. BADLOP:    LD    A,(DE)
  2343.     INC    DE
  2344.     CP    ' '
  2345.     JR    Z,BADSKP
  2346.     CALL    COUT
  2347. BADSKP:    DJNZ    BADLOP
  2348.     RET
  2349.  
  2350. ;=========================================================
  2351.  
  2352. EABORT:
  2353. ;send an error message to console and abort
  2354. ;entry-    DE->error message
  2355.     CALL    TYPLIN
  2356.     JP    QUIT
  2357.  
  2358. ;=========================================================
  2359.  
  2360.     .SBTTL DATA & MESSAGES
  2361.     PAGE
  2362. ;=========================================================
  2363. ;    INITIALIZED DATA AREA
  2364. ;=========================================================
  2365.  
  2366. OVRLAY:                ;overlay is loaded in free memory
  2367. $MEMRY:    DS    2        ;filled in by linker
  2368.  
  2369. ;=========================================================
  2370. ;    MESSAGES
  2371.  
  2372. SIGNON:        ;signon banner
  2373.     DB CR,LF,LF,'ZCNFG CONFIGURATION UTILITY, V'
  2374. VERNUM:    DB    ' .  ('
  2375. SMON:    DB    '  /  /  )'
  2376.     DB    CR,LF,0
  2377.  
  2378. BADMSG:    DB    cr,'Invalid command. Try Again: ',0
  2379.  
  2380. FTMSG:    DB    ')  -Enter up to '
  2381. FTMSG1:    DB    '3  characters: ',0
  2382.  
  2383. PRMPD0:    DB    ') Enter a number ',0
  2384. PRMPH0:    DB    ') Enter HEX ',0
  2385. PRMPT1:    DB    ' =>',0
  2386. FROMP:    DB    'from ',0
  2387. TOMSG:    DB    ' to ',0
  2388.  
  2389. BDUMSG:    DB cr,lf,'Check for possible Drive or user error..',cr,lf,lf
  2390.  
  2391. DUMSG:    DB    ") New DU",0
  2392. DUMSG1:    DB    " ('?' for default) ",0
  2393.  
  2394. PSEMSG:        ;prompt for next menu help screen
  2395.     DB    '(Space or CR to continue, ^C for Menu)',cr
  2396.     DB    0        ;string terminator
  2397.  
  2398. ERMSG0:        ;Invalid overlay file
  2399.     DB    'BAD CFG FILE - Does not start with RST 0'
  2400.     DB    ' or RET code.',CR,LF
  2401.     DB    0        ;string terminator
  2402.  
  2403. ERMSG1:        ;report not found
  2404.     DB    ' was not found.',cr,lf
  2405.     DB    0        ;string terminator
  2406.  
  2407. ERMSG2:    DB    'Target data inappropriate for this overlay - '
  2408.     DB    'WRONG CONFIGURATION OVERLAY?',CR,LF
  2409.     DB    0        ;string terminator
  2410.  
  2411. FN6MSG:    DB    ') Enter filespec option ',0
  2412.  
  2413. OVLMSG:    DB    CR,LF,'BAD DATA IN '
  2414. OVFNAM:    DB    '                '
  2415.     DB    ' in the case table for menu #'
  2416. BADMNU:    DB    '   , item '
  2417. CURITM:    DB    ' '        ;current menu choice
  2418.     DZ    CR,LF
  2419.  
  2420. ;=========================================================
  2421.  
  2422. SPACES:    DB    '      '    ;for an empty field....
  2423.     DB    0        ;string terminator
  2424.  
  2425. ;======================================================
  2426.     .SBTTL CONTROL SCREEN IMAGE
  2427.     PAGE
  2428. ;=========================================================
  2429.  
  2430. ;screen image for menu & pgm control selections.
  2431. ;This screen is always appended to target-specific
  2432. ;menus provided by the configuration overlay.
  2433.  
  2434. PRMPT0:
  2435.     DB    '----------------------------  ZCNFG COMMANDS'
  2436.     DB    '  ----------------------------',CR,LF
  2437.     DB    ' / ',DIM,' Explain Options    ',BRIGHT,'   >'
  2438.     DB    ' ',DIM,' Next Menu        ',BRIGHT,'  Esc ',DIM
  2439.     DB    ' Save Changes & eXit    ',BRIGHT,'  ',CR,LF
  2440.     DB    ' ? ',DIM,' Explain Commands   ',BRIGHT,'   <'
  2441.     DB    ' ',DIM,' Previous Menu    ',BRIGHT,'  ^C  ',DIM
  2442.     DB    ' Quit with no changes   ',BRIGHT,'  ',CR,LF
  2443.     DB    CR,LF
  2444. BAR000:    DB    ' Which choice? ',0
  2445.  
  2446. ;=========================================================
  2447.  
  2448. ;Menu & Pgm control options case table
  2449. ;This table is searched last for program control
  2450. ;options. If a match is not found, then the entry
  2451. ;at CTLCSE is executed as a default.
  2452. CTLCS0:    DB    (ctlcse-ctlcs1)/(ctlcs2-ctlcs1)    ;number of cases
  2453.     DB    ctlcs2-ctlcs1            ;bytes per record
  2454. CTLCS1:    DB    '/'        ;explain CFG menu items
  2455.     DW    MNUHLP
  2456. CTLCS2:    DB    '?'        ;explain internal menu items
  2457.     DW    CMDHLP
  2458.     DB    'Q'        ;quit - no update
  2459.     DW    QUIT
  2460.     DB    'Q'-'@'        ;quit - no update
  2461.     DW    QUIT
  2462.     DB    CTLC        ;also quit on ^C
  2463.     DW    QUIT
  2464.     DB    CR        ;Re-prompt if CR
  2465.     DW    CRNTRY
  2466.     DB    '>'        ;next menu
  2467.     DW    GOTONM
  2468.     DB    'D'-'@'        ;next menu
  2469.     DW    GOTONM
  2470.     DB    'F'-'@'        ;next menu
  2471.     DW    GOTONM
  2472.     DB    '.'        ;next menu
  2473.     DW    GOTONM
  2474.     DB    '<'        ;previous menu
  2475.     DW    GOTOLM
  2476.     DB    'A'-'@'        ;previous menu
  2477.     DW    GOTOLM
  2478.     DB    'S'-'@'        ;previous menu
  2479.     DW    GOTOLM
  2480.     DB    ','        ;previous menu
  2481.     DW    GOTOLM
  2482.     DB    'X'        ;quit with options updated
  2483.     DW    EXIT
  2484.     DB    'X'-'@'        ;quit with options updated
  2485.     DW    EXIT
  2486.     DB    'W'        ;quit with options updated
  2487.     DW    EXIT
  2488.     DB    'W'-'@'        ;quit with options updated
  2489.     DW    EXIT
  2490.     DB    ESC        ;quit with options updated
  2491.     DW    EXIT
  2492. CTLCSE:        ;label used to calc number of entries
  2493.     DB    0        ;dummy entry for default case
  2494.     DW    BADCMD        ;default case, err msg & ret C
  2495.  
  2496.     PAGE
  2497. ;=========================================================
  2498.  
  2499. CMDMSG:        ;Help for command keystrokes
  2500.     DB    CR,LF
  2501.     DB    'Other keys perform the same functions as those'
  2502.     DB    ' shown at the',CR,LF
  2503.     DB    'bottom of the main screen. Use them if that''s'
  2504.     DB    ' what your fingers',CR,LF
  2505.     DB    'prefer. If X, W, or Q are present as selections'
  2506.     DB    ' in the main menu',CR,LF
  2507.     DB    'then they perform the configuration function'
  2508.     DB    ' and NOT the function',CR,LF
  2509.     DB    'shown below.',CR,LF,CR,LF
  2510.     DB    'Command         Alternates  ',HT,'Function performed'
  2511.     DB    CR,LF,CR,LF
  2512.     DB    '   /               (none)   ',HT,'display CFG'
  2513.     DB    ' help screens',CR,LF
  2514.     DB    '   ?               (none)   ',HT,'display this'
  2515.     DB    ' screen',CR,LF
  2516.     DB    '   >               . ^D ^F  ',HT,'display next'
  2517.     DB    ' CFG menu',CR,LF
  2518.     DB    '   <               , ^A ^S  ',HT,'display previous'
  2519.     DB    ' CFG menu',CR,LF
  2520.     DB    '   Esc             X ^X W ^W',HT,'save changes'
  2521.     DB    ' and exit',CR,LF
  2522.     DB    '   ^C              Q ^Q     ',HT,'exit without'
  2523.     DB    ' saving changes',CR,LF
  2524.     DB    0
  2525.  
  2526. ;=========================================================
  2527.  
  2528. HLPMSG:        ;The Help Screen
  2529.     DB    CR,LF
  2530.     DB    'Configures option data in Executable files (TFS), using'
  2531.     DB    ' a configuration',CR,LF
  2532.     DB    'data file (FS) which may be in a LBR (/FS or [DIR:]FN.LBR).'
  2533.     DB    CR,LF,CR,LF
  2534.     DB    'Syntax: '
  2535. HLP000:    DB    ' ZCNFG   TFS  [[/]FS]  [[/]FS]',CR,LF,CR,LF
  2536.     DB    'Examples:  (Configure TGT.COM, default LBR is '
  2537. HLP001:    DB    '   :'
  2538. HLP002:    DB    'config.lbr  )',CR,LF,CR,LF
  2539.     DB    '     ZCNFG TGT TGT /CFG01     ;uses TGT.CFG in CFG01.LBR'
  2540.     DB    CR,LF
  2541.     DB    '     ZCNFG TGT /CFG01 TGT     ;order of args 2,3 optional'
  2542.     DB    ' with ''/''',CR,LF
  2543.     DB    '     ZCNFG TGT TGT CFG01      ;''/'' optional if LBR is'
  2544.     DB    ' 3rd argument',CR,LF
  2545.     DB    '     ZCNFG TGT CFG01.LBR      ;''/'' optional with explicit'
  2546.     DB    ' .LBR',CR,LF
  2547.     DB    '     ZCNFG TGT TGT            ;TGT.CFG on Path (includes'
  2548.     DB    ' default LBR)',CR,LF
  2549.     DB    '     ZCNFG TGT                ;<internal FN.CFG> or TGT.CFG'
  2550.     DB    ' on Path',CR,LF
  2551.     DB    '     ZCNFG ZCNFG              ;configures itself to assign'
  2552.     DB    ' ALT:, etc.',CR,LF,CR,LF
  2553.     DB    'FS, TFS are ZCPR style filespecs. All parts optional except'
  2554.     DB    ' TGT FN.',CR,LF
  2555.     DB    'Seeks FS files on a configurable internal path which includes'
  2556.     DB    CR,LF
  2557.     DB    ' Alt Directory unless superseded by a DIR: form in FS.'
  2558.     DB    CR,LF
  2559.     DB    'See ZCNFG.HLP for full syntax and usage. ',CR,LF
  2560.     DB    0
  2561.  
  2562. ;=========================================================
  2563. ;    UNINITIALIZED DATA
  2564.  
  2565.     DSEG
  2566. UDSTART:            ;labels DS block for initialization
  2567. Z3MSGF:    DS    1        ;records presence of ZCPR3x
  2568. DEFDU:    DS    2        ;default DU at signon, drv is 1..16
  2569. COLCNT:    DS    1        ;screen column counter
  2570. ROWCNT:    DS    1        ;screen line counter
  2571. RELOCC:    DS    2,0        ;overlay relocation constant
  2572. FCB_CR:    DS    1        ;current record at start of cfg block
  2573. NCRECS:    DS    1        ;number rcrds in cfg block (1 or 2)
  2574. CFGFLG:    DS    1        ;TRUE if CFG file named on cmd line
  2575. LBRFLG:    DS    1        ;TRUE if LBR file named on cmd line
  2576.  
  2577. UCFLAG:    DS    1        ;bitmapped string processing control
  2578.                 ;bit 0:0=UC only, 1=both LC,UC
  2579.                 ;bit 7:0=HBS not allowed, 1=HBS is OK
  2580. ERRCTL:    DS    1        ;bit mapped error test control flag
  2581.  
  2582. ;CFG file search paths
  2583. PATH:    DS    2        ;Current path pointer
  2584. PATH11:    DS    2
  2585. PATH12:    DS    2
  2586.     DS    2        ;first path terminator
  2587. PATH21:    DS    2
  2588. PATH22:    DS    2
  2589.     DS    2        ;second path terminator
  2590.  
  2591. ;note the extended FCBs. User number precedes
  2592. ;the drive byte in the normal FCB. Routines in
  2593. ;ZCNFG use this byte for auto-select. (see OPNFIL)
  2594. OVLUSR:    DS    1        ;user area for overlay
  2595. OVLFCB:    DS    1        ;overlay drive
  2596. OVLFN:    DS    8        ;overlay filename
  2597. OVLFT:    DS    3        ;filetype
  2598.     DS    24        ;balance of fcb
  2599.  
  2600. LBRDU:    DS    2        ;DU used for LBR, drv is 0..15
  2601. LUD:    DS    2        ;Length of LBR directory
  2602.     DS    2        ;Next block of current file
  2603.     DS    2        ;Remaining blocks, current
  2604. LUDFIL:    DS    11        ;current FN
  2605. LUDFCB:    DS    36        ;FCB for Library
  2606. LUDFN    EQU    LUDFCB+1
  2607. LUDFT    EQU    LUDFCB+9
  2608. LUDUSR    EQU    LUDFCB-1
  2609. LUSTAT:    DS    1        ;return from LUINIT
  2610.  
  2611. TMPSCR:    DS    30,0        ;temporary input data buffer
  2612. TMPUSR:    DS    1        ;user byte for temp fcb
  2613. TMPFCB:    DS    36        ;temp fcb for fname destination
  2614. TMPFN    EQU    TMPFCB+1    ; and for CFG file name
  2615. TMPFT    EQU    TMPFCB+9
  2616.  
  2617. TGTUSR:    DS    1        ;user number for tgt
  2618. TGTFCB:    DS    1        ;drive
  2619. TGTFN:    DS    8        ;target filename
  2620. TGTFT:    DS    3        ;target file type
  2621.     DS    24        ;balance of tgt fcb
  2622.  
  2623. UDLEN    EQU    $-UDSTART
  2624.  
  2625. ;local stack & system stack pointer
  2626.     DS    40
  2627. STACK:    DS    2
  2628.  
  2629. TGTBUF:    DS    100H        ;working buffer for first
  2630.                 ;two records from target file
  2631.     END
  2632.