;Protector v4.0 (c) RAF 1990
;Written by Rafal Wiosna on 1990.12.18
;Especially 4 News Flash
;Based on the green bootblock by unknown...
;
;This bootblock will check if something was changed in:
;	-CoolCapture
;	-ColdCapture
;	-WarmCapture (for no reason)
;	-KickTagPtr
;	-Interrupts (should point to ROM on reset)
;
;It will also check if you're in ntsc mode on pal Amiga or iversely
;(not checked for ntsc!!!)
;
;Do the following (for those who don't know how to...):
;1 Load MasterSeka >= 1.53 (I hear an army of DevPac users crying...)
;2.Type:
;	CHIP, PUBLIC OR ABS-MEM>c
;	WORKSPACE (max. 447)>100
;	SEKA>r
;	FILENAME>protector.s	;decrunch this file firstly!!!
;				;kill the marked line!!!
;	SEKA>a
;	OPTIONS> (just RETURN)
;	No Errors
;	SEKA>b start
;	205C892E (Old was 00000000)
;3.Insert your WorkBench and make it write enable.
;4.Type.
;	SEKA>ws
;	BEG>start
;	SECTOR>0
;	AMOUNT>2
;5.Copy the bootblock to any 'dos' disk (with CLI window visible)
;6.Send me 100 pounds...
;
;Or if you wanna a file version of this protector (for a harddisk for example)
;do the following:
;1.-3. as written
;4.	SEKA>wo
;	FILENAME>dh0:c/protector
;5.Insert command protector in your startup-sequence.
;6.Send me 150 pounds...


;The main program starts here

;****EXEC OFFSETS***
OldOpenLibrary	equ	-408
DisplayAlert	equ	-90
CloseLibrary	equ	-414
FindResident	equ	-96
ExecBase	equ	4

	bra.s	run	;kill this line if you want a bootblock version 

Start:
	dc.b	'DOS',0
	dc.l	0
	dc.l	880

Run:
	move.l	ExecBase.w,a6
	bsr.s	Check
	bset	#1,$bfe001		;kill the filters
	lea	DosName(pc),a1		;usual bootblock starts here
	jsr	FindResident(a6)
	tst.l	d0
	beq.s	BError			;no dos.library (!!!)
	move.l	d0,a0
	move.l	$16(a0),a0
	moveq.l	#0,d0
	rts

BError:
	move.l	#-1,d0			;I'm ill...
	rts	

Check:
	movem.l	d0-d7/a0-a6,-(sp)
	tst.l	$2a(a6)	;ColdCapture
	bne.s	Virus
	tst.l	$2e(a6)	;CoolCapture
	bne.s	Virus
	tst.l	$32(a6)	;WarmCapture
	bne.s	Virus
	tst.l	$226(a6);KickTagPtr
	bne.s	Virus
	move.w	#$079,d7		;if everything's ok change the color
	bra.L	CheckInts
Dalej:
	bsr.s	CheckNTSC
NoReset:
	cmp.b	#$80,$dff006
	bne.s	NoReset			;wait to line $80 to get color all
	move.w	d7,$dff180		;the time you insert disk
	movem.l	(sp)+,d0-d7/a0-a6
	rts

Virus:
	lea	IntuitionName(pc),a1
	jsr	OldOpenLibrary(a6)
	move.l	d0,a6
	moveq	#0,d0
	moveq	#38,d1
	lea	VirusMessage(pc),a0	;we have something inside system
	jsr	DisplayAlert(a6)
	tst.l	d0			;LMB pressed?
	bne.s	HardReset
	move.l	a6,a1
	move.l	ExecBase.w,a6
	jsr	CloseLibrary(a6)
	move.w	#$f00,d7		;red screen means something strange
	bra.s	Dalej			;is in memory

HardReset:
	clr.l	ExecBase.w		;kill the execbase to do a hard-reset
SoftReset:
	lea	Reset(pc),a0		;the only reset routine
	move.l	a0,$80.w		;it calls the autoboot
	trap	#0			;rom of A590 harddisk
Reset:
	lea	2,a0			;unlike the other (a bad ones)
	reset				;do
	jmp	(a0)			;this will be executed!!!

CheckNTSC:
	move.b	$212(a6),d0		;power supply frequency
	cmp.b	$213(a6),d0		;vertical blanking frequency
	beq.s	NoNTSC			;or NoPAL on ntsc machines
	lea	PalText(pc),a0
	lea	FreqText(pc),a1
	moveq	#3,d6
	cmp.b	#50,$213(a6)		;check if ntsc amiga in pal
	beq.s	PalAmiga		;(i think this will never happen)
	lea	NTSCText(pc),a0
PalAmiga:
	move.b	(a0)+,(a1)+
	dbra	d6,PalAmiga
	lea	IntuitionName(pc),a1
	jsr	OldOpenLibrary(a6)
	move.l	d0,a6
	moveq	#0,d0
	moveq	#38,d1
	lea	NTSCMessage(pc),a0	;display message with NTSC or PAL
	jsr	DisplayAlert(a6)
	tst.l	d0
	bne.s	SoftReset
	move.l	a6,a1
	move.l	ExecBase.w,a6
	jsr	CloseLibrary(a6)
NoNTSC:
	rts

CheckInts:
	lea	8,a0			;this routine will check interrupts
	moveq.l	#$1f,d0			;when you're using a file version
IntCheck:
	cmp.l	#$00f80000,(a0)+	;you must know that some programs
	bcs.L	Virus			;use interrupts for their stuff so
	dbra	d0,IntCheck		;protector will report a virus
	bra.L	Dalej

DosName:
	dc.b	'dos.library',0
	even

IntuitionName:
	dc.b	'intuition.library',0
	even

VirusMessage:
	dc.b	0,64,11
	dc.b	"Warning !!! - Suspicious program found in memory !!!"
	dc.b	0,1
	dc.b	0,100,21
	dc.b	"This could be a Virus !!!  Shall I remove it ?"
	dc.b	0,1
	dc.b	0,20,31
	dc.b	"LEFT = Do it now!"
	dc.b	0,1
	dc.b	1,142,31
	dc.b	"RIGHT = I like viruses!"
	dc.b	0,0
	even

NTSCMessage:
	dc.b	0,126,11
	dc.b	"Warning !!! - Amiga is not in "
FreqText:
	dc.b	"xxxx!!!"
	dc.b	0,1
	dc.b	0,120,21
	dc.b	"Shall I do a soft reset to change it ?"
	dc.b	0,1
	dc.b	0,20,31
	dc.b	"LEFT = Do it now!"
	dc.b	0,1
	dc.b	1,150,31
	dc.b	"RIGHT = No need to..."
	dc.b	0,0
	even

PalText:
	dc.b	"PAL "

NTSCText:
	dc.b	"NTSC"

dc.b "Protector, Led, Screentest v4.0 (c) by RAFal Wiosna epecially 4"
dc.b " News Flash."
	even
Rest:
	blk.l	[Start+$400-Rest]/4,"RAF!"	;fill the rest of bootblock

