	.module mbs1.c
	.dbfile mbs1.c
	.area data
_servo_limits::
	.blkb 2
	.area idata
	.word 600
	.area data
	.blkb 2
	.area idata
	.word 4800
	.area data
	.blkb 2
	.area idata
	.word 600
	.area data
	.blkb 2
	.area idata
	.word 4800
	.area data
	.blkb 2
	.area idata
	.word 600
	.area data
	.blkb 2
	.area idata
	.word 4800
	.area data
	.blkb 2
	.area idata
	.word 600
	.area data
	.blkb 2
	.area idata
	.word 4800
	.area data
	.blkb 2
	.area idata
	.word 600
	.area data
	.blkb 2
	.area idata
	.word 4800
	.area data
_srv_lim_default::
	.blkb 1
	.area idata
	.byte 1
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCME\include/isrdecl.h
	.dbfunc SCI_isr
	.dbline 41
; /***************INCLUDES**********************/
; 
; #include <analog.h>
; #include <clocktjp.h>
; #include <motorme.h>
; #include <servome.h>
; #include <serialtp.h>
; #include <isrdecl.h>
; #include <vectors.h>
; #include <stdio.h>
; 
; 
; /*************END INCLUDES*****************/
; //notes:  Needs to move a little longer before it scans each bit.  Also check the thresholds.
; /**************CONSTANTS*********************/
; 
; #define LEFT_MOTOR 0
; #define RIGHT_MOTOR 1
; #define MAX_SPEED 100
; #define MIN_SPEED 0
; #define AVOID_THRESHOLD 120
; #define SCAN_THRESHOLD 20
; #define LEFT_IR analog(3)
; #define MID_IR analog(4)
; #define RIGHT_IR analog(5)
; #define SCAN analog(6)
; #define BACK_IR analog(0)
; #define REAR_IR analog(1)
; #define FRONT_IR analog(2)
; #define IRE *(unsigned char *) (0x7000)
; /***********END CONSTANTS**************/
; 
; void do_scan(void);
; 
; void main(void)
; {
; 
; int irdr, irdl,irdb,irdsf, diff,irdsr, irdm, speedr, speedl;
; 
; init_analog();
; init_motorme();
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; init_servome();
; init_clocktjp();
; init_serial();
; IRE = 0x07;
; 
; 
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; 
; while(1)
; {
; 
; 	irdr= RIGHT_IR;
; 	irdl= LEFT_IR;
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 59
; 	irdm= MID_IR;
; 	irdb= BACK_IR;
; 	irdsr= REAR_IR;
; 	irdsf= FRONT_IR;
; 	diff = irdsf - irdsr; 
;    
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 65
; 	if (diff== 0)
; 	{
; 		if (irdm < AVOID_THRESHOLD)
; 		{
; 		printf("diff is 0 %d\n", SCAN);
; 		if (SCAN < SCAN_THRESHOLD)
L6:
	rti
;  IX -> 0,x
_TOC2_isr::
	.dbfunc TOC2_isr
	.dbline 83
; 			do_scan();
; 		speedl = 70;
; 		speedr = 70;
; 		}
; 		else 
; 		{
; 		speedl = 100;
; 		speedr = -100;
; 		}
; 		
; 	}
; 	else if ((irdm > AVOID_THRESHOLD)&&(irdl > AVOID_THRESHOLD))
; 	{
; 	speedl = 100;
; 	speedr = -100;
; 	}else if ((irdsf > 110)&&(diff < 0)) 
; 	{
; 	printf("front is is higher %d\n", SCAN);
L7:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
; 	if (SCAN < SCAN_THRESHOLD)
; 			do_scan();
; 	speedl = 70;
; 	speedr = 60;
; 	}
; 	else if ((irdsr > 110)&&(diff>-5))
L8:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 	{
;     printf("rear is higher %d\n", SCAN);
;     if (SCAN < SCAN_THRESHOLD)
; 			do_scan();
; 	speedl = 60;
; 	speedr = 70;
; 	}
; 	else
; 	{
; 	 	if (irdr < AVOID_THRESHOLD)
; 			speedl = 100;
; 			else 
L9:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
; 			speedl = -100;
; 		 if (irdl < AVOID_THRESHOLD)
; 		 	speedr = 100;
; 			else
; 			speedr = -100;
; 	}
L10:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 	motorme(LEFT_MOTOR, speedl);
; 	motorme(RIGHT_MOTOR, speedr);
; 	wait(150);
; 	motorme(LEFT_MOTOR, 0);
; 	motorme(RIGHT_MOTOR, 0);
; 	
L11:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 119
; 	
; }
; }
; 
; void do_scan()
; {
L12:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
;  int sbone,sbtwo;
;   motorme(RIGHT_MOTOR, 0);
;  motorme(LEFT_MOTOR, 0);
;  printf("Rolled backed to: %d\n", SCAN);
;  wait(3000);
;  motorme(RIGHT_MOTOR, 50);
L13:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
;  motorme(LEFT_MOTOR, 50);	
;  wait(215);
;  motorme(RIGHT_MOTOR, 0);
;  motorme(LEFT_MOTOR, 0);	
;  wait(1000);
;  sbtwo = (SCAN < 20);
L14:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
;  printf("Bit Two : %d\n", SCAN);
;  wait(4000);
;  motorme(RIGHT_MOTOR, 50);
;  motorme(LEFT_MOTOR, 50);	
;  wait(210);
;  motorme(RIGHT_MOTOR, 0);
L15:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
;  motorme(LEFT_MOTOR, 0);	
;  wait(1000);
;  sbone = (SCAN < 20);
;  printf("Bit One : %d\n", SCAN);
;   wait(4000);
;  if ((sbone)&&(sbtwo))
L16:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
;  	IRE = 0x1f;
;  else if (sbtwo)
;  	IRE = 0x17;
;  else if (sbone)
;  	IRE = 0x0f;
;  wait (700);
L17:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
;  motorme(RIGHT_MOTOR, 40);
;  motorme(LEFT_MOTOR, 40);
;  wait(50);
;  }
;   
;   
L18:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area text
;  IX -> 0,x
;           irdb -> 2,x
;           irdr -> 4,x
;           irdl -> 6,x
;         speedl -> 8,x
;         speedr -> 10,x
;           irdm -> 12,x
;          irdsr -> 14,x
;          irdsf -> 16,x
;           diff -> 18,x
_main::
	jsr __enterb
	.byte 0x14
	.dbfile mbs1.c
	.dbfunc main
	.dbline 40
	jsr _init_analog
	.dbline 41
	jsr _init_motorme
	.dbline 42
	jsr _init_servome
	.dbline 43
	jsr _init_clocktjp
	.dbline 44
	jsr _init_serial
	.dbline 45
	ldab #7
	stab 0x7000
	jmp L21
