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