	incdir "ram:include/"
	include exec_lib.i
	include dos_lib.i

CALLLIB	MACRO
	jsr _LVO\1(a6)
	ENDM

_LVOColdReboot = -$2d6

START
	movea.l	4.w,a6			;a6: ExecBase

	move.b (a0),d0
	cmpi.b	#'?',d0			;'?' als Parameter?
	beq.s	reset_usage
	bclr	#5,d0			;'w' oder 'W' als Parameter?
	cmpi.b	#'W',d0
	beq.s	reset_wait

	CALLLIB Disable			;stop the system
	move.l	a6,$26(a6)		;ChkBase zerstören => Kaltstart

	moveq	#36,d0
	cmp.w	20(a6),d0		;bei OS >= 2.0 Kickstart-Routine
	bhs.s	.oldkick		;verwenden
	CALLLIB ColdReboot		;führt Reset aus (Warmstart)

.oldkick
	CALLLIB SuperState
	lea	$fc0002,a0		;Adresse Reset-Routine
	reset				;Peripherie-Reset
	jmp	(a0)			;Reset


reset_wait:
	move.l	a6,$26(a6)		;ChkBase zerstören
	moveq	#0,d0			;Ende
	rts

reset_usage:
	lea	DOSName(pc),a1		;DOS-Lib öffnen
	moveq	#0,d0
	CALLLIB OpenLibrary
	tst.l	d0
	beq.s	ende

	movea.l	d0,a6			;Ausgabe ermitteln
	CALLLIB Output
	move.l	d0,d1
	move.l	#text,d2		;Text ausgeben
	move.l	#textlen,d3
	CALLLIB Write

	movea.l	a6,a1			;DOS-Lib schließen
	CALLEXEC CloseLibrary
ende:
	moveq	#0,d0
	rts

;*** Daten ***

DOSName: dc.b "dos.library",0

;für DOS-Befehl Version
	dc.b 0,"$VER: Reset 1.2 (30.7.92  © Thies Wellpott)",0
text:	dc.b "Usage:",$a
	dc.b "  Reset w   next reset (e. g. CTRL-A-A) is a cold reset",$a
	dc.b "  Reset     confirm cold reset",$a
textlen = *-text
	even

