	.module dendenis.c
	.dbfile dendenis.c
	.area text
;  IX -> 0,x
_SCI_isr::
	.dbfile C:\ICCTK\include/isrtk.h
	.dbfunc SCI_isr
	.dbline 40
; /************************************************************************
;  * Title        smokeden.c                                	                
;  * Programmer	Sean Justice	        				
;  * Date         July 17,1999      	                                
;  * Version	1			                		
;  *								        
;  * Description
;  * Start by hit the rear bumper and then Denise will not do 
;  * anything until she has detected smoke.
;  *	
;  *	Functions:
;  *		detectsmoke() used to detect if the smoke detector 
;  * 		has detected any smoke
;  *								
;  * Use Hyperterm with the following settings:                           
;  *   									
;  *      COM1, 9600 Baud, 8 bits, No Parity, 1 Stop bit, No Flow         
;  *      of Control, VT100 Terminal, WrapLines.				
;  *									
;  *Usage: Verify functionality of TALRIK's sensors.
;  ************************************************************************/
;  
; /**************************** Includes **********************************/
; 
; #include <tkbase.h>
; 
; 
; /************************ End of includes *******************************/
; 
; 
; /*************************** Constants **********************************/
; 
; /*IR emitter output port driver, the output latch at address 0xffb9 */
; #define IRE_OUT   *(unsigned char *)(0xffb9) 
; 
; /*Constant for driving all the 40KHz modulated IR emitters on when loaded into IRE_OUT */
; #define IRE_ALL_ON 0xff 
; 
; /*Constant for turning all the 40KHz modulated IR emitters off when loaded into IRE_OUT */
; #define IRE_ALL_OFF 0x00
L2:
	rti
;  IX -> 0,x
_SPI_isr::
	.dbfunc SPI_isr
	.dbline 46
; 
; #define BUMPER_FUZZY 10
; #define NOSMOKE 40
; #define IRTHRESHOLD 110
; #define FIRE 50
;  
L3:
	rti
;  IX -> 0,x
_PAIE_isr::
	.dbfunc PAIE_isr
	.dbline 52
; /************************ End of Constants ******************************/
; int rspeed = 0;
; int lspeed = 0;
; 
; void detectsmoke(void);
; void avoidobject(void);
L4:
	rti
;  IX -> 0,x
_PAV_isr::
	.dbfunc PAV_isr
	.dbline 58
; void righturn(void);
; void lefturn(void);
; void checkbump(void);
; void firecheck(void);
; 
; void main(void)
L5:
	rti
;  IX -> 0,x
_TOF_isr::
	.dbfunc TOF_isr
	.dbline 64
