home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols200 / vol276 / zex.mac < prev    next >
Text File  |  1994-07-13  |  42KB  |  1,959 lines

  1.     .Z80
  2.     ASEG
  3. ;
  4. ;
  5. ;  program:  zex
  6. ;  author:  richard conn (derived from ex, which was written by someone else)
  7. ;  version:  3.0
  8. ;  date:  8 mar 84
  9. ;  previous versions:  none
  10. ;
  11. ;Modified by Bob Logan for assembly by M80 & Z80 codes 25/4/85
  12. ;
  13. VERS    EQU    30
  14. ZEXADR    EQU    0DB00H    ;address of zex running module CHANGE THIS to suit 
  15. ; uour own system (needs to be 400h below ZCPR3)
  16. ;
  17. ; zcpr3 definitions
  18. ;
  19.     MACLIB    Z3BASE.LIB
  20.  
  21. ;
  22. ;  offsets to zcpr3 environment descriptor elements
  23. ;
  24. EPOFF    EQU    9    ;external path data
  25. MCOFF    EQU    24    ;command line data
  26.  
  27. ;
  28. ;  general equates
  29. ;
  30. BELL    EQU    7
  31. CTRLZ    EQU    1AH    ;^z
  32. DELAY    EQU    6000H    ;delay constant for timer loop
  33. BS    EQU    'H'-'@'    ;backspace
  34. CR    EQU    0DH
  35. LF    EQU    0AH
  36.  
  37. ;
  38. ;  zex monitor command bytes
  39. ;
  40. PSUP    EQU    80H    ;^. print suppress flag
  41. IMON    EQU    81H    ;^< immediate mode start
  42. IMOFF    EQU    82H    ;^> immediate mode stop
  43. MSUP    EQU    83H    ;^# zex message suppress flag
  44. CRWAIT    EQU    84H    ;^? zex runtime wait for cr flag
  45. REXEC    EQU    85H    ;^: zex runtime re-execute flag
  46. CRBWAIT    EQU    86H    ;^/ zex runtime ring bell and wait for cr flag
  47. RNG    EQU    87H    ;^* ZEX RUNTIME RING BELL
  48. UICH    EQU    88H    ;^" user input command char sequence
  49. IPS    EQU    89H    ;^& false if print suppress
  50. ;
  51. ;  cp/m constants
  52. ;
  53. WARM    EQU    0
  54. BDISK    EQU    4
  55. BDOS    EQU    5
  56. DFCB    EQU    5CH
  57. BUFF    EQU    80H
  58.  
  59. ;    start of zex initiator code segment
  60.  
  61.     ORG    100H
  62. ;    .PHASE    100H
  63.  
  64. ; external ZCPR3 Environment Descriptor
  65.  
  66.     JP    start
  67.     db    'Z3ENV'        ;this is a ZCPR3 Utility
  68.     db    1        ;external Environment Descriptor
  69. z3eadr:
  70.     dw    z3env
  71. start:
  72.     LD    HL,(z3eadr)    ;pt to ZCPR3 environment
  73.  
  74. ; start of Program -- Initialize ZCPR3 Environment
  75.  
  76.     call    z3init        ;initialize the ZCPR3 Env
  77.     JP    START0
  78. ;
  79. ;  initial command line area
  80. ;
  81.     DB    0FFH        ;size of command line
  82. DBUFF:    DB    0FFH        ;size of buffer
  83.     DS    100H        ;space for command line
  84. ;
  85. ;  start of zex
  86. ;
  87. START0:
  88.     DB    0        ;replaced with ret to prevent reentry
  89.     LD    A,(DFCB+1)    ;check for help request
  90.     CP    '/'        ;help?
  91.     JP    Z,HELP
  92.     LD    (CCPSTK),SP    ;ccp stack ptr
  93.     LD    SP,CCPSTK    ;user stack area
  94.     LD    A,0C9H        ; (8080 ret)
  95.     LD    (START),A    ;prevent re-entrance by zcpr
  96.     LD    HL,BUFF        ;copy input line into dbuff
  97.     LD    DE,DBUFF
  98.     LD    BC,128        ;size of buffer
  99.     LDIR
  100.     LD    DE,SIGNON    ;logo
  101.     CALL    PRINT
  102.     CALL    ZEXACTV        ;check for recursion
  103.     CALL    ZRELOC        ;relocate zex module
  104.     CALL    ZPARMS        ;extract parameters from command line
  105.     LD    A,(DFCB+1)    ;check to see if sub file present
  106.     CP    ' '        ;<sp>=no
  107.     PUSH    AF        ;save flag
  108.     CALL    NZ,OPENSB    ;open and load zex file if present or abort
  109.     POP    AF        ;get flag
  110.     CALL    Z,INPUTSB    ;input commands from user
  111. ;
  112. ;  hl now points to byte after loaded text
  113. ;
  114.     CALL    ZMCL        ;store rest of multiple command line
  115.     CALL    ZLINES        ;copy and process command lines
  116. ;
  117. ;  set up for zex execution and run; hl pts to bottom of data area
  118. ;
  119.     PUSH    HL        ;save ptr to end of data
  120.     LD    HL,(RELSTRT)    ;get ptr to start of zex
  121.     LD    (GOADR),HL    ;set address to run to
  122.     DEC    HL        ;pt to start of data area
  123.     LD    (Z3MSG+09H),HL    ;set address of next char for zex processing
  124.     LD    (Z3MSG+0BH),HL    ;set address of first char for zex processing
  125.     LD    A,0FFH        ;set zex running flag
  126.     LD    (Z3MSG+08H),A    ;zex is now running
  127.     POP    HL        ;hl is ptr to end of data
  128.     LD    (HL),A        ;set up end of data
  129.     DEC    HL
  130.     LD    A,(BDOS+2)    ;set up bdos jump to protect data
  131.     LD    (HL),A
  132.     DEC    HL
  133.     LD    A,(BDOS+1)
  134.     LD    (HL),A
  135.     DEC    HL
  136.     LD    (HL),0C3H    ;sim jump
  137.     LD    (BDOS+1),HL    ;set new bdos address
  138.     LD    HL,0        ;assume no multiple commands
  139.     LD    A,(MCAVAIL)    ;get flag
  140.     OR    A        ;0=none
  141.     JP    Z,GOTOZEX    ;no multiple commands, so bc=0
  142.     LD    HL,(MCADR)    ;get address of multiple command buffer
  143. ;
  144. ;  zex monitor entry parameters --
  145. ;    hl    address of multiple command buffer or 0 if none
  146. ;
  147. GOTOZEX:
  148.     DB    0C3H    
  149. GOADR:    DW    0
  150. ;
  151. ; init zcpr3 environment
  152. ;
  153. Z3INIT:
  154.     PUSH    HL        ;save ptr to environment
  155.     LD    DE,MCOFF    ;offset to cl data
  156.     ADD    HL,DE
  157.     LD    E,(HL)        ;get cl address
  158.     INC    HL
  159.     LD    D,(HL)
  160.     INC    HL        ;get cl size
  161.     LD    A,(HL)
  162.     OR    D        ;if all three values are 0, then no command line
  163.     OR    E
  164.     LD    (MCAVAIL),A    ;set available flag
  165.     EX    DE,HL        ;hl pts to cl
  166.     LD    (MCADR),HL
  167.     POP    HL        ;get ptr to environment
  168.     LD    DE,EPOFF    ;offset to external path data
  169.     ADD    HL,DE
  170.     LD    E,(HL)        ;get external path address
  171.     INC    HL
  172.     LD    D,(HL)
  173.     LD    A,D        ;check for any
  174.     OR    E
  175.     LD    (EPAVAIL),A    ;set available flag
  176.     EX    DE,HL
  177.     LD    (EPADR),HL    ;set address
  178.     RET
  179. ;
  180. ; z3init buffers
  181. ;
  182. INTPATH:            ;internal path
  183.     DB    1,0        ;disk a, user 0
  184.     DB    0,0        ;end of path
  185. MCAVAIL:            ;multiple command line data
  186.     DB    0
  187. MCADR:
  188.     DW    0
  189. EPAVAIL:            ;external path data
  190.     DB    0
  191. EPADR:
  192.     DW    0
  193.  
  194. ;
  195. ;  print help message for zex
  196. ;
  197. HELP:
  198.     LD    DE,SIGNON    ;print banner
  199.     CALL    PRINT
  200.     LD    HL,HMSG        ;print message
  201.     CALL    HPRINT
  202.     LD    C,1        ;get char
  203.     CALL    BDOS
  204.     CP    'C'-'@'        ;^c?
  205.     RET    Z
  206.     LD    DE,CRLFS
  207.     CALL    PRINT
  208.     LD    DE,SIGNON
  209.     CALL    PRINT
  210.     LD    HL,HMSG0
  211.     CALL    HPRINT
  212.     LD    C,1        ;get char
  213.     CALL    BDOS
  214.     CP    'C'-'@'        ;^c?
  215.     RET    Z
  216.     LD    DE,CRLFS
  217.     CALL    PRINT
  218.     LD    DE,SIGNON
  219.     CALL    PRINT
  220.     LD    HL,HMSG1
  221. HPRINT:
  222.     LD    A,(HL)        ;get char
  223.     OR    A        ;done?
  224.     RET    Z
  225.     INC    HL        ;pt to next
  226.     PUSH    HL        ;save ptr
  227.     LD    E,A        ;char in e
  228.     LD    C,2        ;console output
  229.     CALL    BDOS
  230.     POP    HL        ;get ptr
  231.     JR    HPRINT
  232.  
  233. HMSG:
  234.     DB    CR,LF,LF
  235.     DB    'ZEX is an indirect command file processing facility, similar'
  236.     DB    CR,LF,'to the standard CP/M SUBMIT facility and the other '
  237.     DB    'ZCPR2'
  238.     DB    CR,LF,'indirect command file processing facility, SUB2.'
  239.     DB    CR,LF,'The major difference between the SUBMIT-like programs'
  240.     DB    CR,LF,'and ZEX is that ZEX is memory-based, storing a command'
  241.     DB    CR,LF,'processor and the interpreted command file itself in'
  242.     DB    CR,LF,'memory, just under ZCPR2.'
  243.     DB    CR,LF,LF
  244.     DB    'There is a basic tradeoff to be considered when using ZEX'
  245.     DB    CR,LF,'as opposed to SUB2.  Since ZEX is memory-based, it '
  246.     DB    'offers'
  247.     DB    CR,LF,'the advantage of greatly increased operating speed '
  248.     DB    'over'
  249.     DB    CR,LF,'SUB2.  Also, ZEX intercepts all input unless user '
  250.     DB    'input'
  251.     DB    CR,LF,'is explicitly enabled (the ^" command), in which case'
  252.     DB    ' the user'
  253.     DB    CR,LF,'is allowed to enter text from his console during a '
  254.     DB    'ZEX run.'
  255.     DB    CR,LF,'SUB2, on the other hand, inputs from the command file'
  256.     DB    ' only'
  257.     DB    CR,LF,'at the command line prompt unless XSUB is active.  ZEX'
  258.     DB    ' acts like'
  259.     DB    CR,LF,'SUB2 and XSUB combined.  The only bad feature of ZEX is'
  260.     DB    ' that'
  261.     DB    CR,LF,'ZEX significantly shortens the TPA work area, so '
  262.     DB    'programs which'
  263.     DB    CR,LF,'require a lot of memory may have trouble running under'
  264.     DB    ' ZEX.'
  265.     DB    CR,LF,'This is why SUB2 is provided to the ZCPR2 user along '
  266.     DB    'with ZEX.'
  267.     DB    CR,LF,LF,'Strike Any Key to Continue, ^C to Abort - ',0
  268.  
  269. HMSG0:
  270.     DB    CR
  271.     DB    LF,LF,'ZEX is invoked by one of the following command lines --'
  272.     DB    CR,LF
  273.     DB    CR,LF,'    ZEX <subfile> <parameters>'
  274.     DB    CR,LF,'or'
  275.     DB    CR,LF,'    ZEX'
  276.     DB    CR,LF
  277.     DB    CR,LF,'The first form executes the indicated command file'
  278.     DB    CR,LF,'(<subfile> may be of type ZEX or SUB, and if a ZEX and'
  279.     DB    ' SUB both'
  280.     DB    CR,LF,'exist, the ZEX file is used), passing to it the '
  281.     DB    'indicated '
  282.     DB    CR,LF,'parameters, similar to the way SUBMIT is used.'
  283.     DB    CR,LF
  284.     DB    CR,LF,'The second form allows the user to enter a series of '
  285.     DB    'commands.'
  286.     DB    CR,LF,'ZEX presents the user with a prompt like "n:", where'
  287.     DB    CR,LF,'n is a line number, and the user may enter any command'
  288.     DB    CR,LF,'line.  Input is terminated by simply striking the'
  289.     DB    CR,LF,'RETURN key.'
  290.     DB    CR,LF,LF,'ZEX can be aborted by ^C from console.'
  291.     DB    CR,LF,LF,'The following screen displays the ZEX control codes.'
  292.     DB    CR,LF,LF,'Strike Any Key to Continue, ^C to Abort - ',0
  293.  
  294. HMSG1:
  295.     DB    CR,LF,LF
  296.     DB    '    **** ZEX Embedded Command Processing Facility ****'
  297.     DB    CR,LF,LF
  298.     DB    'ZEX supports an enhanced command processing facility which '
  299.     DB    'includes the'
  300.     DB    CR,LF,'following escaped character commands which may be'
  301.     DB    CR,LF,'embedded in the text of the command file or user'
  302.     DB    CR,LF,'input and will be executed after the command run begins'
  303.     DB    ' --'
  304.     DB    CR,LF
  305.     DB    CR,LF,'    Cmd Meaning        Cmd Meaning'
  306.     DB    CR,LF,'     |  insert <CR>        ^|  insert <CR> <LF>'
  307.     DB    CR,LF,'    ^:  rerun command file    ^.  suppress print of chars'
  308.     DB    CR,LF,'    ^#  toggle ZEX msgs    ^$  define default params'
  309.     DB    CR,LF,'    ^?  wait for user <CR>    ^/  ring and wait for <CR>'
  310.     DB    CR,LF,'    ^*  ring bell        ^"  allow user input'
  311.     DB    CR,LF,'    ^<  display chars only    ^>  stop display'
  312.     DB    CR,LF,'    ;;  zex comment        $n  1<=n<=9 for param'
  313.     DB    CR,LF,'    $$  =$            $^  =^'
  314.     DB    CR,LF,'    $|  =|            ^c  insert ctrl char c'
  315.     DB    CR,LF,LF,LF,LF,0
  316.  
  317.  
  318. ;
  319. ;  relocate zex module into high memory just below zcpr2
  320. ;
  321.  
  322. ZRELOC:                ;*****
  323.     LD    HL,REST
  324.     LD    BC,RELE
  325.     LD    DE,ZEXADR
  326.     PUSH    DE        ;save load address
  327.     LDIR
  328.     POP    HL        ;get back load address in hl
  329.     LD    (RELSTRT),HL    ;save ptr
  330.     DEC    HL        ;relocate program-1
  331.     LD    (OUTBUF),HL    ;save ptr to byte in front of relocated program
  332.     RET
  333. ;
  334. ;  get parameters from command line
  335. ;    terminate each parameter with a binary zero, and set pointers
  336. ;    to each parameter
  337. ;
  338. ZPARMS:
  339.     LD    DE,DBUFF    ;terminate command line with cr
  340.     LD    A,(DE)        ;get char count
  341.     INC    DE        ;pt to first char
  342.     PUSH    DE
  343.     LD    L,A        ;hl = number of chars in line
  344.     LD    H,0
  345.     ADD    HL,DE        ;pt to after last char
  346.     LD    (HL),CR        ;store <cr>
  347.     LD    HL,PRMDMY    ;start at dummy parameter for .sub file spec
  348.     PUSH    HL
  349.     LD    BC,PRMPNL+2
  350.     XOR    A
  351.     CALL    FILL        ;clear ptr area
  352.     POP    HL        ;get ptr to pointer for parameter 0
  353.     POP    DE        ;get ptr to first char in line
  354.     LD    A,PRMPNL/2+1    ;number of parameters possible, max
  355.     LD    (PRMMAX),A    ;highest parameter # + 1 for .SUB SPEC
  356. ;
  357. ;  parameter extraction routine  hl pts to first param ptr, de pts to line
  358. ;
  359. PARMS:
  360.     LD    B,0        ;clear parameter counter
  361.     LD    (ERRLNE),DE    ;save in case of error
  362. ;
  363. PARMSL:
  364.     LD    A,(DE)        ;ignore leading spaces
  365.     INC    DE
  366.     CP    CR
  367.     JR    Z,ENDLNE
  368.     CP    ' '
  369.     JR    Z,PARMSL
  370.     DEC    DE        ;back up to 1st char
  371.     LD    (HL),E        ;save address in table
  372.     INC    HL
  373.     LD    (HL),D
  374.     INC    HL
  375.     INC    B        ;count+1
  376.     LD    A,(PRMMAX)
  377.     CP    B
  378.     JP    C,PRMTOO    ;too many arguments
  379. ;
  380. ENDPRM:
  381.     LD    A,(DE)        ;go to end of parameter
  382.     INC    DE
  383.     CP    CR
  384.     JR    Z,ENDLNE
  385.     CP    ' '        ;skip until <sp>
  386.     JR    NZ,ENDPRM
  387.     XOR    A        ;a=0 to terminate param
  388.     DEC    DE        ;pt to <sp> following param
  389.     LD    (DE),A        ;terminate parameter
  390.     INC    DE        ;pt to char after <sp>
  391.     JR    PARMSL        ;ignore spaces between parameters
  392. ENDLNE:
  393.     XOR    A        ;store zero after last parameter
  394.     DEC    DE        ;pt to cr
  395.     LD    (DE),A        ;terminate last parameter
  396.     INC    DE        ;pt to after last param
  397.     LD    A,CR        ;store ending cr
  398.     LD    (DE),A
  399.     RET
  400. ;
  401. ;  input command lines from user
  402. ;
  403. INPUTSB:
  404.     LD    HL,0
  405.     LD    (LINES),HL    ;start line counter
  406.     LD    A,0FFH        ;set buffer length
  407.     LD    (DBUFF-1),A
  408.     LD    HL,BEGREL    ;set up output buffer
  409.     LD    (INBUF),HL
  410. GETLIN:
  411.     CALL    CRLF
  412.     LD    HL,(LINES)
  413.     INC    HL
  414.     LD    (LINES),HL
  415.     CALL    DECOUT        ;print line #
  416.     LD    E,':'        ;get prompt
  417.     CALL    OUTCHR
  418.     LD    E,' '
  419.     CALL    OUTCHR
  420.     LD    DE,DBUFF-1
  421.     LD    C,10        ;read console buffer
  422.     CALL    BDOS
  423.     LD    DE,DBUFF
  424.     LD    A,(DE)        ;get length
  425.     LD    B,A
  426.     INC    DE
  427.     LD    HL,(INBUF)    ;get input pointer
  428.     OR    A        ;see if end
  429.     RET    Z        ;done with input
  430.     EX    DE,HL
  431.     CALL    MOVE        ;move to input buffer
  432.     EX    DE,HL
  433.     LD    (HL),CR
  434.     INC    HL
  435.     LD    (HL),LF
  436.     INC    HL
  437.     LD    (INBUF),HL
  438.     JR    GETLIN
  439. ;
  440. ;  open and load sub file
  441. ;
  442. OPENSB:
  443.     CALL    PUTUD        ;save user/disk
  444. ;
  445. ;  set up to read zex file
  446. ;
  447.     LD    DE,DFCB+9
  448.     LD    HL,ZEXNAM    ;move 'sub' to dfcb file type
  449.     LD    BC,3
  450.     LDIR
  451.     XOR    A        ;zero cr field
  452.     LD    (DFCB+32),A
  453.     LD    DE,BUFF        ;set dma address
  454.     LD    C,26        ;set dma
  455.     CALL    BDOS
  456.     LD    DE,DFCB
  457.     LD    HL,INTPATH    ;pt to internal path
  458.     LD    A,(EPAVAIL)    ;external paths available?
  459.     OR    A        ;0=no
  460.     JR    Z,OSB1        ;use internal path
  461.     LD    HL,(EPADR)    ;pt to external path
  462. OSB1:
  463.     PUSH    HL        ;save path ptr
  464.     CALL    FNDFILE        ;look for file along path and say if it is found
  465.     POP    HL        ;get path ptr
  466.     JP    NZ,READSB
  467. ;
  468. ;  zex file not found -- set up to read sub file
  469. ;
  470.     PUSH    HL        ;save path ptr
  471.     CALL    GETUD        ;restore user/disk
  472.     LD    DE,DFCB+9    ;set type to sub
  473.     LD    HL,SUBNAM
  474.     LD    BC,3
  475.     LDIR
  476.     XOR    A        ;zero cr field
  477.     LD    (DFCB+32),A
  478.     POP    HL        ;pt to path
  479.     LD    DE,DFCB        ;pt to fcb
  480.     CALL    FNDFILE        ;look for file
  481.     JP    NZ,READSB
  482. RSBERR:
  483.     CALL    GETUD        ;restore user/disk
  484.     LD    HL,NOSBF2
  485.     LD    DE,DFCB+1
  486.     LD    B,8        ;name length
  487.     CALL    MOVEFN        ;move file name
  488.     LD    B,3        ;type length
  489.     LD    (HL),'.'
  490.     INC    HL
  491.     LD    DE,DFCB+9    ;file type pointer
  492.     CALL    MOVEFN        ;move file type
  493.     LD    (HL),'$'    ;end terminater
  494.     JP    NOSUB
  495. ;*
  496. ;*  FNDFILE -- LOOK FOR FILE ALONG ZCPR3 PATH
  497. ;*  INPUT PARAMETERS:  HL = BASE ADDRESS OF PATH, DE = PTR TO FCB OF FILE
  498. ;*  OUTPUT PARAMETERS:  A=0 AND ZERO FLAG SET IF NOT FOUND, NZ IF FOUND
  499. ;*
  500. FNDFILE:
  501.     LD    (PATH),HL    ;save path base address
  502.     LD    C,17        ;search for first
  503.     CALL    BENTRY        ;look for file
  504.     INC    A        ;set flag
  505.     JP    NZ,FF5        ;found it -- return found flag
  506.     EX    DE,HL        ;hl=fcb ptr
  507.     LD    (FCBPTR),HL    ;save it
  508.     LD    HL,(PATH)    ;pt to path for failure possibility
  509.     LD    C,32        ;get current user
  510.     LD    E,0FFH
  511.     CALL    BENTRY
  512.     LD    (TMPUSR),A    ;save it for later
  513. ;
  514. ; main search loop
  515. ;
  516. FF1:
  517.     LD    A,(HL)        ;get drive
  518.     AND    7FH        ;mask msb
  519.     OR    A        ;0=done=command not found
  520.     JR    NZ,FF2        ;no error abort?
  521. ;
  522. ; file not found error
  523. ;
  524.     XOR    A        ;zero flag means not found
  525.     RET
  526. ;
  527. ; look for command in directory pted to by hl; drive in a
  528. ;
  529. FF2:
  530.     LD    E,A        ;disk in e
  531.     CP    '$'        ;current disk?
  532.     JR    NZ,FF3        ;skip default drive selection if so
  533.     LD    A,(BDISK)    ;get default user/disk
  534.     AND    0FH        ;mask for default disk
  535.     INC    A        ;prep for following dcr a
  536.     LD    E,A        ;disk number in e
  537. FF3:
  538.     DEC    E        ;adjust path 1 to 0 for a, etc
  539.     LD    C,14        ;select disk fct
  540.     CALL    BENTRY        ;select drive
  541.     INC    HL        ;pt to user number
  542.     LD    A,(HL)        ;get user number
  543.     AND    7FH        ;mask out msb
  544.     INC    HL        ;pt to next entry in path
  545.     PUSH    HL        ;save ptr
  546.     LD    E,A        ;save in e
  547.     CP    '$'        ;match?
  548.     JR    NZ,FF4        ;do not select current user if so
  549.     LD    A,(TMPUSR)    ;get original user number
  550.     LD    E,A        ;select user
  551. FF4:
  552.     LD    C,32
  553.     CALL    BENTRY
  554.     LD    HL,(FCBPTR)    ;get ptr to fcb
  555.     EX    DE,HL        ;... in de
  556.     LD    C,17        ;search for first
  557.     CALL    BENTRY        ;look for file
  558.     POP    HL        ;get ptr to next path entry
  559.     INC    A        ;set flag
  560.     JR    Z,FF1        ;continue path search if search failed
  561. ;
  562. ; file found -- perform system test and proceed if approved
  563. ;
  564. FF5:
  565.     LD    A,0FFH        ;set ok return
  566.     OR    A
  567.     RET
  568.  
  569. ;
  570. ;  bdos routine
  571. ;
  572. BENTRY:
  573.     PUSH    HL        ;save regs
  574.     PUSH    DE
  575.     PUSH    BC
  576.     CALL    BDOS
  577.     POP    BC        ;get regs
  578.     POP    DE
  579.     POP    HL
  580.     RET
  581.  
  582. ;* BUFFERS
  583. FCBPTR:
  584.     DS    2        ;pointer to fcb for file search
  585. TMPUSR:
  586.     DS    1        ;current user number
  587. PATH:
  588.     DS    2        ;base address of path
  589. ;
  590. ;  putud -- save away current user/disk
  591. ;  getud -- restore current user/disk
  592. ;
  593. PUTUD:
  594.     LD    E,0FFH        ;get current user
  595.     LD    C,32        ;bdos
  596.     CALL    BDOS
  597.     LD    (CUSER),A    ;save current user away
  598.     LD    C,25        ;get current disk
  599.     CALL    BDOS
  600.     LD    (CDISK),A
  601.     RET
  602. GETUD:
  603.     LD    A,(CDISK)    ;get current disk
  604.     LD    E,A        ;... in e
  605.     LD    C,14        ;select disk
  606.     CALL    BDOS
  607.     LD    A,(CUSER)    ;get current user
  608.     LD    E,A        ;... in e
  609.     LD    C,32        ;select user
  610.     CALL    BDOS
  611.     RET
  612. CDISK:
  613.     DS    1        ;current disk number
  614. CUSER:
  615.     DS    1        ;current user number
  616. ;
  617. ;  open and read sub file
  618. ;
  619. READSB:
  620.     LD    C,15        ;open file
  621.     CALL    BDOS        ;bdos
  622.     INC    A        ;error?
  623.     JP    Z,RSBERR
  624. ;
  625. ;  read in and store sub file
  626. ;
  627. READTX:
  628.     LD    HL,(INBUF)    ;get ptr to next byte
  629.     EX    DE,HL        ;set ptr in de
  630.     LD    HL,80H        ;get sector offset
  631.     ADD    HL,DE        ;hl pts to following block to be read, de pts to
  632.     LD    (INBUF),HL    ;  block to read; save ptr to following block
  633.     LD    C,26        ;set dma address
  634.     CALL    BDOS
  635.     LD    DE,DFCB
  636.     LD    C,20        ;read sequential
  637.     CALL    BDOS
  638.     OR    A
  639.     JR    Z,READTX    ;read complete .sub file
  640.     CALL    GETUD        ;restore current user/disk
  641.     LD    HL,(INBUF)    ;make sure buffer's terminated
  642.     LD    DE,-100H    ;pt to first byte of last block read
  643.     ADD    HL,DE
  644.     LD    B,80H        ;look at at most 80h bytes
  645. SKIP1A:
  646.     LD    A,(HL)        ;get byte
  647.     CP    CTRLZ        ;eof?
  648.     JR    Z,SKIP1B
  649.     INC    HL        ;pt to next
  650.     DEC    B        ;count down
  651.     JR    NZ,SKIP1A
  652. ;  hl now points to after last valid char in file
  653. SKIP1B:
  654.     LD    (INBUF),HL    ;set ptr
  655.     RET            ;done with no error
  656.  
  657. ;
  658. ;  this part of the code stores the rest of the command line as part of the
  659. ;  command file for zcpr2; on entry, hl pts to next available byte
  660. ;
  661. ZMCL:
  662.     EX    DE,HL        ;buffer pted to by de
  663.     LD    HL,(MCADR)    ;get base address of multiple command line
  664.     LD    A,(HL)        ;get low
  665.     INC    HL
  666.     LD    H,(HL)        ;get high
  667.     LD    L,A        ;hl pts to next char in multiple command line
  668.     EX    DE,HL        ;de pts to next char in command line, hl pts to buf end
  669.     LD    A,(MCAVAIL)    ;multiple commands enabled?
  670.     OR    A        ;0=no
  671.     JR    Z,ENDSTR    ;terminate file; hl pts to next byte
  672.     LD    A,(DE)        ;get first byte
  673.     LD    B,A        ;save first byte in b
  674.     XOR    A        ;a=0
  675.     LD    (DE),A        ;clear command line
  676.     INC    DE        ;pt to next byte
  677.     LD    A,B        ;get first byte
  678.     CP    ';'        ;separation char?
  679.     JR    NZ,CMCMD1    ;process if not
  680. ;
  681. ;  loop to store rest of multiple command line into loaded file
  682. ;
  683. CMCMD:
  684.     LD    A,(DE)        ;get byte from line
  685. CMCMD1:
  686.     OR    A        ;eol if zero
  687.     JR    Z,CMEND        ;read in file; hl pts to next available byte
  688.     LD    (HL),A        ;store byte
  689.     INC    HL        ;pt to next
  690.     INC    DE
  691.     JR    CMCMD
  692. CMEND:
  693.     LD    (HL),CR        ;store <cr> <lf>
  694.     INC    HL
  695.     LD    (HL),LF
  696.     INC    HL        ;pt to next available byte
  697. ;
  698. ;  mark end of buffer and continue
  699. ;
  700. ENDSTR:
  701.     LD    (HL),1AH    ;eof character
  702.     LD    (ENDBUF),HL    ;eob address
  703.     LD    A,L
  704.     SUB    LOW BEGREL+1    ;see if buffer's empty
  705.     LD    A,H
  706.     SBC    A,HIGH BEGREL
  707.     JP    C,BUFLOW
  708.     RET
  709. ;
  710. ;  copy and process command lines, placing final command line form under zex
  711. ;    return with hl pting to next available byte in memory buffer under zex
  712. ;
  713. ZLINES:
  714.     XOR    A
  715.     LD    (IMFLG1),A
  716.     LD    (IMFLG2),A
  717.     LD    (PRTFLG),A
  718.     LD    (OUTCNT),A
  719.     LD    HL,1
  720.     LD    (LINES),HL    ;set line count
  721.     LD    HL,(OUTBUF)    ;pt to byte just below loaded zex
  722.     LD    (OUTLNE),HL
  723.     LD    (BUFSTR),HL
  724.     LD    DE,BEGREL    ;pt to first byte of command buffer
  725. ;
  726. ;  main copy loop to copy buffer at begrel to just under zex with processing
  727. ;
  728. MOVSTR:
  729.     LD    A,(DE)        ;get next command byte
  730.     INC    DE        ;pt to following
  731.     AND    7FH        ;make sure no parity
  732.     CP    LF        ;new line?
  733.     JR    NZ,MOVST0
  734. ;
  735. ;  new line -- don't store <lf> and increment line count
  736. ;
  737. MOVSTX:
  738.     CALL    INCR        ;increment line count
  739.     JR    MOVSTR        ;continue
  740. ;
  741. ;  begin character processing
  742. ;    a contains char, de pts to byte after char, hl pts to next buffer pos
  743. ;
  744. MOVST0:
  745.     CP    1AH        ;end of input?
  746.     RET    Z        ;done if so
  747.     CP    '|'        ;carriage return?
  748.     JR    NZ,MOVST1    ;nope
  749. ;
  750. ;  process carriage return form (|)
  751. ;
  752.     PUSH    DE        ;save old pointer
  753.     INC    DE        ;look for eof after | (pt to lf)
  754.     INC    DE        ;pt to possible eof
  755.     LD    A,(DE)        ;get present location+2
  756.     POP    DE        ;get old pointer
  757.     CP    1AH        ;end of buffer
  758.     RET    Z        ;end, so no following <cr>
  759.     LD    A,CR        ;make char a <cr>
  760.     CALL    INCR        ;increment lines for errors
  761.     JR    MOVST4        ;store <cr> in a
  762. ;
  763. ;  check for non-cr forms
  764. ;    at this point, de pts to next char in line and hl pts to next
  765. ;    byte in buffer (moving down)
  766. ;
  767. MOVST1:
  768.     LD    C,A        ;save char in c
  769.     LD    A,(IMFLG1)
  770.     CP    IMON        ;immediate mode on ?
  771.     LD    A,C        ;get char back
  772.     JR    Z,MOVST2    ;yes..skip zex comment processing
  773.     CP    ';'        ;first ';'?
  774.     JP    Z,EXCOMM    ;process possible zex comment
  775. MOVST2:
  776.     CP    '^'        ;control char?
  777.     JR    Z,MOVST5    ;convert control characters
  778.     CP    '$'        ;parameter or control char?
  779.     CALL    Z,GTPARM    ;substitute command parameter or control char.
  780. MOVST3:
  781.     LD    (LCHR),A    ;save last char entered
  782.     CP    CR        ;=cr?
  783.     JR    NZ,MOVST4
  784.     LD    C,A        ;save char temporarily
  785.     LD    A,(OUTCNT)    ;get char output flag
  786.     OR    A        ;any char?
  787.     LD    A,C
  788.     JR    Z,MOVSTR    ;no..use input cr only if other non-control
  789. ;                     characters in current line
  790. ;  place char in buffer
  791. ;    char in a, hl pts to buffer loc
  792. ;
  793. MOVST4:
  794.     CALL    CHRSTR        ;add to buffer
  795.     CALL    CNTINC        ;increment count
  796.     JR    MOVSTR
  797. ;
  798. ;  prefix was an uparrow (^), so process control chars
  799. ;
  800. MOVST5:
  801.     CALL    GETCMD        ;validate control characters
  802.     CP    ':'
  803.     JR    Z,REXC        ;re-execute
  804.     CP    '?'
  805.     JR    Z,GCRW        ;cr wait
  806.     CP    '/'
  807.     JR    Z,GCRBW        ;ring bell and wait for <cr>
  808.     CP    '"'
  809.     JR    Z,UISET        ;user input
  810.     CP    '*'
  811.     JR    Z,GRNG        ;continually ring bell while waiting for <cr>
  812.     CP    '|'
  813.     JR    Z,GCRLF        ;cr,lf generation
  814.     CP    '$'
  815.     JR    Z,PRMDEF    ;default parameters' line
  816.     CP    '.'
  817.     JP    Z,PRTSUP    ;print suppress toggle
  818.     CP    '#'
  819.     JP    Z,MSGSUP    ;message suppress toggle
  820.     CP    '<'
  821.     JP    Z,IMPRTY    ;immediate mode start
  822.     CP    '>'
  823.     JP    Z,IMPRTN    ;immediate mode stop
  824.     CP    '&'
  825.     JR    Z,IFPSUP    ;print suppress during false if
  826. MVST3:    JR    MOVST3        ;other control codes
  827. ;
  828. IFPSUP:
  829.     LD    A,IPS        ;convert '^&' to if print suppress flag
  830.     JR    MVST3
  831. ;
  832. REXC:
  833.     LD    A,REXEC        ;convert '^:' to re-execute flag
  834.     JR    MVST3
  835. ;
  836. GCRW:
  837.     LD    A,CRWAIT    ;convert '^?' to crwait flag
  838.     JR    MVST3
  839. ;
  840. GCRBW:
  841.     LD    A,CRBWAIT    ;convert '^/' to crbwait flag
  842.     JR    MVST3
  843. ;
  844. ;  allow user input from now on, but first skip out rest of line
  845. ;
  846. UISET:
  847.     LD    A,(DE)        ;get next char
  848.     AND    7FH        ;mask it
  849.     CP    LF        ;done?
  850.     JR    Z,UISET1
  851.     CP    1AH        ;eof?
  852.     JR    Z,UISET1
  853.     INC    DE        ;pt to next char
  854.     JR    UISET        ;continue skipping
  855. UISET1:
  856.     LD    A,UICH        ;control char
  857.     JR    MVST3
  858. ;
  859. GRNG:
  860.     LD    A,RNG        ;convert '^*' TO RNG FLAG
  861.     JR    MVST3
  862. ;
  863. GCRLF:
  864.     LD    A,CR        ;generate cr & lf
  865.     CALL    CHRSTR
  866.     LD    A,LF
  867.     CALL    CHRSTR
  868.     LD    (LCHR),A
  869.     JP    MOVSTR
  870. ;
  871. PRMDEF:
  872.     PUSH    HL
  873.     LD    HL,PRMDFP
  874.     PUSH    HL
  875.     LD    BC,PRMDFL
  876.     XOR    A
  877.     CALL    FILL        ;clear ptr table
  878.     POP    HL
  879.     LD    A,PRMDFL/2
  880.     LD    (PRMMAX),A    ;highest parameter #
  881.     CALL    PARMS        ;build default parameters ptrs
  882.     POP    HL
  883.     INC    DE        ;skip cr
  884.     LD    A,LF
  885.     JP    MOVSTX        ;continue at eol
  886. ;
  887. ;  check to see if previous char was also a ; and flush as zex comment if so
  888. ;
  889. EXCOMM:
  890.     PUSH    HL
  891.     LD    HL,LCHR        ;pt to previous char
  892.     CP    (HL)        ; double ;?
  893.     LD    (HL),A        ;store current char as previous char
  894.     POP    HL
  895.     JP    NZ,MOVST3    ;no...continue
  896.     LD    C,A        ;save char
  897.     LD    A,(PRTFLG)
  898.     CP    PSUP
  899.     LD    A,C
  900.     JP    Z,MOVST3    ;print suppress
  901.     LD    A,(IMFLG1)
  902.     CP    IMON
  903.     LD    A,C
  904.     JP    Z,MOVST3    ;immediate mode
  905.     INC    HL        ;yes..ignore previous ;
  906.     PUSH    HL
  907.     LD    HL,LCHR
  908.     LD    A,(OUTCNT)
  909.     DEC    A        ;drop 1 char.
  910.     LD    (OUTCNT),A
  911. EXCOML:
  912.     LD    A,(DE)        ;ignore characters until eof or lf
  913.     INC    DE
  914.     CP    1AH        ;eof
  915.     JR    Z,EXCOMX
  916.     CP    LF        ;line feed
  917.     JR    NZ,EXCOML
  918.     LD    (HL),A
  919.     LD    A,(OUTCNT)
  920.     OR    A        ;any char. on this line?
  921.     JR    Z,EXCOM2    ;no...skip cr
  922. EXCOM1:
  923.     POP    HL        ;yes..force cr
  924.     LD    A,CR
  925.     CALL    CHRSTR
  926.     LD    A,LF
  927.     JP    MOVSTX        ;continue
  928. ;
  929. EXCOM2:
  930.     POP    HL
  931.     LD    A,LF
  932.     JP    MOVSTX        ;continue
  933. ;
  934. EXCOMX:
  935.     POP    HL
  936.     RET            ;return to main flow, with hl pting to next byte
  937. ;
  938. MSGSUP:
  939.     LD    A,MSUP        ;convert '^#' to message suppress flag
  940.     JP    MOVST3
  941. ;
  942. PRTSUP:
  943.     LD    A,PSUP        ;convert '^.' to print suppress flag
  944.     PUSH    HL
  945.     LD    HL,PRTFLG
  946.     CP    (HL)        ;already on?
  947.     JR    NZ,PRTSST    ;no...set flag
  948.     XOR    A        ;yes..clear flag
  949. PRTSST:
  950.     LD    (HL),A        ;set/reset flag
  951.     POP    HL
  952.     LD    A,PSUP
  953.     JP    MOVST3
  954. ;
  955. IMPRTY:
  956.     LD    A,IMON        ;convert '^<' to immediate mode start
  957.     LD    (LCHR),A
  958.     PUSH    HL
  959.     LD    HL,IMFLG1
  960.     CP    (HL)        ;already on?
  961.     POP    HL
  962.     JP    Z,MOVSTR    ;yes..
  963.     LD    (IMFLG1),A
  964.     LD    (IMFLG2),A
  965.     JP    MOVST3        ;no...
  966. ;
  967. IMPRTN:
  968.     LD    A,IMOFF        ;convert '^>' to immediate mode stop
  969.     LD    (LCHR),A
  970.     PUSH    HL
  971.     LD    HL,IMFLG2
  972.     CP    (HL)        ;already off?
  973.     POP    HL
  974.     JP    Z,MOVSTR    ;yes..
  975.     LD    (IMFLG2),A
  976.     LD    (IMFLG1),A
  977.     JP    MOVST3        ;no...
  978. ;
  979. ;  place char in buffer; a=char, hl pts to buffer loc
  980. ;
  981. CHRSTR:
  982.     PUSH    AF        ;check for input/zex buffer overlap
  983.     PUSH    DE
  984.     PUSH    HL
  985.     LD    HL,(ENDBUF)
  986.     EX    DE,HL
  987.     POP    HL
  988.     LD    A,L
  989.     CP    E
  990.     JR    NZ,CHRSTX    ;lsb<>
  991.     LD    A,H
  992.     CP    D
  993.     JP    Z,OVERL        ;msb=, overlap will occur/abort zex
  994. ;
  995. ; add char to zex's buffer
  996. ;
  997. CHRSTX:
  998.     POP    DE        ;add char. to zex's buffer
  999.     POP    AF
  1000.     LD    (HL),A        ;store char
  1001.     DEC    HL        ;pt to next location (moving down)
  1002.     RET
  1003. ;
  1004. ;  check to see if zex is already active, and abort if so
  1005. ;
  1006. ZEXACTV:
  1007.     LD    A,(Z3MSG+08H)    ;zex running?
  1008.     OR    A        ;0 if no
  1009.     RET    Z
  1010.     LD    DE,ZEXACT
  1011.     CALL    PRINT        ;zex already present
  1012. ;
  1013. ;  abort and return to zcpr2
  1014. ;
  1015. CCPRET:
  1016.     LD    SP,(CCPSTK)    ;restore stack
  1017.     RET            ;return to ccp
  1018. ;
  1019. ;    error exits
  1020. ;
  1021. GETERR:
  1022.     LD    DE,CMDER    ;control character invalid
  1023.     CALL    PRINT
  1024.     JP    LINE        ;print line # and line and exit
  1025. ;
  1026. NUMERR:
  1027.     LD    DE,NONUM    ;excessive number
  1028.     CALL    PRINT
  1029.     JP    LINE        ;print line # and line and exit
  1030. ;
  1031. PRMERR:
  1032.     LD    DE,PMERR
  1033.     CALL    PRINT
  1034.     JP    LINE        ;print line # and line and exit
  1035. ;
  1036. PRMTOO:
  1037.     LD    DE,TOOARG    ;too many parameter arguments
  1038.     CALL    PRINT
  1039.     LD    HL,(ERRLNE)
  1040.     CALL    EPRT        ;print parameter line
  1041.     JR    CCPRET
  1042. ;
  1043. BUFLOW:
  1044.     LD    DE,BUFMTY    ;text buffer empty
  1045.     CALL    PRINT
  1046.     JR    CCPRET
  1047. ;
  1048. NOSUB:
  1049.     LD    DE,NOSBF1    ;.sub file not found
  1050.     CALL    PRINT
  1051.     LD    DE,NOTHER
  1052.     CALL    PRINT
  1053.     JR    CCPRET
  1054. ;
  1055. OVERL:
  1056.     LD    DE,OVERLP    ;input/zex buffer overlap
  1057.     CALL    PRINT
  1058.     JP    LINE
  1059. ;
  1060. ;    subroutines
  1061. ;
  1062. ;    control codes 0-1fh
  1063. ;    with support for $ . # < >
  1064. ;
  1065. GETCMD:
  1066.     LD    A,(DE)        ;get next character
  1067.     INC    DE        ;increment pointer
  1068.     CP    '|'
  1069.     RET    Z        ;cr,lf generation
  1070.     CP    'a'-1        ;lowercase?
  1071.     JR    C,GETUPR    ;nope
  1072.     CP    'z'+1        ;a-z?
  1073.     JP    NC,GETERR    ;nope
  1074.     SUB    'a'-'A'     ;get to uppercase
  1075. GETUPR:
  1076.     CP    '@'        ;0-1fh control code?
  1077.     JR    NC,GETCC
  1078.     CP    ':'
  1079.     RET    Z        ;re-execute
  1080.     CP    '?'
  1081.     RET    Z        ;cr wait
  1082.     CP    '/'
  1083.     RET    Z        ;cr wait and ring bell
  1084.     CP    '*'
  1085.     RET    Z        ;ring bell
  1086.     CP    '"'
  1087.     RET    Z        ;user input
  1088.     CP    '$'
  1089.     RET    Z        ;default parameters' line
  1090.     CP    '.'
  1091.     RET    Z        ;print suppress toggle
  1092.     CP    '#'
  1093.     RET    Z        ;message suppress toggle
  1094.     CP    '<'
  1095.     RET    Z        ;immediate mode start
  1096.     CP    '>'
  1097.     RET    Z        ;immediate mode stop
  1098.     CP    '&'
  1099.     RET    Z        ;false if print suppress
  1100.     JP    GETERR
  1101. GETCC:
  1102.     SUB    '@'        ;get control code
  1103.     RET    NC
  1104.     JP    GETERR
  1105. ;
  1106. ;  extract parameter element whose $n specification is pointed to by de
  1107. ;    de pts to char after the $
  1108. ;    buffer to place resulting parameter is pted to by hl
  1109. ;
  1110. GTPARM:
  1111.     LD    A,(DE)        ;get char after the $
  1112.     INC    DE        ;pt to next char
  1113.     CP    '$'        ;if double $, then store as $
  1114.     RET    Z
  1115.     CP    '^'        ;up arrow
  1116.     RET    Z
  1117.     CP    '|'        ;carriage return
  1118.     RET    Z
  1119.     CP    '1'        ;check for valid digit (1-9)
  1120.     JP    C,PRMERR
  1121.     CP    '9'+1        ;range error?
  1122.     JP    NC,PRMERR
  1123.     SUB    '1'        ;get actual # (zero relative)
  1124.     ADD    A,A        ;double for offset
  1125.     LD    (PRMNUM),A
  1126.     PUSH    DE        ;save ptrs
  1127.     PUSH    HL
  1128.     LD    HL,PRMPNT    ;pt to parameter ptr table
  1129.     CP    PRMPNL-1    ;parameter number within range?
  1130.     JP    NC,NOPARM    ;> highest #
  1131.     LD    E,A
  1132.     LD    D,0
  1133.     ADD    HL,DE
  1134.     LD    E,(HL)        ;get parameter pointer
  1135.     INC    HL
  1136.     LD    D,(HL)
  1137.     POP    HL        ;restore ptr to next byte in output buffer below zex
  1138.     LD    A,E        ;any param?
  1139.     OR    D
  1140.     JR    Z,NOPARM    ;no parameter present, try defaults
  1141. ;
  1142. ;  move parameter pted to by de into buffer below zex, 1st byte pted to by hl
  1143. ;
  1144. MOVPRM:
  1145.     LD    A,(DE)        ;get parameter char
  1146.     INC    DE        ;pt to next
  1147.     OR    A        ;done?
  1148.     JP    Z,ENDPAR
  1149.     CALL    CHRSTR        ;store chars
  1150.     JR    MOVPRM
  1151. ;
  1152. ;  parameter placed in memory -- continue
  1153. ;
  1154. ENDPAR:
  1155.     POP    DE        ;get ptr to next char in line
  1156.     POP    AF        ;clear stack
  1157.     JP    MOVSTR        ;resume processing
  1158. ;
  1159. ;  no parameter pted to
  1160. ;
  1161. NOPARM:
  1162.     PUSH    HL        ;save ptr to next byte in buffer below zex
  1163.     LD    HL,PRMDFP    ;try default parameters
  1164.     LD    A,(PRMNUM)
  1165.     CP    PRMDFL-1
  1166.     JP    NC,NUMERR    ;> highest #
  1167.     LD    E,A
  1168.     LD    D,0
  1169.     ADD    HL,DE
  1170.     LD    E,(HL)        ;get parameter pointer
  1171.     INC    HL
  1172.     LD    D,(HL)
  1173.     POP    HL
  1174.     LD    A,E
  1175.     OR    D
  1176.     JR    NZ,MOVPRM    ;move parameter into buffer
  1177.     JR    ENDPAR        ;resume with no parameter
  1178. ;
  1179. MOVEFN:
  1180.     LD    A,(DE)
  1181.     CP    ' '        ;see if space
  1182.     RET    Z
  1183.     LD    (HL),A
  1184.     INC    DE        ;increment pointers
  1185.     INC    HL
  1186.     DJNZ    MOVEFN
  1187.     RET
  1188. ;
  1189. ;  increment line count, and affect only hl (must not affect a)
  1190. ;
  1191. INCR:
  1192.     PUSH    HL        ;save output pointer
  1193.     LD    HL,(LINES)
  1194.     INC    HL        ;increment line counter
  1195.     LD    (LINES),HL
  1196.     LD    HL,LCHR        ;clear last character
  1197.     LD    (HL),0
  1198.     LD    HL,OUTCNT    ;clear character count
  1199.     LD    (HL),0
  1200.     LD    L,E        ;de=hl
  1201.     LD    H,D
  1202.     LD    (BEGLIN),HL
  1203.     POP    HL
  1204.     LD    (OUTLNE),HL    ;save new output line
  1205.     RET
  1206. ;
  1207. CNTINC:
  1208.     CP    ' '        ;control character?
  1209.     RET    C        ;yes..
  1210.     CP    UICH        ;user input char?
  1211.     JR    Z,CNTIN1
  1212.     AND    80H        ;special control?
  1213.     RET    NZ        ;yes..
  1214.     LD    A,(PRTFLG)
  1215.     CP    PSUP        ;print suppress flag?
  1216.     RET    Z        ;yes..
  1217.     LD    A,(IMFLG1)
  1218.     CP    IMON        ;immediate mode?
  1219.     RET    Z        ;yes..
  1220. CNTIN1:
  1221.     LD    A,(OUTCNT)
  1222.     INC    A
  1223.     LD    (OUTCNT),A
  1224.     RET
  1225. ;
  1226. PRINT:
  1227.     LD    C,9        ;print string at (de)
  1228.     JP    BDOS
  1229. ;
  1230. EPRT:
  1231.     LD    A,(HL)        ;print parameter line at (hl)
  1232.     CP    CR
  1233.     RET    Z
  1234.     CP    0
  1235.     JR    NZ,EPRT1
  1236.     LD    A,' '
  1237. EPRT1:
  1238.     INC    HL
  1239.     PUSH    HL
  1240.     LD    E,A
  1241.     LD    C,2
  1242.     CALL    BDOS
  1243.     POP    HL
  1244.     JR    EPRT
  1245. ;
  1246. CRLF:
  1247.     LD    DE,CRLFS    ;print cr/lf
  1248.     JP    PRINT
  1249. ;
  1250. LINE:
  1251.     LD    DE,LINEM    ;print line # and line in error and exit
  1252.     CALL    PRINT
  1253.     LD    HL,(LINES)
  1254.     CALL    DECOUT        ;print line #
  1255.     CALL    CRLF
  1256.     LD    HL,(BEGLIN)
  1257.     PUSH    HL        ;save begging pointer
  1258. FINDCR:
  1259.     LD    A,(HL)
  1260.     INC    HL
  1261.     CP    1AH        ;end of buffer
  1262.     JR    Z,FOUND
  1263.     CP    CR
  1264.     JR    NZ,FINDCR
  1265. FOUND:
  1266.     LD    (HL),0        ;end of string
  1267.     POP    HL        ;start of string
  1268.     CALL    PRNTHL        ;print bad line
  1269.     JP    CCPRET        ;thats all folks
  1270. ;
  1271. PRNTHL:
  1272.     LD    A,(HL)        ;print line at (hl)
  1273.     INC    HL
  1274.     OR    A
  1275.     RET    Z
  1276.     LD    E,A
  1277.     PUSH    HL        ;save pointer
  1278.     CALL    OUTCHR
  1279.     POP    HL        ;get pointer back
  1280.     JR    PRNTHL
  1281. ;
  1282. OUTCHR:
  1283.     LD    C,2        ;print character in e
  1284.     JP    BDOS
  1285. ;
  1286. DECOUT:
  1287.     PUSH    HL        ;print decimal line number
  1288.     PUSH    DE
  1289.     PUSH    BC
  1290.     LD    BC,-10        ;radix for conversion
  1291.     LD    DE,-1        ;this becomes no divided by radix
  1292. DX:
  1293.     ADD    HL,BC        ;subtract 10
  1294.     INC    DE
  1295.     JP    C,DX
  1296.     LD    BC,10
  1297.     ADD    HL,BC        ;add radix back in once
  1298.     EX    DE,HL
  1299.     LD    A,H
  1300.     OR    L        ;test for zero
  1301.     CALL    NZ,DECOUT    ;recursive call
  1302.     LD    A,E
  1303.     ADD    A,'0'        ;convert from bcd to hex
  1304.     LD    E,A        ;to e for output
  1305.     LD    C,2
  1306.     CALL    BDOS
  1307.     POP    BC        ;restore registers
  1308.     POP    DE
  1309.     POP    HL
  1310.     RET
  1311. ;
  1312. MOVE:
  1313.     LD    A,(HL)        ;move string at (hl) to (de) for length in b
  1314.     INC    HL
  1315.     LD    (DE),A
  1316.     INC    DE
  1317.     DJNZ    MOVE
  1318.     RET
  1319. ;
  1320. FILL:
  1321.     PUSH    DE        ; fill storage at (hl) with character in a
  1322.     LD    E,A        ; for length in bc
  1323.     LD    A,B
  1324.     OR    C
  1325.     LD    A,E
  1326.     POP    DE
  1327.     RET    Z
  1328.     DEC    BC
  1329.     LD    (HL),A
  1330.     INC    HL
  1331.     JR    FILL
  1332. ;
  1333. ;    working storage area
  1334. ;
  1335. SUBNAM:
  1336.     DB    'SUB'
  1337. ZEXNAM:
  1338.     DB    'ZEX'
  1339. LINEM:
  1340.     DB    ' Error Line # $'
  1341. ZEXACT:
  1342.     DB    CR,LF,' ZEX Already Present$'
  1343. BUFMTY:
  1344.     DB    CR,LF,'Text Buffer Empty$'
  1345. OVERLP:
  1346.     DB    CR,LF,'Input/ZEX Buffer Overlap$'
  1347. NONUM:
  1348.     DB    CR,LF,'Parameter Number out of range$'
  1349. NOPRM:
  1350.     DB    CR,LF,'No Parameter or Default Parameter$'
  1351. PMERR:
  1352.     DB    CR,LF,'Parameter$'
  1353. NOSBF1:
  1354.     DB    CR,LF,'File '
  1355. NOSBF2:
  1356.     DB    'filename.typ$'
  1357. NOTHER:
  1358.     DB    ' not there$'
  1359. CMDER:
  1360.     DB    CR,LF,'Control character$'
  1361. TOOARG:
  1362.     DB    CR,LF,'Too many arguments - $'
  1363. SIGNON:
  1364.     DB    'ZEX, Version '
  1365.     DB    VERS/10+'0','.',(VERS MOD 10)+'0','$'
  1366. CRLFS:
  1367.     DB    CR,LF,'$'
  1368. ;
  1369.     DS    80        ;stack space
  1370. CCPSTK:
  1371.     DW    0        ;ccp stack ptr
  1372. IMFLG1:
  1373.     DB    0        ;=imon encountered
  1374. IMFLG2:
  1375.     DB    0        ;=imoff encountered
  1376. PRTFLG:
  1377.     DB    0        ;=psup on
  1378. LCHR:
  1379.     DB    0        ;last character read
  1380. PRMMAX:
  1381.     DB    0        ;highest parameter #
  1382. PRMNUM:
  1383.     DB    0        ;current $<1-9> number * 2 (ZERO RELATIVE)
  1384. ERRLNE:
  1385.     DW    0
  1386. BITMAP:
  1387.     DB    0        ;present offset bit's
  1388. COUNT:
  1389.     DB    0FFH        ;present offset bit count
  1390. BEGLIN:
  1391.     DW    BEGREL        ;beginning of old line pointer
  1392. LINES:
  1393.     DW    1
  1394. INBUF:
  1395.     DW    BEGREL
  1396. ENDBUF:
  1397.     DW    0        ;end of input buffer
  1398. OUTCNT:
  1399.     DB    0
  1400. OUTLNE:
  1401.     DW    0
  1402. RELSTRT:
  1403.     DW    0
  1404. OUTBUF:
  1405.     DW    0
  1406. BUFSTR:
  1407.     DW    0
  1408. RELOCL:
  1409.     DW    0        ;length of reloc program (filled in by sid)
  1410. PRMDFP:             ;default parameter ptrs
  1411.     DS    18
  1412.  
  1413. PRMDFL    EQU    $-PRMDFP
  1414. PRMDMY:
  1415.     DW    0        ;dummy parameter for .sub file spec.
  1416. PRMPNT:             ;command line parameter ptrs
  1417.     DS    18
  1418.  
  1419. PRMPNL    EQU    $-PRMPNT
  1420. PATCH:                ;patch area
  1421.     REPT    32
  1422.  
  1423.     DB    'p'
  1424.     ENDM
  1425.     DS    60
  1426.  
  1427. BEGREL:
  1428.     DS    0    ;reloc program starts here (also used as buffer)
  1429. ;
  1430. ;    ENDIF
  1431. ;
  1432. ;    end of zex initiator code segment
  1433. ;
  1434.  
  1435. ;*****************¬ STAR╘ O╞ ZE╪ *******************
  1436.  
  1437. ;
  1438. ;    start of zex relocated code segment
  1439. ;        hl pts to multiple command buffer
  1440. ;         or hl=0 if no multiple commands
  1441. ;
  1442. REST    EQU    $
  1443.  
  1444. ;    .DEPHASE
  1445.     .PHASE    ZEXADR        ;????
  1446.  
  1447. ZEX:
  1448.     LD    (EXMBASE),HL    ;save address of mcl buffer
  1449.     LD    HL,(Z3MSG+09H)    ;pt to next char
  1450.     LD    A,(HL)        ;get 1st char
  1451.     CP    MSUP        ;1st char=message suppress?
  1452.     JR    NZ,ZEX1        ;no...
  1453.     DEC    HL        ;yes..skip character
  1454.     LD    (Z3MSG+09H),HL    ;set ptr to next char
  1455.     LD    (MSUPFL),A    ;set initial flag
  1456. ZEX1:
  1457.     LD    SP,MEMTOP
  1458.     LD    HL,(BDOS+1)    ;get warm jump for standard ccp
  1459.     LD    (MEMTOP),HL    ;set ptr to top of memory
  1460.     INC    HL
  1461.     LD    E,(HL)        ;de = address of actual bdos
  1462.     INC    HL
  1463.     LD    D,(HL)
  1464.     EX    DE,HL        ;hl pts to actual bdos
  1465.     LD    A,H        ;subtract 8 for ccp entry point
  1466.     SUB    8
  1467.     LD    H,A
  1468.     LD    L,3        ;set up for warm ccp jump
  1469.     LD    (CCPJMP),HL
  1470.     LD    HL,(WARM+1)    ;save warm boot address
  1471.     LD    (WARMPT),HL
  1472.     LD    DE,BSWARM    ;save old bios jumps
  1473.     LD    BC,12
  1474.     LDIR            ;move bios jumps
  1475.     LD    DE,(WARMPT)
  1476.     LD    HL,LOCJMP    ;store new bios jumps
  1477.     LD    BC,12
  1478.     LDIR            ;move new bios jumps to bios area
  1479. ;
  1480. ;    zex runtime bios intercept routines
  1481. ;
  1482. NWARM:
  1483.     LD    SP,MEMTOP
  1484.     LD    HL,(Z3MSG+09H)    ;see if we're at buffers end
  1485.     LD    A,(HL)
  1486.     CP    0FFH        ;test it
  1487.     JP    Z,WARMX        ;warm return
  1488.     LD    HL,(WARMPT)    ;set warm boot address
  1489.     LD    (WARM+1),HL
  1490.     LD    HL,(MEMTOP)    ;set bdos entry address
  1491.     LD    (BDOS+1),HL
  1492.     LD    DE,BUFF        ;dma address
  1493.     LD    C,26        ;set dma
  1494.     CALL    BDOS
  1495.     LD    A,(BDISK)
  1496.     LD    C,A
  1497.     LD    HL,(CCPJMP)
  1498.     JP    (HL)        ;goto console processor
  1499. ;
  1500. ;    jmp table to overlay bios with new zex-based jumps
  1501. ;
  1502. LOCJMP:
  1503.     JP    NWARM        ;warm
  1504.     JP    BCONST        ;const
  1505.     JP    NCONIN        ;conin
  1506.     JP    NCONOT        ;conot
  1507. ;
  1508. ;    console input intercept routine
  1509. ;
  1510. NCONIN:
  1511.     LD    HL,Z3MSG+7    ;pt to zex message byte
  1512.     LD    A,(HL)        ;get zex message
  1513.     CP    2        ;suspend intercept?
  1514.     JP    Z,BCONIN    ;get input via bios if user input active
  1515.     CP    1        ;prompt just printed?
  1516.     JR    NZ,NCONNP
  1517.     LD    (HL),0        ;clear zex message
  1518.     LD    HL,STARTM    ;print message
  1519.     CALL    PMSG
  1520. ;    lda    pmchr        ;print prompt char
  1521. ;    mov    c,a
  1522. ;    call    bconot
  1523. NCONNP:
  1524.     LD    A,(Z3MSG+08H)    ;is zex running?
  1525.     OR    A        ;0=no
  1526.     JP    Z,WARMX        ;abort zex if not
  1527.     LD    (CONSTK),SP
  1528.     LD    SP,MEMTOP    ;set user stack
  1529. NCONNL:
  1530.     CALL    BCONST        ;get console status
  1531.     OR    A
  1532.     JP    Z,GETBUF    ;get character from buffer
  1533.     CALL    BCONIN        ;get character
  1534.     CP    'C'-'@'     ;see if terminate character
  1535.     JP    Z,ZEXABRT
  1536.     CP    'S'-'@'     ;13h
  1537.     JR    NZ,NCONEX
  1538.     CALL    BCONIN        ;wait for next character
  1539.     AND    7FH
  1540.     LD    HL,(Z3MSG+09H)    ;pt to next char
  1541.     INC    HL
  1542.     LD    (HL),A
  1543.     LD    (Z3MSG+09H),HL    ;reset ptr
  1544.     LD    A,'S'-'@'    ;13h
  1545. NCONEX:
  1546.     LD    SP,(CONSTK)    ;restore caller's stack
  1547.     RET
  1548. ;
  1549. ;  return next char from input buffer
  1550. ;
  1551. GETBUF:
  1552.     LD    A,(IPSUPFL)    ;combine psupfl and ipsupfl to set print flag
  1553.     OR    A        ;0=no suppress
  1554.     JR    Z,GBUF0
  1555.     LD    HL,Z3MSG+1    ;pt to if flag
  1556.     LD    A,(HL)        ;get if flag
  1557.     OR    A        ;no if?
  1558.     JR    Z,GBUF0
  1559.     INC    HL
  1560.     AND    (HL)        ;set if state
  1561.     JR    NZ,GBUF0    ;current if is true
  1562.     LD    A,0FFH        ;suppress print
  1563.     LD    (OUTFLG),A
  1564.     JR    GBUF1
  1565. GBUF0:
  1566.     LD    A,(PSUPFL)    ;set print suppress flag for nconot
  1567.     LD    (OUTFLG),A
  1568. GBUF1:
  1569.     CALL    GETCHR        ;get next character
  1570.     CP    UICH        ;user input?
  1571.     JP    Z,UISTRT    ;yes..set user input pending flag
  1572.     CP    REXEC        ;re-execute?
  1573.     JP    Z,REXECR    ;yes..reset buffer ptr
  1574.     CP    CRWAIT        ;cr wait?
  1575.     JP    Z,CRWRTN    ;yes..wait for cr
  1576.     CP    CRBWAIT        ;cr wait with ring bell?
  1577.     JP    Z,CRBWRTN    ;yes..wait for cr and ring bell
  1578.     CP    RNG        ;ring bell?
  1579.     JP    Z,RNGBELL    ;yes..just ring the bell
  1580.     CP    MSUP        ;message suppress flag?
  1581.     JP    Z,MSUPCK    ;yes..toggle flag
  1582.     CP    PSUP        ;print suppress ?
  1583.     JP    Z,PSUPCK    ;yes..toggle flag
  1584.     CP    IPS        ;false if print suppress?
  1585.     JP    Z,IPSUPCK
  1586.     CP    IMON        ;immediate mode start ?
  1587.     JP    Z,IMFLGS    ;yes..set flag
  1588.     CP    IMOFF        ;immediate mode stop?
  1589.     JP    Z,IMFLGS    ;yes..reset flag
  1590.     CP    CR        ;cr?
  1591.     JR    NZ,GETEXT    ;no...exit
  1592. ;
  1593. ; cr, so reset print suppression based only on ipsupfl
  1594. ;
  1595.     LD    A,(IPSUPFL)    ;combine psupfl and ipsupfl to set print flag
  1596.     OR    A        ;0=no suppress
  1597.     JR    Z,GBUF2
  1598.     LD    HL,Z3MSG+1    ;pt to if flag
  1599.     LD    A,(HL)        ;get if flag
  1600.     OR    A        ;no if?
  1601.     JR    Z,GBUF2
  1602.     INC    HL
  1603.     AND    (HL)        ;set if state
  1604.     JR    NZ,GBUF2    ;current if is true
  1605.     LD    A,0FFH        ;suppress print
  1606.     LD    (OUTFLG),A
  1607.     LD    A,CR
  1608.     JR    GETEXT
  1609. GBUF2:
  1610.     XOR    A
  1611.     LD    (OUTFLG),A    ;yes..reset print suppression
  1612.     LD    A,CR
  1613. GETEXT:
  1614.     LD    C,A
  1615.     LD    A,(IMFLG)
  1616.     CP    IMON        ;immediate mode ?
  1617.     LD    A,C
  1618.     JP    NZ,NCONEX    ;no...return to caller with char
  1619.     CALL    BCONOT        ;yes..immediate echo to console
  1620.     JP    NCONNL        ;...loop until imoff
  1621. ;
  1622. ;  ^" command
  1623. ;
  1624. UISTRT:
  1625.     LD    A,2        ;set message to suspend intercept
  1626.     LD    (Z3MSG+7),A
  1627.     LD    SP,(CONSTK)    ;restore caller's stack
  1628.     JP    NCONIN        ;get char from user for now
  1629. ;
  1630. ;  ^: command
  1631. ;
  1632. REXECR:
  1633.     LD    HL,(Z3MSG+0BH)    ;start at top of buffer again
  1634.     LD    (Z3MSG+09H),HL
  1635.     XOR    A
  1636.     LD    (IMFLG),A    ;reset all flags
  1637.     LD    (PSUPFL),A
  1638.     LD    (IPSUPFL),A
  1639.     LD    (MSUPFL),A
  1640.     JP    NCONNL        ;...loop until ^c
  1641. ;
  1642. ;  ^? command
  1643. ;
  1644. CRWRTN:
  1645.     CALL    BCONIN        ;get input char
  1646.     CP    'C'-'@'
  1647.     JP    Z,ZEXABRT    ;=^c
  1648.     CP    CR
  1649.     JR    Z,CRWRTX    ;=<cr>
  1650.     CP    ' '
  1651.     JR    Z,CRWRTX    ;=<sp>
  1652.     LD    C,BELL
  1653.     CALL    BCONOT        ;<>cr
  1654.     JR    CRWRTN
  1655. ;
  1656. ;  ^/ command
  1657. ;
  1658. CRBWRTN:
  1659.     LD    HL,DELAY    ;set counter
  1660. CRBWR1:
  1661.     PUSH    HL        ;save counter
  1662.     CALL    BCONST        ;check status
  1663.     POP    HL        ;get counter
  1664.     OR    A        ;set flags
  1665.     JR    NZ,CRBWR2
  1666.     DEC    HL        ;count down
  1667.     LD    A,H        ;done?
  1668.     OR    L
  1669.     JR    NZ,CRBWR1
  1670.     LD    C,BELL        ;ring bell
  1671.     CALL    BCONOT
  1672.     JR    CRBWRTN
  1673. CRBWR2:
  1674.     CALL    BCONIN        ;get char
  1675.     CP    'C'-'@'        ;abort?
  1676.     JP    Z,ZEXABRT
  1677.     CP    CR        ;cont if <cr>
  1678.     JR    NZ,CRBWRTN
  1679. ;
  1680. ;  ^| command
  1681. ;
  1682. CRWRTX:
  1683.     LD    C,A        ;echo cr/lf
  1684.     CALL    NCONOT
  1685.     LD    C,LF
  1686.     CALL    NCONOT
  1687.     JP    GETBUF
  1688. ;
  1689. ;  ^* COMMAND
  1690. ;
  1691. RNGBELL:
  1692.     LD    C,BELL        ;ring bell
  1693.     CALL    NCONOT
  1694.     JP    GETBUF
  1695. ;
  1696. ;  ^. command
  1697. ;
  1698. PSUPCK:
  1699.     LD    HL,PSUPFL
  1700.     CP    (HL)
  1701.     JR    NZ,PSUPST    ;set flags if not equal
  1702.     XOR    A        ;else reset flags
  1703. PSUPST:
  1704.     LD    (HL),A        ;set/reset saved flag
  1705.     JP    GETBUF        ;and get next character (sets exec flag)
  1706. ;
  1707. ;  ^& command
  1708. ;
  1709. IPSUPCK:
  1710.     LD    HL,IPSUPFL
  1711.     CP    (HL)
  1712.     JR    NZ,PSUPST    ;set flags if not equal
  1713.     XOR    A        ;else reset flags
  1714.     JR    PSUPST        ;set/reset flag in a
  1715. ;
  1716. ;  ^# command
  1717. ;
  1718. MSUPCK:
  1719.     LD    HL,MSUPFL
  1720.     CP    (HL)
  1721.     JR    NZ,MSUPST    ;set flags if not equal
  1722.     XOR    A        ;else reset flag
  1723. MSUPST:
  1724.     LD    (HL),A        ;set/reset flag
  1725.     JP    GETBUF        ;and get next character
  1726. ;
  1727. ;  ^< and ^> commands
  1728. ;
  1729. IMFLGS:
  1730.     LD    (IMFLG),A    ;set/reset immediate mode flag
  1731.     JP    GETBUF        ;get next character
  1732. ;
  1733. ;    console output intercept routine
  1734. ;
  1735. NCONOT:
  1736.     LD    A,(OUTFLG)    ;print suppression?
  1737.     OR    A
  1738.     RET    NZ        ;yes...ignore echo
  1739.     LD    A,C
  1740.     LD    (PMCHR),A    ;set last char output
  1741.     JP    BCONOT
  1742. ;
  1743. ;  get next char from buffer and terminate zex if end of buffer
  1744. ;
  1745. GETCHR:
  1746.     LD    HL,(Z3MSG+09H)    ;pt to next char
  1747.     LD    A,(HL)        ;get it
  1748.     DEC    HL        ;pt to following
  1749.     LD    (Z3MSG+09H),HL    ;reset ptr
  1750.     CP    0FFH        ;eob?
  1751.     RET    NZ        ;no...return
  1752.     LD    HL,(Z3MSG+09H)    ;pt to eob
  1753.     INC    HL        ;point to eob
  1754.     LD    (Z3MSG+09H),HL
  1755.     CALL    MOVBAK        ;move jumps back
  1756.     CALL    BDOSRST        ;restore bdos address
  1757.     CALL    PRDONEM
  1758.     XOR    A        ;turn off zex
  1759.     LD    (Z3MSG+08H),A
  1760.     LD    SP,(CONSTK)    ;get old stack
  1761.     LD    A,CR        ;return carriage return
  1762.     RET
  1763.  
  1764. ;
  1765. ;  print done message with following prompt char
  1766. ;
  1767. PRDONEM:
  1768.     LD    HL,DONEM    ;print message
  1769.     CALL    PMSG
  1770.     LD    A,(PMCHR)    ;print prompt char
  1771.     LD    C,A        ;in c for bios
  1772.     JP    BCONOT
  1773.  
  1774. ;
  1775. ;  restore bdos jmp if necessary
  1776. ;
  1777. BDOSRST:
  1778.     LD    HL,(MEMTOP)    ;see if bdos+1=memtop
  1779.     EX    DE,HL
  1780.     LD    HL,(BDOS+1)
  1781.     LD    A,E
  1782.     SUB    L
  1783.     LD    A,D
  1784.     SBC    A,H
  1785.     RET    NZ        ;don't replace bdos jump
  1786.     INC    DE        ;pt to bdos jump
  1787.     LD    A,(DE)        ;get low address
  1788.     LD    L,A        ;... in l
  1789.     INC    DE
  1790.     LD    A,(DE)        ;get high address
  1791.     LD    H,A        ;... in h
  1792.     LD    (BDOS+1),HL    ;reset bdos jump
  1793.     RET
  1794. ;
  1795. ;    ^c abort exit
  1796. ;
  1797. ZEXABRT:
  1798.     LD    SP,MEMTOP    ;^c aborts zex
  1799.     LD    HL,ABORTD    ;abort
  1800.     CALL    PMSG
  1801.     JR    WARMX1        ;don't print done message
  1802. ;
  1803. ;  abort zex and return to zcpr2
  1804. ;
  1805. WARMX:
  1806.     CALL    PRDONEM        ;print done message
  1807. ;
  1808. ;  entry point to abort zex without message
  1809. ;
  1810. WARMX1:
  1811.     XOR    A        ;say that zex is not running
  1812.     LD    (Z3MSG+08H),A
  1813.     CALL    MOVBAK        ;move jumps back
  1814.     CALL    BDOSRST        ;restore bdos jumps
  1815.     LD    HL,(EXMBASE)    ;multiple command lines enabled?
  1816.     LD    A,H        ;any on?
  1817.     OR    L
  1818.     JP    Z,WARM        ;none on if address is zero, so just warm boot
  1819. ;
  1820. ;  this section of code clears the multiple command line buffer
  1821. ;
  1822.     LD    D,H        ;de pts to multiple command buffer also
  1823.     LD    E,L
  1824.     PUSH    HL        ;save ptr
  1825.     LD    HL,4        ;pt to first char of line
  1826.     ADD    HL,DE
  1827.     LD    (HL),0        ;set first char of line to zero for eol
  1828.     EX    DE,HL        ;de pts to first char of line
  1829.     POP    HL        ;get ptr
  1830.     LD    (HL),E        ;store address of empty command (eol)
  1831.     INC    HL
  1832.     LD    (HL),D
  1833.     JP    WARM
  1834. ;
  1835. PMSG:
  1836.     PUSH    HL
  1837.     LD    A,(IPSUPFL)    ;combine psupfl and ipsupfl to set print flag
  1838.     OR    A        ;0=no suppress
  1839.     JR    Z,PMSG0
  1840.     LD    HL,Z3MSG+1    ;pt to if flag
  1841.     LD    A,(HL)        ;get if flag
  1842.     OR    A        ;no if?
  1843.     JR    Z,PMSG0
  1844.     INC    HL
  1845.     AND    (HL)        ;set if state
  1846.     POP    HL        ;in case of return
  1847.     RET    Z        ;skip message if suppressed
  1848.     PUSH    HL
  1849. PMSG0:
  1850.     POP    HL
  1851.     LD    A,(MSUPFL)    ;print message at (hl)
  1852.     CP    MSUP        ;messages suppressed?
  1853.     RET    Z        ;yes..exit
  1854. PMSGL:
  1855.     LD    A,(HL)        ;get next char
  1856.     OR    A        ;end of message?
  1857.     RET    Z        ;yes..exit
  1858.     INC    HL        ;pt to next char
  1859.     PUSH    HL        ;save ptr
  1860.     LD    C,A        ;output char
  1861.     CALL    BCONOT
  1862.     POP    HL        ;restore ptr
  1863.     JR    PMSGL
  1864. ;
  1865. ;    subroutines
  1866. ;
  1867. MOVBAK:
  1868.     LD    HL,(WARMPT)    ;move old jump table back to bios
  1869.     EX    DE,HL
  1870.     LD    HL,BSWARM
  1871.     LD    BC,12
  1872.     LDIR
  1873.  
  1874. ;
  1875. ;  replace zex routine jumps with bios jumps
  1876. ;
  1877. F121:
  1878.     LD    HL,BSWARM    ; insure only bios    1.1.2
  1879.     LD    DE,NWARM     ;  calls from now on    1.1.2
  1880.     LD    BC,3        ;   for programs    1.1.2
  1881.     LDIR            ;    that may have    1.1.2
  1882.     LD    HL,BCONIN    ;     copied our    1.1.2
  1883.     LD    DE,NCONIN    ;      addresses as    1.1.2
  1884.     LD    BC,3        ;    if they were    1.1.2
  1885.     LDIR            ;     in the bios.    1.1.2
  1886.     LD    HL,BCONOT    ;  (mbasic does this)    1.1.2
  1887.     LD    DE,NCONOT    ;            1.1.2
  1888.     LD    BC,3        ;            1.1.2
  1889.     LDIR            ;            1.1.2
  1890.     RET
  1891. ;
  1892. ;    working storage area
  1893. ;
  1894. ABORTD:
  1895.     DB    CR,LF,'[ZEX Aborted]',CR,LF,0
  1896. STARTM:
  1897.     DB    ' ZEX: ',0
  1898. DONEM:
  1899.     DB    'Done',0
  1900.  
  1901.     DS    30        ;stack space
  1902.  
  1903. MEMTOP:
  1904.     DW    0
  1905. EXMBASE:
  1906.     DW    0
  1907. CCPJMP:
  1908.     DW    0
  1909. WARMPT:
  1910.     DW    0
  1911. ;
  1912. ;    original bios jmp table
  1913. ;
  1914. BSWARM:
  1915.     JP    $
  1916. BCONST:
  1917.     JP    $
  1918. BCONIN:
  1919.     JP    $
  1920. BCONOT:
  1921.     JP    $
  1922. ;
  1923. PMCHR:
  1924.     DB    0
  1925. PSUPFL:
  1926.     DB    0
  1927. IPSUPFL:
  1928.     DB    0
  1929. OUTFLG:
  1930.     DB    0
  1931. NUICH:
  1932.     DB    0
  1933. IMFLG:
  1934.     DB    0
  1935. MSUPFL:
  1936.     DB    0
  1937. CONSTK:
  1938.     DW    0
  1939.  
  1940. ;?PLEN    DEFL    $
  1941. ;    IF (?PLEN MOD 8) GT 0
  1942. ;?PLEN    DEFL    (?PLEN AND 0FFF8H)+8    ;get next boundary
  1943. ;    ENDIF
  1944. ;
  1945. ;DRVERL    EQU    ?PLEN
  1946. ;
  1947. ;DRVL8    EQU    DRVERL/8    ;length of relocation bit map
  1948. ;    ORG    DRVERL
  1949. ;
  1950. ;
  1951. ;    end of zex relocated code segment
  1952. ;
  1953.     .DEPHASE
  1954.  
  1955. REEND    EQU    $
  1956. RELE    EQU    REEND-REST
  1957.  
  1958.     END
  1959.