home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / util / clrrsx11.zz0 / CLRRSX11.Z80
Encoding:
Text File  |  1993-06-09  |  8.3 KB  |  330 lines

  1. ; Program:    CLRRSX
  2. ; Author:    Jay Sage
  3. ; Date:     July 20, 1986
  4. ;
  5. ; This program is used to remove any installed RSX (resident system extension)
  6. ; modules that are present.
  7. ;
  8. ; An RSX is deemed to be present if the warmboot vector at 0001h does not
  9. ; point to an address ending in 03, or the BDOS vector at 0006h does not point
  10. ; to an address ending in 06, or the BIOS and BDOS pages do not differ by 0EH.
  11. ; (see Version 1.1 notes for additional RSX conditions now detected - [bm])
  12. ;
  13. ; This program installs itself automatically the first time it is run on the
  14. ; system with no RSX present by copying the virgin BIOS jump vectors into a
  15. ; buffer at the end of the program.  (As of version 1.1, the program also
  16. ; saves the original BDOS+6 entry point and the jump address to which it
  17. ; branches.  This is what some above-the-BIOS system extensions use to
  18. ; divert BDOS calls since they do not have to protect the CCP. - [bm])
  19. ;
  20. ; Subsequently, if it is called with an RSX present, it restores the BIOS jump
  21. ; table (Version 1.1 restores jump address at BDOS+7 - [bm]) and warm boots.
  22. ;
  23. ; When it is called with an RSX present and it has not been installed, then an
  24. ; error message is given.  Similarly, an error message is given when it has
  25. ; been installed already but is called when no RSX is present.
  26. ;
  27. ; Note that the file name in the FCB at the beginning of the code must be the
  28. ; actual name of the program in order to carry out the installation.  Once the
  29. ; program has been installed, however, it can be renamed.
  30.  
  31. ; Version 1.1:    CLRRSX now has two additional capabilities, it now checks for
  32. ;        alteration of the jump table as an RSX condition, except when
  33. ;        being installed, in which case it would have no reference to
  34. ;        check from.  It also restores the original initial BDOS jump
  35. ;        address at BDOS+7.  These two additions make CLRRSX useful
  36. ;        for detaching BDOS/BIOS-diverting code that does not alter
  37. ;        page 0, such as Plu*Perfect DateStamper when relocated above
  38. ;        the BIOS.  This makes it possible, for example, to load
  39. ;        DateStamper into the IOP buffer at IOP plus an offset for
  40. ;        the dummy IOP code, detach it at will with CLRRSX, and
  41. ;        reload it afterwards (INIT.IOP would have to be LDRed into
  42. ;        place before reloading DateStamper if an active IOP is in
  43. ;        the buffer - or patch the DS loader to patch in a dummy
  44. ;        IOP segment before loading the actual DS code).
  45. ;                        7/22/86 - Bruce Morgen
  46.  
  47. entries    equ    17        ; BIOS table entries that need restoring
  48.  
  49. bdos    equ    0005h        ; BDOS entry point
  50.  
  51. printf    equ    09h        ; BDOS functions
  52. setdma    equ    1ah
  53. rread    equ    21h
  54. rwrite    equ    22h
  55. open    equ    0fh
  56.  
  57. cr    equ    13
  58. lf    equ    10
  59.  
  60. ;------------------------------
  61.  
  62.     org    100h        ; Start of program
  63.  
  64.     jp    start
  65.  
  66. ;------------------------------
  67.  
  68. progfcb:    ; FCB for program
  69.  
  70.     defb    0        ; Drive
  71.         ;12345678
  72.     defb    'CLRRSX  '    ; Name (exactly 8 characters)
  73.         ;123
  74.     defb    'COM'        ; Type (exactly 3 characters)
  75.     defs    21        ; Space for rest of main FCB
  76. recaddr:
  77.     defs    3        ; Space for random record address
  78.  
  79. ;------------------------------
  80.  
  81. start:        ; Check first to see if already installed
  82.  
  83.     ld    a,(instfl)    ; Check the install flag
  84.     or    a
  85.     jr    z,notinst    ; Branch if not installed
  86.  
  87.         ; See if RSX is there to clear
  88.  
  89.     call    chkrsx
  90. insret:    ld    de,norestmsg
  91.     jr    z,print        ; Branch if restore not needed
  92.  
  93. ;------------------------------
  94.  
  95.         ; Perform restore operation to clear RSX
  96.  
  97.     ld    hl,(biosaddr)    ; Get real BIOS address
  98.     ld    de,biostbl    ; Point to virgin BIOS table
  99.     ex    de,hl        ; Source address in hl
  100.     ld    bc,3*entries    ; Bytes to copy
  101.     ldir            ; Copy whole table
  102.     ld    de,(bdosentr)    ; Get BDOS entry point
  103.     inc    de        ; Bump to JP dest. address position
  104.     ld    hl,bdosjmp    ; Point to our authentic address
  105.     ldi            ; Move and bump
  106.     ldi            ; Once more
  107.     ld    de,restmsg    ; Inform user
  108.     call    print
  109.     jp    biostbl+3    ; Warm boot (restores page 0 vectors)
  110.  
  111. ;------------------------------
  112.  
  113. notinst:    ; Program needs to be installed
  114.  
  115.     call    chkrsx        ; See if RSX present
  116.     ld    de,cannotmsg
  117.     jr    nz,print    ; If so, branch to error message
  118.  
  119.     jp    install
  120.  
  121. ;------------------------------
  122.  
  123. cannot:        ; Cannot install when RSX is present
  124.     ld    de,cannotmsg
  125.     jr    print
  126.  
  127. ;------------------------------
  128.  
  129. openerr:
  130.     ld    de,openerrmsg
  131.     jr    print
  132.  
  133. ;------------------------------
  134.  
  135. filerr:
  136.     ld    de,filerrmsg
  137.     jr    print
  138.  
  139. ;---------------------------------------------------------------------------
  140.  
  141. ; SUBROUTINES
  142.  
  143. print:
  144.     ld    c,printf    ; BDOS print string function
  145.     jp    bdos
  146.  
  147. ;------------------------------
  148.  
  149. install:    ; Install program
  150.  
  151.     call    initfcb        ; Initialize FCB
  152.     ld    de,progfcb    ; Open file
  153.     ld    c,open
  154.     call    bdos
  155.     inc    a        ; Check for success
  156.     ld    de,openerrmsg
  157.     jr    z,print        ; If not, report error and quit
  158.  
  159.     ld    de,80h        ; Make sure dma address is right
  160.     ld    c,setdma
  161.     call    bdos
  162.  
  163.         ; Read the random record
  164.  
  165.     call    setrand        ; Set random record address
  166.     ld    de,progfcb    ; Read the sector
  167.     ld    c,rread
  168.     call    bdos
  169.     or    a        ; Make sure no error
  170.     jr    nz,filerr
  171.  
  172.         ; Update record contents
  173.  
  174.     ld    hl,(0001)    ; Get BIOS page address
  175.     ld    l,0
  176.     ld    (80h),hl
  177.     ex    de,hl        ; Save in DE
  178.     ld    hl,(0006)    ; Get BDOS entry point
  179.     ld    (80h+[bdosentr-buffer]),hl ; Save in buffer
  180.     inc    hl        ; Point at JP dest. address
  181.     ld    a,(hl)        ; Read it out into HL
  182.     inc    hl
  183.     ld    h,(hl)
  184.     ld    l,a
  185.     ld    (80h+[bdosjmp-buffer]),hl  ; And store it
  186.     ld    hl,80h+[instfl-buffer]    ; Set HL as buffer pointer
  187.     dec    (hl)        ; Set installed-flag
  188.     inc    hl        ; Point to beginning of vector table
  189.     ex    de,hl        ; Destination in DE, source in HL
  190.     ld    bc,3*entries    ; Bytes to copy
  191.     ldir
  192.  
  193.         ; Write sector back
  194.  
  195.     ld    de,progfcb
  196.     ld    c,rwrite
  197.     call    bdos
  198.     or    a        ; Make sure no file error
  199.     ld    de,filerrmsg
  200.     jr    nz,print
  201.  
  202.     ld    de,instalmsg    ; Inform user and quit
  203.     jr    print
  204.  
  205. ;------------------------------
  206.  
  207. chkrsx:        ; See if RSX already present; if so, return non-zero
  208.  
  209.     ld    hl,(0006h)    ; Get BDOS vector
  210.     ld    a,l        ; Make sure low part is 06
  211.     cp    6
  212.     ret    nz        ; RSX must be present
  213.     ex    de,hl
  214.     ld    hl,(0001h)    ; Get BIOS warmboot vector
  215.     ld    a,(instfl)    ; CLRRSX installed?
  216.     or    a
  217.     jr    z,noinst    ; If not, no table compare
  218.     push    hl        ; Save warm boot vector
  219.     push    de        ; and BDOS entry on stack
  220.     dec    hl        ; Decrement
  221.     dec    hl        ; to BIOS table
  222.     dec    hl        ; start.
  223.     ld    de,biostbl    ; Point to virgin table
  224.     ld    b,entries*3    ; Length in B for counter
  225. tbloop:    ld    a,(de)        ; Virgin byte in A
  226.     cp    (hl)        ; Compare to BIOS
  227.     jp    nz,insret    ; If different, there's an RSX
  228.     inc    de        ; Bump pointers
  229.     inc    hl
  230.     djnz    tbloop        ; Count down
  231.     pop    de        ; Restore BDOS
  232.     pop    hl        ; and BIOS vector dests.
  233. noinst:    ld    a,l        ; Make sure low part of BIOS dest.is 03
  234.     cp    3
  235.     ret    nz        ; If not, RSX must be present
  236.     ld    a,h        ; Get BIOS page
  237.     sub    d        ; Subtract BDOS page
  238.     cp    0eh        ; Zero if no RSX
  239.     ret            ; Otherwise return NZ
  240.  
  241. ;------------------------------
  242.  
  243. initfcb:
  244.     ld    hl,progfcb+12    ; Point to part of FCB to zero out
  245.     ld    b,21h-0ch    ; Bytes to zero
  246.     xor    a        ; Zero A
  247. initfcb1:
  248.     ld    (hl),a
  249.     inc    hl
  250.     djnz    initfcb1
  251.     ret
  252.  
  253. ;------------------------------
  254.  
  255. setrand:    ; Set random record value
  256.  
  257.     ld    hl,[buffer-100h]/80h    ; Random record number for buffer
  258.     ld    (recaddr),hl    ; Store in FCB
  259.     ret
  260.  
  261. ;---------------------------------------------------------------------------
  262.  
  263. ; MESSAGE TEXT
  264.  
  265. cannotmsg:
  266.     defb    cr,lf
  267.     defb    'RSX present; cannot install program.'
  268.     defb    cr,lf
  269.     defb    '$'
  270.  
  271. openerrmsg:
  272.     defb    cr,lf
  273.     defb    'Cannot install program; not found in current directory.'
  274.     defb    cr,lf
  275.     defb    '$'
  276.  
  277. norestmsg:
  278.     defb    cr,lf
  279.     defb    'No RSX present; no need to clear.'
  280.     defb    cr,lf
  281.     defb    '$'
  282.  
  283. restmsg:
  284.     defb    cr,lf
  285.     defb    'RSX cleared from system.'
  286.     defb    cr,lf
  287.     defb    '$'
  288.  
  289. instalmsg:
  290.     defb    cr,lf
  291.     defb    'Program installed with BIOS data.'
  292.     defb    cr,lf
  293.     defb    '$'
  294.  
  295. filerrmsg:
  296.     defb    cr,lf
  297.     defb    'Error reading or writing file.'
  298.     defb    cr,lf
  299.     defb    '$'
  300.  
  301. ;---------------------------------------------------------------------------
  302.  
  303. ; BUFFERS to hold intall flag and virgin BIOS jump table
  304.  
  305.     org    [ $ + 7fh ] and    0ff80h    ; Get record boundary
  306.  
  307. buffer:
  308.  
  309. biosaddr:
  310.     defs    2        ; Address of real BIOS
  311.  
  312. bdosentr:
  313.     defs    2        ; Address of real BDOS entry
  314.  
  315. bdosjmp:
  316.     defs    2        ; JP dest. address for BDOS+7
  317.  
  318. instfl:
  319.     defb    0        ; Program-installed flag (0 as assembled)
  320.  
  321. biostbl:
  322.     defs    3 * entries    ; Virgin BIOS table
  323.  
  324.     defb    0        ; Byte to force saving buffers in COM file
  325.  
  326.     end
  327.  assembled)
  328.  
  329. biostbl:
  330.     defs    3 * entries    ; Virg