	cpu LMM
	.module config.c
	.area memory(abs)
	.org 0x7fc0
_defaultparams::
	.word 512
	.word 512
	.word 0
	.word 0
	.word 1024
	.word 1024
	.word 412
	.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
;            frs -> X+0
_loadPrefs::
	.dbline -1
	push X
	mov X,SP
	add SP,6
	.dbline 13
; #include "config.h"
; #include <flashblock.h>
; 
; params_t params;
; 
; 
; #pragma abs_address: 0x7fc0
; params_t defaultparams={512, 512, 0, 0, 1024, 1024, 412};
; #pragma end_abs_address
; 
; 
; void loadPrefs()
; {
	.dbline 16
; 	FLASH_READ_STRUCT frs;
; 	 
; 	frs.wARG_BlockId = FLASHBLOCKNUMBER;		// Block Id to write
	mov [X+1],-1
	mov [X+0],1
	.dbline 17
; 	frs.pARG_FlashBuffer = (unsigned char*) &params;
	mov [X+3],<_params
	mov [X+2],>_params
	.dbline 18
; 	frs.wARG_ReadCount = sizeof(params);
	mov [X+5],14
	mov [X+4],0
	.dbline 20
; 	
; 	FlashReadBlock(&frs);
	mov REG[0xd0],>__r0
	push X
	mov A,7
	push A
	pop A
	xcall _FlashReadBlock
	pop X
	.dbline 24
; 	
; 	// sanity check parameters (mostly intended for the
; 	// first time, when the flash contains garbage.)
; 	if (params.joycx<100 || params.joycx>900)
	mov REG[0xd0],>_params
	mov A,[_params+1]
	sub A,100
	mov A,[_params]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L9
X0:
	mov REG[0xd0],>_params
	mov A,-124
	sub A,[_params+1]
	mov A,[_params]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(3 ^ 0x80)
	sbb A,[__rX]
	jnc L7
X1:
L9:
	.dbline 25
; 		params.joycx=512;
	mov REG[0xd0],>_params
	mov [_params+1],0
	mov [_params],2
L7:
	.dbline 27
; 		
; 	if (params.joycy<100 || params.joycy>900)
	mov REG[0xd0],>_params
	mov A,[_params+2+1]
	sub A,100
	mov A,[_params+2]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L14
X2:
	mov REG[0xd0],>_params
	mov A,-124
	sub A,[_params+2+1]
	mov A,[_params+2]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(3 ^ 0x80)
	sbb A,[__rX]
	jnc L10
X3:
L14:
	.dbline 28
; 		params.joycy=512;
	mov REG[0xd0],>_params
	mov [_params+2+1],0
	mov [_params+2],2
L10:
	.dbline 30
; 
; 	if (params.batsensedivide<100 || params.batsensedivide>1000)
	mov REG[0xd0],>_params
	mov A,[_params+12+1]
	sub A,100
	mov A,[_params+12]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L20
X4:
	mov REG[0xd0],>_params
	mov A,-24
	sub A,[_params+12+1]
	mov A,[_params+12]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(3 ^ 0x80)
	sbb A,[__rX]
	jnc L16
X5:
L20:
	.dbline 31
; 		params.batsensedivide=412;
	mov REG[0xd0],>_params
	mov [_params+12+1],-100
	mov [_params+12],1
L16:
	.dbline 33
; 
; 	if (params.joyxmin>250 || params.joyxmin<0)
	mov REG[0xd0],>_params
	mov A,-6
	sub A,[_params+4+1]
	mov A,[_params+4]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(0 ^ 0x80)
	sbb A,[__rX]
	jc L26
X6:
	mov REG[0xd0],>_params
	mov A,[_params+4+1]
	sub A,0
	mov A,[_params+4]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jnc L22
X7:
L26:
	.dbline 34
; 		params.joyxmin=0;
	mov REG[0xd0],>_params
	mov [_params+4+1],0
	mov [_params+4],0
L22:
	.dbline 36
; 
; 	if (params.joyymin>250 || params.joyymin<0)
	mov REG[0xd0],>_params
	mov A,-6
	sub A,[_params+8+1]
	mov A,[_params+8]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(0 ^ 0x80)
	sbb A,[__rX]
	jc L32
X8:
	mov REG[0xd0],>_params
	mov A,[_params+8+1]
	sub A,0
	mov A,[_params+8]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jnc L28
X9:
L32:
	.dbline 37
; 		params.joyymin=0;
	mov REG[0xd0],>_params
	mov [_params+8+1],0
	mov [_params+8],0
L28:
	.dbline 39
; 	
; 	if (params.joyxmax<700 || params.joyxmax>1024)
	mov REG[0xd0],>_params
	mov A,[_params+6+1]
	sub A,-68
	mov A,[_params+6]
	xor A,-128
	sbb A,(2 ^ 0x80)
	jc L38
X10:
	mov REG[0xd0],>_params
	mov A,0
	sub A,[_params+6+1]
	mov A,[_params+6]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(4 ^ 0x80)
	sbb A,[__rX]
	jnc L34
X11:
L38:
	.dbline 40
; 		params.joyxmax=1024;
	mov REG[0xd0],>_params
	mov [_params+6+1],0
	mov [_params+6],4
L34:
	.dbline 42
; 		
; 	if (params.joyymax<700 || params.joyymax>1024)
	mov REG[0xd0],>_params
	mov A,[_params+10+1]
	sub A,-68
	mov A,[_params+10]
	xor A,-128
	sbb A,(2 ^ 0x80)
	jc L44
X12:
	mov REG[0xd0],>_params
	mov A,0
	sub A,[_params+10+1]
	mov A,[_params+10]
	xor A,-128
	mov REG[0xd0],>__r0
	mov [__rX],A
	mov A,(4 ^ 0x80)
	sbb A,[__rX]
	jnc L40
X13:
L44:
	.dbline 43
	mov REG[0xd0],>_params
	mov [_params+10+1],0
	mov [_params+10],4
L40:
	.dbline -2
	.dbline 44
; 		params.joyymax=1024;
; }
L4:
	add SP,-6
	pop X
	.dbline 0 ; func end
	ret
	.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 47
; 
; unsigned char savePrefs()
; {
	.dbline 50
;  FLASH_WRITE_STRUCT fws;
;  
;  fws.wARG_BlockId = FLASHBLOCKNUMBER;		// Block Id to write
	mov [X+1],-1
	mov [X+0],1
	.dbline 51
;  fws.pARG_FlashBuffer = (unsigned char*)  &params;
	mov [X+3],<_params
	mov [X+2],>_params
	.dbline 52
;  fws.cARG_Temperature = 25;	
	mov [X+4],25
	.dbline 54
;  
;  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
L46:
	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::
	.word 0,0,0,0,0
	.byte 0,0,0,0
	.dbsym e params _params X
