;/* Title	: Initialization routines */
;/* Author	: Jan Skalicky, 2005 */


/* stack init (use for reinitialization only) */
init_stack:
	push	r20

	ldi		r20, high(RAMEND)
	out		sph, r20
	ldi		r20, low(RAMEND)
	out		spl, r20
	
	pop		r20
	ret

/* timer/counter 2 init */
init_tim2:
	push	r16

	cli
	ldi		r16, 0b00001000
	sts		ASSR, r16
	ldi		r16, 0b00000001
	sts		TIMSK2, r16
	ldi		r16, 0b00000011
	sts		TCCR2A, r16
	sei

	pop		r16
	ret

/* joystick buttons init */
init_joy:
	push	r16
	push	r17

	in		r17, DDRE
	andi	r17, 0b11110011
	in		r16, PORTE
	ori		r16, 0b00001100
	out		DDRE, r17
	out		PORTE, r16
	ldi		r16, 0b00000000
	sts		DIDR1, r16
	in		r17, DDRB
	andi	r17, 0b00101111
	in		r16, PORTB
	ori		r16, 0b11010000
	out		DDRB, r17
	out		PORTB, r16

	pop		r17
	pop		r16
	ret