	.module smokden2.c
	.dbfile smokden2.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>
; #include <stdio.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);  /*clear screen*/
;   printf("%s", place);  /*home cursor*/
;   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");
;   
;   while (1)
;   {
;   	avoidobject();
L9:
	rti
;  IX -> 0,x
_TIC2_isr::
	.dbfunc TIC2_isr
	.dbline 106
;   	checkbump();
;   	firecheck();
;   }
;   
; 
; }
L10:
	rti
;  IX -> 0,x
_TIC1_isr::
	.dbfunc TIC1_isr
	.dbline 112
; 
; /**************************** End of Main ******************************/
; 
; void detectsmoke(void)
; {
; 	read_IR();
L11:
	rti
;  IX -> 0,x
_RTI_isr::
	.dbfunc RTI_isr
	.dbline 118
; 	
; 	while (IRDT[IR5clk] < NOSMOKE)
; 		{
; 			read_IR();
; 			wait(10);
; 		}
L12:
	rti
;  IX -> 0,x
_IRQ_isr::
	.dbfunc IRQ_isr
	.dbline 124
; 	printf("I have found smoke\n");
; }
; 
; void avoidobject(void)
; {
; 		 
L13:
	rti
;  IX -> 0,x
_XIRQ_isr::
	.dbfunc XIRQ_isr
	.dbline 130
; 	
; 	 	read_IR();
; 	    rspeed = lspeed = 100;
; 	    motortk(RIGHT_MOTOR, rspeed);
; 	    motortk(LEFT_MOTOR, lspeed);
; 	 	
L14:
	rti
;  IX -> 0,x
_SWI_isr::
	.dbfunc SWI_isr
	.dbline 136
; 	 	if ((IRDT[IR1clk] > IRTHRESHOLD) || (IRDT[IR2clk] > IRTHRESHOLD))
; 	 		{
; 	 			printf("Object to my right, so\n");
; 	 			printf("I will avoid it\n\n");
; 	 			righturn();	 			
; 	 		}
L15:
	rti
;  IX -> 0,x
_ILLOP_isr::
	.dbfunc ILLOP_isr
	.dbline 142
; 	 	
; 		 else if ((IRDT[IR4clk] > IRTHRESHOLD) || (IRDT[IR3clk] > IRTHRESHOLD))
; 	 
; 	 		{
; 	 			printf("Object to my left, so\n");
; 	 			printf("I will avoid it\n\n");
L16:
	rti
;  IX -> 0,x
_COP_isr::
	.dbfunc COP_isr
	.dbline 148
; 	 			lefturn();	
; 	 		}
; 	 
; }
; 
; void righturn(void)
L17:
	rti
;  IX -> 0,x
_CLMON_isr::
	.dbfunc CLMON_isr
	.dbline 154
