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 / TCJ37-L2.WZ / TCJ37-L2.WS
Text File  |  2000-06-30  |  4KB  |  137 lines

  1.  
  2. ; PROGRAM:  UTILPAT -- Utility Patch
  3. ; AUTHOR:   Jay Sage
  4. ; DATE:     November 30, 1988
  5.  
  6. ; This patch *may* allow BIOS-specific utilities to
  7. ; work under NZ-COM.
  8.  
  9. ; The address below must be set to the first free byte
  10. ; after the utility's code.
  11.  
  12. patchaddr    equ    0000h
  13.  
  14. ; The address below must be set to the address at which
  15. ; execution will continue after the patch code is
  16. ; executed.
  17.  
  18. startaddr    equ    0000h
  19.  
  20. ; The following macro should be filled in with any opcodes
  21. ; that were at address 100H and following and had to be
  22. ; replaced by the jump to the patch code.  If the utility
  23. ; began with a JP STARTADDR instruction, then leave this
  24. ; macro blank
  25.  
  26. replaced    macro
  27.                 ; put instructions here
  28.         endm
  29.  
  30. ; The macro below is used to enter the list of addresses
  31. ; at which LD HL,(0001) instructions appear that must be
  32. ; patched.  Replace the symbol ADDR1 by the first such
  33. ; address and insert additional similar lines for any other
  34. ; addresses to be patched.
  35. addrlist    macro
  36.     dw    addr1        ; Repeat for each address
  37.         endm
  38.  
  39. ldhl    equ    21h        ; Load-hl-direct opcode
  40. offset    equ    5ah - 3        ; Offset from BIOS warm boot entry
  41.                 ; ..to the NZ-COM signature
  42.  
  43. ; The following code will be patched in at address 100h to
  44. ; vector control to the patch code.
  45.  
  46.     org    100h
  47.  
  48.     jp    patchaddr
  49.  
  50. ; The actual patch code begins here.
  51.  
  52.     org    patchaddr
  53.  
  54. ; If NZ-COM is running, HL will now contain the ENV address.
  55. ; We will need this later, so we save it.
  56.  
  57.     ld    (envaddr),hl
  58.  
  59. ; Now we must find out if NZ-COM is running.  This is done
  60. ; by looking for its signature "NZ-COM" at a specific offset
  61. ; from the virtual BIOS warm boot entry point.  If this
  62. ; signature is not found, the patch can be skipped.
  63.  
  64.     ld    hl,(0001)    ; Get possible virtual
  65.                 ; ..BIOS address
  66.     ld    de,offset    ; Offset to signature
  67.     add    hl,de
  68.     ld    de,signature    ; Point to what the
  69.                 ; ..signature should be
  70.     ld    b,sigsize    ; Length of signature
  71. sigloop:
  72.     ld    a,(de)
  73.     cp    (hl)        ; Check character
  74.     inc    de        ; Advance pointers
  75.     inc    hl
  76.     jr    nz,exitpatch    ; Jump if not NZ-COM system
  77.     djnz    sigloop        ; Loop through signature
  78.  
  79. ; We get here if NZ-COM is running.  Now we must make the
  80. ; necessary patches to the utility.  First we must determine
  81. ; the address of the warm boot entry to the real BIOS.
  82. ; NZ-COM keeps the page address at offset 2 into the ENV.
  83.  
  84. envaddr    equ    $ + 1
  85.     ld    hl,$-$        ; Filled in by code above
  86.     inc    hl        ; Advance to CBIOS page
  87.     inc    hl
  88.     ld    a,(hl)        ; Get page of CBIOS
  89.     ld    (cbiospage),a    ; Put it into code below
  90.  
  91. ; Now we patch in the changes to the utility code.
  92.  
  93.     ld    de,table    ; Point to address table
  94.     ld    b,tablesize    ; Addresses in table
  95. patchloop:
  96.     ld    a,(de)        ; Low byte of address
  97.     inc    de        ; Advance pointer
  98.     ld    l,a        ; Put in low byte of HL
  99.     ld    a,(de)        ; High byte of address
  100.     inc    de        ; Advance pointer
  101.     ld    h,a        ; Put in high byte of HL
  102.     ld    (hl),ldhl    ; Patch in direct-load opcode
  103.     inc    hl
  104.     ld    (hl),03H    ; Low warm boot address
  105.     inc    hl
  106. cbiospage equ    $ + 1
  107.     ld    (hl),0        ; Filled in by code above
  108.     djnz    patchloop    ; Loop through address list
  109.  
  110. exitpatch:
  111.  
  112. ; Here we have to exit from the patch and resume execution
  113. ; of the original utility.  First we execute instructions, if
  114. ; any, replaced by the patch intercept code.
  115.  
  116.     replaced        ; Macro
  117.  
  118. ; Then we jump to the utility code.
  119.  
  120.     jp    startaddr
  121.  
  122. ; The following is what the NZ-COM signature should look like.
  123.  
  124. signature:
  125.     db    'NZ-COM'
  126. sigsize    equ    $ - signature
  127.  
  128. ; We put the table of addresses to patch here.
  129.  
  130. table:
  131.     addrlist        ; Macro with address list
  132. tablesize    equ    ( $ - table ) / 2
  133.  
  134.     end
  135.  
  136.