home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / zpatch13.lbr / ZPATCH.ZZ0 / ZPATCH.Z80
Encoding:
Text File  |  1993-06-07  |  33.2 KB  |  1,224 lines

  1. ; ZPATCH vers 1.3
  2. ; April 5, 1988 
  3. ; author: Steven M. Cohen
  4. ;
  5. ; Version 1.3 fixes various bugs in version 1.1.
  6. ;  -- Searches now work correctly after the search function's help
  7. ;     screen is printed.  (Thanks, Ron Bardarson)
  8. ;  -- The infamous "8-character" NDR bug (which, incredibly enough
  9. ;     caused the display to go haywire) has been fixed. (Thanks, Bruce Morgen)
  10. ;  -- An error in the DEC24 routine of M24 has been fixed.  DEC24 was
  11. ;     not used until version 1.3, so the error went unnoticed.
  12. ;
  13. ; The following enhancements are also provided:
  14. ;  -- Some needless screen-repainting has been eliminated.  (More work
  15. ;     is still to be done in this area.)
  16. ;  -- Arrow keys now work in the non-edit mode for advancing the address
  17. ;     pointer byte by byte.
  18. ;  -- Several command keys have been changed for more consistency with other
  19. ;     Z-system tools:
  20. ;       X (execute) changed to R (run)
  21. ;       R (record #) changed to #
  22. ;       Q and  (quit) changed to X and  (exit)
  23. ;  -- This version is a ZCPR33 type-3 utility that can be linked to origin at
  24. ;     addresses other than 100H.
  25. ;  -- It automatically set the offset when working on Z33 type-3 .COM files
  26. ;     to their correct load address.
  27. ;  -- The ZEXRUN code has been eliminated in accordance with Jay Sage's
  28. ;     Z33 programming notes
  29. ;
  30. ; This is an INTERIM version that fixes all known bugs.
  31. ; On the drawing board is an entirely revamped version that will implement
  32. ; a much more logical command interface and several other new features.
  33. ; Since I am rather busy these days, I decided to relase this version now
  34. ; because I have no idea when the revamped version will be released.
  35. ; ZPATCH and all files contained within ZPATCH13.LBR are copyright
  36. ; 1988 by Steven M. Cohen.  They are released Apr 5, 1988 through the 
  37. ; good offices of ZSIG, the Z-system users group.  They may be freely
  38. ; copied by all but must not be sold either by themselves or as part
  39. ; of another package of software without the expressed written consent
  40. ; of the author.
  41. ;
  42. ; The author may be contacted by electronic mail on the Lillipute Z-Node
  43. ; in Chicago, 312-649-1730, which is also the official remote access system
  44. ; of ZSIG.
  45. ;
  46. ; This program was very much a learning experience for the programmer.
  47. ; It uses a MODULAR approach to assembly language programming, wherein
  48. ; the whole was built up from building blocks which might also find use
  49. ; in different future applications.  One advantage of this approach for me
  50. ; was that once debugged these routines only needed to be LINKED to the rest
  51. ; of the program, not reassembled over and over.  The disadvantage for the
  52. ; reader of this source code is that it might just be more difficult to follow.
  53. ; That is why source code has been so long in being released for this program.
  54. ; Finally after some prodding by Bruce Morgen I am releasing this source,
  55. ; even as I understand that some may find it difficult to follow.  Better
  56. ; something than nothing, however.
  57. ;
  58. ; the files BEDITOR.REL, M24.REL, and SYSEXT.REL are relocatable files
  59. ; included in ZPATCH11.LBR.  
  60. ;
  61. ; BEDITOR.REL is a library of routines for the byte editor used in 
  62. ; ZPATCH.  
  63. ;
  64. ; M24.REL is a library of routines to handle conversion of numeric strings
  65. ; to 24-bit numbers.  It also includes some utility routines for handling
  66. ; these quantities. 
  67. ;
  68. ; SYSEXT.REL is a library of routines either built upon or replacing
  69. ; routines from SYSLIB,Z3LIB,and VLIB, which may be regarded as useful 
  70. ; extensions to these.  
  71. ;
  72. ; Source for all these libraries has been released.
  73. ;
  74. ; EXTERNAL ROUTINES used by ZPATCH
  75. ;
  76. ;       routines found in the standard Z-system libraries of Richard Conn
  77. ;
  78.     ; syslib
  79.     EXT    IALLOC,ALLOC,BLINE,CAPS,CIN,COUT,PA2HC,GETFS1
  80.     EXT    MHL4HC,PHL4HC,F$OPEN,R$READ,R$WRITE,F$CLOSE,COMPHD
  81.     EXT    RETUD,LOGUD,CRLF,SKSP,SKNSP,F$READ
  82.     ; z3lib
  83.     EXT    ZFNAME,PUTCST,GETEFCB,GETSH2,QSHELL,SHPOP,SHPUSH,GETWHL
  84.     EXT    PUTZEX,GETZRUN,GETCL1,GETCL2,PUTCL,DUTDIR,GETDUOK,GETEFCB
  85.     EXT    ROOT
  86.     ; vlib
  87.     EXT    Z3VINIT,VPRINT,AT,STNDEND,GXYMSG,EREOL,CLS,TINIT,DINIT,GOTOXY
  88.     ; z33lib
  89.     EXT    GETSRUN
  90. ;    
  91. ;ROUTINES from libraries that were developed by the author for use in
  92. ;this program and possibly others.
  93. ;
  94.     ; beditor
  95.     EXT    SHOWBYTE,SEARCH,CONTINU,INFOMSG,DISPLAY,SAK,MESSAGE
  96.     EXT    EDITOR,HEXDMP,DSPSEC,UNSHOWB
  97. ;
  98.         ; m24
  99.     EXT    DOUBLE24,HALVE24,RADIX,NUMINP,RADIXDSP
  100. ;
  101.     ; sysext
  102.     EXT    VLPSTR,VPSTR,LDFIL,MUD,DUDIRPFX,COPY8
  103. ;Assembly instructions for ZPATCH:
  104. ;
  105. ;Z80ASM/SLRNK:
  106. ;
  107. ;SET SLR EQUATE TO TRUE
  108. ;then
  109. ;Z80ASM ZPATCH.%D%D%Z/6;IF ~ER;SLRNK /P:nnnn,ZPATCH,ZPATCH/N/E;FI
  110. ; where nnnn is the desired hex load address
  111. ;
  112. ;
  113. ;M80/L80:
  114. ;SET SLR EQUATE TO FALSE
  115. ;then
  116. ;m80=zpatch
  117. ;l80 zpatch,beditor/s,m24/s,sysext/s,z33lib/s,vlib/s,z3lib/s,syslib/s,zpatch/n/e
  118. ;
  119. ;
  120. ;ZAS/ZLINK:
  121. ;SET SLR EQUATE TO FALSE
  122. ;then
  123. ;ZAS ZPATCH
  124. ;ZLINK ZPATCH,BEDITOR/,M24/,SYSEXT/,z33lib/,VLIB/,Z3LIB/,SYSLIB/
  125. ;
  126. ; If using SLR tools to assemble and link the linking libraries can be 
  127. ; specified within the source program and need not be specified on the 
  128. ; linker command line.  If not using the SLR tools the libraries must be 
  129. ; linked in the same order as given under the .request statement below.
  130. ;
  131. FALSE    EQU    0
  132. TRUE    EQU    NOT FALSE
  133. SLR    EQU    TRUE    ;set false if not using SLR tools
  134.  
  135.     IF    SLR
  136.  
  137. .request BEDITOR,M24,SYSEXT,VLIB,z33lib,Z3LIB,SYSLIB
  138.  
  139.     ENDIF
  140. ;
  141. ; VARIABLES USED TO TRANSMIT DATA BETWEEN THIS PROGRAM AND THE
  142. ; MODULES WITHIN BEDITOR.REL
  143. ;
  144.     GLOBAL    Z3EADR,FCB,OFFS,ABSADR,OUTBUF,FILESIZE,RECNUM
  145.     GLOBAL    BUFBEG,STRADR,DEFDU,SECADR,VERSION
  146. ;
  147. ; VARIOUS CONSTANTS included in a library file.
  148. ;
  149.     INCLUDE    ZPATCH.LIB
  150. ;
  151. ; MACROS needed to accomplish the 24-bit math needed to implement
  152. ; addressing within files longer than 64K
  153. ;
  154.     INCLUDE    MATH24.LIB
  155. ;
  156.     .z80                ;for m80 compatiblity
  157. Z3ENV    ASET    0FE00H
  158. VERS    EQU    13
  159. ;    ORG    100H        ; SRLNK barfs on this and it's really
  160.                 ; unnecessary with any linker if you
  161.                 ; give it the proper commands.
  162. ;
  163. ; environment definition
  164. ;
  165.     IF    Z3ENV NE 0
  166. ;
  167. ; external ZCPR3 environment descriptor
  168. ;
  169. ORIGIN:
  170.     JP    START
  171.     DB    'Z3ENV'        ; this is a ZCPR33 utility
  172.     DB    3        ; type-3 utility
  173. Z3EADR:
  174.     DW    Z3ENV
  175.     DW    ORIGIN
  176. ROOTONLY:            ; true if zpatch.com will be located in
  177.     DB    TRUE        ; root dir:
  178. USEPATH:            ; if rootonly is false, should system search 
  179.     DB    FALSE        ; the path for zpatch.com?
  180. DUSER:                ; if usepath and rootonly are both false
  181.     DB    15         ; make this the user area for ZPATCH.COM
  182. DDRIVE:    DB    0        ; and this the drive
  183. HELPCH:    DB    FALSE        ; TRUE TO ALLOW CHAINING TO HELP FILE
  184. ;
  185. START:
  186.     LD    HL,(Z3EADR)    ; pt to    ZCPR3 environment
  187. ;
  188.     ELSE            ; is this just ritual?  Does anyone know of 
  189.                 ; anyone who uses the internal environmental
  190.                 ; descriptor??????
  191. ;
  192. ; internal ZCPR3 environment descriptor
  193. ;
  194.     MACLIB    Z3BASE.LIB
  195.     MACLIB    SYSENV.LIB
  196. Z3EADR:
  197.     JP    START
  198.     SYSENV
  199. START:
  200.     LD    HL,Z3EADR    ; pt to    ZCPR3 environment
  201.     ENDIF
  202. ;
  203. ; start    of program -- initialize ZCPR3 environment
  204. ;
  205.     CALL    Z3VINIT
  206.     CALL    TINIT
  207. ;
  208. ; Scan the default FCB Area for a help request ('/') 
  209. ;
  210.     LD    A,(FCB1+1)
  211.     CP    '/'        ; Help requested?
  212.     JR    NZ,GSH        ; no, on with it.
  213.     LD    HL,HLPMSG    ; yes, give it and
  214.     JP    STRING        ; abort
  215. ;
  216. ; get shell data
  217. ;
  218. GSH:    CALL    GETSH2        ; is there a shell stack?
  219.     LD    (SHSTK),HL
  220.     JR    Z,SHBAD        ; no, abort
  221.     LD    A,E
  222.     CP    32        ; Is shell stack entry >= 32 bytes?
  223.     JR    NC,SHFINE    ; yes, continue
  224. SHBAD:    LD    HL,SHERR    ; no, so error and abort
  225.     JP    STRING
  226. ;
  227. ; ZPATCH uses a scheme of shell stack management first hinted at by the author
  228. ; in his W.Z80, then developed and carried to its logical conclusion by 
  229. ; Jay Sage.  The author's idea in W was to use the shell stack to hold
  230. ; not, strictly speaking, the command line to be reloaded, but also other
  231. ; information for "taking up where we left off".  This was done, in retrospect,
  232. ; quite clumsily in W -- since we hogged two whole shell stack entries to
  233. ; accomplish the task.  Jay's refinement of this idea was to realize
  234. ; that the shell stack should not contain the whole command line
  235. ; but just enough to get the shell reloaded.  The shell can be written to
  236. ; take care of getting the rest of its information, and what is left 
  237. ; of the shell stack entry can be used to store what information is 
  238. ; necessary in an optimal fashion i.e., an FCB fragment 
  239. ; rather than DIR:FILENAME.TYP.
  240. ;
  241. ; In the case of ZPATCH we are storing, besides the initial command line,
  242. ; the name of the file we are working on in the form of an 11-byte 
  243. ; FCB segment (FILENAMETYP), the DU: spec for this file as a word in the 
  244. ; typical SYSLIB format, and finally our address within that file 
  245. ; as three bytes. To make absolutely certain that there will never be 
  246. ; any overlap we are forced to restrict possible
  247. ; renames of this shell to 6 characters or fewer.  We thus allow for an
  248. ; 8 char named directory entry, a colon, a 6-char command name followed by
  249. ; a null.  That is 16 bytes, leaving 16 in the standard configuration for
  250. ; our other purposes.
  251. ;
  252. ;
  253.  
  254. SHFINE:             ;establish a pointer to the aforementioned
  255.     LD    DE,16        ;FCB segment in the shell stack area
  256.     ADD    HL,DE        ;which is always located at SHSTK+16
  257.     LD    (SHFCB),HL    ;
  258.                 ;must have the extended file control block
  259.                 ;feature implemented so ZPATCH knows the
  260.                 ;name under which it is to be invoked.
  261.     CALL    GETEFCB        
  262.     JR    NZ,SHF2        ;EFCB IS OK
  263.     LD    DE,EFCBERR    ;no EFCB, so error msg and abort
  264. ABORTION:
  265.     JP    STRING
  266. SHF2:    
  267.     LD    DE,7        ;IF THERE IS an EFCB
  268.     ADD    HL,DE        ;IT MUST HOLD A <7 CHAR NAME
  269.     LD    A,(HL)        ;as mentioned above
  270.     CP    ' '        ;SO EFCB+7 MUST HOLD A SPACE
  271.     JR    Z,WHEELT
  272.     LD    HL,NAMERR    ;if >6 chars in the name, error msg
  273.     JR    ABORTION    ;and abort.
  274. ;
  275. ;
  276. ; is user wheel-privileged?
  277. ;
  278. WHEELT:
  279.         CALL    GETWHL
  280.     JR    NZ,ALO        ; WHEEL BYTE OKAY, LET USER GO
  281.     LD    HL,PEONMSG    ; KICK THE SLOB OUT.
  282.     JR     ABORTION
  283. ; now that we have established that we are running on
  284. ; a Z-system that has the features we need and that we have not
  285. ; illegally renamed the program we can go on to do the real work
  286. ; which starts by allocating some variable storage
  287. ;
  288. ALO:
  289.     XOR    A        ; ALLOCATE FREE MEM FROM CODEND 
  290.     CALL    IALLOC        ; TO CCP-1
  291.  
  292.     LD    DE,1024
  293.     CALL    ALLOC
  294.     LD    (OUTBUF),HL    ;1024 byte buffer for hex-dump output
  295.  
  296.     LD    DE,2
  297.     CALL    ALLOC
  298.     LD    (BUFBEG),HL    ;pointer to BLINE input buffer
  299.                 ; initialize this buffer
  300.     LD    (HL),255    ; indicate a 255 byte buffer there
  301.     INC    HL        ; 
  302.     LD    (HL),0        ; initialize counter byte to 0
  303.     LD    DE,512
  304.     CALL    ALLOC        ; 512 bytes for actual buffer
  305.                 ; 256 for input buffer and an
  306.                 ; additional 256 for parsing by the search 
  307.                 ; module
  308.     LD    (STRADR),HL    ; has its own pointer
  309.  
  310.     LD    DE,18        ; another scratch buffer
  311.     CALL    ALLOC
  312.     LD    (SHELBUF),HL    ; 18 bytes long.
  313. ;
  314. ;
  315.     CALL    RETUD        ;get the current du:
  316.     LD    (DEFDU),BC    ;store it away 
  317. ;
  318. ; determine whether to install shell or    not
  319. ;
  320.     CALL    QSHELL        ; is this a call to install shell?
  321.     JR    NZ,CKTCAP    ; yes, go install
  322.                 ; no so prepare to reinvoke.
  323.  
  324. HIERCHEK:            ; check the command level hierarchy
  325.                 ; if anything above shell in priority
  326.                 ; drop out to the CCP and run that first
  327.     CALL    GETCL2        ; command line pending?
  328.     RET    NZ        ; return to CCP
  329.     CALL    GETZRUN        ; zex running?
  330.     RET    NZ        ; return to CCP
  331.     CALL    GETSRUN        ; submit running
  332.     RET    NZ        ; return to CCP
  333.     CALL    SAK        ; our "strike any key" prompt on reinvocation
  334.     LD    HL,(SHFCB)    ; we first move our info off the shell stack
  335.     LD    DE,(FCB)    ; to the locations where ZPATCH normally
  336.     LD    BC,11        ; expects 
  337.     INC    DE
  338.     LDIR            ; to find it
  339.     LD    DE,FILDU    ; storage for DU: of file
  340.     LDI            ; move two bytes off shell stack
  341.     LDI
  342.     LD    DE,ABSADR    ; storage for address within file
  343.     LDI            ; move three bytes off shell stack.
  344.     LDI
  345.     LDI
  346. ;
  347.     JP    RUNSH        ; skip installation of shell
  348. ;
  349. ; install shell
  350. ;
  351. CKTCAP:             ; make sure TCAP is adequate before we get
  352.                 ; into things too deeply.
  353.     CALL    CLS        ; try to clear screen
  354.     JR    Z,BADTCAP    ; Abort if function missing
  355.     LD    HL,0101
  356.     CALL    GOTOXY        ; try to use direct cursor motion 
  357.     JR    NZ,INSTSH    ; OK to continue
  358. BADTCAP:
  359.     LD    HL,TCAPERR
  360.     JP    STRING
  361.  
  362. INSTSH:    
  363.         
  364.     CALL    GETDU
  365.     CALL    SHASM        ; put together the shell stack entry
  366.                 ; and load it on the shell stack
  367.     JP    Z,runsh        ; everything all right
  368.     LD    HL,SHERR    ; No so error msg
  369.     JP    STRING        ; and abort        
  370.  
  371. ;
  372. ; dump the shell and exit
  373. ; Message in DE.
  374. QUIT:                
  375.     CALL    SHPOP        ; take our name    off
  376.     JP    EXIT        ; reset z3 command status and ret to ccp
  377. ;
  378. ; write    string (address given in DE)
  379. ;
  380. STRING:
  381.     CALL    CRLF        ; new line        
  382.     CALL    VPSTR        ; print string
  383.     RET
  384. EXIT:    XOR    A        ; common exit point.  
  385.     CALL    DINIT        ; reset the terminal
  386.     JP    PUTCST        ; reset z3 command status msg and ret to ccp
  387. ;
  388. ; assemble our shell stack entry as described above
  389. SHASM:    
  390.     XOR    A        ; initialize the shell buffer with
  391.     LD    HL,(SHELBUF)    ; nulls        
  392.     PUSH    HL        ; save its beginning
  393.     LD    BC,16
  394.     CALL    LDFIL
  395. ;
  396.     EX    DE,HL        ; put the buffer address in DE.
  397.     CALL    ROOT        ; root directory in BC
  398.     LD    A,(ROOTONLY)    ; is that what we want?
  399.     OR    A        
  400.     JR    NZ,PUTIT    ; nz = yes, no need to search further
  401.     LD    A,(USEPATH)    ; not root only, shall we search
  402.                 ; the path (i.e.) put NO DIR reference
  403.                 ; in front of "ZPATCH"?
  404.     CPL            ; reverse sense
  405.     OR    A        
  406.     JR    Z,PUTFN        ; Z says yes
  407.                 ; no, get user and drive 
  408.     LD    BC,(DUSER)    ; from the patch area    
  409.                 ; now that all params are set we can
  410. PUTIT:    CALL    DUDIRPFX    ; MOVE DIR: or DU: to buffer 
  411. PUTFN:    CALL    GETEFCB        ; EFCB address in HL
  412.     INC    HL        ; we want its FN field 
  413.     CALL    COPY8        ; copy just the file name to buffer
  414.     POP    HL        ; hl holds shstk
  415.     CALL    SHPUSH        ; put it in shellstack
  416.     LD    HL,(FCB)    ; now move our copy of the file's FCB
  417.     INC    HL
  418.     LD    BC,11        ; 
  419.     LD    DE,(SHFCB)    ; to the shell stack        
  420.     LDIR
  421.     LD    HL,FILDU    ; move the file's DU which we've been storing
  422.     LDI            ; to the shell stack
  423.     LDI
  424.     LD    HL,ABSADR    ; and now move our address within the 
  425.     LDI            ; file (thats 3 bytes)
  426.     LDI            ; to shell stack
  427.     LDI
  428.     RET                
  429.  
  430. ;
  431. RUNSH: 
  432.     CALL    DRADIX        ; Install default radix
  433.     CALL    CLS        ; clear the screen
  434.     CALL    ARROWS
  435. ;
  436. ; now evaluate the param in FCB1
  437. ;
  438.     LD    A,(FCB1+1)    ; was a parameter left?
  439.     CP    ' '        ; space means no
  440.     JP    Z,GETFN        ; prompt for a file name
  441. FTOP:                ; entry pt for new file load                    
  442.     LD    BC,(FILDU)
  443.     CALL    LOGUD        ; log into file's DU
  444.     LD    DE,(FCB)
  445.     CALL    F$OPEN        ; open it
  446.     JR    Z,FILEOK    ; OK?
  447. FNF:
  448.     LD    (FILEFLAG),A    ; NO, store that result
  449.     CALL    CLS
  450.     CALL    BMENU        ; present limited menu
  451.     CALL    MESSAGE        ; tell 'em not found
  452.     DB    'File not Found'
  453.     DB    BUZZER,0
  454. LLOOP:    
  455.     CALL    MNURD        ; read user's response
  456. LSEARCH:
  457.     LD    HL,LCTABLE    ; search the limited commands
  458.     JR    CMSLOOP        ; act on it
  459. ;
  460. FILEOK:                ; file opened OK
  461.     LD    (FILEFLAG),A    ;store that result in memory
  462.     CALL    F$READ        ; read the first record            
  463.     PUSH    DE        ; save pointer to FCB
  464.     CALL    OFSFIG        ; calculate beginning offset based on file type 
  465.     LD    (OFFS),HL    
  466.     SUB1624 OFFS,TBUFF    ; store as a 24-bit quantity
  467.     CALL    CLS        ; clear the screen
  468.     POP    DE        ; restore pointer to FCB
  469.     CALL    GETFS1        ; file size in records
  470.     DEC    HL        ; less 1
  471.     LD    (FILESIZE),HL    ; store file's size to memory
  472. ;
  473. ; re entry point for many commands
  474. ;
  475. RDLOOP:                
  476.     CALL    ADRREC        ; convert address to record number
  477. RDLOOP1:
  478.     mov24   OldRecNum,RecNum
  479.     ld    hl,(recnum)    ; put it in HL
  480.     LD    DE,FCB1        
  481.     CALL    R$READ        ; read that record from the file randomly
  482. EDLOOP:    
  483.     LD    HL,TBUFF    ; 80H in HL    
  484.     CALL    HEXDMP        ; dump the sector into memory
  485.     CALL    DISPLAY        ; put it on the screen
  486. EDLOOP1:
  487.     CALL    SHOWBYTE    ; highlight current byte
  488.     CALL    MENU        ; show the menu
  489.  
  490. FLOOP:    
  491.     CALL    MNURD        ; read user choice
  492. CMSEARCH:
  493.     LD    HL,CMTABLE    ; full command list
  494. CMSLOOP:
  495.     LD    B,A        ; store user choice away
  496.     LD    A,(HL)        ; get table choice
  497.     OR    A        ; is it null? (end of table)
  498.     LD    A,B        ; first restore user choice to A
  499.     JR    Z,CMDRET    ; not null so do it again
  500.     CP    (HL)        ; compare user input to table entry
  501.     INC    HL        ; move to routine address
  502.     JR    z,MATCH        ; if equal, process command
  503.     INC    HL        ; unequal, bump the pointer
  504.     INC    HL
  505.     JR    CMSLOOP        ; and check next table entry
  506. ;
  507. CMDRET:                ; user choice not in table    
  508.     LD    A,(FILEFLAG)    ; working with an open file?
  509.     OR    A    
  510.     JR    Z,FLOOP        ; yes, process full menu
  511.     JP    LLOOP        ; no, process limited menu
  512. ;
  513. MATCH:                ; user input matches table entry
  514.     LD    E,(HL)        ; low byte in E
  515.     INC    HL
  516.     LD    D,(HL)        ; high byte in D
  517.     EX    DE,HL        ; move it to HL
  518.     JP    (HL)        ; go to it
  519. ;
  520. ; table of commands in format:
  521. ; db    command letter     
  522. ; dw    command address
  523. ;
  524. CMTABLE:            
  525.     db    '>'        
  526.     dw    FORWARD
  527.     db    '.'
  528.     dw    FORWARD
  529.     db    '<'
  530.        dw    BACK    
  531.     db    ','
  532.     dw    BACK
  533.     db    'A'
  534.     dw    ADDRESS
  535.     db    'B'
  536.     dw    BOTTOM
  537.     db    'C'
  538.     dw    CALLCONT
  539.     db    'E'
  540.     dw    ENTRED
  541.     db    'O'
  542.     dw    CHOFFSET
  543.     db    'P'
  544.     dw    PRINTSEC
  545.     db    '#'
  546.     dw    RECFIND
  547.     db    'S'
  548.     dw    CALLSCH
  549.     db    'T'
  550.     dw    TOP
  551.     db    'W'
  552.     dw    WRITE
  553. UpArrow:
  554.         db    'E'-'@'
  555.     DW    UP16
  556. DownArrow:
  557.     db     'X'-'@'
  558.     DW    DOWN16
  559. LeftArrow:
  560.     db    'S'-'@'
  561.     DW    UP1
  562. RightArrow:
  563.     db    'D'-'@'
  564.     DW    DOWN1
  565. LCTABLE:            ; limited command table entry point
  566.     db    'X'-'@'        ; quit with either ^Q
  567.     dw     QUITZP    
  568.     db    'X'        ; or Q
  569.     dw     QUITZP    
  570.     db    'F'
  571.     dw    GETFN
  572.     db    'H'
  573.     dw    HELP
  574.     db    'R'
  575.     dw    XECUTE
  576.     db    'Z'
  577.     dw    ZCPR3
  578.     db    0        ; indicated end of command table
  579. ;
  580. ENTRED:                ; entry and exit from editor
  581.     CALL    EDITOR    
  582.     PUSH    AF        ; save carry flag which indicates write or no        
  583.     CALL    CLS
  584.     CALL    GXYMSG
  585.     DB    23,5
  586.     DB    "Written",0    ; in either case this goes to screen
  587.     POP    AF        ; now get carry flag
  588.     JP    C,WRITE        ; if carry, write to disk
  589.     CALL    GXYMSG        ; we didn't want a write
  590.     DB    23,1        
  591.     DB    "Not",0        ; so preface "Written" with "Not"
  592.     JP    EDLOOP        ; go back to command menus
  593. ;
  594. QUITZP:                ; close the file and quit the shell
  595.     CALL    CLOSEF
  596.     CALL    CLS        ; leave a cleam slate
  597.     JP    QUIT
  598. ;
  599. FORWARD:            ; move forward one sector
  600.     LD    HL,(RECNUM)
  601.     INC    HL        ; add 1 to current record number
  602.     LD    DE,(FILESIZE)    
  603.     CALL    COMPHD        ; past EOF?
  604.     JR    Z,EXITBF    ; no, so go there
  605.     JR    C,EXITBF    ; no, so go there
  606.                 ; yes fall through to next routine
  607. ;
  608. TOP:                ; move to the beginning of file
  609.     LD    HL,0        ; record # 0
  610.     JR    EXITBF        ; go there
  611. ;
  612. BACK:                ; move back one sector
  613.     LD    HL,(RECNUM)
  614.     LD    A,H        ; are we BOF?
  615.     OR    L
  616.     JR    Z,BOTTOM    ; yes, go to EOF.
  617.     DEC    HL        ; no, just subtract 1 from recnum
  618.     JR    EXITBF        ; and go there
  619. BOTTOM:    LD    HL,(FILESIZE)    ; get last record of file
  620.     
  621. EXITBF:                ; common exit point for all movement routines
  622.                 ; desired record number is in HL
  623.     LD    (RECNUM),HL    ; store it in HL
  624.     CALL    RECADR        ; readjust address within file
  625.     JP    RDLOOP        ; show new record and get next user input
  626. ;
  627. WRITE:                ; write sector to disk
  628.     LD    DE,FCB1
  629.     LD    HL,(RECNUM)
  630.     CALL    R$WRITE
  631.     JP    EDLOOP        ; get next user input
  632. ;
  633. PRINTSEC:            ; write sector to LST: device
  634.     LD    HL,INFOMSG    ; banner line
  635.     CALL    VLPSTR        ; to printer
  636.     LD    HL,(OUTBUF)    ; hex dump
  637.     CALL    VLPSTR        ; to printer
  638.     JP    FLOOP        ; get next response
  639. ;
  640. CHOFFSET:            ; get new offset value from user
  641.     CALL    MESSAGE
  642.     DB    'Enter new offset: ',0
  643.     LD    DE,OFFS
  644.     CALL    NUMINP        ; input a number and store in OFFS
  645.     SUB1624 OFFS,TBUFF    ; subtract 80H for actual DMA address
  646.     JP    EDLOOP        ; display screen anew and get response
  647.  
  648. UP1:    
  649.     DEC24    numbuf
  650.     JR    ADDR0
  651. DOWN1:
  652.     INC24    numbuf
  653.     JR    ADDR0
  654. UP16:    SUB1624 numbuf,16
  655.     JR    ADDR0
  656. DOWN16: ADD1624 numbuf,16
  657.     JR    ADDR0    
  658. ADDRESS:            ; get address to show from user
  659.     CALL    MESSAGE
  660.     DB    'Enter address: ',0
  661.  
  662.     ld    de,numbuf    
  663.     CALL    NUMINP        ; input a number
  664.     sub1624 numbuf,tbuff    ; adjust for actual DMA address
  665.     sub24    numbuf,offs    ; adjust for offset
  666. ADDR0:  CALL    UNSHOWB
  667.     ld    de,numbuf
  668.     ex    de,hl
  669.     ld    a,(hl)
  670.     push    af        ;save lowest byte of numbuf
  671.     ld    b,7        ;convert to a record number value
  672. ALP:    call    halve24        ;by halving 7 times
  673.     djnz    alp
  674.     push    hl        ;save this value
  675.     ld    de,(numbuf)
  676.     ld    hl,(filesize)
  677.     call    comphd
  678.      pop    hl
  679.     pop    bc        ;lowest byte of numbuf in b
  680.     ld    a,b        ;in a
  681.     JR    C,ADDR1X    ; filesize<numbuf=out of range
  682. ADDR1:                ; NO carry = address OK
  683.     ld    b,7        ;convert back to a file address
  684. a1lp:   call    double24    ; by doubling seven times
  685.     djnz    a1lp
  686.     or    (hl)        ; or low byte with original low byte now
  687.                 ; in a
  688.     ld    (hl),a        ; put it back in numbuf
  689.     mov24    absadr,numbuf    ; this is the new address within file
  690. ADDR1A:
  691.     call     ADRREC
  692.     PUSH    HL
  693.     LD    HL,OldRecNum
  694.     LD    DE,RecNum
  695.     LD    B,3
  696. COMP:   LD    A,(DE)
  697.     CP    (HL)
  698.     JR    NZ,NUREC    ; yes, they're different, must read
  699.     INC    DE
  700.     INC    HL
  701.     DJNZ    COMP
  702.     POP    HL        ; no,they're the same, don't read
  703.     JP    EDLOOP1
  704. NUREC:  
  705.     POP    HL
  706.     JP    RDLOOP1        ; address OK, get it and dump it
  707. ;
  708. ADDR1X:    CALL    MESSAGE        ; address out of range
  709.     DB    'Address ',0    ; tell em so
  710.     PUSH    HL
  711.     LD    HL,OOR
  712.     CALL    VPSTR
  713.     POP    HL
  714.     CALL    EREOL        ; clear rest of line
  715.     JP    FLOOP        ; get next input from user
  716. ;
  717. RECFIND:            ; go to record
  718.     CALL    RADIX
  719.     DB    10        ; get this one in decimal 
  720.     CALL    MESSAGE
  721.     DB    'Enter Record # ',0
  722.     LD    DE,NUMBUF
  723.     CALL    NUMINP        
  724.     CALL    DRADIX        ; put back default hex radix
  725.     LD    HL,(NUMBUF)
  726.     DEC    HL            ; computers like 0..n-1, humans 1..n 
  727.     LD    DE,(filesize)
  728.     INC    DE
  729.     CALL    COMPHD        ; beyond EOF?
  730.     JR    NC,TOOBIG    ; 
  731.     LD    (RECNUM),HL    ; yes, so give error message
  732.     CALL    RECADR        ; no, convert to address
  733.     JR    ADDR1A        ; get it and dump it
  734. TOOBIG:    CALL    MESSAGE        ; tell em bad news
  735.     DB    'Record # ',0
  736.     CALL    VPRINT
  737. OOR:    DB    'out of range',buzzer,0
  738.     CALL    EREOL
  739. ADDR2:    JP    FLOOP        ; get next command
  740. ;
  741. ; Search routine dispatch and evaluation
  742. ;
  743. CALLCONT:            ; entry pt for continue command
  744.     CALL    CONTINU        ; do it
  745.     JR    EVALSCH        ; evaluate results
  746. CALLSCH:            ; entry point for search command
  747.     CALL    MESSAGE        ; get search string        
  748. SMSG:
  749.     DB    'Enter Search String: ',0
  750.     CALL    VPRINT
  751.     DB    '(or ? for Help) ',0
  752.     LD    HL,(BUFBEG)
  753.     XOR    A
  754.     CALL    BLINE        ; read search string from user
  755.     OR    A        ; if no input, don't search
  756.     JR    Z,NULLEXIT
  757.     LD    A,'?'        ; '?' in first char = help request
  758.     CP    (HL)        ; help request?
  759.     JR    NZ,DOSCH    ; NO, process as search string
  760.     CALL    CLS        ; YES, clear screen
  761.     LD    HL,SRCHMSG    ; print help    
  762.     CALL    VPSTR
  763.     CALL    AT
  764.     DB    23,1        ; re-prompt (without or ? for help)
  765.     LD    HL,SMSG
  766.     CALL    VPSTR
  767.     LD    HL,(BUFBEG)    ; try again
  768.     xor    a        ; don't capitalize input 
  769.     CALL    BLINE        ; get input
  770.     OR    A        ; if no input, don't search
  771.     JR    NZ,DOSCH
  772.     CALL    CLS
  773.     JR    NX2 
  774. DOSCH:
  775.     CALL     SEARCH        ; look for it
  776. EVALSCH:
  777.     PUSH    AF        ; save flags
  778.     CALL    DRADIX        ; put default radix back
  779.     CALL    CLS        ; clear screen after possible help request
  780.     POP    AF        ; return flags
  781.     CALL    REACTION    ; react to em
  782.     JP    RDLOOP
  783. NULLEXIT:
  784.     CALL    MESSAGE
  785.     DB    0
  786. NX2:    JP    EDLOOP        ; and return for more
  787. ;
  788. REACTION:            ; respond to flags returned by search routine
  789.     JR    Z,MATCHED    ; Z = matched or aborted
  790. NOMATCH:            ; NZ = bad search string or not found
  791.     JR    C,BADSTMSG    ; carry = bad string
  792.     CALL    MESSAGE        ; not carry = not found
  793.     DB    'String not found',0  ;tell'em
  794.     RET
  795. BADSTMSG:
  796.     CALL    MESSAGE        ; bad search string
  797.     DB    'Search String Error',buzzer,0  
  798.     RET
  799. MATCHED:            ; matched or aborted
  800.     JR    C,ABORTED    ; carry = aborted
  801.                 ; NC = must be a match
  802.     mov24    numbuf,absadr   ; convert address for display purposes
  803.     add24    numbuf,offs    ; adjust for offset
  804.     add1624 numbuf,tbuff    ; adjust for DMA address
  805.     CALL    MESSAGE        
  806.     DB    'Found at ',0    ; tell 'em good news
  807.     ld    a,(numbuf+2)    ; highest byte
  808.     ld    hl,(numbuf)    ; lowest 2 bytes
  809.     CALL    pa2hc        ; print high
  810.     CALL    phl4hc        ; print lowest 2
  811.     RET
  812. ;
  813. ABORTED:
  814. ;    EX    DE,HL        ; old address within file to HL
  815.     CALL    MESSAGE
  816.     DB    'Search aborted ',0
  817.     RET
  818. ;
  819. GETFN:                ; get new file name from user
  820.     CALL    MESSAGE
  821.     DB    'Enter File Name: ',0
  822.     LD    HL,(BUFBEG)
  823.     CALL    BLINE         ; get user input
  824.     OR    A
  825.     JP    Z,NULLEXIT    ; don't perform function if no input
  826.     LD    A,(FILEFLAG)    ; see if a file is open before we
  827.     OR    A        ; try to close it
  828.     JR    NZ,GFN1        ; none open, none to close
  829.     CALL    CLOSEF        ; gotta close open file
  830. GFN1:    LD    DE,(FCB)    
  831.     CALL    ZFNAME        ; parse it as Z would    
  832.     CALL    GETDU        ; 
  833.     XOR    A
  834.     LDfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlfor "nlGE
  835.     DB    0        ; clear message line
  836. diffHL,(Sumbuf)F)
  837.     CALL    VPSTR        ; print our desit
  838.                 ; now we read cmdline
  839.     LD    HL,(BUFBEG)
  840.     CALL    BLINE     to but input
  841.     OR    A
  842.     JP    Z,NULLEXIT
  843. CMDINP2:
  844.     LD    A,(HL)        ;look at first char of our command FN:CP    '$'        ; a '$'    ; 
  845.     10    PUTMCL1    ;no, just move it to mcl
  846.     PUSH    HL        ;yes, save this loc
  847. ;
  848. ; comve l 7-bits in type field of FCB to see if it's a .COM file
  849. ;
  850.     LD    HL,COM        ; is it a .COM file?
  851.     LD    DE,FCB1+9    
  852.     CALL    SEVENB
  853.     POP    HL        ; get beginning of buffer
  854.     JR    NZ,S iCOM    ; no, tell em they can't do that
  855.     LD    DE,256        ; make a new buffer (space already allocated)
  856.     ADD    HL,DE
  857.     PUSH    HL
  858.     EX    DE,HL        ; new buffer address in DE
  859.     CALL    RETUD        ; DU in # '
  860.     CALL    DUDIRPFX    ; prefix it4hDU: or DIR: as proper
  861.     LD    HL,FCB1+1    
  862.     CE 0PY8     devove file name from FCB until ' ' or 8 chars
  863.     LD    HL,(STRADR)    
  864.     INC    HL        ;mpt one byte past the '$'
  865. NLOOP:
  866.     LD    A,(HL)        ; keep moving byte until null found 
  867.     OR    A
  868.     LDI
  869.     JR    NZ,NLOOP
  870. ;                
  871. PUTMCL:    POP    HL        ; buffer address
  872. PUTMCL1:
  873.     CALL    CLOSEF        ; close the file
  874. PMCL2:    CALL    PUTCL        ; put it in z3 command buffer
  875.  
  876. ZEXIT:    JP    EXIT        ; and leave shell (temporarily)
  877. ;
  878. XECUTE:                ; Execute the file if it is a .COM file
  879.                 ; handle as if user chose Z and responded
  880.                 ; with '$' alone.  saves code to do this way.
  881.     CALL    REPUTML        ; reload the shell stack4hneprogram nein
  882.     LD    BC, the mOLLAR)    ; move '$',0 to input buffer
  883. diffHL,(STRADR)
  884.     LD    (HL),C
  885.     INC    HL
  886.     LD    (HL),B
  887.     DEC    HL
  888.     JR    CMDINP2        ; and process as user input
  889. DOLLAR:
  890.     DB    '$',0
  891. ;    
  892. NONCOM:             ; not a com file
  893.     CALL    MESSAGE
  894.     DB    'not a .COM file',0
  895.     LD    A,(FILEFLAG)        ; have we an open file?
  896.     OR    A
  897.     JP    NZ,LLOOP        ; no, only have limited menu
  898.     JP      FLOOP            ; yes, do full menu
  899. ;
  900. HELP:                    ; help command
  901.     LD    A,(HELPCH)        ; don't do it if help not enabled
  902.     OR    A
  903.     JP    Z,CMDRET
  904.     CALL    REPUTML            ; okay to do it
  905.     LD    HL,HELPCMD
  906.     PUSH    HL
  907.     JR    PUTMCL            ; put help into multi-command buffer
  908. HELPCMD:
  909.     DB    "HELP ZPATCH",0
  910.  
  911. ;
  912. ; full menu if file opened successfully
  913. ;
  914. MENU:
  915.     CALL    GXYMSG
  916.     DB    14,10
  917.     DB    HV,'E',LV,'dit',0
  918.     CALL    GXYMSG
  919.     DB    14,50
  920.     DB    HV,'W',LV,'rite to disk',0
  921.     CALL    GXYMSG
  922.     DB    15,5
  923.     DB    HV,'<',LV,' or ',HV,',',LV,' - back one sector',0
  924.     CALL    GXYMSG
  925.     DB    15,45
  926.     DB    HV,'>',LV,' or ',HV,'.',LV,' - forward one sector',0
  927.     CALL    GXYMSG
  928.     DB    16,10
  929.     DB    HV,'T',LV,'op of file',0
  930.     CALL    GXYMSG
  931.     DB    16,50
  932.     DB    HV,'B',LV,'ottom of file',0
  933.     CALL    GXYMSG
  934.     DB    17,5
  935.     DB    LV,'Goto ',HV,'A',LV,'ddress',0
  936.     CALL    GXYMSG
  937.     DB    17,45
  938.     DB    'Goto ',HV,'#',LV,'of record',0
  939.     CALL    GXYMSG
  940.     DB    18,10
  941.     DB    HV,,'P',LV,'rint sector',0
  942.     CALL    GXYMSG
  943.     DB    18,43
  944.     DB    LV,'Change ',HV,'O',LV,'ffset',0
  945.     CALL    GXYMSG
  946.     DB    19,10
  947.     DB    HV,'S',LV,'earch',0
  948.     CALL    GXYMSG
  949.     DB    19,50
  950.     DB    HV,'C',LV,'ontinue search',0
  951. ;
  952. ; limited menu if file not open
  953. ;
  954. BMENU:
  955.     CALL    GXYMSG
  956.     DB    20,9
  957.     DB    LV,'e',HV,'X',LV,'it',0
  958.     CALL    GXYMSG
  959.     DB    20,45
  960.     DB    LV,'Give ',HV,'F',LV,'ile Name',0
  961.     CALL    GXYMSG
  962.     DB    21,10
  963.     DB    HV,'R',LV,'un .COM file',0
  964.     CALL    GXYMSG
  965.     DB    21,50
  966.     DB    HV,'Z',LV,'CPR3 command',2,    DBD    A,(HELPCH)
  967.     OR    A
  968.     RET    Z
  969.     CALL    GXYMSG
  970.     DB    21,30
  971.     DB    HV,'H',LV,'elp',2,0
  972.     RET
  973. ;
  974. MNURD:    CALL    GXYMSG
  975.     DB    22,30        ; clear any previous input
  976.     DB    ' ',8,0
  977.     CALL    CIN        ; get neprogram nput from user
  978.     CALL    CAPS        ; capitalize it
  979.     PUSH    AF        ; save input
  980.     CALL    MESSAGE        ; after input is read...
  981.     DB      0            ; clear MESSAGE LINE
  982.     MOV24    numbuf,absadr
  983.     POP    AF        ; restore input
  984.     RET        
  985. ;
  986. ; CONVERT AN ABSOLUTE FILE BYTE ADDDECS INTO A RANDOM RECORD NUMBER
  987. ;
  988. ADRREC:
  989.     MOV24    NUMBUF,ABSADR
  990.     LD    HL,NUMBUF
  991.     LD    B,7
  992. ADRRCLP:
  993.     CALL    HALVE24
  994.     DJNZ    ADRRCLP
  995.     MOV24    RECNUM,NUMBUF
  996.     RET
  997. ;
  998. ; CONVERT A RANDOM RECORD NUMBER INTO AN ABSOLUTE FILE BYTE ADDRESS 
  999. RECADR:
  1000.     MOV24    NUMBUF,RECNUM
  1001.     LD    HL,NUMBUF
  1002.     LD    B,7
  1003. RCADRLP:
  1004.     CALL    DOUBLE24
  1005.     DJNZ    RCADRLP
  1006.     MOV24    ABSADR,NUMBUF
  1007.     RET
  1008. ;
  1009. GETDU:                    ; routine for getting afor ": spec from
  1010.                     ; an FCB.
  1011.     LD    BC,(DEFr i        ; start with the DEFAULT DU:
  1012.     LD    HL,(FCB)        ; FCB addr in HL
  1013.     LD    A,(HL)            ; 1st byte into A
  1014.     OR    A            ; is it 0    ; 
  1015.         Z,DEFA            ; yes, use default
  1016.     DEC    A            ; no decrease by one
  1017.     LD    B,A            ; and put in B.
  1018. DEFA:
  1019.         LD    DE,13            ; go to Z3 user # area of FCB
  1020.     ADD    HL,DE            
  1021.     LD    A,(HL)            ; into A
  1022.     LD    C,A            ; and C
  1023.     LD    (FILr i,BC        ; storename in enteU
  1024.     RET    
  1025.     
  1026. ;
  1027. ; Figure the offset to use for .COM files, and all ZCPR3
  1028. ; system segments
  1029. ;
  1030. OFSFIG:            
  1031.     LD    IX,(Z3EADR)    ; ENV ptr
  1032.     LD    DE,FCB1+9
  1033. TSTCOM:    LD    HL,COM        ; .COM file
  1034.     CALL    SEVENB
  1035.     JR    NZ,TSTENVCONTo, move on to next
  1036.     LD    A,(88H)        ; first record has been read into 80H0        3        ; check type-byte for Z33 type-3 .COM file        
  1037.     LD    HL,100H        ; offset is 100H
  1038.     RET    NZ        ; not z33 type 3, use default
  1039.     LD    HL,(8BH)    ; offset read from the file
  1040.     RET
  1041. ;
  1042. TSTENV:                ; A Z3 environmental descriptor?
  1043.     LD    HL,Z3EADR-4
  1044.     CALL    SEVENB
  1045.     JR    NZ,TSTZ3T    ; no, move on to next
  1046.     LD    HL,(Z3EADR)    ; yes, offset IS (z3eadr)
  1047.     RET
  1048. ;
  1049. TSTZ3T: LD    HL,Z3T        ; A z3 terminal descriptor?
  1050.     CALL    SEVENB
  1051.     JR    NZ,TSTRCP    ; no, move on to next
  1052.     LD    HL,(Z3EADR)
  1053.     LD    DE,80H
  1054.     ADD    HL,DE        ; ENV PTR + 80H= terminal descriptor ptr
  1055.     RET
  1056. ;
  1057. TSTRCP: LD    HL,RCP        ; A z3 Resident command package?
  1058.     CALL    SEVENB
  1059.     JR    NZ,TSTIOP    ; no, move on to next
  1060.     LD    L,(IX+0CH)    ; get offset from ENVIRONMENT DESCRIPTOR
  1061.     LD    H,(IX+0DH)
  1062.     RET        
  1063. ;
  1064. TSTIOP:    LD    HL,IOP        ; A z3 input-output package?
  1065.     CALL    SEVENB
  1066.     JR    NZ,TSTFCP    ; no, move on to next
  1067.     LD    L,(IX+0FH)    ; get offset from ENVIRONMENT DESCRIPTOR
  1068.     LD    H,(IX+10H)
  1069.     RET
  1070. ;
  1071. TSTFCP:    LD    HL,FCP        ; A z3 flow-command package?
  1072.     CALL    SEVENB
  1073.     JR    NZ,TSTNDR    ; no, move on to next
  1074.     LD    L,(IX+12H)    ; get offset from ENVIRONMENT DESCRIPTOR
  1075.     LD    H,(IX+13H)
  1076.     RET
  1077. ;
  1078. TSTNDR: LD    HL,NDR        ; A z3 named directory file?
  1079.     CALL    SEVENB        
  1080.     JR    NZ,DEFTO0    ; no, use default
  1081.     LD    L,(IX+15H)    ; get offset from ENVIRONMENT DESCRIPTOR
  1082.     LD    H,(IX+16H)
  1083.     RET
  1084. DEFTO0:    LD    HL,0
  1085.     RET
  1086. ;
  1087. ; 7 bit comparison of three-byte buffers
  1088. ;
  1089. SEVENB:    PUSH    DEFCB
  1090.     0303H    ; b=3 controls loop, c=3 to adjust for cpi's
  1091. SEVENLP:
  1092.     LD    A, the mE)        ; get byte in A
  1093.     INC    DE        ; point to next
  1094.     AND    07FH        ; strip high bit0    I            ; comve l and increment HL
  1095.     JR    NZ,SLPXT    ; not same, exit with nz flag
  1096.     DJNZ    SEVENLP        ; else exit is with z flag
  1097. SLPXT:    POP    DE    
  1098.     RET
  1099. ;
  1100. ; CLOSE FILE AND DECET USER AREA BEFORE EXITING
  1101. ;
  1102. CLOSEF:    LD    DE,(FCB)
  1103.     CALL    F$CLOSE
  1104.     LD    BC,(DEFr i,,OGUD
  1105.     RET
  1106. ;    
  1107. ; reset the default (HEX) radix
  1108. ;
  1109. DRADIX:    CALL    RADIX
  1110.     DEFB    16    ; 16=hex,10=dec,2=bin others default to decimal
  1111.     RET
  1112. ;
  1113. ; initialize arrow key values in command table from TCAP
  1114. ; if unsupported leave with WS keys as default
  1115. ;
  1116. ARROint f:
  1117.     LD    HL,(Z3EADR)
  1118.     LD    DE,90H
  1119.     ADD    HL,DE
  1120.     LD    A,(HL)
  1121.     OR    A
  1122.     RET    Z
  1123.     LD    (UpArrow),A
  1124.     INC    HL
  1125.     LD    A,(HL)
  1126.     LD    (DownArrow),A
  1127.     INC    HL
  1128.     LD    A,(HL)
  1129. diff(RightArrow),A
  1130.     INC    HL
  1131.     LD    A,(HL)
  1132. diff(LeftArrow),A
  1133.     RET
  1134. ;
  1135. ; CLEAR OFF THE OLD SHELL STACK ENTRY, REASSEMBLE A NEW ONE
  1136. ; PUT ON PUTML STACK
  1137. ;
  1138. RESHELL:
  1139.     CALL    SHPOP
  1140.     CALL    SHASM        ; shell stack reassembly and loading
  1141.     RET
  1142. ;
  1143. HLPMSG: DB    'ZPATCH [du:]FILENAME.TYP',0
  1144. SHERR:    DB    'Shell Stack Error',0
  1145. EFCBERR:DB    'Ext. FCB Error',0
  1146. NAMERR: DB    "Why did you rename ZPATCH?",0
  1147. TCAPERR:
  1148.     DB    'Inadequate TCAP',0
  1149. PEONMSG:
  1150.     DB    "Can't run ZPATCH w/o wheel privileges",0
  1151. SHSTK:  DW    0
  1152. SHFCB:    DW    0
  1153. comvUF:DW    0
  1154. ;
  1155. COM:    DB    'COM'            ;command file extent
  1156. ENV:    DB    'ENV'            ;Z3 system segments
  1157. RCP:    DB    'RCP'            ;"     "       "
  1158. IOP:    DB    'IOP'            ;"     "       "
  1159. FCP:    DB    'FCP'            ;"     "       "
  1160. NDR:    DB    'NDR'            ;"     "       "
  1161. Z3T:    DB    'Z3T'            ;"     "       "
  1162. S iAME: DB    'Noname '
  1163. FILEFLAG:                ; flag so program knows if it has
  1164.     DB    0FFH            ; open file or not.  DEFAULT NO.
  1165. ;
  1166. ; Search help screen
  1167. ;
  1168. SRCHMSG:
  1169.     DB    2,"SEARCH SYNTAX:",CR,LF,CR,LF,1
  1170.     DB    '"ASCII stringto C',CR,LF
  1171.     DB    'HEX bytes and ASCII string units delimited by commas',CR,LF 
  1172.     DB    '"Steven" = "S",74,"ev",65,6e',CR,LF,CR,LF
  1173.     DB    'Options at end after semicolon',CR,LF,2
  1174.     DB    ' N P,1,' - start at beginning (else from present pos)',2,CR,LF
  1175.     DB    ' B',1,' - backward search',2,CR,LF
  1176.     DB    ' M',1,' - AND mask byte *',2,CR,LF
  1177.     DB    ' S',1,' - skip * occurrences',2,CR,LF
  1178.     DB    ' U',1,' - upper=lower',2,CR,LF
  1179.     DB    ' 7',1,' - 7-bit search',1,CR,LF,CR,LF
  1180.     DB    '   * = input after desit',CR,LF,CR,LF
  1181.     DB    'e.g. "Steven";b7u -> 7-bit backward search '
  1182.     DB    'w/o regard to caps',CR,LF,CR,LF
  1183.     DB    '^C to abort search',2,0
  1184. ;
  1185. NUMBUF:    M24BQ            ; numeric scratch buffer
  1186. enteU:  DW    0
  1187. ; the byte LINE and the following pointers are all externals
  1188. ;
  1189. LINE::                ; line on which screen display of sector starts
  1190.     DB    5
  1191. FCB::    
  1192.     DW    FCB1        ; address of FCB of edited file
  1193. OFFS::                ; offset of apparent vs absolute address
  1194.     M24Bresttt; a 24-bit quantity 
  1195. ABSADR::            ; address within file
  1196.     M24Bresttt; a 24-bit quantity 
  1197. OUTBUF::             ; address of screen dump output
  1198.     DW    0
  1199. FILESIZE::            ; size of file in sectors 
  1200.     DW    0
  1201. RECNUM::            ; current record number
  1202.     M24Bresttt; a 24-bit quantity 
  1203. OldRecNum:
  1204.     DB    0FFH,0FFH,0FFH
  1205. BUFBEG:: 
  1206.     DW    0        ; pointer to BLINE buffer
  1207. STRADR::
  1208.     DW    0        ; pointer to actual input of bline buffer
  1209. DEFDU::
  1210.     DW    0        ; storage for defualt DU:
  1211. SECADR::
  1212.     DW    TBUFF       devemory address of edited sector
  1213. VERSION::
  1214.     DB    (VERS mod 10)+30H
  1215.     DB    (VERS/10)+30H
  1216. ;
  1217.     END
  1218.                      ; have we changed record numbers?
  1219.