; {
; 	printf("Turning right.\n");
; 	rspeed = -100;
; 	lspeed = 100;
; 	motortk(RIGHT_MOTOR, rspeed);
; 	motortk(LEFT_MOTOR, lspeed);
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 smokden2.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
	.dbline 73
	ldd 0,x
	addd #18
	pshb
	psha
	ldd #L22
	jsr _printf
	puly
	.dbline 74
	ldd 0,x
	addd #11
	pshb
	psha
	ldd #L22
	jsr _printf
	puly
	.dbline 75
	ldd #L23
	jsr _printf
L24:
	.dbline 77
L25:
	jsr _rear_bumper
	cpd #10
	blo L24
	.dbline 79
	jsr _read_IR
	.dbline 82
	ldd #L27
	jsr _printf
	.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 92
	ldd #L28
	jsr _printf
	.dbline 94
	ldd #500
	jsr _wait
	.dbline 96
	ldd #L29
	jsr _printf
	bra L31
L30:
	.dbline 100
	jsr _avoidobject
	.dbline 101
	jsr _checkbump
	.dbline 102
	jsr _firecheck
	.dbline 103
L31:
	.dbline 98
	bra L30
L19:
	xgdx
	addd #24
	xgdx
	txs
	pulx
	rts
;  IX -> 0,x
_detectsmoke::
	.dbfunc detectsmoke
	.dbline 112
	jsr _read_IR
	bra L35
L34:
	.dbline 116
	jsr _read_IR
	.dbline 117
	ldd #10
	jsr _wait
	.dbline 118
L35:
	.dbline 114
	ldd _IRDT+16
	cpd #40
	blo L34
	.dbline 119
	ldd #L38
	jsr _printf
	.dbline 120
L33:
	rts
;  IX -> 0,x
_avoidobject::
	.dbfunc avoidobject
	.dbline 126
	jsr _read_IR
	.dbline 127
	ldd #100
	std _lspeed
	ldd #100
	std _rspeed
	.dbline 128
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 129
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 131
	ldd _IRDT+8
	cpd #110
	bhi L43
	ldd _IRDT
	cpd #110
	bls L40
L43:
	.dbline 133
	ldd #L44
	jsr _printf
	.dbline 134
	ldd #L45
	jsr _printf
	.dbline 135
	jsr _righturn
	.dbline 136
	bra L41
L40:
	.dbline 138
	ldd _IRDT+14
	cpd #110
	bhi L50
	ldd _IRDT+12
	cpd #110
	bls L46
L50:
	.dbline 141
	ldd #L51
	jsr _printf
	.dbline 142
	ldd #L45
	jsr _printf
	.dbline 143
	jsr _lefturn
	.dbline 144
L46:
L41:
	.dbline 146
L39:
	rts
;  IX -> 0,x
_righturn::
	.dbfunc righturn
	.dbline 150
	ldd #L53
	jsr _printf
	.dbline 151
	ldd #-100
	std _rspeed
	.dbline 152
	ldd #100
	std _lspeed
	.dbline 153
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 154
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	bra L55
L54:
	.dbline 157
	jsr _read_IR
	.dbline 158
	jsr _firecheck
	.dbline 159
L55:
	.dbline 155
; 	while ((IRDT[IR1clk] > IRTHRESHOLD) || (IRDT[IR2clk] > IRTHRESHOLD))
	ldd _IRDT+8
	cpd #110
	bhi L54
	ldd _IRDT
	cpd #110
	bhi L54
	.dbline 160
; 	{
; 		read_IR();
; 		firecheck();
; 	}
; 	wait(300);
	ldd #300
	jsr _wait
	.dbline 161
; }
L52:
	rts
;  IX -> 0,x
_lefturn::
	.dbfunc lefturn
	.dbline 165
; 
; void lefturn(void)
; {
; 	printf("Turning left.\n");
	ldd #L59
	jsr _printf
	.dbline 166
; 	rspeed = 100;
	ldd #100
	std _rspeed
	.dbline 167
; 	lspeed = -100;
	ldd #-100
	std _lspeed
	.dbline 168
; 	motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 169
; 	motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	bra L61
L60:
	.dbline 172
	jsr _read_IR
	.dbline 173
	jsr _firecheck
	.dbline 174
L61:
	.dbline 170
; 	while ((IRDT[IR3clk] > IRTHRESHOLD) || (IRDT[IR4clk] > IRTHRESHOLD))
	ldd _IRDT+12
	cpd #110
	bhi L60
	ldd _IRDT+14
	cpd #110
	bhi L60
	.dbline 175
; 	{
; 		read_IR();
; 		firecheck();
; 	}
; 	wait(300);
	ldd #300
	jsr _wait
	.dbline 177
; 	
; }
L58:
	rts
;  IX -> 0,x
_checkbump::
	.dbfunc checkbump
	.dbline 181
; 
; void checkbump(void)
; {
; 	if (rear_bumper() > BUMPER_FUZZY)
	jsr _rear_bumper
	cpd #10
	bls L66
	.dbline 183
; 		{
; 			printf("You hit my ass\n\n");
	ldd #L68
	jsr _printf
	.dbline 184
; 			rspeed = lspeed = 50;
	ldd #50
	std _lspeed
	ldd #50
	std _rspeed
	.dbline 185
; 			motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 186
; 			motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 187
; 			wait(500);
	ldd #500
	jsr _wait
	.dbline 188
; 			righturn();
	jsr _righturn
	.dbline 189
; 		}
	bra L67
L66:
	.dbline 190
; 	else if (front_bumper() > BUMPER_FUZZY)
	jsr _front_bumper
	cpd #10
	bls L69
	.dbline 192
; 		{
; 			printf("You hit my head\n\n");
	ldd #L71
	jsr _printf
	.dbline 193
; 			rspeed = lspeed = -50;
	ldd #-50
	std _lspeed
	ldd #-50
	std _rspeed
	.dbline 194
; 			motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 195
; 			motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 196
; 			wait(500);
	ldd #500
	jsr _wait
	.dbline 197
; 			righturn();
	jsr _righturn
	.dbline 198
; 		}
L69:
L67:
	.dbline 199
; }
L65:
	rts
