	cpu LMM
	.module main.c
	.area data(ram, con, rel)
_hostbufpos::
	.byte 0
	.dbfile ./main.c
	.dbsym e hostbufpos _hostbufpos c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_hostbufchk::
	.byte 0
	.dbsym e hostbufchk _hostbufchk c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_padbufpos::
	.byte 0
	.dbsym e padbufpos _padbufpos c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_padbufchk::
	.byte 0
	.dbsym e padbufchk _padbufchk c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_slavebufpos::
	.byte 0
	.dbsym e slavebufpos _slavebufpos c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_slavebufchk::
	.byte 0
	.dbsym e slavebufchk _slavebufchk c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_prt0andmask::
	.byte 255
	.dbsym e prt0andmask _prt0andmask c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_prt0ormask::
	.byte 0
	.dbsym e prt0ormask _prt0ormask c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_prt2andmask::
	.byte 255
	.dbsym e prt2andmask _prt2andmask c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_prt2ormask::
	.byte 0
	.dbsym e prt2ormask _prt2ormask c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_ack_flag::
	.byte 0
	.dbsym e pad_ack_flag _pad_ack_flag c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_uslastport::
	.byte 0
	.dbsym e uslastport _uslastport c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_uspingcount::
	.byte 0
	.dbsym e uspingcount _uspingcount c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_slave_ack::
	.byte 0
	.dbsym e slave_ack _slave_ack c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_diag_button_count::
	.word 0
	.dbsym e diag_button_count _diag_button_count s
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_indiag::
	.byte 0
	.dbsym e indiag _indiag c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_commerrs::
	.byte 0
	.dbsym e commerrs _commerrs c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_eventenable::
	.byte 1
	.dbsym e eventenable _eventenable c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_gyrocount::
	.word 0,0
	.dbsym e gyrocount _gyrocount L
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_lastgyrotime::
	.word 0
	.dbsym e lastgyrotime _lastgyrotime i
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_lastPadReceivedTime::
	.word 0
	.dbsym e lastPadReceivedTime _lastPadReceivedTime i
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_allstopenabled::
	.byte 1
	.dbsym e allstopenabled _allstopenabled c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_allowhost::
	.byte 1
	.dbsym e allowhost _allowhost c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_badhostchars::
	.byte 0
	.dbsym e badhostchars _badhostchars c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_badslavechars::
	.byte 0
	.dbsym e badslavechars _badslavechars c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_badpadchars::
	.byte 0
	.dbsym e badpadchars _badpadchars c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area text(rom, con, rel)
	.dbfile ./main.c
	.dbfunc e resetState _resetState fV
;              i -> X+0
_resetState::
	.dbline -1
	push X
	mov X,SP
	add SP,2
	.dbline 110
; //----------------------------------------------------------------------------
; // C main line
; //----------------------------------------------------------------------------
; 
; #include <m8c.h>        // part specific constants and macros
; #include <string.h>
; //#include <I2CHW_1Common.h>
; //#include <I2CHW_1mstr.h>
; 
; #include "PSoCAPI.h"    // PSoC API definitions for all User Modules
; #include "ed_host_int.h"
; #include "ed_pad_int.h"
; #include "ed_slave_int.h"
; #include "util.h"
; #include "pad.h"
; #include "main.h"
; #include "error.h"
; #include "config.h"
; #include "slave.h"
; 
; #define I2CTIMEOUT 5000
; 
; unsigned char hostbuf[HOSTBUFSIZE];
; unsigned char hostbufpos=0;
; unsigned char hostbufchk=0;
; 
; unsigned char padbuf[PADBUFSIZE];
; unsigned char padbufpos=0;
; unsigned char padbufchk=0;
; 
; unsigned char slavebuf[SLAVEBUFSIZE];
; unsigned char slavebufpos=0;
; unsigned char slavebufchk=0;
; 
; unsigned char slavestate[SLAVESTATEBUFSIZE];
; 
; unsigned char prt0andmask=0xff, prt0ormask=0x00;
; unsigned char prt2andmask=0xff, prt2ormask=0x00;
; 
; unsigned char pad_joyx, pad_joyy, pad_buttons;
; unsigned char pad_move_up, pad_move_down, pad_move_left, pad_move_right;
; unsigned short pad_battery_voltage;
; 
; unsigned char pinmode[16];
; unsigned char pad_ack_flag=0;
; 
; unsigned int usrange[2];
; unsigned char uslastport=0;
; unsigned char uspingcount=0;
; 
; unsigned char slave_ack=0;
; 
; unsigned short diag_button_count=0;
; 
; unsigned char indiag=0;			// are we in diagnostics mode?
; 
; unsigned char commerrs=0;		// comm error counter
; 
; // if 1, then each packet will be followed by an
; // event character
; unsigned char eventenable=1; 		
; 
; long gyrocount=0;
; unsigned int lastgyrotime=0;
; 
; unsigned int lastPadReceivedTime=0;
; 
; //********************************************************
; // GLOBALS
; //******************************************************** 
; unsigned int  analog[10];		// we store all of our analog values here, with 2_1 and 2_2 at 8 and 9.
; unsigned char analogFilter[10];
; unsigned char analogNext;	    // which port are we sampling?
; unsigned char analogDelay;      // how many samples have we skipped since updating our main bank of A/Ds?
; 
; unsigned char dac[1];
; 
; unsigned char clockgenstate[3];
; 
; unsigned char allstopenabled=1;
; unsigned char allowhost=1;
; 
; extern void diag(void);
; extern unsigned char selftest(void);
; 
; unsigned char badhostchars=0;
; unsigned char badslavechars=0;
; unsigned char badpadchars=0;
; 
; unsigned int lastcounter;
; 
; //********************************************************
; // FUNCTION PROTOTYPES
; //******************************************************** 
; void resetState(void);
; unsigned char setpinmode(unsigned char pin, unsigned char mode);
; void doSleepCounter(void);
; 
; unsigned char host_chksend(unsigned char chk, unsigned char c);
; void sendAck(unsigned char flags, unsigned char error);
; void sendPacket(unsigned char flags);
; void doGyro(void);
; void idle(void);
; void commerror(unsigned char type);
; 
; //********************************************************
; // Reset internal state.
; //******************************************************** 
; void resetState()
; {
	.dbline 113
; 	int i;
; 
; 	for (i=0;i<4;i++)
	mov [X+1],0
	mov [X+0],0
L3:
	.dbline 114
	mov REG[0xd0],>__r0
	mov A,[X+1]
	mov [__r1],A
	mov A,[X+0]
	mov [__r0],A
	asl [__r1]
	rlc [__r0]
	add [__r1],<_servowidth
	adc [__r0],>_servowidth
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,0
	mvi [__r1],A
	mvi [__r1],A
L4:
	.dbline 113
	inc [X+1]
	adc [X+0],0
	.dbline 113
	mov A,[X+1]
	sub A,4
	mov A,[X+0]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L3
X0:
	.dbline 116
; 		servowidth[i]=0;
; 			
; 	for (i=0;i<10;i++)
	mov [X+1],0
	mov [X+0],0
L7:
	.dbline 117
	.dbline 118
	mov REG[0xd0],>__r0
	mov A,[X+1]
	mov [__r1],A
	mov A,[X+0]
	mov [__r0],A
	asl [__r1]
	rlc [__r0]
	add [__r1],<_analog
	adc [__r0],>_analog
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,0
	mvi [__r1],A
	mvi [__r1],A
	.dbline 119
	mov A,[X+1]
	add A,<_analogFilter
	mov [__r1],A
	mov A,[X+0]
	adc A,>_analogFilter
	mov REG[0xd5],A
	mov A,0
	mvi [__r1],A
	.dbline 120
L8:
	.dbline 116
	inc [X+1]
	adc [X+0],0
	.dbline 116
	mov A,[X+1]
	sub A,10
	mov A,[X+0]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L7
X1:
	.dbline 121
; 	{
; 		analog[i]=0;
; 		analogFilter[i]=0;
; 	}
; 	analogFilter[8]=4;
	mov REG[0xd0],>_analogFilter
	mov [_analogFilter+8],4
	.dbline 122
; 	analogFilter[9]=4;
	mov [_analogFilter+9],4
	.dbline 124
; 	
; 	analogNext=0;
	mov REG[0xd0],>_analogNext
	mov [_analogNext],0
	.dbline 125
; 	analogDelay=0;
	mov REG[0xd0],>_analogDelay
	mov [_analogDelay],0
	.dbline 127
; 	
; 	for (i=0;i<8;i++)
	mov [X+1],0
	mov [X+0],0
L13:
	.dbline 128
	mov A,1
	push A
	mov REG[0xd0],>__r0
	mov A,[X+1]
	push A
	xcall _setpinmode
	add SP,-2
	mov REG[0xd0],>__r0
L14:
	.dbline 127
	inc [X+1]
	adc [X+0],0
	.dbline 127
	mov A,[X+1]
	sub A,8
	mov A,[X+0]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L13
X2:
	.dbline 129
; 		setpinmode(i, PINMODE_DIG_IN_PULLUP);
; 	for (i=8;i<16;i++)
	mov [X+1],8
	mov [X+0],0
L17:
	.dbline 130
	mov A,8
	push A
	mov REG[0xd0],>__r0
	mov A,[X+1]
	push A
	xcall _setpinmode
	add SP,-2
	mov REG[0xd0],>__r0
L18:
	.dbline 129
	inc [X+1]
	adc [X+0],0
	.dbline 129
	mov A,[X+1]
	sub A,16
	mov A,[X+0]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L17
X3:
	.dbline 132
; 		setpinmode(i, PINMODE_ANALOG_IN);
; 		
; 	usrange[0]=0xffff; usrange[1]=0xffff;
	mov REG[0xd0],>_usrange
	mov [_usrange+1],-1
	mov [_usrange],-1
	.dbline 132
	mov [_usrange+2+1],-1
	mov [_usrange+2],-1
	.dbline 134
; 	
; 	dac[0]=0x80;
	mov REG[0xd0],>_dac
	mov [_dac],-128
	.dbline 135
; 	clockgenstate[0]=0x4;
	mov REG[0xd0],>_clockgenstate
	mov [_clockgenstate],4
	.dbline 136
; 	clockgenstate[1]=52;
	mov [_clockgenstate+1],52
	.dbline 137
; 	clockgenstate[2]=26;
	mov [_clockgenstate+2],26
	.dbline 139
; 	
; 	gyrocount=0;
	mov REG[0xd0],>_gyrocount
	mov [_gyrocount],0
	mov [_gyrocount+1],0
	mov [_gyrocount+2],0
	mov [_gyrocount+3],0
	.dbline 141
; 	
; 	for (i=0;i<SLAVESTATEBUFSIZE;i++)
	mov [X+1],0
	mov [X+0],0
L24:
	.dbline 142
	mov REG[0xd0],>__r0
	mov A,[X+1]
	add A,<_slavestate
	mov [__r1],A
	mov A,[X+0]
	adc A,>_slavestate
	mov REG[0xd5],A
	mov A,0
	mvi [__r1],A
L25:
	.dbline 141
	inc [X+1]
	adc [X+0],0
	.dbline 141
	mov A,[X+1]
	sub A,80
	mov A,[X+0]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L24
X4:
	.dbline -2
	.dbline 143
; 		slavestate[i]=0;
; }
L2:
	add SP,-2
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l i 0 I
	.dbend
	.dbfunc e main _main fV
_main::
	.dbline -1
	.dbline 149
; 
; //********************************************************
; // Main.
; //******************************************************** 
; void main()
; {
	.dbline 150
; 	M8C_EnableGInt;
		or  F, 01h

	.dbline 152
; 
; 	resetState();
	xcall _resetState
	.dbline 157
; 
; 	//********************************************************
;  	// turn everything on
; 	//******************************************************** 
; 	ED_HOST_init();
	push X
	xcall _ED_HOST_init
	mov REG[0xd0],>__r0
	pop X
	.dbline 158
;     UART_HOST_IntCntl(UART_HOST_ENABLE_RX_INT | UART_HOST_ENABLE_TX_INT);
	push X
	mov A,3
	xcall _UART_HOST_IntCntl
	.dbline 159
;     UART_HOST_Start(UART_HOST_PARITY_NONE);
	mov A,0
	xcall _UART_HOST_Start
	.dbline 161
;    
;     ED_PAD_init();
	xcall _ED_PAD_init
	mov REG[0xd0],>__r0
	pop X
	.dbline 162
;     UART_PAD_IntCntl(UART_PAD_ENABLE_RX_INT  | UART_PAD_ENABLE_TX_INT);
	push X
	mov A,3
	xcall _UART_PAD_IntCntl
	.dbline 163
;     UART_PAD_Start(UART_PAD_PARITY_NONE);
	mov A,0
	xcall _UART_PAD_Start
	.dbline 165
;  
;  	ED_SLAVE_init();
	xcall _ED_SLAVE_init
	mov REG[0xd0],>__r0
	pop X
	.dbline 166
;     UART_SLAVE_IntCntl(UART_SLAVE_ENABLE_RX_INT |  UART_SLAVE_ENABLE_TX_INT);
	push X
	mov A,3
	xcall _UART_SLAVE_IntCntl
	.dbline 167
;     UART_SLAVE_Start(UART_SLAVE_PARITY_NONE);
	mov A,0
	xcall _UART_SLAVE_Start
	.dbline 169
; 
; 	AMUX4_1_Start();
	xcall _AMUX4_1_Start
	.dbline 170
;  	AMUX4_2_Start();
	xcall _AMUX4_2_Start
	.dbline 172
; 
; 	RefMux_1_Start(RefMux_1_HIGHPOWER);
	mov A,3
	xcall _RefMux_1_Start
	.dbline 173
; 	DelSig_1_Start(DelSig_1_HIGHPOWER);
	mov A,3
	xcall _DelSig_1_Start
	.dbline 174
; 	DelSig_1_StartAD();
	xcall _DelSig_1_StartAD
	.dbline 176
; 	
; 	SAR6_1_Start(SAR6_1_FULLPOWER);
	mov A,3
	xcall _SAR6_1_Start
	.dbline 177
; 	SAR6_2_Start(SAR6_2_FULLPOWER);
	mov A,3
	xcall _SAR6_2_Start
	.dbline 179
; 	
; 	DAC8_1_Start(DAC8_1_HIGHPOWER);
	mov A,3
	xcall _DAC8_1_Start
	.dbline 181
; 	
; 	PWM8_BAUD_Start();
	xcall _PWM8_BAUD_Start
	.dbline 182
; 	PWM8_CLOCK_Start();
	xcall _PWM8_CLOCK_Start
	.dbline 187
; 	
; 	//DAC8_1_Start(DAC8_1_FULLPOWER);
; 	//DAC8_1_WriteStall(0x80);
; 	
; 	PWM8_SERVOCLK_Start();
	xcall _PWM8_SERVOCLK_Start
	.dbline 189
; 	
; 	PWM16_SERVO_Start();
	xcall _PWM16_SERVO_Start
	.dbline 190
; 	PWM16_SERVO_EnableInt();
	xcall _PWM16_SERVO_EnableInt
	.dbline 192
; 	
; 	I2Cm_1_Start();
	xcall _I2Cm_1_Start
	pop X
	.dbline 194
; 	
; 	sleepcounter=0;
	mov REG[0xd0],>_sleepcounter
	mov [_sleepcounter+1],0
	mov [_sleepcounter],0
	.dbline 195
;  	INT_MSK0|=0x40; // enable sleep interrupts. 512Hz clock.
	or REG[0xe0],64
	.dbline 197
; 		
; 	loadPrefs();
	xcall _loadPrefs
L29:
	.dbline 199
L30:
	.dbline 199
; 	
; 	while (sleepcounter<64); // wait 0.125sec for LCD to get ready
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	sub A,64
	mov A,[_sleepcounter]
	sbb A,0
	jc L29
X6:
	.dbline 201
; 	
; 	if (selftest())
	xcall _selftest
	mov REG[0xd0],>__r0
	cmp A,0
	jz L32
	.dbline 202
; 		pad_LcdPrintC(0x00, 0x30, 'B', "OrcBoard Ready!");
	mov A,>L34
	push A
	mov A,<L34
	push A
	mov A,66
	push A
	mov A,48
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L33
L32:
	.dbline 204
; 	else
; 		pad_LcdPrintC(0x00, 0x30, 'b', "Self tests FAILED!");
	mov A,>L35
	push A
	mov A,<L35
	push A
	mov A,98
	push A
	mov A,48
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
L33:
	.dbline 206
; 	
; 	M8C_DisableGInt;
		and F, FEh

	.dbline 207
; 	lastPadReceivedTime=sleepcounter;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	push A
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastPadReceivedTime
	mov [_lastPadReceivedTime],A
	pop A
	mov [_lastPadReceivedTime+1],A
	.dbline 208
; 	M8C_EnableGInt;
		or  F, 01h

	xjmp L37
L36:
	.dbline 214
	.dbline 215
	xcall _idle
	.dbline 216
L37:
	.dbline 213
	xjmp L36
X5:
	.dbline -2
	.dbline 217
; 	
; 	//********************************************************
;  	// Run!
; 	//********************************************************  
;  	while (1)
;  	{
;  		idle();
;    	}   
; }
L28:
	.dbline 0 ; func end
	jmp .
	.dbend
	.dbfunc e idle _idle fV
