                        .module testingspeed.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 000A              .word 10
                        .area data
                        .area text
                ;  IX -> 0,x
                ;              y -> +2,x
                ;              x -> +4,x
 0000           _main::
 0000 BD0000            jsr __enterb
 0003 06                .byte 0x6
 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           ; /* Declarations */
 0004           ; unsigned int OC2hi, OC2lo, OC3hi, OC3lo;      /* Duty cycle data */
 0004           ; unsigned int T_counts=0x4e20, per_on2=50, per_on3=10;
 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           ; void main(void)
 0004           ; {
 0004           ;       int x=0,y=0;
 0004 CC0000            ldd #0
 0007 ED04              std 4,x
 0009 CC0000            ldd #0
 000C ED02              std 2,x
 000E           ;       
 000E           ;       setbaud(BAUD9600);
 000E CC0030            ldd #48
 0011 BD0000            jsr _setbaud
 0014           ;       INTR_OFF();
 0014 0F                                sei
 0015           
 0015           ;       /* set up jump vector for buffalo */
 0015           ;       asm("   ldaa #$7e");
 0015 867E                              ldaa #$7e
 0017           
 0017           ;       asm("   staa $dc");
 0017 97DC                              staa $dc
 0019           
 0019           ;       asm("   ldd #_rtoc2");
 0019 CC008E                            ldd #_rtoc2
 001C           
 001C           ;       asm("   std $dd");
 001C DDDD                              std $dd
 001E           
 001E           ;       asm("   ldaa #$7e");
 001E 867E                              ldaa #$7e
 0020           
 0020           ;       asm("   staa $d9");
 0020 97D9                              staa $d9
 0022           
 0022           ;       asm("   ldd #_rtoc3");
 0022 CC00C4                            ldd #_rtoc3
 0025           
 0025           ;       asm("   std $da");
 0025 DDDA                              std $da
 0027           
 0027           ;       OC2hi = 0x3e8;
 0027 CC03E8            ldd #1000
 002A FD0006            std _OC2hi
 002D           ;       OC2lo = 0x3e8;
 002D CC03E8            ldd #1000
 0030 FD0004            std _OC2lo
 0033           ;       OC3hi = 0x3e8;
 0033 CC03E8            ldd #1000
 0036 FD0002            std _OC3hi
 0039           ;       OC3lo = 0x3e8;
 0039 CC03E8            ldd #1000
 003C FD0000            std _OC3lo
 003F           ;       initoc();
 003F BD0073            jsr _initoc
 0042           ;       motcont = 0x03;
 0042 C603              ldab #3
 0044 F7B590            stab 0xb590
 0047           ;       cnts2();
 0047 BD00FA            jsr _cnts2
 004A 201D              bra L5
 004C           L4:
 004C CC0004            ldd #_per_on3
 004F 37                pshb
 0050 36                psha
 0051 CC02C4            ldd #L7
 0054 BD0000            jsr _scanf
 0057 1838              puly
 0059 BD01D7            jsr _cnts3
 005C FC0004            ldd _per_on3
 005F 37                pshb
 0060 36                psha
 0061 CC02C0            ldd #L8
 0064 BD0000            jsr _printf
 0067 1838              puly
 0069           L5:
 0069           ; 	while(1)
 0069 20E1              bra L4
 006B           X0:
 006B           ; 		{
 006B           ; 		 scanf("%d", &per_on3);
 006B           ; 		 cnts3();
 006B           ; 		 printf("%d\n", per_on3);
 006B           ;         }	 
 006B           ; }		 
 006B           L3:
 006B 8F                xgdx
 006C C30006            addd #6
 006F 8F                xgdx
 0070 35                txs
 0071 38                pulx
 0072                   .dbline 0 ; func end
 0072 39                rts
 0073           _initoc::
 0073           ; void initoc(void)
 0073           ; /* Initialize OC2 */
 0073           ; {
 0073           ; 	TOC2 = TCNT;
 0073           	; vol
 0073 FC100E            ldd 0x100e
 0076 FD1018            std 0x1018
 0079           ;       TOC3 = TCNT;
 0079                   ; vol
 0079 FC100E            ldd 0x100e
 007C FD101A            std 0x101a
 007F           ;       TCTL1 = 0x00;
 007F 7F1020            clr 0x1020
 0082           ;       TFLG1 = 0x60;
 0082 C660              ldab #96
 0084 F71023            stab 0x1023
 0087           ;       TMSK1 = 0x60;
 0087 C660              ldab #96
 0089 F71022            stab 0x1022
 008C           ;       INTR_ON();
 008C 0E                                cli
 008D           
 008D           ; }
 008D           L9:
 008D                   .dbline 0 ; func end
 008D 39                rts
 008E           _rtoc2::
 008E           ; 
 008E           ; void rtoc2(void)
 008E           ; /* Interrupt Service Routine for OC2 PWM */
 008E           ; {  
 008E           ; 	if ((PORTA & 0X40) == 0){ 
 008E 18CE1000          ldy #0x1000
 0092 181F004002        brclr 0,y,#64,X1
 0097 2013              bra L11
 0099           X1:
 0099           ; 		TOC2 = TOC2 + OC2hi;
 0099           	; vol
 0099 FC1018            ldd 0x1018
 009C F30006            addd _OC2hi
 009F FD1018            std 0x1018
 00A2           ;               PORTA = PORTA | 0x40;
 00A2 18CE1000          ldy #0x1000
 00A6 181C0040          bset 0,y,#64
 00AA           ;       }
 00AA 2011              bra L12
 00AC           L11:
 00AC           ; 	else {
 00AC           ; 		TOC2 = TOC2 + OC2lo;
 00AC           	; vol
 00AC FC1018            ldd 0x1018
 00AF F30004            addd _OC2lo
 00B2 FD1018            std 0x1018
 00B5           ;               PORTA = PORTA &  0xBF;
 00B5 18CE1000          ldy #0x1000
 00B9 181D0040          bclr 0,y,#0x40
 00BD           ;       }
 00BD           L12:
 00BD           ; 	//TCTL1 = TCTL1 ^ 0x40;	/* invert OL2 to toggle next OC2 edge */
 00BD           ; 	 
 00BD           ; 	TFLG1 = 0x40;	/* Clear flag OC2F */
 00BD C640              ldab #64
 00BF F71023            stab 0x1023
 00C2           ;       asm("   rti");  /* This is an interrupt service routine */
 00C2 3B                                rti
 00C3           
 00C3           ; }
 00C3           L10:
 00C3                   .dbline 0 ; func end
 00C3 39                rts
 00C4           _rtoc3::
 00C4           ; 
 00C4           ; void rtoc3(void)
 00C4           ; {	
 00C4           ; 	if ((PORTA & 0X20) == 0) {
 00C4 18CE1000          ldy #0x1000
 00C8 181F002002        brclr 0,y,#32,X2
 00CD 2013              bra L14
 00CF           X2:
 00CF           ; 		TOC3 = TOC3 + OC3hi;
 00CF           	; vol
 00CF FC101A            ldd 0x101a
 00D2 F30002            addd _OC3hi
 00D5 FD101A            std 0x101a
 00D8           ;               PORTA = PORTA | 0x20;
 00D8 18CE1000          ldy #0x1000
 00DC 181C0020          bset 0,y,#32
 00E0           ;       }
 00E0 2011              bra L15
 00E2           L14:
 00E2           ; 	else {
 00E2           ; 		TOC3 = TOC3 + OC3lo;
 00E2           	; vol
 00E2 FC101A            ldd 0x101a
 00E5 F30000            addd _OC3lo
 00E8 FD101A            std 0x101a
 00EB           ;               PORTA = PORTA & 0xDF;
 00EB 18CE1000          ldy #0x1000
 00EF 181D0020          bclr 0,y,#0x20
 00F3           ;       }
 00F3           L15:
 00F3           ; 	//TCTL1 = TCTL1 ^ 0x10;	/* invert OL2 to toggle next OC2 edge */
 00F3           ; 	TFLG1 = 0x20;	/* Clear flag OC2F */
 00F3 C620              ldab #32
 00F5 F71023            stab 0x1023
 00F8           ;       asm("   rti");  /* This is an interrupt service routine */
 00F8 3B                                rti
 00F9           
 00F9           ; }
 00F9           L13:
 00F9                   .dbline 0 ; func end
 00F9 39                rts
 00FA           ;  lreg1 -> -4,x
 00FA           ;  lreg2 -> -8,x
 00FA           ;  IX -> 0,x
 00FA           ;          ?temp -> +2,x
 00FA           ;          ?temp -> +6,x
 00FA           _cnts2::
 00FA BD0000            jsr __enterb
 00FD 88                .byte 0x88
 00FE           ; void cnts2 (void)
 00FE           ; {
 00FE           ;       OC2hi=T_counts * (float)per_on2/100;
 00FE FC0002            ldd _per_on2
 0101 04                lsrd
 0102 BD0000            jsr __d2lreg
 0105 BD0000            jsr __long2fp
 0108 BD0000            jsr __fpmov
 010B 18CE02BC          ldy #L20
 010F BD0000            jsr __tofp1
 0112 BD0000            jsr __fpmul
 0115 FC0002            ldd _per_on2
 0118 8400              anda #0
 011A C401              andb #1
 011C BD0000            jsr __d2lreg
 011F BD0000            jsr __pshfp1 ; spill
 0122 BD0000            jsr __long2fp
 0125 BD0000            jsr __fpmov
 0128 BD0000            jsr __pulfp1 ; reload
 012B BD0000            jsr __fpadd
 012E BD0000            jsr __fpmov
 0131 FC0000            ldd _T_counts
 0134 04                lsrd
 0135 BD0000            jsr __d2lreg
 0138 BD0000            jsr __long2fp
 013B BD0000            jsr __pshfp2 ; spill
 013E BD0000            jsr __fpmov
 0141 18CE02BC          ldy #L20
 0145 BD0000            jsr __tofp1
 0148 BD0000            jsr __fpmul
 014B FC0000            ldd _T_counts
 014E 8400              anda #0
 0150 C401              andb #1
 0152 BD0000            jsr __d2lreg
 0155 BD0000            jsr __pshfp1 ; spill
 0158 BD0000            jsr __long2fp
 015B BD0000            jsr __fpmov
 015E BD0000            jsr __pulfp1 ; reload
 0161 BD0000            jsr __fpadd
 0164 BD0000            jsr __pulfp2 ; reload
 0167 BD0000            jsr __fpmul
 016A 18CE02B8          ldy #L21
 016E BD0000            jsr __tofp2
 0171 BD0000            jsr __fpdiv
 0174 EC00              ldd 0,x
 0176 C30002            addd #2
 0179 188F              xgdy
 017B BD0000            jsr __fromfp1
 017E EC00              ldd 0,x
 0180 C30002            addd #2
 0183 188F              xgdy
 0185 BD0000            jsr __tofp1
 0188 18CE02B4          ldy #L22
 018C BD0000            jsr __tofp2
 018F BD0000            jsr __fpcmp
 0192 2D1E              blt L18
 0194 EC00              ldd 0,x
 0196 C30002            addd #2
 0199 188F              xgdy
 019B BD0000            jsr __tofp1
 019E 18CE02B4          ldy #L22
 01A2 BD0000            jsr __tofp2
 01A5 BD0000            jsr __fpsub
 01A8 BD0000            jsr __fp2int
 01AB C38000            addd #0x8000
 01AE ED06              std 6,x
 01B0 200F              bra L19
 01B2           L18:
 01B2 EC00              ldd 0,x
 01B4 C30002            addd #2
 01B7 188F              xgdy
 01B9 BD0000            jsr __tofp1
 01BC BD0000            jsr __fp2int
 01BF ED06              std 6,x
 01C1           L19:
 01C1 EC06              ldd 6,x
 01C3 FD0006            std _OC2hi
 01C6           ;       OC2lo=T_counts - OC2hi;
 01C6 FC0000            ldd _T_counts
 01C9 B30006            subd _OC2hi
 01CC FD0004            std _OC2lo
 01CF           ; }
 01CF           L16:
 01CF 8F                xgdx
 01D0 C30008            addd #8
 01D3 8F                xgdx
 01D4 35                txs
 01D5 38                pulx
 01D6                   .dbline 0 ; func end
 01D6 39                rts
 01D7           ;  lreg1 -> -4,x
 01D7           ;  lreg2 -> -8,x
 01D7           ;  IX -> 0,x
 01D7           ;          ?temp -> +2,x
 01D7           ;          ?temp -> +6,x
 01D7           _cnts3::
 01D7 BD0000            jsr __enterb
 01DA 88                .byte 0x88
 01DB           ; 
 01DB           ; void cnts3 (void)
 01DB           ; {
 01DB           ;       OC3hi=T_counts * (float)per_on3/100;
 01DB FC0004            ldd _per_on3
 01DE 04                lsrd
 01DF BD0000            jsr __d2lreg
 01E2 BD0000            jsr __long2fp
 01E5 BD0000            jsr __fpmov
 01E8 18CE02BC          ldy #L20
 01EC BD0000            jsr __tofp1
 01EF BD0000            jsr __fpmul
 01F2 FC0004            ldd _per_on3
 01F5 8400              anda #0
 01F7 C401              andb #1
 01F9 BD0000            jsr __d2lreg
 01FC BD0000            jsr __pshfp1 ; spill
 01FF BD0000            jsr __long2fp
 0202 BD0000            jsr __fpmov
 0205 BD0000            jsr __pulfp1 ; reload
 0208 BD0000            jsr __fpadd
 020B BD0000            jsr __fpmov
 020E FC0000            ldd _T_counts
 0211 04                lsrd
 0212 BD0000            jsr __d2lreg
 0215 BD0000            jsr __long2fp
 0218 BD0000            jsr __pshfp2 ; spill
 021B BD0000            jsr __fpmov
 021E 18CE02BC          ldy #L20
 0222 BD0000            jsr __tofp1
 0225 BD0000            jsr __fpmul
 0228 FC0000            ldd _T_counts
 022B 8400              anda #0
 022D C401              andb #1
 022F BD0000            jsr __d2lreg
 0232 BD0000            jsr __pshfp1 ; spill
 0235 BD0000            jsr __long2fp
 0238 BD0000            jsr __fpmov
 023B BD0000            jsr __pulfp1 ; reload
 023E BD0000            jsr __fpadd
 0241 BD0000            jsr __pulfp2 ; reload
 0244 BD0000            jsr __fpmul
 0247 18CE02B8          ldy #L21
 024B BD0000            jsr __tofp2
 024E BD0000            jsr __fpdiv
 0251 EC00              ldd 0,x
 0253 C30002            addd #2
 0256 188F              xgdy
 0258 BD0000            jsr __fromfp1
 025B EC00              ldd 0,x
 025D C30002            addd #2
 0260 188F              xgdy
 0262 BD0000            jsr __tofp1
 0265 18CE02B4          ldy #L22
 0269 BD0000            jsr __tofp2
 026C BD0000            jsr __fpcmp
 026F 2D1E              blt L25
 0271 EC00              ldd 0,x
 0273 C30002            addd #2
 0276 188F              xgdy
 0278 BD0000            jsr __tofp1
 027B 18CE02B4          ldy #L22
 027F BD0000            jsr __tofp2
 0282 BD0000            jsr __fpsub
 0285 BD0000            jsr __fp2int
 0288 C38000            addd #0x8000
 028B ED06              std 6,x
 028D 200F              bra L26
 028F           L25:
 028F EC00              ldd 0,x
 0291 C30002            addd #2
 0294 188F              xgdy
 0296 BD0000            jsr __tofp1
 0299 BD0000            jsr __fp2int
 029C ED06              std 6,x
 029E           L26:
 029E EC06              ldd 6,x
 02A0 FD0002            std _OC3hi
 02A3           ;       OC3lo=T_counts - OC3hi;
 02A3 FC0000            ldd _T_counts
 02A6 B30002            subd _OC3hi
 02A9 FD0000            std _OC3lo
 02AC           ; }
 02AC           L23:
 02AC 8F                xgdx
 02AD C30008            addd #8
 02B0 8F                xgdx
 02B1 35                txs
 02B2 38                pulx
 02B3                   .dbline 0 ; func end
 02B3 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
 02B4           L22:
 02B4 47000000          .word 0x4700,0x0
 02B8           L21:
 02B8 42C80000          .word 0x42c8,0x0
 02BC           L20:
 02BC 40000000          .word 0x4000,0x0
 02C0           L8:
 02C0 25640A00          .byte 37,'d,10,0
 02C4           L7:
 02C4 256400            .byte 37,'d,0
