* UnConfig,	July 21, 1990,	  Ismo Suihko,	    Public Domain
*
* Makes all AUTOCONFIG (TM) devices to disappear on reboot.
* Idea from 1.3 Hardware Reference Manual p. 219 and DaveH (Thanks!).
* Allows you to reboot your Amiga without memory expansion and hard disk.
* This program works with 1.2 and 1.3 KS.
*
* If you have A2620/A2630, you can reboot your Amiga on 68000 mode and
* then with this program, you will get an unexpanded Amiga (so you can
* then run some badly written software).
*
* Ismo Suihko, Internet: isuihko@ujocs.joensuu.fi


* All needed constants are EQUed here, you don't need to link with amiga.lib
Supervisor	EQU	-30
Disable 	EQU	-120
CloseLibrary	EQU	-414
OpenLibrary	EQU	-552
Write		EQU	-48
Output		EQU	-60
Delay		EQU	-198
VBlankFrequency EQU	530
CIAB_GAMEPORT0	EQU	6
_ciaa		EQU	$bfe001

* a couple of seconds delay to allow possible disk drive to stop spinning
DELAY	     EQU  3

* open dos.library
	lea	dosname(pc),a1
	moveq	#0,d0
	move.l	4,a6
	jsr	OpenLibrary(a6)
	tst.l	d0
	beq.s	1$	    ; no dos.library?? reboot anyway...

* write something
	move.l	d0,a5
	exg	a5,a6
	jsr	Output(a6)
	move.l	d0,d7
	move.l	d0,d1
	lea	msg(pc),a0
	move.l	a0,d2
	move.l	#msglen,d3
	jsr	Write(a6)

* delay a DELAY seconds
	moveq	#0,d1
	move.b	VBlankFrequency(a5),d1      ; 50 or 60
	mulu	#DELAY,d1   ; put there a short delay, so that floppy disk
	jsr	Delay(a6)   ; drive has time to stop spinning

* check if user had changed his/her mind and is now holding left mousebutton
	btst	#CIAB_GAMEPORT0,_ciaa	; you can still change your mind...
	bne.s	1$

* this is executed only if shutdown was aborted
	move.l	d7,d1
	lea	abort(pc),a0
	move.l	a0,d2
	move.l	#abortlen,d3
	jsr	Write(a6)

* close dos.library and exit
	move.l	a6,a1
	exg	a5,a6
	jsr	CloseLibrary(a6)
	rts

* left mouse button wasn't down, so reboot now without 'reset'
1$
	move.l	4,a6
	jsr	Disable(a6)
	lea	MagicCode(pc),a5
	jsr	Supervisor(a6)

**************************************************************************
MagicCode			; this is executed at the Supervisor level
	move.l	$00fc0004,a0	; get starting location of the ROM
	jmp	(a0)            ; jump there without resetting first
**************************************************************************


dosname dc.b	'dos.library',0

msg	dc.b	'unConfig by Ismo Suihko, 21-Jul-90. Reboot without AUTOCONFIG(TM) devices.',10
	dc.b	'System is going down in ',DELAY+'0',' seconds...',10
	dc.b	'To abort shutdown hold (and keep) left mousebutton down.',10
msglen	EQU	*-msg

abort	dc.b	'*** Aborted',10
abortlen EQU	*-abort

	END