; padElapsedTime -> X+0
_idle::
	.dbline -1
	push X
	mov X,SP
	add SP,2
	.dbline 220
; 
; void idle(void)
; {
	.dbline 223
; 	unsigned int padElapsedTime;
; 	
; 	updateAnalog();
	xcall _updateAnalog
	xjmp L41
L40:
	.dbline 226
	xcall _doHost
L41:
	.dbline 225
; 		 			
; 	while (allowhost && ED_HOST_isData())
	mov REG[0xd0],>_allowhost
	cmp [_allowhost],0
	jz L43
	push X
	xcall _ED_HOST_isData
	mov REG[0xd0],>__r0
	pop X
	cmp A,0
	jnz L40
L43:
	xjmp L45
L44:
	.dbline 229
	xcall _doPad
L45:
	.dbline 228
;  		doHost();
;  			
;  	while (ED_PAD_isData())
	push X
	xcall _ED_PAD_isData
	mov REG[0xd0],>__r0
	pop X
	cmp A,0
	jnz L44
	xjmp L48
L47:
	.dbline 232
	xcall _doSlave
L48:
	.dbline 231
;  		doPad();
;  			
;  	while (ED_SLAVE_isData())
	push X
	xcall _ED_SLAVE_isData
	pop X
	cmp A,0
	jnz L47
	.dbline 234
;  		doSlave();
;  
; 	M8C_DisableGInt;
		and F, FEh

	.dbline 235
;  	padElapsedTime=sleepcounter-lastPadReceivedTime;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	mov REG[0xd0],>_lastPadReceivedTime
	sub A,[_lastPadReceivedTime+1]
	mov [X+1],A
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastPadReceivedTime
	sbb A,[_lastPadReceivedTime]
	mov [X+0],A
	.dbline 236
; 	M8C_EnableGInt;
		or  F, 01h

	.dbline 238
;  	
;  	if ((pad_currentButtons()&PAD_STOP) && allstopenabled)
	xcall _pad_currentButtons
	mov REG[0xd0],>__r0
	mov [__r0],A
	tst [__r0],64
	jz L50
	mov REG[0xd0],>_allstopenabled
	cmp [_allstopenabled],0
	jz L50
	.dbline 239
;  	{
	.dbline 240
;  		allstopenabled=0;
	mov [_allstopenabled],0
	.dbline 241
;  		allstop(ALLSTOP_STOPBUTTON);
	mov A,2
	push A
	xcall _allstop
	add SP,-1
	.dbline 242
;  		allstopenabled=1;
	mov REG[0xd0],>_allstopenabled
	mov [_allstopenabled],1
	.dbline 243
;  	}
L50:
	.dbline 245
;  	
;  	if (padElapsedTime>800L && allstopenabled)
	mov REG[0xd0],>__r0
	mov A,[X+1]
	mov [__r3],A
	mov A,[X+0]
	mov [__r2],A
	mov [__r1],0
	mov A,32
	sub A,[__r3]
	mov A,3
	sbb A,[__r2]
	mov A,0
	sbb A,[__r1]
	mov A,0
	xor A,-128
	mov [__rX],A
	mov A,(0 ^ 0x80)
	sbb A,[__rX]
	jnc L52
X7:
	mov REG[0xd0],>_allstopenabled
	cmp [_allstopenabled],0
	jz L52
	.dbline 246
;  	{
	.dbline 247
;  		allstopenabled=0;
	mov [_allstopenabled],0
	.dbline 248
;  		allstop(ALLSTOP_PADTIMEOUT);
	mov A,1
	push A
	xcall _allstop
	add SP,-1
	.dbline 249
;  		allstopenabled=1;
	mov REG[0xd0],>_allstopenabled
	mov [_allstopenabled],1
	.dbline 250
;  	}
L52:
	.dbline 252
;  		
;  	if (lastcounter!=sleepcounter)
	mov REG[0xd0],>_lastcounter
	mov A,[_lastcounter]
	mov REG[0xd0],>_sleepcounter
	cmp A,[_sleepcounter]
	jnz X8
	mov REG[0xd0],>_lastcounter
	mov A,[_lastcounter+1]
	mov REG[0xd0],>_sleepcounter
	cmp A,[_sleepcounter+1]
	jz L54
X8:
	.dbline 253
;  	{
	.dbline 254
;   		doSleepCounter();
	xcall _doSleepCounter
	.dbline 255
; 		M8C_DisableGInt;
		and F, FEh

	.dbline 256
;   		lastcounter=sleepcounter;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	push A
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastcounter
	mov [_lastcounter],A
	pop A
	mov [_lastcounter+1],A
	.dbline 257
; 		M8C_EnableGInt;
		or  F, 01h

	.dbline 258
;   	}
L54:
	.dbline 260
;  		
; 	usrange[uslastport]=0xffff-Timer16_SONAR_wReadCompareValue();
	push X
	xcall _Timer16_SONAR_wReadCompareValue
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],X
	pop X
	mov A,-1
	sub A,[__r1]
	mov [__r1],A
	mov A,-1
	sbb A,[__r0]
	mov [__r0],A
	mov REG[0xd0],>_uslastport
	mov A,[_uslastport]
	mov REG[0xd0],>__r0
	mov [__r3],A
	mov [__r2],0
	asl [__r3]
	rlc [__r2]
	add [__r3],<_usrange
	adc [__r2],>_usrange
	mov A,[__r2]
	mov REG[0xd5],A
	mov A,[__r0]
	mvi [__r3],A
	mov A,[__r1]
	mvi [__r3],A
	.dbline -2
	.dbline 261
; }
L39:
	add SP,-2
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l padElapsedTime 0 i
	.dbend
	.dbfunc e doSleepCounter _doSleepCounter fV
;              v -> X+1
;            but -> X+0
_doSleepCounter::
	.dbline -1
	push X
	mov X,SP
	add SP,5
	.dbline 264
; 
; void doSleepCounter()
; {
	.dbline 265
; 	unsigned char but=pad_currentButtons();
	xcall _pad_currentButtons
	mov [X+0],A
	.dbline 268
; 	long v;
; 	
; 	if (but&PAD_MENU)
	tst [X+0],32
	jz L57
	.dbline 269
; 		diag_button_count++;
	mov REG[0xd0],>_diag_button_count
	inc [_diag_button_count+1]
	adc [_diag_button_count],0
	xjmp L58
L57:
	.dbline 271
; 	else
; 		diag_button_count=0;
	mov REG[0xd0],>_diag_button_count
	mov [_diag_button_count+1],0
	mov [_diag_button_count],0
L58:
	.dbline 273
	mov REG[0xd0],>_diag_button_count
	mov A,[_diag_button_count+1]
	mov REG[0xd0],>__r0
	mov [__r3],A
	mov REG[0xd0],>_diag_button_count
	mov A,[_diag_button_count]
	mov REG[0xd0],>__r0
	mov [__r2],A
	mov [__r1],0
	mov A,0
	sub A,[__r3]
	mov A,2
	sbb A,[__r2]
	mov A,0
	sbb A,[__r1]
	mov A,0
	xor A,-128
	mov [__rX],A
	mov A,(0 ^ 0x80)
	sbb A,[__rX]
	jnc L59
X9:
	mov REG[0xd0],>_indiag
	cmp [_indiag],0
	jnz L59
	.dbline 274
	.dbline 275
	mov [_indiag],1
	.dbline 276
	xcall _diag
	.dbline 277
	mov REG[0xd0],>_diag_button_count
	mov [_diag_button_count+1],0
	mov [_diag_button_count],0
	.dbline 278
	mov REG[0xd0],>_indiag
	mov [_indiag],0
	.dbline 279
L59:
	.dbline -2
	.dbline 280
; 	
; 	if (diag_button_count>DIAG_BUTTON_THRESH && !indiag)
; 		{
; 		indiag=1;
; 		diag();
; 		diag_button_count=0;
; 		indiag=0;
; 		}
; }
L56:
	add SP,-5
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l v 1 L
	.dbsym l but 0 c
	.dbend
	.dbfunc e updateAnalog _updateAnalog fV
;          dtime -> X+6
;             sv -> X+2
;              v -> X+0
_updateAnalog::
	.dbline -1
	push X
	mov X,SP
	add SP,8
	.dbline 283
; 
; void updateAnalog(void)
; {
	.dbline 288
; 	unsigned int v;
; 	unsigned int dtime;
; 	long  sv;
; 	
; 	v=(SAR6_2_cGetSample()<<10)+0x8000;
	push X
	xcall _SAR6_2_cGetSample
	mov REG[0xd0],>__r0
	pop X
	mov [__r1],A
	tst [__r1],-128
	jz X10
X10:
	mov REG[0xd0],>__r0
	mov A,[__r1]
	mov [__r0],A
	mov [__r1],0
	asl [__r0]
	asl [__r1]
	rlc [__r0]
	mov A,[__r1]
	add A,0
	mov [X+1],A
	mov A,[__r0]
	adc A,-128
	mov [X+0],A
	.dbline 289
; 	analog[8]=analog[8]-(analog[8]>>analogFilter[8])+(v>>analogFilter[8]);
	mov REG[0xd0],>_analogFilter
	mov A,[_analogFilter+8]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov A,[X+1]
	mov [__r3],A
	mov A,[X+0]
	mov [__r2],A
	mov A,[__r1]
	and A,15
	jz X11
X12:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r2]
	rrc [__r3]
	dec A
	jnz X12
X11:
	mov REG[0xd0],>_analogFilter
	mov A,[_analogFilter+8]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov REG[0xd0],>_analog
	mov A,[_analog+16+1]
	push A
	mov A,[_analog+16]
	mov REG[0xd0],>__r0
	mov [__r4],A
	pop A
	mov [__r5],A
	mov A,[__r1]
	and A,15
	jz X13
X14:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r4]
	rrc [__r5]
	dec A
	jnz X14
X13:
	mov REG[0xd0],>_analog
	mov A,[_analog+16+1]
	mov REG[0xd0],>__r0
	sub A,[__r5]
	mov [__r1],A
	mov REG[0xd0],>_analog
	mov A,[_analog+16]
	mov REG[0xd0],>__r0
	sbb A,[__r4]
	mov [__r0],A
	mov A,[__r1]
	add A,[__r3]
	mov REG[0xd0],>_analog
	mov [_analog+16+1],A
	mov REG[0xd0],>__r0
	mov A,[__r0]
	adc A,[__r2]
	mov REG[0xd0],>_analog
	mov [_analog+16],A
	.dbline 291
; 
; 	v=(SAR6_1_cGetSample()<<10)+0x8000;	
	push X
	xcall _SAR6_1_cGetSample
	mov REG[0xd0],>__r0
	pop X
	mov [__r1],A
	tst [__r1],-128
	jz X15
X15:
	mov REG[0xd0],>__r0
	mov A,[__r1]
	mov [__r0],A
	mov [__r1],0
	asl [__r0]
	asl [__r1]
	rlc [__r0]
	mov A,[__r1]
	add A,0
	mov [X+1],A
	mov A,[__r0]
	adc A,-128
	mov [X+0],A
	.dbline 292
; 	analog[9]=analog[9]-(analog[9]>>analogFilter[9])+(v>>analogFilter[9]);
	mov REG[0xd0],>_analogFilter
	mov A,[_analogFilter+9]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov A,[X+1]
	mov [__r3],A
	mov A,[X+0]
	mov [__r2],A
	mov A,[__r1]
	and A,15
	jz X16
X17:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r2]
	rrc [__r3]
	dec A
	jnz X17
X16:
	mov REG[0xd0],>_analogFilter
	mov A,[_analogFilter+9]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov REG[0xd0],>_analog
	mov A,[_analog+18+1]
	push A
	mov A,[_analog+18]
	mov REG[0xd0],>__r0
	mov [__r4],A
	pop A
	mov [__r5],A
	mov A,[__r1]
	and A,15
	jz X18
X19:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r4]
	rrc [__r5]
	dec A
	jnz X19
X18:
	mov REG[0xd0],>_analog
	mov A,[_analog+18+1]
	mov REG[0xd0],>__r0
	sub A,[__r5]
	mov [__r1],A
	mov REG[0xd0],>_analog
	mov A,[_analog+18]
	mov REG[0xd0],>__r0
	sbb A,[__r4]
	mov [__r0],A
	mov A,[__r1]
	add A,[__r3]
	mov REG[0xd0],>_analog
	mov [_analog+18+1],A
	mov REG[0xd0],>__r0
	mov A,[__r0]
	adc A,[__r2]
	mov REG[0xd0],>_analog
	mov [_analog+18],A
	.dbline 294
; 
; 	if (!DelSig_1_fIsDataAvailable())
	push X
	xcall _DelSig_1_fIsDataAvailable
	mov REG[0xd0],>__r0
	pop X
	cmp A,0
	jnz L72
	.dbline 295
; 		return;
	xjmp L61
L72:
	.dbline 297
; 
; 	v=DelSig_1_iGetDataClearFlag();
	push X
	xcall _DelSig_1_iGetDataClearFlag
	mov REG[0xd0],>__r0
	mov [__r0],X
	pop X
	mov [X+1],A
	mov A,[__r0]
	mov [X+0],A
	.dbline 299
; 
; 	analogDelay++;			// since the A/D is pipelined, we must throw out 2 samples after changing the mux.
	mov REG[0xd0],>_analogDelay
	inc [_analogDelay]
	.dbline 300
; 	if (analogDelay>=3)
	cmp [_analogDelay],3
	jc L74
X20:
	.dbline 301
; 	{
	.dbline 302
; 		v=v<<2; // left align
	asl [X+1]
	rlc [X+0]
	asl [X+1]
	rlc [X+0]
	.dbline 304
; 		
; 		analogDelay=0;	
	mov REG[0xd0],>_analogDelay
	mov [_analogDelay],0
	.dbline 305
; 		analog[analogNext]=analog[analogNext]-(analog[analogNext]>>analogFilter[analogNext])+(v>>analogFilter[analogNext]);
	mov REG[0xd0],>_analogNext
	mov A,[_analogNext]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	add [__r1],<_analog
	adc [__r0],>_analog
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r2],A
	mvi A,[__r1]
	sub [__r1],2
	mov [__r3],A
	mov REG[0xd0],>_analogNext
	mov A,[_analogNext]
	mov REG[0xd0],>__r0
	mov [__r5],A
	mov [__r4],0
	add [__r5],<_analogFilter
	adc [__r4],>_analogFilter
	mov A,[__r4]
	mov REG[0xd4],A
	mvi A,[__r5]
	mov [__r5],A
	mov A,[X+1]
	mov [__r7],A
	mov A,[X+0]
	mov [__r6],A
	mov A,[__r5]
	and A,15
	jz X21
X22:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r6]
	rrc [__r7]
	dec A
	jnz X22
X21:
	mov REG[0xd0],>__r0
	mov A,[__r3]
	push A
	mov A,[__r2]
	mov [__r8],A
	pop A
	mov [__r9],A
	mov A,[__r5]
	and A,15
	jz X23
X24:
	and F,-5
	mov REG[0xd0],>__r0
	rrc [__r8]
	rrc [__r9]
	dec A
	jnz X24
X23:
	mov REG[0xd0],>__r0
	mov A,[__r9]
	sub [__r3],A
	mov A,[__r8]
	sbb [__r2],A
	mov A,[__r7]
	add [__r3],A
	mov A,[__r6]
	adc [__r2],A
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[__r2]
	mvi [__r1],A
	mov A,[__r3]
	mvi [__r1],A
	.dbline 307
