
	;stops 880 requesters on a A500. not needed in ks2+
	;by shagratt/LSD

	section	lard,code

code:	IncDir	"DH0:Include/"
	Include	Intuition/Intuition.I
	Include	Intuition/Intuition_Lib.I
	Include	Libraries/dos_LIb.i
	Include	Libraries/Dos.i
	Include	Exec/Exec_Lib.I
	Include	Exec/Exec.I
	Include	Misc/EasyStart.i

	move.l	4,a6
	move.l	20(a6),d0		; execbase verison
	cmp.l	#$00220002,d0	; check ks version
	bgt	.error		; coz ks2 does it anyway & sometimes it fucks up!

	Lea	DosName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l 	D0,_DOSBase
	Beq	.error

	lea	code(pc),a0
	move.l	-4(a0),d3
	move.l	d3,segaddress
	move.l	#0,-4(a0)
	
	move.l	_DOSBase,a6
	move.l	#myname,d1
	move.l	#0,d2
	move.l	#4000,d4
	jsr	-138(a6)			; create proc

.error	clr.l	d0	
	rts


	Section	Main,Code
Start:
	Lea	IntName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l	D0,_IntuitionBase
	Beq	Error

	Lea	MainWindow,a0
	CALLINT	OpenWindow
	Move.l	D0,_MyWinBase
	Beq	CloseInt
	Move.l	D0,A0
	Move.l	wd_RPort(A0),_MyWinRPort
	Move.l	wd_UserPort(a0),_MyWinUserPort

	******************* this is the no 880 patch *****************

	move.l	_intuitionbase,a1
	move.l	a1,a0

	lea	-346(a1),a0		; ks 1.2/1.3 offset (autorequest)
	cmp.w	#$4ef9,-588(a1)	; check if jump
	bne	ks210_noalert

	lea	-586(a1),a0		; ks 2.0 offset (autorequest)
	bra	ks13_noalert

ks210_noalert:
	cmp.w	#$4ef9,-594(a1)	; check if jump
	bne	ks13_noalert

	lea	-588(a1),a0		; ks 2.0 offset (autorequest)

ks13_noalert:
	move.l	a0,reqpos
	move.l	(a0),oldreq+2
	move.l	#do_alert,(a0)

WaitLoop
	Move.l	_MyWinUserPort,A0
	CALLEXEC	WaitPort
	Move.l	_MyWinUserPort,A0
	CALLEXEC	GetMsg
	Move.l	D0,A1
	Move.l	im_Class(A1),D2		;D2=IDCMP Flags Directly
	Move.w	im_Code(A1),D3		;D3=Data ie key why class=Rawkey
	Move.w	im_Qualifier(A1),D4		;D4=things like CTRL SHIFT
	Move.w	im_MouseX(a1),D5		;D5=MouseX Coordinate
	Move.w	im_MouseY(a1),D6		;D5=MouseY Coordinate
	Move.l	im_IAddress(A1),D7		;D7=Addres of Intuition Obj ie Gadget
	Movem.l	D0-D7/A0-A6,-(A7)	
	CALLEXEC	ReplyMsg
	Movem.l	(a7)+,D0-D7/A0-A6
	Cmp.l	#CLOSEWINDOW,D2
	Bne	WaitLoop

Exit
	Move.l	_MyWinBase,A0
	CALLINT	CloseWindow

CloseInt
	Move.l	_IntuitionBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary

	move.l	reqpos,a0
	move.l	oldreq+2,(a0)


	move.l	_DOSBASE,a6
	move.l	segaddress,d1
	jmp	-156(a6)			; unloadseg

Error	Moveq	#1,D0
	Rts

do_alert:	movem.l	d0-d7/a0-a6,-(a7)

	Move.l	_IntuitionBase,A0
	move.l	ib_ActiveWindow(a0),_activewindow
	move.l	ib_ActiveScreen(a0),_activescreen

	move.l	#0,lengths

	move.l	a1,a0
	
	move.l	12(a0),a1
	move.b	-1(a1),lengths+0

	move.l	16(a0),a0		; line 2
	cmp.l	#0,a0
	beq	req_err
	move.l	12(a0),a1
	move.b	-1(a1),lengths+1
	
	move.l	16(a0),a0		; line 3
	cmp.l	#0,a0
	beq	req_err
	move.l	12(a0),a1
	move.b	-1(a1),lengths+2

req_err:	movem.l	(a7)+,d0-d7/a0-a6

	cmp.l	#$16011700,lengths	; key 880 already set
	beq	req_no
	cmp.l	#$171d0000,lengths	; disk is corrupt, use diskdoctor
	beq	req_no
	cmp.l	#$0f0f0000,lengths	; not a dos disk in unit
	beq	req_no
	cmp.l	#$16011300,lengths	; disk is unreadable, use disk doctor
	beq	req_no

oldreq:	jsr	$12345678

	movem.l	d0-d7/a0-a6,-(a7)

	Move.l	_IntuitionBase,A1

	move.l	_activescreen,a0	; restore original screen
	CALLINT	ScreenToFront	; after alert - not necessary for Killing 880 reqs
		
	movem.l	(a7)+,d0-d7/a0-a6
	rts	

req_no:	clr.l	d0
	rts

reqpos:		dc.l	0

_IntuitionBase	Dc.l	0
_DOSBase		Dc.l	0
_GfxBase		Dc.l	0

_MyWinBase		Dc.l	0
_MyWinRPort		Dc.l	0
_MyWinUserPort	Dc.l	0
_MyWinVPort		Dc.l	0

_activewindow:	dc.l	0
_activescreen:	dc.l	0

segaddress		dc.l	0
lengths:		dc.l	0

IntName		INTNAME
DosName		DOSNAME

MainWindow:
	dc.w	100,0	
	dc.w	300,10
	dc.b	0,1	
	dc.l	CLOSEWINDOW+DISKINSERTED
	dc.l	NOCAREREFRESH+WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH
	dc.l	0	
	dc.l	0	
	dc.l	MainTitle	
	dc.l	0	
	dc.l	0	
	dc.w	5,5	
	dc.w	-1,-1	
	dc.w	WBENCHSCREEN	
MainTitle
	Dc.b	'No880 v1.0a by Shagratt/LSD',0
	Even

myname:	dc.b	"No880",0



