	cpu LMM
	.module config.c
	.area memory(abs)
	.org 0x7fc0
_defaultparams::
	.word 3
	.byte 5
	.dbfile ./config.c
	.dbsym e defaultparams _defaultparams X
	.area data(ram, con, rel)
	.dbfile ./config.c
	.area text(rom, con, rel)
	.dbfile ./config.c
	.dbfunc e loadPrefs _loadPrefs fV
;              v -> X+6
;            frs -> X+0
_loadPrefs::
	.dbline -1
	push X
	mov X,SP
	add SP,7
	.dbline 13
; #include "config.h"
; #include "PSoCAPI.h"    // PSoC API definitions for all User Modules
; 
; #include <flashblock.h>
; 
; params_t params;
; 
; #pragma abs_address: 0x7fc0
; params_t defaultparams={3, 5};
; #pragma end_abs_address
; 
; void loadPrefs()
; {
	.dbline 18
; 	unsigned char v;
; 
; 	FLASH_READ_STRUCT frs;
; 	 
; 	frs.wARG_BlockId = FLASHBLOCKNUMBER;		// Block Id to write
	mov [X+1],-1
	mov [X+0],1
	.dbline 19
; 	frs.pARG_FlashBuffer = (unsigned char*) &params;
	mov [X+3],<_params
	mov [X+2],>_params
	.dbline 20
; 	frs.wARG_ReadCount = sizeof(params);
	mov [X+5],3
	mov [X+4],0
	.dbline 22
; 	
; 	FlashReadBlock(&frs);
	mov REG[0xd0],>__r0
	push X
	mov A,7
	push A
	pop A
	xcall _FlashReadBlock
	pop X
	.dbline 25
; 
; 	// activate the parameters.
; 	params.drivemode&=(DRIVEMODE_SWAPLR | DRIVEMODE_LEFTINV | DRIVEMODE_RIGHTINV);
	mov REG[0xd0],>_params
	and [_params+2],7
	.dbline 27
; 
; 	PWM8_BAUD_Stop();
	push X
	xcall _PWM8_BAUD_Stop
	pop X
	.dbline 29
; 
; 	if (params.baud==1)
	mov REG[0xd0],>_params
	cmp [_params],0
	jnz L8
	cmp [_params+1],1
	jnz L8
X0:
	.dbline 30
; 		v=25;
	mov [X+6],25
	xjmp L9
L8:
	.dbline 31
; 	else if (params.baud==2)
	mov REG[0xd0],>_params
	cmp [_params],0
	jnz L10
	cmp [_params+1],2
	jnz L10
X1:
	.dbline 32
; 		v=23;
	mov [X+6],23
	xjmp L11
L10:
	.dbline 33
; 	else if (params.baud==3)
	mov REG[0xd0],>_params
	cmp [_params],0
	jnz L12
	cmp [_params+1],3
	jnz L12
X2:
	.dbline 34
; 		v=11;
	mov [X+6],11
	xjmp L13
L12:
	.dbline 36
; 	else
; 	{
	.dbline 37
; 		params.baud=0;
	mov REG[0xd0],>_params
	mov [_params+1],0
	mov [_params],0
	.dbline 38
; 		v=51; // use default baud of 115.2kbps
	mov [X+6],51
	.dbline 39
; 	}
L13:
L11:
L9:
	.dbline 41
; 		
; 	PWM8_BAUD_WritePulseWidth(v/2);
	mov REG[0xd0],>__r0
	mov A,2
	push A
	mov A,[X+6]
	push A
	xcall __divmodu_8X8_8
	pop A
	add SP,-1
	push X
	xcall _PWM8_BAUD_WritePulseWidth
	pop X
	.dbline 42
; 	PWM8_BAUD_WritePeriod(v);
	push X
	mov A,[X+6]
	xcall _PWM8_BAUD_WritePeriod
	.dbline 44
; 	
; 	PWM8_BAUD_Start();
	xcall _PWM8_BAUD_Start
	pop X
	.dbline -2
	.dbline 46
; 
; }
L4:
	add SP,-7
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l v 6 c
	.dbsym l frs 0 X
	.dbend
	.dbfunc e savePrefs _savePrefs fc
;            fws -> X+0
_savePrefs::
	.dbline -1
	push X
	mov X,SP
	add SP,8
	.dbline 49
; 
; unsigned char savePrefs()
; {
	.dbline 52
;  FLASH_WRITE_STRUCT fws;
;  
;  fws.wARG_BlockId = FLASHBLOCKNUMBER;		// Block Id to write
	mov [X+1],-1
	mov [X+0],1
	.dbline 53
;  fws.pARG_FlashBuffer = (unsigned char*)  &params;
	mov [X+3],<_params
	mov [X+2],>_params
	.dbline 54
;  fws.cARG_Temperature = 25;	
	mov [X+4],25
	.dbline 56
;  
;  return bFlashWriteBlock(&fws);
	mov REG[0xd0],>__r0
	push X
	mov A,7
	push A
	pop A
	xcall _bFlashWriteBlock
	mov REG[0xd0],>__r0
	pop X
	.dbline -2
L14:
	add SP,-8
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l fws 0 X
	.dbend
	.area data(ram, con, rel)
	.dbfile ./config.c
_params::
	.byte 0,0,0
	.dbsym e params _params X