; 	
; 		if (analogNext==7)
	mov REG[0xd0],>_analogNext
	cmp [_analogNext],7
	jnz L76
	.dbline 308
; 		{
	.dbline 309
; 			M8C_DisableGInt;
		and F, FEh

	.dbline 310
; 	 		dtime=sleepcounter-lastgyrotime;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	mov REG[0xd0],>_lastgyrotime
	sub A,[_lastgyrotime+1]
	mov [X+7],A
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastgyrotime
	sbb A,[_lastgyrotime]
	mov [X+6],A
	.dbline 311
; 			lastgyrotime=sleepcounter;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	push A
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastgyrotime
	mov [_lastgyrotime],A
	pop A
	mov [_lastgyrotime+1],A
	.dbline 312
; 			M8C_EnableGInt;
		or  F, 01h

	.dbline 314
; 			
; 			sv=(signed int) (v-32768);
	mov REG[0xd0],>__r0
	mov A,[X+1]
	mov [__r3],A
	mov A,[X+0]
	mov [__r2],A
	sub [__r3],0
	sbb [__r2],-128
	mov A,[__r3]
	mov [__r1],A
	mov A,[__r2]
	mov [__r0],A
	mov A,[__r1]
	mov [X+5],A
	mov A,[__r0]
	mov [X+4],A
	tst [X+4],-128
	jz X25
	mov [X+3],-1
	mov [X+2],-1
	jmp X26
X25:
	mov [X+3],0
	mov [X+2],0
X26:
	.dbline 315
; 			sv*=dtime;
	mov REG[0xd0],>__r0
	mov A,[X+7]
	mov [__r3],A
	mov A,[X+6]
	mov [__r2],A
	mov A,0
	push A
	push A
	mov A,[__r2]
	push A
	mov A,[__r3]
	push A
	mov A,[X+2]
	push A
	mov A,[X+3]
	push A
	mov A,[X+4]
	push A
	mov A,[X+5]
	push A
	xcall __mul_32X32_32
	add SP,-4
	pop A
	mov [X+5],A
	pop A
	mov [X+4],A
	pop A
	mov [X+3],A
	pop A
	mov [X+2],A
	.dbline 316
; 			gyrocount+=sv;
	mov REG[0xd0],>_gyrocount
	mov A,[X+5]
	add [_gyrocount+3],A
	mov A,[X+4]
	adc [_gyrocount+2],A
	mov A,[X+3]
	adc [_gyrocount+1],A
	mov A,[X+2]
	adc [_gyrocount],A
	.dbline 317
; 		}
L76:
	.dbline 320
; 		
; 		// rotate the port
; 		analogNext=(analogNext+1)&7;
	mov REG[0xd0],>_analogNext
	mov A,[_analogNext]
	add A,1
	and A,7
	mov [_analogNext],A
	.dbline 321
; 		AMUX4_1_InputSelect(analogNext>>1);
	mov A,[_analogNext]
	mov REG[0xd0],>__r0
	mov [__r0],A
	and F,-5
	rrc [__r0]
	push X
	mov A,[__r0]
	xcall _AMUX4_1_InputSelect
	pop X
	.dbline 322
; 		AMUX4_2_InputSelect(analogNext>>1);
	mov REG[0xd0],>_analogNext
	mov A,[_analogNext]
	mov REG[0xd0],>__r0
	mov [__r0],A
	and F,-5
	rrc [__r0]
	push X
	mov A,[__r0]
	xcall _AMUX4_2_InputSelect
	pop X
	.dbline 324
; 		
; 		if (analogNext&1)
	mov REG[0xd0],>_analogNext
	tst [_analogNext],1
	jz L78
	.dbline 325
; 			ABF_CR0=ABF_CR0|0x80;
	or F,0x10  ; iopage = 1
	or REG[0x62],-128
	and F,0xEF ; iopage = 0
	xjmp L79
L78:
	.dbline 327
; 		else
; 			ABF_CR0=ABF_CR0&0x7f;
	or F,0x10  ; iopage = 1
	and REG[0x62],127
	and F,0xEF ; iopage = 0
L79:
	.dbline 328
L74:
	.dbline -2
	.dbline 329
; 	}	
; }
L61:
	add SP,-8
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l dtime 6 i
	.dbsym l sv 2 L
	.dbsym l v 0 i
	.dbend
	.dbfunc e doPad _doPad fV
;              c -> X+0
_doPad::
	.dbline -1
	push X
	mov X,SP
	add SP,3
	.dbline 336
; 
; 
; 
; /////////////////////////////// PAD ///////////////////////////////////////////
; 
; void doPad(void)
; {
	.dbline 337
; 	char c=ED_PAD_getData();
	push X
	xcall _ED_PAD_getData
	pop X
	mov [X+0],A
	.dbline 340
; 	
; 	// wait for header
; 	if (padbufpos==0 && c!=237)
	mov REG[0xd0],>_padbufpos
	cmp [_padbufpos],0
	jnz L81
	cmp [X+0],-19
	jz L81
	.dbline 341
; 	{
	.dbline 342
; 		badpadchars++;
	mov REG[0xd0],>_badpadchars
	inc [_badpadchars]
	.dbline 343
; 		return;
	xjmp L80
L81:
	.dbline 346
; 	}
; 		
; 	padbuf[padbufpos++]=c;
	mov REG[0xd0],>_padbufpos
	mov A,[_padbufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add A,1
	mov REG[0xd0],>_padbufpos
	mov [_padbufpos],A
	mov REG[0xd0],>__r0
	add [__r1],<_padbuf
	adc [__r0],>_padbuf
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[X+0]
	mvi [__r1],A
	.dbline 348
; 	
; 	if (padbufpos<2 || padbufpos<padbuf[1])
	mov REG[0xd0],>_padbufpos
	cmp [_padbufpos],2
	jc L86
X27:
	mov REG[0xd0],>_padbufpos
	mov A,[_padbufpos]
	mov REG[0xd0],>_padbuf
	cmp A,[_padbuf+1]
	jnc L83
X28:
L86:
	.dbline 349
; 		padbufchk=(padbufchk<<1) + c + (padbufchk&0x80 ? 1 : 0);
	mov REG[0xd0],>_padbufchk
	tst [_padbufchk],-128
	jz L88
	mov [X+2],1
	mov [X+1],0
	xjmp L89
L88:
	mov [X+2],0
	mov [X+1],0
L89:
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov REG[0xd0],>_padbufchk
	mov A,[_padbufchk]
	mov REG[0xd0],>__r0
	mov [__r3],A
	asl [__r3]
	mov A,[__r3]
	add A,[__r1]
	mov [__r1],A
	mov A,[X+2]
	add [__r1],A
	mov A,[__r1]
	mov REG[0xd0],>_padbufchk
	mov [_padbufchk],A
L83:
	.dbline 352
; 		
; 	// if we're too long, quit!
; 	if (padbufpos>=PADBUFSIZE)
	mov REG[0xd0],>_padbufpos
	cmp [_padbufpos],-128
	jc L90
X29:
	.dbline 353
; 		{
	.dbline 354
; 		padbufpos=0;
	mov REG[0xd0],>_padbufpos
	mov [_padbufpos],0
	.dbline 355
; 		padbufchk=0;
	mov REG[0xd0],>_padbufchk
	mov [_padbufchk],0
	.dbline 356
; 		return;
	xjmp L80
L90:
	.dbline 360
; 		}
; 	
; 	// wait for rest of packet. 
; 	if (padbuf[1]!=padbufpos)
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+1]
	mov REG[0xd0],>_padbufpos
	cmp A,[_padbufpos]
	jz L92
	.dbline 361
; 		return;
	xjmp L80
L92:
	.dbline 364
; 	
; 	// we have the whole packet now.
; 	if (padbufchk==padbuf[padbufpos-1])
	mov REG[0xd0],>_padbufpos
	mov A,[_padbufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_padbuf-1
	adc [__r0],>_padbuf-1
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mov REG[0xd0],>_padbufchk
	mov A,[_padbufchk]
	mov REG[0xd0],>__r0
	cmp A,[__r0]
	jnz L95
	.dbline 365
; 	{
	.dbline 366
; 		M8C_DisableGInt;
		and F, FEh

	.dbline 367
; 		lastPadReceivedTime=sleepcounter;
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter+1]
	push A
	mov A,[_sleepcounter]
	mov REG[0xd0],>_lastPadReceivedTime
	mov [_lastPadReceivedTime],A
	pop A
	mov [_lastPadReceivedTime+1],A
	.dbline 368
; 		M8C_EnableGInt;
		or  F, 01h

	.dbline 369
; 		doPadMessage();
	xcall _doPadMessage
	.dbline 370
; 	}
	xjmp L96
L95:
	.dbline 372
; 	else
; 	{
	.dbline 373
; 		badpadchars+=padbuf[1];
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+1]
	mov REG[0xd0],>_badpadchars
	add [_badpadchars],A
	.dbline 374
; 		commerror(1);
	mov A,1
	push A
	xcall _commerror
	add SP,-1
	.dbline 375
; 	}
L96:
	.dbline 378
; 		
; 	// handle the packet
; 	padbufpos=0;
	mov REG[0xd0],>_padbufpos
	mov [_padbufpos],0
	.dbline 379
; 	padbufchk=0;
	mov REG[0xd0],>_padbufchk
	mov [_padbufchk],0
	.dbline -2
	.dbline 380
; }
L80:
	add SP,-3
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c 0 c
	.dbend
	.dbfunc e doPadMessage _doPadMessage fV
;              i -> X+0
_doPadMessage::
	.dbline -1
	push X
	mov X,SP
	add SP,1
	.dbline 383
; 
; void doPadMessage()
; {
	.dbline 386
; 	unsigned char i;
; 	
; 	if (padbuf[3]=='*') // if this is a state packet, spy on it.
	mov REG[0xd0],>_padbuf
	cmp [_padbuf+3],42
	jnz L100
	.dbline 387
; 	{
	.dbline 388
; 		pad_joyx=padbuf[4];
	mov A,[_padbuf+4]
	mov REG[0xd0],>_pad_joyx
	mov [_pad_joyx],A
	.dbline 389
; 		pad_joyy=padbuf[5];
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+5]
	mov REG[0xd0],>_pad_joyy
	mov [_pad_joyy],A
	.dbline 390
; 		pad_buttons=padbuf[6];
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+6]
	mov REG[0xd0],>_pad_buttons
	mov [_pad_buttons],A
	.dbline 391
; 		pad_move_up=padbuf[7]>>4;
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+7]
	asr A
	asr A
	asr A
	asr A
	and A,15
	mov REG[0xd0],>_pad_move_up
	mov [_pad_move_up],A
	.dbline 392
; 		pad_move_down=padbuf[7]&0x0f;
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+7]
	and A,15
	mov REG[0xd0],>_pad_move_down
	mov [_pad_move_down],A
	.dbline 393
; 		pad_move_left=padbuf[8]>>4;
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+8]
	asr A
	asr A
	asr A
	asr A
	and A,15
	mov REG[0xd0],>_pad_move_left
	mov [_pad_move_left],A
	.dbline 394
; 		pad_move_right=padbuf[8]&0x0f;
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+8]
	and A,15
	mov REG[0xd0],>_pad_move_right
	mov [_pad_move_right],A
	.dbline 395
; 		pad_battery_voltage=(padbuf[9]<<8)+padbuf[10];
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+9]
	mov REG[0xd0],>_pad_battery_voltage
	mov [_pad_battery_voltage],A
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+10]
	mov REG[0xd0],>_pad_battery_voltage
	mov [_pad_battery_voltage+1],A
	.dbline 396
; 	}
L100:
	.dbline 398
; 	
; 	if (((padbuf[2]&0xc0)!=0xc0 || padbuf[3]=='*') && !indiag)
	mov REG[0xd0],>_padbuf
	mov A,[_padbuf+2]
	and A,-64
	cmp A,-64
	jnz L116
	cmp [_padbuf+3],42
	jnz L112
L116:
	mov REG[0xd0],>_indiag
	cmp [_indiag],0
	jnz L112
	.dbline 399
; 	{
	.dbline 401
; 		// forward the packet to the host
; 		for (i=0;i<padbufpos;i++)
	mov [X+0],0
	xjmp L120
L117:
	.dbline 402
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_padbuf
	adc [__r0],>_padbuf
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push X
	xcall _ED_HOST_putData
	pop X
L118:
	.dbline 401
	inc [X+0]
L120:
	.dbline 401
	mov REG[0xd0],>_padbufpos
	mov A,[X+0]
	cmp A,[_padbufpos]
	jc L117
X30:
	.dbline 403
; 			ED_HOST_putData(padbuf[i]);
; 		if (eventenable)
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L121
	.dbline 404
; 			ED_HOST_putData(EVENTCHAR);
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
L121:
	.dbline 405
; 	}
L112:
	.dbline 407
	mov REG[0xd0],>_padbuf
	cmp [_padbuf+2],-64
	jnz L123
	cmp [_padbuf+3],0
	jnz L123
	.dbline 408
	mov REG[0xd0],>_pad_ack_flag
	mov [_pad_ack_flag],1
L123:
	.dbline -2
	.dbline 409
; 
; 	if (padbuf[2]==0xc0 && padbuf[3]==0) // an ack?
; 		pad_ack_flag=1;
; }
L99:
	add SP,-1
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l i 0 c
	.dbend
	.dbfunc e doSlave _doSlave fV
;              c -> X+0
_doSlave::
	.dbline -1
	push X
	mov X,SP
	add SP,3
	.dbline 414
