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

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