;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	VirusX Virus Removal Code
;
;	(which makes a lot more sense in ASM than as a page full
;	of bizarre typecasts in C).
;
;	All of these routines return 0 if nothing was found,
;	or Nonzero if a Virus of some sort was found (and removed).
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Public Symbols
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	XDEF	_BW_Handler		; Remove Byte Warrior
	XDEF	_LamerHandler		; Remove the Lamer Exterminator
	XDEF	_Lamer2Handler		; Remove the Lamer2 Exterminator
	XDEF	_Revenge_Handler	; Remove the Revenge Virus
	XDEF	_DiskDoktor_Handler	; Remove guess who.
	XDEF	_CheckRAMForIRQ		; Check/Remove the IRQ Virus
	XDEF	_MicroSystems_Handler	; Remove the MS Virus
	XDEF	_VKill_Handler		; Remove the VKill Virus

	XREF	_TD 			; Trackdisk Vector
	
_LVODisable	EQU	-$78
_LVOForbid	EQU	-$84
_LVOEnable	EQU	-$7E
_LVOPermit	EQU	-$8A

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	BW_Handler
;
;	Check a fixed address against 0x444f5301, and just change
;	some fixed stuff if it's found.
;
;	The Byte warrior hangs around via CoolCapture, which is taken
;	care of back in that C mess.
;
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

_BW_Handler
	lea	$7f800,a0
	cmp.l	#$444f5300,(a0)		; Check $7f800 for DOS\0
	bne.s	NoVirusFound

	lea	$7f954,a0
	cmp.w	#$4afc,(a0)		; And 7f954 for ILLEGAL
	bne.s	NoVirusFound

	move.l	$4,a6
	jsr	_LVOForbid(a6)		; No task switching while we fix

	lea	$7f972,a0
	move.w	#$4ef9,(a0)+
	move.w	#$00fc,(a0)+
	move.w	#$06dc,(a0)

	move.l	#0,$7f800		; Clear DOS signature

	jsr	_LVOPermit(a6)
	bra	VirusFound

NoVirusFound
	clr.l	d0
	rts

VirusFound
	moveq	#1,D0
	rts




;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	LamerHandler
;
;	Look at an indirect from an offset from the Trackdisk
;	vector for a signature of ID_DOS_DISK (eeek!), and if so,
;	clean things up.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

HLReg	Reg	A2-A3/A6

_LamerHandler
	movem.l	HLReg,-(a7)
	
	move.l	4,a6

	move.l	_TD,a0
	sub.w	#$1c,a0
	move.l	(a0),a1
	sub.w	#$17c,a1	; Now A0 is TDm1C and A1 is it LamerBase

	cmp.l	#$444f5300,(a1)
	beq.s	.Got

	movem.l	(a7)+,HLReg	; No got
	bra	NoVirusFound
 
; Now we know it's there.
	
.Got
	clr.l	d0
	move.l	d0,(a1)		; Kill Signature

	jsr	_LVOForbid(a6)

	move.l	a1,a2
	add.w	#$3a8,a2	; a2 = virus[3a8]
	move.l	a6,a3
	sub.w	#$262,a3
	move.l	(a2),(a3)	; Change ExecBase vector thing

	move.l	a1,a2
	add.w	#$3ac,a2
	move.l	(a2),(a0)

	jsr	_LVOPermit(a6)

	move.l	#0,$226(a6)	; Clear KickTagPtr

	movem.l	(a7)+,HLReg

	bra	VirusFound


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Lamer2Handler
;
;	Look at an indirect from an offset from the Trackdisk
;	vector for a signature of ID_DOS_DISK (eeek!), and if so,
;	clean things up.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

HL2Reg	Reg	A2-A3/A6

_Lamer2Handler
	movem.l	HL2Reg,-(a7)
	
	move.l	4,a6

	move.l	_TD,a0
	sub.w	#$1c,a0
	move.l	(a0),a1
	sub.w	#$184,a1	; Now A0 is TDm1C and A1 is it LamerBase

	cmp.l	#$444f5300,(a1)
	beq.s	.Got

	movem.l	(a7)+,HL2Reg	; No got
	bra	NoVirusFound
 