; 
; /////////////////////////////// SLAVE ///////////////////////////////////////////
; 
; void doSlave(void)
; {
	.dbline 415
; 	char c=ED_SLAVE_getData();
	push X
	xcall _ED_SLAVE_getData
	pop X
	mov [X+0],A
	.dbline 418
; 	
; 	// wait for header
; 	if (slavebufpos==0 && c!=237)
	mov REG[0xd0],>_slavebufpos
	cmp [_slavebufpos],0
	jnz L128
	cmp [X+0],-19
	jz L128
	.dbline 419
; 	{
	.dbline 420
; 		badslavechars++;
	mov REG[0xd0],>_badslavechars
	inc [_badslavechars]
	.dbline 421
; 		return;
	xjmp L127
L128:
	.dbline 424
; 	}
; 		
; 	slavebuf[slavebufpos++]=c;
	mov REG[0xd0],>_slavebufpos
	mov A,[_slavebufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add A,1
	mov REG[0xd0],>_slavebufpos
	mov [_slavebufpos],A
	mov REG[0xd0],>__r0
	add [__r1],<_slavebuf
	adc [__r0],>_slavebuf
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[X+0]
	mvi [__r1],A
	.dbline 426
; 	
; 	if (slavebufpos<2 || slavebufpos<slavebuf[1])
	mov REG[0xd0],>_slavebufpos
	cmp [_slavebufpos],2
	jc L133
X31:
	mov REG[0xd0],>_slavebufpos
	mov A,[_slavebufpos]
	mov REG[0xd0],>_slavebuf
	cmp A,[_slavebuf+1]
	jnc L130
X32:
L133:
	.dbline 427
; 		slavebufchk=(slavebufchk<<1) + c + (slavebufchk&0x80 ? 1 : 0);
	mov REG[0xd0],>_slavebufchk
	tst [_slavebufchk],-128
	jz L135
	mov [X+2],1
	mov [X+1],0
	xjmp L136
L135:
	mov [X+2],0
	mov [X+1],0
L136:
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov REG[0xd0],>_slavebufchk
	mov A,[_slavebufchk]
	mov REG[0xd0],>__r0
	mov [__r3],A
	asl [__r3]
	mov A,[__r3]
	add A,[__r1]
	mov [__r1],A
	mov A,[X+2]
	add [__r1],A
	mov A,[__r1]
	mov REG[0xd0],>_slavebufchk
	mov [_slavebufchk],A
L130:
	.dbline 430
; 	
; 	// if we're too long, quit!
; 	if (slavebufpos>=SLAVEBUFSIZE)
	mov REG[0xd0],>_slavebufpos
	cmp [_slavebufpos],64
	jc L137
X33:
	.dbline 431
; 		{
	.dbline 432
; 		slavebufpos=0;
	mov REG[0xd0],>_slavebufpos
	mov [_slavebufpos],0
	.dbline 433
; 		slavebufchk=0;
	mov REG[0xd0],>_slavebufchk
	mov [_slavebufchk],0
	.dbline 434
; 		return;
	xjmp L127
L137:
	.dbline 438
; 		}
; 	
; 	// wait for rest of packet. 
; 	if (slavebuf[1]!=slavebufpos)
	mov REG[0xd0],>_slavebuf
	mov A,[_slavebuf+1]
	mov REG[0xd0],>_slavebufpos
	cmp A,[_slavebufpos]
	jz L139
	.dbline 439
; 		return;
	xjmp L127
L139:
	.dbline 442
; 	
; 	// check checksum	
; 	if (slavebufchk==slavebuf[slavebufpos-1])
	mov REG[0xd0],>_slavebufpos
	mov A,[_slavebufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_slavebuf-1
	adc [__r0],>_slavebuf-1
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mov REG[0xd0],>_slavebufchk
	mov A,[_slavebufchk]
	mov REG[0xd0],>__r0
	cmp A,[__r0]
	jnz L142
	.dbline 443
; 		doSlaveMessage();
	xcall _doSlaveMessage
	xjmp L143
L142:
	.dbline 445
; 	else
; 	{
	.dbline 446
; 		badslavechars+=slavebuf[1];
	mov REG[0xd0],>_slavebuf
	mov A,[_slavebuf+1]
	mov REG[0xd0],>_badslavechars
	add [_badslavechars],A
	.dbline 447
; 		commerror(2);
	mov A,2
	push A
	xcall _commerror
	add SP,-1
	.dbline 448
; 	}
L143:
	.dbline 451
; 
; 	// handle the packet
; 	slavebufpos=0;
	mov REG[0xd0],>_slavebufpos
	mov [_slavebufpos],0
	.dbline 452
; 	slavebufchk=0;
	mov REG[0xd0],>_slavebufchk
	mov [_slavebufchk],0
	.dbline -2
	.dbline 453
; }
L127:
	add SP,-3
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c 0 c
	.dbend
	.dbfunc e doSlaveMessage _doSlaveMessage fV
;              i -> X+0
_doSlaveMessage::
	.dbline -1
	push X
	mov X,SP
	add SP,1
	.dbline 456
; 
; void doSlaveMessage()
; {
	.dbline 459
; 	unsigned char i;
; 	
; 	if (slavebuf[3]=='*') // if this is a state packet, spy on it.
	mov REG[0xd0],>_slavebuf
	cmp [_slavebuf+3],42
	jnz L147
	.dbline 460
; 	{
	.dbline 461
; 		for (i=0;i<slavebufpos;i++)
	mov [X+0],0
	xjmp L153
L150:
	.dbline 462
; 			{
	.dbline 463
; 			if (i<SLAVESTATEBUFSIZE)
	cmp [X+0],80
	jnc L154
X34:
	.dbline 464
; 				slavestate[i]=slavebuf[i];
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_slavebuf
	adc [__r0],>_slavebuf
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mov A,[X+0]
	mov [__r3],A
	mov [__r2],0
	add [__r3],<_slavestate
	adc [__r2],>_slavestate
	mov A,[__r2]
	mov REG[0xd5],A
	mov A,[__r0]
	mvi [__r3],A
L154:
	.dbline 465
L151:
	.dbline 461
	inc [X+0]
L153:
	.dbline 461
	mov REG[0xd0],>_slavebufpos
	mov A,[X+0]
	cmp A,[_slavebufpos]
	jc L150
X35:
	.dbline 466
; 			}		
; 	}
L147:
	.dbline 468
; 	
; 	if ((slavebuf[2]&0xc0)!=0xc0)
	mov REG[0xd0],>_slavebuf
	mov A,[_slavebuf+2]
	and A,-64
	mov REG[0xd0],>__r0
	cmp A,-64
	jz L156
	.dbline 469
; 	{
	.dbline 471
; 		// forward the packet to the host
; 		for (i=0;i<slavebufpos;i++)
	mov [X+0],0
	xjmp L162
L159:
	.dbline 472
	.dbline 473
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_slavebuf
	adc [__r0],>_slavebuf
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push X
	xcall _ED_HOST_putData
	pop X
	.dbline 474
L160:
	.dbline 471
	inc [X+0]
L162:
	.dbline 471
	mov REG[0xd0],>_slavebufpos
	mov A,[X+0]
	cmp A,[_slavebufpos]
	jc L159
X36:
	.dbline 476
; 			{
; 			ED_HOST_putData(slavebuf[i]);
; 			}
; 			
; 		if (eventenable)
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L163
	.dbline 477
; 			ED_HOST_putData(EVENTCHAR);
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
L163:
	.dbline 478
; 	}
L156:
	.dbline 480
	mov REG[0xd0],>_slavebuf
	mov A,[_slavebuf+2]
	and A,-64
	cmp A,-64
	jnz L165
	.dbline 481
	.dbline 482
	mov REG[0xd0],>_slave_ack
	mov [_slave_ack],1
	.dbline 483
L165:
	.dbline -2
	.dbline 484
; 
; 	if ((slavebuf[2]&0xc0)==0xc0)
; 	{
; 		slave_ack=1;
; 	}
; }
L146:
	add SP,-1
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l i 0 c
	.dbend
	.dbfunc e doHost _doHost fV
;              c -> X+1
;              i -> X+0
_doHost::
	.dbline -1
	push X
	mov X,SP
	add SP,4
	.dbline 489
; 
; /////////////////////////////// HOST ///////////////////////////////////////////
; 
; void doHost(void)
; {
	.dbline 492
; 	unsigned char i;
; 	
; 	char c=ED_HOST_getData();
	push X
	xcall _ED_HOST_getData
	pop X
	mov [X+1],A
	.dbline 495
; 	
; 	// wait for header
; 	if (hostbufpos==0 && c!=237)
	mov REG[0xd0],>_hostbufpos
	cmp [_hostbufpos],0
	jnz L169
	cmp [X+1],-19
	jz L169
	.dbline 496
; 	{
	.dbline 497
; 		badhostchars++;
	mov REG[0xd0],>_badhostchars
	inc [_badhostchars]
	.dbline 498
; 		return;
	xjmp L168
L169:
	.dbline 501
; 	}
; 		
; 	hostbuf[hostbufpos++]=c;
	mov REG[0xd0],>_hostbufpos
	mov A,[_hostbufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add A,1
	mov REG[0xd0],>_hostbufpos
	mov [_hostbufpos],A
	mov REG[0xd0],>__r0
	add [__r1],<_hostbuf
	adc [__r0],>_hostbuf
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[X+1]
	mvi [__r1],A
	.dbline 503
; 
; 	if (hostbufpos<2 || hostbufpos<hostbuf[1])
	mov REG[0xd0],>_hostbufpos
	cmp [_hostbufpos],2
	jc L174
X37:
	mov REG[0xd0],>_hostbufpos
	mov A,[_hostbufpos]
	mov REG[0xd0],>_hostbuf
	cmp A,[_hostbuf+1]
	jnc L171
X38:
L174:
	.dbline 504
; 		hostbufchk=(hostbufchk<<1) + c + (hostbufchk&0x80 ? 1 : 0);
	mov REG[0xd0],>_hostbufchk
	tst [_hostbufchk],-128
	jz L176
	mov [X+3],1
	mov [X+2],0
	xjmp L177
L176:
	mov [X+3],0
	mov [X+2],0
L177:
	mov REG[0xd0],>__r0
	mov A,[X+1]
	mov [__r1],A
	mov REG[0xd0],>_hostbufchk
	mov A,[_hostbufchk]
	mov REG[0xd0],>__r0
	mov [__r3],A
	asl [__r3]
	mov A,[__r3]
	add A,[__r1]
	mov [__r1],A
	mov A,[X+3]
	add [__r1],A
	mov A,[__r1]
	mov REG[0xd0],>_hostbufchk
	mov [_hostbufchk],A
L171:
	.dbline 507
; 		
; 	// if we're too long, quit!
; 	if (hostbufpos>=HOSTBUFSIZE)
	mov REG[0xd0],>_hostbufpos
	cmp [_hostbufpos],-128
	jc L178
X39:
	.dbline 508
; 		{
	.dbline 509
; 		hostbufpos=0;
	mov REG[0xd0],>_hostbufpos
	mov [_hostbufpos],0
	.dbline 510
; 		hostbufchk=0;
	mov REG[0xd0],>_hostbufchk
	mov [_hostbufchk],0
	.dbline 511
; 		return;
	xjmp L168
L178:
	.dbline 515
; 		}
; 	
; 	// wait for rest of packet. 
; 	if (hostbuf[1]!=hostbufpos)
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+1]
	mov REG[0xd0],>_hostbufpos
	cmp A,[_hostbufpos]
	jz L180
	.dbline 516
; 		return;
	xjmp L168
L180:
	.dbline 520
; 	
; 	// check the checksum...
; 	// we have the whole packet now.
; 	if (hostbufchk==hostbuf[hostbufpos-1])
	mov REG[0xd0],>_hostbufpos
	mov A,[_hostbufpos]
	mov REG[0xd0],>__r0
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_hostbuf-1
	adc [__r0],>_hostbuf-1
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mov REG[0xd0],>_hostbufchk
	mov A,[_hostbufchk]
	mov REG[0xd0],>__r0
	cmp A,[__r0]
	jnz L183
	.dbline 521
; 		{
	.dbline 522
; 		c=hostbuf[2]&0xc0;
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	and A,-64
	mov [X+1],A
	.dbline 523
; 		if (c==0x00) // host->master
	cmp [X+1],0
	jnz L187
	.dbline 524
; 			{
	.dbline 525
; 			doHostMessage();
	xcall _doHostMessage
	.dbline 526
; 			}
	xjmp L184
L187:
	.dbline 527
; 		else if (c==0x40) // host->slave
	cmp [X+1],64
	jnz L189
	.dbline 528
; 			{
	.dbline 529
; 			for (i=0;i<hostbufpos;i++)
	mov [X+0],0
	xjmp L194
L191:
	.dbline 530
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_hostbuf
	adc [__r0],>_hostbuf
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push X
	xcall _ED_SLAVE_putData
	pop X
L192:
	.dbline 529
	inc [X+0]
L194:
	.dbline 529
	mov REG[0xd0],>_hostbufpos
	mov A,[X+0]
	cmp A,[_hostbufpos]
	jc L191
X40:
	.dbline 531
; 				ED_SLAVE_putData(hostbuf[i]);
; 			}
	xjmp L184
L189:
	.dbline 532
; 		else if (c==0x80) // host->pad
	cmp [X+1],-128
	jnz L184
	.dbline 533
; 			{
	.dbline 534
; 			for (i=0;i<hostbufpos;i++)
	mov [X+0],0
	xjmp L200
L197:
	.dbline 535
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_hostbuf
	adc [__r0],>_hostbuf
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push X
	xcall _ED_PAD_putData
	pop X
L198:
	.dbline 534
	inc [X+0]
L200:
	.dbline 534
	mov REG[0xd0],>_hostbufpos
	mov A,[X+0]
	cmp A,[_hostbufpos]
	jc L197
X41:
	.dbline 536
; 				ED_PAD_putData(hostbuf[i]);
; 			}
	.dbline 537
; 		}
	xjmp L184
L183:
	.dbline 539
; 	else
; 	{
	.dbline 540
; 		badhostchars+=hostbuf[1];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+1]
	mov REG[0xd0],>_badhostchars
	add [_badhostchars],A
	.dbline 541
; 		commerror(3);
	mov A,3
	push A
	xcall _commerror
	add SP,-1
	.dbline 542
; 	}
L184:
	.dbline 545
; 	
; 	// reset
; 	hostbufpos=0;
	mov REG[0xd0],>_hostbufpos
	mov [_hostbufpos],0
	.dbline 546
; 	hostbufchk=0;
	mov REG[0xd0],>_hostbufchk
	mov [_hostbufchk],0
	.dbline -2
	.dbline 547
; }
L168:
	add SP,-4
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c 1 c
	.dbsym l i 0 c
	.dbend
	.dbfunc e doHostMessage _doHostMessage fV
;            err -> X+10
;            res -> X+9
;              v -> X+7
;          count -> X+3
;            chk -> X+2
;            len -> X+1
;           port -> X+0
_doHostMessage::
	.dbline -1
	push X
	mov X,SP
	add SP,11
	.dbline 552
; 
; #define OFFSET 3
; 
; void doHostMessage()
; {
	.dbline 556
; 	unsigned char port;
; 	unsigned int v;
; 	long count;
; 	unsigned char len=hostbuf[1]-4;
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+1]
	sub A,4
	mov [X+1],A
	.dbline 560
; 	unsigned char err, res;
; 	unsigned char chk;
; 	
; 	if (hostbuf[OFFSET]=='*' && len==1)
	cmp [_hostbuf+3],42
	jnz L204
	cmp [X+1],1
	jnz L204
	.dbline 561
; 	{
	.dbline 562
; 		sendPacket(hostbuf[2]);
	mov A,[_hostbuf+2]
	push A
	xcall _sendPacket
	add SP,-1
	.dbline 563
; 		return;
	xjmp L202
L204:
	.dbline 566
; 	}
; 
; 	if (hostbuf[OFFSET]=='X' && len==1)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],88
	jnz L208
	cmp [X+1],1
	jnz L208
	.dbline 567
; 	{
	.dbline 568
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	.dbline 569
; 		allstop(ALLSTOP_SOFTWAREREQ);
	mov A,3
	push A
	xcall _allstop
	add SP,-3
	.dbline 570
; 		return;
	xjmp L202
L208:
	.dbline 574
; 	}
; 	
; 	// set servo: Spvv
; 	if (hostbuf[OFFSET]=='S' && len==4)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],83
	jnz L212
	cmp [X+1],4
	jnz L212
	.dbline 575
; 	{
	.dbline 576
; 		port=hostbuf[OFFSET+1];
	mov A,[_hostbuf+4]
	mov [X+0],A
	.dbline 577
; 		v=(hostbuf[OFFSET+2]<<8)+hostbuf[OFFSET+3];
	mov A,[_hostbuf+5]
	mov [X+7],A
	mov A,[_hostbuf+6]
	mov [X+8],A
	.dbline 579
; 		
; 		if (port>=0 && port<=3)
	cmp [X+0],0
	jc L218
X42:
	mov A,3
	cmp A,[X+0]
	jc L218
X43:
	.dbline 580
; 		{
	.dbline 583
; 			// don't allow an interrupt while we're writing the new value
; 			// or we could (with low probability) read a bogus servo width.
; 			M8C_DisableGInt;
		and F, FEh

	.dbline 584
; 			servowidth[port]=v;
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	add [__r1],<_servowidth
	adc [__r0],>_servowidth
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[X+7]
	mvi [__r1],A
	mov A,[X+8]
	mvi [__r1],A
	.dbline 585
; 			M8C_EnableGInt;
		or  F, 01h

	.dbline 587
; 
; 			sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 588
; 			return;
	xjmp L202
L218:
	.dbline 591
; 		}
; 
; 		sendAck(hostbuf[2], EBADPORT);
	mov A,1
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 592
; 		return;
	xjmp L202
L212:
	.dbline 596
; 	}
; 	
; 	// digital write: Dpv
; 	if (hostbuf[OFFSET]=='D' && len==3)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],68
	jnz L222
	cmp [X+1],3
	jnz L222
	.dbline 597