; /****************************** Main ***********************************/
; {
;   unsigned int bl, cv, fb, rb;
;   char clear[]= "\x1b\x5B\x32\x4A\x04";  /* clear screen */ 
;   char place[]= "\x1b[1;1H";		/* Home cursor */
; 
L6:
	rti
;  IX -> 0,x
_TOC4_isr::
	.dbfunc TOC4_isr
	.dbline 76
; 
;   init_analog();
;   init_motortk();
;   init_clocktk();
;   init_serial();
; 
;   IRE_OUT = IRE_ALL_ON;    /* Turns on all the 40KHz modulated IR emitters */
; 
;   /*printf("%s", clear);  
;   printf("%s", place);  
;   printf("Hit my ass to start me\n\n");*/
;   
L7:
	rti
;  IX -> 0,x
_TOC1_isr::
	.dbfunc TOC1_isr
	.dbline 94
;   while (rear_bumper() < BUMPER_FUZZY);
;   
;   read_IR();
;   
;     
;   /*printf("starting to look for smoke\n\n");*/
;     
;   
;   
;   detectsmoke();
;   
;   rspeed = lspeed = 100;
;   motortk(RIGHT_MOTOR, rspeed);
;   motortk(LEFT_MOTOR, lspeed);
;   
;   /*printf("Will start to look for the fire\n\n");*/
; 	
; 	wait(500);
L8:
	rti
;  IX -> 0,x
_TIC3_isr::
	.dbfunc TIC3_isr
	.dbline 100
; 
;   /*printf("Starting to avoid objects\n");*/
;   
;   avoidobject();
;   
; 
L9:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 106
; }
; 
; /**************************** End of Main ******************************/
; 
; void detectsmoke(void)
; {
L10:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 112
; 	read_IR();
; 	
; 	while (IRDT[IR5clk] < NOSMOKE)
; 		{
; 			read_IR();
; 			wait(10);
L11:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 118
; 		}
; 	/*printf("I have found smoke\n");*/
; }
; 
; void avoidobject(void)
; {
L12:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 124
; 	/*printf("Starting motors at full speed\n");*/
; 	
; 	
; 	 
; 	 while (1)
; 	 {
L13:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 130
; 	 	checkbump();
; 	 	
; 	 		 	
; 	 	read_IR();
; 	 	firecheck();
; 	 	
L14:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 136
; 	    rspeed = lspeed = 100;
; 	    motortk(RIGHT_MOTOR, rspeed);
; 	    motortk(LEFT_MOTOR, lspeed);
; 	 	
; 	 	if ((IRDT[IR1clk] > IRTHRESHOLD) || (IRDT[IR2clk] > IRTHRESHOLD))
; 	 		{
L15:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 142
; 	 			/*printf("Object to my right, so\n");
; 	 			printf("I will avoid it\n\n");*/
; 	 			righturn();	 			
; 	 		}
; 	 	
; 		 else if ((IRDT[IR4clk] > IRTHRESHOLD) || (IRDT[IR3clk] > IRTHRESHOLD))
L16:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 148
; 	 
; 	 		{
; 	 			/*printf("Object to my left, so\n");
; 	 			printf("I will avoid it\n\n");*/
; 	 			lefturn();	
; 	 		}
L17:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 154
; 	 }
; }
; 
; void righturn(void)
; {
; 	/*printf("Turning right.\n");*/
L18:
	rti
	.area data
_drew::
	.blkw 1
	.area idata
	.word _interrupt_vectors
	.area data
_rspeed::
	.blkb 2
	.area idata
	.word 0
	.area data
_lspeed::
	.blkb 2
	.area idata
	.word 0
	.area text
L20:
	.byte 27,91,50,'J,4,0
L21:
	.byte 27,91,49,59,49,'H,0
;  IX -> 0,x
;             rb -> 3,x
;             fb -> 5,x
;             cv -> 7,x
;             bl -> 9,x
;          place -> 11,x
;          clear -> 18,x
_main::
	jsr __enterb
	.byte 0x18
	.dbfile dendenis.c
	.dbfunc main
	.dbline 62
	ldd 0,x
	addd #18
	ldy #L20
	pshx
	xgdx
	ldd #6
	jsr __asgnblk
	pulx
	.dbline 63
	ldd 0,x
	addd #11
	ldy #L21
	pshx
	xgdx
	ldd #7
	jsr __asgnblk
	pulx
	.dbline 66
	jsr _init_analog
	.dbline 67
	jsr _init_motortk
	.dbline 68
	jsr _init_clocktk
	.dbline 69
	jsr _init_serial
	.dbline 71
	ldab #255
	stab 0xffb9
L22:
	.dbline 77
L23:
	jsr _rear_bumper
	cpd #10
	blo L22
	.dbline 79
	jsr _read_IR
	.dbline 86
	jsr _detectsmoke
	.dbline 88
	ldd #100
	std _lspeed
	ldd #100
	std _rspeed
	.dbline 89
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 90
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 94
	ldd #500
	jsr _wait
	.dbline 98
	jsr _avoidobject
	.dbline 101
L19:
	xgdx
	addd #24
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
_detectsmoke::
	.dbfunc detectsmoke
	.dbline 107
	jsr _read_IR
	bra L27
L26:
	.dbline 111
	jsr _read_IR
	.dbline 112
	ldd #10
	jsr _wait
	.dbline 113
L27:
	.dbline 109
	ldd _IRDT+16
	cpd #40
	blo L26
	.dbline 115
L25:
	rts
;  IX -> 0,x
_avoidobject::
	.dbfunc avoidobject
	.dbline 118
	bra L32
L31:
	.dbline 125
	jsr _checkbump
	.dbline 128
	jsr _read_IR
	.dbline 129
	jsr _firecheck
	.dbline 131
	ldd #100
	std _lspeed
	ldd #100
	std _rspeed
	.dbline 132
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 133
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 135
	ldd _IRDT+8
	cpd #110
	bhi L37
	ldd _IRDT
	cpd #110
	bls L34
L37:
	.dbline 139
	jsr _righturn
	.dbline 140
	bra L35
L34:
	.dbline 142
	ldd _IRDT+14
	cpd #110
	bhi L42
	ldd _IRDT+12
	cpd #110
	bls L38
L42:
	.dbline 147
	jsr _lefturn
	.dbline 148
L38:
L35:
	.dbline 149
L32:
	.dbline 123
	bra L31
L30:
	rts
;  IX -> 0,x
_righturn::
	.dbfunc righturn
	.dbline 155
; 	rspeed = -100;
	ldd #-100
	std _rspeed
	.dbline 156
; 	lspeed = 100;
	ldd #100
	std _lspeed
	.dbline 157
; 	motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 158
; 	motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	bra L45
L44:
	.dbline 161
	jsr _read_IR
	.dbline 162
	jsr _firecheck
	.dbline 163
L45:
	.dbline 159
; 	while ((IRDT[IR1clk] > IRTHRESHOLD) || (IRDT[IR2clk] > IRTHRESHOLD))
	ldd _IRDT+8
	cpd #110
	bhi L44
	ldd _IRDT
	cpd #110
	bhi L44
	.dbline 164
; 	{
; 		read_IR();
; 		firecheck();
; 	}
; 	wait(300);
	ldd #300
	jsr _wait
	.dbline 165
; }
L43:
	rts