; Now we know it's there.
	
.Got
	clr.l	d0
	move.l	d0,(a1)		; Kill Signature

	jsr	_LVOForbid(a6)

	clr.l	-$262(a6)

	move.l	a1,a2
	add.w	#$39c,a2
	move.l	(a2),(a0)

	clr.l	$226(a6)	; Clear KickTagPtr

	jsr	_LVOPermit(a6)

	movem.l	(a7)+,HL2Reg

	bra	VirusFound


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Revenge_Handler -
;	
;	Check for, and remove, the Revenge Virus.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_Revenge_Handler:
	movem.l	a2/a6,-(a7)
	
	move.l	4,a6
	move.l	a6,a0
	sub.w	#$1c6,a0
	move.l	(a0),d0
	cmp.l	#$100,d0
	blt.s	.Found
	
	movem.l	(a7)+,a2/a6
	bra	NoVirusFound

.Found	jsr	_LVODisable(a6)
	
	clr.l	$2e(a6)			; Kill CoolCapsher

	move.l	$D2,A1
	move.l	a1,(a0)		; Fix DoIO

	move.w	#$4e71,$E0

	jsr	_LVOEnable(a6)

	movem.l	(a7)+,a2/a6
	bra	VirusFound

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Remove the Disk Doctor.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_DiskDoktor_Handler
	move.l	a6,-(a7)
	
	move.l	4,a6
	move.l	-$1c6(a6),a0

	cmp.w	#$4eb9,(a0)
	bne.s	.NotFound

	cmp.w	#$48e7,6(a0)
	beq.s	.Found

.NotFound
	move.l	(a7)+,a6
	bra	NoVirusFound

.Found
	jsr	_LVOForbid(a6)

	move.l	a6,a0
	sub.w	#$1c6,a0		; A0 points to DoIO
	
	move.l	(a0),a1
	move.w	#$4e75,$15c(a1)
	
	move.w	#$4e75,$1e2(a1)

	move.l	(a0),a1
	move.l	2(a1),(a0)

	jsr	_LVOPermit(a6)
	
	move.l	(a7)+,a6
	bra	VirusFound


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	CheckRAMForIRQ - Check RAM for IRQ, return 1 if found
;	  and removed.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_CheckRAMForIRQ
	move.l	a6,-(a7)		; Save A6...
	move.l	$4,a6

	move.l	a6,a0
	sub.w	#$196,a0		; OldOpenLibrary
	move.l	(a0),a1
	cmp.l	#$2f3a0010,(a1)
	bne.s	.NotFound
	add.w	#$12,a1
	move.l	(a1),(a0)
	clr.l	$226(a6)		; Clear KickTagPtr
	clr.l	d0
	bra.s	.go
.NotFound
	clr.l	d0
.go	move.l	(a7)+,a6
	rts



;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Find/Remove the Microsystems virus.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_MicroSystems_Handler
	move.l	a6,-(a7)
	move.l	4,a6
	move.l	a6,a0
	sub.w	#$118,a0
	clr.l	d0
	cmp.l	#$7f520,(a0)
	bne.s	.Done
	lea	$7f536,a1		; Old AddTask
	move.l	(a1),(a0)
	clr.l	$2e(a6)			; Kill CoolCapsher
	moveq	#1,d0
.Done	move.l	(a7)+,a6
	rts


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;	Find/Remove the VKill virus.
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
_VKill_Handler
	movem.l	a6/a0/a1/d1,-(a7)
	
	clr.l	d0
	
	move.l	4,a6
	movea.l	$3a(a6),a1		; A1=SysStkLower
	
	cmp.l	#$612643FA,$c(a1)
	bne.s	.Done
	cmp.l	#$00184EAE,$10(a1)
	bne.s	.Done

	;:: Yes, we've found one.
	
	clr.l	$2e(a6)			; Clear CoolCapture
	
	sub.w	#$16c,a6		; Now A6 points at PutMsg Vector

	move.l	$11e(a1),(a6)		; Fix PutMsg

	moveq	#1,d0			; Set flag for requester

.Done	movem.l	(a7)+,a6/a0/a1/d1
	rts