; 	{
	.dbline 598
; 		port=hostbuf[OFFSET+1];
	mov A,[_hostbuf+4]
	mov [X+0],A
	.dbline 599
; 		v=hostbuf[OFFSET+2];
	mov A,[_hostbuf+5]
	mov REG[0xd0],>__r0
	mov [X+8],A
	mov [X+7],0
	.dbline 600
; 		if (port>15 || v>1)
	mov A,15
	cmp A,[X+0]
	jc L229
X44:
	mov A,1
	sub A,[X+8]
	mov A,0
	sbb A,[X+7]
	jnc L227
X45:
L229:
	.dbline 601
; 		{
	.dbline 602
; 			sendAck(hostbuf[2], EBADPORT);
	mov A,1
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 603
; 			return;
	xjmp L202
L227:
	.dbline 606
; 		}
; 		
; 		if (v>1)
	mov A,1
	sub A,[X+8]
	mov A,0
	sbb A,[X+7]
	jnc L231
X46:
	.dbline 607
; 		{
	.dbline 608
; 			sendAck(hostbuf[2], EBADPARAM);
	mov A,2
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 609
; 			return;
	xjmp L202
L231:
	.dbline 612
; 		}
; 		
; 		if (v)
	cmp [X+7],0
	jnz X47
	cmp [X+8],0
	jz L234
X47:
	.dbline 613
; 			v=0xff;
	mov [X+8],-1
	mov [X+7],0
L234:
	.dbline 615
; 			
; 		if (port<8)
	cmp [X+0],8
	jnc L236
X48:
	.dbline 616
; 		{
	.dbline 617
; 			port=1<<port;
	mov REG[0xd0],>__r0
	mov [__r0],1
	mov A,[X+0]
	and A,7
	jz X49
X50:
	mov REG[0xd0],>__r0
	asl [__r0]
	dec A
	jnz X50
X49:
	mov REG[0xd0],>__r0
	mov A,[__r0]
	mov [X+0],A
	.dbline 619
; 
; 			PRT2DR=(PRT2DR&prt2andmask&(~port))|prt2ormask|(v&port);
	mov A,[X+0]
	mov [__r1],A
	mov A,[X+8]
	and A,[__r1]
	mov [__r1],A
	mov REG[0xd0],>_prt2ormask
	mov A,[_prt2ormask]
	mov REG[0xd0],>__r0
	mov [__r3],A
	mov A,[X+0]
	cpl A
	mov [__r5],A
	mov REG[0xd0],>_prt2andmask
	mov A,[_prt2andmask]
	mov REG[0xd0],>__r0
	mov [__r7],A
	mov A,REG[0x8]
	and A,[__r7]
	and A,[__r5]
	or A,[__r3]
	or A,[__r1]
	mov REG[0x8],A
	.dbline 620
; 		}
	xjmp L237
L236:
	.dbline 622
; 		else
; 		{
	.dbline 623
; 			port=1<<(port-8);
	mov REG[0xd0],>__r0
	mov A,[X+0]
	sub A,8
	mov [__r2],1
	and A,7
	jz X51
X52:
	mov REG[0xd0],>__r0
	asl [__r2]
	dec A
	jnz X52
X51:
	mov REG[0xd0],>__r0
	mov A,[__r2]
	mov [X+0],A
	.dbline 624
; 			PRT0DR=(PRT0DR&prt0andmask&(~port))|prt0ormask|(v&port);
	mov A,[X+0]
	mov [__r1],A
	mov A,[X+8]
	and A,[__r1]
	mov [__r1],A
	mov REG[0xd0],>_prt0ormask
	mov A,[_prt0ormask]
	mov REG[0xd0],>__r0
	mov [__r3],A
	mov A,[X+0]
	cpl A
	mov [__r5],A
	mov REG[0xd0],>_prt0andmask
	mov A,[_prt0andmask]
	mov REG[0xd0],>__r0
	mov [__r7],A
	mov A,REG[ 0]
	and A,[__r7]
	and A,[__r5]
	or A,[__r3]
	or A,[__r1]
	mov REG[ 0],A
	.dbline 625
; 		}
L237:
	.dbline 627
; 		
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 628
; 		return;
	xjmp L202
L222:
	.dbline 632
; 	}
; 	
; 	// set mode:   Cpm
; 	if (hostbuf[OFFSET]=='C' && len==3)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],67
	jnz L239
	cmp [X+1],3
	jnz L239
	.dbline 633
; 	{
	.dbline 634
; 		port=hostbuf[OFFSET+1];
	mov A,[_hostbuf+4]
	mov [X+0],A
	.dbline 635
; 		v=hostbuf[OFFSET+2];
	mov A,[_hostbuf+5]
	mov REG[0xd0],>__r0
	mov [X+8],A
	mov [X+7],0
	.dbline 636
; 		err=setpinmode(port, v);
	mov A,[X+8]
	push A
	mov A,[X+0]
	push A
	xcall _setpinmode
	mov [X+10],A
	.dbline 638
; 
; 		sendAck(hostbuf[2], err);
	mov A,[X+10]
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-4
	.dbline 639
; 		return;		
	xjmp L202
L239:
	.dbline 643
; 	}
; 
; 	// set clock:  Kspw  (source, period, width)
; 	if (hostbuf[OFFSET]=='K' && len==4)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],75
	jnz L245
	cmp [X+1],4
	jnz L245
	.dbline 644
; 	{
	.dbline 645
; 		if (hostbuf[OFFSET+1]>0x0f)
	mov A,15
	cmp A,[_hostbuf+4]
	jnc L248
X53:
	.dbline 646
; 			{
	.dbline 647
; 			sendAck(hostbuf[2], EBADPARAM);
	mov A,2
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 648
; 			return;			
	xjmp L202
L248:
	.dbline 651
; 			}
; 		
; 		clockgenstate[0]=hostbuf[OFFSET+1];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+4]
	mov REG[0xd0],>_clockgenstate
	mov [_clockgenstate],A
	.dbline 652
; 		clockgenstate[1]=hostbuf[OFFSET+2];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+5]
	mov REG[0xd0],>_clockgenstate
	mov [_clockgenstate+1],A
	.dbline 653
; 		clockgenstate[2]=hostbuf[OFFSET+3];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+6]
	mov REG[0xd0],>_clockgenstate
	mov [_clockgenstate+2],A
	.dbline 658
; 		
; 	//	PWM8_CLOCK_Stop();
; 		
; 	//	PWM8_CLOCK_INPUT_REG=(PWM8_CLOCK_INPUT_REG&0xf0) | hostbuf[OFFSET+1];
; 		PWM8_CLOCK_WritePeriod(hostbuf[OFFSET+2]);
	push X
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+5]
	xcall _PWM8_CLOCK_WritePeriod
	.dbline 659
; 		PWM8_CLOCK_WritePulseWidth(hostbuf[OFFSET+3]);
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+6]
	xcall _PWM8_CLOCK_WritePulseWidth
	pop X
	.dbline 663
; 
; 	//	PWM8_CLOCK_Start();
; 
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 664
; 		return;
	xjmp L202
L245:
	.dbline 667
; 	}
; 	
; 	if (hostbuf[OFFSET]=='F' && len==3)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],70
	jnz L260
	cmp [X+1],3
	jnz L260
	.dbline 668
; 	{
	.dbline 669
; 		port=hostbuf[OFFSET+1];
	mov A,[_hostbuf+4]
	mov [X+0],A
	.dbline 670
; 		v=hostbuf[OFFSET+2];
	mov A,[_hostbuf+5]
	mov REG[0xd0],>__r0
	mov [X+8],A
	mov [X+7],0
	.dbline 672
; 
; 		if (port>9)
	mov A,9
	cmp A,[X+0]
	jnc L265
X54:
	.dbline 673
; 		{
	.dbline 674
; 			sendAck(hostbuf[2], EBADPORT);
	mov A,1
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 675
; 			return;
	xjmp L202
L265:
	.dbline 677
; 		}
; 		if (v>15)
	mov A,15
	sub A,[X+8]
	mov A,0
	sbb A,[X+7]
	jnc L268
X55:
	.dbline 678
; 		{
	.dbline 679
; 			sendAck(hostbuf[2], EBADPARAM);
	mov A,2
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 680
; 			return;
	xjmp L202
L268:
	.dbline 683
; 		}
; 			
; 		analogFilter[port]=v;
	mov REG[0xd0],>__r0
	mov A,[X+8]
	mov [__r0],A
	mov A,[X+0]
	mov [__r3],A
	mov [__r2],0
	add [__r3],<_analogFilter
	adc [__r2],>_analogFilter
	mov A,[__r2]
	mov REG[0xd5],A
	mov A,[__r0]
	mvi [__r3],A
	.dbline 684
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 685
; 		return;
	xjmp L202
L260:
	.dbline 689
; 	}
; 
; 	// set DAC:  Vv
; 	if (hostbuf[OFFSET]=='V' && len==2)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],86
	jnz L272
	cmp [X+1],2
	jnz L272
	.dbline 690
; 	{
	.dbline 691
; 		dac[0]=hostbuf[OFFSET+1];
	mov A,[_hostbuf+4]
	mov REG[0xd0],>_dac
	mov [_dac],A
	.dbline 692
; 		if (dac[0]>254)	// enforce wonky maximum value.
	mov A,-2
	cmp A,[_dac]
	jnc L276
X56:
	.dbline 693
; 			dac[0]=254;
	mov REG[0xd0],>_dac
	mov [_dac],-2
L276:
	.dbline 694
; 		DAC8_1_WriteBlind(dac[0]);
	push X
	mov REG[0xd0],>_dac
	mov A,[_dac]
	xcall _DAC8_1_WriteBlind
	pop X
	.dbline 695
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 696
; 		return;
	xjmp L202
L272:
	.dbline 702
; 	}
; 	
; 	// we've set the hardware to do a timer capture on a falling edge.
; 	// we must generate a >10uSec pulse. At 24 MHz, this means 240 cycles.
; 	// Rp
; 	if (hostbuf[OFFSET]=='R' && len==2) // sonaR.
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],82
	jnz L279
	cmp [X+1],2
	jnz L279
	.dbline 703
; 	{
	.dbline 704
; 		Timer16_SONAR_Stop();
	push X
	xcall _Timer16_SONAR_Stop
	pop X
	.dbline 706
; 
; 		port=hostbuf[OFFSET+1];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+4]
	mov [X+0],A
	.dbline 707
; 		if (port!=4 && port!=6)
	cmp [X+0],4
	jz L283
	cmp [X+0],6
	jz L283
	.dbline 708
; 			{
	.dbline 709
; 			sendAck(hostbuf[2], EBADPORT);
	mov A,1
	push A
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 710
; 			return;
	xjmp L202
L283:
	.dbline 713
; 			}
; 		
; 		if (port==4)
	cmp [X+0],4
	jnz L286
	.dbline 714
; 			{
	.dbline 715
; 			uslastport=0;
	mov REG[0xd0],>_uslastport
	mov [_uslastport],0
	.dbline 716
; 			uspingcount=(uspingcount&0xf0) | (((uspingcount&0x0f)+1)&0x0f);
	mov REG[0xd0],>_uspingcount
	mov A,[_uspingcount]
	and A,15
	mov REG[0xd0],>__r0
	mov [__r0],A
	add [__r0],1
	and [__r0],15
	mov REG[0xd0],>_uspingcount
	mov A,[_uspingcount]
	and A,-16
	mov REG[0xd0],>__r0
	or A,[__r0]
	mov REG[0xd0],>_uspingcount
	mov [_uspingcount],A
	.dbline 717
; 			}
	xjmp L287
L286:
	.dbline 719
; 		else
; 			{
	.dbline 720
; 			uslastport=1;
	mov REG[0xd0],>_uslastport
	mov [_uslastport],1
	.dbline 721
; 			uspingcount=(uspingcount&0x0f) | (((uspingcount&0xf0)+0x10)&0xf0);
	mov REG[0xd0],>_uspingcount
	mov A,[_uspingcount]
	and A,-16
	mov REG[0xd0],>__r0
	mov [__r0],A
	add [__r0],16
	and [__r0],-16
	mov REG[0xd0],>_uspingcount
	mov A,[_uspingcount]
	and A,15
	mov REG[0xd0],>__r0
	or A,[__r0]
	mov REG[0xd0],>_uspingcount
	mov [_uspingcount],A
	.dbline 722
; 			}
L287:
	.dbline 726
; 			
; 		// hook up pulse input; use row 1 or row 3 depending on port=4 or 6
; 		// (echo will be on pin 5 or 7)
; 		Timer16_SONAR_INPUT_LSB_REG=(Timer16_SONAR_INPUT_LSB_REG&0x0f) | ((0x0c+(port-4+1))<<4);
	mov REG[0xd0],>__r0
	mov A,[X+0]
	sub A,4
	mov [__r0],A
	add [__r0],1
	add [__r0],12
	mov A,[__r0]
	asl A
	asl A
	asl A
	asl A
	mov [__r0],A
	or F,0x10  ; iopage = 1
	mov A,REG[0x59]
	mov [__r2],A
	and [__r2],15
	mov A,[__r2]
	or A,[__r0]
	mov REG[0x59],A
	and F,0xEF ; iopage = 0
	.dbline 729
; 		
; 		// convert the port into a bit mask.
; 		port=1<<port;
	mov [__r0],1
	mov A,[X+0]
	and A,7
	jz X57
X58:
	mov REG[0xd0],>__r0
	asl [__r0]
	dec A
	jnz X58
X57:
	mov REG[0xd0],>__r0
	mov A,[__r0]
	mov [X+0],A
	.dbline 732
; 				
; 		// pulse goes high
; 		PRT2DR=(PRT2DR&prt2andmask&(~port))|prt2ormask|port;
	mov A,[X+0]
	cpl A
	mov [__r0],A
	mov A,REG[0x8]
	mov [__r2],A
	mov REG[0xd0],>_prt2andmask
	mov A,[_prt2andmask]
	mov REG[0xd0],>__r0
	and [__r2],A
	mov A,[__r2]
	and A,[__r0]
	mov [__r0],A
	mov REG[0xd0],>_prt2ormask
	mov A,[_prt2ormask]
	mov REG[0xd0],>__r0
	or [__r0],A
	mov A,[X+0]
	or [__r0],A
	mov A,[__r0]
	mov REG[0x8],A
	.dbline 735
	mov [X+3],0
	mov [X+4],0
	mov [X+5],0
	mov [X+6],0
L288:
	.dbline 735
L289:
	.dbline 735
; 
; 		// about 240 cycle delay
; 		for (count=0;count<5;count++);
	add [X+6],1
	adc [X+5],0
	adc [X+4],0
	adc [X+3],0
	.dbline 735
	mov A,[X+6]
	sub A,5
	mov A,[X+5]
	sbb A,0
	mov A,[X+4]
	sbb A,0
	mov A,[X+3]
	xor A,-128
	sbb A,(0 ^ 0x80)
	jc L288
X59:
	.dbline 738
; 				
; 		// intialize period to 0xffff and start timer
; 		Timer16_SONAR_WritePeriod(0xffff);
	push X
	mov A,-1
	mov X,A
	xcall _Timer16_SONAR_WritePeriod
	.dbline 739
; 		Timer16_SONAR_WriteCompareValue(0x0000);
	mov A,0
	mov X,A
	xcall _Timer16_SONAR_WriteCompareValue
	pop X
	.dbline 743
; 		
; 		// don't allow an interrupt to introduce unpredictable noise in our range
; 		// measurement
; 		M8C_DisableGInt;
		and F, FEh

	.dbline 745
; 
; 		Timer16_SONAR_Start();
	push X
	xcall _Timer16_SONAR_Start
	pop X
	.dbline 748
; 
; 		// pulse goes low		
; 		PRT2DR=(PRT2DR&prt2andmask&(~port))|prt2ormask;
	mov REG[0xd0],>__r0
	mov A,[X+0]
	cpl A
	mov [__r0],A
	mov A,REG[0x8]
	mov [__r2],A
	mov REG[0xd0],>_prt2andmask
	mov A,[_prt2andmask]
	mov REG[0xd0],>__r0
	and [__r2],A
	mov A,[__r2]
	and A,[__r0]
	mov [__r0],A
	mov REG[0xd0],>_prt2ormask
	mov A,[_prt2ormask]
	mov REG[0xd0],>__r0
	or [__r0],A
	mov A,[__r0]
	mov REG[0x8],A
	.dbline 750
; 
; 		M8C_EnableGInt;
		or  F, 01h

	.dbline 754
; 		
; 		// set reload-period to 0x0000 (so the timer stops at zero)
; 		// Timer16_SONAR_WritePeriod(0x0000);
; 		sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 756
; 
; 		return;
	xjmp L202
L279:
	.dbline 761
; 	}
; 	
; 	// combined write/read i2c transaction
; 	// J<addr><readlen><buf>
; 	if (hostbuf[OFFSET]=='J' && len>=3)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],74
	jnz L293
	cmp [X+1],3
	jc L293
X60:
	.dbline 762
; 	{
	.dbline 763
; 		res = I2Cm_1_bWriteBytes(hostbuf[OFFSET+1], &hostbuf[OFFSET+3], len-3, I2Cm_1_NoStop);
	push X
	mov A,2
	push A
	mov A,[X+1]
	sub A,3
	push A
	mov A,>_hostbuf+6
	push A
	mov A,<_hostbuf+6
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+4]
	push A
	xcall _I2Cm_1_bWriteBytes
	add SP,-5
	pop X
	mov [X+9],A
	.dbline 765
; 		
; 		if (!res)
	cmp [X+9],0
	jnz L298
	.dbline 766
