                        .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 0032              .word 50
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 0032              .word 50
                        .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
                ;  lreg1 -> -4,x
                ;  lreg2 -> -8,x
                ;  IX -> 0,x
                ;        cnttime -> +2,x
                ;              x -> +4,x
 0000           _main::
 0000 BD0000            jsr __enterb
 0003 88                .byte 0x88
 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=50, per_on3=50, 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 18CE02FB          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 $d9");
 0025 97D9                              staa $d9
 0027           
 0027           ;       asm("   ldd #_rtoc2");
 0027 CC00C1                            ldd #_rtoc2
 002A           
 002A           ;       asm("   std $dd");
 002A DDDD                              std $dd
 002C           
 002C           ;       asm("   ldd #_rtoc3");
 002C CC00F7                            ldd #_rtoc3
 002F           
 002F           ;       asm("   std $da");
 002F DDDA                              std $da
 0031           
 0031 2069              bra L6
 0033           L5:
 0033           ; 	
 0033           ; 	
 0033           ; 	/*initoc();
 0033           ; 	
 0033           ; 	
 0033           ; 	
 0033           ; 	cnts2();
 0033           ; 	cnts3();*/
 0033           ; 	
 0033           ; 	
 0033           ; 	while(1)
 0033           ; 	{	 
 0033           ; 		 ADCTL=0x01;
 0033 C601              ldab #1
 0035 F71030            stab 0x1030
 0038           L8:
 0038           L9:
 0038           ; 		 while((ADCTL & 0x80) != 0x80);
 0038           	; vol
 0038 F61030            ldab 0x1030
 003B C480              andb #128
 003D C180              cmpb #128
 003F 26F7              bne L8
 0041           ;                printf ( "%d\n" , ADR1);
 0041                   ; vol
 0041 F61031            ldab 0x1031
 0044 4F                clra
 0045 37                pshb
 0046 36                psha
 0047 CC02F7            ldd #L11
 004A BD0000            jsr _printf
 004D 1838              puly
 004F           ;                
 004F           ;                x = (ADR1 - (ADR1*.2));
 004F                   ; vol
 004F F61031            ldab 0x1031
 0052 4F                clra
 0053 BD0000            jsr __d2lreg
 0056 BD0000            jsr __long2fp
 0059 BD0000            jsr __fpmov
 005C 18CE02F3          ldy #L12
 0060 BD0000            jsr __tofp1
 0063 BD0000            jsr __fpmul
 0066 BD0000            jsr __fpmov
 0069                   ; vol
 0069 F61031            ldab 0x1031
 006C 4F                clra
 006D BD0000            jsr __d2lreg
 0070 BD0000            jsr __long2fp
 0073 BD0000            jsr __fpsub
 0076 EC00              ldd 0,x
 0078 C30004            addd #4
 007B 188F              xgdy
 007D BD0000            jsr __fromfp1
 0080           ;               
 0080           ;                 if (ADR1 < 170 && ADR1 > 100){
 0080                   ; vol
 0080 F61031            ldab 0x1031
 0083 C1AA              cmpb #170
 0085 2415              bhs L13
 0087                   ; vol
 0087 F61031            ldab 0x1031
 008A C164              cmpb #100
 008C 230E              bls L13
 008E           ;                       initoc();
 008E BD00A6            jsr _initoc
 0091           ;                       motcont = 0x03;
 0091 C603              ldab #3
 0093 F7B590            stab 0xb590
 0096           ;                       cnts2();
 0096 BD012D            jsr _cnts2
 0099           ;                       cnts3();
 0099 BD020A            jsr _cnts3
 009C           ;                       
 009C           ;             }
 009C           L13:
 009C           L6:
 009C 2095              bra L5
 009E           X0:
 009E           ; 
 009E           ; 		
 009E           ;      }
 009E           ; 	
 009E           ; }
 009E           L3:
 009E 8F                xgdx
 009F C30008            addd #8
 00A2 8F                xgdx
 00A3 35                txs
 00A4 38                pulx
 00A5                   .dbline 0 ; func end
 00A5 39                rts
 00A6           _initoc::
 00A6           ; 
 00A6           ; void initoc(void)
 00A6           ; /* Initialize OC2 */
 00A6           ; {
 00A6           ; 	TOC2 = TCNT;
 00A6           	; vol
 00A6 FC100E            ldd 0x100e
 00A9 FD1018            std 0x1018
 00AC           ;       TOC3 = TCNT;
 00AC                   ; vol
 00AC FC100E            ldd 0x100e
 00AF FD101A            std 0x101a
 00B2           ;       TCTL1 = 0x00;
 00B2 7F1020            clr 0x1020
 00B5           ;       TFLG1 = 0x60;
 00B5 C660              ldab #96
 00B7 F71023            stab 0x1023
 00BA           ;       TMSK1 = 0x60;
 00BA C660              ldab #96
 00BC F71022            stab 0x1022
 00BF           ;       INTR_ON();
 00BF 0E                                cli
 00C0           
 00C0           ; }
 00C0           L15:
 00C0                   .dbline 0 ; func end
 00C0 39                rts
 00C1           _rtoc2::
 00C1           ; 
 00C1           ; void rtoc2(void)
 00C1           ; /* Interrupt Service Routine for OC2 PWM */
 00C1           ; {  
 00C1           ; 	if ((PORTA & 0X40) == 0){ 
 00C1 18CE1000          ldy #0x1000
 00C5 181F004002        brclr 0,y,#64,X1
 00CA 2013              bra L17
 00CC           X1:
 00CC           ; 		TOC2 = TOC2 + OC2lo;
 00CC           	; vol
 00CC FC1018            ldd 0x1018
 00CF F30004            addd _OC2lo
 00D2 FD1018            std 0x1018
 00D5           ;               PORTA = PORTA | 0x40;
 00D5 18CE1000          ldy #0x1000
 00D9 181C0040          bset 0,y,#64
 00DD           ;               }
 00DD 2009              bra L18
 00DF           L17:
 00DF           ; 	else
 00DF           ; 		TOC2 = TOC2 + OC2hi;
 00DF           	; vol
 00DF FC1018            ldd 0x1018
 00E2 F30006            addd _OC2hi
 00E5 FD1018            std 0x1018
 00E8           L18:
 00E8           ; 		PORTA = PORTA |  0xBF;
 00E8 18CE1000          ldy #0x1000
 00EC 181C00BF          bset 0,y,#191
 00F0           ;       //TCTL1 = TCTL1 ^ 0x40; /* invert OL2 to toggle next OC2 edge */
 00F0           ;       TFLG1 = 0x40;   /* Clear flag OC2F */
 00F0 C640              ldab #64
 00F2 F71023            stab 0x1023
 00F5           ;       asm("   rti");  /* This is an interrupt service routine */
 00F5 3B                                rti
 00F6           
 00F6           ; }
 00F6           L16:
 00F6                   .dbline 0 ; func end
 00F6 39                rts
 00F7           _rtoc3::
 00F7           ; 
 00F7           ; void rtoc3(void)
 00F7           ; {	
 00F7           ; 	if ((PORTA & 0X20) == 0) {
 00F7 18CE1000          ldy #0x1000
 00FB 181F002002        brclr 0,y,#32,X2
 0100 2013              bra L20
 0102           X2:
 0102           ; 		TOC3 = TOC3 + OC3lo;
 0102           	; vol
 0102 FC101A            ldd 0x101a
 0105 F30000            addd _OC3lo
 0108 FD101A            std 0x101a
 010B           ;               PORTA = PORTA | 0x20;
 010B 18CE1000          ldy #0x1000
 010F 181C0020          bset 0,y,#32
 0113           ;       }       
 0113 2009              bra L21
 0115           L20:
 0115           ; 	else
 0115           ; 		TOC3 = TOC3 + OC3hi;
 0115           	; vol
 0115 FC101A            ldd 0x101a
 0118 F30002            addd _OC3hi
 011B FD101A            std 0x101a
 011E           L21:
 011E           ; 		PORTA = PORTA | 0xDF;
 011E 18CE1000          ldy #0x1000
 0122 181C00DF          bset 0,y,#223
 0126           ;       //TCTL1 = TCTL1 ^ 0x10; /* invert OL2 to toggle next OC2 edge */
 0126           ;       TFLG1 = 0x20;   /* Clear flag OC2F */
 0126 C620              ldab #32
 0128 F71023            stab 0x1023
 012B           ;       asm("   rti");  /* This is an interrupt service routine */
 012B 3B                                rti
 012C           
 012C           ; }
 012C           L19:
 012C                   .dbline 0 ; func end
 012C 39                rts
 012D           ;  lreg1 -> -4,x
 012D           ;  lreg2 -> -8,x
 012D           ;  IX -> 0,x
 012D           ;          ?temp -> +2,x
 012D           ;          ?temp -> +6,x
 012D           _cnts2::
 012D BD0000            jsr __enterb
 0130 88                .byte 0x88
 0131           ; void cnts2 (void)
 0131           ; {
 0131           ;       OC2hi=T_counts * (float)per_on2/100;
 0131 FC0002            ldd _per_on2
 0134 04                lsrd
 0135 BD0000            jsr __d2lreg
 0138 BD0000            jsr __long2fp
 013B BD0000            jsr __fpmov
 013E 18CE02EF          ldy #L26
 0142 BD0000            jsr __tofp1
 0145 BD0000            jsr __fpmul
 0148 FC0002            ldd _per_on2
 014B 8400              anda #0
 014D C401              andb #1
 014F BD0000            jsr __d2lreg
 0152 BD0000            jsr __pshfp1 ; spill
 0155 BD0000            jsr __long2fp
 0158 BD0000            jsr __fpmov
 015B BD0000            jsr __pulfp1 ; reload
 015E BD0000            jsr __fpadd
 0161 BD0000            jsr __fpmov
 0164 FC0000            ldd _T_counts
 0167 04                lsrd
 0168 BD0000            jsr __d2lreg
 016B BD0000            jsr __long2fp
 016E BD0000            jsr __pshfp2 ; spill
 0171 BD0000            jsr __fpmov
 0174 18CE02EF          ldy #L26
 0178 BD0000            jsr __tofp1
 017B BD0000            jsr __fpmul
 017E FC0000            ldd _T_counts
 0181 8400              anda #0
 0183 C401              andb #1
 0185 BD0000            jsr __d2lreg
 0188 BD0000            jsr __pshfp1 ; spill
 018B BD0000            jsr __long2fp
 018E BD0000            jsr __fpmov
 0191 BD0000            jsr __pulfp1 ; reload
 0194 BD0000            jsr __fpadd
 0197 BD0000            jsr __pulfp2 ; reload
 019A BD0000            jsr __fpmul
 019D 18CE02EB          ldy #L27
 01A1 BD0000            jsr __tofp2
 01A4 BD0000            jsr __fpdiv
 01A7 EC00              ldd 0,x
 01A9 C30002            addd #2
 01AC 188F              xgdy
 01AE BD0000            jsr __fromfp1
 01B1 EC00              ldd 0,x
 01B3 C30002            addd #2
 01B6 188F              xgdy
 01B8 BD0000            jsr __tofp1
 01BB 18CE02E7          ldy #L28
 01BF BD0000            jsr __tofp2
 01C2 BD0000            jsr __fpcmp
 01C5 2D1E              blt L24
 01C7 EC00              ldd 0,x
 01C9 C30002            addd #2
 01CC 188F              xgdy
 01CE BD0000            jsr __tofp1
 01D1 18CE02E7          ldy #L28
 01D5 BD0000            jsr __tofp2
 01D8 BD0000            jsr __fpsub
 01DB BD0000            jsr __fp2int
 01DE C38000            addd #0x8000
 01E1 ED06              std 6,x
 01E3 200F              bra L25
 01E5           L24:
 01E5 EC00              ldd 0,x
 01E7 C30002            addd #2
 01EA 188F              xgdy
 01EC BD0000            jsr __tofp1
 01EF BD0000            jsr __fp2int
 01F2 ED06              std 6,x
 01F4           L25:
 01F4 EC06              ldd 6,x
 01F6 FD0006            std _OC2hi
 01F9           ;       OC2lo=T_counts - OC2hi;
 01F9 FC0000            ldd _T_counts
 01FC B30006            subd _OC2hi
 01FF FD0004            std _OC2lo
 0202           ; }
 0202           L22:
 0202 8F                xgdx
 0203 C30008            addd #8
 0206 8F                xgdx
 0207 35                txs
 0208 38                pulx
 0209                   .dbline 0 ; func end
 0209 39                rts
 020A           ;  lreg1 -> -4,x
 020A           ;  lreg2 -> -8,x
 020A           ;  IX -> 0,x
 020A           ;          ?temp -> +2,x
 020A           ;          ?temp -> +6,x
 020A           _cnts3::
 020A BD0000            jsr __enterb
 020D 88                .byte 0x88
 020E           ; 
 020E           ; void cnts3 (void)
 020E           ; {
 020E           ;       OC3hi=T_counts * (float)per_on3/100;
 020E FC0004            ldd _per_on3
 0211 04                lsrd
 0212 BD0000            jsr __d2lreg
 0215 BD0000            jsr __long2fp
 0218 BD0000            jsr __fpmov
 021B 18CE02EF          ldy #L26
 021F BD0000            jsr __tofp1
 0222 BD0000            jsr __fpmul
 0225 FC0004            ldd _per_on3
 0228 8400              anda #0
 022A C401              andb #1
 022C BD0000            jsr __d2lreg
 022F BD0000            jsr __pshfp1 ; spill
 0232 BD0000            jsr __long2fp
 0235 BD0000            jsr __fpmov
 0238 BD0000            jsr __pulfp1 ; reload
 023B BD0000            jsr __fpadd
 023E BD0000            jsr __fpmov
 0241 FC0000            ldd _T_counts
 0244 04                lsrd
 0245 BD0000            jsr __d2lreg
 0248 BD0000            jsr __long2fp
 024B BD0000            jsr __pshfp2 ; spill
 024E BD0000            jsr __fpmov
 0251 18CE02EF          ldy #L26
 0255 BD0000            jsr __tofp1
 0258 BD0000            jsr __fpmul
 025B FC0000            ldd _T_counts
 025E 8400              anda #0
 0260 C401              andb #1
 0262 BD0000            jsr __d2lreg
 0265 BD0000            jsr __pshfp1 ; spill
 0268 BD0000            jsr __long2fp
 026B BD0000            jsr __fpmov
 026E BD0000            jsr __pulfp1 ; reload
 0271 BD0000            jsr __fpadd
 0274 BD0000            jsr __pulfp2 ; reload
 0277 BD0000            jsr __fpmul
 027A 18CE02EB          ldy #L27
 027E BD0000            jsr __tofp2
 0281 BD0000            jsr __fpdiv
 0284 EC00              ldd 0,x
 0286 C30002            addd #2
 0289 188F              xgdy
 028B BD0000            jsr __fromfp1
 028E EC00              ldd 0,x
 0290 C30002            addd #2
 0293 188F              xgdy
 0295 BD0000            jsr __tofp1
 0298 18CE02E7          ldy #L28
 029C BD0000            jsr __tofp2
 029F BD0000            jsr __fpcmp
 02A2 2D1E              blt L31
 02A4 EC00              ldd 0,x
 02A6 C30002            addd #2
 02A9 188F              xgdy
 02AB BD0000            jsr __tofp1
 02AE 18CE02E7          ldy #L28
 02B2 BD0000            jsr __tofp2
 02B5 BD0000            jsr __fpsub
 02B8 BD0000            jsr __fp2int
 02BB C38000            addd #0x8000
 02BE ED06              std 6,x
 02C0 200F              bra L32
 02C2           L31:
 02C2 EC00              ldd 0,x
 02C4 C30002            addd #2
 02C7 188F              xgdy
 02C9 BD0000            jsr __tofp1
 02CC BD0000            jsr __fp2int
 02CF ED06              std 6,x
 02D1           L32:
 02D1 EC06              ldd 6,x
 02D3 FD0002            std _OC3hi
 02D6           ;       OC3lo=T_counts - OC3hi;
 02D6 FC0000            ldd _T_counts
 02D9 B30002            subd _OC3hi
 02DC FD0000            std _OC3lo
 02DF           ; }     
 02DF           L29:
 02DF 8F                xgdx
 02E0 C30008            addd #8
 02E3 8F                xgdx
 02E4 35                txs
 02E5 38                pulx
 02E6                   .dbline 0 ; func end
 02E6 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
 02E7           L28:
 02E7 47000000          .word 0x4700,0x0
 02EB           L27:
 02EB 42C80000          .word 0x42c8,0x0
 02EF           L26:
 02EF 40000000          .word 0x4000,0x0
 02F3           L12:
 02F3 3E4CCCCD          .word 0x3e4c,0xcccd
 02F7           L11:
 02F7 25640A00          .byte 37,'d,10,0
 02FB           L4:
 02FB 00000000          .word 0x0,0x0