;  IX -> 0,x
_firecheck::
	.dbfunc firecheck
	.dbline 202
; void firecheck(void)
; {
; 	read_IR();
	jsr _read_IR
	.dbline 204
; 	
; 	if (IRDT[IR6clk] > FIRE)
	ldd _IRDT+10
	cpd #50
	bls L73
	.dbline 207
; 	{
; 		
; 		rspeed = lspeed = 0;
	ldd #0
	std _lspeed
	ldd #0
	std _rspeed
	.dbline 208
; 		motortk(RIGHT_MOTOR, rspeed);
	ldd _rspeed
	pshb
	psha
	ldd #1
	jsr _motortk
	puly
	.dbline 209
; 		motortk(LEFT_MOTOR, lspeed);
	ldd _lspeed
	pshb
	psha
	ldd #0
	jsr _motortk
	puly
	.dbline 211
; 		 
; 		 printf("I have found fire\n\n");
	ldd #L76
	jsr _printf
	.dbline 213
; 		 
; 		 wait(1000);
	ldd #1000
	jsr _wait
	.dbline 214
; 	}
L73:
	.dbline 215
; }
L72:
	rts
L76:
	.byte 'I,32,'h,'a,'v,'e,32,'f,'o,'u,'n,'d,32,'f,'i,'r
	.byte 'e,10,10,0
L71:
	.byte 'Y,'o,'u,32,'h,'i,'t,32,'m,'y,32,'h,'e,'a,'d,10
	.byte 10,0
L68:
	.byte 'Y,'o,'u,32,'h,'i,'t,32,'m,'y,32,'a,'s,'s,10,10
	.byte 0
L59:
	.byte 'T,'u,'r,'n,'i,'n,'g,32,'l,'e,'f,'t,46,10,0
L53:
	.byte 'T,'u,'r,'n,'i,'n,'g,32,'r,'i,'g,'h,'t,46,10,0
L51:
	.byte 'O,'b,'j,'e,'c,'t,32,'t,'o,32,'m,'y,32,'l,'e,'f
	.byte 't,44,32,'s,'o,10,0
L45:
	.byte 'I,32,'w,'i,'l,'l,32,'a,'v,'o,'i,'d,32,'i,'t,10
	.byte 10,0
L44:
	.byte 'O,'b,'j,'e,'c,'t,32,'t,'o,32,'m,'y,32,'r,'i,'g
	.byte 'h,'t,44,32,'s,'o,10,0
L38:
	.byte 'I,32,'h,'a,'v,'e,32,'f,'o,'u,'n,'d,32,'s,'m,'o
	.byte 'k,'e,10,0
L29:
	.byte 'S,'t,'a,'r,'t,'i,'n,'g,32,'t,'o,32,'a,'v,'o,'i
	.byte 'd,32,'o,'b,'j,'e,'c,'t,'s,10,0
L28:
	.byte 'W,'i,'l,'l,32,'s,'t,'a,'r,'t,32,'t,'o,32,'l,'o
	.byte 'o,'k,32,'f,'o,'r,32,'t,'h,'e,32,'f,'i,'r,'e,10
	.byte 10,0
L27:
	.byte 's,'t,'a,'r,'t,'i,'n,'g,32,'t,'o,32,'l,'o,'o,'k
	.byte 32,'f,'o,'r,32,'s,'m,'o,'k,'e,10,10,0
L23:
	.byte 'H,'i,'t,32,'m,'y,32,'a,'s,'s,32,'t,'o,32,'s,'t
	.byte 'a,'r,'t,32,'m,'e,10,10,0
L22:
	.byte 37,'s,0
