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 / TCJ39.WS < prev    next >
Text File  |  2000-06-30  |  14KB  |  262 lines

  1.                                Z-System Corne≥ (c)
  2.                                  by Jay Sage
  3.                         The Computer Journal, Issue 39
  4.                           Reproduced with permission
  5.                            of author and publisher
  6.  
  7.  
  8.    For this issue I will discuss some unique new capabilities made possibleì
  9. by NZCOM that have already proved their value and that I hope will beì
  10. exploited to a much greater extent in the future.  I originally had severalì
  11. other issues on my agenda, but Lee A. Hart sent me such an interestingì
  12. article that I wanted to leave plenty of room for it.
  13.  
  14.  
  15.                       System Enhancements Using NZCOM
  16.  
  17.    I'm afraid that many people think of NZCOM as just a way for unskilledì
  18. users to get Z-System running on their computers.  It's true that NZCOMì
  19. accomplishes that, but, as I have asserted often before, NZCOM does muchì
  20. more than that.  It offers possibilities that a manually installed Z-Systemì
  21. cannot achieve.  I would like to describe one of them here and will do soì
  22. first in the context of a problem that arose with the new ZSDOS and ZDDOSì
  23. disk operating systems on some computers.
  24.  
  25.    Because CP/M was created originally for the 8080 microprocessor, a numberì
  26. of BIOS implementors (the BIOS, or Basic Input/Output System, is theì
  27. hardware-dependent part of CP/M) felt that they could make free use of theì
  28. additional registers introduced with the Z80 chip.  These registers includedì
  29. two index registers, called IX and IY, and a duplicate set of the standardì
  30. registers denoted with primes on the names (e.g., B' or HL').
  31.  
  32.    This was perhaps excusable at the time, but it is poor programmingì
  33. practice for an operating system to change anything other than what isì
  34. explicitly indicated in the specifications.  Most BIOS writers who have usedì
  35. the Zilog registers have been careful to restore the original values beforeì
  36. exit from the BIOS routines.  Unfortunately, a few BIOSes fail to do that. ì
  37. Among them are the following: Epson QX10, Zorba, Televideo 803 and TPC-1,ì
  38. Oneac On, and the Osborne Executive.  The Bondwell is on the suspect list,ì
  39. and there are probably others we don't know about yet.
  40.  
  41.    The (mis)use of these registers poses no problem for programs written toì
  42. run on the 8080, but today we are rapidly moving beyond the limitations ofì
  43. the 8080 and making extensive use of the Z80 registers to pack more powerì
  44. into operating system components and application programs.  Today, the Z¡
  45. System, true to its name, is intended to run only on the Z80 or upwardlyì
  46. compatible processors like the HD64180, Z180, or Z280.
  47.  
  48.    Several users who purchased ZDOS (that is ZSDOS and ZDDOS) found that itì
  49. would not work properly on their computers.  An investigation turned up theì
  50. fact that the BIOSes in those computers were modifying the index registers. ì
  51. This also explained why those same users had been experiencing strangeì
  52. problems with JetLDR, Bridger Mitchell's superb Z-System module loader.  Itìèalso explained some mysterious problems I was having with a number ofì
  53. programs (for example, EDITNDR) on my Televideo 803!  The question was whatì
  54. to do about the problem.
  55.  
  56.    In the ancient days, when computers always came with the source to theirì
  57. BIOS and their owners were always intimately familiar with the proceduresì
  58. for rebuilding their operating systems, the solution would have been toì
  59. rewrite the BIOS with the proper PUSH IX and POP IX instructions to preserveì
  60. the index register values.  But what could we do today for nonprogrammersì
  61. and those without BIOS source code?  NZCOM provided the answer quite nicely!
  62.  
  63.    As I explained in a column long ago, NZCOM works by creating what I callì
  64. a virtual BIOS (I'll call it VBIOS) lower in memory in order to open upì
  65. space for the Z-System modules between it and the real BIOS (often calledì
  66. the custom BIOS or CBIOS).  The source for this virtual BIOS is available. ì
  67. Except for the warmboot code and some minor complications for IOPì
  68. (input/output processor) support, the standard NZCOM VBIOS module justì
  69. vectors calls that come to it up to the real BIOS.
  70.  
  71.    But no one says this is all it is allowed to do.  ZDOS authors Camì
  72. Cotrill and Hal Bower found it quite easy to surround the vectors with codeì
  73. to save and restore registers.  First they released ZSNZBI11.LBR, whichì
  74. contained the source and ZRL file (loadable by NZCOM) for a VBIOS thatì
  75. preserved the IX and IY registers for all disk function calls.  Later theyì
  76. discovered that some of the machines changed the index registers even forì
  77. console I/O function calls, and others changed the alternate registers. ì
  78. They then wrote ZSNZBI12.LBR, whose VBIOS preserves all the registers forì
  79. all BIOS functions.
  80.  
  81.    Instead of having the virtual BIOS routines jump directly to the realì
  82. BIOS, they jump to an intermediate entry point.  For example, the list¡
  83. status vector in the jump table has a JP ILSTST (intermediate list status),ì
  84. and the code at ILSTST is
  85.  
  86.     ILSTST: LD      A,45
  87.             JR      DOBIOS
  88.  
  89. The offset for the BIOS function is placed in the A register and thenì
  90. control is transferred to a general BIOS-calling routine shown in Table 1ì
  91. that implements the register protection.  The routine JPHL referenced thereì
  92. contains only the code line JP (HL), which vectors the CPU off to the BIOSì
  93. with a return to the DOBIOS code.
  94.  
  95. -----------------------------------------------------------------------------
  96.  
  97. DOBIOS: LD      HL,CBIOS    ; Start with address of real BIOS 
  98.         ADD     A,L        ; Add offset in A (never a
  99.         LD      L,A             ; ..carry since on page boundary)
  100.         EXX                     ; Swap to alternate registers
  101.         LD      (HLP),HL    ; Save them all in memory
  102.         LD      (DEP),DE
  103.         LD      (BCP),BCè        LD      (IXREG),IX    ; Save index registers, too
  104.         LD      (IYREG),IY
  105.         EXX            ; Back to regular registers
  106.         EX      AF,AF'          ; Swap to alternate PSW
  107.         PUSH    AF        ; Save it on stack
  108.         EX      AF,AF'        ; Back to original PSW
  109.         CALL    JPHL            ; Actually call the BIOS!
  110.         EXX            ; Restore alternate and index
  111.         LD      HL,(HLP)    ; ..registers
  112.         LD      DE,(DEP)
  113.         LD      BC,(BCP)
  114.         LD      IX,(IXREG)
  115.         EX      AF,AF'        ; Alternate PSW, too
  116.         POP     AF
  117.         EX      AF,AF'
  118.         RET
  119.  
  120. ; Register save area
  121.  
  122. BCP:    DEFS    2               ; BC'
  123. DEP:    DEFS    2               ; DE'
  124. HLP:    DEFS    2               ; HL'
  125. IXREG:  DEFS    2               ; IX
  126. IYREG:  DEFS    2               ; IY
  127.  
  128.         END
  129.  
  130. Table 1.  Code from ZSNZBI12.Z80 that preserves all index and alternateì
  131. registers across BIOS calls in NZCOM.
  132.  
  133. -----------------------------------------------------------------------------
  134.  
  135.    To use this replacement VBIOS, you have to run MKZCM and create an NZCOMì
  136. system with 4 records allocated for the BIOS instead of the standard 2. ì
  137. Because the BIOS must start on a page rather than just a record boundary,ì
  138. MKZCM will sometimes make automatic adjustments to the BIOS size. ì
  139. Therefore, you should specify changes in MKZCM starting with the higher¡
  140. numbered modules; the adjustment in the BIOS allocation should be made last. ì
  141. If an attempt to enter a value of 4 results in MKZCM using 5, then you couldì
  142. go back (if you don't like wasting memory) and make one of the other modulesì
  143. (such as the NDR) one record larger and then respecify a 4-record BIOS.
  144.  
  145.    There are many other ways that NZCOM can be used to introduce systemì
  146. enhancements without having to make changes in the real BIOS.  As anì
  147. example, we will show how to add support for the drive vector in environmentì
  148. descriptors of type 80H and above (implemented with NZCOM and Z3PLUS).  Theì
  149. drive vector is a 16-bit value stored as a word beginning at offset 34H inì
  150. the environment descriptor.  It specifies which disk drives are actuallyì
  151. implemented on a system.  The lowest order bit in the word is for drive Aì
  152. and the highest for drive P.  A zero in a bit position indicates that theì
  153. corresponding drive is not available.  For example, on my SB180 the bytes atì
  154. addresses ENV+34H and ENV+35H were 7FH and 00H, respectively.  Thus the wordìèvalue is 007FH or 0000,0000,0111,1111 binary, indicating that I had drivesì
  155. A, B, C, D, E, F, and G. When the hard disk E partition developed a problemì
  156. that made it unusable, I changed the 7FH value to 6FH, thereby disablingì
  157. drive E.  You can display the drive vector using menu selection 3 in theì
  158. SHOW program (ZSHOW for Z3PLUS).
  159.  
  160.    The ZCPR34 command processor knows about the drive vector and will notì
  161. allow command references to unsupported drives.  But what about programsì
  162. that you run?  Unfortunately, the BIOS generally knows only which drives areì
  163. potentially implemented, and it may try to access a nonexistent drive.  Whenì
  164. 'smart' BIOSes encounter this problem, they often prompt the user as to whatì
  165. to do next.  This is fine if you are sitting at the console and can takeì
  166. appropriate action to recover, but if the system is being run remotely,ì
  167. there is generally no way for the remote user to recover.  In fact, becauseì
  168. the 'smart' BIOS uses direct hardware calls to display the "Abort, Retry,ì
  169. Ignore?" message rather than calls through the BIOS vector table, the remoteì
  170. user does not even see the message and just thinks the system has crashed. ì
  171. My Z-Node got hung once that way when I forgot to put a diskette back into aì
  172. floppy drive.  A caller attempted to access it, and when I got home, theì
  173. BIOS was dutifully beeping at me and waiting for me to tell it what to do.
  174.  
  175.    My first stab at writing a VBIOS that observes the drive vectorì
  176. restrictions is shown in Table 2.  Now that I have read Lee Hart's column, Iì
  177. am sure that this code can be made shorter, faster, or both!  But I willì
  178. leave that as an exercise for the reader.  (I already see one place where Iì
  179. could save a byte.)
  180.  
  181.    The listing assumes you are starting with the ZSNZBIO described earlier. ì
  182. Just add the extra equate for DRVEC under the /_ENV_/ common block andì
  183. replace the simple ISELDK (intermediate select disk) code with the slightlyì
  184. more complex version shown in the Table.  I put this on my Televideo, andì
  185. the results were most pleasant.  Now when I attempt to access a nonexistentì
  186. drive, the system does not force a direct-CBIOS warmboot that drops me outì
  187. of NZCOM.
  188.  
  189. -----------------------------------------------------------------------------
  190.  
  191.  
  192. ; Add DRVEC definition in the ENV common
  193.  
  194.     COMMON    /_ENV_/
  195. Z3ENV:
  196. DRVEC    EQU    Z3ENV+34H    ; Drive vector
  197. CCP    EQU    Z3ENV+3FH
  198. DOS    EQU    Z3ENV+42H
  199.  
  200. ; Modify ISELDK as follows and place it after the DOBIOS code and before
  201. ; the data area for register storage.
  202.  
  203. ISELDK:    LD    HL,(DRVEC)    ; Get drive vector
  204.     LD    A,16        ; Subtract requested drive
  205.     SUB    C        ; .. from 16è    LD    B,A        ; .. and put into B
  206. ISELDK1:
  207.     ADD    HL,HL        ; Move bits left into carry
  208.     DJNZ    ISELDK1        ; Loop 16-<drive> times
  209.     LD    HL,0        ; BIOS return code for invalid drive
  210.     RET    NC        ; Return if drive vector bit not set
  211.     LD    A,27        ; Otherwise, use CBIOS function
  212.     JR    DOBIOS        ; .. at offset 27
  213.  
  214. Table 2.  Code added to virtual BIOS to support the environment drive vectorì
  215. at the BIOS level.
  216.  
  217. -----------------------------------------------------------------------------
  218.  
  219.    These two examples of system enhancements by no means exhaust theì
  220. possibilities.  One can implement all kinds of additional features andì
  221. drivers right in the NZCOM VBIOS.  Joe Wright suggested early during NZCOMì
  222. development that one should create an absolutely stripped down CBIOS, oneì
  223. that contains only the functions that are absolutely necessary to get theì
  224. system running and then implement all the bells and whistles in the VBIOS. ì
  225. These extra features would include things like RAM-disk drivers, keyboardì
  226. type-ahead buffers, logical drive swapping facilities, and disk errorì
  227. recovery management routines.  With this strategy, one can actually achieveì
  228. a larger TPA with an NZCOM system than one had under the standard CP/Mì
  229. system, since the CBIOS can be made smaller and the fancy features droppedì
  230. when a larger TPA is more important.
  231.  
  232.    For example, the "Abort, Retry, Ignore" message should be implemented inì
  233. the VBIOS, with the CBIOS returning from disk errors with standard errorì
  234. codes.  With the normal VBIOS, the error will simply be passed back to theì
  235. DOS, which will report the error in its usual way ("BDOS ERROR on..." in theì
  236. case of the Digital Research BDOS).  A more elaborate VBIOS can detect theì
  237. error, report it to the user, and allow the operation to be retried.  Whenì
  238. the system is running in remote mode, either the simpler VBIOS can be usedì
  239. or the prompt can be vectored properly through the jump table so that theì
  240. remote user will be able to deal with the problem.
  241.  
  242.    Similarly, one should be able to handle the swapping of logical driveì
  243. names in the VBIOS.  There are a couple of pitfalls to watch out for,ì
  244. however.  If you change logical names, you better make sure that the diskì
  245. system is reset, probably both before and after the swap.  You also betterì
  246. make sure that NZCOM can still find its CCP file, which is normally kept inì
  247. directory A15:.  If you swap the A drive without providing a copy of thisì
  248. CCP in the new A drive, you'll be in serious trouble.  Of course, theì
  249. swapping would be handled by a utility program, and it would worry aboutì
  250. these requirements.  The VBIOS would simply have the code for translatingì
  251. references to a logical drive value in register C into a possibly differentì
  252. physical drive value.
  253.  
  254.    I hope that this short discussion has given some of you ideas forì
  255. imaginative applications of the new capability offered by the NZCOM virtualì
  256. BIOS.  If so, I would love to hear about them and to see sample code.è
  257. [This article was originally published in issue 39 of The Computer Journal,
  258. P.O. Box 12, South Plainfield, NJ 07080-0012 and is reproduced with the
  259. permission of the author and the publisher. Further reproduction for non-
  260. commercial purposes is authorized. This copyright notice must be retained.
  261. (c) Copyright 1989, 1991 Socrates Press and respective authors]
  262.