L20:
	.dbline 52
	ldd #5
	jsr _analog
	std 4,x
	.dbline 53
	ldd #3
	jsr _analog
	std 6,x
	.dbline 54
	ldd #4
	jsr _analog
	std 12,x
	.dbline 55
	ldd #0
	jsr _analog
	std 2,x
	.dbline 56
	ldd #1
	jsr _analog
	std 14,x
	.dbline 57
	ldd #2
	jsr _analog
	std 16,x
	.dbline 58
	ldd 16,x
	subd 14,x
	std 18,x
	.dbline 60
	ldd 18,x
	bne L23
	.dbline 62
	ldd 12,x
	cpd #120
	bge L25
	.dbline 64
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L27
	jsr _printf
	puly
	.dbline 65
	ldd #6
	jsr _analog
	cpd #20
	bge L28
	.dbline 66
	jsr _do_scan
L28:
	.dbline 67
	ldd #70
	std 8,x
	.dbline 68
	ldd #70
	std 10,x
	.dbline 69
	jmp L24
L25:
	.dbline 72
	ldd #100
	std 8,x
	.dbline 73
	ldd #-100
	std 10,x
	.dbline 76
	jmp L24
L23:
	.dbline 77
	ldd 12,x
	cpd #120
	ble L30
	ldd 6,x
	cpd #120
	ble L30
	.dbline 79
	ldd #100
	std 8,x
	.dbline 80
	ldd #-100
	std 10,x
	.dbline 81
	jmp L31
L30:
	ldd 16,x
	cpd #110
	ble L32
	ldd 18,x
	bge L32
	.dbline 83
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L34
	jsr _printf
	puly
	.dbline 84
	ldd #6
	jsr _analog
	cpd #20
	bge L35
	.dbline 85
	jsr _do_scan
L35:
	.dbline 86
	ldd #70
	std 8,x
	.dbline 87
	ldd #60
	std 10,x
	.dbline 88
	bra L33
L32:
	.dbline 89
	ldd 14,x
	cpd #110
	ble L37
	ldd 18,x
	cpd #-5
	ble L37
	.dbline 91
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L39
	jsr _printf
	puly
	.dbline 92
	ldd #6
	jsr _analog
	cpd #20
	bge L40
	.dbline 93
	jsr _do_scan
