; TotalReset v1.1 : Empty chip-ram and flash until user reset
; by Kyzer/CSG
; $VER: TotalReset.asm 1.1 (08.04.98)
;
	incdir	include:
	include	lvo/exec_lib.i
	include	exec/execbase.i
	include	hardware/custom.i
_custom=$dff000
ROMEND=$1000000
SIZEOFFSET=-$14

	move.l	4.w,a6
	move.l	MaxLocMem(a6),d7
	lea	go(pc),a5
	jsr	_LVODisable(a6)
	jsr	_LVOSupervisor(a6)

go	move.w	#$7fff,d0
	lea	_custom+dmacon,a5
	move.w	d0,(a6)
	move.w	d0,intena-dmacon(a5)
	move.w	d0,intreq-dmacon(a5)

	suba.l	a0,a0
	lea	.codestart(pc),a2

.codestart

.clear	cmp.l	a2,a0
	bne.s	.notus
	adda.w	#.codeend-.codestart,a0
.notus	clr.l	(a0)+
	cmp.l	d7,a0
	blt.s	.clear

	; 'backwards compatibility' reset routine, ie we shouldn't really
	; rely on it, but we do. Oh dear.

	lea	ROMEND,a0		; end of ROM
	sub.l	SIZEOFFSET(a0),a0	; (end of ROM)-(ROM size)=ROM start
	move.l	4(a0),a0		; Get initial PC
	subq.l	#2,a0			; now points to second RESET
	cnop	0,4
	reset				;\_ these two instructions must
	jmp	(a0)			;/  share a longword.

.codeend
