
*********************************************************************
**
** SASM SNES Include File 
** ~~~~~~~~~~~~~~~~~~~~~~
** Super NES ResetHandler V1.0 - 'Enables RESET SWITCH of SNES'
** 
** $: FWS - 09/03/93 - created this file!
**
** Thanks to Delphi, for debugging helps...
**
*********************************************************************

	IFD	RESETHANDLER_I
		WARN	Double Inclusion of RESETHANDLER.I
	ELSE

RESETHANDLER_I	set	1

	; first some info to the novice user that we may reduce
	; the default stacksize by one byte. anyway, code that
	; uses the stack nearly overflow'd won't run safe, so
	; i guess nothing serious will happen....

	WARN	ResetHandler uses lowest stack ($100) location !!
	.include	snes:include/vectors.i

	DBUG					;patch smc+ header

; Reset Handler Code [in EMU=6502 MODE!] © 1993 by FWS & Delphi
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

rh_IDBYTE	EQU	$100
rh_LOWRAM	EQU	$80

	lda	rh_IDBYTE			;first run?
	cmp	#"!"
	bne	.endresetroutine

;goto back to SUPERCOM PRO.2 SCREEN
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	ldx	#0				;no go back to supercom
.copy:	lda	.resetroutine,x
	sta	!(rh_LOWRAM),x			;THIS IS ABSOLUTE ADDRESSING :)
	inx
	cpx	#.endresetroutine-.resetroutine
	bne	.copy
	jmp	!rh_LOWRAM

; This piece of code to be copied down to RAM
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.resetroutine:
	lda	#0				;no 65816 cmds here!
	sta	rh_IDBYTE

	lda	#$ff
	sta	$e004				;tell magicom to disable ROM!
	jmp	(VEMU_RESET)
.endresetroutine:

	lda	#"!"				;start file first & save mode
	sta	rh_IDBYTE

	ENDC