; 		{
	.dbline 767
; 			sendAck(hostbuf[2], EI2CERR);
	mov A,4
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 768
; 			return;
	xjmp L202
L298:
	.dbline 771
; 		}
; 		
; 		len = hostbuf[OFFSET+2];
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+5]
	mov [X+1],A
	.dbline 772
; 		res = I2Cm_1_fReadBytes(hostbuf[OFFSET+1], &hostbuf[OFFSET+3], len, I2Cm_1_RepStart);
	push X
	mov A,1
	push A
	mov A,[X+1]
	push A
	mov A,>_hostbuf+6
	push A
	mov A,<_hostbuf+6
	push A
	mov A,[_hostbuf+4]
	push A
	xcall _I2Cm_1_fReadBytes
	add SP,-5
	pop X
	mov [X+9],A
	.dbline 774
; 		
; 		if (!res)
	cmp [X+9],0
	jnz L304
	.dbline 775
; 		{
	.dbline 776
; 			sendAck(hostbuf[2], EI2CERR);
	mov A,4
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 777
; 			return;
	xjmp L202
L304:
	.dbline 780
; 		}
; 
; 		chk=0;	
	mov [X+2],0
	.dbline 781
; 		chk = host_chksend(chk, 237);
	mov A,-19
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 782
; 		chk = host_chksend(chk, 5+len);
	mov A,[X+1]
	add A,5
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+2],A
	.dbline 783
; 		chk = host_chksend(chk, hostbuf[2]);
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 784
; 		chk = host_chksend(chk, ESUCCESS);
	mov A,0
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 785
; 		for (port=0;port<len;port++) // reusing port variable
	mov [X+0],0
	xjmp L311
L308:
	.dbline 786
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_hostbuf+6
	adc [__r0],>_hostbuf+6
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+2],A
L309:
	.dbline 785
	inc [X+0]
L311:
	.dbline 785
	mov A,[X+0]
	cmp A,[X+1]
	jc L308
X61:
	.dbline 787
; 			chk = host_chksend(chk, hostbuf[OFFSET+3+port]);
; 		chk = host_chksend(chk, chk);
	mov A,[X+2]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 789
; 
; 		return;	
	xjmp L202
L293:
	.dbline 793
; 	}
; 	
; 	// I2C write: I<addr><buf>
; 	if (hostbuf[OFFSET]=='I' && len>=2)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],73
	jnz L313
	cmp [X+1],2
	jc L313
X62:
	.dbline 794
; 	{
	.dbline 795
; 		res = I2Cm_1_bWriteBytes(hostbuf[OFFSET+1], &hostbuf[OFFSET+2], len-2, I2Cm_1_CompleteXfer);
	push X
	mov A,0
	push A
	mov A,[X+1]
	sub A,2
	push A
	mov A,>_hostbuf+5
	push A
	mov A,<_hostbuf+5
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+4]
	push A
	xcall _I2Cm_1_bWriteBytes
	add SP,-5
	pop X
	mov [X+9],A
	.dbline 797
; 		
; 		if (res)
	cmp [X+9],0
	jz L318
	.dbline 798
; 		{
	.dbline 799
; 			sendAck(hostbuf[2], ESUCCESS);
	mov A,0
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 800
; 		}
	xjmp L319
L318:
	.dbline 802
; 		else
; 		{
	.dbline 803
; 			sendAck(hostbuf[2], EI2CERR);
	mov A,4
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 804
; 		}
L319:
	.dbline 806
; 			
; 		if (eventenable)
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L202
	.dbline 807
; 			ED_HOST_putData(EVENTCHAR);
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
	.dbline 809
; 
; 		return;
	xjmp L202
L313:
	.dbline 813
; 	}
; 	
; 	// I2C read: i<addr><len>
; 	if (hostbuf[OFFSET]=='i' && len==3)
	mov REG[0xd0],>_hostbuf
	cmp [_hostbuf+3],105
	jnz L324
	cmp [X+1],3
	jnz L324
	.dbline 814
; 	{
	.dbline 815
; 		len=hostbuf[OFFSET+2];
	mov A,[_hostbuf+5]
	mov [X+1],A
	.dbline 817
; 
; 		res = I2Cm_1_fReadBytes(hostbuf[OFFSET+1], &hostbuf[OFFSET+2], len, I2Cm_1_CompleteXfer);
	push X
	mov A,0
	push A
	mov A,[X+1]
	push A
	mov A,>_hostbuf+5
	push A
	mov A,<_hostbuf+5
	push A
	mov A,[_hostbuf+4]
	push A
	xcall _I2Cm_1_fReadBytes
	mov REG[0xd0],>__r0
	add SP,-5
	pop X
	mov [X+9],A
	.dbline 819
; 		
; 		if (res)
	cmp [X+9],0
	jz L330
	.dbline 820
; 		{
	.dbline 821
; 			chk=0;	
	mov [X+2],0
	.dbline 822
; 			chk = host_chksend(chk, 237);
	mov A,-19
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 823
; 			chk = host_chksend(chk, 5+len);
	mov A,[X+1]
	add A,5
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+2],A
	.dbline 824
; 			chk = host_chksend(chk, hostbuf[2]);
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 825
; 			chk = host_chksend(chk, ESUCCESS);
	mov A,0
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 826
; 			for (port=0;port<len;port++) // reusing port variable
	mov [X+0],0
	xjmp L336
L333:
	.dbline 827
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_hostbuf+5
	adc [__r0],>_hostbuf+5
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+2],A
L334:
	.dbline 826
	inc [X+0]
L336:
	.dbline 826
	mov A,[X+0]
	cmp A,[X+1]
	jc L333
X63:
	.dbline 828
; 				chk = host_chksend(chk, hostbuf[OFFSET+2+port]);
; 			chk = host_chksend(chk, chk);
	mov A,[X+2]
	push A
	mov A,[X+2]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+2],A
	.dbline 829
; 		}
	xjmp L331
L330:
	.dbline 831
; 		else
; 		{
	.dbline 832
; 			sendAck(hostbuf[2], EI2CERR);
	mov A,4
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline 833
; 		}
L331:
	.dbline 835
; 	
; 		if (eventenable)
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L202
	.dbline 836
; 			ED_HOST_putData(EVENTCHAR);
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
	.dbline 838
; 	
; 		return;
	xjmp L202
L324:
	.dbline 841
; 	}
; 	
; 	sendAck(hostbuf[2], EUNKNOWNCMD);
	mov A,3
	push A
	mov REG[0xd0],>_hostbuf
	mov A,[_hostbuf+2]
	push A
	xcall _sendAck
	add SP,-2
	.dbline -2
	.dbline 842
; }
L202:
	add SP,-11
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l err 10 c
	.dbsym l res 9 c
	.dbsym l v 7 i
	.dbsym l count 3 L
	.dbsym l chk 2 c
	.dbsym l len 1 c
	.dbsym l port 0 c
	.dbend
	.dbfunc e setpinmode _setpinmode fc
;            dm0 -> X+7
;            dm1 -> X+6
;            dm2 -> X+5
;       clearbit -> X+4
;        andmask -> X+3
;         ormask -> X+2
;             gs -> X+1
;           mask -> X+0
;           mode -> X-5
;            pin -> X-4
_setpinmode::
	.dbline -1
	push X
	mov X,SP
	add SP,10
	.dbline 846
