//------------------------------------------------------------------------
//   FILE        : start.asm                
//   DESCRIPTION : start-up code            
//   CPU GROUP   : 33A(ROM32K)              
//------------------------------------------------------------------------



//------------------------------------------------------------------------

#define APP_VARIABLE_VECT_ADDRESS	0xf960
//------------------------------------------------------------------------


	//.text
// upraveno mapovani zavadece a inicializacnich rutin do sekce Bootloader
	.section	.start,"a"
	.global	_start
	.type	_start, @function

_start:
    ldc	#_istack, isp   // set interrupt stack pointer 
	mov.b	#0x02,0x0a	// write enable in protect regist  er 
	mov.b	#0x00,0x04	// set processer mode  :single chip mode 
						// 0x04 is the address of processor mode register 0 

	mov.b	#0x00,0x0a	// write disable in protect register 
	ldc	#0x0080,flg		// select USER STACK POINTER (BIT7=1,USP) (BIT7=0,ISP) 
	ldc	#_ustack,sp		// set user stack pointer 
	

//-----------------------------------------------------------------------------
// zmena start vektoru a tabulky variabilnich vektoru
	ldc 	#0x0, intbh	
	ldc 	#APP_VARIABLE_VECT_ADDRESS, intbl	
	
//-----------------------------------------------------------------------------
	
	// ADD THIS TO ENABLE INTERRUPTS 
	fset	I			
		
	// call the hardware initialiser 
	jsr.a	_hw_initialise	

	// load data section from ROM to RAM 
	mov.b	#0x00,R1H    	// load 00 in R1H 
	mov.w	#_mdata,a0   	// store the load address of data section in A0 
	mov.w	#_data,a1    	// store the start address of data section in, A1 
	mov.w	#_edata,r3   	// store the end address of data section in R3 
	sub.w	a1,r3	     	// R3=R3-A1 Store size of data section in R3 
	smovf.b		     


// bss initialisation : zero out bss 
	mov.b	#0x00,R0L       // load R0L reg with 0x0 (value at which bss section will be initialised) 
	mov.w	#_bss, a1    	// store the start address of bss in A1 
	mov.w	#_ebss, a0   	// store the end address of bss in A0 
	sub.w   a1,a0	     	// (A0 = A0-A1) 
	mov.w   a0,r3	     	// Store size of bss section in reg R3 
	sstr.b


// start user program 
	jsr.a	_main		
	
	.end
