home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / ZCPR33 / A-R / EASE20.LBR / EASE.ZZ0 / EASE.Z80
Text File  |  2000-06-30  |  42KB  |  2,364 lines

  1. ; PROGRAM:    Error And Shell Editor
  2. ; AUTHOR:    Paul Pomerleau and Jay Sage
  3. ; DATE:        October 23, 1987
  4. ; VERSION:    2.0
  5.  
  6. ; Copyright 1987, Paul Pomerleau
  7.  
  8. ; This program provides a history shell and error handler for ZCPR3.3
  9. ;   A complex line editor is used to edit command lines.
  10.  
  11. ; Run EASEDOC.COM to get a listing of Key-Command Bindings.
  12.  
  13. ; This file assembles with SLR's Z80ASM
  14.  
  15. ;    =====================================================
  16. ;
  17. ;        D E F I N I T I O N S    S E C T I O N
  18. ;
  19. ;    =====================================================
  20.  
  21. version    equ    20
  22. betastage    equ    ' '
  23.  
  24. no    equ    0
  25. yes    equ    0ffh
  26.  
  27. cr    equ    0dh
  28. lf    equ    0ah
  29. bell    equ    07h
  30. tab    equ    09h
  31.  
  32. bdos    equ    0005h
  33. bios    equ    0000h
  34. secbuf    equ    0080h
  35. sectop    equ    0100h
  36. killlen    equ    300
  37. maxsec    equ    8
  38.  
  39.     public    cout,ccout,print,pstr,crlf
  40.     extrn    acase2,sua,gua            ; SYSLIB
  41.     extrn    getmsg,getcst,putcst,putzex    ; Z3LIB
  42.     extrn    z3init,getquiet
  43.     extrn    erradr,getcl1,z3log
  44.     extrn    getwhl,getduok,dutdir
  45.     extrn    getsh,qshell,shpush,shpop,putreg,getreg
  46.     extrn    qerror,getsrun,haltsub
  47.     extrn    z33chk,stopxsub,subon        ; Z33LIB
  48.     extrn    getzrun,stopzex,haltzex
  49.     extrn    getefcb,parse2
  50.  
  51. ;    ==========================================================
  52. ;
  53. ;        S T A N D A R D    P R O G R A M    H E A D E R
  54. ;
  55. ;    ==========================================================
  56.  
  57. ENTRY:
  58.     jp    START
  59.     defb    'Z3ENV'
  60.     defb    3        ; Type-3 environment
  61. ENVADDR:
  62.     dw    0f300h
  63.     dw    ENTRY
  64.     defb    version
  65.  
  66.                 ; To go to the Error Handler, just
  67.                 ;   go to START with error flag set.
  68.  
  69. ;    ======================================================
  70. ;
  71. ;        C O N F I G U R A T I O N    A R E A
  72. ;
  73. ;    ======================================================
  74.  
  75. NAME:    db    'EASE    VAR'            ; Command history file
  76.  
  77. WIDTH:    dw    80                ; Length of line
  78.  
  79. TOOSHORT:
  80.     dw    02                ; Don't store in history 
  81.                         ;   if shorter than...
  82. GOBEGFLG:
  83.     db    yes
  84.  
  85. BEEPFLG:
  86.     db    yes
  87.  
  88. SMARTSAV:
  89.     db    yes                ; No causes penny pinching.
  90.  
  91. USEMEM:    db    no                ; Use memory (vs. registers)
  92. MEMLOC:    dw    47h                ; Memory location (3 free ones)
  93. STARTREG:                    ;   for EASE to use always.
  94.     db    7                ; First register to use
  95.  
  96. USE6:    db    no                ; Set to TRUE to use
  97.                         ;   BDOS 6 for input.
  98.  
  99. TABLE:    db    [[LASTCASE - VECTOR] / 3]    ; Number of cases
  100.     dw    BEEP                ; Default case ring bell
  101.  
  102. VECTOR:    db    'Q'
  103.     dw    SHIFTED        ; Meta Key
  104.     db    'D'
  105.     dw    FCHR        ; Right Char
  106.     db    'S'
  107.     dw    BCHR        ; Left Char
  108.     db    'E'
  109.     dw    UP        ; Up line
  110.     db    'X'
  111.     dw    DOWN        ; Down line
  112.     db    'A'
  113.     dw    MBWORD        ; Left word
  114.     db    'F'
  115.     dw    MFWORD        ; Right word
  116.     db    'S'+80h
  117.     dw    GOBOLN        ; Start of line
  118.     db    'D'+80h
  119.     dw    GOEOLN        ; End of line
  120.     db    'G'
  121.     dw    FDEL        ; Del char right
  122.     db    'H'
  123.     dw    DELCHR        ; Del char left
  124.     db    127
  125.     dw    DELCHR        ; Del char left
  126.     db    'T'
  127.     dw    FDWORD        ; Del word right
  128.     db    127 + 80h
  129.     dw    BDWORD        ; Del word left
  130.     db    'R'
  131.     dw    CMDKILL        ; Kill to semi-colon
  132.     db    'Y'+80h
  133.     dw    DELTOEND    ; Delete to end of line
  134.     db    'Y'
  135.     dw    DELLIN        ; Delete line
  136.     db    'U'
  137.     dw    UNDO        ; Reinsert deleted text
  138.     db    'B'
  139.     dw    BACKLINE    ; Back in history shell
  140.     db    'N'
  141.     dw    NEXTLINE    ; Forward in history shell
  142.     db    'O'
  143.     dw    BSEARCH        ; Search for first char
  144.     db    'V'
  145.     dw    TOGLIN        ; Toggle insert
  146. CCOMP:    db    'I'
  147.     dw    COMPLETE    ; Complete filename
  148.     db    'P'
  149.     dw    QINSERT        ; Insert any char
  150.     db    'W'
  151.     dw    REPLOT        ; Redraw line
  152.     db    'C'
  153.     dw    WARM        ; Warm Boot
  154.     db    'M'
  155.     dw    DONE        ; End edit
  156.     db    '_'+80h
  157.     dw    QUITSH        ; End EASE
  158. LASTCASE:
  159.  
  160. PUNC:    db    ',.:!#%^&<>[]{}()_+-=`~/\|; ',tab
  161. PUNCLEN    equ    $ - PUNC
  162. SEP:    db    ' ,=/<>|',tab
  163. SEPLEN    equ    $ - SEP
  164. ;    ===================================================
  165. ;
  166. ;        M A I N    C O D E    S E C T I O N
  167. ;
  168. ;    ===================================================
  169. RESTORE_STACK:
  170.     ld    sp,(SAVED_STACK)
  171.     ret
  172.  
  173. START:
  174.     ld    hl,(envaddr)    ; Get environment address
  175.     call    z3init        ; Initialize library routines
  176.     call    z33chk
  177.     ret    nz
  178.     call    SETCPM3
  179.     ld    (SAVED_STACK),sp
  180.     ld    hl,STACK
  181.     ld    sp,hl
  182.     ld    hl,RESTORE_STACK
  183.     push    hl
  184.     ld    a,(5dh)
  185.     push    af
  186.     call    GETSEC        ; Get the sector number
  187.     call    EASERUN
  188.     jr    z,FPFINE
  189.     ld    hl,BUFFER
  190.     ld    (POS),hl
  191.     call    SETFILE
  192.     call    RECOVER
  193.     call    PUTSEC
  194. FPFINE:    ld    c,19h    ; Get current disk
  195.     call    ADOS
  196.     inc    a
  197.     ld    (OLDDRIVE),a
  198.     pop    af
  199.     ld    (5dh),a
  200.     call    qerror        ; See if error handler invocation
  201.     jp    z,errorh    ; If so, branch to error processing
  202.     call    qshell
  203.     jp    z,RUNSH        ; Yes, don't install
  204.  
  205. ;=============================================================================
  206. ;
  207. ;        I N S T A L L A T I O N    C O D E
  208. ;
  209. ;=============================================================================
  210.  
  211. ; Program was invoked manually, so we need to set it up shell and error handler.
  212.  
  213. ;----------------------------------------
  214.  
  215. ; Subtask 1 -- determine whether to use a DU or a DIR prefix
  216. ;
  217. ; The program can examine the ZCPR33 option bytes to determine what features
  218. ; are supported (DU and/or DIR forms, which one first, wheel control over DU
  219. ; use, etc.).  For now we will just assume that a DU prefix will be used and
  220. ; will omit coding this block.
  221.  
  222. ;----------------------------------------
  223.  
  224. ; Get user option: if null, do both.  If E, then install the error handler
  225. ; else install the shell.
  226.  
  227.     ld    a,(5dh)
  228.     cp    'C'
  229.     jp    z,RUNSHNP
  230.     call    header
  231.     ld    a,(5dh)
  232.     cp    ' '            ; Error handler and shell
  233.     jr    z,BOTH
  234.     cp    'E'            ; Only error handler
  235.     jr    z,ERRONLY
  236.     jr    ISHELL            ; Only the shell
  237. BOTH:    call    ISHELL
  238.  
  239. ;----------------------------------------
  240.  
  241. ; Subtask 2 -- build error handling command line including directory prefix
  242. ; using data from the external FCB.  We use the fact that the drive and user
  243. ; where the program was actually found along the path are stored in the
  244. ; command file control block.  The user number is kept in the usual place;
  245. ; the drive is kept in the following byte.  The drive is in the range 1..16
  246. ; (unless the command is resident, in which case the drive byte is 0).
  247.  
  248. ERRONLY:
  249.     call    getmsg        ; Get pointer to error command line
  250.     ld    de,10h        ; ..in message buffer
  251.     add    hl,de
  252.     call    PUT_NAME_TO_HL
  253.     call    getquiet
  254.     ret    nz
  255.     call    CLPRINT
  256.     dc    ' Error Handler'
  257.     jr    P_CLST
  258.  
  259. ISHELL:    ld    hl,BUFFER
  260.     call    PUT_NAME_TO_HL
  261.     call    SHPUSH        ; Store the shell name
  262.     jr    nz,SHBAD    ; Push to deep?  Then abort
  263.     push    hl
  264.     call    SETFILE
  265.     call    RECOVER        ; Use existing file
  266.     call    PUTSEC
  267.     pop    hl
  268.     call    getquiet
  269.     ret    nz
  270. PRWELC:    call    CLPRINT
  271.     dc    ' Shell'
  272. P_CLST:    call    PRINT
  273.     dc    ': '
  274.     jp    PSTR        ; PRINT the string there and quit
  275.  
  276. SHBAD:    call    CLPRINT
  277. SHERR:    dc    'Shell Error'
  278.     ret
  279.  
  280. RECOVER:
  281.     ld    hl,SEC
  282.     ld    bc,BUFFER-SEC-1
  283.     call    ZERO
  284.     call    SET
  285.     call    OPEN
  286.     ret    z
  287. ;    jr    z,DELSET
  288. DOFNO:    call    FNOWRITE
  289.     jr    nz,DOFNO
  290.     call    FNOWRITE
  291.     jr    nz,DOFNO
  292.     jp    BNOWRITE
  293.  
  294. DELSET:    
  295.     ld    c,19        ; Delete
  296.     call    FBDOS
  297. SET:    xor    a
  298.     ld    (SEC),a        ; First sector
  299.     ld    hl,SECBUF + 1    ; +1==So no long pause -- at least at first.
  300.     ld    (FP),hl
  301.     jp    PUTSEC
  302.  
  303. PUT_NAME_TO_HL:
  304.     push    hl        ; Save pointer for way below
  305.     ex    de,hl        ; Switch pointer into DE
  306.  
  307.     call    getefcb        ; Get address of the command FCB
  308.     inc    hl        ; Advance pointer to name of program
  309.                 ; Get drive user from Z33's FCB.
  310.     push    hl
  311.     ld    bc,13        ; Offset to drive number
  312.     add    hl,bc        ; HL now points to the drive number
  313.  
  314. ; Here we get the drive where the program was found.  Since we know that this
  315. ; is not a resident program, there is no need to check for a zero value.
  316.  
  317.     ld    a,(hl)        ; Get it and
  318.     add    a,'A'-1        ; ..convert to a letter
  319.     ld    (de),a        ; Save in error command line
  320.     inc    de        ; Increment command line pointer
  321.  
  322.     dec    hl        ; Back up to user number
  323.     ld    a,(hl)        ; Get it and
  324.     call    mafdc        ; ..convert to decimal in command line
  325.  
  326.     ld    a,':'        ; Put in the colon
  327.     ld    (de),a
  328.     inc    de
  329.  
  330. cont1:
  331.     pop    hl        ; Restore the pointer to the command name
  332.     ld    bc,8        ; Copy 8 characters of name
  333.     ldir            ; ..into error command line
  334.  
  335.     xor    a        ; Store terminating null
  336.     ld    (de),a
  337.     pop    hl
  338.     ret
  339.  
  340. ;=============================================================================
  341. ;
  342. ;        E R R O R    H A N D L I N G    C O D E
  343. ;
  344. ;=============================================================================
  345.  
  346. ; This is the main entry point for error handling
  347.  
  348. errorh:
  349.     ld    a,(BEEPFLG)    ; Did the user want a Beep?
  350.     or    a
  351.     call    nz,BEEP
  352.  
  353. ;----------------------------------------
  354.  
  355. ; Subtask 1 -- Display program signon message
  356.  
  357. task1:
  358.     call    header
  359.  
  360. ;----------------------------------------
  361.  
  362. ; Subtask 2 -- Display system status
  363.  
  364. ; This task determines whether ZEX and/or SUBMIT are running.  Input
  365. ; redirection from either of them is turned off while error handling is
  366. ; performed (so user can provide the input).
  367.  
  368. task2:
  369.     call    stopzex        ; Stop ZEX input redirection
  370.  
  371.     call    CLPRINT
  372.     dc    lf,tab,'(ZEX '
  373.  
  374.     call    getzrun        ; Find out if ZEX is running
  375.     ld    e,a
  376.     ld    (ZEXORSUB),a
  377.     call    ponoff        ; Print on/off
  378.  
  379.     call    subon
  380.     jr    z,task2a    ; Branch if submit not supported
  381.  
  382.     call    PRINT
  383.     dc    ', SUBMIT '
  384.  
  385. ; See if submit is supported by the command processor
  386.  
  387.  
  388.     call    stopxsub    ; Stop XSUB input redirection
  389.     call    getsrun        ; Get submit running flag
  390.     call    ponoff        ; PRINT on/off
  391.     or    e
  392.     ld    (ZEXORSUB),a
  393.  
  394. ; See if wheel byte is on or off
  395.  
  396. task2a:
  397.     call    PRINT
  398.     dc    ', WHEEL '
  399.  
  400.     call    getwhl
  401.     call    ponoff
  402.     ld    a,')'
  403.     call    COUT
  404.  
  405. ;----------------------------------------
  406.  
  407. ; Subtask 3 -- Determine source of the error (internal or external) and
  408. ; display that information.
  409.  
  410. task3:
  411.     call    CLPRINT
  412.     dc    tab
  413.     call    getcst        ; Get command status flag
  414.     bit    3,a        ; See if external command bit is set
  415.     jr    nz,external    ; Branch if external error
  416.  
  417.     call    PRINT        ; "IN"ternal
  418.     dc    'In'
  419.     jr    task3a
  420.  
  421. external:
  422.     call    PRINT        ; "EX"ternal
  423.     dc    'Ex'
  424.  
  425. task3a:
  426.     call    PRINT        ; "TERNAL ERROR"
  427.     dc    'ternal error #'
  428.  
  429.     call    xcmdoff        ; Clear the external command bit (and ECP bit)
  430.  
  431. ;----------------------------------------
  432.  
  433. ; Subtask 4 -- Determine the error return code and display information about
  434. ; the nature of the error.  This section of the code can be expanded to cover
  435. ; more error types as they are defined.
  436.  
  437. task4:
  438.  
  439.     call    getmsg
  440.     ld    a,(hl)        ; Get the error return code
  441.     push    af        ; Save for use below
  442.     call    pafdc        ; Display the number
  443.     
  444.     call    PRINT
  445.     dc    ' -- '
  446.  
  447.     pop    af        ; Get error code back
  448.     cp    22
  449.     jr    c,OKERR
  450.     ld    a,4
  451. OKERR:    dec    a
  452.     ld    b,a
  453.     ld    hl,DUCHANGE
  454.     or    a
  455.     jr    z,PRINTERR
  456. SKIPERR:
  457.     ld    a,(hl)
  458.     inc    hl
  459.     and    10000000b
  460.     jr    z,SKIPERR
  461.     djnz    SKIPERR
  462. PRINTERR:
  463.     call    PSTR
  464.     call    CRLF
  465.  
  466.  
  467. ;----------------------------------------
  468.  
  469. ; Subtask 5 -- Display bad command line
  470. ;
  471. ; In the final code, much more elaborate error processing would be performed
  472. ; here (or more likely, the code here will be used as a framework for existing
  473. ; error handlers).
  474.  
  475. task5:
  476.     call    erradr        ; Get pointer to bad command line
  477.     push    hl        ; Save for reuse below
  478.     ld    de,BUFFER
  479.  
  480. scan:                ; Find end of this command
  481.     ld    a,(hl)
  482.     ld    (de),a
  483.     or    a        ; See if end of command line buffer
  484.     jr    z,GOTEND
  485.     cp    ';'        ; See if at command separator
  486.     jr    z,task5a
  487.     inc    hl        ; Point to next character
  488.     inc    de
  489.     jr    scan        ; Continue scanning
  490.  
  491. task5a:
  492.     push    af
  493.     push    hl
  494. FILLREST:
  495.     inc    hl
  496.     inc    de
  497.     ld    a,(hl)
  498.     ld    (de),a
  499.     or    a
  500.     jr    nz,FILLREST
  501.     pop    hl
  502.     pop    af
  503. GOTEND:
  504. OKT5A:    ld    a,(hl)
  505.     ld    (hl),0        ; Mark end of string
  506.     ld    (delimptr),hl    ; Save ptr to bad command's delimiter
  507.     ld    (delim),a    ; Store delimiter
  508.     push    af
  509.     ld    a,(ZEXORSUB)
  510.     or    a
  511.     jp    z,ERREDIT
  512.     call    CLPRINT
  513.     dc    tab,'Bad Command:',tab
  514.     pop    af
  515.     pop    hl        ; Restore pointer to beginning of command
  516.     push    af        ; Save delimiting character
  517.     call    PSTR        ; Display the bad command
  518.  
  519.     pop    af
  520.     or    a
  521.     jr    z,task6        ; If no rest of line, get out without output
  522.     push    hl        ; Save pointer to rest of command line
  523.     call    CLPRINT
  524.     dc    tab,'Rest of Line:',tab
  525.     pop    hl
  526.  
  527. task5b:
  528.     dec    hl        ; Pt back to bad command delimiter
  529.     ld    (hl),a        ; Put semicolon back
  530.     inc    hl
  531.     call    PSTR        ; PRINT rest of command line
  532.                 ;   AND RETURN!
  533.  
  534. ;----------------------------------------
  535.  
  536. ; Subtask 6 -- Deal with the bad command
  537.  
  538. ; This is where the real error handling is performed.  Here we just flush
  539. ; the entire command line and abort any submit job, but in a real error
  540. ; handler, several other functions would be performed.  With normal command
  541. ; lines (ZEX and SUBMIT not running), the user has the following three basic
  542. ; choices: fix the bad command, skip the bad command, or abort the entire
  543. ; command line.  If ZEX is running, there is an additional choice that should
  544. ; be available: abort the entire ZEX script.  Similarly, if SUBMIT is running,
  545. ; the user must be given the option to abort the entire submit job.
  546. ; This code implements all of the above with the additional feature
  547. ; that if the bad command is the last on the line, the option to skip
  548. ; to next command is not presented as it would be meaningless.
  549.  
  550. task6:
  551.     call    CLPRINT
  552.     dc    cr,lf,tab,'(E)dit/(A)bort'
  553.     ld    a,(delim)    ; Get bad command delimiter
  554.     or    a
  555.     jr    z,task6a    ; No trailing commands; skip next option
  556.     call    PRINT
  557.     dc    '/(C)ontinue'
  558. task6a:
  559.     call    PRINT
  560.     dc    ': '
  561.  
  562. task6c:    call    capin        ; get response
  563.     ld    b,a        ; Save for a moment
  564.     ld    a,(delim)    ; Get command delimiter again
  565.     or    a
  566.     ld    a,b        ; Response back in A
  567.     jr    z,task6b    ; Don't allow 's' choice if no trailing command
  568.     cp    'C'        ; Continue?
  569.     jr    z,skip
  570.  
  571. task6b:
  572.     cp    'A'        ; Abort?
  573.     jr    z,abort
  574.     cp    'E'        ; Edit?
  575.     jp    z,edit
  576.     call    beep        ; Bad input
  577.     jr    task6c
  578.  
  579. ;-----------------------------------------------------------------------------
  580.  
  581. ; Skip over bad command and resume with next in line
  582.  
  583. skip:
  584.     call    getcl1        ; Pt to command line buffer
  585.     ld    de,(delimptr)    ; DE pts to bad command's delimiter
  586.     inc    de        ; Now pointing to next command
  587.     ld    (hl),e        ; Stuff address in
  588.     inc    hl        ; ..first two bytes
  589.     ld    (hl),d        ; ..of multiple command line buffer
  590.  
  591.     call    PRINT
  592.     defb    'Continuing...',1
  593.     ret            ; Resume command execution with next command
  594.  
  595.  
  596. ;-----------------------------------------------------------------------------
  597.  
  598. ; Abort (flush) command line
  599.  
  600. abort:
  601.     call    abortmsg
  602.     call    getzrun        ; See if ZEX is running
  603.     jr    z,abort2    ; Branch if not
  604.  
  605. ; Deal with running ZEX script
  606.  
  607.     call    CLPRINT
  608.     dc    tab,'Abort ZEX script (Y/N)? '
  609.  
  610.     call    getyesno    ; Get user's answer
  611.     jr    nz,abort1    ; Branch if negative response
  612.  
  613.     call    haltzex        ; Abort ZEX
  614.     call    abortmsg
  615.     jr    abort2
  616.  
  617. abort1:
  618.     call    abort3
  619.  
  620. ; Deal with running SUBMIT job
  621.  
  622. abort2:
  623.     call    getsrun        ; Is a submit job running
  624.     ret    z        ; If not, return to command processor
  625.  
  626.     call    CLPRINT
  627.     dc    tab,'Abort SUBMIT job (Y/N)? '
  628.  
  629.     call    getyesno    ; Get user's answer
  630.     jr    nz,abort3    ; Branch if negative response
  631.  
  632.     call    haltsub        ; Abort SUBMIT
  633.  
  634. abortmsg:
  635.     call    PRINT
  636.     defb    'Aborted',1
  637.     ret
  638.  
  639. abort3:
  640.     call    PRINT
  641.     defb    ' No',1
  642.  
  643.     ret            ; Back to command processor
  644.  
  645. ;-----------------------------------------------------------------------------
  646.  
  647. ; XCMDOFF -- turn off external command flag
  648.  
  649. ; This routine turns off the external command bit and the ECP bit in the
  650. ; command status flag.
  651.  
  652. xcmdoff:
  653.     call    getcst        ; Get the command status flag
  654.     and    11110011b
  655.                 ; ..the error handler on return
  656.     jp    putcst        ; Put new value back and return
  657.  
  658. ;-----------------------------------------------------------------------------
  659.  
  660. ; GETYESNO -- get yes/no answer from user
  661.  
  662. ; Only 'Y' or 'y' accepted as affirmative answers.  Routine returns Z if
  663. ; affirmative, NZ otherwise.
  664.  
  665. getyesno:
  666.     call    capin        ; Get user response
  667.     cp    'Y'
  668.     ret
  669.  
  670. ;-----------------------------------------------------------------------------
  671.  
  672. ; PONOFF -- PRINT ON or OFF in message
  673. ;
  674. ; If the Z flag is set on entry, 'OFF' is displayed; otherwize 'ON' is
  675. ; displayed.
  676.  
  677. ponoff:
  678.     jr    z,poff
  679.  
  680.     call    PRINT
  681.     dc    'ON'
  682.     ret
  683.  
  684. poff:
  685.     call    PRINT
  686.     dc    'OFF'
  687.     ret
  688.  
  689. ; ------------------------------
  690. ; header -- PRINT program name and version
  691. ;
  692. header:    call    CLPRINT
  693.     defb    'Z33 Error And Shell Editor, Vers. '
  694.     defb    version / 10 + '0'
  695.     defb    '.'
  696.     defb    version mod 10 + '0'
  697.     dc    betastage
  698.     ret
  699.  
  700. ; ------------------------------
  701. ; CLPRINT -- PRINT CR LF and then following string.
  702. CLPRINT:
  703.     call    CRLF
  704.     jp    PRINT
  705.  
  706. ;-----------------------------------------------------------------------------
  707. ; Prompt -- PRINT a DU/DIR prompt.
  708. ;
  709. PROMPT:    call    QPROMPT        ; PRINT the DU:DIR
  710.     ld    a,(INSFLG)
  711. INSPROMPT:
  712.     or    a
  713.     ld    a,'>'        ; For insert
  714.     jr    nz,INSOK
  715.     ld    a,'}'        ; For no insert
  716. INSOK:    call    COUT
  717.     ld    a,'>'
  718.     jp    COUT
  719.  
  720. QPROMPT:
  721.     call    QERROR
  722.     jr    nz,NOTERR
  723.     call    PRINT
  724.     dc    '[Error] '
  725. NOTERR:    call    getmsg
  726.     ld    bc,2eh
  727.     add    hl,bc
  728.     ld    c,(hl)
  729.     inc    hl
  730.     ld    b,(hl)
  731.     call    getduok
  732.     jr    z,NODU
  733.     ld    a,b
  734.     add    a,'A'        ; Make it a letter    
  735.     call    COUT        ; Write it
  736.     ld    a,c
  737.     call    pafdc        ; Write it as a number
  738. NODU:    call    dutdir        ; Get the NDR
  739.     ret    z
  740.     push    hl
  741.     call    getduok
  742.     ld    a,':'
  743.     call    nz,COUT        ; And the colon to separate
  744.     pop    hl
  745.     ld    b,8        ; Eight chars max
  746. NAMELOOP:
  747.     ld    a,(hl)        ; Get the first char
  748.     cp    ' '        ; Is it the last
  749.     ret    z        ; YUP.  done
  750.     call    COUT        ; Write it
  751.     inc    hl
  752.     djnz    NAMELOOP    ; Repeat
  753.     ret
  754.  
  755. ; -----------------------------------------------------------
  756. ; FillLine
  757. ;  Check length of the new, edited, command line.  If it will 
  758. ; fit, copy it to the Z3 multiple command line buffer and 
  759. ; return to the CPR to execute it.  Otherwise, display error 
  760. ; message and branch back to the editor.
  761.  
  762. GETLEN:    ld    hl,BUFFER
  763.     push    hl
  764.     xor    a
  765.     ld    bc,killlen + 2
  766.     cpir            ; Find the ZERO
  767.  
  768.     dec    hl
  769.     pop    de
  770.     push    hl
  771.     sbc    hl,de        ; Get the length
  772.     ld    b,h
  773.     ld    c,l
  774.     pop    hl
  775.     ret
  776.  
  777. FILL:    xor    a
  778.     call    putcst        ; No errors
  779.     call    getcl1        ; Get Z3 command line addr in hl,
  780.                 ; ..length in a
  781.     cp    c        ; Compare with length of new line
  782.     jr    c,FILLERR    ; Branch if new line too long
  783.     ld    a,b        ; High order byte of length should be 0
  784.     or    a
  785.     jr    nz,FILLERR    ; Branch if not
  786.     push    hl        ; Save Z3CL
  787.     ld    de,4        ; Offset to first character in buffer
  788.     add    hl,de
  789.     ex    de,hl        ; First char address in DE
  790.     pop    hl        ; Z3CL address in HL
  791.     ld    (hl),e        ; Store ptr to first command
  792.     inc    hl        ; At Z3CL
  793.     ld    (hl),d
  794.     ld    hl,BUFFER    ; Get back pointer to new command
  795.     push    hl
  796.     inc    bc        ; Adjust length to include trailing null
  797.     ldir            ; Copy to system command line
  798.     call    EASERUN
  799.     pop    hl
  800.     ret    nz        ; Return if it was an error
  801.     ld    a,(SAVFLG)
  802.     or    a
  803.     ret    z        ; Didn't change from read: Don't save
  804.     push    hl
  805.     call    GETLEN        ; Get length again
  806.     ld    hl,(TOOSHORT)
  807.     sbc    hl,bc
  808.     pop    hl
  809.     ret    nc        ; Too short to save
  810.     push    hl
  811.     call    OPEN        ; Open 'er up
  812.     call    GETSEC        ; Get the intitial position
  813.     call    RRAND        ; Read in the current record
  814.     xor    a
  815.     call    WFFILE        ; Put the null to space the lines
  816.     pop    hl
  817. FILLWRITE:
  818.     ld    a,(hl)        ; Loop to put in the whole line
  819.     push    hl
  820.     call    WFFILE        ; Put in the next char of the line
  821.     pop    hl
  822.     ld    a,(hl)
  823.     inc    hl
  824.     or    a
  825.     jr    nz,FILLWRITE
  826.     call    BNOWRITE
  827.     call    PUTSEC
  828.     xor    a
  829.     call    WFFILE        ; Write final spacer null
  830.     xor    a
  831.     call    WFFILE        ; Put the null to space the lines
  832. FLUSH:    call    WRAND
  833. CLOSE:    ld    c,16        ; Close the file
  834. FBDOS:    ld    de,FCB
  835.     jp    BDOS        ; Go back to CPR to execute it
  836.  
  837. FILLERR:            ; To long for CCP to digest
  838.     call    CLPRINT
  839.     defb    bell,tab
  840.     defb    'Too long!',1
  841.     jp    EDIT2
  842.  
  843. EASERUN:
  844.     ld    b,0
  845.     call    GET
  846.     cp    'E'
  847.     ret
  848.  
  849. GET:    ld    a,(USEMEM)    ; B = Location 0..2
  850.     or    a
  851.     jr    z,GREGS
  852.     push    hl
  853.     push    de
  854.     ld    d,0
  855.     ld    e,b
  856.     ld    hl,(MEMLOC)
  857.     add    hl,de
  858.     ld    a,(hl)
  859.     pop    de
  860.     pop    hl
  861.     ret
  862. GREGS:    ld    a,(STARTREG)
  863.     push    bc
  864.     add    b
  865.     ld    b,a
  866.     call    getreg
  867.     pop    bc
  868.     ret
  869.  
  870. PUT:    ld    c,a        ; A = Data, B = location 0..2
  871.     ld    a,(USEMEM)
  872.     or    a
  873.     jr    z,PREGS
  874.     push    hl
  875.     push    de
  876.     ld    d,0
  877.     ld    e,b
  878.     ld    hl,(MEMLOC)
  879.     add    hl,de
  880.     ld    (hl),c
  881.     pop    de
  882.     pop    hl
  883.     ret
  884. PREGS:    ld    a,(STARTREG)
  885.     push    bc
  886.     add    b
  887.     ld    b,a
  888.     ld    a,c
  889.     call    putreg
  890.     pop    bc
  891.     ret
  892.  
  893. GETSEC:    ld    b,1
  894.     call    GET
  895.     ld    (SEC),a
  896.     inc    b
  897.     call    GET
  898.     ld    h,0
  899.     ld    l,a
  900.     ld    (FP),hl        ; Put the File Pointer to saved FP
  901.     ret
  902.  
  903. PUTSEC:    ld    a,'E'
  904.     ld    b,0
  905.     call    PUT
  906.     ld    a,(SEC)
  907.     call    INCPUT
  908.     ld    de,(FP)        ; Get SEC & FP
  909.     ld    a,e
  910. INCPUT:    inc    b
  911.     jp    PUT
  912.  
  913. ;-----------------------------------------------------------------------------
  914. ; Edit -- He, He, He...
  915. ;
  916. ERREDIT:
  917.     pop    af
  918.     pop    hl
  919.     jr    EDITNOE
  920. EDIT:    call    PRINT
  921.     db    'Edit',1    ; PRINT the 'E' for edit choice
  922. EDITNOE:
  923.     call    CRLF
  924.     ld    bc,BUFFER - ENDFLG - 1    ; Setup for zeroing out
  925.     jr    ESETUP
  926.  
  927. ;--------------------------
  928.  
  929. ; Run Shell (RUNSH) -- clear out the buffers and go to the editor.
  930.  
  931. RUNSH:
  932.     
  933. RUNSHNP:
  934.     call    GETSEC
  935.     ld    a,1        ; Z3 Cmd line for ZEX
  936.     call    putzex        ; Make ZEX think we are Z3
  937.     ld    bc,BUFFER - ENDFLG
  938. ESETUP:    call    SETUP
  939.  
  940. EDIT2:
  941.     call    OUTPUT1
  942. ELOOP:    xor    a
  943.     ld    (NOOUT+1),a    ; OK for output
  944.     call    GETKEY
  945.     ld    b,a
  946.     ld    a,(SHIFT)    ; Get shift mask
  947.     or    b
  948.     push    af
  949.     xor    a
  950.     ld    (SHIFT),a    ; Clear shift mask
  951.     pop    af
  952.     cp    ' '
  953.     jr    c,CONTROL    ; Yes, it's a command
  954.     cp    127
  955.     jr    nc,CONTROL
  956.     call    SAVECMD
  957.     call    INSERT        ; No, it's just a letter
  958.     jr    ELOOP
  959.  
  960. CONTROL:
  961.     ld    hl,ELOOP    ; Return to...
  962.     push    hl
  963.     ld    de,TABLE    ; Go to proper command
  964.     call    UCASE
  965.     call    SAVECMD
  966.     call    acase2
  967.  
  968. SAVECMD:
  969.     push    af
  970.     ld    a,(JUSTCMD)
  971.     ld    (LASTCMD),a
  972.     pop    af
  973.     ld    (JUSTCMD),a
  974.     ret
  975.  
  976. SHIFTED:
  977.     ld    a,10000000b    ; Make shift mask set high bit
  978.     ld    (SHIFT),a
  979.     ret
  980.  
  981. DELCHR:    call    DPOS        ; Back up and delete forward
  982.     ret    z
  983.     call    DELETE
  984.     jp    SHOWTOEND
  985.  
  986. FCHR:    call    FWRAP        ; Go ahead a char and wrap if EOL
  987.     jp    IPOS
  988.  
  989. FWRAP:    ld    hl,(POS)    ; Check for forward wrap
  990.     ld    a,(hl)
  991.     or    a
  992.     ret    nz
  993.     pop    hl
  994.     jp    GOBOLN
  995.  
  996. BCHR:    call    BWRAP        ; Go back and wrap if BOL
  997.     jp    DPOS
  998.  
  999. BWRAP:    ld    hl,(POS)    ; Check for back wrap
  1000.     dec    hl
  1001.     ld    a,(hl)
  1002.     or    a
  1003.     ret    nz
  1004.     pop    hl
  1005.     jp    GOEOLN
  1006.  
  1007. MBWORD:    call    BWRAP        ; Word forward with wrap
  1008. BWORD:    call    DPOS        ; Word forward without
  1009.     ret    z
  1010.     inc    de
  1011.     call    PUNCCP        ; Looking for punctuation
  1012.     jr    z,BWORD        ; Skip punct
  1013. BWORD2:    call    DPOS
  1014.     ret    z
  1015.     inc    de
  1016.     call    PUNCCP        ; Go till we hit punct
  1017.     jr    nz,BWORD2
  1018.     dec    de
  1019.     jp    IPOS
  1020.  
  1021. PUNCCP:    ld    hl,PUNC        ; Check for punctuation
  1022.     ld    bc,PUNCLEN
  1023.     cpir
  1024.     ret
  1025.  
  1026. FDWORD:    ld    de,0        ; Delete forward a word
  1027.     call    FWORD        ; Word forward
  1028.     push    de
  1029. FDWBACK:
  1030.     ld    a,d
  1031.     or    e
  1032.     jr    z,FDWENDBACK
  1033.     dec    de
  1034.     call    DPOS        ; Back up same number of Chars
  1035.     jr    FDWBACK
  1036. FDWENDBACK
  1037.     pop    de        ; Delete same number of chars
  1038.     jr    BDWRD1
  1039.  
  1040. BDWORD:    ld    de,0        ; Delete a word backwards
  1041.     call    BWORD
  1042. BDWRD1:    call    SETKILL
  1043. BDWRD2:    ld    a,d
  1044.     or    e
  1045.     jp    z,BDWRDEND
  1046.     dec    de
  1047.     push    de
  1048.     push    hl
  1049.     call    DELETE        ; Delete same number
  1050.     pop    hl
  1051.     inc    hl
  1052.     pop    de
  1053.     jr    BDWRD2
  1054.  
  1055. BDWRDEND:
  1056.     ld    (hl),0
  1057.     jp    SHOWTOEND
  1058.  
  1059. MFWORD:    call    FWRAP        ; Forward word with wrap
  1060. FWORD:    call    IPOS
  1061.     ret    z
  1062.     inc    de
  1063.     call    PUNCCP        ; Skip until punct
  1064.     jr    nz,FWORD
  1065. FWORD2:    call    IPOS
  1066.     ret    z
  1067.     inc    de
  1068.     call    PUNCCP        ; Skip punct
  1069.     jr    z,FWORD2
  1070.     dec    de
  1071.     jp    DPOS        ; Back up one
  1072.  
  1073. UP:    ld    hl,(WIDTH)    ; Back 80 chars
  1074. BACKUP:    ld    a,h
  1075.     or    l
  1076.     ret    z
  1077.     dec    hl
  1078.     push    hl
  1079.     call    DPOS        ; back up that many
  1080.     pop    hl
  1081.     ret    z
  1082.     cp    ' '
  1083.     jr    nc,BACKUP    ; Control chars count double
  1084.     ld    a,h
  1085.     or    l
  1086.     ret    z
  1087.     dec    hl
  1088.     jr    BACKUP
  1089.  
  1090. DOWN:    ld    hl,(WIDTH)    ; Go down a line
  1091. DOWNLOOP:
  1092.     ld    a,h
  1093.     or    l
  1094.     ret    z
  1095.     dec    hl
  1096.     push    hl
  1097.     call    IPOS        ; Forward 'til hl = zero
  1098.     pop    hl
  1099.     ret    z
  1100.     cp    ' '        ; Control chars count double
  1101.     jr    nc,DOWNLOOP
  1102.     ld    a,h
  1103.     or    l
  1104.     ret    z
  1105.     dec    hl
  1106.     jr    DOWNLOOP
  1107.  
  1108. COMPLETE:
  1109.     xor    a
  1110.     cpl
  1111.     ld    (NOOUT+1),a    ; NO output
  1112.     ld    hl,LASTCMD
  1113.     ld    a,(CCOMP)
  1114.     cp    (hl)
  1115.     jr    z,COMP2OK
  1116.     call    ISOLATE_NAME
  1117.     call    GET_FCB
  1118. COMPL3:    push    af
  1119.     xor    a
  1120.     ld    (NOOUT+1),a
  1121.     pop    af
  1122.     jp    z,NOT_FOUND
  1123.     call    BACK_UP_AND_REDISPLAY
  1124.     ret
  1125.  
  1126. COMP2OK:
  1127.     call    GET_NEXT
  1128.     ld    hl,(POS)
  1129.     jr    COMPL3
  1130.  
  1131. ISOLATE_NAME:
  1132.     ld    hl,(POS)
  1133.     push    hl
  1134. COMPLOOP:
  1135.     call    DPOS
  1136.     jr    z,COMPDONE
  1137.     ld    hl,SEP
  1138.     ld    bc,SEPLEN
  1139.     cpir
  1140.     jr    z,COMP2DONE
  1141.     jr    COMPLOOP
  1142. COMP2DONE:
  1143.     call    IPOS
  1144. COMPDONE:
  1145.     ld    hl,(POS)
  1146.     pop    de
  1147.     push    de
  1148.     ld    a,(de)
  1149.     push    af
  1150.     xor    a
  1151.     ld    (de),a
  1152.     ld    de,TBUF
  1153.     ld    (STARTNAME),hl
  1154. MLOOP:    ld    a,(hl)
  1155.     call    UPCASE
  1156.     ld    (de),a
  1157.     inc    de
  1158.     inc    hl
  1159.     cp    ':'
  1160.     jr    nz,NOCOLON
  1161.     ld    (STARTNAME),hl
  1162. NOCOLON:
  1163.     or    a
  1164.     jr    nz,MLOOP
  1165.     ld    hl,STARDOTSTAR
  1166.     dec    de
  1167.     ld    bc,4
  1168.     ldir
  1169.     pop    af
  1170.     pop    hl
  1171.     ld    (hl),a
  1172.     ret
  1173.  
  1174. GET_FCB:
  1175.     push    hl
  1176.     ld    hl,TBUF
  1177.     push    hl
  1178.     ld    de,5ch
  1179.     call    parse2
  1180.     ld    a,(5ch+15)
  1181.     or    a
  1182.     jr    nz,MISSION_ABORT
  1183.     pop    de        ; DMA at TBUF
  1184.     call    DMA
  1185.     ld    de,5ch
  1186.     call    PUTUD
  1187.     call    DZ3LOG
  1188.     ld    a,(5ch+13)
  1189.     ld    (SEARCH_USER),a
  1190.     ld    c,17
  1191.     call    ADOS
  1192. NEXT_NAME:
  1193.     inc    a
  1194.     jr    z,NOGO
  1195.     push    af
  1196.     call    SETDMA
  1197.     call    GETUD
  1198.     pop    af
  1199.     or    a
  1200. NOGO:    pop    hl
  1201.     ret
  1202.  
  1203. MISSION_ABORT:
  1204.     xor    a
  1205.     pop    hl
  1206.     pop    hl
  1207.     ret
  1208.  
  1209. GET_NEXT:
  1210.     push    hl
  1211.     ld    de,TBUF
  1212.     call    DMA
  1213.     ld    de,5ch
  1214.     call    PUTUD
  1215.     ld    a,(SEARCH_USER)
  1216.     ld    (5ch+13),a
  1217.     call    DZ3LOG
  1218.     ld    c,18
  1219.     call    ADOS
  1220.     jr    NEXT_NAME
  1221.  
  1222. NOT_FOUND:
  1223.     xor    a
  1224.     ld    (JUSTCMD),a
  1225.     ld    (POS),hl
  1226.     jp    beep
  1227.  
  1228. BACK_UP_AND_REDISPLAY:
  1229.     push    af
  1230.     ld    de,(STARTNAME)
  1231.     ld    (POS),hl
  1232.     jr    DEL_CHK_LOOP
  1233. DEL_LOOP:
  1234.     push    de
  1235.     call    DELCHR
  1236.     pop    de
  1237. DEL_CHK_LOOP:
  1238.     ld    hl,(POS)
  1239.     or    a
  1240.     sbc    hl,de
  1241.     jr    nz,DEL_LOOP
  1242.     pop    af
  1243.     dec    a
  1244.     add    a,a
  1245.     add    a,a
  1246.     add    a,a
  1247.     add    a,a
  1248.     add    a,a
  1249.     ld    e,a
  1250.     ld    d,0
  1251.     ld    hl,TBUF + 1
  1252.     add    hl,de
  1253.     ld    b,8
  1254. FNLOOP:
  1255.     ld    a,(hl)
  1256.     and    1111111b
  1257.     cp    ' '
  1258.     push    hl
  1259.     push    bc
  1260.     call    nz,INSERT
  1261.     pop    bc
  1262.     pop    hl
  1263.     inc    hl
  1264.     djnz    FNLOOP
  1265. FIRSTNAME:
  1266.     push    hl
  1267.     ld    a,'.'
  1268.     call    INSERT
  1269.     pop    hl
  1270.     ld    b,3
  1271. TYPLOOP:
  1272.     ld    a,(hl)
  1273.     and    1111111b
  1274.     cp    ' '
  1275.     jr    z,LASTNAME
  1276.     push    hl
  1277.     push    bc
  1278.     call    INSERT
  1279.     pop    bc
  1280.     pop    hl
  1281.     inc    hl
  1282.     djnz    TYPLOOP
  1283. LASTNAME:
  1284.     call    SHOWTOEND
  1285.     ret
  1286.  
  1287. WARM:    call    DONEOUT
  1288.     jp    0
  1289.  
  1290. DONE:    pop    hl        ; Save it and run it
  1291.     call    DONEOUT
  1292.     call    GETLEN        ; Get the length in BC
  1293.     ld    a,(BUFFER)
  1294.     cp    ';'        ; Comment?
  1295.     jr    z,JRUNSH
  1296.     or    a        ; Empty?
  1297.     jp    nz,FILL        ; Stuff the buffer
  1298. JRUNSH:    call    qerror
  1299.     ret    z
  1300.     call    qshell
  1301.     ret    nz
  1302.     call    CRLF
  1303.     jp    RUNSHNP
  1304.  
  1305. FDEL:    call    DELETE        ; Delete forward a char
  1306.     ret    z
  1307.     jp    SHOWTOEND    ; Redisplay
  1308.  
  1309. QINSERT:
  1310.     call    GETKEY        ; Get a key and insert it -- whatever it is
  1311.     or    a
  1312.     ret    z
  1313.     jp    INSERT
  1314.  
  1315. TOGLIN:                ; And Diagnostic Key (sometimes...)
  1316. ;    ld    b,0
  1317. ;    call    GET
  1318. ;    call    pa2hc
  1319. ;    call    print
  1320. ;    db    ', ',0
  1321. ;    ld    b,1
  1322. ;    call    GET
  1323. ;    call    pa2hc
  1324. ;    call    print
  1325. ;    db    ', ',0
  1326. ;    ld    b,2
  1327. ;    call    GET
  1328. ;    call    pa2hc
  1329. ;    call    print
  1330. ;    db    13,10,'FP:',0
  1331. ;    ld    a,(FP)
  1332. ;    call    pa2hc
  1333. ;    call    print
  1334. ;    db    ', SEC:',0
  1335. ;    ld    a,(SEC)
  1336. ;    call    pa2hc
  1337. ;    call    print
  1338. ;    db    ', BACK:',0
  1339. ;    ld    a,(BACKFLG)
  1340. ;    call    pa2hc
  1341. ;    call    print
  1342. ;    db    ', END:',0
  1343. ;    ld    a,(ENDFLG)
  1344. ;    call    pa2hc
  1345. ;    call    print
  1346. ;    db    '  ',0
  1347. ;    ret
  1348.  
  1349.     ld    hl,INSFLG    ; Toggle the insert flag
  1350.     ld    a,(hl)
  1351.     cpl
  1352.     ld    (hl),a
  1353.     ld    hl,(POS)
  1354.     push    hl
  1355.     push    af
  1356.     call    GOBOLN
  1357.     call    BACK
  1358.     call    BACK        ; Back up to the begining and back to ICHAR
  1359.     pop    af
  1360.     call    INSPROMPT
  1361.     pop    de
  1362. TOGLP:    ld    hl,(POS)    ; Go fwd to where we were
  1363.     sbc    hl,de
  1364.     ret    z
  1365.     call    IPOS
  1366.     jr    TOGLP
  1367.  
  1368. CMDKILL:
  1369.     call    SETKILL
  1370. CKL:    push    hl
  1371.     call    DELETE        ; Delete to a semi-colon
  1372.     pop    hl
  1373.     inc    hl
  1374.     cp    ';'
  1375.     jr    z,CKDONE
  1376.     or    a        ; Or a NULL
  1377.     jr    nz,CKL
  1378. CKDONE:    ld    (hl),0
  1379.     jp    SHOWTOEND    ; Redisplay
  1380.  
  1381. DELLN1:    call    GOBOLN
  1382.     jr    NSDELTOEND
  1383.  
  1384. DELLIN:
  1385.     call    GOBOLN        ; Go to start
  1386. DELTOEND:
  1387.     call    SETKILL
  1388. NSDELTOEND:
  1389.     call    CLRTOEND    ; Wipe everything on screen
  1390.     ld    hl,(POS)
  1391.     ld    (hl),0        ; Put a null at the start
  1392.     ret
  1393.  
  1394. GOEOLN:    call    IPOS        ; Move to end of line
  1395.     jr    nz,GOEOLN
  1396.     ret
  1397.  
  1398. GOBOLN:    call    DPOS        ; Move to start of line
  1399.     jr    nz,GOBOLN
  1400.     ret
  1401.  
  1402. REPLOT:    ld    hl,(POS)    ; RePRINT entire line
  1403.     push    hl
  1404.     call    GOEOLN        ; Go to end and give us a CR LF
  1405. REPLT1:    call    CRLF
  1406.     call    OUTPUT        ; Redisplay
  1407.     pop    de
  1408. GOTOPOS:
  1409.     or    a
  1410.     call    IPOS        ; Move fwd to old position
  1411.     sbc    hl,de
  1412.     ret    z
  1413.     jr    c,GOTOPOS
  1414. GP2:    call    DPOS
  1415.     ret    z
  1416.     sbc    hl,de        ; Done?
  1417.     ret    z
  1418.     jr    GP2
  1419.  
  1420. CAPIN:    call    cin
  1421.     ; Fall through to UPCASE
  1422.  
  1423. UCASE:    push    bc        ; Upcase A
  1424.     push    af
  1425.     and    80h
  1426.     ld    b,a
  1427.     pop    af
  1428.     and    7fh        ; Keep high bit
  1429.     call    UCASE2        ; Real upcase
  1430.     or    b
  1431.     pop    bc
  1432.     ret
  1433.  
  1434. UCASE2:
  1435.     cp    ' '        ; Standard blah blah upcase funct
  1436.     jr    nc,NOTCTL
  1437.     add    '@'
  1438. NOTCTL:    cp    'a'
  1439.     ret    c        ; Not a lowercase
  1440.     cp    'z'+1
  1441.     ret    nc        ; Not a lowercase
  1442.     sub    ' '        ; Yes, a lowercase
  1443.     ret
  1444.  
  1445. UPCASE:            ; More standard upcase
  1446.     cp    'z' + 1
  1447.     ret    nc
  1448.     cp    'a'
  1449.     ret    c
  1450.     sub    a,'a'-'A'
  1451.     ret
  1452.  
  1453. BSEARCH:
  1454.     call    OPEN        ; Check for open, etc.
  1455.     ld    hl,(FP)        ; Get our locations
  1456.     ld    a,(SEC)
  1457.     push    af
  1458.     push    hl
  1459.     ld    a,(ENDFLG)    ; Did we hit the end?
  1460.     or    a
  1461.     jr    z,BBDONE
  1462.     ld    a,(BACKFLG)    ; Did we back up right before this?
  1463.     or    a
  1464.     jr    nz,BBDONE
  1465.     call    BNOWRITE
  1466.     jr    z,BSRCHNO1
  1467. BBACK:    call    BNOWRITE    ; Find the NULL
  1468.     jr    nz,BBACK
  1469. BBDONE:    ld    bc,BUFFER
  1470.     push    bc
  1471. BSRCHL:    call    BNOWRITE    ; Is this the end?
  1472. BSRCHL2:
  1473.     call    BNOWRITE
  1474.     jr    z,BSRCHNO
  1475.     call    FNOWRITE    ; No, Place us properly
  1476. BSRCL1:    call    BNOWRITE
  1477.     jr    nz,BSRCL1
  1478.     call    FNOWRITE
  1479.     ld    c,0
  1480.     pop    de
  1481.     push    de
  1482. BSRCHECKING:
  1483.     inc    c
  1484.     call    UCASE
  1485.     ld    b,a
  1486.     ld    a,(de)
  1487.     ld    hl,(POS)
  1488.     sbc     hl,de
  1489.     jr    z,BSRGOTIT
  1490.     inc    de
  1491.     call    UCASE        ; Make all upcase
  1492.     cp    b
  1493.     jr    nz,BSRGOTIT    ; Same?
  1494.     push    de
  1495.     push    bc
  1496.     call    FNOWRITE
  1497.     pop    bc
  1498.     pop    de
  1499.     jr    BSRCHECKING
  1500. BSRGOTIT:
  1501.     push    af
  1502.     ld    b,c
  1503. BSR_BACKING_UP:
  1504.     push    bc
  1505.     call    BNOWRITE
  1506.     pop    bc
  1507.     djnz    BSR_BACKING_UP
  1508.     pop    af
  1509.     jr    nz,BSRCHL2
  1510.     call    NSDELTOEND
  1511.     xor    a
  1512.     call    BESET        ; We went back -- Indicate it
  1513.     cpl
  1514.     ld    de,(POS)
  1515.     ld    (NOOUT+1),a
  1516.     pop    bc
  1517.     pop    hl
  1518.     pop    af
  1519.     push    de
  1520.     call    GETLINE        ; Get a whole line in
  1521.     pop    hl
  1522.     ld    (POS),hl
  1523.     call    NOSAV
  1524. ;    xor    a        ; Getline always ends with a null
  1525.     ld    (NOOUT+1),a
  1526.     jp    SHOWTOEND
  1527. BSRCHNO:
  1528.     pop    bc
  1529. BSRCHNO1:
  1530.     call    BEEP        ; Not found do the beep thing
  1531. PUTBACK:
  1532.     pop    hl
  1533.     pop    af
  1534.     ld    (FP),hl        ; Restore our pointers
  1535.     ld    (SEC),a
  1536. RRAND:    ld    c,21h
  1537.     call    DORAND        ; Read that first one back in
  1538.     or    a
  1539.     ret    z
  1540. ZBUF:    push    de
  1541.     ld    hl,SECBUF    ; Zero out our record
  1542.     ld    bc,127
  1543.     call    ZERO
  1544.     pop    de
  1545.     ret
  1546.  
  1547. QUITSH:    call    qerror        ; Pop the shell stack
  1548. ;    ret    z        ; Unless we're in the error handler.
  1549.     pop    hl
  1550.     call    nz,SHPOP
  1551.     call    EASERUN
  1552.     ld    a,0
  1553.     ld    b,0
  1554.     call    z,PUT
  1555. DONEOUT:
  1556.     call    GOEOLN        ; Go to the end and CR
  1557.     ld    a,13
  1558. JCOUT:    jp    COUT
  1559.  
  1560. BEEP:    ld    a,bell
  1561.     jr    JCOUT
  1562.  
  1563. BACKLINE:            ; Go to previous command line
  1564.     call    OPEN
  1565.     ld    a,(ENDFLG)
  1566.     or    a
  1567.     call    z,EZER        ; Till we get to start
  1568. BGET:    call    BNOWRITE
  1569.     call    z,FNOWRITE
  1570.     jr    z,BEEP        ; No command line before
  1571.     ld    hl,TBUF
  1572.     ld    (hl),0
  1573.     inc    hl
  1574. BINSERT:            ; Insert the line backing up
  1575.     ld    (hl),a
  1576.     inc    hl
  1577.     push    hl
  1578.     call    BNOWRITE
  1579.     pop    hl
  1580.     jr    nz,BINSERT
  1581.     push    hl
  1582.     ld    hl,BACKFLG    ; Did we just go backwards?
  1583.     ld    a,(hl)
  1584.     ld    (hl),0ffh
  1585.     or    a
  1586.     pop    hl
  1587.     jr    z,BGET
  1588.     push    hl
  1589.     call    DELLN1        ; Kill existing line
  1590.     pop    hl
  1591.     dec    hl
  1592. BIN2:    ld    a,(hl)
  1593.     dec    hl
  1594.     or    a
  1595.     jr    z,GOBEGINOPTION    ; Put her there
  1596.     push    hl
  1597.     call    INSERT
  1598.     pop    hl
  1599.     jr    BIN2
  1600.  
  1601. GOBEGINOPTION:
  1602.     push    af
  1603.     ld    a,(GOBEGFLG)
  1604.     or    a
  1605.     call    nz,GOBOLN
  1606.     call    NOSAV
  1607.     pop    af
  1608.     ret
  1609.  
  1610. NEXTLINE:
  1611.     ld    a,(ENDFLG)    ; Are we at the end?
  1612.     or    a
  1613.     ret    z
  1614.     call    OPEN        ; Open the sucker if it ain't already
  1615. GETLINE:
  1616. FGET:    call    FNOWRITE
  1617.     jr    z,CHKTOP    ; At the end?
  1618.     push    af
  1619.     call    NOTTOP        ; Set flag
  1620.     pop    af
  1621.     ld    hl,TBUF
  1622. FINSERT:
  1623.     ld    (hl),a
  1624.     inc    hl
  1625.     push    hl
  1626.     call    FNOWRITE    ; Bring 'em in
  1627.     pop    hl
  1628.     jr    nz,FINSERT
  1629.     ld    (hl),0
  1630.     ld    hl,BACKFLG    ; Did we go back?
  1631.     ld    a,(hl)
  1632.     ld    (hl),0
  1633.     or    a
  1634.     jr    nz,FGET
  1635.     call    DELLN1        ; Delete the line
  1636.     ld    hl,TBUF
  1637. FIN2:    ld    a,(hl)
  1638.     inc    hl
  1639.     or    a
  1640.     jr    z,GOBEGINOPTION
  1641.     push    hl
  1642.     call    INSERT        ; Push the chars in
  1643.     pop    hl
  1644.     jr    FIN2
  1645.  
  1646. CHKTOP:    call    DELLN1        ; Clean out existing line
  1647.     call    BNOWRITE
  1648.     xor    a
  1649.     jr    ESET        ; Fix End Flag
  1650.  
  1651. NOTTOP:    xor    a
  1652.     cpl
  1653.     jr    ESET
  1654.  
  1655. EZER:    xor    a        ; Set the lot of them
  1656.     cpl
  1657. BESET:    ld    (BACKFLG),a
  1658. ESET:    ld    (ENDFLG),a
  1659.     ret
  1660.  
  1661. ; ---------------------------------------
  1662. ; Support routines for the commands above
  1663. ;
  1664. SETSCAN:
  1665.     push    af        ; Delete line and quiet terminal
  1666.     call    DELLN1
  1667.     xor    a
  1668.     cpl
  1669.     ld    (NOOUT+1),a
  1670.     pop    af
  1671.     ret
  1672.  
  1673. INSERT:    call    DOSAV
  1674.     ld    e,a        ; Put the char in
  1675.     ld    a,(INSFLG)
  1676.     or    a
  1677.     jr    nz,YAINS
  1678.     ld    hl,(POS)
  1679.     ld    a,(hl)
  1680.     or    a
  1681.     ld    a,e
  1682.     jr    nz,OVERWRITE    ; Do we insert?
  1683. YAINS:    xor    a
  1684.     ld    b,a
  1685.     push    de
  1686.     call    MOVEUP        ; Push them up
  1687.     pop    de
  1688.     jp    z,BEEP        ; No room
  1689.     ld    a,e
  1690. OVERWRITE:
  1691.     ld    hl,(POS)
  1692.     ld    (hl),a
  1693.     call    IPOS        ; Skip over it (PRINTing it)
  1694.     jp    SHOWTOEND    ; Redisplay
  1695.  
  1696. DELETE:    call    DOSAV
  1697.     ld    de,(POS)    ; Kill a char quiet-like
  1698.     ld    a,(de)
  1699.     or    a
  1700.     ret    z
  1701.     push    af
  1702.     ld    hl,DELETED
  1703.     inc    (hl)
  1704.     cp    ' '
  1705.     jr    nc,NOINC2    ; Increment DELETED as neccessary
  1706.     inc    (hl)
  1707. NOINC2:    call    MOVEDOWN    
  1708.     pop    af
  1709.     or    a
  1710.     ret
  1711.  
  1712. SETKILL:
  1713.     push    de
  1714.     ld    hl,(POS)
  1715.     ld    de,KILL
  1716.     push    de
  1717.     ld    bc,killlen    ; Stop before NULL in KILL
  1718.     ldir            ; Move it
  1719.     pop    hl
  1720.     pop    de
  1721.     ret
  1722.  
  1723. OUTPUT:    call    crlf        ; New line
  1724. OUTPUT1:
  1725.     call    PROMPT        ; Redisplay prompt
  1726. OUTPUT2:
  1727.     ld    hl,BUFFER    ; And command line
  1728.     ld    (POS),hl
  1729.     jp    SHOWTOEND
  1730.  
  1731. CLRTOEND:
  1732.     ld    hl,(POS)    ; Wipe out command line from cursor to right
  1733.     ld    de,0
  1734.     call    DOSAV
  1735. CLRLOOP:
  1736.     ld    a,(hl)        ; Loop until NULL
  1737.     or    a
  1738.     jr    z,NOWBACK
  1739.     cp    ' '
  1740.     jr    nc,CLR2
  1741.     inc    de
  1742.     call    SPACE        ; Two for Control Chars
  1743. CLR2:    call    SPACE        ; Overwrite it
  1744.     inc    hl
  1745.     inc    de
  1746.     jr    CLRLOOP
  1747. NOWBACK:
  1748.     ld    a,d
  1749.     or    e
  1750.     ret    z
  1751.     dec    de
  1752.     call    BACK        ; And return to old location
  1753.     jr    NOWBACK
  1754.  
  1755. IPOS:    ld    hl,(POS)    ; Get current char and PRINT it
  1756.     ld    a,(hl)
  1757.     or    a
  1758.     ret    z        ; Return zero if NULL
  1759.     push    af
  1760.     inc    hl
  1761.     ld    (POS),hl
  1762.     push    bc
  1763.     ld    b,a
  1764.     ld    a,(NOOUT + 1)    ; Silence?
  1765.     or    a
  1766.     ld    a,b
  1767.     pop    bc
  1768.     call    z,CCOUT
  1769.     pop    af
  1770.     ret
  1771.  
  1772. DPOS:    ld    hl,(POS)    ; Back up (^H)
  1773.     dec    hl
  1774.     ld    a,(hl)
  1775.     or    a
  1776.     ret    z
  1777.     push    af
  1778.     ld    (POS),hl
  1779.     cp    ' '
  1780.     call    c,BACK        ; Two for Control Char
  1781.     call    BACK
  1782.     pop    af
  1783.     ret
  1784.  
  1785. SHOWTOEND:
  1786.     call    PRINTHL        ; Show line to end
  1787.     jr    nz,SHOWLP
  1788.     ld    hl,DELETED    ; With spaces for deleted text
  1789.     ld    a,(hl)
  1790.     or    a
  1791.     jr    z,SHOWLP
  1792. SHW1:    push    af
  1793.     call    SPACE
  1794.     pop    af
  1795.     dec    a
  1796.     jr    nz,SHW1
  1797. SHW2:    call    BACK
  1798.     dec    (hl)
  1799.     jr    nz,SHW2
  1800. SHOWLP:    ld    a,d
  1801.     or    e
  1802.     ret    z
  1803.     dec    de
  1804.     call    DPOS
  1805.     jr    SHOWLP
  1806.  
  1807. PRINTHL:
  1808.     ld    de,0        ; Show text at HL to NULL
  1809. PHLOOP:    call    IPOS
  1810.     ret    z
  1811.     inc    de
  1812. KILLFLG:
  1813.     ld    a,0        ; Check for UNDO
  1814.     or    a
  1815.     ret    nz
  1816.     push    bc
  1817.     ld    c,11        ; Check for console in
  1818.     call    ADOS
  1819.     pop    bc
  1820.     or    a
  1821.     jr    z,PHLOOP
  1822.     call    cin        ; Check for previous input
  1823.     ld    (GETKEY+1),a
  1824.     cp    ' '
  1825.     jr    c,PHLOOP
  1826.     cp    127        ; If it's an input, don't redisplay
  1827.     ret    nz
  1828.     jr    PHLOOP
  1829.  
  1830. GETKEY:    ld    b,0
  1831.     xor    a
  1832.     ld    (GETKEY+1),a    ; Save the previous key
  1833.     ld    a,b
  1834.     or    a
  1835.     call    z,cin
  1836.     ret
  1837.  
  1838. MOVEUP:    ld    hl,(POS)    ; Move the text up to accept new char
  1839.     ld    a,' '
  1840. UPLOOP:    ld    b,(hl)
  1841.     ld    (hl),a
  1842.     inc    hl
  1843.     ld    a,b
  1844.     or    a
  1845.     jr    nz,UPLOOP
  1846.     ld    (hl),a
  1847.     ld    de,BUFFER + killlen
  1848.     sbc    hl,de        ; Until the end
  1849.     jr    z,MOVEDOWN    ; No good, move it back
  1850.     or    1
  1851.     ret
  1852.  
  1853. MOVEDOWN:            ; Move a char out -- Delete
  1854.     ld    hl,(POS)
  1855.     ld    d,h
  1856.     ld    e,l
  1857. DNLOOP:    inc    hl
  1858.     ld    a,(hl)        ; Pull them down till we find a NULL
  1859.     ld    (de),a
  1860.     or    a
  1861.     inc    de
  1862.     jr    nz,DNLOOP
  1863.     ret
  1864.  
  1865. UNDO:    ld    hl,KILL        ; Insert Kill buffer
  1866.     xor    a
  1867.     cpl
  1868.     ld    (KILLFLG + 1),a
  1869.     call    UNDO1
  1870.     xor    a
  1871.     ld    (KILLFLG + 1),a
  1872.     jp    SHOWTOEND
  1873. UNDO1:    ld    a,(hl)        ; insert at HL until NULL
  1874.     inc    hl
  1875.     or    a
  1876.     ret    z
  1877.     push    hl
  1878.     call    INSERT
  1879.     pop    hl
  1880.     jr    UNDO1
  1881.  
  1882. WFFILE:    call    RCHECK        ; Forward a char in the file with write
  1883.     ld    de,(FP)
  1884.     ld    (de),a
  1885.     ld    hl,SECTOP-1
  1886.     sbc    hl,de
  1887.     jr    nz,FNOWRITE
  1888.     call    WRAND
  1889. FNOWRITE:            ; Forward a char
  1890.     call    RCHECK
  1891.     ld    de,(FP)
  1892.     inc    de
  1893.     ld    hl,SECTOP
  1894.     sbc    hl,de
  1895.     jr    nz,NOREAD
  1896.     ld    hl,SEC
  1897.     inc    (hl)
  1898.     call    RRAND
  1899.     ld    de,SECBUF
  1900. NOREAD:    ld    a,(de)
  1901.     ld    (FP),de
  1902.     or    a
  1903.     ret
  1904.  
  1905. WBFILE:    call    RCHECK        ; Back a char in file with write
  1906.     ld    de,(FP)
  1907.     ld    (de),a
  1908.     ld    hl,SECBUF
  1909.     sbc    hl,de
  1910.     jr    nz,BNOWRITE
  1911.     call    WRAND
  1912. BNOWRITE:            ; Back a char
  1913.     call    RCHECK
  1914.     or    a
  1915.     ld    de,(FP)
  1916.     dec    de
  1917.     ld    hl,SECBUF-1
  1918.     sbc    hl,de
  1919.     jr    nz,NOREAD
  1920.     ld    hl,SEC
  1921.     dec    (hl)        ; Should never get to be ZERO... Honest.
  1922.     jr    nc,BNOZERO
  1923.     ld    (hl),0        ; But, what the hell, it's free.
  1924. BNOZERO:
  1925.     call    RRAND
  1926.     ld    de,SECTOP-1
  1927.     jr    NOREAD
  1928.  
  1929. WRAND:    ld    c,22h        ; Write random
  1930.     call    DORAND
  1931.     or    a
  1932.     ret    z
  1933.     jp    nz,WMERR
  1934.  
  1935. DORAND:    ld    a,(SEC)        ; Put random record in right place in FCB
  1936.     ld    hl,FCB+33    ; Set the DMA and call BDOS
  1937.     ld    (hl),a
  1938.     inc    hl
  1939.     xor    a
  1940.     ld    (hl),a
  1941.     inc    hl
  1942.     ld    (hl),a
  1943.     push    de
  1944.     call    SETDMA
  1945.     call    FBDOS
  1946.     pop    de
  1947.     ret
  1948.  
  1949. SETDMA:    push    bc        ; Set the DMA to the SECBUF
  1950.     ld    de,SECBUF
  1951.     call    DMA
  1952.     pop    bc
  1953.     ret
  1954.  
  1955. DMA:    ld    c,26
  1956.     jp    ADOS
  1957.  
  1958. BCD2:    push    bc        ; Format two digit numbers
  1959.     ld    c,0ffh
  1960. BCD2A:    inc    c
  1961.     sub    10
  1962.     jr    nc,BCD2A    ; Put them in BCD (??) form
  1963.     add    a,10
  1964.     ld    b,a
  1965.     ld    a,c
  1966.     rlca
  1967.     rlca
  1968.     rlca
  1969.     rlca
  1970.     or    b
  1971.     pop    bc
  1972.     ret
  1973.  
  1974. PAFDC:    ld    d,0        ; PRINT them out
  1975.  
  1976. MAFDC:    push    af        ; Put them in a memory location
  1977.     call    BCD2
  1978.     push    af
  1979.     rra
  1980.     rra
  1981.     rra
  1982.     rra
  1983.     and    1111b
  1984.     call    nz,DEPUT    ; Output tens
  1985.     pop    af
  1986.     call    DEPUT        ; Output ones
  1987.     pop    af
  1988.     ret
  1989. DEPUT:    and    1111b
  1990.     add    '0'
  1991.     inc    d
  1992.     dec    d        ; Check for output
  1993.     jp    z,COUT
  1994.     ld    (de),a        ; Else memory stuff
  1995.     inc    de
  1996.     ret
  1997.  
  1998. SETCPM3:
  1999.     ld    a,(USE6)
  2000.     or    a
  2001.     jr    nz,SETCINFN6
  2002.     ld    hl,CINFN1    ; .. set vector to
  2003.     ld    (cinjmp),hl    ; .. function 6 routine
  2004.     ld    c,12        ; if CP/M Plus
  2005.     call    BDOS
  2006.     cp    30h
  2007.     ret    c
  2008. SETCINFN6:
  2009.     ld    hl,CINFN6    ; .. set vector to
  2010.     ld    (cinjmp),hl    ; .. function 6 routine
  2011.     ret    
  2012. ;
  2013. cinjmp equ $+1
  2014. CIN:    jp    0        ;vector to console input routine
  2015. ;
  2016.  
  2017. ;
  2018. ; Bdos console in, fn 1--no echo.
  2019. ;
  2020. CINFN1:
  2021.     push    hl
  2022.     push    de
  2023.     push    bc
  2024.     ld    hl,(1)        ; patch bios conout
  2025.     ld    de,9
  2026.     add    hl,de
  2027.     ld    e,(hl)        ; save bios byte (might not be JP)
  2028.     ld    (hl),0c9h    ; .. to RET to prevent echo
  2029.     ld    c,1        ; get char from bdos
  2030.     call    ADOS
  2031.     ld    (hl),e        ; restore bios conout byte
  2032.     pop    bc
  2033.     pop    de
  2034.     pop    hl
  2035.     ret
  2036. ;
  2037. ; Bdos console in, fn 6--no echo.
  2038. ;
  2039. CINFN6:
  2040.     push    de
  2041.     push    bc
  2042. CINF60:    ld    c,6
  2043.     ld    e,0ffh
  2044.     call    ADOS
  2045.     or    a
  2046.     jr    z,CINF60    ;..wait for input
  2047.     pop    bc
  2048.     pop    de
  2049.     ret
  2050.  
  2051. RCHECK:    push    af        ; Have we read already?
  2052.     ld    a,(RDFLG)
  2053.     or    a
  2054.     jr    nz,RCK1        ; Yes
  2055.     cpl
  2056.     ld    (RDFLG),a    ; No, now yes
  2057.     push    hl
  2058.     push    bc
  2059.     call    RRAND        ; And read
  2060.     pop    bc
  2061.     pop    hl
  2062. RCK1:    pop    af
  2063.     ret
  2064.  
  2065. SETFILE:            ; Make FCB ok w/respect to Z33 FCB
  2066.     ld    hl,FCB
  2067.     ld    bc,35        ; Zero out FCB and DMA.
  2068.     call    ZERO
  2069.     ld    hl,SECBUF
  2070.     ld    bc,80h
  2071.     call    ZERO
  2072.     ld    hl,NAME
  2073.     ld    de,FCB+1
  2074.     ld    bc,11
  2075.     ldir
  2076.     call    getefcb
  2077.     ld    bc,14        ; Offset to drive number
  2078.     add    hl,bc        ; HL now points to the drive number
  2079.  
  2080. ; Here we get the drive where the program was found.  Since we know that this
  2081. ; is not a resident program, there is no need to check for a zero value.
  2082.  
  2083.     ld    a,(hl)        ; Get it and
  2084.     ld    de,FCB
  2085.     ld    (de),a
  2086.     dec    hl        ; Back up to user number
  2087.     ld    a,(hl)        ; Get it and
  2088.     ld    (FCB+13),a    ; put it in our FCB
  2089.     ld    de,FCB
  2090.     jp    z3log
  2091.  
  2092. OPEN:    call    EASERUN
  2093.     ret    nz        ; Don't perform any file operations!
  2094.     ld    hl,OPENFLG    ; Open the file
  2095.     ld    a,(hl)
  2096.     or    a
  2097.     ret    nz
  2098.     ld    (hl),0ffh
  2099. OKFP:    call    SETFILE
  2100.     ld    c,15        ; Open
  2101.     call    FBDOS
  2102.     inc    a
  2103.     ret    nz
  2104. YANEW:    call    DELSET
  2105.     ld    c,22        ; Make
  2106.     call    FBDOS
  2107.     inc    a
  2108.     jr    z,WMERR
  2109.     call    ZBUF
  2110.     call    SETDMA
  2111.     xor    a
  2112.     ret
  2113.  
  2114. SETUP:    ld    hl,INSFLG    ; Fill and Zap
  2115.     ld    (hl),0ffh
  2116.     inc    hl
  2117.     ld    (hl),0ffh    ; BACKFLG
  2118.     inc    hl
  2119.     jp    ZERO        ; Zero out to exhaustion of bc
  2120.  
  2121. NOSAV:    push    af
  2122.     xor    a
  2123. SAVSTO:    push    bc
  2124.     ld    b,a
  2125.     ld    a,(SMARTSAV)
  2126.     or    b
  2127.     ld    (SAVFLG),a
  2128.     pop    bc
  2129.     pop    af
  2130.     ret
  2131.  
  2132. DOSAV:    push    af
  2133.     xor    a
  2134.     cpl
  2135.     jr    SAVSTO
  2136.  
  2137. ZERO:    ld    d,h        ; Fill and area with zeros
  2138.     ld    e,l
  2139.     inc    de
  2140.     ld    (hl),0
  2141.     ldir
  2142.     ret
  2143.  
  2144. WMERR:    call    GOEOLN        ; Write and error message
  2145.     call    crlf
  2146.     ld    hl,DISKFULL
  2147.     call    PSTR
  2148.     ld    a,'!'
  2149.     ld    (OPENFLG),a
  2150.     call    COUT
  2151.     pop    hl
  2152.     jp    REPLOT
  2153.  
  2154. DZ3LOG:    ld    a,(de)
  2155.     or    a
  2156.     ld    a,(OLDDRIVE)
  2157.     jp    nz,z3log
  2158.     ld    (de),a
  2159.     jp    z3log
  2160.  
  2161. PUTUD:    push    bc
  2162.     push    af
  2163.     call    GUA
  2164.     ld    (SUSER),a
  2165.     ld    c,19h
  2166.     call    ADOS
  2167.     ld    (SDRIVE),a
  2168.     pop    af
  2169.     pop    bc
  2170.     ret
  2171.  
  2172. GETUD:    push    de
  2173.     push    bc
  2174.     push    af
  2175.     ld    a,(SUSER)
  2176.     call    SUA
  2177.     ld    a,(SDRIVE)
  2178.     call    SETDRIVE
  2179.     pop    af
  2180.     pop    bc
  2181.     pop    de
  2182.     ret
  2183.  
  2184. SETDRIVE:
  2185.     ld    e,a
  2186.     ld    c,0eh
  2187. ADOS:    push    bc
  2188.     push    de
  2189.     push    hl
  2190.     call    BDOS
  2191.     pop    hl
  2192.     pop    de
  2193.     pop    bc
  2194.     ret
  2195.  
  2196.  
  2197. PRINT:    ex    (sp),hl        ; PRINT a string
  2198.     call    PSTR
  2199.     ex    (sp),hl
  2200.     ret
  2201.  
  2202. PSTR:    push    af        ; PRINT a string at HL
  2203.     ld    a,(hl)
  2204.     inc    hl
  2205.     or    a
  2206.     jr    z,PSTR1
  2207.     cp    1
  2208.     jr    z,DCRLF        ; If 1, then end with a CRLF
  2209.     push    af
  2210.     and    01111111b
  2211.     call    COUT
  2212.     pop    af
  2213.     and    10000000b
  2214.     jr    nz,PSTR1
  2215.     pop    af
  2216.     jr    PSTR
  2217. DCRLF:    call    CRLF
  2218. PSTR1:    pop    af
  2219.     ret
  2220.  
  2221. CCOUT:    push    af
  2222. ;    cp    8        ; For valid CCOUT, these are needed...
  2223. ;    jr    z,OK        ;   But who's gonna know?
  2224. ;    cp    13
  2225. ;    jr    z,OK
  2226. ;    cp    10
  2227. ;    jr    z,OK
  2228.     cp    ' '
  2229.     jr    nc,OK
  2230.     push    af
  2231.     ld    a,'^'
  2232.     call    COUT
  2233.     pop    af
  2234.     add    '@'
  2235. OK:    call    COUT
  2236.     pop    af
  2237.     ret
  2238.  
  2239. SPACE:    ld    a,' '        ; PRINT a space
  2240.     jr    COUT
  2241.  
  2242. BACK:    ld    a,8        ; PRINT a ^H
  2243.  
  2244. COUT:    push    af        ; Output
  2245.     push    bc
  2246.     push    de
  2247.     push    hl
  2248.     ld    e,a
  2249.  
  2250. NOOUT:    ld    a,0        ; Being quiet
  2251.     or    a
  2252.     ld    c,6
  2253.     call    z,pbdos        ; And the real PRINT
  2254.     pop    hl
  2255.     pop    de
  2256.     pop    bc
  2257. CPOP:    pop    af
  2258.     ret
  2259.  
  2260. PBDOS:    ld    a,e
  2261.     ld    hl,SPOS
  2262.     cp    8
  2263.     jr    z,BACKP
  2264.     cp    13
  2265.     jr    z,ZEROP
  2266.     cp    7
  2267.     jr    z,NOIP
  2268.     cp    10
  2269.     jr    z,NOIP
  2270.     cp    9
  2271.     jr    z,TABCHR
  2272.     inc    (hl)
  2273. NOIP:    jp    BDOS        ; BIOS COUT
  2274. ZEROP:    ld    (hl),1
  2275. BACKP:    dec    (hl)
  2276.     jr    NOIP
  2277. TABCHR:    ld    a,' '        ; Expand Tab
  2278.     call    COUT
  2279.     ld    a,7
  2280.     and    (hl)
  2281.     ret    z
  2282.     jr    TABCHR
  2283.  
  2284. CRLF:    call    PRINT        ; PRINT a CRLF
  2285.     dc    cr,lf
  2286.     ret
  2287.  
  2288.  
  2289. ;============================================================================= 
  2290. ;               C O N S T A N T S
  2291. ;=============================================================================
  2292. DUCHANGE:
  2293.     dc    'Illegal attempt to change directory'
  2294. BADDU:
  2295.     dc    'Invalid directory'
  2296. BADPW:
  2297.     dc    'Incorrect password'
  2298. UNKNOWN:
  2299.     dc    'Unknown error'
  2300. BADFORM:
  2301.     dc    'Bad command name (file type or wild card used)'
  2302. BADECP:
  2303.     dc    'Command not found (even by ECP)'
  2304. BADCMD:
  2305.     dc    'Requested load file not found on disk'
  2306. AMBIG:
  2307.     dc    'Ambiguous or missing file name'
  2308. BADNUM:
  2309.     dc    'Bad numerical expression'
  2310. NOFILE:
  2311.     dc    'Source file not found'
  2312. DISKFULL:
  2313.     dc    'Disk full'
  2314. OVERFLOW:
  2315.     dc    'TPA overflow'
  2316. DUPLICATE:
  2317.     dc    'Duplicate file specifications'
  2318.     dc    'Segment too large'
  2319.     dc    'Bad segment address'
  2320.     dc    'Command line overflow'
  2321.     dc    'Duplicate file specification'
  2322.  
  2323.     dc    '7'
  2324.     dc    '8'    ; 17...19 not yet in use
  2325.     dc    '9'
  2326.     dc    'Can''t load rsx'
  2327.     dc    'Can''t remove rsx'
  2328. STARDOTSTAR:
  2329.     db    '*.*',0
  2330.  
  2331. ;               B U F F E R S 
  2332. ;        -------------
  2333.  
  2334. STACK    equ    entry + 1310h
  2335. SAVED_STACK    equ    stack + 2
  2336. FCB    equ    saved_stack + 2
  2337. OLDDRIVE    equ    fcb + 36
  2338. STARTNAME    equ    olddrive + 1
  2339. SEARCH_USER    equ    startname + 2
  2340. LASTCMD    equ    search_user + 1
  2341. JUSTCMD    equ    lastcmd + 1
  2342. SUSER    equ    justcmd + 1
  2343. SDRIVE    equ    suser + 1
  2344. SEC    equ    sdrive + 1
  2345. FP    equ    sec + 2
  2346. POS    equ    fp + 2
  2347. DELIMPTR    equ    pos + 2
  2348. DELIM    equ    delimptr + 2
  2349. ZEXORSUB    equ    delim + 2
  2350. INSFLG    equ    zexorsub + 1
  2351. BACKFLG    equ    insflg + 1
  2352. ENDFLG    equ    backflg + 1
  2353. RDFLG    equ    endflg + 1
  2354. OPENFLG    equ    rdflg + 1
  2355. SHIFT    equ    openflg + 1
  2356. SAVFLG    equ    shift + 1
  2357. SPOS    equ    savflg + 1
  2358. DELETED    equ    spos + 1
  2359. TBUF    equ    deleted + 2
  2360. KILL    equ    tbuf + killlen + 2
  2361. BUFFER    equ    kill + killlen + 2
  2362. DEFAULT_TOP_OF_BUFFER    equ    buffer + killlen
  2363.     end
  2364. equ    d