; **************************************************************************
; *                                                                        *
; * NTSC switch                                 use DevPac 2.xx            *
; * -----------                                                            *
; * Program by WPJ, helped by WHIPLASH!                                    *
; *                                                                        *
; **************************************************************************
;
; Usage: NTSC             - Resets and switches your amiga to ntsc format
;    or  NTSC n           - also switches your Fast-Mem off.
;
;  This program switches your Amiga (if fitted with a new fat agnus) to   
;  ntsc mode and resets, so you can boot a ntsc program and see it on     
;  your screen without a beatiful black bar at the bottom of your screen. 
;  On most monitors and televisions the screen gets bigger, but on the    
;  new 1084S monitor the screensize will stay the same, but your screen   
;  will be moved down some lines.                                         
;
;  Hints for using this program:
;  -----------------------------
;  If you use it often, please remember the programmer and send him a
;  donation.
;  It is also useful to put this program in a bootblock if you use it 
;  often.
;                                                       WPJ                   
;                                                       Sandenburg 108        
;                                                       1965 NM  Heemskerk    
;                                                       Holland               
;                                                       (0)2510-47830         
;


	include	'include/exec/exec_lib.i'

Start:
	move.l	d0,no_of_parameters		; Save # of parameters
	move.l	#end-ntsc,d0
	moveq	#2,d1				; Search for space in Chipmem

	CALLEXEC	AllocMem

	tst.l	d0				; No space left ?
	beq.s	.error				; Then leave the program

	move.l	d0,a1
	move.l	a1,42(a6)			; Mem pointer in ColdCapture 

	move.l	#end-ntsc,d0
	lea	ntsc,a0
.copy	move.b	(a0)+,(a1)+			; Copy the ntsc program
	dbf	d0,.copy

	moveq	#0,d1
	lea	34(a6),a0			; Start at the SoftVector
	moveq	#$16,d0
.chksum	add.w	(a0)+,d1			; Calculate checksum
	dbf	d0,.chksum

	not.w	d1
	move.w	d1,82(a6)			; Place checksum

; ********************
; * Reset your amiga *
; ********************

	CALLEXEC	SuperState		; To superstate
	move.l	$fc0004,a1			; Get Resetadress

	cmpi.l	#2,no_of_parameters		; is there a parameter ?
	beq.s	.skip				; yes ? turn off fast mem
	
	reset					; Clear in/outputs
						; (If you remove this command
						;  then your fastmem will be
						;  turned off.)
.skip	jmp	(a1)				; Reset

.error	moveq	#103,d0				; Out of memory error
	rts					; Leave program

; **************************
; * Switch to ntsc program *
; **************************

ntsc:
	move.w	#0,$dff1dc		        ; Switch to ntsc (#32 = pal)
	jmp	(a5)				; Jump back
end:	

; *******************
; * Additional data *
; *******************

no_of_parameters	dc.l	0		; # of parameters


