;AddReset By Niklas Sjöberg

		incdir	/include/
		include	exec/execbase.i
		include	exec/exec_lib.i
		include exec/memory.i
		include	"libraries/dos_lib.i"
		include "libraries/dos.i"
		
Print		MACRO
		lea	\1(PC),a1
		lea	\1_end(PC),a2
		suba.l	a1,a2
		move.l	a1,d2			;buf
		move.l	a2,d3			;len
		CALLDOS	Output
		move.l	d0,d1
		CALLDOS	Write
		ENDM

		lea	Dosname(PC),a1
		moveq	#0,d0
		CALLEXEC OpenLibrary
		tst.l	d0
		beq	error
		move.l	d0,_DOSBase
		
		move.l	#end-start,d0
		move.l	#MEMF_CHIP,d1	;If PUBLIC it won't work
		CALLEXEC AllocMem	;
		tst.l	d0		;No mem
		beq	error_res
		move.l	d0,a1
		move.l	a1,ColdCapture(a6) ;Patch us in reset
		move.w	#end-start,d0	;Len of our routine
		lea	start,a0
l1		move.b	(a0)+,(a1)+	;Copy to reserved mem
		dbf	d0,l1
		
		moveq	#0,d1
		lea.l	SoftVer(a6),a0	;Get base for chksum
		move.w	#$16,d0
l2		add.w	(a0)+,d1	;Calc ShkSum
		dbf	d0,l2
		not.w	d1
		move.w	d1,ChkSum(a6)	
		Print	res
error		moveq	#0,d0
		rts		

error_res	Print	no_res
		rts
		
start
		move.w	#$ffff,d0
fladder
		move.w	#$00f,$dff180
		move.w	#$fff,$dff180
		move.w	#$f00,$dff180
		sub.l	#1,d0
		beq	ut
		jmp	fladder(PC)
ut		move.w	#0,$b00000
		jmp	(a5)		;Continue with reset from
					;the place we jumped in.
end

_DOSBase
Dosname		DOSNAME

no_res		dc.b	'Unable to install myself! Read the docs!',10,13
		dc.b	'(Are you out of CHIP-mem?)',10,13
		
no_res_end

res		dc.b	'Installed OK.',10,13
		dc.b	'AdSpeed will now boot in 14MHz after reset.',10,13
res_end