; 
; // returns non-zero on error
; unsigned char setpinmode(unsigned char pin, unsigned char mode)
; {
	.dbline 848
; unsigned char mask;						// the bit mask for this pin
; unsigned char dm2, dm1, dm0, gs=0; 		// direction mode bits and global select
	mov [X+1],0
	.dbline 849
; unsigned char ormask=0, andmask=0xff;	// whether this pin will be prevented from going hi/low
	mov [X+2],0
	.dbline 849
	mov [X+3],-1
	.dbline 850
; unsigned char clearbit=0;				// whether this pin will have a zero written to it
	mov [X+4],0
	.dbline 884
; 
; // Summary of Tech Ref Manual info:
; // Each pin described by three bits, called DM2, DM1, and DM0.
; // Each bit is stored in a different register.
; //
; // DM: 2 1 0	Pin Output High    Pin Output Low    Notes
; // ----------   ----------------   ----------------  -------------------
; //     0 0 0         Strong           Resistive		 "pull down", set out=1
; //     0 0 1         Strong            Strong        "totem pole"
; //     0 1 0          Hi-Z              Hi-Z         Digital Input Enabled
; //     0 1 1        Resistive          Strong        "pull up", set out=0
; //     1 0 0          Weak              Hi-Z         
; //     1 0 1          Weak              Weak         "weak totem pole"
; //     1 1 0          Hi-Z				Hi-Z         Analog Input
; //     1 1 1          Hi-Z              Weak         I2C-Compat.
; //
; // PRTxGS port connects the pin to its corresponding global bus.
; // If DM210=010, it connects to global input
; // Otherwise, it connects to global output.
; //
; // Note: 
; // If using pull-ups, you MUST write '0's to the corresponding bit whenever
; // you write to PRTxDR. Likewise, when using pull-downs, you MUST write '1's to 
; // the corresponding bit.
; //
; // Here's our general scheme: for a given pin, it can have any of a number of
; // "standard" modes (dig in/out, analog in for some pins). The "special" modes, 
; // such as servo, sonar_echo, are activated by setting the corresponding GS pin.
; // We "preconfigure" all of the special modes so that by setting the GS pin, it 
; // becomes appropriately connected. Note that this means that any given pin can only
; // have a single "special" function.
; 
; // catch illegal arguments 
; if (pin>15)   // illegal pin number
	mov A,15
	cmp A,[X-4]
	jnc L343
X65:
	.dbline 885
; 	return EBADPORT;
	mov REG[0xd0],>__r0
	mov A,1
	xjmp L342
L343:
	.dbline 887
; 
; if (mode>PINMODE_MAX)
	mov A,12
	cmp A,[X-5]
	jnc L345
X66:
	.dbline 888
; 	return EBADPARAM;
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L345:
	.dbline 890
; 		
; if (mode==PINMODE_ANALOG_IN && !(pin>=8 || pin==0 || pin==3))
	cmp [X-5],8
	jnz L347
	cmp [X-4],8
	jnc L347
X67:
	cmp [X-4],0
	jz L347
	cmp [X-4],3
	jz L347
	.dbline 891
; 	return EBADPARAM; // can't do analog on that pin.
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L347:
	.dbline 893
; 
; if (mode==PINMODE_SERVO && pin>3)
	cmp [X-5],5
	jnz L349
	mov A,3
	cmp A,[X-4]
	jnc L349
X68:
	.dbline 894
; 	return EBADPARAM; // can't do servo on that pin
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L349:
	.dbline 896
; 
; if (mode==PINMODE_SONAR_PING && !(pin==4 || pin==6))
	cmp [X-5],6
	jnz L351
	cmp [X-4],4
	jz L351
	cmp [X-4],6
	jz L351
	.dbline 897
; 	return EBADPARAM;
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L351:
	.dbline 899
; 
; if (mode==PINMODE_SONAR_ECHO && !(pin==5 || pin==7))
	cmp [X-5],7
	jnz L353
	cmp [X-4],5
	jz L353
	cmp [X-4],7
	jz L353
	.dbline 900
; 	return EBADPARAM;
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L353:
	.dbline 902
; 
; if (mode==PINMODE_CLOCK_OUT && !(pin==14))
	cmp [X-5],10
	jnz L355
	cmp [X-4],14
	jz L355
	.dbline 903
; 	return EBADPARAM;
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L355:
	.dbline 905
; 
; if (mode==PINMODE_ANALOG_OUT && !(pin==12))
	cmp [X-5],9
	jnz L357
	cmp [X-4],12
	jz L357
	.dbline 906
; 	return EBADPARAM;
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L357:
	.dbline 910
; 	
; 
; // Look-up table for our mode pins.
; switch (mode)
	mov A,[X-5]
	mov [X+9],A
	mov [X+8],0
	cmp [X+8],0
	jnz X69
	cmp [X+9],0
	jz L362
X69:
	cmp [X+8],0
	jnz X70
	cmp [X+9],1
	jz L363
X70:
	cmp [X+8],0
	jnz X71
	cmp [X+9],2
	jz L364
X71:
	cmp [X+8],0
	jnz X72
	cmp [X+9],3
	jz L366
X72:
	cmp [X+8],0
	jnz X73
	cmp [X+9],4
	jz L367
X73:
	cmp [X+8],0
	jnz X74
	cmp [X+9],5
	jz L368
X74:
	cmp [X+8],0
	jnz X75
	cmp [X+9],6
	jz L365
X75:
	cmp [X+8],0
	jnz X76
	cmp [X+9],7
	jz L369
X76:
	cmp [X+8],0
	jnz X77
	cmp [X+9],8
	jz L370
X77:
	cmp [X+8],0
	jnz X78
	cmp [X+9],9
	jz L370
X78:
	cmp [X+8],0
	jnz X79
	cmp [X+9],10
	jz L368
X79:
	xjmp L359
X64:
	.dbline 911
; 	{
L362:
	.dbline 913
; 	case PINMODE_DIG_IN:
; 		dm2=0x00; dm1=0xff; dm0=0x00;
	mov [X+5],0
	.dbline 913
	mov [X+6],-1
	.dbline 913
	mov [X+7],0
	.dbline 914
; 	break;
	xjmp L360
L363:
	.dbline 917
; 	
; 	case PINMODE_DIG_IN_PULLUP:
; 		dm2=0x00; dm1=0xff; dm0=0xff;
	mov [X+5],0
	.dbline 917
	mov [X+6],-1
	.dbline 917
	mov [X+7],-1
	.dbline 918
; 		ormask=0xff;
	mov [X+2],-1
	.dbline 919
; 	break;
	xjmp L360
L364:
	.dbline 922
; 
; 	case PINMODE_DIG_IN_PULLDN:
; 		dm2=0x00; dm1=0x00; dm0=0x00;
	mov [X+5],0
	.dbline 922
	mov [X+6],0
	.dbline 922
	mov [X+7],0
	.dbline 923
; 		andmask=0x00;
	mov [X+3],0
	.dbline 924
; 		break;
	xjmp L360
L365:
	.dbline 927
; 
; 	case PINMODE_SONAR_PING:
; 		clearbit=1;
	mov [X+4],1
L366:
	.dbline 930
; 		// fallthrough
; 	case PINMODE_DIG_OUT_STRONG:
; 		dm2=0x00; dm1=0x00; dm0=0xff;
	mov [X+5],0
	.dbline 930
	mov [X+6],0
	.dbline 930
	mov [X+7],-1
	.dbline 931
; 		break;
	xjmp L360
L367:
	.dbline 934
; 		
; 	case PINMODE_DIG_OUT_SLOW:
; 		dm2=0xff; dm1=0x00; dm0=0xff;
	mov [X+5],-1
	.dbline 934
	mov [X+6],0
	.dbline 934
	mov [X+7],-1
	.dbline 935
; 		break;
	xjmp L360
L368:
	.dbline 939
; 	
; 	case PINMODE_CLOCK_OUT:
; 	case PINMODE_SERVO:
; 		dm2=0x00; dm1=0x00; dm0=0xff; gs=0xff;
	mov [X+5],0
	.dbline 939
	mov [X+6],0
	.dbline 939
	mov [X+7],-1
	.dbline 939
	mov [X+1],-1
	.dbline 940
; 		break;
	xjmp L360
L369:
	.dbline 943
; 	
; 	case PINMODE_SONAR_ECHO:
; 		dm2=0x00; dm1=0xff; dm0=0x00; gs=0xff;
	mov [X+5],0
	.dbline 943
	mov [X+6],-1
	.dbline 943
	mov [X+7],0
	.dbline 943
	mov [X+1],-1
	.dbline 944
; 		break;	
	xjmp L360
L370:
	.dbline 948
; 
; 	case PINMODE_ANALOG_OUT:
; 	case PINMODE_ANALOG_IN:
; 		dm2=0xff; dm1=0xff; dm0=0x00;
	mov [X+5],-1
	.dbline 948
	mov [X+6],-1
	.dbline 948
	mov [X+7],0
	.dbline 949
; 		break;	
	xjmp L360
L359:
	.dbline 952
; 		
; 	default:
; 		return EBADPARAM; // unknown pin type
	mov REG[0xd0],>__r0
	mov A,2
	xjmp L342
L360:
	.dbline 955
; 	}
; 
; if (pin==12)
	cmp [X-4],12
	jnz L371
	.dbline 956
; {
	.dbline 957
; 	if (mode!=PINMODE_ANALOG_OUT)
	cmp [X-5],9
	jz L373
	.dbline 958
; 		ABF_CR0&=~(0x10);
	or F,0x10  ; iopage = 1
	and REG[0x62],-17
	and F,0xEF ; iopage = 0
	xjmp L374
L373:
	.dbline 960
; 	else
; 		ABF_CR0|=(0x10);
	or F,0x10  ; iopage = 1
	or REG[0x62],16
	and F,0xEF ; iopage = 0
L374:
	.dbline 961
; }
L371:
	.dbline 963
; 
; if (pin<=7)
	mov A,7
	cmp A,[X-4]
	jc L375
X80:
	.dbline 964
; 	{
	.dbline 965
; 	mask=1<<pin;
	mov REG[0xd0],>__r0
	mov [__r0],1
	mov A,[X-4]
	and A,7
	jz X81
X82:
	mov REG[0xd0],>__r0
	asl [__r0]
	dec A
	jnz X82
X81:
	mov REG[0xd0],>__r0
	mov A,[__r0]
	mov [X+0],A
	.dbline 966
; 	PRT2DM2=(PRT2DM2&(~mask)) | (dm2&mask);
	mov A,[X+5]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[0xb]
	and A,[__r2]
	or A,[__r0]
	mov REG[0xb],A
	.dbline 967
; 	PRT2DM1=(PRT2DM1&(~mask)) | (dm1&mask);
	mov A,[X+6]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	or F,0x10  ; iopage = 1
	mov A,REG[0x9]
	and A,[__r2]
	or A,[__r0]
	mov REG[0x9],A
	.dbline 968
; 	PRT2DM0=(PRT2DM0&(~mask)) | (dm0&mask);
	mov A,[X+7]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[0x8]
	and A,[__r2]
	or A,[__r0]
	mov REG[0x8],A
	and F,0xEF ; iopage = 0
	.dbline 969
; 	PRT2GS =(PRT2GS&(~mask))  | (gs&mask);
	mov A,[X+1]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[0xa]
	and A,[__r2]
	or A,[__r0]
	mov REG[0xa],A
	.dbline 970
; 	prt2andmask = (prt2andmask&(~mask)) | (andmask&mask);
	mov A,[X+3]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov REG[0xd0],>_prt2andmask
	mov A,[_prt2andmask]
	mov REG[0xd0],>__r0
	and A,[__r2]
	or A,[__r0]
	mov REG[0xd0],>_prt2andmask
	mov [_prt2andmask],A
	.dbline 971
; 	prt2ormask  = (prt2ormask&(~mask))  | (ormask&mask);
	mov REG[0xd0],>__r0
	mov A,[X+2]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov REG[0xd0],>_prt2ormask
	mov A,[_prt2ormask]
	mov REG[0xd0],>__r0
	and A,[__r2]
	or A,[__r0]
	mov REG[0xd0],>_prt2ormask
	mov [_prt2ormask],A
	.dbline 973
; 	
; 	PRT2DR=(PRT2DR&prt2andmask) | prt2ormask;
	mov A,REG[0x8]
	mov REG[0xd0],>__r0
	mov [__r0],A
	mov REG[0xd0],>_prt2andmask
	mov A,[_prt2andmask]
	mov REG[0xd0],>__r0
	and [__r0],A
	mov REG[0xd0],>_prt2ormask
	mov A,[_prt2ormask]
	mov REG[0xd0],>__r0
	or [__r0],A
	mov A,[__r0]
	mov REG[0x8],A
	.dbline 975
; 	
; 	if (clearbit)
	cmp [X+4],0
	jz L376
	.dbline 976
; 		PRT2DR=PRT2DR&(~mask);
	mov A,[X+0]
	cpl A
	mov [__r0],A
	mov A,REG[0x8]
	and A,[__r0]
	mov REG[0x8],A
	.dbline 977
; 	}
	xjmp L376
L375:
	.dbline 979
; else
; 	{
	.dbline 980
; 	mask=1<<(pin-8);
	mov REG[0xd0],>__r0
	mov A,[X-4]
	sub A,8
	mov [__r2],1
	and A,7
	jz X83
X84:
	mov REG[0xd0],>__r0
	asl [__r2]
	dec A
	jnz X84
X83:
	mov REG[0xd0],>__r0
	mov A,[__r2]
	mov [X+0],A
	.dbline 981
; 	PRT0DM2=(PRT0DM2&(~mask)) | (dm2&mask);
	mov A,[X+5]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[0x3]
	and A,[__r2]
	or A,[__r0]
	mov REG[0x3],A
	.dbline 982
; 	PRT0DM1=(PRT0DM1&(~mask)) | (dm1&mask);
	mov A,[X+6]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	or F,0x10  ; iopage = 1
	mov A,REG[0x1]
	and A,[__r2]
	or A,[__r0]
	mov REG[0x1],A
	.dbline 983
; 	PRT0DM0=(PRT0DM0&(~mask)) | (dm0&mask);
	mov A,[X+7]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[ 0]
	and A,[__r2]
	or A,[__r0]
	mov REG[ 0],A
	and F,0xEF ; iopage = 0
	.dbline 984
; 	PRT0GS =(PRT0GS&(~mask))  | (gs&mask);	
	mov A,[X+1]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov A,REG[0x2]
	and A,[__r2]
	or A,[__r0]
	mov REG[0x2],A
	.dbline 985
; 	prt0andmask = (prt0andmask&(~mask)) | (andmask&mask);
	mov A,[X+3]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov REG[0xd0],>_prt0andmask
	mov A,[_prt0andmask]
	mov REG[0xd0],>__r0
	and A,[__r2]
	or A,[__r0]
	mov REG[0xd0],>_prt0andmask
	mov [_prt0andmask],A
	.dbline 986
; 	prt0ormask  = (prt0ormask&(~mask))  | (ormask&mask);
	mov REG[0xd0],>__r0
	mov A,[X+2]
	and A,[X+0]
	mov [__r0],A
	mov A,[X+0]
	cpl A
	mov [__r2],A
	mov REG[0xd0],>_prt0ormask
	mov A,[_prt0ormask]
	mov REG[0xd0],>__r0
	and A,[__r2]
	or A,[__r0]
	mov REG[0xd0],>_prt0ormask
	mov [_prt0ormask],A
	.dbline 988
; 
; 	PRT0DR=(PRT0DR&prt0andmask) | prt0ormask;
	mov A,REG[ 0]
	mov REG[0xd0],>__r0
	mov [__r0],A
	mov REG[0xd0],>_prt0andmask
	mov A,[_prt0andmask]
	mov REG[0xd0],>__r0
	and [__r0],A
	mov REG[0xd0],>_prt0ormask
	mov A,[_prt0ormask]
	mov REG[0xd0],>__r0
	or [__r0],A
	mov A,[__r0]
	mov REG[ 0],A
	.dbline 989
; 	if (clearbit)
	cmp [X+4],0
	jz L379
	.dbline 990
; 		PRT0DR=PRT0DR&(~mask);
	mov A,[X+0]
	cpl A
	mov [__r0],A
	mov A,REG[ 0]
	and A,[__r0]
	mov REG[ 0],A
L379:
	.dbline 991
; 	}
L376:
	.dbline 993
; 
; pinmode[pin]=mode;
	mov REG[0xd0],>__r0
	mov A,[X-4]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_pinmode
	adc [__r0],>_pinmode
	mov A,[__r0]
	mov REG[0xd5],A
	mov A,[X-5]
	mvi [__r1],A
	.dbline 995
; 
; return ESUCCESS;
	mov A,0
	.dbline -2
L342:
	add SP,-10
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l dm0 7 c
	.dbsym l dm1 6 c
	.dbsym l dm2 5 c
	.dbsym l clearbit 4 c
	.dbsym l andmask 3 c
	.dbsym l ormask 2 c
	.dbsym l gs 1 c
	.dbsym l mask 0 c
	.dbsym l mode -5 c
	.dbsym l pin -4 c
	.dbend
	.dbfunc e allstop _allstop fV
;           type -> X-4
_allstop::
	.dbline -1
	push X
	mov X,SP
	.dbline 999
; }
; 
; void allstop(unsigned char type)
; {
	.dbline 1000
; 	slave_allstop();
	xcall _slave_allstop
	.dbline 1002
; 	
; 	pad_LcdClear();
	xcall _pad_LcdClear
	.dbline 1003
; 	allowhost=0;
	mov REG[0xd0],>_allowhost
	mov [_allowhost],0
	.dbline 1007
; 	
; 	//                          1234567890123456
; 	
; 	pad_LcdPrintC(0x00, 0x08, 'd', "                ");
	mov A,>L382
	push A
	mov A,<L382
	push A
	mov A,100
	push A
	mov A,8
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	.dbline 1008
; 	pad_LcdPrintC(0x00, 0x10, 'd', "    All Stop    ");
	mov A,>L383
	push A
	mov A,<L383
	push A
	mov A,100
	push A
	mov A,16
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-10
	.dbline 1011
; 
; 
; 	pad_LcdPrintC(0x00, 0x20, 'B', "Hit stick button");
	mov A,>L384
	push A
	mov A,<L384
	push A
	mov A,66
	push A
	mov A,32
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	.dbline 1012
; 	pad_LcdPrintC(0x00, 0x28, 'B', "to resume.");
	mov A,>L385
	push A
	mov A,<L385
	push A
	mov A,66
	push A
	mov A,40
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-10
	.dbline 1014
; 
; 	if (type==ALLSTOP_PADTIMEOUT)
	cmp [X-4],1
	jnz L386
	.dbline 1015
; 		pad_LcdPrintC(0x00, 0x38, 'd', "  (Pad Timeout) ");
	mov A,>L388
	push A
	mov A,<L388
	push A
	mov A,100
	push A
	mov A,56
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L394
L386:
	.dbline 1016
; 	else if (type==ALLSTOP_STOPBUTTON)
	cmp [X-4],2
	jnz L389
	.dbline 1017
; 		pad_LcdPrintC(0x00, 0x38, 'd', "  (Stop Button) ");
	mov A,>L391
	push A
	mov A,<L391
	push A
	mov A,100
	push A
	mov A,56
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L394
L389:
	.dbline 1019
; 	else
; 		pad_LcdPrintC(0x00, 0x38, 'd', "   (Soft Halt)  ");
	mov A,>L392
	push A
	mov A,<L392
	push A
	mov A,100
	push A
	mov A,56
	push A
	mov A,0
	push A
	xcall _pad_LcdPrintC
	add SP,-5
	xjmp L394
L393:
	.dbline 1023
	xcall _slave_allstop
L394:
	.dbline 1022
; 	
; 	// wait for them to release the stop button
; 	while (pad_pollButtons()!=0)
	xcall _pad_pollButtons
	mov REG[0xd0],>__r0
	cmp A,0
	jnz L393
L396:
	.dbline 1026
L397:
	.dbline 1026
; 		slave_allstop();
; 	
; 	// wait for them to press the menu/stick button
; 	while ((pad_pollButtons()&(PAD_MENU | PAD_STICK))==0);
	xcall _pad_pollButtons
	mov REG[0xd0],>__r0
	mov [__r0],A
	tst [__r0],48
	jz L396
	.dbline 1029
; 	
; 	// wait for them to release the menu/stick button
; 	pad_waitButtonRelease();
	xcall _pad_waitButtonRelease
	.dbline 1031
; 	
; 	pad_LcdClear();
	xcall _pad_LcdClear
	.dbline 1034
; 
; 	// reset all our comms buffers
; 	ED_HOST_init();
	push X
	xcall _ED_HOST_init
	pop X
	.dbline 1036
; 	
; 	allowhost=1;
	mov REG[0xd0],>_allowhost
	mov [_allowhost],1
	.dbline -2
	.dbline 1038
; 
; }
L381:
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l type -4 c
	.dbend
	.dbfunc e host_chksend _host_chksend fc
;              c -> X-5
;            chk -> X-4
_host_chksend::
	.dbline -1
	push X
	mov X,SP
	add SP,2
	.dbline 1041
; 
; unsigned char host_chksend(unsigned char chk, unsigned char c)
; {
	.dbline 1042
; 	ED_HOST_putData(c);
	push X
	mov A,[X-5]
	xcall _ED_HOST_putData
	pop X
	.dbline 1044
; 	
; 	return (chk<<1)+c+(chk&0x80 ? 1 : 0);
	tst [X-4],-128
	jz L401
	mov [X+1],1
	mov [X+0],0
	xjmp L402
L401:
	mov [X+1],0
	mov [X+0],0
L402:
	mov REG[0xd0],>__r0
	mov A,[X-4]
	mov [__r1],A
	asl [__r1]
	mov A,[X-5]
	add [__r1],A
	mov A,[X+1]
	add [__r1],A
	mov A,[__r1]
	.dbline -2
L399:
	add SP,-2
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c -5 c
	.dbsym l chk -4 c
	.dbend
	.dbfunc e host_chksendi _host_chksendi fc
;              c -> X-6
;            chk -> X-4
_host_chksendi::
	.dbline -1
	push X
	mov X,SP
	.dbline 1048
; }
; 
; unsigned char host_chksendi(unsigned char chk, unsigned int c)
; {
	.dbline 1049
; 	chk = host_chksend(chk, c>>8);
	mov REG[0xd0],>__r0
	mov A,[X-6]
	push A
	mov A,[X-4]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X-4],A
	.dbline 1050
; 	chk = host_chksend(chk, c&0xff);
	mov A,[X-5]
	push A
	mov A,[X-4]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X-4],A
	.dbline 1051
; 	return chk;
	mov A,[X-4]
	.dbline -2
L403:
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c -6 i
	.dbsym l chk -4 c
	.dbend
	.dbfunc e sendAck _sendAck fV
;            chk -> X+0
;          error -> X-5
;          flags -> X-4
_sendAck::
	.dbline -1
	push X
	mov X,SP
	add SP,1
	.dbline 1056
	.dbline 1057
	mov [X+0],0
	.dbline 1058
	mov A,-19
	push A
	mov A,[X+0]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+0],A
	.dbline 1059
	mov A,5
	push A
	mov A,[X+0]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+0],A
	.dbline 1060
	mov A,[X-4]
	push A
	mov A,[X+0]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X+0],A
	.dbline 1061
	mov A,[X-5]
	push A
	mov A,[X+0]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+0],A
	.dbline 1062
	mov A,[X+0]
	push A
	mov A,[X+0]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+0],A
	.dbline 1064
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L405
	.dbline 1065
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
L405:
	.dbline -2
	.dbline 1067
; }
; 
; // note: convention that error==0 means no error
; void sendAck(unsigned char flags, unsigned char error)
; {
; 	unsigned char chk=0;	
; 	chk = host_chksend(chk, 237);
; 	chk = host_chksend(chk, 5);
; 	chk = host_chksend(chk, flags);
; 	chk = host_chksend(chk, error);
; 	chk = host_chksend(chk, chk);
; 	
; 	if (eventenable)
; 		ED_HOST_putData(EVENTCHAR);
; 
; }
L404:
	add SP,-1
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l chk 0 c
	.dbsym l error -5 c
	.dbsym l flags -4 c
	.dbend
	.area data(ram, con, rel)
	.dbfile ./main.c
_host_chksendfilt_skipchars::
	.byte 0
	.dbsym e host_chksendfilt_skipchars _host_chksendfilt_skipchars c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area data(ram, con, rel)
	.dbfile ./main.c
_host_chksendfilt_length::
	.byte 0
	.dbsym e host_chksendfilt_length _host_chksendfilt_length c
	.area data(ram, con, rel)
	.dbfile ./main.c
	.area text(rom, con, rel)
	.dbfile ./main.c
	.dbfunc e host_chksendfilt _host_chksendfilt fc
;              c -> X-5
;            chk -> X-4
_host_chksendfilt::
	.dbline -1
	push X
	mov X,SP
	.dbline 1076
