
	OPT	O+

*
* TestPAL - a proggy that checks if your Amiga recognised its PAL option...
*
* This thingy is FULLY Public Domain.
* Hack it, slash it, trash it, do whatever. I don't care...
*
* Comments ? Pizza ? Girls ? (only dark haired)
* Send it all to
*
*  Peter Fröhlich
*  Ebenböckstr. 19
*  D-8000 München 60
*

*
* Created 03-May-90 P.Fröhlich
*  I just saw another TestPAL and thought that it should work shorter...
*  It does...
*
* Edited 05-Jun-90 P.Fröhlich
*  Error 20 is too high, let's return 5 for better use in startup-sequence.
*
* Edited xx-xxx-90 P.Fröhlich
*  Inserted official reset-code from the RKM Companion disks.
*
* Edited 03-Mar-91 P.Fröhlich
*  Reassembling my newer version after source code crashed.
*  Included ColdReboot.asm in the archive.
*  First official release via Z-NET.
*

	INCDIR	"INC:"
	INCLUDE	"misc/lib.i"	* defines all library symbols
	INCLUDE	"exec/execbase.i"
	INCLUDE	"exec/libraries.i"

ABSEXECBASE	EQU 4		;Pointer to the Exec library base
MAGIC_ROMEND	EQU $01000000	;End of Kickstart ROM
MAGIC_SIZEOFFSET	EQU -$14		;Offset from end of ROM to Kickstart size
V36_EXEC		EQU 36		;Exec with the ColdReboot() function
TEMP_ColdReboot	EQU -726		;Offset of the V36 ColdReboot function

_main:
	moveq	#0,d0			* clear libversion and returncode
	move.l	(ABSEXECBASE).w,a6		* get execbase
	cmp.b	#50,VBlankFrequency(a6)	* are we PAL ?
	beq.s	PAL			* yes ->

	lea	_DosName(PC),a1
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,a6			* get _DosBase
	jsr	_LVOOutput(a6)
	move.l	d0,d1
	lea	TXT_Message(PC),a0
	move.l	a0,d2
	moveq.l	#LEN_Message,d3
	jsr	_LVOWrite(a6)		* write a msg
	moveq	#100,d1
	jsr	_LVODelay(a6)		* wait 2 seconds


_ColdReboot:	move.l	(ABSEXECBASE).w,a6
		cmp.w	#V36_EXEC,LIB_VERSION(a6)
		blt.s	old_exec
		jmp	TEMP_ColdReboot(a6)     ;Let Exec do it...
		;NOTE: Control flow never returns to here

;---- manually reset the Amiga ---------------------------------------------
old_exec:	lea.l	GoAway(pc),a5           ;address of code to execute
		jsr	_LVOSupervisor(a6)      ;trap to code at (a5)...
		;NOTE: Control flow never returns to here

;-------------- MagicResetCode ---------DO NOT CHANGE-----------------------
		CNOP	0,4			;IMPORTANT! Longword align!
GoAway:		lea.l	MAGIC_ROMEND,a0 	;(end of ROM)
		sub.l	MAGIC_SIZEOFFSET(a0),a0 ;(end of ROM)-(ROM size)=PC
		move.l	4(a0),a0                ;Get Initial Program Counter
		subq.l	#2,a0			;now points to second RESET
		reset				;first RESET instruction
		jmp	(a0)                    ;CPU Prefetch executes this
		;NOTE: the RESET and JMP instructions must share a longword!
;---------------------------------------DO NOT CHANGE-----------------------

PAL:
	rts

TXT_Message:
	dc.b	$9b,"33;1m"
	dc.b	"Boot Error:"
	dc.b	$9b,"m"
	dc.b	" NTSC mode active. Rebooting.",10,0
LEN_Message	equ	*-TXT_Message

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

	END

