                        .module STOPGOTEST.c
                        .area data
 0000           _T_counts::
 0000                   .blkb 2
                        .area idata
 0000 4E20              .word 20000
                        .area data
 0002           _per_on2::
 0002                   .blkb 2
                        .area idata
 0002 0019              .word 25
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 0019              .word 25
                        .area data
 0006           _helper::
 0006                   .blkb 2
                        .area idata
 0006 0000              .word 0
                        .area data
 0008           _cntflag::
 0008                   .blkb 2
                        .area idata
 0008 0000              .word 0
                        .area data
                        .area text
                ;  IX -> 0,x
                ;        cnttime -> +2,x
                ;              x -> +4,x
 0000           _main::
 0000 BD0000            jsr __enterb
 0003 08                .byte 0x8
 0004           ; /* C Listing 11.4 */
 0004           ; 
 0004           ; #include <hc11.h>     /* Include register definitions */
 0004           ; #include <stdio.h>
 0004           ; #define motcont *(unsigned char volatile *)(0xB590)
 0004           ; 
 0004           ; 
 0004           ; /* Declarations */
 0004           ; unsigned int OC2hi, OC2lo, OC3hi, OC3lo;      /* Duty cycle data */
 0004           ; unsigned int T_counts=0x4e20, per_on2=25, per_on3=25, helper=0,cntflag=0;
 0004           ; 
 0004           ; 
 0004           ; /* Prototypes */
 0004           ; void initoc(void);
 0004           ; void rtoc2(void);
 0004           ; void rtoc3(void);
 0004           ; void cnts2(void);
 0004           ; void cnts3(void);
 0004           ; 
 0004           ; 
 0004           ; 
 0004           ; void main(void)
 0004           ; {
 0004           ;       int cnttime;
 0004           ;       float x=0;
 0004 18CE02DA          ldy #L4
 0008 BD0000            jsr __tofp1
 000B EC00              ldd 0,x
 000D C30004            addd #4
 0010 188F              xgdy
 0012 BD0000            jsr __fromfp1
 0015           ;       OPTION = 0x93;
 0015 C693              ldab #147
 0017 F71039            stab 0x1039
 001A           ;       
 001A           ;       setbaud(BAUD9600);
 001A CC0030            ldd #48
 001D BD0000            jsr _setbaud
 0020           ;       INTR_OFF();
 0020 0F                                sei
 0021           
 0021           ;       /* set up jump vector for buffalo */
 0021           ;       asm("   ldaa #$7e");
 0021 867E                              ldaa #$7e
 0023           
 0023           ;       asm("   staa $dc");
 0023 97DC                              staa $dc
 0025           
 0025           ;       asm("   staa $eb");
 0025 97EB                              staa $eb
 0027           
 0027           ;       asm("   staa $d9");
 0027 97D9                              staa $d9
 0029           
 0029           ;       asm("   ldd #_rtoc2");
 0029 CC0094                            ldd #_rtoc2
 002C           
 002C           ;       asm("   std $dd");
 002C DDDD                              std $dd
 002E           
 002E           ;       asm("   ldd #_rtoc3");
 002E CC00CA                            ldd #_rtoc3
 0031           
 0031           ;       asm("   std $da");
 0031 DDDA                              std $da
 0033           
 0033           ;       asm("   ldd #_RTIINTR");
 0033 CC02BA                            ldd #_RTIINTR
 0036           
 0036           ;       asm("   std $ec");
 0036 DDEC                              std $ec
 0038           
 0038 2035              bra L6
 003A           X0:
 003A           ; 	
 003A           ; 	
 003A           ; 	/*initoc();
 003A           ; 	
 003A           ; 	
 003A           ; 	
 003A           ; 	cnts2();
 003A           ; 	cnts3();*/
 003A           ; 	
 003A           ; while (1)
 003A           ; {	 
 003A           L8:
 003A           ; 	while(cntflag <= 244)
 003A           ; 	{	 
 003A           ; 		 ADCTL=0x01;
 003A C601              ldab #1
 003C F71030            stab 0x1030
 003F           L11:
 003F           L12:
 003F           ; 		 while((ADCTL & 0x80) != 0x80);
 003F           	; vol
 003F F61030            ldab 0x1030
 0042 C480              andb #128
 0044 C180              cmpb #128
 0046 26F7              bne L11
 0048           ;                printf ( "%d\n" , ADR1);
 0048                   ; vol
 0048 F61031            ldab 0x1031
 004B 4F                clra
 004C 37                pshb
 004D 36                psha
 004E CC02D6            ldd #L14
 0051 BD0000            jsr _printf
 0054 1838              puly
 0056           ;                
 0056           ;               
 0056           ;                               
 0056           ;                 if (ADR1 < 200 && ADR1 > 100){
 0056                   ; vol
 0056 F61031            ldab 0x1031
 0059 C1C8              cmpb #200
 005B 2409              bhs L15
 005D                   ; vol
 005D F61031            ldab 0x1031
 0060 C164              cmpb #100
 0062 2302              bls L15
 0064           ;                 break;
 0064 2009              bra L10
 0066           L15:
 0066           L9:
 0066 FC0008            ldd _cntflag
 0069 1A8300F4          cpd #244
 006D 23CB              bls L8
 006F           L10:
 006F           L6:
 006F 20F5              bra L9
 0071           X1:
 0071           ; 	      }
 0071           ;      }
 0071           ; 	  	   	/*initoc();
 0071           ; 			motcont = 0x03;
 0071           ; 			cnts2();
 0071           ; 			cnts3();*/
 0071           ; }			
 0071           ; }
 0071           L3:
 0071 8F                xgdx
 0072 C30008            addd #8
 0075 8F                xgdx
 0076 35                txs
 0077 38                pulx
 0078                   .dbline 0 ; func end
 0078 39                rts
 0079           _initoc::
 0079           ; 
 0079           ; void initoc(void)
 0079           ; /* Initialize OC2 */
 0079           ; {
 0079           ; 	TOC2 = TCNT;
 0079           	; vol
 0079 FC100E            ldd 0x100e
 007C FD1018            std 0x1018
 007F           ;       TOC3 = TCNT;
 007F                   ; vol
 007F FC100E            ldd 0x100e
 0082 FD101A            std 0x101a
 0085           ;       TCTL1 = 0x00;
 0085 7F1020            clr 0x1020
 0088           ;       TFLG1 = 0x60;
 0088 C660              ldab #96
 008A F71023            stab 0x1023
 008D           ;       TMSK1 = 0x60;
 008D C660              ldab #96
 008F F71022            stab 0x1022
 0092           ;       INTR_ON();
 0092 0E                                cli
 0093           
 0093           ; }
 0093           L17:
 0093                   .dbline 0 ; func end
 0093 39                rts
 0094           _rtoc2::
 0094           ; 
 0094           ; void rtoc2(void)
 0094           ; /* Interrupt Service Routine for OC2 PWM */
 0094           ; {  
 0094           ; 	if ((PORTA & 0X40) == 0){ 
 0094 18CE1000          ldy #0x1000
 0098 181F004002        brclr 0,y,#64,X2
 009D 2013              bra L19
 009F           X2:
 009F           ; 		TOC2 = TOC2 + OC2lo;
 009F           	; vol
 009F FC1018            ldd 0x1018
 00A2 F30004            addd _OC2lo
 00A5 FD1018            std 0x1018
 00A8           ;               PORTA = PORTA | 0x40;
 00A8 18CE1000          ldy #0x1000
 00AC 181C0040          bset 0,y,#64
 00B0           ;               }
 00B0 2009              bra L20
 00B2           L19:
 00B2           ; 	else
 00B2           ; 		TOC2 = TOC2 + OC2hi;
 00B2           	; vol
 00B2 FC1018            ldd 0x1018
 00B5 F30006            addd _OC2hi
 00B8 FD1018            std 0x1018
 00BB           L20:
 00BB           ; 		PORTA = PORTA |  0xBF;
 00BB 18CE1000          ldy #0x1000
 00BF 181C00BF          bset 0,y,#191
 00C3           ;       //TCTL1 = TCTL1 ^ 0x40; /* invert OL2 to toggle next OC2 edge */
 00C3           ;       TFLG1 = 0x40;   /* Clear flag OC2F */
 00C3 C640              ldab #64
 00C5 F71023            stab 0x1023
 00C8           ;       asm("   rti");  /* This is an interrupt service routine */
 00C8 3B                                rti
 00C9           
 00C9           ; }
 00C9           L18:
 00C9                   .dbline 0 ; func end
 00C9 39                rts
 00CA           _rtoc3::
 00CA           ; 
 00CA           ; void rtoc3(void)
 00CA           ; {	
 00CA           ; 	if ((PORTA & 0X20) == 0) {
 00CA 18CE1000          ldy #0x1000
 00CE 181F002002        brclr 0,y,#32,X3
 00D3 2013              bra L22
 00D5           X3:
 00D5           ; 		TOC3 = TOC3 + OC3lo;
 00D5           	; vol
 00D5 FC101A            ldd 0x101a
 00D8 F30000            addd _OC3lo
 00DB FD101A            std 0x101a
 00DE           ;               PORTA = PORTA | 0x20;
 00DE 18CE1000          ldy #0x1000
 00E2 181C0020          bset 0,y,#32
 00E6           ;       }       
 00E6 2009              bra L23
 00E8           L22:
 00E8           ; 	else
 00E8           ; 		TOC3 = TOC3 + OC3hi;
 00E8           	; vol
 00E8 FC101A            ldd 0x101a
 00EB F30002            addd _OC3hi
 00EE FD101A            std 0x101a
 00F1           L23:
 00F1           ; 		PORTA = PORTA | 0xDF;
 00F1 18CE1000          ldy #0x1000
 00F5 181C00DF          bset 0,y,#223
 00F9           ;       //TCTL1 = TCTL1 ^ 0x10; /* invert OL2 to toggle next OC2 edge */
 00F9           ;       TFLG1 = 0x20;   /* Clear flag OC2F */
 00F9 C620              ldab #32
 00FB F71023            stab 0x1023
 00FE           ;       asm("   rti");  /* This is an interrupt service routine */
 00FE 3B                                rti
 00FF           
 00FF           ; }
 00FF           L21:
 00FF                   .dbline 0 ; func end
 00FF 39                rts
 0100           ;  lreg1 -> -4,x
 0100           ;  lreg2 -> -8,x
 0100           ;  IX -> 0,x
 0100           ;          ?temp -> +2,x
 0100           ;          ?temp -> +6,x
 0100           _cnts2::
 0100 BD0000            jsr __enterb
 0103 88                .byte 0x88
 0104           ; void cnts2 (void)
 0104           ; {
 0104           ;       OC2hi=T_counts * (float)per_on2/100;
 0104 FC0002            ldd _per_on2
 0107 04                lsrd
 0108 BD0000            jsr __d2lreg
 010B BD0000            jsr __long2fp
 010E BD0000            jsr __fpmov
 0111 18CE02D2          ldy #L28
 0115 BD0000            jsr __tofp1
 0118 BD0000            jsr __fpmul
 011B FC0002            ldd _per_on2
 011E 8400              anda #0
 0120 C401              andb #1
 0122 BD0000            jsr __d2lreg
 0125 BD0000            jsr __pshfp1 ; spill
 0128 BD0000            jsr __long2fp
 012B BD0000            jsr __fpmov
 012E BD0000            jsr __pulfp1 ; reload
 0131 BD0000            jsr __fpadd
 0134 BD0000            jsr __fpmov
 0137 FC0000            ldd _T_counts
 013A 04                lsrd
 013B BD0000            jsr __d2lreg
 013E BD0000            jsr __long2fp
 0141 BD0000            jsr __pshfp2 ; spill
 0144 BD0000            jsr __fpmov
 0147 18CE02D2          ldy #L28
 014B BD0000            jsr __tofp1
 014E BD0000            jsr __fpmul
 0151 FC0000            ldd _T_counts
 0154 8400              anda #0
 0156 C401              andb #1
 0158 BD0000            jsr __d2lreg
 015B BD0000            jsr __pshfp1 ; spill
 015E BD0000            jsr __long2fp
 0161 BD0000            jsr __fpmov
 0164 BD0000            jsr __pulfp1 ; reload
 0167 BD0000            jsr __fpadd
 016A BD0000            jsr __pulfp2 ; reload
 016D BD0000            jsr __fpmul
 0170 18CE02CE          ldy #L29
 0174 BD0000            jsr __tofp2
 0177 BD0000            jsr __fpdiv
 017A EC00              ldd 0,x
 017C C30002            addd #2
 017F 188F              xgdy
 0181 BD0000            jsr __fromfp1
 0184 EC00              ldd 0,x
 0186 C30002            addd #2
 0189 188F              xgdy
 018B BD0000            jsr __tofp1
 018E 18CE02CA          ldy #L30
 0192 BD0000            jsr __tofp2
 0195 BD0000            jsr __fpcmp
 0198 2D1E              blt L26
 019A EC00              ldd 0,x
 019C C30002            addd #2
 019F 188F              xgdy
 01A1 BD0000            jsr __tofp1
 01A4 18CE02CA          ldy #L30
 01A8 BD0000            jsr __tofp2
 01AB BD0000            jsr __fpsub
 01AE BD0000            jsr __fp2int
 01B1 C38000            addd #0x8000
 01B4 ED06              std 6,x
 01B6 200F              bra L27
 01B8           L26:
 01B8 EC00              ldd 0,x
 01BA C30002            addd #2
 01BD 188F              xgdy
 01BF BD0000            jsr __tofp1
 01C2 BD0000            jsr __fp2int
 01C5 ED06              std 6,x
 01C7           L27:
 01C7 EC06              ldd 6,x
 01C9 FD0006            std _OC2hi
 01CC           ;       OC2lo=T_counts - OC2hi;
 01CC FC0000            ldd _T_counts
 01CF B30006            subd _OC2hi
 01D2 FD0004            std _OC2lo
 01D5           ; }
 01D5           L24:
 01D5 8F                xgdx
 01D6 C30008            addd #8
 01D9 8F                xgdx
 01DA 35                txs
 01DB 38                pulx
 01DC                   .dbline 0 ; func end
 01DC 39                rts
 01DD           ;  lreg1 -> -4,x
 01DD           ;  lreg2 -> -8,x
 01DD           ;  IX -> 0,x
 01DD           ;          ?temp -> +2,x
 01DD           ;          ?temp -> +6,x
 01DD           _cnts3::
 01DD BD0000            jsr __enterb
 01E0 88                .byte 0x88
 01E1           ; 
 01E1           ; void cnts3 (void)
 01E1           ; {
 01E1           ;       OC3hi=T_counts * (float)per_on3/100;
 01E1 FC0004            ldd _per_on3
 01E4 04                lsrd
 01E5 BD0000            jsr __d2lreg
 01E8 BD0000            jsr __long2fp
 01EB BD0000            jsr __fpmov
 01EE 18CE02D2          ldy #L28
 01F2 BD0000            jsr __tofp1
 01F5 BD0000            jsr __fpmul
 01F8 FC0004            ldd _per_on3
 01FB 8400              anda #0
 01FD C401              andb #1
 01FF BD0000            jsr __d2lreg
 0202 BD0000            jsr __pshfp1 ; spill
 0205 BD0000            jsr __long2fp
 0208 BD0000            jsr __fpmov
 020B BD0000            jsr __pulfp1 ; reload
 020E BD0000            jsr __fpadd
 0211 BD0000            jsr __fpmov
 0214 FC0000            ldd _T_counts
 0217 04                lsrd
 0218 BD0000            jsr __d2lreg
 021B BD0000            jsr __long2fp
 021E BD0000            jsr __pshfp2 ; spill
 0221 BD0000            jsr __fpmov
 0224 18CE02D2          ldy #L28
 0228 BD0000            jsr __tofp1
 022B BD0000            jsr __fpmul
 022E FC0000            ldd _T_counts
 0231 8400              anda #0
 0233 C401              andb #1
 0235 BD0000            jsr __d2lreg
 0238 BD0000            jsr __pshfp1 ; spill
 023B BD0000            jsr __long2fp
 023E BD0000            jsr __fpmov
 0241 BD0000            jsr __pulfp1 ; reload
 0244 BD0000            jsr __fpadd
 0247 BD0000            jsr __pulfp2 ; reload
 024A BD0000            jsr __fpmul
 024D 18CE02CE          ldy #L29
 0251 BD0000            jsr __tofp2
 0254 BD0000            jsr __fpdiv
 0257 EC00              ldd 0,x
 0259 C30002            addd #2
 025C 188F              xgdy
 025E BD0000            jsr __fromfp1
 0261 EC00              ldd 0,x
 0263 C30002            addd #2
 0266 188F              xgdy
 0268 BD0000            jsr __tofp1
 026B 18CE02CA          ldy #L30
 026F BD0000            jsr __tofp2
 0272 BD0000            jsr __fpcmp
 0275 2D1E              blt L33
 0277 EC00              ldd 0,x
 0279 C30002            addd #2
 027C 188F              xgdy
 027E BD0000            jsr __tofp1
 0281 18CE02CA          ldy #L30
 0285 BD0000            jsr __tofp2
 0288 BD0000            jsr __fpsub
 028B BD0000            jsr __fp2int
 028E C38000            addd #0x8000
 0291 ED06              std 6,x
 0293 200F              bra L34
 0295           L33:
 0295 EC00              ldd 0,x
 0297 C30002            addd #2
 029A 188F              xgdy
 029C BD0000            jsr __tofp1
 029F BD0000            jsr __fp2int
 02A2 ED06              std 6,x
 02A4           L34:
 02A4 EC06              ldd 6,x
 02A6 FD0002            std _OC3hi
 02A9           ;       OC3lo=T_counts - OC3hi;
 02A9 FC0000            ldd _T_counts
 02AC B30002            subd _OC3hi
 02AF FD0000            std _OC3lo
 02B2           ; }     
 02B2           L31:
 02B2 8F                xgdx
 02B3 C30008            addd #8
 02B6 8F                xgdx
 02B7 35                txs
 02B8 38                pulx
 02B9                   .dbline 0 ; func end
 02B9 39                rts
 02BA           _RTIINTR::
 02BA           ; 
 02BA           ; void RTIINTR (void)
 02BA           ; {
 02BA           ;   TFLG2 = 0x40;
 02BA C640              ldab #64
 02BC F71025            stab 0x1025
 02BF           ;   
 02BF           ;   cntflag ++;
 02BF FC0008            ldd _cntflag
 02C2 C30001            addd #1
 02C5 FD0008            std _cntflag
 02C8           ;   
 02C8           ;   asm("         rti");
 02C8 3B                                  rti
 02C9           
 02C9           ; }
 02C9           L35:
 02C9                   .dbline 0 ; func end
 02C9 39                rts
                        .area bss
 0000           _OC3lo::
 0000                   .blkb 2
 0002           _OC3hi::
 0002                   .blkb 2
 0004           _OC2lo::
 0004                   .blkb 2
 0006           _OC2hi::
 0006                   .blkb 2
                        .area text
 02CA           L30:
 02CA 47000000          .word 0x4700,0x0
 02CE           L29:
 02CE 42C80000          .word 0x42c8,0x0
 02D2           L28:
 02D2 40000000          .word 0x4000,0x0
 02D6           L14:
 02D6 25640A00          .byte 37,'d,10,0
 02DA           L4:
 02DA 00000000          .word 0x0,0x0
