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 / TCJ32.WS < prev    next >
Text File  |  2000-06-30  |  46KB  |  885 lines

  1.                                Z-System Corne≥ (c)
  2.                                  by Jay Sage
  3.                         The Computer Journal, Issue 32
  4.                           Reproduced with permission
  5.                            of author and publisher
  6.  
  7.      As usual, I find myself with the deadline for this TCJ column fastì
  8. approaching, wondering how two months have passed so quickly.  And, asì
  9. usual, I have far more material that I would like to talk about than I willì
  10. have time to put down on paper (or, should I say, disk).  This column isì
  11. probably going to be shorter than average, just as the previous one was muchì
  12. longer, and some of the promised discussions will be deferred still further. ì
  13. Given the reasons, you will be understanding I hope: Joe Wright and I are inì
  14. the process of putting the final touches on the new releases of ZCOM andì
  15. ZCPR34!  By the time you read this, they will definitely be available.  Evenì
  16. if you usually find my columns a bit too technical for your tastes, I hopeì
  17. you will read on as I describe these two exciting developments.
  18.  
  19.      I will not describe it here this time, but Bridger Mitchell has veryì
  20. nearly completed code similar to NZCOM that will run on CP/M-Plus systems. ì
  21. At last people with newer CP/M machines for which CP/M 2.2 is not availableì
  22. will also be able to run Z System.  And they will be able to do it whileì
  23. retaining almost all of the good features of CP/M-Plus!
  24.  
  25.  
  26.                                 The New ZCOM
  27.  
  28.      Two issues ago (TCJ #30) I described the status of the nascent NZCOM. ì
  29. Things have developed considerably since then, and I can now provide someì
  30. specific details.
  31.  
  32.      First some philosophical comments.  This may sound rather strong, butì
  33. Joe and I both firmly believe that NZCOM is one of the most exciting andì
  34. remarkable developments in the history of microcomputer operating systems. ì
  35. With all the computers we have had experience with, the operating system hasì
  36. been a static entity.  You 'boot' up the computer, and there you have theì
  37. operating system, fixed and immutable.  Few computers offer more than oneì
  38. operating system.  With those that do, the only way you can get a differentì
  39. operating system is to 'reboot', which generally involves inserting a newì
  40. boot diskette and pressing the reset button.  And never do you get to defineì
  41. the characteristics of that operating system.  You just take what theì
  42. manufacturer deigns to let you use.
  43.  
  44.      With NZCOM the operating system becomes a flexible tool just like anì
  45. application program.  You can change operating systems at any time, evenì
  46. right in the middle of a multiple command line sequence.  You can do itì
  47. manually, or alias scripts can do it automatically, in response toì
  48. conditions in the system!  And you can determine which Z System features areì
  49. supported.
  50.  
  51.      You can change the whole operating system or just a part of it.  Wouldì
  52. you like a new command processor?  No problem.  With a simple command, NZCOMìèwill load it.  No assembly or configuration required.  One file fits all! ì
  53. That new CCP will continue to run until you load another one.  Want toì
  54. experiment with a new disk operating system (we are playing with severalì
  55. exciting new ones)?  Again, no problem.  NZCOM can load them in a jiffy. ì
  56. This makes for a whole new world of flexibility and adaptability,ì
  57. experimentation and education.
  58.  
  59.      Need more memory to run a big application program?  Fine.  Just load aì
  60. small operating system while that application is running.  When it isì
  61. finished, go back to the big system with bells and whistles like namedì
  62. directories, lots of resident commands, or special input/output facilitiesì
  63. (such as keyboard redefiners or redirection of screen or printer output toì
  64. disk).
  65.  
  66.      Until you try this system, it is hard to imagine how easy it is to doì
  67. these things.  Gone are the days of taking source code (no source code isì
  68. needed), editing configuration files (you don't need an editor), assemblingì
  69. (you don't need an assembler), and patching (you don't have to know how toì
  70. use the arcane SYSGEN and DDT).  Simple REL files for a particular moduleì
  71. can be used by anyone on any system.  Of course, if you want to createì
  72. custom modules of your own special design, you can still do it, but this isì
  73. no longer required, as it used to be.  Hackers can hack, but users canì
  74. simply use!
  75.  
  76.      Joe and I are really hoping that NZCOM will open the world of Z Systemì
  77. to the general community, to those who have no interest in learning toì
  78. assemble their own operating system or do not have the tools or skills.  Ifì
  79. you have been at all intrigued by the Z System (how could you not haveì
  80. been?), now is your chance to experiment.
  81.  
  82.      Getting NZCOM running is basically a two-step process, with each stepì
  83. remarkably easy to perform.  First you define the system or systems youì
  84. want.  This is done with the program MKNZC (MaKe NZ-Com).  Then you load theì
  85. Z System you want using the program NZCOM.  The details are explained below. ì
  86. Some comments of interest to the technically inclined are enclosed inì
  87. brackets.  Feel free to skip over them.
  88.  
  89.  
  90. Defining NZCOM Systems
  91.  
  92.      Here is how a person with a stock CP/M computer would go about gettingì
  93. NZCOM going.  [First technical aside: Ironically, those of us who, withì
  94. great skill and hard work, created manually installed Z Systems have a muchì
  95. harder job ahead of us.  To use NZCOM effectively, we must first strip outì
  96. all the ZCPR3 code in our fancy BIOSs and get back to a lean, Z-less system. ì
  97. I just spent the good part of an evening doing that for my BigBoard Iì
  98. computer (though, to be fair to my programming expertise, I should add thatì
  99. the hardest part was finding where I had stashed the BIOS source code).] ì
  100. For the discussion that follows, we will assume that the files in the NZCOMì
  101. package have been copied onto a working disk in drive A.
  102.  
  103.      As we said earlier, the first step is to use MKNZC, an easy menu-drivenìèprogram, to specify the characteristics of our Z Systems.  Its output is aì
  104. descriptor file that is used later to load the system.  What if you don'tì
  105. know enough yet about the Z System to make those choices?  Again, noì
  106. problem.  There is a standard (or, in computer language, 'default') systemì
  107. defined for you already, and we will start by making it.  We do that byì
  108. entering the command line
  109.  
  110.     A>mknzc nzcom
  111.  
  112. This will bring up a menu screen like the one shown in Fig. 1.  The onlyì
  113. difference on your system will be in the actual addresses for the modules,ì
  114. since they vary from computer to computer.  Press the 'S' key to save theì
  115. configuration.  MKNZC displays a message to the effect that it is writingì
  116. out the file NZCOM.NZC.
  117.  
  118.      [Technical aside: Files of type NZC are NZCOM descriptor files.  Theyì
  119. are simple text files, as shown in Fig. 2.  For those of you who write yourì
  120. own assembly language programs, you may notice a strong similarity to theì
  121. symbol or SYM file produced by an assembler or linker (yep, identical).  Theì
  122. symbols in this file define all the necessary parameters of the system to beì
  123. created.]
  124.  
  125.      From the values in Fig. 1, you can see that the default Z System offersì
  126. every feature available.  When this system is running later, the TPAì
  127. (transient program area, the memory available for the application programsì
  128. that do your real work) will be 49.0k bytes.  This value, of course, is forì
  129. my computer; as they say, "yours may vary."  A 'k' or kilobyte is actuallyì
  130. 1024 bytes, so this is really 50,176 bytes or characters.  The original CP/Mì
  131. system, by the way, had a TPA of 54.25k bytes, so we are paying a cost ofì
  132. 5.25k bytes for this spare-no-expense Z System.  As luxurious and opulent asì
  133. this system is, it still leaves plenty of TPA for most application programs.
  134.  
  135.      Sometimes, however, we have an application program that is reallyì
  136. hungry for memory.  Database managers, spread sheets, and C compilers oftenì
  137. fall into this category.  So does the new WordStar Release 4.  We will nowì
  138. use MKNZC to define a minimum Z System for when we run those applications. ì
  139. To give this version the name MINIMUM, enter the command
  140.  
  141.     A>mknzc minimum
  142.  
  143. When the menu comes up, press key '4'.  You will be asked to define theì
  144. number of records (128-byte blocks) to allocate to the input/output packageì
  145. or IOP.  Enter '0' and press return.  Similarly reduce to zero theì
  146. allocations for the resident command package (RCP), flow command packageì
  147. (FCP), and named directories register (NDR).  You will be left with theì
  148. screen shown in Fig. 3.  Press the 'S' key to save the definition of thisì
  149. minimal Z System in the descriptor file MINIMUM.NZC [shown in Fig. 4 for theì
  150. technically inclined].
  151.  
  152.      Notice that the TPA has grown to 53.25k, only 1k less than the originalì
  153. miserable CP/M system.  Even with this meagre Z System, costing only 1k ofì
  154. TPA, you get the following features (and more):è
  155.     multiple commands on a line
  156.     the alias facility that provides automatic command sequence
  157.         generation
  158.     automatic, user-defined search path for COM files
  159.     extended command processing (ARUNZ, described in TCJ #31,
  160.         for example)
  161.     error handling that tells you what's wrong with a bad command
  162.         and allows you to correct it
  163.     shells (menu systems, command history shell for saving and
  164.         recalling old commands, file-maintenance shells, etc.)
  165.     terminal-independent full-screen operation via Unix-like
  166.         TCAP (terminal capabilities descriptor)
  167.  
  168.      These are only two of a wide variety of possible Z Systems.  As youì
  169. gain experience with NZCOM, you can fine tune the definitions to meet all ofì
  170. your needs.  For my BigBoard I computer, I have defined four systems.  Twoì
  171. of them, called FULL and TINY, have the features shown in the two examplesì
  172. here.  A third one is called SMALL.  Not quite as diminutive as TINY, itì
  173. sacrifices an additional 0.5k of TPA to retain the flow command packageì
  174. (FCP), which is so valuable in providing high levels of command automation. ì
  175. Even my voracious application programs can usually get by under this system.
  176.  
  177.      Finally, I have a system called NORMAL, which, as the name implies, isì
  178. the one I use most of the time.  It is the same as FULL but without an IOP. ì
  179. The most common use for an IOP is to run keyboard redefiners like NuKey. ì
  180. Most people like this feature, but splendid as NuKey is, for some reason myì
  181. style does not find much use for keyboard macros (I've become a ratherì
  182. skillful typist and can generally type faster than I can think of moving myì
  183. finger to a special key), so I generally omit the IOP and gain 1.5k of TPA.
  184.  
  185.  
  186. Loading the NZCOM Systems
  187.  
  188.      Having defined the systems above, we can now fire them up even moreì
  189. easily.  For the default NZCOM system, just enter the following simpleì
  190. command:
  191.  
  192.     A>nzcom
  193.  
  194. With no argument after the command name, NZCOM will load the system definedì
  195. with the name NZCOM.  As it does this, you will see a signon message on theì
  196. screen, followed by a series of dots, each one indicating that anotherì
  197. module has been loaded.  [Technical aside:  If you want to see moreì
  198. precisely what is going on, just add the option "/v" to the command toì
  199. select verbose mode.  You will then get a screen display something like thatì
  200. shown in Fig. 5.  I'll have more to say about what all this means a littleì
  201. later.]
  202.  
  203.      After NZCOM starts running, it executes a program called START.COM. ì
  204. This is usually an alias command, a program that simply passes another moreì
  205. complex command line on to the command processor.  I will not explain theìèdetails of START here, but after it finishes, Z System will be up andì
  206. running, waiting for your commands.
  207.  
  208.  
  209. How NZCOM Works
  210.  
  211.      This section is for the technically inclined, so if that's not you,ì
  212. pretend there are square brackets around this whole section and skip aheadì
  213. to the next section.  Here we are going to explain what some of thoseì
  214. verbose-mode messages mean and what NZCOM is doing to create the system onì
  215. the fly.
  216.  
  217.      First NZCOM loads the descriptor file into memory.  Among other things,ì
  218. this file has the information about which system modules to load and to whatì
  219. starting addresses.  The first module loaded is the command processor.  Itì
  220. is loaded from the file NZCPR.REL, which has the code for the commandì
  221. processor (ZCPR34) in so-called relocatable form.
  222.  
  223.      There is some very interesting assembly/linkage razzle-dazzle that goesì
  224. on here.  With the REL files one usually plays with, only the run-timeì
  225. execution address of the code is unknown at assembly time and must beì
  226. resolved by the linker.  Things are much trickier here.  When the commandì
  227. processor code was assembled, not only was its own run-time starting addressì
  228. unknown, but the addresses of various other system components, such as theì
  229. message buffer and multiple command line, to which it refers in countlessì
  230. places, are also unknown.  Since there is no fixed relationship between theì
  231. addresses of the CCP and these other modules, there is no way to define theì
  232. addresses using equates in the code.
  233.  
  234.      Put another way, when NZCOM converts NZCPR.REL into actual object code,ì
  235. it must resolve not only the calls and jumps and data loads that refer toì
  236. other locations in the command processor but also those that refer to theì
  237. other system modules.  Fortunately, advanced assemblers and linkers --ì
  238. including those from SLR Systems and a ZAS follow-on under development byì
  239. Echelon -- already have a mechanism to handle this problem.  It was Bridgerì
  240. Mitchell who recognized how this mechanism, called named common, couldì
  241. accomplish what was needed here.
  242.  
  243.      When code with symbols in named common is assembled, the correspondingì
  244. bytes in the resulting REL file are marked not only for relocation but forì
  245. relocation with respect to a specific common block.  The SLR assemblersì
  246. support up to 12 named common blocks.  NZCOM contains very sophisticatedì
  247. linking code that resolves the references to data items in the commonì
  248. blocks, the addresses of which it gets, naturally, from the NZC descriptorì
  249. file.
  250.  
  251.      Fig. 6 shows a partial listing of the file NZCMN.LIB, which isì
  252. referenced in a MACLIB statement in each module assembled for use by NZCOM. ì
  253. Seven named common blocks are defined: _BIOS_, _ENV_, _SSTK_, _MSG_, _FCB_,ì
  254. _MCL_, and _XSTK_ for the CBIOS, environment descriptor, shell stack,ì
  255. message buffer, external file control block, multiple command line buffer,ì
  256. and external stack, respectively.  Note that no common blocks are definedìèfor the RCP, FCP, or NDR.  References to these package must be madeì
  257. indirectly at run time, using data obtained from the environment descriptorì
  258. in memory.
  259.  
  260.      How does the NZCOM loader figure out that the file NZCPR.REL is theì
  261. command processor?  You might think that it uses the name of the file, but,ì
  262. in fact even if you had a copy of it called MYNEWCP.REL, NZCOM would be ableì
  263. to load it just as well.  The answer is that the source code contains theì
  264. directive
  265.  
  266.         NAME ('CCP')
  267.  
  268. which gives the REL file an internal module name.  It is this name thatì
  269. NZCOM uses to determine what kind of module the code represents.
  270.  
  271.      After the command processor is loaded, the other modules are loaded inì
  272. succession in similar fashion, except for two.  The named directory fileì
  273. NZCOM.NDR is a file that you can make or change with the standard utilityì
  274. programs MKDIR or EDITNDR/SAVENDR.  There is nothing in an NDR file thatì
  275. requires relocation at all.  The same is true for the Z3T terminalì
  276. descriptor (TCAP) file.  It can be created using the TCSELECT utility.
  277.  
  278.      When all the loading is done, a copy of the command processor objectì
  279. code is written out to a file called NZCOM.CCP.  This file is used forì
  280. subsequent warm boots, since we obviously cannot warm boot from what is onì
  281. the system tracks of the disk (the Digital Research command processor isì
  282. still there, after all).  At this point we can resume the non-technicalì
  283. discussion.
  284.  
  285.  
  286. Changing NZCOM Systems
  287.  
  288.      Now that you have Z System running, you can start to work with it andì
  289. learn about it.  I am not going to discuss Z System in general here; theì
  290. subject is much too extensive.  One thing you can do is to get out your backì
  291. issues of TCJ and experiment with the programs described there.  Another isì
  292. to buy the "Z System User Guide" published by Echelon.  That book describesì
  293. the Z System from a less technical point of view than Richard Conn's "ZCPR3,ì
  294. The Manual," also published by Echelon.
  295.  
  296.      What I would like to discuss now is some of the ways you can use the dynamic capabilities of NZCOM.  First we will describe how you change theì
  297. entire operating system.  For these examples we will assume that you haveì
  298. been doing work in various directory areas on your system and that you haveì
  299. set up named directories.  Let's say you are in your dBase II area now. ì
  300. Since you know that dBase II needs a lot of memory to run efficiently (orì
  301. should I say 'tolerably,' since it never runs efficiently!) and sinceì
  302. (unlike WordStar 4, for example) it cannot make use of any Z System featuresì
  303. anyway, you want to load the minimum system we created earlier.  You canì
  304. probably guess what the command is:
  305.  
  306.     B2:DBASE>nzcom minimum
  307. è     [More technical stuff: Fig. 7 shows the screen display you would getì
  308. with the "/v" verbose option on this command.]   For the minimum systemì
  309. NZCOM loads only a command processor, disk operating system, and virtualì
  310. BIOS.  The other system segments disappear.  This includes the NDR or namedì
  311. directory register, so the prompt changes to
  312.  
  313.     B2>
  314.  
  315. The START alias does not run this time.  It runs only when NZCOM is loadedì
  316. from a non-NZCOM system (such as CP/M).
  317.  
  318.      In general, when loading a new version of the operating system fromì
  319. another that is currently running, NZCOM loads only the modules that must beì
  320. loaded, either (1) because they did not exist before or (2) because they areì
  321. now at a different address or have a different size.  For example, when Iì
  322. load my FULL system from the NORMAL system to add an IOP, only the CCP, DOS,ì
  323. BIOS, and IOP are loaded, since the RCP, FCP, and NDR are in the same placeì
  324. as before and have the same size.  When modules do have to be loaded, filesì
  325. with the default names shown in Fig. 5 are used.  Later we will discuss howì
  326. you can load modules with other names.
  327.  
  328.      There are a number of system modules that never change in the presentì
  329. version of NZCOM.  (Yes, like the famous Al Jolson lines, you ain't seenì
  330. nothin' yet!)  These include the environment descriptor, message buffer,ì
  331. shell stack, path, wheel byte, and multiple command line buffer.  With theì
  332. exception of module addresses in the environment descriptor, data in theseì
  333. fixed system modules remain unaffected.  This means that if you had selectedì
  334. an error handler, for example, or a shell such as a command history shell,ì
  335. they will still be in effect after a change of system.
  336.  
  337.      Because the multiple command line buffer is preserved through the loadì
  338. of a new system, you can include NZCOM commands as part of multiple commandì
  339. sequences, alias scripts, and shell (MENU, VMENU, or ZFILER) macros.  Thus,ì
  340. for example, you could have entered the command
  341.  
  342.     B2:DBASE>nzcom minimum;dbase etc.
  343.  
  344. In this case the operating system would have changed, and then DBASE wouldì
  345. have started running.  I will not go into the technical details here, butì
  346. there are ways to write an alias script, which might be called DB, thatì
  347. would check to see if the minimum system was already running and, if not,ì
  348. automatically load it before invoking DBASE.
  349.  
  350.      Nothing says the operating system can change only once in the course ofì
  351. a multiple command line.  You might have alias scripts that change to aì
  352. minimum system, run a specific command, and then reload the normal systemì
  353. again.  There is a time penalty associated with this (though very little ifì
  354. you have the NZCOM files on a RAM disk), but the result is that theì
  355. application program sees a big TPA while it is running, but you always see aì
  356. nice, full-featured Z System.
  357.  
  358.      NZCOM does not even insist that you stay in Z System.  On the contrary. ìèOn a cold load from CP/M it will build (if it does not exist already) aì
  359. program called NZCPM that, when run from Z System, will restore the originalì
  360. CP/M system.
  361.  
  362.      [Technical aside: Even if you need absolutely every available byte ofì
  363. TPA, you can still automate the process.  You can use the submit facility toì
  364. run a batch job that exits from Z System entirely, runs an application underì
  365. plain CP/M, and then returns to Z System.  You do have to observe someì
  366. precautions.  For example, you have to make sure that all command lines inì
  367. the batch file that will execute while Z System is not in effect are validì
  368. CP/M commands.  Once the batch script has reloaded Z System using the NZCOMì
  369. command, it can resume using appropriate Z System commands, includingì
  370. multiple commands on a line.
  371.  
  372.      Another factor to bear in mind is that NZCPM returns you to CP/M inì
  373. drive A user 0 no matter where you were when it executed.  Since ZCPR3ì
  374. (starting with version 3.3) writes its submit file to directory A0 ratherì
  375. than the current directory, there is no problem with continuing operation ofì
  376. the batch file under CP/M.  However, when you reload NZCOM (it will be aì
  377. cold load, including execution of START), you will not automatically be backì
  378. in your original directory.  End aside.]
  379.  
  380.  
  381. Changing Parts of the System
  382.  
  383.      The NZCOM command is not limited to loading whole new operatingì
  384. systems; with a slightly different syntax it can also load individual systemì
  385. modules, rather like the LDR program in a manually installed Z System. ì
  386. There are two important differences, however.
  387.  
  388.      The first is that NZCOM loads code modules (IOP, RCP, and FCP) from RELì
  389. files rather than from absolute files such as SYS.FCP or DEBUG.RCP. ì
  390. Absolute files can still be loaded using LDR, but this is undesirable underì
  391. NZCOM, since the addresses of the modules may change as different systemsì
  392. are loaded.  NZCOM has the advantage of using a single REL file no matterì
  393. which system it is being loaded into.  In the future, RCPs, FCPs, and IOPsì
  394. will be distributed in REL form instead of (or in addition to) source codeì
  395. form.  The REL file is much smaller and can be used without knowing how toì
  396. assemble the code.
  397.  
  398.      The second difference is that NZCOM can load command processors andì
  399. disk operating systems as well.  This makes it very easy to change versionsì
  400. of the command processor (with or without security or named directory orì
  401. submit support, for example) or to experiment with alternative DOSs, such asì
  402. Z80DOS or P2DOS.  This will be a real boon to the development of newì
  403. operating system components, since one can test new versions so easily andì
  404. quickly.
  405.  
  406.      For convenience, NZCOM can also load named directory files (of typeì
  407. NDR) and terminal descriptor files (of type Z3T).  This is so that you doì
  408. not have to have LDR.COM on your disk.  On an NZCOM system, LDR is aì
  409. dangerous command, since it does not have safeguards against loadingìèabsolute system components to addresses for which they were not assembled. ì
  410. With an NZCOM system, you should remove LDR.COM from your disk.
  411.  
  412.  
  413. Other NZCOM Features
  414.  
  415.      There are many more things that could be said about NZCOM that I willì
  416. save for another time.  There is just one more that I want to mention now,ì
  417. and that is the extra "Custom Patch Area" that can be defined with MKNZCì
  418. (see Fig. 1).  This option in MKNZC allows one to establish an area inì
  419. protected memory just below the CBIOS (custom BIOS or real BIOS).  This areaì
  420. can be used by various operating system extensions that one wants toì
  421. preserve from one NZCOM system to another.
  422.  
  423.      Because of the techniques it uses for patching the Z System onto CP/M,ì
  424. NZCOM will not work when a resident system extension (RSX) is present. ì
  425. Thus, for example, you cannot run NZCOM from inside a ZEX script or ifì
  426. DateStamper or BYE is active in low memory (if they are loaded above theì
  427. CBIOS, there is no problem).  I am presently using the patch area forì
  428. DateStamper.  With NZCOM you can effectively have an above-BIOS version ofì
  429. DateStamper without having to move your BIOS down.
  430.  
  431.      I am also planning to experiment with putting BYE in the custom patchì
  432. area.  I think this can be made to work, and it would permit NZCOM to beì
  433. used on my Z-Node (and I mean used actively -- so that the NZCOM system canì
  434. be changed even from a remote terminal!).
  435.  
  436.      There are special facilities in NZCOM that I do not have the energy toì
  437. explain now whereby information about a currently running system can beì
  438. extracted before the new system has been loaded and used to initialize theì
  439. new system just before NZCOM turns over control to it.  This allows an RSX'sì
  440. hooks into the operating system to be maintained.
  441.  
  442.  
  443.                              ZCPR Version 3.4
  444.  
  445.      Now let's turn to the subject of ZCPR version 3.4, which will beì
  446. released along with NZCOM.  Z34, as I will refer to it, is much more anì
  447. evolutionary step from Z33 than Z33 was from Z30.  There are four newì
  448. features worth pointing out.
  449.  
  450.  
  451. Type-4 Programs
  452.  
  453.      The most important and exciting enhancement is the introduction of whatì
  454. is called the type-4 program.
  455.  
  456.      With Z33 I added support for a new kind of program to run under ZCPR3. ì
  457. Programs designed to take advantage of the special features of the Z Systemì
  458. have at the beginning of the code a special block of data called the Z3ENVì
  459. header.  This header identifies the program as a ZCPR3 program and containsì
  460. the address of the ZCPR3 environment descriptor, where all the informationìènecessary to find out about the Z System facilities is available.  It alsoì
  461. contains a type byte.  Conventional Z System programs were of type 1. ì
  462. (Type-2 programs are similar but actually have the entire environmentì
  463. desciptor in the header.  Programs of this type are extremely rare.  In someì
  464. senses they are a holdover from ZCPR2 and now obsolete.)
  465.  
  466.      For the new type-3 program I added an additional datum in the Z3ENVì
  467. header: the starting address for which the code had been assembled orì
  468. linked.  The command processor automatically loads the file to that addressì
  469. before transferring control to it.
  470.  
  471.      Type-3 programs are usually linked to run in high memory (for example,ì
  472. 8000H or 32K decimal) where they do not interfere with most data or code inì
  473. the TPA.  Programs that run as extensions of the operating system (viz.ì
  474. history shells, extended command processors, transient IF processor) or asì
  475. the equivalents of resident programs (viz. ERA.COM, REN.COM, SAVE.COM) areì
  476. particularly suitable for implementation as type-3 programs.  One cannotì
  477. always foresee when these programs will be invoked, and it is nice if theì
  478. contents of memory at the bottom of the TPA are not affected when they doì
  479. run.
  480.  
  481.      With type-3 programs one must choose in advance the address at whichì
  482. they will run.  If the address is too high, there may not be enough room forì
  483. them to load, and if too low, they are more likely to interfere withì
  484. valuable TPA contents.  In most situations it would clearly be preferable ifì
  485. the program could be loaded automatically as high as possible in memory.  Iì
  486. thought of this from the beginning but compromised on the type-3 constructì
  487. because it was so easy to code.
  488.  
  489.      Joe Wright was not satisfied with this compromise.  He soon wrote anì
  490. initial version of the type-4 program, which does relocate automatically toì
  491. the top of memory.  With a lot of cooperation between us, we have honed itì
  492. to the point where it functions very nicely and does not add very much codeì
  493. to the command processor.
  494.  
  495.      Because type-3 programs run at a fixed address, albeit not necessarilyì
  496. 100H, they can be assembled and linked in the usual fashion, and the programì
  497. files contain actual binary object code.  Type-4 programs, on the otherì
  498. hand, must be relocatable by the command processor at run time.  Thus objectì
  499. code alone is not sufficient.
  500.  
  501.      One possibility would be to use a REL file directly.  This would haveì
  502. been very convenient, but the code required to load a REL file is far tooì
  503. complex to include in a command processor running in a 64K memory segment. ì
  504. There is a less familiar relocatable type file known as a PRL (Pageì
  505. ReLocatable) file that, because it restricts the relocation to pageì
  506. boundaries (and other reasons), is much easier to relocate.
  507.  
  508.      A PRL file consists of three parts.  The middle part is a standard codeì
  509. image for execution at 100H.  After this comes what is called a bit map,ì
  510. where, for each byte in the code image, there is a bit of 0 or 1 to tellì
  511. whether that byte must be offset for execution at a different page.  The bitìèmap is one eighth the length of the code image.  Finally, one page (256ì
  512. bytes) at the beginning of the file serves as a header.  This headerì
  513. contains information about the size of the program so that the code thatì
  514. loads it can figure out where the object code ends and the bit map begins.
  515.  
  516.      In the type-4 program, this header is extended to include the codeì
  517. necessary (1) to calculate the highest address in memory at which theì
  518. program can be loaded and (2) to perform the code relocation to that addressì
  519. using the bit map.  The way this is accomplished is somewhat intricate.
  520.  
  521.      The command processor loads the first record of the type-4 file intoì
  522. the temporary buffer at 80H as usual to determine the program type.  If itì
  523. is type 4, the CCP then calls the code in the header.  That code calculatesì
  524. the load address and then (this clever idea was Joe's) calls the commandì
  525. processor back to load the program code and bit map into memory at theì
  526. proper address.  When this call is complete and control returns to theì
  527. header code, it then performs the relocation of the code image at theì
  528. execution address in memory.  Only then is control returned to the commandì
  529. processor for initialization and execution of the program.
  530.  
  531.      The result of this tricky scheme is that most of the type-4 supportì
  532. code that would otherwise have been required in the command processor is inì
  533. the header instead (this was my contribution to the type-4 concept).  Sinceì
  534. a PRL file has a two record header anyway (almost all of which is otherwiseì
  535. empty), you get to add this code for free.
  536.  
  537.      Joe pointed out to me some dangers with my type-3 construct.  Suppose aì
  538. type-3 program designed to run at 8000H is somehow loaded to 100H instead. ì
  539. Any attempt to execute it is likely to have less than desirableì
  540. consequences, to put it mildly.  This was not a serious problem with aì
  541. normal (at the time) ZCPR33 system.  Since the command processor wouldì
  542. automatically load the type-3 program to the correct address, it took someì
  543. deliberate action by the user to create the dangerous situation described. ì
  544. Of course, the poor fellow still running ZCPR30 who decided to try out aì
  545. type-3 program...
  546.  
  547.      However, now that NZCOM is here, the user may very well decide to dropì
  548. back into CP/M from Z System to perform some tasks.  In this situation, aì
  549. type-3 program is a live weapon, just waiting to blow up the system.  Theì
  550. type-4 program poses a similar danger.
  551.  
  552.      We have come up with two defense strategies.  One can be implemented inì
  553. the program itself.  There is code (TYP3HDR1.Z80) that can be placed at theì
  554. beginning of a type-3 program (based on ideas conceived independently by Bobì
  555. Freed and Joe Wright) that will verify that the code is running at theì
  556. proper address.  This part of the code is, as it must be, addressì
  557. independent (it uses only relative jumps).  If the load address is found toì
  558. be wrong, a warning message is displayed and control is returned to theì
  559. command processor before any damage can be done.  This is the friendlierì
  560. method, but it makes the programs longer.
  561.  
  562.      The second defense method does not impose any overhead on the programìècode.  It is easier to use than the other method, and it can generally beì
  563. patched into existing type-3 programs in object form.  It can also beì
  564. applied with type-4 programs, for which the first method cannot be usedì
  565. (type-4 files begin with a relocation header and not with program code, andì
  566. the system must be prevented from trying to execute the header when theì
  567. program is invoked under CP/M).
  568.  
  569.      With this method, one places a byte of C7H, the RST 0 instructionì
  570. opcode, at the beginning of the file.  Execution of this instruction causesì
  571. a call to address 0, which induces a warm boot.  This behavior may beì
  572. puzzling to the user, but at least it does no damage.  How, then, will suchì
  573. a program ever execute?  The answer is that ZCPR34 checks the first byte ofì
  574. a type-3 program to see if it is a C7H.  If it is, the command processorì
  575. replaces it with a C3H, the JP instruction opcode.  To take advantage ofì
  576. this method, the program code must begin with a "JP START" instruction inì
  577. which the JP is replaced by RST 0 (note: you cannot use JR START instead). ì
  578. The proper assembly language source code is illustrated in Fig. 8.  Noteì
  579. that the replacement of the RST 0 by a JP is not required with a type-4ì
  580. program since the header (which is where this construct appears) is neverì
  581. intended to be executed as a standard program, even under Z34.
  582.  
  583.  
  584. The Extended Environment Descriptor and the Drive Vector
  585.  
  586.      The definition of the ZCPR3 environment descriptor has been modifiedì
  587. and extended.  I will not go into all the details here, but I will describeì
  588. the main changes.
  589.  
  590.      First, to make some space available for additional importantì
  591. information, the extended ENV eliminates definitions for all but one consoleì
  592. and one printer.  Eventually there will be a tool (utility program) thatì
  593. allows interactive or command-line redefinition of the characteristics ofì
  594. these single devices so that you will actually have more rather than lessì
  595. flexibility.
  596.  
  597.      The extended ENV will now contain the addresses and sizes in records ofì
  598. the CCP, DOS, and BIOS (actually, the size of the BIOS is not included). ì
  599. This information has been added to deal with problems in some specialì
  600. operating system versions where the CCP and/or DOS do not have theirì
  601. standard sizes of 16 and 28 records respectively, such as in the Echelonì
  602. Hyperspace DOS for the DT-42 computer.  Future versions of NZCOM, which willì
  603. support variable CCP, DOS, and BIOS modules, will also need this.
  604.  
  605.      Finally, a long needed feature has at last been implemented; a driveì
  606. vector.  The maximum-drive value in the ENV was not adequate in a systemì
  607. with non-contiguous drives (A, B, and F, for example).  Now you can tell theì
  608. system exactly which drives you have on the system, and the commandì
  609. processor will do its best to prevent references to nonexistent drives.
  610.  
  611.  
  612. Ever More Sensible Named Directory Security
  613. è     With Z33 I made it possible to refer by drive/user (DU) to directoriesì
  614. beyond the range specified by the maximum drive and maximum user values inì
  615. the environment provided the directory area had a name with no password.  Itì
  616. seemed only reasonable that if a user could access the drive by name, heì
  617. should be allowed to access it by its equivalent DU as well.
  618.  
  619.      The converse situation, however, was not handled according to similarì
  620. logic.  Suppose the maximum user was 7 but there was a password-protectedì
  621. named directory for user 6.  Under Z33 one had the anomalous situation thatì
  622. the user could refer freely to the directory using the DU form but would beì
  623. pestered for the password if he used the named-directory (DIR) form.  Thisì
  624. just didn't seem reasonable, and Z34 has corrected this.
  625.  
  626.  
  627. Extended ECP Interface
  628.  
  629.      With Z34 I have added an additional option along the lines of BADDUECP. ì
  630. The BADDUECP option allows directory-change commands of the form NAME: orì
  631. DU: that refer to illegal directories to be passed on to the extendedì
  632. command processor (ECP) instead of directly to the error handler.  On my Z-Node, for example, I use the ARUNZ extended command processor to permitì
  633. references to reasonable facsimiles to the actual directory names to workì
  634. via alias scripts.
  635.  
  636.      With Z33 attempts to execute a command containing an illegal wildcardì
  637. character or with an explicit file type would be flagged as errors andì
  638. passed directly to the error handler.  With Z34 one has the option (via theì
  639. option BADCMDECP) to pass these forms of bad command to the extended commandì
  640. processor as well.
  641.  
  642.      Here are a couple of examples of how this feature can be used with theì
  643. ARUNZ extended command processor.  First, one can enter the following scriptì
  644. into the alias definition file ALIAS.CMD:
  645.  
  646.     ?  help $*
  647.  
  648. Now when a user enters the command "?", he will get the help system insteadì
  649. of an error message telling him that he entered a bad command.
  650.  
  651.      You can also use this facility to allow further shorthand commands. ì
  652. With the script definition
  653.  
  654.     DIM.Z3T   ldr dim.z3t   (or nzcom dim.z3t)
  655.  
  656. Now you can load the dim-video TCAP for your system simply by just enteringì
  657. the name of the TCAP file.  Using wildcard specifiers in the name of theì
  658. alias script, you can make any command with a type of Z3T load theì
  659. corresponding TCAP file.  Similarly, entering the name of a library (forì
  660. example, LBRNAME.LBR) on the command line could automatically invoke VLU onì
  661. that library.  The same concept would allow one to enter the name of aì
  662. source-code file (for example, THISPROG.Z80 or THATPROG.MAC) toì
  663. automatically invoke the appropriate assembler (Z80ASM/ZAS or SLRMAC/M80 forì
  664. these two examples).è
  665.      This feature opens another whole dimension for experimentation, and Iì
  666. am sure that users will come up with all kinds of new ways to use it. ì
  667. PLEASE NOTE: if this feature is implemented, you cannot use the old versionì
  668. of ARUNZ that I so painstakingly documented in my last column (alas, barelyì
  669. born and already obsolete).  Previous versions of ARUNZ used '?' and '.' forì
  670. special purposes.  Those characters were carefully chosen because they couldì
  671. never appear in command names passed to ARUNZ, but now they can!  Therefore,ì
  672. in version 0.9H of ARUNZ I have changed these characters to '_' (underscore)ì
  673. instead of '?' and ',' (comma) instead of '.'.
  674.  
  675.      That's it for this issue, I'm afraid.  I still didn't get to aì
  676. discussion of defects in the shell coding for WordStar 4 (I hope these willì
  677. be corrected in version 5, which is apparently really in the works at thisì
  678. time).  My discussion of the ZEX in-memory batch processor and theì
  679. improvements I have been making to it will also have to wait still longer.
  680.  
  681. ------------------------------------------------------------------------------
  682.  
  683.     1.*    Command Processor    CCP    BD00        16 Records
  684.     2.*    Disk Operating System    DOS    C500        28 Records
  685.     3.*    NZ-COM Bios        BIO    D300         2 Records
  686.  
  687.     4.    In/Output Processor    IOP    D400        12 Records
  688.     5.    Resident Command Proc    RCP    DA00        16 Records
  689.     6.    Flow Control Processor    FCP    E200         4 Records
  690.     7.    Named Directory Reg    NDR    E400        14 Names
  691.  
  692.     8.*    Environment Descriptor    ENV    E500         2 Records
  693.     9.*    Shell Stack        SHS    E600         4 Entries
  694.  
  695.     P.    Custom Patch Area    PAT    0000         0 Records
  696.         Customer's CBIOS    TOP    E800
  697.  
  698.             Effective TPA size 49.0k
  699.  
  700.     * Items 1, 2, 3, 8 and 9 are not changeable in this version.
  701.  
  702.     Selection: (or <S>ave or <Q>uit) _
  703.  
  704.  
  705. Figure 1.  Screen displayed by the MKNZC program when run under CP/M.  Thisì
  706. is the standard or default system definition.
  707.  
  708. ------------------------------------------------------------------------------
  709.  
  710. E806 CBIOS    0080 ENVTYP    E6F4 EXPATH    0005 EXPATHS    DA00 RCP
  711. 0010 RCPS    D400 IOP    000C IOPS    E200 FCP    0004 FCPS
  712. E400 Z3NDIR    000E Z3NDIRS    E700 Z3CL    00CB Z3CLS    E500 Z3ENV
  713. 0002 Z3ENVS    E600 SHSTK    0004 SHSTKS    0020 SHSIZE    E680 Z3MSG
  714. E6D0 EXTFCB    E7D0 EXTSTK    0000 QUIET    E6FF Z3WHL    0004 SPEED
  715. 0010 MAXDRV    001F MAXUSR    0001 DUOK    0000 CRT    0000 PRTè0050 COLS    0018 ROWS    0016 LINS    FFFF DRVEC    0000 SPAR1
  716. 0050 PCOL    0042 PROW    003A PLIN    0001 FORM    0066 SPAR2
  717. 0042 SPAR3    003A SPAR4    0001 SPAR5    BD00 CCP    0010 CCPS
  718. C500 DOS    001C DOSS    D300 BIO    0000 PUBDRV    0000 PUBUSR
  719.  
  720. Figure 2.  For the technically inclined, this is a listing of the contentsì
  721. of the NZCOM.NZC system descriptor file produced by MKNZC.
  722.  
  723. ------------------------------------------------------------------------------
  724.  
  725.     1.*    Command Processor    CCP    CE00        16 Records
  726.     2.*    Disk Operating System    DOS    D600        28 Records
  727.     3.*    NZ-COM Bios        BIO    E400         2 Records
  728.  
  729.     4.    In/Output Processor    IOP    0000         0 Records
  730.     5.    Resident Command Proc    RCP    0000         0 Records
  731.     6.    Flow Control Processor    FCP    0000         0 Records
  732.     7.    Named Directory Reg    NDR    0000         0 Names
  733.  
  734.     8.*    Environment Descriptor    ENV    E500         2 Records
  735.     9.*    Shell Stack        SHS    E600         4 Entries
  736.  
  737.     P.    Custom Patch Area    PAT    0000         0 Records
  738.         Customer's CBIOS    TOP    E800
  739.  
  740.             Effective TPA size 53.25k
  741.  
  742.     * Items 1, 2, 3, 8 and 9 are not changeable in this version.
  743.  
  744.     Selection: (or <S>ave or <Q>uit) _
  745.  
  746.  
  747. Figure 3.  Screen displayed by the MKNZC program after eliminating the IOP,ì
  748. RCP, FCP, and NDR modules in order to define a minimal Z System.
  749.  
  750. ------------------------------------------------------------------------------
  751.  
  752. E806 CBIOS    0080 ENVTYP    E6F4 EXPATH    0005 EXPATHS    0000 RCP
  753. 0000 RCPS    0000 IOP    0000 IOPS    0000 FCP    0000 FCPS
  754. 0000 Z3NDIR    0000 Z3NDIRS    E700 Z3CL    00CB Z3CLS    E500 Z3ENV
  755. 0002 Z3ENVS    E600 SHSTK    0004 SHSTKS    0020 SHSIZE    E680 Z3MSG
  756. E6D0 EXTFCB    E7D0 EXTSTK    0000 QUIET    E6FF Z3WHL    0004 SPEED
  757. 0010 MAXDRV    001F MAXUSR    0001 DUOK    0000 CRT    0000 PRT
  758. 0050 COLS    0018 ROWS    0016 LINS    FFFF DRVEC    0000 SPAR1
  759. 0050 PCOL    0042 PROW    003A PLIN    0001 FORM    0066 SPAR2
  760. 0042 SPAR3    003A SPAR4    0001 SPAR5    CE00 CCP    0010 CCPS
  761. D600 DOS    001C DOSS    E400 BIO    0000 PUBDRV    0000 PUBUSR
  762.  
  763. Figure 4.  For the technically inclined, this is a listing of the fileì
  764. MINIMUM.NZC, which describes a minimum-size version of an NZCOM system forì
  765. the computer in Figs. 1 and 2.
  766. è------------------------------------------------------------------------------
  767.  
  768.     A>nzcom /v
  769.     NZCOM Ver 2.0 Copyright (C) 1987-88 Alpha Systems Corp. 21 Jan 88
  770.      Input buffer start 1C00
  771.      Read  buffer start 1D00
  772.      Write buffer start 3D00
  773.      Loading A0:NZCOM.NZC
  774.      Loading A0:NZCPR.REL for BD00 at 3D00
  775.      Loading A0:NZDOS.REL for C500 at 4500
  776.      Loading A0:NZBIO.REL for D300 at 5300
  777.      Loading A0:NZIOP.REL for D400 at 5400
  778.      Loading A0:NZRCP.REL for DA00 at 5A00
  779.      Loading A0:NZFCP.REL for E200 at 6200
  780.      Loading A0:NZCOM.NDR for E400 at 6400
  781.      Loading A0:NZCOM.Z3T for E580 at 6580
  782.      Writing A15:NZCOM.CCP
  783.      Booting NZ-COM...
  784.  
  785. Figure 5.  This is the screen display produced by NZCOM as it loads theì
  786. default system definition NZCOM.NZC with the verbose option.
  787.  
  788. ------------------------------------------------------------------------------
  789.  
  790. ; Named COMMON declarations start here
  791. ; For compatibility, these are the same names used by Bridger Mitchell's
  792. ; JetLDR
  793.  
  794.     common    /_BIOS_/
  795. cbios:                ; Customer's bios address
  796.  
  797.     common    /_ENV_/
  798. z3env:                ; Z3 Environment descriptor
  799. z3envs    equ    2        ; Size (records)
  800. rcp    equ    z3env+12
  801. rcps    equ    yes        ; Used as existence test, not size
  802. fcp    equ    z3env+18
  803. fcps    equ    yes        ; Used as existence test, not size
  804. z3ndir    equ    z3env+21
  805. z3ndirs    equ    yes        ; Used as existence test, not size
  806.  
  807. drvec    equ    z3env+52    ; Valid drive vector
  808.  
  809. ccp    equ    z3env+63    ; CCP entry
  810. ccps    equ    z3env+65    ; Size
  811.  
  812. dos    equ    z3env+66    ; DOS entry (+6)
  813. doss    equ    z3env+68    ; Size
  814.  
  815. bio    equ    z3env+69    ; BIO entry
  816.  
  817.     common    /_SSTK_/èshstk:                ; Top of Shell stack
  818. shstks    equ    4        ; 4 entries
  819. shsize    equ    32        ; 32 bytes each
  820.  
  821.     common    /_MSG_/
  822. z3msg:                ; Message buffer
  823. z3msgs    equ    80        ; 80 bytes long
  824.  
  825.     common    /_FCB_/
  826. extfcb:                ; External file control block
  827. extfcbs    equ    36        ; 36 bytes long
  828. expath    equ    extfcb+extfcbs    ; External path
  829. expaths    equ    5        ; 5 elements
  830. z3whl    equ    expath+(expaths*2)+1 ; The wheel byte
  831. z3whls    equ    1        ; 1 byte
  832.  
  833.     common    /_MCL_/
  834. z3cl:                ; Multiple command line
  835. z3cls    equ    203        ; Maximum command length
  836. nzpat    equ    z3cl+256    ; Potential User patch area
  837.  
  838.     common    /_XSTK_/
  839. extstk:                ; External stack
  840. extstks    equ    48        ; Size (bytes)
  841.  
  842.     cseg            ; Select Code Segment
  843.  
  844. ; End of NZCMN.LIB
  845.  
  846. Figure 6.  This is a partial listing of the file NZCMN.LIB, which definesì
  847. the named common blocks used during assembly of modules for use by NZCOM.
  848.  
  849. ------------------------------------------------------------------------------
  850.  
  851.     B2:DBASE>nzcom minimum /v
  852.     NZCOM Ver 2.0 Copyright (C) 1987-88 Alpha Systems Corp. 21 Jan 88
  853.      Input buffer start 1C00
  854.      Read  buffer start 1D00
  855.      Write buffer start 3D00
  856.      Loading A0:MINIMUM.NZC
  857.      Loading A0:NZCPR.REL for CE00 at 3D00
  858.      Loading A0:NZDOS.REL for D600 at 4500
  859.      Loading A0:NZBIO.REL for E400 at 5300
  860.      Loading A0:NZCOM.Z3T for E580 at 5480
  861.      Writing A15:NZCOM.CCP
  862.      Booting NZ-COM...
  863.  
  864. Figure 7.  This is the screen display when NZCOM loads the minimum systemì
  865. from a running default system.
  866.  
  867. ------------------------------------------------------------------------------
  868. è    ENTRY:                ; Beginning of program
  869.         DB    0C7H        ; RST 0 opcode, will become JP
  870.         DW    START
  871.         DB    'Z3ENV'        ; ZCPR3 program ID
  872.         DB    3        ; Type 3
  873.     ENVADR:    DW    0        ; ENV address filled in by Z34
  874.         DW    ENTRY        ; Execution address
  875.     START:                ; Beginning of main program
  876.  
  877. Figure 8.  Form of the Z3ENV header code in a protected type-3 program.  Anì
  878. attempt to execute this code under CP/M will result in a warm boot.
  879.  
  880. [This article was originally published in issue 32 of The Computer Journal,
  881. P.O. Box 12, South Plainfield, NJ 07080-0012 and is reproduced with the
  882. permission of the author and the publisher. Further reproduction for non-
  883. commercial purposes is authorized. This copyright notice must be retained.
  884. (c) Copyright 1988, 1991 Socrates Press and respective authors]
  885.