home *** CD-ROM | disk | FTP | other *** search
- ; Program: CLRRSX
- ; Author: Jay Sage
- ; Date: July 20, 1986
- ;
- ; This program is used to remove any installed RSX (resident system extension)
- ; modules that are present.
- ;
- ; An RSX is deemed to be present if the warmboot vector at 0001h does not
- ; point to an address ending in 03, or the BDOS vector at 0006h does not point
- ; to an address ending in 06, or the BIOS and BDOS pages do not differ by 0EH.
- ; (see Version 1.1 notes for additional RSX conditions now detected - [bm])
- ;
- ; This program installs itself automatically the first time it is run on the
- ; system with no RSX present by copying the virgin BIOS jump vectors into a
- ; buffer at the end of the program. (As of version 1.1, the program also
- ; saves the original BDOS+6 entry point and the jump address to which it
- ; branches. This is what some above-the-BIOS system extensions use to
- ; divert BDOS calls since they do not have to protect the CCP. - [bm])
- ;
- ; Subsequently, if it is called with an RSX present, it restores the BIOS jump
- ; table (Version 1.1 restores jump address at BDOS+7 - [bm]) and warm boots.
- ;
- ; When it is called with an RSX present and it has not been installed, then an
- ; error message is given. Similarly, an error message is given when it has
- ; been installed already but is called when no RSX is present.
- ;
- ; Note that the file name in the FCB at the beginning of the code must be the
- ; actual name of the program in order to carry out the installation. Once the
- ; program has been installed, however, it can be renamed.
-
- ; Version 1.1: CLRRSX now has two additional capabilities, it now checks for
- ; alteration of the jump table as an RSX condition, except when
- ; being installed, in which case it would have no reference to
- ; check from. It also restores the original initial BDOS jump
- ; address at BDOS+7. These two additions make CLRRSX useful
- ; for detaching BDOS/BIOS-diverting code that does not alter
- ; page 0, such as Plu*Perfect DateStamper when relocated above
- ; the BIOS. This makes it possible, for example, to load
- ; DateStamper into the IOP buffer at IOP plus an offset for
- ; the dummy IOP code, detach it at will with CLRRSX, and
- ; reload it afterwards (INIT.IOP would have to be LDRed into
- ; place before reloading DateStamper if an active IOP is in
- ; the buffer - or patch the DS loader to patch in a dummy
- ; IOP segment before loading the actual DS code).
- ; 7/22/86 - Bruce Morgen
-
- entries equ 17 ; BIOS table entries that need restoring
-
- bdos equ 0005h ; BDOS entry point
-
- printf equ 09h ; BDOS functions
- setdma equ 1ah
- rread equ 21h
- rwrite equ 22h
- open equ 0fh
-
- cr equ 13
- lf equ 10
-
- ;------------------------------
-
- org 100h ; Start of program
-
- jp start
-
- ;------------------------------
-
- progfcb: ; FCB for program
-
- defb 0 ; Drive
- ;12345678
- defb 'CLRRSX ' ; Name (exactly 8 characters)
- ;123
- defb 'COM' ; Type (exactly 3 characters)
- defs 21 ; Space for rest of main FCB
- recaddr:
- defs 3 ; Space for random record address
-
- ;------------------------------
-
- start: ; Check first to see if already installed
-
- ld a,(instfl) ; Check the install flag
- or a
- jr z,notinst ; Branch if not installed
-
- ; See if RSX is there to clear
-
- call chkrsx
- insret: ld de,norestmsg
- jr z,print ; Branch if restore not needed
-
- ;------------------------------
-
- ; Perform restore operation to clear RSX
-
- ld hl,(biosaddr) ; Get real BIOS address
- ld de,biostbl ; Point to virgin BIOS table
- ex de,hl ; Source address in hl
- ld bc,3*entries ; Bytes to copy
- ldir ; Copy whole table
- ld de,(bdosentr) ; Get BDOS entry point
- inc de ; Bump to JP dest. address position
- ld hl,bdosjmp ; Point to our authentic address
- ldi ; Move and bump
- ldi ; Once more
- ld de,restmsg ; Inform user
- call print
- jp biostbl+3 ; Warm boot (restores page 0 vectors)
-
- ;------------------------------
-
- notinst: ; Program needs to be installed
-
- call chkrsx ; See if RSX present
- ld de,cannotmsg
- jr nz,print ; If so, branch to error message
-
- jp install
-
- ;------------------------------
-
- cannot: ; Cannot install when RSX is present
- ld de,cannotmsg
- jr print
-
- ;------------------------------
-
- openerr:
- ld de,openerrmsg
- jr print
-
- ;------------------------------
-
- filerr:
- ld de,filerrmsg
- jr print
-
- ;---------------------------------------------------------------------------
-
- ; SUBROUTINES
-
- print:
- ld c,printf ; BDOS print string function
- jp bdos
-
- ;------------------------------
-
- install: ; Install program
-
- call initfcb ; Initialize FCB
- ld de,progfcb ; Open file
- ld c,open
- call bdos
- inc a ; Check for success
- ld de,openerrmsg
- jr z,print ; If not, report error and quit
-
- ld de,80h ; Make sure dma address is right
- ld c,setdma
- call bdos
-
- ; Read the random record
-
- call setrand ; Set random record address
- ld de,progfcb ; Read the sector
- ld c,rread
- call bdos
- or a ; Make sure no error
- jr nz,filerr
-
- ; Update record contents
-
- ld hl,(0001) ; Get BIOS page address
- ld l,0
- ld (80h),hl
- ex de,hl ; Save in DE
- ld hl,(0006) ; Get BDOS entry point
- ld (80h+[bdosentr-buffer]),hl ; Save in buffer
- inc hl ; Point at JP dest. address
- ld a,(hl) ; Read it out into HL
- inc hl
- ld h,(hl)
- ld l,a
- ld (80h+[bdosjmp-buffer]),hl ; And store it
- ld hl,80h+[instfl-buffer] ; Set HL as buffer pointer
- dec (hl) ; Set installed-flag
- inc hl ; Point to beginning of vector table
- ex de,hl ; Destination in DE, source in HL
- ld bc,3*entries ; Bytes to copy
- ldir
-
- ; Write sector back
-
- ld de,progfcb
- ld c,rwrite
- call bdos
- or a ; Make sure no file error
- ld de,filerrmsg
- jr nz,print
-
- ld de,instalmsg ; Inform user and quit
- jr print
-
- ;------------------------------
-
- chkrsx: ; See if RSX already present; if so, return non-zero
-
- ld hl,(0006h) ; Get BDOS vector
- ld a,l ; Make sure low part is 06
- cp 6
- ret nz ; RSX must be present
- ex de,hl
- ld hl,(0001h) ; Get BIOS warmboot vector
- ld a,(instfl) ; CLRRSX installed?
- or a
- jr z,noinst ; If not, no table compare
- push hl ; Save warm boot vector
- push de ; and BDOS entry on stack
- dec hl ; Decrement
- dec hl ; to BIOS table
- dec hl ; start.
- ld de,biostbl ; Point to virgin table
- ld b,entries*3 ; Length in B for counter
- tbloop: ld a,(de) ; Virgin byte in A
- cp (hl) ; Compare to BIOS
- jp nz,insret ; If different, there's an RSX
- inc de ; Bump pointers
- inc hl
- djnz tbloop ; Count down
- pop de ; Restore BDOS
- pop hl ; and BIOS vector dests.
- noinst: ld a,l ; Make sure low part of BIOS dest.is 03
- cp 3
- ret nz ; If not, RSX must be present
- ld a,h ; Get BIOS page
- sub d ; Subtract BDOS page
- cp 0eh ; Zero if no RSX
- ret ; Otherwise return NZ
-
- ;------------------------------
-
- initfcb:
- ld hl,progfcb+12 ; Point to part of FCB to zero out
- ld b,21h-0ch ; Bytes to zero
- xor a ; Zero A
- initfcb1:
- ld (hl),a
- inc hl
- djnz initfcb1
- ret
-
- ;------------------------------
-
- setrand: ; Set random record value
-
- ld hl,[buffer-100h]/80h ; Random record number for buffer
- ld (recaddr),hl ; Store in FCB
- ret
-
- ;---------------------------------------------------------------------------
-
- ; MESSAGE TEXT
-
- cannotmsg:
- defb cr,lf
- defb 'RSX present; cannot install program.'
- defb cr,lf
- defb '$'
-
- openerrmsg:
- defb cr,lf
- defb 'Cannot install program; not found in current directory.'
- defb cr,lf
- defb '$'
-
- norestmsg:
- defb cr,lf
- defb 'No RSX present; no need to clear.'
- defb cr,lf
- defb '$'
-
- restmsg:
- defb cr,lf
- defb 'RSX cleared from system.'
- defb cr,lf
- defb '$'
-
- instalmsg:
- defb cr,lf
- defb 'Program installed with BIOS data.'
- defb cr,lf
- defb '$'
-
- filerrmsg:
- defb cr,lf
- defb 'Error reading or writing file.'
- defb cr,lf
- defb '$'
-
- ;---------------------------------------------------------------------------
-
- ; BUFFERS to hold intall flag and virgin BIOS jump table
-
- org [ $ + 7fh ] and 0ff80h ; Get record boundary
-
- buffer:
-
- biosaddr:
- defs 2 ; Address of real BIOS
-
- bdosentr:
- defs 2 ; Address of real BDOS entry
-
- bdosjmp:
- defs 2 ; JP dest. address for BDOS+7
-
- instfl:
- defb 0 ; Program-installed flag (0 as assembled)
-
- biostbl:
- defs 3 * entries ; Virgin BIOS table
-
- defb 0 ; Byte to force saving buffers in COM file
-
- end
- assembled)
-
- biostbl:
- defs 3 * entries ; Virg