;  IX -> 0,x
_lefturn::
	.dbfunc lefturn
	.dbline 170
; 
; void lefturn(void)
; {
; 	/*printf("Turning left.\n");*/
; 	rspeed = 100;
	ldd #100
	std _rspeed
	.dbline 171
; 	lspeed = -100;
	ldd #-100
	std _lspeed
	.dbline 172
; 	motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 173
; 	motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	bra L50
L49:
	.dbline 176
	jsr _read_IR
	.dbline 177
	jsr _firecheck
	.dbline 179
L50:
	.dbline 174
; 	while ((IRDT[IR3clk] > IRTHRESHOLD) || (IRDT[IR4clk] > IRTHRESHOLD))
	ldd _IRDT+12
	cpd #110
	bhi L49
	ldd _IRDT+14
	cpd #110
	bhi L49
	.dbline 180
; 	{
; 		read_IR();
; 		firecheck();
; 		
; 	}
; 	wait(300);
	ldd #300
	jsr _wait
	.dbline 182
; 	
; }
L48:
	rts
;  IX -> 0,x
_checkbump::
	.dbfunc checkbump
	.dbline 186
; 
; void checkbump(void)
; {
; 	if (rear_bumper() > BUMPER_FUZZY)
	jsr _rear_bumper
	cpd #10
	bls L55
	.dbline 189
; 		{
; 			/*printf("You hit my ass\n\n");*/
; 			rspeed = lspeed = 50;
	ldd #50
	std _lspeed
	ldd #50
	std _rspeed
	.dbline 190
; 			motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 191
; 			motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 192
; 			wait(500);
	ldd #500
	jsr _wait
	.dbline 193
; 			righturn();
	jsr _righturn
	.dbline 194
; 		}
	bra L56
L55:
	.dbline 195
; 	else if (front_bumper() > BUMPER_FUZZY)
	jsr _front_bumper
	cpd #10
	bls L57
	.dbline 198
; 		{
; 			/*printf("You hit my head\n\n");*/
; 			rspeed = lspeed = -50;
	ldd #-50
	std _lspeed
	ldd #-50
	std _rspeed
	.dbline 199
; 			motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 200
; 			motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 201
; 			wait(500);
	ldd #500
	jsr _wait
	.dbline 202
; 			righturn();
	jsr _righturn
	.dbline 203
; 		}
L57:
L56:
	.dbline 204
; }
L54:
	rts
;  IX -> 0,x
_firecheck::
	.dbfunc firecheck
	.dbline 207
; void firecheck(void)
; {
; 	read_IR();
	jsr _read_IR
	.dbline 209
; 	
; 	if (IRDT[IR6clk] > FIRE)
	ldd _IRDT+10
	cpd #50
	bls L60
	.dbline 212
; 	{
; 		
; 		rspeed = lspeed = 0;
	ldd #0
	std _lspeed
	ldd #0
	std _rspeed
	.dbline 213
; 		motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 214
; 		motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 218
; 		 
; 		 /*printf("I have found fire\n\n");*/
; 		 
; 		 wait(1000);
	ldd #1000
	jsr _wait
	.dbline 219
; 	}
L60:
	.dbline 220
; }
L59:
	rts
