	.module demoone.c
	.dbfile demoone.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
; /********************************************************
; *                                                       *
; * Title:       demoone.c                                *
; * Programmer:  Andrew Sinclair (from code by A. Arroyo) *
; * Date:        8 June 2000                              *
; * Version:     1.0                                      *
; *                                                       *
; * Description:                                          *
; * A simple collision avoidance program for EEL 5666     *
; * using the MMPP robot. The robot will read each IR     *
; * detector and turn away from any obstacle in its path  *
; * if the IR value exceeds a threshold. If the bumper is *
; * sensed then the robot will back up, turn away, and go *
; * on. The robot will also wait for the bumper to be     *
; * sensed before beginning operation.                    *
; *                                                       *
; ********************************************************/
; 
; 
; /******************** Includes *************************/
; #include <analog.h>
; #include <motorme.h>
; #include <servome.h>
; #include <clocktjp.h>
; #include <isrdecl.h>
; #include <vectors.h>
; #include <stdio.h>
; /***************** End of Includes *********************/
; 
; 
; /******************** Constants ************************/
; #define LEFT_MOTOR  1
; #define RIGHT_MOTOR 0
; #define MAX_SPEED   100
; #define ZERO_SPEED  0
; #define AVOID_THRESHOLD 100
; #define BUMPER analog(3)
; #define LEFT_IR analog(4)
; #define RIGHT_IR analog(0)
; /**************** End of Constants *********************/
; 
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 47
; 
; /******************* Prototypes ************************/
; void turn(void);
; /**************** End of Prototypes ********************/
; 
; 
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 53
; void main(void)
; /********************** Main ***************************/
; {
; int irdr, irdl, speedr, speedl;
; 	
; init_analog();
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 59
; init_motorme();
; init_clocktjp();
; 
; 	
; *(unsigned char *) 0x7000=0x07; /*Turn on the IR emitters*/
; 	
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 65
; /*while(BUMPER<120); /*Press the rear bumper to start the program*/
; 	while(1)
; 	{
; 	 irdr = RIGHT_IR;
; 	 irdl = LEFT_IR;
; 
L6:
	rti
;  IX -> 0,x
_TOC2_isr::
	.dbfunc TOC2_isr
	.dbline 83
; 	 if (irdl > AVOID_THRESHOLD)
; 	 	 speedr = -MAX_SPEED;
; 	 else speedr = MAX_SPEED;
; 
; 	 if (irdr > AVOID_THRESHOLD)
; 		 speedl = -MAX_SPEED;
; 	 else speedl = MAX_SPEED;
; 	
; 	 motorme(RIGHT_MOTOR, speedr);
; 	 motorme(LEFT_MOTOR, speedl);
; 	
; 	 /* Back Bump Switch */
; 	 if((BUMPER>10)&&(BUMPER<30))
; 	 {
; 	  motorme(LEFT_MOTOR, MAX_SPEED);
; 	  motorme(RIGHT_MOTOR, MAX_SPEED);
; 	  wait(600);
; 	  turn();
L7:
	rti
;  IX -> 0,x
_TOC3_isr::
	.dbfunc TOC3_isr
	.dbline 89
; 	 }
; 	 
; 	 /* Right-Front Bump Switch */
; 	 if((BUMPER>35)&&(BUMPER<55))
; 	 {
; 	  motorme(LEFT_MOTOR, -MAX_SPEED);
L8:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 101
; 	  motorme(RIGHT_MOTOR, MAX_SPEED);
; 	  wait(600);
; 	  turn();
; 	 }
; 
; 	 /* Front Bump Switch */
; 	 if((BUMPER>70)&&(BUMPER<90))
; 	 {
; 	  motorme(LEFT_MOTOR, -MAX_SPEED);
; 	  motorme(RIGHT_MOTOR, -MAX_SPEED);
; 	  wait(600);
; 	  turn();
L9:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 107
; 	 }
; 
; 	 /* Left-Front Bump Switch */
; 	 if((BUMPER>120)&&(BUMPER<140))
; 	 {
; 	  motorme(LEFT_MOTOR, MAX_SPEED);
L10:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 113
; 	  motorme(RIGHT_MOTOR, -MAX_SPEED);
; 	  wait(600);
; 	  turn();
; 	 }
; 
; 
L11:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 119
; 	 wait(35);
; 	}
; }
; /******************* End of Main ***********************/
; 
; 
L12:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 125
; void turn(void)
; /********************************************************
; * Function: Will turn in a random direction for a       *
; * "random" amount of time, dictated by the fast         *
; * changing lower bits in mseconds().                    *
; *                                                       *
L13:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 131
; * Returns: None                                         *
; *                                                       *
; * Inputs                                                *
; *  Parameters: None                                     *
; *  Globals:    None                                     *
; *  Registers:  TCNT                                     *
L14:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 137
; * Outputs                                               *
; *  Parameters: None                                     *
; *  Globals:    None                                     *
; *  Registers:  None                                     *
; * Functions called: motorme(), wait()                   *
; ********************************************************/
L15:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 143
; {
;  int i;
;  unsigned rand;
;  
;  rand = TCNT;
;  
L16:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 149
;  if (rand & 0x0001)
;  /* turn left */
;  {
;   motorme(RIGHT_MOTOR, MAX_SPEED);
;   motorme(LEFT_MOTOR, -MAX_SPEED);
;  }
L17:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 155
;  else
;  /* turn right */
;  {
;   motorme(RIGHT_MOTOR, -MAX_SPEED);
;   motorme(LEFT_MOTOR, MAX_SPEED);
;  }
L18:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area text
;  IX -> 0,x
;         speedl -> 2,x
;         speedr -> 4,x
;           irdl -> 6,x
;           irdr -> 8,x
_main::
	jsr __enterb
	.byte 0xa
	.dbfile demoone.c
	.dbfunc main
	.dbline 53
	jsr _init_analog
	.dbline 54
	jsr _init_motorme
	.dbline 55
	jsr _init_clocktjp
	.dbline 58
	ldab #7
	stab 0x7000
	jmp L21
L20:
	.dbline 63
	ldd #0
	jsr _analog
	std 8,x
	.dbline 64
	ldd #4
	jsr _analog
	std 6,x
	.dbline 66
	ldd 6,x
	cpd #100
	ble L23
	.dbline 67
	ldd #-100
	std 4,x
	bra L24
L23:
	.dbline 68
	ldd #100
	std 4,x
L24:
	.dbline 70
	ldd 8,x
	cpd #100
	ble L25
	.dbline 71
	ldd #-100
	std 2,x
	bra L26
L25:
	.dbline 72
	ldd #100
	std 2,x
L26:
	.dbline 74
	ldd 4,x
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 75
	ldd 2,x
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 78
	ldd #3
	jsr _analog
	cpd #10
	ble L27
	ldd #3
	jsr _analog
	cpd #30
	bge L27
	.dbline 80
	ldd #100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 81
	ldd #100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 82
	ldd #600
	jsr _wait
	.dbline 83
	jsr _turn
	.dbline 84
L27:
	.dbline 87
	ldd #3
	jsr _analog
	cpd #35
	ble L29
	ldd #3
	jsr _analog
	cpd #55
	bge L29
	.dbline 89
	ldd #-100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 90
	ldd #100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 91
	ldd #600
	jsr _wait
	.dbline 92
	jsr _turn
	.dbline 93
L29:
	.dbline 96
	ldd #3
	jsr _analog
	cpd #70
	ble L31
	ldd #3
	jsr _analog
	cpd #90
	bge L31
	.dbline 98
	ldd #-100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 99
	ldd #-100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 100
	ldd #600
	jsr _wait
	.dbline 101
	jsr _turn
	.dbline 102
L31:
	.dbline 105
	ldd #3
	jsr _analog
	cpd #120
	ble L33
	ldd #3
	jsr _analog
	cpd #140
	bge L33
	.dbline 107
	ldd #100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 108
	ldd #-100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 109
	ldd #600
	jsr _wait
	.dbline 110
	jsr _turn
	.dbline 111
L33:
	.dbline 114
	ldd #35
	jsr _wait
	.dbline 115
L21:
	.dbline 61
	jmp L20
L19:
	xgdx
	addd #10
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
;              i -> 2,x
;           rand -> 4,x
_turn::
	jsr __enterb
	.byte 0x6
	.dbfunc turn
	.dbline 142
	; vol
	ldd 0x100e
	std 4,x
	.dbline 144
	ldd 4,x
	anda #0
	andb #1
	cpd #0
	beq L36
	.dbline 147
	ldd #100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 148
	ldd #-100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 149
	bra L37
L36:
	.dbline 153
	ldd #-100
	pshb
	psha
	ldd #0
	jsr _motorme
	puly
	.dbline 154
	ldd #100
	pshb
	psha
	ldd #1
	jsr _motorme
	puly
	.dbline 155
L37:
	.dbline 157
;  
;  i=(rand % 1024);
	ldd 4,x
	anda #3
	andb #255
	std 2,x
	.dbline 158
;  if(i>250)
	ldd 2,x
	cpd #250
	ble L38
	.dbline 159
;   wait(i);
	ldd 2,x
	jsr _wait
	bra L39
L38:
	.dbline 160
;  else wait(250);
	ldd #250
	jsr _wait
L39:
	.dbline 161
; }
L35:
	xgdx
	addd #6
	xgdx
	txs
	pulx
	rts
	.area bss
_timertjp::
	.blkb 2
_days::
	.blkb 2
_hours::
	.blkb 2
_minutes::
	.blkb 2
_seconds::
	.blkb 2
_msec::
	.blkb 2
_servo_width::
	.blkb 10
