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 / JSAGE / ZSUS / TCJ / TCJ35-L1.Z80 < prev    next >
Text File  |  2000-06-30  |  10KB  |  343 lines

  1. ; Program:    WordStar Shell Modification Patches
  2. ; Author:    Jay Sage
  3. ; Date:        August 7, 1988
  4.  
  5. ; Patches to make the WordStar Release 4 'R' command operate as a ZCPR2-type
  6. ; shell.  Several routines in WS.COM and WS.OVR must be changed.
  7. ;
  8. ; 1. WordStar must be prevented from pushing its name onto the Z-System shell
  9. ;    stack.  However, a flag that is used by the 'R' command to determine how
  10. ;    to operate must be set as if WS4 had set itself up as a shell.
  11. ;
  12. ; 2. The popping of the shell stack when WS4 terminates must be disabled.
  13. ;
  14. ; 3. The user input to the prompt from the 'R' command must be handled
  15. ;    differently.  A command to reinvoke WS4 must be appended to the user's
  16. ;    input, and then any commands pending in the multiple command line buffer
  17. ;    must be added as well.  The result is then placed into the command line
  18. ;    buffer.  If overflow occurs, the user command is ignored, and an error
  19. ;    message is displayed until a key is pressed.  The chaining command is of
  20. ;    the form ";DUU:WSNAME ,".  The comma at the end of the command tail is
  21. ;    used as a signal that WS4 was invoked as a ZCPR2 shell.
  22. ;
  23. ; 4. An optional patch can be included to defeat the use of the path for
  24. ;    searching for the overlay files.  An internal path can be specified.
  25.  
  26. ;------------------------------------------------------------
  27.  
  28. no    equ    0
  29. yes    equ    not no
  30.  
  31. intpath    equ    yes        ; Use internal path to find OVR files?
  32.  
  33. morpat    equ    045bh        ; Patch area
  34. namebuf    equ    morpat+128-16    ; Keep program ";DUU:PROGNAME ,<0>"
  35.                 ; ..at end of patch area
  36. envoff    equ    0aa4h        ; WordStar ENV offset routine
  37. zflag    equ    2200h        ; Z-System running flag
  38. rcmdbuf    equ    1f38h        ; Buffer for 'R' command input
  39. rcmd    equ    rcmdbuf+1    ; Beginning of user's command line
  40. clrscr    equ    0386h        ; Clear screen character sequence
  41. scrnfn    equ    17c7h        ; Routine to perform screen functions
  42. conout    equ    0280h        ; Routine to output character in A to console
  43.  
  44. bell    equ    07        ; Bell character
  45.  
  46. ;----------------------------------------------------------------------
  47. ;
  48. ;            PATCHES TO WS.OVR
  49. ;
  50. ;----------------------------------------------------------------------
  51.  
  52. ; Modifications to the code that pushes WordStar onto the shell stack.
  53.  
  54. ; This patch prevents the WordStar shell entry from being set up, but it
  55. ; sets the flag in 2200h that makes WordStar think that it has set it up.
  56. ; In this way, the 'R' command will work as it would with shells engaged.
  57. ; The space is used to determine the command line needed to reinvoke
  58. ; WordStar.  The ZCPR33 facility for returning the directory in which the
  59. ; program was located is used to provide an explicit DU: prefix.  The
  60. ; resulting command line is kept at the end of the user patch area.
  61.  
  62. offset    defl    2380h        ; Real address = address in overlay + offset
  63.  
  64.     org    3cbfh        ; Place to install patch
  65.  
  66.     ld    e,24h        ; Get pointer to XFCB
  67.     call    envoff        ; HL -> XFCB
  68.  
  69.     push    hl
  70.     ld    de,0dh        ; Offset to user number where WS.COM found
  71.     add    hl,de
  72.     ld    b,(hl)        ; User number to B
  73.     inc    hl
  74.     ld    a,(hl)        ; Drive to A
  75.  
  76.     add    a,'A'-1        ; Convert drive to letter
  77.     ld    hl,namebuf    ; Point to buffer at end of patch area
  78.     ld    (hl),';'    ; Command separator
  79.     inc    hl
  80.     ld    (hl),a        ; Store drive letter
  81.     inc    hl
  82.  
  83.     ld    a,b        ; Now work on user number
  84.     ld    c,'0'-1        ; Tens value
  85. tens:
  86.     inc    c
  87.     sub    10
  88.     jr    nc,tens
  89.     add    10+'0'        ; Convert units to ASCII
  90.     ld    (hl),c        ; Stash tens digit
  91.     inc    hl
  92.     ld    (hl),a        ; Stash units digit
  93.     inc    hl
  94.  
  95.     ld    (hl),':'    ; Insert colon
  96.     inc    hl
  97.  
  98.     pop    de        ; Get pointer to XFCB again
  99.     ld    b,8        ; Maximum of 8 letters
  100. copyname:
  101.     inc    de        ; Advance to next letter
  102.     ld    a,(de)
  103.     cp    ' '
  104.     jr    z,copydone    ; Quit at first space
  105.     ld    (hl),a
  106.     inc    hl
  107.     dec    b
  108.     jr    nz,copyname    ; Quit after eight characters
  109. copydone:
  110.     ld    (hl),' '    ; Put shell signal tail (a comma)
  111.     inc    hl
  112.     ld    (hl),','
  113.     inc    hl
  114.     ld    (hl),0        ; Put in terminating null
  115.  
  116.     ld    a,0ffh        ; Fool WS into thinking shell installed
  117.     ld    (zflag),a
  118.     jp    60aah
  119.  
  120. end1pat:
  121. endaddr    defl    60aah - offset
  122. free    defl    endaddr - end1pat
  123.      if    $ gt endaddr
  124.     ERROR: Patch to shell installation at 3CBFh is too long
  125.      endif
  126.  
  127. ;------------------------------------------------------------
  128.  
  129. ; This patch takes the user's response to the 'R' command, adds the command
  130. ; to reinvoke WordStar, and appends any pending commands in the command line
  131. ; buffer.  The result is written out to the command line buffer.  This
  132. ; implements a ZCPR2-style shell for the 'R' command.
  133.  
  134. ; If the resulting command line is too long for the MCL, an error message is
  135. ; displayed until a key is pressed, and then WS resumes as if no command line
  136. ; had been entered.
  137.  
  138. ; The first part of this patch replaces code in WS.OVR.  There is not enough
  139. ; space there for all the code, so it continues in the user patch area.
  140.  
  141. offset    defl    -1e00h        ; Real address = address in overlay - offset
  142.  
  143. scratch    equ    0a000h        ; Area to use as scratch buffer
  144.  
  145.     org    67b2h        ; Address in WS.OVR
  146.  
  147.     ld    hl,rcmdbuf    ; Point to 'R' command buffer
  148.     ld    c,(hl)        ; Get length into BC
  149.     ld    b,0
  150.     inc    hl        ; Point to user's command
  151.     ld    de,scratch    ; Scratch buffer in RAM
  152.     ldir            ; Copy user's command to buffer
  153.  
  154.     ld    hl,namebuf    ; Point to WS4 reinvocation command line
  155.     call    cpy2nul        ; Copy through ending null
  156.     jp    morpat        ; Continue in patch area
  157.  
  158. end2pat:
  159. free    defl    67cbh - end2pat
  160.      if    $ gt 67cbh
  161.     ERROR: Patch to command-line code at 67B2h is too long
  162.      endif
  163.  
  164. ;----------------------------------------------------------------------
  165. ;
  166. ;            PATCHES TO WS.COM
  167. ;
  168. ;----------------------------------------------------------------------
  169.  
  170.  
  171. ; This is the continuation of the patch in WS.OVR that inserts the user's
  172. ; command line, together with the WS reinvocation command, into the multiple
  173. ; command buffer.
  174.  
  175.     org    morpat
  176.  
  177.     push    de        ; Save pointer to buffer
  178.     ld    e,18h        ; Get pending commands from MCL
  179.     call    envoff
  180.     ld    e,(hl)        ; Get pointer to next command into DE
  181.     inc    hl
  182.     ld    d,(hl)
  183.     ex    de,hl        ; Switch into HL as source for copy
  184.     pop    de        ; Destination pointer into buffer
  185.     call    cpy2nul        ; Copy through ending null
  186.  
  187.     ld    hl,clrscr    ; Clear the screen
  188.     call    scrnfn
  189.  
  190.     ld    e,18h        ; Get MCL pointer
  191.     call    envoff        ; HL -> MCL buffer, A = max characters
  192.  
  193.     ; Check length of new command
  194.  
  195.     ld    de,scratch    ; Point to new command line
  196.     ld    b,a        ; Max length in B
  197. lenloop:
  198.     ld    a,(de)
  199.     or    a
  200.     jr    z,oklength
  201.     inc    de
  202.     djnz    lenloop
  203.  
  204.     ld    de,errmsg    ; Display error message
  205.     ld    c,9
  206.     call    0005h
  207.     call    sak        ; Wait for key to be pressed
  208.     jp    7f4eh        ; Pretend no user input
  209.  
  210. oklength:
  211.     ld    de,4        ; Offset to command line in buffer
  212.     ex    de,hl        ; Reverse pointers
  213.     add    hl,de
  214.     ex    de,hl        ; HL = MCL, DE = MCL+4
  215.     ld    (hl),e        ; Set up pointer in MCL
  216.     inc    hl
  217.     ld    (hl),d
  218.     ld    hl,scratch    ; Source for command line
  219.     call    cpy2nul        ; Copy it in
  220.  
  221.     jp    13f6h        ; Chain to command line from WS
  222.  
  223. errmsg:
  224.     db    bell,'MCL Ovfl - press any key...$'
  225.  
  226. end3pat:
  227. free    defl    namebuf - end3pat
  228.      if    $ gt namebuf
  229.     ERROR: Patch in MORPAT is too long
  230.      endif
  231.  
  232. ;------------------------------------------------------------
  233.  
  234. ; This optional patch causes WS4 to use an internal path to locate
  235. ; its overlay files.
  236.  
  237.      if    intpath
  238.  
  239.     org    0f5fh        ; This is where z3 path location is determined
  240.  
  241.     call    setpath        ; Call alternative routine
  242.     nop            ; Must fill 5 bytes
  243.     nop
  244.  
  245.      endif    ;intpath
  246.  
  247. ;------------------------------------------------------------
  248.  
  249.  
  250. ; Modification to the termination routine that pops the shell stack.
  251.  
  252. ; This patch eliminates the popping of the shell stack on exit from
  253. ; WordStar.  The space from the end of this patch to 13f6h is available
  254. ; for other uses (40 bytes).
  255.  
  256.     org    13ceh
  257.  
  258.     jp    13f6h        ; Exit routine
  259.  
  260.  
  261. ; This routine copies the string pointed to by HL to the address pointed to by
  262. ; DE until a null byte is encountered.  The null byte is copied as well.
  263.  
  264. cpy2nul:
  265.     ld    a,(hl)        ; Get source character
  266.     ld    (de),a        ; Put into destination
  267.     or    a        ; Check for null
  268.     ret    z        ; If so, quit
  269.     inc    hl        ; Bump up pointers
  270.     inc    de
  271.     jr    cpy2nul
  272.  
  273.     
  274. ; Alternative internal path routine
  275.  
  276.      if    intpath
  277.  
  278. setpath:
  279.     ld    hl,path0    ; Point to internal path size
  280.     ld    a,(hl)
  281.     inc    hl        ; Point to actual path
  282.     or    a        ; Set flags
  283.     ret
  284.  
  285. path0:    db    2        ; Allow up to two elements
  286.     db    2        ; Drive (A=1)
  287.     db    4        ; User
  288.     db    0,0        ; Space for another entry
  289.     db    0        ; Terminating null
  290.  
  291.      endif    ;intpath
  292.  
  293. end4pat:
  294. free    defl    13f6h - end4pat
  295.      if    $ gt 13f6h
  296.     ERROR: Patch in shell popping code at 13CEh is too long
  297.      endif
  298.  
  299. ;------------------------------------------------------------
  300.  
  301. ; Modification to initialization code where WS4 determines if it was
  302. ; invoked as a shell.  We have defined a convention where a comma on
  303. ; the end of the command line signals WS4 to display its shell-wait
  304. ; message and wait for the user to press a key.
  305.  
  306.     org    1a2fh
  307.  
  308.     ld    hl,80h        ; Point to command tail
  309.     ld    l,(hl)        ; Get length into L
  310.     set    7,l        ; In effect, add 80h
  311.     ld    a,(hl)        ; Get last character
  312.     cp    ','        ; See if it is a comma
  313.     jr    nz,1a5fh    ; Not a 'shell', so go on ahead
  314.  
  315.     ld    (hl),' '    ; Get rid of the comma
  316.  
  317.     ld    de,1b10h    ; Display 'shell wait' message
  318.     ld    c,9        ; (note: message is trashed by other code and
  319.     call    0005        ; ..cannot be called from elsewhere)
  320.     call    sak        ; Wait for key to be pressed
  321.  
  322.     jr    1a5fh        ; Proceed normally
  323.  
  324. sak:
  325.     ld    e,0ffh        ; Poll console input status
  326.     ld    c,6
  327.     call    0005
  328.     or    a
  329.     jr    z,sak        ; ..until a key is pressed
  330.  
  331.     ld    e,0dh        ; Echo carriage return
  332.     ld    c,6
  333.     jp    0005
  334.  
  335. end5pat:
  336. free    defl    1a5fh - end5pat
  337.      if    $ gt 1a5fh
  338.     ERROR: Patch to initialization code at 1A2Fh is too long
  339.      endif
  340.  
  341.  
  342.     end
  343.