home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / tcj / tcj35.ws < prev    next >
Encoding:
Text File  |  1994-09-02  |  28.1 KB  |  517 lines

  1.      My column about shells and WordStar Release 4 (WS4) in TCJ issue #33ì
  2. prompted more than the usual level of commentary.  There were extensiveì
  3. discussions on Z-Node-Central and the Lillipute Z-Node (the official TCJì
  4. bulletin board), and several messages reached me over the ARPA network.  Notì
  5. all of the comments were favorable, but I was nevertheless happy to receiveì
  6. them.  They helped further clarify my thinking on the very important subjectì
  7. of shells and have spurred me on to prove my points by actually convertingì
  8. WS4 to a ZCPR2-style shell!  After a bit of follow-up discussion, I willì
  9. describe how this conversion was accomplished.
  10.  
  11.  
  12.                                 Corrections
  13.  
  14.      There were some things I said in the previous column that wereì
  15. factually wrong, and before I do anything else I wish to correct them.
  16.  
  17.      First, I stated that the Z-System code in WS4 was written by someoneì
  18. other than MicroPro.  I was wrong.  David McCord, who was vice president atì
  19. Echelon at the time WS4 was developed, sent me a message with the facts ofì
  20. this matter.  Echelon, through staff like David and through publishedì
  21. materials, educated Peter Mireau of MicroPro on the facilities andì
  22. philosophy of Z-System.  Peter did all the actual programming, so the codingì
  23. mistakes were his fault, not Echelon's or David's.
  24.  
  25.      From a broader perspective, however, as I stated in the previousì
  26. column, the real culprit was inadequate testing.  Bugs in the code wouldì
  27. have been discovered and conceptual issues clarified had more people in theì
  28. Z community been involved as beta testers.  There are so many differentì
  29. styles of using Z-System that it takes a number of testers to uncoverì
  30. problems.  Within days after copies of WS4 were delivered to users of my Z¡
  31. Node, I started getting questions about strange behavior exhibited by WS4,ì
  32. behavior that turned out to result from its operation as a shell.
  33.  
  34.      A second mistake in the earlier column was my implication that WS4 doesì
  35. not get its own name from the ZCPR3 external file control block (XFCB).  Iì
  36. no longer remember what made me think that this was the case, but Davidì
  37. McCord assured me (and I have now verified for myself) that WS4 does,ì
  38. indeed, get its name from the XFCB when it sets up the shell stack entry.
  39.  
  40.      Finally, one reader reported to me that my WSSHLOFF routine (the oneì
  41. that completely disables shells while WS4 is running and reenables them whenì
  42. WS4 terminated) crashed his system.  Unfortunately, a large number ofì
  43. misprints crept into the listings in going from my disk file to the printedì
  44. pages.  Most of the typos were obvious, but one was compounded by a doubleì
  45. error.  In the WSSHLOFF listing, the value for EXITSUB was printed as 03BVh. ì
  46. The 'V' was obviously a mistake, and clever readers looked at the similarì
  47. listing for WSSHLFIX, where the value was given as 03B3h.  This,ì
  48. regrettably, looks correct but was also a typo.  The proper value is 03BEh. ì
  49. We hope that Art Carlson will make sure that the listings in this column areì
  50. transcribed accurately (so that all the mistakes will be mine!).
  51.  
  52.  
  53.                              More WS4 Comments
  54.  
  55.      While on the subject of WS4, I would like to add a few further commentsìèabout how it works.  Not surprisingly (considering when it was developed),ì
  56. in creating its shell stack entry WS4 does not make use of the facilityì
  57. introduced with ZCPR version 3.3 that allows a program to determine from theì
  58. XFCB not only its name but also the directory from which it was actuallyì
  59. loaded (the user number is at offset 13 and the drive, with A=1, at offsetì
  60. 14).
  61.  
  62.      As a result, in order for WS4 to be reinvoked as a shell, the commandì
  63. search path must include the directory in which WS4 is located.  I mentionì
  64. this here as a reminder and suggestion to authors of new or updated shellsì
  65. and error handlers that they use this Z33 facility to avoid the requirementì
  66. that the program be on the path and to speed up loading of the program (byì
  67. eliminating any search for it).  My WordStar conversion described later addsì
  68. this feature.
  69.  
  70.      With WS4 it is generally necessary that the command search path includeì
  71. WS4's directory for an additional reason.  I learned the hard way that whenì
  72. WS4 runs under Z-System, it pays no attention to the drive and user numberì
  73. that WSCHANGE specified as the location for the overlay files; it only usesì
  74. the search path to try to locate them.
  75.  
  76.      This is a problem for me because, as I have explained at length inì
  77. previous columns, I put only my small RAM disk on the path and use ARUNZì
  78. aliases to invoke all programs except the very few that fit on the RAM disk. ì
  79. With this approach, there is no way to get WS4 to find its overlay files. ì
  80. The conversion addresses this problem also.
  81.  
  82.  
  83.                            ZCPR2 vs. ZCPR3 Shells
  84.  
  85.      I would not like to take up again one of the subjects raised in issueì
  86. #33: ZCPR2-style versus ZCPR3-style shells.
  87.  
  88.      First an aside.  Shells seem to be a surprisingly emotional issue.  Iì
  89. thought my earlier column presented a fairly carefully and calmly reasonedì
  90. discussion of some aspects of shells, including their pros and their cons. ì
  91. Some readers, however, took great offense at my even questioning the currentì
  92. method of implementing shells or of what some people are trying to do withì
  93. them.
  94.  
  95.      One reader went so far as to suggest that I had no business commentingì
  96. on the subject when, by my own admission, there are a number of shells thatì
  97. I have never used.  Besides the fact that this is hardly a reasonedì
  98. argument, I would like to make sure that the following facts about shellsì
  99. are fully appreciated.
  100.  
  101.      ZCPR3-style shells are a facility of the command processor.  Withoutì
  102. special code in the CPR, there would be no such shells.  As the author ofì
  103. the two latest versions of the ZCPR command processor, I think I can speakì
  104. with some authority (though certainly not with infallibility) on theì
  105. subject, since in writing that code I had to consider the issue of shellsì
  106. rather carefully from a rigorous theoretical viewpoint.
  107.  
  108.      ZCPR2-style shells, quite the contrary, are not a facility of theì
  109. command processor; they are a facility of the individual shell programs. ìèTheir functioning depends only on the operation of the multiple command lineì
  110. facility.  The command processor does not treat a Z2 shell command anyì
  111. differently than it treats any other command.  This is really the key to theì
  112. difference between the two shell implementations.
  113.  
  114.      In the previous column I stated: "...I am coming to the conclusion thatì
  115. only programs like history shells...should be implemented as ZCPR3-styleì
  116. shells.  Other programs, like ZFILER and WordStar should use the ZCPR2ì
  117. style."  I then invited readers to enlighten me if I was missing someì
  118. important point.  I got some responses to this invitation, but no one yetì
  119. has offered me any evidence that I had missed any important point.
  120.  
  121.      One reader reiterated essentially the same difference between Z2 and Z3ì
  122. shells that I attempted to demonstrate with my example in which WordStar wasì
  123. invoked in a multiple command line.  Apparently the point bears repeating.
  124.  
  125.      This reader presented the point using a command line like theì
  126. following:
  127.  
  128.         ZFILER;ECHO TESTING
  129.  
  130. Under ZCPR2, ZFILER would run and present its file display to the user.  Ifì
  131. the user generated a command line "CMDLINE" as the result of a macro or inì
  132. response to the prompt after the 'Z' command, a Z2-shell version of ZFILERì
  133. would build the command sequence "CMDLINE;ZFILER" and insert it into theì
  134. multiple command line buffer just before the next command to be executed. ì
  135. This would give:
  136.  
  137.         CMDLINE;ZFILER;ECHO TESTING
  138.  
  139. The user's command line would run, and then ZFILER would be invoked again. ì
  140. Only on termination of ZFILER would the last command, "ECHO TESTING", beì
  141. performed.
  142.  
  143.      A Z3 shell would respond to the same command line from the user inì
  144. quite a different way.  As before, ZFILER would be invoked first.  It wouldì
  145. determine from the Z3 message buffer that it had been invoked manually andì
  146. would respond by pushing its own name onto the shell stack.  Then it wouldì
  147. terminate.  The command processor would then proceed to run "ECHO TESTING". ì
  148. Only after that, once the command line was empty, would ZFILER be reloaded,ì
  149. this time as a shell.  Recognizing its shell status, it would now displayì
  150. its screen of file names and do its real work.
  151.  
  152.      The reader who submitted this example, if I understood him correctly,ì
  153. viewed the Z3 behavior as correct and the Z2 behavior as wrong.  If you areì
  154. an experienced Z-System user, you will probably recognize in this reader aì
  155. fellow expert (and, indeed, he is).  He is so used to ZCPR3 that he noì
  156. longer notices that it is the behavior of the Z3 shell that is trulyì
  157. bizarre!
  158.  
  159.      Consider the following two command lines:
  160.  
  161.     (1) ZFILER;ECHO TESTING
  162.     (2) ECHO TESTING;ZFILER
  163.  
  164. èWe have already analyzed the first one; the second one can safely be left asì
  165. an exercise for the reader.  We will simply state the answer that underì
  166. ZCPR3 they will accomplish exactly the same thing!  This is hardly a resultì
  167. that conforms to intuition, and I still remember in my early days as a Z¡
  168. Node sysop trying to explain to quite a few users why the second command onì
  169. a VFILER command line executes first!
  170.  
  171.      Under ZCPR2 the result is just what one would expect.  In the firstì
  172. case, ZFILER runs first, and ECHO runs only after the user terminates ZFILERì
  173. using its 'X' command.  In the second case, ECHO runs first and ZFILERì
  174. second.  In other words, with Z2 shells, commands are executed in the orderì
  175. they are entered, a notion that does not require long experience and greatì
  176. expertise to understand and get used to!  And it gives the user a greaterì
  177. measure of control.
  178.  
  179.  
  180.                            Mixed Z2 and Z3 Shells
  181.  
  182.      The same reader submitted another interesting example that illustratesì
  183. the confusing behavior that can arise when Z2 and Z3 shells are mixed.  Hereì
  184. we assume that WordStar has been implemented as a Z2 shell and ZFILER as aì
  185. Z3 shell.  Suppose we use the 'R' command of WordStar to enter the commandì
  186. "ZFILER".  WS4, as a Z2 shell, would generate the command line
  187.  
  188.         ZFILER;WS
  189.  
  190. ZFILER, as a Z3 shell, would install itself on the shell stack and proceedì
  191. to execute "WS".  ZFILER would not run in its file maintenance mode untilì
  192. after we terminated WordStar.
  193.  
  194.      This is, admittedly, probably not what one intended, since we mostì
  195. likely entered the ZFILER command with the intention of doing some fileì
  196. maintenance before returning to WordStar.  On the other hand, it isì
  197. certainly no more bizarre than what we saw in our earlier example.
  198.  
  199.      If both WS4 and ZFILER were Z3 shells, then the invocation of ZFILERì
  200. from the WS4 'R' command would cause it to become the active shell (the oneì
  201. on the top of the shell stack).  The WS4 shell would be pushed down in theì
  202. shell stack, and ZFILER would take control.  With a little thought, however,ì
  203. you will see that the same is also true if both ZFILER and WS4 are Z2ì
  204. shells!
  205.  
  206.      The strange behavior with the mixed shells in the above example arisesì
  207. in part because ZFILER was not really being used as a shell in the Z3 sense,ì
  208. namely, as a replacement for the command processor's command-line inputì
  209. routine.  It was intended as a file maintenance utility.
  210.  
  211.      Suppose we had entered the command "EASE" (the Z3-type history shell)ì
  212. instead of "ZFILER" from our Z2 version of WordStar.  This would establishì
  213. EASE as the current shell and return to WordStar.  That behavior would notì
  214. seem strange, because in this case we would be thinking of our EASE commandì
  215. as establishing the shell to be used in place of the command processor theì
  216. next time the command processor needed a new command line.  So long asì
  217. WordStar is running, there is no need for EASE to do anything.  We expect itì
  218. to take effect only after we are finished using WordStar.
  219. è
  220.  
  221.                    Nested Z2 Shells and Recursive Aliases
  222.  
  223.      Although I had once thought that the Z3 shell stack was required inì
  224. order to nest shells, I showed in the earlier column that this is not theì
  225. case. Z2-style shells can, in fact, be nested more flexibly.  There is noì
  226. predetermined limit to the nesting depth or to the amount of informationì
  227. that can be passed with each shell command line.  The only limit is imposedì
  228. by the length of the multiple command line buffer, just as with the nestingì
  229. of aliases.
  230.  
  231.      With the standard shell stack configuration of 4 32-byte entries, if aì
  232. shell command uses only 16 bytes, 16 bytes are wasted.  On the other hand,ì
  233. if a shell command needs 48 bytes to hold its information, it cannot run atì
  234. all under this configuration (NZ-COM can come to the rescue by allowing theì
  235. shell stack configuration to be changed on the fly).  With Z2 shells, theseì
  236. problems go away.  In 64 bytes of command line, one can have two 32-byteì
  237. shell commands or a combination of one 16-byte shell command and one 48-byteì
  238. shell command (or five 12-byte shell commands).
  239.  
  240.      I did overlook one point when I described putting data for the shellsì
  241. on the command line.  In the Z3 shell stack, one can include, after theì
  242. shell command's terminating null, any binary data that one wishes.  Thus 256ì
  243. values are possible for each extra byte in the shell stack entry.
  244.  
  245.      In order to carry shell data on the command line, several additionalì
  246. constraints apply.  First, the command processor strips the high bits offì
  247. all characters in the command line, so only 128 values are available toì
  248. start with.  Secondly, the null character cannot be used because the commandì
  249. processor would interpret this as the end of the command line (that leavesì
  250. 127 values).  Finally, letters are converted to upper case, thereby makingì
  251. the characters from 'a' to 'z' inaccessible (scratch another 26).  Thisì
  252. leaves only 101 possible values out of the original 256.  Moreover, extraì
  253. characters are required as flags to signal the program to consider itself asì
  254. having been invoked as a shell (a service provided in ZCPR3 by a flag in theì
  255. message buffer).  All of these things reduce the efficiency with which theì
  256. space in the command line buffer can be used compared to the space in theì
  257. shell stack.
  258.  
  259.      One reader pointed out that recursive aliases cannot be used withì
  260. Z2-type shells.  This is true...but only if one is using the pseudo¡
  261. recursive alias that I invented.  This kind of alias accomplishes a crudeì
  262. approximation to recursion by discarding any pending commands in the commandì
  263. line buffer.  This will, indeed, discard any shell reinvocation commands. ì
  264. However, if one uses the logically sound and rigorous recursive aliasì
  265. technique invented by Dreas Nielsen (see my column in issue #28), there isì
  266. no problem.  It sometimes pays to do things right!
  267.  
  268.      In fact, it seems to me that the Z2 shell is, in essence, a recursiveì
  269. alias, a program that keeps invoking itself.  And this is just what most (ifì
  270. not all) Z3 shells actually do.  I am still awaiting an example of somethingì
  271. (good) that a Z3 shell can do that cannot be done in some equivalent wayì
  272. with a Z2 shell or recursive alias.
  273.  
  274. è
  275.                         The Real Difference Between
  276.                               Z2 and Z3 Shells
  277.  
  278.      After much reflection, I think I have finally put my finger on theì
  279. fundamental distinction between Z2 and Z3 shells.  It derives from the factsì
  280. I alluded to earlier: that the Z3 shell is a true creature of the commandì
  281. processor and the Z2 shell is not.
  282.  
  283.      Here is an example that will illustrate the point.  Suppose the historyì
  284. shell EASE were implemented as a Z2-style shell and that while it isì
  285. running, we issue the command "DIR".  EASE will insert into the command lineì
  286. a sequence like the following:
  287.  
  288.         DIR;EASE
  289.  
  290. DIR will run, and then EASE will be reinvoked.  Looks fine!  But now supposeì
  291. the user enters the command "IF EXIST FN.FT".  EASE will then generate theì
  292. command line
  293.  
  294.         IF EXIST FN.FT;EASE
  295.  
  296. If the file FN.FT exists, this will again work just fine, but suppose theì
  297. file does not exist.  Then the system will enter a false flow state, and theì
  298. EASE command (and perhaps other commands pending in the command line afterì
  299. it) will be flushed by the command processor.  The shell function will beì
  300. lost, and any other pending commands will be processed in an unintended way.
  301.  
  302.      For a Z2 shell to function properly in general, all command linesì
  303. inserted by it must result in the same flow state at the end of the commandì
  304. line as at the beginning.  With a MENU shell it could be possible for theì
  305. system designer to guarantee this, since he can control which commands areì
  306. generated by the shell.  With a history type shell it would be nearlyì
  307. impossible to ensure that this condition would always be met.
  308.  
  309.      The critical feature of shell processing under ZCPR3 is that flowì
  310. processing is suspended during the operation of shells.  This allows them toì
  311. run, as they must, even after the user has passed a command that leaves theì
  312. system in a false flow state.  The ZCPR33 Users Guide goes into some detailì
  313. on this matter, and had I remembered better what I wrote there, it would notì
  314. have taken me this long to come to the essence of the Z2-vs.-Z3 shell issue.
  315.  
  316.      Some users of ZCPR33 have modified the way the command processor dealsì
  317. with flow control in shell processing.  No one has yet convinced me of theì
  318. value of this (the risks are undeniable).  It still seems to me that Z2-typeì
  319. shells and recursive aliases can accomplish the same thing, but in aì
  320. logically sound way.
  321.  
  322.      I have extended an invitation to Dreas Nielsen to write a series ofì
  323. columns for TCJ explaining his very powerful shell programs.  Since he isì
  324. also one of the people who has made this modification to the CPR, perhaps heì
  325. will also present the other side of this story and explain why it isì
  326. necessary or desirable to treat shells the way he does.
  327.  
  328.  
  329. è                        Remaking WordStar Release 4
  330.  
  331.      When I first received my copy of WordStar 4 and encountered problems ì
  332. with the way it handled shells, I fired up the DSD debugger and tried to ì
  333. figure out how to fix it.  After a considerable amount of rummaging about inì
  334. the code (and especially trying to figure out what was going on insideì
  335. WS.OVR), I gave up.  Later I tried again...and failed again.  In the courseì
  336. of preparing this column, I decided to have one more go at it, and this time ì
  337. things started to click.
  338.  
  339.      The patches I will describe here are preliminary and have not yet been ì
  340. extensively tested.  In fact, as I write this, I am the only one who hasì
  341. used them, and you know what I said above about the dangers of a testì
  342. program that does not involve a variety of Z-System users.  So, you areì
  343. hereby recruited, if you are willing, to join the test program.
  344.  
  345.      Since I may very well have made some mistakes, and since there areì
  346. further changes that people may want to make (let's hear your suggestions),ì
  347. I will not only give the results; I will describe the process by which theseì
  348. patches have been developed.
  349.  
  350.  
  351.                              Cracking the Code
  352.  
  353.      The first step toward changing the code was figuring out how the virginì
  354. WordStar was doing what it did.  In particular, I wanted to locate routinesì
  355. related to Z-System functions, so the first thing I tried was searching forì
  356. all references to address 109h, which contains the address of the Z-Systemì
  357. environment (ENV).  Any WS4 feature that made use of a Z-System facilityì
  358. would have to get information from the ENV.
  359.  
  360.      As best I recall, this did not turn up many references and did notì
  361. particularly help (though it was a good idea, and that's why I mention it). ì
  362. In the end, I just started tracing the code from the beginning, figuringì
  363. that WS4 would have to determine fairly early whether it was running underì
  364. Z-System or standard CP/M.  This turned out to be correct, and very soon Iì
  365. came to the key Z routine, at address 0AA4h in WS.COM.  This routine returnsì
  366. the address and size of a Z-System module specified by an offset passed inì
  367. the E register.
  368.  
  369.      Having discovered this routine, I used DSD to find all references to itì
  370. in WS.COM and WS.OVR.  They occur with the following values of E:
  371.  
  372.     E =  9h        the command search path (PATH)
  373.     E = 15h        the named directory register (NDR)
  374.     E = 18h        the multiple command line buffer (MCL)
  375.     E = 1Eh        the shell stack (SHL)
  376.     E = 22h        the message buffer (MSG)
  377.     E = 24h        the external file control block (XFCB)
  378.  
  379.  
  380.                          Setting up the Shell Stack
  381.  
  382.      The block of code beginning around address 3CBFh in WS.OVR makesì
  383. references to MCL, XFCB, and SHL.  I guessed correctly that this had to beìèthe code where WS4 sets up its shell stack entry.  (This block of code, byì
  384. the way, is where the shell-pushing mistake occurs for the case where theì
  385. shell stack is currently empty.)
  386.  
  387.      The patch for this part of WS.OVR (see Listing 1) modifies this code. ì
  388. First of all, since WS4 is going to operate as a Z2-type shell, we do notì
  389. want it to do anything with the shell stack.  It is easy to disable the codeì
  390. by simply skipping over it, but one has to watch out for subtleties. ì
  391. Indeed, in order for the 'R' command to use the MCL and not chain using theì
  392. greatly inferior CP/M method, WS4 has to think that the shell entry wasì
  393. established successfully.
  394.  
  395.      I noticed that a flag was being set into address 2200h, and I surmisedì
  396. that it is used by WS4 to show that it is running under Z-System.  In theì
  397. patch, I set this flag even though the shell stack entry is not being setì
  398. up.  I have not examined all references to this flag, and there is a chanceì
  399. that there are additional, more complex effects.  If any problems appearì
  400. with the patched version of WordStar, this flag might be involved.  For theì
  401. initial attempt at fixing WS4, I just took the easiest course of action, andì
  402. so far it appears to have worked.
  403.  
  404.      It seemed foolish to waste space in WS.OVR by doing nothing more thanì
  405. setting the flag and jumping to where the original code resumed (60AAh). ì
  406. Instead, I have used the space to compute the command line necessary toì
  407. reinvoke WordStar.  The code gets not only the name by which WordStar wasì
  408. invoked but also the drive and user number from which it was loaded.  Aì
  409. command line of the form ";DUU:WSNAME" is generated.
  410.  
  411.      There is one extra step in this part of the patch.  When running as aì
  412. Z3 shell, WS4 knows from the command status flag in the message buffer whenì
  413. it was invoked as a shell so it can put up the press-any-key message beforeì
  414. clearing the screen and resuming operation.  As a Z2 shell, WS4 cannot useì
  415. this facility.  Instead, a signal has to be included in the command tail. ì
  416. For reasons that I will not go into in full detail, I chose for this signalì
  417. a comma at the very end of the tail.  Very briefly, the comma is a handyì
  418. character because it is not parsed into the default file control blocks,ì
  419. where a program could confuse it with a file name.
  420.  
  421.      The final reinvocation command line, with its terminating null, takesì
  422. the form
  423.  
  424.         ;DUU:WSNAME ,<0>
  425.  
  426. Since I could not be sure that this section of overlay code would persist inì
  427. memory until the command would be used, I store it at the top of the WS4'sì
  428. user patch area (MORPAT).
  429.  
  430.  
  431.                  The Initialization and Termination Patches
  432.  
  433.      Having made the above modification, we must make two others in order toì
  434. remain consistent.  First, we must modify the WS4 initialization code inì
  435. which it determines whether or not it was invoked as a shell.  This is theì
  436. patch at address 1A2Fh in WS.COM.  The patch calculates the address of theì
  437. last character passed in the command tail and checks to see if it was aìècomma.  If not, it proceeds with normal operation of the program.
  438.  
  439.      If there is a comma, the shell-wait message must be displayed until theì
  440. user presses a key.  But one must also remove the comma from the commandì
  441. tail to ensure that WordStar not think it has been passed a file name.  Atì
  442. present I do this by replacing the comma with a space.  This is notì
  443. rigorous, but it seems to work, since WS4 is apparently not confused by aì
  444. tail consisting only of spaces (unfortunately, a number of programs are).
  445.  
  446.      Since WS4 no longer pushes its name onto the shell stack, we must alsoì
  447. prevent it from popping the shell stack when it terminates.  This is theì
  448. patch at address 13CEh in WS.COM.  This is the easiest patch of all, sinceì
  449. we simply have to skip some code.  As an additional benefit, this frees upì
  450. about 40 bytes of space that we use for some of our other patch code.
  451.  
  452.  
  453.                            Fixing the 'R' Command
  454.  
  455.      Now we come to the main item in this set of patches -- the code thatì
  456. makes the 'R' command work as a ZCPR2-type shell.  The new code here is muchì
  457. more complex than what it replaces, and we can only fit part of it at theì
  458. original location 67B2h in WS.OVR.  We put what we can there and continueì
  459. with the rest in the MORPAT area in WS.COM.
  460.  
  461.      The basic strategy is to take the command line entered by the user inì
  462. response to the 'R' command prompt, append the WS reinvocation commandì
  463. (including its semicolon separator), and append any remaining command lineì
  464. pending in the multiple command line buffer (if there is one, it will beginì
  465. with a semicolon also).  If there is enough room for the result in the MCL,ì
  466. then it is moved there and chained to.  If not, a warning message isì
  467. displayed on the screen until a key is pressed, and the user command isì
  468. ignored.
  469.  
  470.      To implement this strategy, I chose the simplest method I could thinkì
  471. of.  Since the 'R' command operates from the WordStar no-file menu, theì
  472. entire WS edit buffer is available as a scratch area.  I picked an arbitraryì
  473. address of A000h for a buffer in which to build the new command line. ì
  474. Again, rigorous code calculate the address.  My code is a quick-and-dirtyì
  475. solution.
  476.  
  477.  
  478.                          Finding the Overlay Files
  479.  
  480.      As I noted earlier, with my style of operation, WS4 had trouble findingì
  481. its overlays.  To solve that problem, the patch includes an optional sectionì
  482. to install an internal search path for the overlay files.  This patch isì
  483. installed at address 0F5Fh in WS.COM, where it replaces a call for theì
  484. location of the Z-System path with a call to a routine that returns theì
  485. address and size of an internal path.  In Listing 1 the internal path hasì
  486. the single element B4:, the directory in which I keep my WordStar programì
  487. files.  You can put any values you want here.
  488.  
  489.  
  490.                            Installing the Patches
  491.  
  492. è     It is not possible to install the patches in WS.OVR using MLOAD or aì
  493. debugger, because the OVR file is too large to load entirely into memory. ì
  494. ZPATCH, on the other hand, can handle the job splendidly.  ZPATCH assumes anì
  495. offset of 0000 for a file of type OVR, while the addresses in the listingì
  496. are those shown when the file (as much as can fit) is read into memory underì
  497. a debugger.  To make things consistent, you should use the ZPATCH 'O'ì
  498. command to set the offset to 100.  
  499.  
  500.      Key in the new data carefully, checking from time to time that theì
  501. address is still correct.  Also, be careful not to go beyond a recordì
  502. boundary while in ZPATCH.  It wraps from the end of the record back to theì
  503. beginning of that record without warning (this really gave me grief until Iì
  504. caught on to the problem).  When you get to the end of the current record,ì
  505. write it out (^W), advance to the next record (>), and reenter edit modeì
  506. (E).  Then you can resume entering data.
  507.  
  508.      The attached listing was made with a specially configured version ofì
  509. the SLR Z80ASM assembler.  Normally, I have it display addresses in logicalì
  510. order for easier interpretation.  For hand keying of a patch, however, it isì
  511. far more convenient to have the bytes of a word in physical order.  Justì
  512. watch out when reading the displayed symbol values.  They, too, are storedì
  513. in byte-reversed format.
  514.  
  515.      It is possible to use MLOAD to install just the patches for WS.COM. ì
  516. Simply delete the parts of WSPAT.Z80 that refer to patches in WS.OVR andì
  517. assemble the remaining code to a HEX file.
  518.  
  519.      Enjoy playing with (and using) this different (improved) version ofì
  520. WordStar 4, and let me know what you think and what further suggestions youì
  521. have.
  522.