                        .module firsttest.c
                        .area data
 0000           _T_counts::
 0000                   .blkb 2
                        .area idata
 0000 4E20              .word 20000
                        .area data
                        .area text
 0000           _main::
 0000           ; /* C Listing 11.4 */
 0000           ; 
 0000           ; #include <hc11.h>	/* Include register definitions */
 0000           ; #include <stdio.h>
 0000           ; #define motcont *(unsigned char volatile *)(0xB590)
 0000           ; #define linetrack *(unsigned char volatile *) (0XB5A0)
 0000           ; 
 0000           ; 
 0000           ; /* Declarations */
 0000           ; unsigned int OC2hi, OC2lo, OC3hi, OC3lo;	/* Duty cycle data */
 0000           ; unsigned int T_counts=0x4e20, per_on2, per_on3; //helper=0,cntflag=0;
 0000           ; 
 0000           ; 
 0000           ; /* Prototypes */
 0000           ; void initoc(void);
 0000           ; void rtoc2(void);
 0000           ; void rtoc3(void);
 0000           ; void cnts2(void);
 0000           ; void cnts3(void);
 0000           ; //void RTIINTR (void);
 0000           ; 
 0000           ; 
 0000           ; void main(void)
 0000           ; {
 0000           ;  	
 0000           ; 	setbaud(BAUD9600);
 0000 CC0030            ldd #48
 0003 BD0000            jsr _setbaud
 0006           ;       INTR_OFF();
 0006 0F                                sei
 0007           
 0007           ;       /* set up jump vector for buffalo */
 0007           ;       asm("   ldaa #$7e");
 0007 867E                              ldaa #$7e
 0009           
 0009           ;       asm("   staa $dc");
 0009 97DC                              staa $dc
 000B           
 000B           ;       //asm(" staa $eb");
 000B           ;       asm("   staa $d9");
 000B 97D9                              staa $d9
 000D           
 000D           ;       asm("   ldd #_rtoc2");
 000D CC0078                            ldd #_rtoc2
 0010           
 0010           ;       asm("   std $dd");
 0010 DDDD                              std $dd
 0012           
 0012           ;       asm("   ldd #_rtoc3");
 0012 CC00AE                            ldd #_rtoc3
 0015           
 0015           ;       asm("   std $da");
 0015 DDDA                              std $da
 0017           
 0017           ;       //asm(" ldd #_RTIINTR");
 0017           ;       //asm(" std $ec");
 0017           ;       OC2hi = 0x3e8;
 0017 CC03E8            ldd #1000
 001A FD000A            std _OC2hi
 001D           ;       OC2lo = 0x3e8;
 001D CC03E8            ldd #1000
 0020 FD0008            std _OC2lo
 0023           ;       OC3hi = 0x3e8;
 0023 CC03E8            ldd #1000
 0026 FD0006            std _OC3hi
 0029           ;       OC3lo = 0x3e8;
 0029 CC03E8            ldd #1000
 002C FD0004            std _OC3lo
 002F 2029              bra L5
 0031           L4:
 0031           ; 	//TMSK2=0x40;
 0031           ; 	//PACTL=PACTL|0x03;
 0031           ; 	
 0031           ; 	//initoc();
 0031           ; 	
 0031           ; 	//cnts2();
 0031           ; 	//cnts3();
 0031           ; 	
 0031           ; 	while(1)
 0031           ; 	{	 //printf("%x\n",linetrack);
 0031           ; 		 TMSK1=0x00;
 0031 7F1022            clr 0x1022
 0034           ;        PORTA=0x00;
 0034 7F1000            clr 0x1000
 0037 201A              bra L8
 0039           L7:
 0039 BD005D            jsr _initoc
 003C C603              ldab #3
 003E F7B590            stab 0xb590
 0041 CC0014            ldd #20
 0044 FD0002            std _per_on2
 0047 CC0014            ldd #20
 004A FD0000            std _per_on3
 004D BD00E4            jsr _cnts2
 0050 BD01C1            jsr _cnts3
 0053           L8:
 0053           	; vol
 0053 F6B5A0            ldab 0xb5a0
 0056 C105              cmpb #5
 0058 27DF              beq L7
 005A           L5:
 005A 20D5              bra L4
 005C           X0:
 005C           ; 	 	 while (linetrack == 0x05){
 005C           ; 		 	initoc();
 005C           ; 			motcont = 0x03;
 005C           ; 			per_on2=20;
 005C           ; 			per_on3=20;
 005C           ; 			cnts2();
 005C           ; 			cnts3();
 005C           ; 			//printf("%x\n",linetrack);
 005C           ; 			
 005C           ; 			}
 005C           ; 		 /*while (linetrack == 0x01){
 005C           ; 		 	initoc();
 005C           ; 		 	per_on2= 90;
 005C           ; 			per_on3=10;
 005C           ; 		 	cnts2();
 005C           ; 		 	cnts3();
 005C           ; 		 	printf("%x\n",linetrack);
 005C           ; 	 		motcont = 0x03;
 005C           ; 		 }*/	 
 005C           ; 		 /*while (linetrack == 0x04){
 005C           ; 		    initoc();
 005C           ; 		 	per_on2=10;
 005C           ; 			per_on3=90;
 005C           ; 		 	cnts2();
 005C           ; 		 	cnts3();
 005C           ; 			printf("%x\n",linetrack);
 005C           ; 		 	//printf("%x   %x   %x    %x\n",OC2hi,OC2lo,OC3hi,OC3lo); 
 005C           ; 	 		motcont = 0x03;
 005C           ; 		 }*/	 
 005C           ; 		//else //if  (helper == 10){ 
 005C           ; 			// {TMSK1=0x00;
 005C           ;     		// PORTA=0x00;}
 005C           ; 			 //printf("%d\n",helper);
 005C           ; 			 
 005C           ; 			 	 
 005C           ;     }
 005C           ; 
 005C           ; 	
 005C           ; }
 005C           L3:
 005C                   .dbline 0 ; func end
 005C 39                rts
 005D           _initoc::
 005D           ; 
 005D           ; void initoc(void)
 005D           ; /* Initialize OC2 */
 005D           ; {
 005D           ; 	TOC2 = TCNT;
 005D           	; vol
 005D FC100E            ldd 0x100e
 0060 FD1018            std 0x1018
 0063           ;       TOC3 = TCNT;
 0063                   ; vol
 0063 FC100E            ldd 0x100e
 0066 FD101A            std 0x101a
 0069           ;       TCTL1 = 0x00;
 0069 7F1020            clr 0x1020
 006C           ;       TFLG1 = 0x60;
 006C C660              ldab #96
 006E F71023            stab 0x1023
 0071           ;       TMSK1 = 0x60;
 0071 C660              ldab #96
 0073 F71022            stab 0x1022
 0076           ;       INTR_ON();
 0076 0E                                cli
 0077           
 0077           ; }
 0077           L10:
 0077                   .dbline 0 ; func end
 0077 39                rts
 0078           _rtoc2::
 0078           ; 
 0078           ; void rtoc2(void)
 0078           ; /* Interrupt Service Routine for OC2 PWM */
 0078           ; {  
 0078           ; 	if ((PORTA & 0X40) == 0){ 
 0078 18CE1000          ldy #0x1000
 007C 181F004002        brclr 0,y,#64,X1
 0081 2013              bra L12
 0083           X1:
 0083           ; 		TOC2 = TOC2 + OC2lo;
 0083           	; vol
 0083 FC1018            ldd 0x1018
 0086 F30008            addd _OC2lo
 0089 FD1018            std 0x1018
 008C           ;               PORTA = PORTA | 0x40;
 008C 18CE1000          ldy #0x1000
 0090 181C0040          bset 0,y,#64
 0094           ;               }
 0094 2009              bra L13
 0096           L12:
 0096           ; 	else
 0096           ; 		TOC2 = TOC2 + OC2hi;
 0096           	; vol
 0096 FC1018            ldd 0x1018
 0099 F3000A            addd _OC2hi
 009C FD1018            std 0x1018
 009F           L13:
 009F           ; 		PORTA = PORTA |  0xBF;
 009F 18CE1000          ldy #0x1000
 00A3 181C00BF          bset 0,y,#191
 00A7           ;       //TCTL1 = TCTL1 ^ 0x40; /* invert OL2 to toggle next OC2 edge */
 00A7           ;       TFLG1 = 0x40;   /* Clear flag OC2F */
 00A7 C640              ldab #64
 00A9 F71023            stab 0x1023
 00AC           ;       asm("   rti");  /* This is an interrupt service routine */
 00AC 3B                                rti
 00AD           
 00AD           ; }
 00AD           L11:
 00AD                   .dbline 0 ; func end
 00AD 39                rts
 00AE           _rtoc3::
 00AE           ; 
 00AE           ; void rtoc3(void)
 00AE           ; {	
 00AE           ; 	if ((PORTA & 0X20) == 0) {
 00AE 18CE1000          ldy #0x1000
 00B2 181F002002        brclr 0,y,#32,X2
 00B7 2013              bra L15
 00B9           X2:
 00B9           ; 		TOC3 = TOC3 + OC3lo;
 00B9           	; vol
 00B9 FC101A            ldd 0x101a
 00BC F30004            addd _OC3lo
 00BF FD101A            std 0x101a
 00C2           ;               PORTA = PORTA | 0x20;
 00C2 18CE1000          ldy #0x1000
 00C6 181C0020          bset 0,y,#32
 00CA           ;       }       
 00CA 2009              bra L16
 00CC           L15:
 00CC           ; 	else
 00CC           ; 		TOC3 = TOC3 + OC3hi;
 00CC           	; vol
 00CC FC101A            ldd 0x101a
 00CF F30006            addd _OC3hi
 00D2 FD101A            std 0x101a
 00D5           L16:
 00D5           ; 		PORTA = PORTA | 0xDF;
 00D5 18CE1000          ldy #0x1000
 00D9 181C00DF          bset 0,y,#223
 00DD           ;       //TCTL1 = TCTL1 ^ 0x10; /* invert OL2 to toggle next OC2 edge */
 00DD           ;       TFLG1 = 0x20;   /* Clear flag OC2F */
 00DD C620              ldab #32
 00DF F71023            stab 0x1023
 00E2           ;       asm("   rti");  /* This is an interrupt service routine */
 00E2 3B                                rti
 00E3           
 00E3           ; }
 00E3           L14:
 00E3                   .dbline 0 ; func end
 00E3 39                rts
 00E4           ;  lreg1 -> -4,x
 00E4           ;  lreg2 -> -8,x
 00E4           ;  IX -> 0,x
 00E4           ;          ?temp -> +2,x
 00E4           ;          ?temp -> +6,x
 00E4           _cnts2::
 00E4 BD0000            jsr __enterb
 00E7 88                .byte 0x88
 00E8           ; void cnts2 (void)
 00E8           ; {
 00E8           ;       OC2hi=T_counts * (float)per_on2/100;
 00E8 FC0002            ldd _per_on2
 00EB 04                lsrd
 00EC BD0000            jsr __d2lreg
 00EF BD0000            jsr __long2fp
 00F2 BD0000            jsr __fpmov
 00F5 18CE02A6          ldy #L21
 00F9 BD0000            jsr __tofp1
 00FC BD0000            jsr __fpmul
 00FF FC0002            ldd _per_on2
 0102 8400              anda #0
 0104 C401              andb #1
 0106 BD0000            jsr __d2lreg
 0109 BD0000            jsr __pshfp1 ; spill
 010C BD0000            jsr __long2fp
 010F BD0000            jsr __fpmov
 0112 BD0000            jsr __pulfp1 ; reload
 0115 BD0000            jsr __fpadd
 0118 BD0000            jsr __fpmov
 011B FC0000            ldd _T_counts
 011E 04                lsrd
 011F BD0000            jsr __d2lreg
 0122 BD0000            jsr __long2fp
 0125 BD0000            jsr __pshfp2 ; spill
 0128 BD0000            jsr __fpmov
 012B 18CE02A6          ldy #L21
 012F BD0000            jsr __tofp1
 0132 BD0000            jsr __fpmul
 0135 FC0000            ldd _T_counts
 0138 8400              anda #0
 013A C401              andb #1
 013C BD0000            jsr __d2lreg
 013F BD0000            jsr __pshfp1 ; spill
 0142 BD0000            jsr __long2fp
 0145 BD0000            jsr __fpmov
 0148 BD0000            jsr __pulfp1 ; reload
 014B BD0000            jsr __fpadd
 014E BD0000            jsr __pulfp2 ; reload
 0151 BD0000            jsr __fpmul
 0154 18CE02A2          ldy #L22
 0158 BD0000            jsr __tofp2
 015B BD0000            jsr __fpdiv
 015E EC00              ldd 0,x
 0160 C30002            addd #2
 0163 188F              xgdy
 0165 BD0000            jsr __fromfp1
 0168 EC00              ldd 0,x
 016A C30002            addd #2
 016D 188F              xgdy
 016F BD0000            jsr __tofp1
 0172 18CE029E          ldy #L23
 0176 BD0000            jsr __tofp2
 0179 BD0000            jsr __fpcmp
 017C 2D1E              blt L19
 017E EC00              ldd 0,x
 0180 C30002            addd #2
 0183 188F              xgdy
 0185 BD0000            jsr __tofp1
 0188 18CE029E          ldy #L23
 018C BD0000            jsr __tofp2
 018F BD0000            jsr __fpsub
 0192 BD0000            jsr __fp2int
 0195 C38000            addd #0x8000
 0198 ED06              std 6,x
 019A 200F              bra L20
 019C           L19:
 019C EC00              ldd 0,x
 019E C30002            addd #2
 01A1 188F              xgdy
 01A3 BD0000            jsr __tofp1
 01A6 BD0000            jsr __fp2int
 01A9 ED06              std 6,x
 01AB           L20:
 01AB EC06              ldd 6,x
 01AD FD000A            std _OC2hi
 01B0           ;       OC2lo=T_counts - OC2hi;
 01B0 FC0000            ldd _T_counts
 01B3 B3000A            subd _OC2hi
 01B6 FD0008            std _OC2lo
 01B9           ; }
 01B9           L17:
 01B9 8F                xgdx
 01BA C30008            addd #8
 01BD 8F                xgdx
 01BE 35                txs
 01BF 38                pulx
 01C0                   .dbline 0 ; func end
 01C0 39                rts
 01C1           ;  lreg1 -> -4,x
 01C1           ;  lreg2 -> -8,x
 01C1           ;  IX -> 0,x
 01C1           ;          ?temp -> +2,x
 01C1           ;          ?temp -> +6,x
 01C1           _cnts3::
 01C1 BD0000            jsr __enterb
 01C4 88                .byte 0x88
 01C5           ; 
 01C5           ; void cnts3 (void)
 01C5           ; {
 01C5           ;       OC3hi=T_counts * (float)per_on3/100;
 01C5 FC0000            ldd _per_on3
 01C8 04                lsrd
 01C9 BD0000            jsr __d2lreg
 01CC BD0000            jsr __long2fp
 01CF BD0000            jsr __fpmov
 01D2 18CE02A6          ldy #L21
 01D6 BD0000            jsr __tofp1
 01D9 BD0000            jsr __fpmul
 01DC FC0000            ldd _per_on3
 01DF 8400              anda #0
 01E1 C401              andb #1
 01E3 BD0000            jsr __d2lreg
 01E6 BD0000            jsr __pshfp1 ; spill
 01E9 BD0000            jsr __long2fp
 01EC BD0000            jsr __fpmov
 01EF BD0000            jsr __pulfp1 ; reload
 01F2 BD0000            jsr __fpadd
 01F5 BD0000            jsr __fpmov
 01F8 FC0000            ldd _T_counts
 01FB 04                lsrd
 01FC BD0000            jsr __d2lreg
 01FF BD0000            jsr __long2fp
 0202 BD0000            jsr __pshfp2 ; spill
 0205 BD0000            jsr __fpmov
 0208 18CE02A6          ldy #L21
 020C BD0000            jsr __tofp1
 020F BD0000            jsr __fpmul
 0212 FC0000            ldd _T_counts
 0215 8400              anda #0
 0217 C401              andb #1
 0219 BD0000            jsr __d2lreg
 021C BD0000            jsr __pshfp1 ; spill
 021F BD0000            jsr __long2fp
 0222 BD0000            jsr __fpmov
 0225 BD0000            jsr __pulfp1 ; reload
 0228 BD0000            jsr __fpadd
 022B BD0000            jsr __pulfp2 ; reload
 022E BD0000            jsr __fpmul
 0231 18CE02A2          ldy #L22
 0235 BD0000            jsr __tofp2
 0238 BD0000            jsr __fpdiv
 023B EC00              ldd 0,x
 023D C30002            addd #2
 0240 188F              xgdy
 0242 BD0000            jsr __fromfp1
 0245 EC00              ldd 0,x
 0247 C30002            addd #2
 024A 188F              xgdy
 024C BD0000            jsr __tofp1
 024F 18CE029E          ldy #L23
 0253 BD0000            jsr __tofp2
 0256 BD0000            jsr __fpcmp
 0259 2D1E              blt L26
 025B EC00              ldd 0,x
 025D C30002            addd #2
 0260 188F              xgdy
 0262 BD0000            jsr __tofp1
 0265 18CE029E          ldy #L23
 0269 BD0000            jsr __tofp2
 026C BD0000            jsr __fpsub
 026F BD0000            jsr __fp2int
 0272 C38000            addd #0x8000
 0275 ED06              std 6,x
 0277 200F              bra L27
 0279           L26:
 0279 EC00              ldd 0,x
 027B C30002            addd #2
 027E 188F              xgdy
 0280 BD0000            jsr __tofp1
 0283 BD0000            jsr __fp2int
 0286 ED06              std 6,x
 0288           L27:
 0288 EC06              ldd 6,x
 028A FD0006            std _OC3hi
 028D           ;       OC3lo=T_counts - OC3hi;
 028D FC0000            ldd _T_counts
 0290 B30006            subd _OC3hi
 0293 FD0004            std _OC3lo
 0296           ; }     
 0296           L24:
 0296 8F                xgdx
 0297 C30008            addd #8
 029A 8F                xgdx
 029B 35                txs
 029C 38                pulx
 029D                   .dbline 0 ; func end
 029D 39                rts
                        .area bss
 0000           _per_on3::
 0000                   .blkb 2
 0002           _per_on2::
 0002                   .blkb 2
 0004           _OC3lo::
 0004                   .blkb 2
 0006           _OC3hi::
 0006                   .blkb 2
 0008           _OC2lo::
 0008                   .blkb 2
 000A           _OC2hi::
 000A                   .blkb 2
                        .area text
 029E           L23:
 029E 47000000          .word 0x4700,0x0
 02A2           L22:
 02A2 42C80000          .word 0x42c8,0x0
 02A6           L21:
 02A6 40000000          .word 0x4000,0x0