L40:
	.dbline 94
	ldd #60
	std 8,x
	.dbline 95
	ldd #70
	std 10,x
	.dbline 96
	bra L38
L37:
	.dbline 99
	ldd 4,x
	cpd #120
	bge L42
	.dbline 100
	ldd #100
	std 8,x
	bra L43
L42:
	.dbline 102
	ldd #-100
	std 8,x
L43:
	.dbline 103
	ldd 6,x
	cpd #120
	bge L44
	.dbline 104
	ldd #100
	std 10,x
	bra L45
L44:
	.dbline 106
	ldd #-100
	std 10,x
L45:
	.dbline 107
L38:
L33:
L31:
L24:
	.dbline 108
	ldd 8,x
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 109
	ldd 10,x
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 110
	ldd #150
	jsr _wait
	.dbline 111
	ldd #0
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 112
	ldd #0
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 115
L21:
	.dbline 49
	jmp L20
L19:
	xgdx
	addd #20
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;          ?temp -> 2,x
;          ?temp -> 4,x
;          sbone -> 6,x
;          sbtwo -> 8,x
_do_scan::
	jsr __enterb
	.byte 0xa
	.dbfunc do_scan
	.dbline 121
	ldd #0
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 122
	ldd #0
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 123
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L47
	jsr _printf
	puly
	.dbline 124
	ldd #3000
	jsr _wait
	.dbline 125
	ldd #50
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 126
	ldd #50
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 127
	ldd #215
	jsr _wait
	.dbline 128
	ldd #0
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 129
	ldd #0
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 130
	ldd #1000
	jsr _wait
	.dbline 131
	ldd #6
	jsr _analog
	cpd #20
	bge L49
	ldd #1
	std 4,x
	bra L50
L49:
	ldd #0
	std 4,x
L50:
	ldd 4,x
	std 8,x
	.dbline 132
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L51
	jsr _printf
	puly
	.dbline 133
	ldd #4000
	jsr _wait
	.dbline 134
	ldd #50
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 135
	ldd #50
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 136
	ldd #210
	jsr _wait
	.dbline 137
	ldd #0
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 138
	ldd #0
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 139
	ldd #1000
	jsr _wait
	.dbline 140
	ldd #6
	jsr _analog
	cpd #20
	bge L53
	ldd #1
	std 2,x
	bra L54
L53:
	ldd #0
	std 2,x
L54:
	ldd 2,x
	std 6,x
	.dbline 141
	ldd #6
	jsr _analog
	pshb
	psha
	ldd #L55
	jsr _printf
	puly
	.dbline 142
	ldd #4000
	jsr _wait
	.dbline 143
	ldd 6,x
	beq L56
	ldd 8,x
	beq L56
	.dbline 144
	ldab #31
	stab 0x7000
	bra L57
L56:
	.dbline 145
	ldd 8,x
	beq L58
	.dbline 146
	ldab #23
	stab 0x7000
	bra L59
L58:
	.dbline 147
	ldd 6,x
	beq L60
	.dbline 148
	ldab #15
	stab 0x7000
L60:
L59:
L57:
	.dbline 149
	ldd #700
	jsr _wait
	.dbline 150
	ldd #40
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 151
	ldd #40
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 152
	ldd #50
	jsr _wait
	.dbline 153
L46:
	xgdx
	addd #10
	xgdx
	txs
	pulx
	rts
	.area bss
_servo_width::
	.blkb 10
_timertjp::
	.blkb 2
_days::
	.blkb 2
_hours::
	.blkb 2
_minutes::
	.blkb 2
_seconds::
	.blkb 2
_msec::
	.blkb 2
	.area text
L55:
	.byte 'B,'i,'t,32,'O,'n,'e,32,58,32,37,'d,10,0
L51:
	.byte 'B,'i,'t,32,'T,'w,'o,32,58,32,37,'d,10,0
L47:
	.byte 'R,'o,'l,'l,'e,'d,32,'b,'a,'c,'k,'e,'d,32,'t,'o
	.byte 58,32,37,'d,10,0
L39:
	.byte 'r,'e,'a,'r,32,'i,'s,32,'h,'i,'g,'h,'e,'r,32,37
	.byte 'd,10,0
L34:
	.byte 'f,'r,'o,'n,'t,32,'i,'s,32,'i,'s,32,'h,'i,'g,'h
	.byte 'e,'r,32,37,'d,10,0
L27:
	.byte 'd,'i,'f,'f,32,'i,'s,32,48,32,37,'d,10,0