; 
; // These functions allow for partial sending of
; // a packet. You set up skipchars and length appropriately,
; // and it will only transmit the characters you want.
; unsigned char host_chksendfilt_skipchars=0;
; unsigned char host_chksendfilt_length=0;
; 
; unsigned char host_chksendfilt(unsigned char chk, unsigned char c)
; {
	.dbline 1077
; 	if (host_chksendfilt_skipchars==0)
	mov REG[0xd0],>_host_chksendfilt_skipchars
	cmp [_host_chksendfilt_skipchars],0
	jnz L408
	.dbline 1078
; 	{
	.dbline 1079
; 		if (host_chksendfilt_length>0)
	mov REG[0xd0],>_host_chksendfilt_length
	mov A,0
	cmp A,[_host_chksendfilt_length]
	jnc L410
X85:
	.dbline 1080
; 			{
	.dbline 1081
; 			host_chksendfilt_length--;
	mov REG[0xd0],>_host_chksendfilt_length
	dec [_host_chksendfilt_length]
	.dbline 1082
; 			return host_chksend(chk, c);	
	mov A,[X-5]
	push A
	mov A,[X-4]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	xjmp L407
L410:
	.dbline 1084
; 			}
; 		return chk;
	mov A,[X-4]
	mov REG[0xd0],>__r0
	xjmp L407
L408:
	.dbline 1086
; 	}
; 	host_chksendfilt_skipchars--;
	mov REG[0xd0],>_host_chksendfilt_skipchars
	dec [_host_chksendfilt_skipchars]
	.dbline 1087
; 	return chk;
	mov A,[X-4]
	mov REG[0xd0],>__r0
	.dbline -2
L407:
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c -5 c
	.dbsym l chk -4 c
	.dbend
	.dbfunc e host_chksendfilti _host_chksendfilti fc
;              c -> X-6
;            chk -> X-4
_host_chksendfilti::
	.dbline -1
	push X
	mov X,SP
	.dbline 1091
; }
; 
; unsigned char host_chksendfilti(unsigned char chk, unsigned int c)
; {
	.dbline 1092
; 	chk = host_chksendfilt(chk, c>>8);
	mov REG[0xd0],>__r0
	mov A,[X-6]
	push A
	mov A,[X-4]
	push A
	xcall _host_chksendfilt
	mov REG[0xd0],>__r0
	mov [X-4],A
	.dbline 1093
; 	chk = host_chksendfilt(chk, c&0xff);
	mov A,[X-5]
	push A
	mov A,[X-4]
	push A
	xcall _host_chksendfilt
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X-4],A
	.dbline 1094
; 	return chk;
	mov A,[X-4]
	.dbline -2
L412:
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l c -6 i
	.dbsym l chk -4 c
	.dbend
	.dbfunc e sendPacket _sendPacket fV
;            chk -> X+1
;              i -> X+0
;          flags -> X-4
_sendPacket::
	.dbline -1
	push X
	mov X,SP
	add SP,2
	.dbline 1099
; }
; 
; //////////////////////////////////////////////////
; void sendPacket(unsigned char flags)
; {
	.dbline 1100
; 	unsigned char chk=0;
	mov [X+1],0
	.dbline 1103
; 	unsigned char i;
; 		
; 	chk = host_chksend(chk, 237);
	mov A,-19
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1104
; 	chk = host_chksend(chk, 69);
	mov A,69
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1105
; 	chk = host_chksend(chk, flags);
	mov A,[X-4]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1106
; 	chk = host_chksend(chk, '*'); // i'm a state packet
	mov A,42
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1108
; 
; 	chk = host_chksendi(chk, sleepcounter); 
	mov REG[0xd0],>_sleepcounter
	mov A,[_sleepcounter]
	push A
	mov A,[_sleepcounter+1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	add SP,-5
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1110
; 
; 	chk = host_chksend(chk, PRT0DR);  // dig 0-7
	mov A,REG[ 0]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1111
; 	chk = host_chksend(chk, PRT2DR);  // dig 8-15
	mov A,REG[0x8]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov REG[0xd0],>__r0
	mov [X+1],A
	.dbline 1114
; 	
; 	// SERVOS
; 	for (i=0;i<4;i++)
	mov [X+0],0
	xjmp L417
L414:
	.dbline 1115
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	add [__r1],<_servowidth
	adc [__r0],>_servowidth
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	add SP,-3
	mov REG[0xd0],>__r0
	mov [X+1],A
L415:
	.dbline 1114
	inc [X+0]
L417:
	.dbline 1114
	cmp [X+0],4
	jc L414
X86:
	.dbline 1118
; 		chk = host_chksendi(chk, servowidth[i]); 
; 
; 	// ANALOG
; 	for (i=0;i<10;i++)
	mov [X+0],0
	xjmp L421
L418:
	.dbline 1119
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	asl [__r1]
	rlc [__r0]
	add [__r1],<_analog
	adc [__r0],>_analog
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mvi A,[__r1]
	mov [__r1],A
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	add SP,-3
	mov REG[0xd0],>__r0
	mov [X+1],A
L419:
	.dbline 1118
	inc [X+0]
L421:
	.dbline 1118
	cmp [X+0],10
	jc L418
X87:
	.dbline 1120
; 		chk = host_chksendi(chk, analog[i]); 
; 	for (i=0;i<10;i+=2)
	mov [X+0],0
	xjmp L425
L422:
	.dbline 1121
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_analogFilter
	adc [__r0],>_analogFilter
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	mov [__r0],A
	mov A,[X+0]
	mov [__r3],A
	mov [__r2],0
	add [__r3],<_analogFilter+1
	adc [__r2],>_analogFilter+1
	mov A,[__r2]
	mov REG[0xd4],A
	mvi A,[__r3]
	asl A
	asl A
	asl A
	asl A
	or A,[__r0]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+1],A
L423:
	.dbline 1120
	add [X+0],2
L425:
	.dbline 1120
	cmp [X+0],10
	jc L422
X88:
	.dbline 1124
; 		chk = host_chksend(chk, (analogFilter[i+1]<<4) | analogFilter[i]);
; 		
; 	// PIN MODES
; 	for (i=0;i<16;i+=2)
	mov [X+0],0
	xjmp L430
L427:
	.dbline 1125
	mov REG[0xd0],>__r0
	mov A,[X+0]
	mov [__r1],A
	mov [__r0],0
	add [__r1],<_pinmode+1
	adc [__r0],>_pinmode+1
	mov A,[__r0]
	mov REG[0xd4],A
	mvi A,[__r1]
	asl A
	asl A
	asl A
	asl A
	mov [__r0],A
	mov A,[X+0]
	mov [__r3],A
	mov [__r2],0
	add [__r3],<_pinmode
	adc [__r2],>_pinmode
	mov A,[__r2]
	mov REG[0xd4],A
	mvi A,[__r3]
	or A,[__r0]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-2
	mov REG[0xd0],>__r0
	mov [X+1],A
L428:
	.dbline 1124
	add [X+0],2
L430:
	.dbline 1124
	cmp [X+0],16
	jc L427
X89:
	.dbline 1128
	mov REG[0xd0],>_usrange
	mov A,[_usrange]
	push A
	mov A,[_usrange+1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	add SP,-3
	mov [X+1],A
	.dbline 1129
	mov REG[0xd0],>_usrange
	mov A,[_usrange+2]
	push A
	mov A,[_usrange+2+1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	mov [X+1],A
	.dbline 1130
	mov REG[0xd0],>_uspingcount
	mov A,[_uspingcount]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-5
	mov [X+1],A
	.dbline 1133
	mov REG[0xd0],>_clockgenstate
	mov A,[_clockgenstate]
	and A,15
	mov REG[0xd0],>__r0
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1134
	mov REG[0xd0],>_clockgenstate
	mov A,[_clockgenstate+1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+1],A
	.dbline 1135
	mov REG[0xd0],>_clockgenstate
	mov A,[_clockgenstate+2]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1138
	mov REG[0xd0],>_dac
	mov A,[_dac]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+1],A
	.dbline 1141
	mov REG[0xd0],>_gyrocount
	mov A,[_gyrocount]
	push A
	mov A,[_gyrocount+1]
	push A
	mov A,[_gyrocount+2]
	push A
	mov A,[_gyrocount+3]
	mov REG[0xd0],>__r0
	mov [__r3],A
	pop A
	mov [__r2],A
	pop A
	mov [__r1],A
	pop A
	mov [__r0],A
	mov A,16
X90:
	mov REG[0xd0],>__r0
	asr [__r0]
	rrc [__r1]
	rrc [__r2]
	rrc [__r3]
	dec A
	jnz X90
	mov A,[__r3]
	mov [__r1],A
	mov A,[__r2]
	push A
	mov A,[__r1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	add SP,-3
	mov [X+1],A
	.dbline 1142
	mov REG[0xd0],>_gyrocount
	mov A,[_gyrocount+3]
	mov REG[0xd0],>__r0
	mov [__r3],A
	mov REG[0xd0],>_gyrocount
	mov A,[_gyrocount+2]
	mov REG[0xd0],>__r0
	mov [__r2],A
	mov A,[__r3]
	mov [__r1],A
	mov A,[__r2]
	push A
	mov A,[__r1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksendi
	mov [X+1],A
	.dbline 1145
	mov REG[0xd0],>_badhostchars
	mov A,[_badhostchars]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-5
	mov [X+1],A
	.dbline 1146
	mov REG[0xd0],>_badslavechars
	mov A,[_badslavechars]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1147
	mov REG[0xd0],>_badpadchars
	mov A,[_badpadchars]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+1],A
	.dbline 1149
	mov REG[0xd0],>_ED_HOST_fStatus
	mov A,[_ED_HOST_fStatus]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1150
	mov REG[0xd0],>_ED_SLAVE_fStatus
	mov A,[_ED_SLAVE_fStatus]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	mov [X+1],A
	.dbline 1151
	mov REG[0xd0],>_ED_PAD_fStatus
	mov A,[_ED_PAD_fStatus]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	mov [X+1],A
	.dbline 1153
	mov REG[0xd0],>_ED_HOST_fStatus
	mov [_ED_HOST_fStatus],0
	.dbline 1154
	mov REG[0xd0],>_ED_SLAVE_fStatus
	mov [_ED_SLAVE_fStatus],0
	.dbline 1155
	mov REG[0xd0],>_ED_PAD_fStatus
	mov [_ED_PAD_fStatus],0
	.dbline 1158
	mov A,[X+1]
	push A
	mov A,[X+1]
	push A
	xcall _host_chksend
	add SP,-4
	.dbline 1160
	mov REG[0xd0],>_eventenable
	cmp [_eventenable],0
	jz L435
	.dbline 1161
	push X
	mov A,-18
	xcall _ED_HOST_putData
	pop X
L435:
	.dbline -2
	.dbline 1163
; 		chk = host_chksend(chk, pinmode[i] | (pinmode[i+1]<<4));
; 	
; 	// ULTRASOUND RANGE
; 	chk = host_chksendi(chk, usrange[0]); 
; 	chk = host_chksendi(chk, usrange[1]); 
; 	chk = host_chksend(chk, uspingcount);
; 	
; 	// CLOCK DATA
; 	chk = host_chksend(chk, clockgenstate[0]&0x0f);
; 	chk = host_chksend(chk, clockgenstate[1]);
; 	chk = host_chksend(chk, clockgenstate[2]);
; 
; 	// DAC value
; 	chk = host_chksend(chk, dac[0]);
; 	
; 	// Gyro
; 	chk = host_chksendi(chk, gyrocount>>16); 
; 	chk = host_chksendi(chk, gyrocount&0x00ffff); 
; 
; 	// Comm statistics
; 	chk = host_chksend(chk, badhostchars);
; 	chk = host_chksend(chk, badslavechars);
; 	chk = host_chksend(chk, badpadchars);
; 	
; 	chk = host_chksend(chk, ED_HOST_fStatus);
; 	chk = host_chksend(chk, ED_SLAVE_fStatus);
; 	chk = host_chksend(chk, ED_PAD_fStatus);
; 	
; 	ED_HOST_fStatus=0;
; 	ED_SLAVE_fStatus=0;
; 	ED_PAD_fStatus=0;
; 
; 	// the checksum
; 	host_chksend(chk, chk);
; 
; 	if (eventenable)
; 		ED_HOST_putData(EVENTCHAR);
; 
; }
L413:
	add SP,-2
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l chk 1 c
	.dbsym l i 0 c
	.dbsym l flags -4 c
	.dbend
	.dbfunc e commerror _commerror fV
;           type -> X-4
_commerror::
	.dbline -1
	push X
	mov X,SP
	.dbline 1166
; 
; void commerror(unsigned char type)
; {
	.dbline -2
	.dbline 1174
; /*
; 	char buf[4];
; 	formatInt(type, buf, 2);
; 	
; //	pad_LcdPrintC(0,56,'b',"err");
; 	pad_LcdPrint(112,56,'b',buf);
; */
; }
L437:
	pop X
	.dbline 0 ; func end
	ret
	.dbsym l type -4 c
	.dbend
	.area data(ram, con, rel)
	.dbfile ./main.c
_lastcounter::
	.byte 0,0
	.dbsym e lastcounter _lastcounter i
	.area data(ram, con, rel)
	.dbfile ./main.c
_clockgenstate::
	.byte 0,0,0
	.dbsym e clockgenstate _clockgenstate A[3:3]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_dac::
	.byte 0
	.dbsym e dac _dac A[1:1]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_analogDelay::
	.byte 0
	.dbsym e analogDelay _analogDelay c
	.area data(ram, con, rel)
	.dbfile ./main.c
_analogNext::
	.byte 0
	.dbsym e analogNext _analogNext c
	.area data(ram, con, rel)
	.dbfile ./main.c
_analogFilter::
	.byte 0,0,0,0,0,0,0,0,0,0
	.dbsym e analogFilter _analogFilter A[10:10]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_analog::
	.word 0,0,0,0,0
	.byte 0,0,0,0,0,0,0,0,0,0
	.dbsym e analog _analog A[20:10]i
	.area data(ram, con, rel)
	.dbfile ./main.c
_usrange::
	.byte 0,0,0,0
	.dbsym e usrange _usrange A[4:2]i
	.area data(ram, con, rel)
	.dbfile ./main.c
_pinmode::
	.word 0,0,0,0,0
	.byte 0,0,0,0,0,0
	.dbsym e pinmode _pinmode A[16:16]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_battery_voltage::
	.byte 0,0
	.dbsym e pad_battery_voltage _pad_battery_voltage s
	.area data(ram, con, rel)
	.dbfile ./main.c
_slavebuf::
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.byte 0,0,0,0
	.dbsym e slavebuf _slavebuf A[64:64]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_padbuf::
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.byte 0,0,0,0,0,0,0,0
	.dbsym e padbuf _padbuf A[128:128]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_hostbuf::
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.byte 0,0,0,0,0,0,0,0
	.dbsym e hostbuf _hostbuf A[128:128]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_slavestate::
	.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.word 0,0,0,0,0
	.byte 0,0,0,0,0,0,0,0,0,0
	.dbsym e slavestate _slavestate A[80:80]c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_move_right::
	.byte 0
	.dbsym e pad_move_right _pad_move_right c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_move_left::
	.byte 0
	.dbsym e pad_move_left _pad_move_left c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_move_down::
	.byte 0
	.dbsym e pad_move_down _pad_move_down c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_move_up::
	.byte 0
	.dbsym e pad_move_up _pad_move_up c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_buttons::
	.byte 0
	.dbsym e pad_buttons _pad_buttons c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_joyy::
	.byte 0
	.dbsym e pad_joyy _pad_joyy c
	.area data(ram, con, rel)
	.dbfile ./main.c
_pad_joyx::
	.byte 0
	.dbsym e pad_joyx _pad_joyx c
	.area lit(rom, con, rel)
L392:
	.byte 32,32,32,40,'S,'o,'f,'t,32,'H,'a,'l,'t,41,32,32
	.byte 0
L391:
	.byte 32,32,40,'S,'t,'o,'p,32,'B,'u,'t,'t,'o,'n,41,32
	.byte 0
L388:
	.byte 32,32,40,'P,'a,'d,32,'T,'i,'m,'e,'o,'u,'t,41,32
	.byte 0
L385:
	.byte 't,'o,32,'r,'e,'s,'u,'m,'e,46,0
L384:
	.byte 'H,'i,'t,32,'s,'t,'i,'c,'k,32,'b,'u,'t,'t,'o,'n
	.byte 0
L383:
	.byte 32,32,32,32,'A,'l,'l,32,'S,'t,'o,'p,32,32,32,32
	.byte 0
L382:
	.byte 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32
	.byte 0
L35:
	.byte 'S,'e,'l,'f,32,'t,'e,'s,'t,'s,32,'F,'A,'I,'L,'E
	.byte 'D,33,0
L34:
	.byte 'O,'r,'c,'B,'o,'a,'r,'d,32,'R,'e,'a,'d,'y,33,0
