                        .module cl11_4.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 005A              .word 90
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 005A              .word 90
                        .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=90, per_on3=90;
 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 CC00C4                            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 CC00FA                            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 BD00A9            jsr _initoc
 0042           ;       
 0042           ;       
 0042           ;               
 0042           ;                
 0042           ;                x=0;
 0042 CC0000            ldd #0
 0045 ED04              std 4,x
 0047           ;                cnts2();
 0047 BD0130            jsr _cnts2
 004A           ;                cnts3();
 004A BD020D            jsr _cnts3
 004D           ;                printf("%x   %x   %x    %x\n",OC2hi,OC2lo,OC3hi,OC3lo); 
 004D FC0000            ldd _OC3lo
 0050 37                pshb
 0051 36                psha
 0052 FC0002            ldd _OC3hi
 0055 37                pshb
 0056 36                psha
 0057 FC0004            ldd _OC2lo
 005A 37                pshb
 005B 36                psha
 005C FC0006            ldd _OC2hi
 005F 37                pshb
 0060 36                psha
 0061 CC02FF            ldd #L4
 0064 BD0000            jsr _printf
 0067 BD0000            jsr __movspb
 006A 08                .byte 8
 006B 200C              bra L6
 006D           L5:
 006D C603              ldab #3
 006F F7B590            stab 0xb590
 0072 EC04              ldd 4,x
 0074 C30001            addd #1
 0077 ED04              std 4,x
 0079           L6:
 0079           ; 	 	 
 0079           ; 		 while(x <= 40000){
 0079 EC04              ldd 4,x
 007B 1A839C40          cpd #0x9c40
 007F 23EC              bls L5
 0081 200A              bra L9
 0083           L8:
 0083 7FB590            clr 0xb590
 0086 EC02              ldd 2,x
 0088 C30001            addd #1
 008B ED02              std 2,x
 008D           L9:
 008D           ; 		 	motcont=0x03;
 008D           ; 			x++;
 008D           ; 			}
 008D           ; 		 while(y <= 40000){
 008D EC02              ldd 2,x
 008F 1A839C40          cpd #0x9c40
 0093 23EE              bls L8
 0095           ;                       motcont=0x00;
 0095           ;                       y++;
 0095           ;                       }
 0095           ;                TMSK1=0x00;
 0095 7F1022            clr 0x1022
 0098           ;                PORTA=0x00;
 0098 7F1000            clr 0x1000
 009B           ;                printf("HELP ME\n");
 009B CC02F6            ldd #L11
 009E BD0000            jsr _printf
 00A1           ;                //asm(" swi");
 00A1           ;        
 00A1           ; }              
 00A1           L3:
 00A1 8F                xgdx
 00A2 C30006            addd #6
 00A5 8F                xgdx
 00A6 35                txs
 00A7 38                pulx
 00A8                   .dbline 0 ; func end
 00A8 39                rts
 00A9           _initoc::
 00A9           ; void initoc(void)
 00A9           ; /* Initialize OC2 */
 00A9           ; {
 00A9           ; 	TOC2 = TCNT;
 00A9           	; vol
 00A9 FC100E            ldd 0x100e
 00AC FD1018            std 0x1018
 00AF           ;       TOC3 = TCNT;
 00AF                   ; vol
 00AF FC100E            ldd 0x100e
 00B2 FD101A            std 0x101a
 00B5           ;       TCTL1 = 0x00;
 00B5 7F1020            clr 0x1020
 00B8           ;       TFLG1 = 0x60;
 00B8 C660              ldab #96
 00BA F71023            stab 0x1023
 00BD           ;       TMSK1 = 0x60;
 00BD C660              ldab #96
 00BF F71022            stab 0x1022
 00C2           ;       INTR_ON();
 00C2 0E                                cli
 00C3           
 00C3           ; }
 00C3           L12:
 00C3                   .dbline 0 ; func end
 00C3 39                rts
 00C4           _rtoc2::
 00C4           ; 
 00C4           ; void rtoc2(void)
 00C4           ; /* Interrupt Service Routine for OC2 PWM */
 00C4           ; {  
 00C4           ; 	if ((PORTA & 0X40) == 0){ 
 00C4 18CE1000          ldy #0x1000
 00C8 181F004002        brclr 0,y,#64,X0
 00CD 2013              bra L14
 00CF           X0:
 00CF           ; 		TOC2 = TOC2 + OC2lo;
 00CF           	; vol
 00CF FC1018            ldd 0x1018
 00D2 F30004            addd _OC2lo
 00D5 FD1018            std 0x1018
 00D8           ;               PORTA = PORTA | 0x40;
 00D8 18CE1000          ldy #0x1000
 00DC 181C0040          bset 0,y,#64
 00E0           ;       }
 00E0 2009              bra L15
 00E2           L14:
 00E2           ; 	else 
 00E2           ; 		TOC2 = TOC2 + OC2hi;
 00E2           	; vol
 00E2 FC1018            ldd 0x1018
 00E5 F30006            addd _OC2hi
 00E8 FD1018            std 0x1018
 00EB           L15:
 00EB           ; 		PORTA = PORTA &  0xBF;
 00EB 18CE1000          ldy #0x1000
 00EF 181D0040          bclr 0,y,#0x40
 00F3           ;       
 00F3           ;       //TCTL1 = TCTL1 ^ 0x40; /* invert OL2 to toggle next OC2 edge */
 00F3           ;        
 00F3           ;       TFLG1 = 0x40;   /* Clear flag OC2F */
 00F3 C640              ldab #64
 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           _rtoc3::
 00FA           ; 
 00FA           ; void rtoc3(void)
 00FA           ; {	
 00FA           ; 	if ((PORTA & 0X20) == 0) {
 00FA 18CE1000          ldy #0x1000
 00FE 181F002002        brclr 0,y,#32,X1
 0103 2013              bra L17
 0105           X1:
 0105           ; 		TOC3 = TOC3 + OC3lo;
 0105           	; vol
 0105 FC101A            ldd 0x101a
 0108 F30000            addd _OC3lo
 010B FD101A            std 0x101a
 010E           ;               PORTA = PORTA | 0x20;
 010E 18CE1000          ldy #0x1000
 0112 181C0020          bset 0,y,#32
 0116           ;       }
 0116 2009              bra L18
 0118           L17:
 0118           ; 	else 
 0118           ; 		TOC3 = TOC3 + OC3hi;
 0118           	; vol
 0118 FC101A            ldd 0x101a
 011B F30002            addd _OC3hi
 011E FD101A            std 0x101a
 0121           L18:
 0121           ; 		PORTA = PORTA & 0xDF;
 0121 18CE1000          ldy #0x1000
 0125 181D0020          bclr 0,y,#0x20
 0129           ;       
 0129           ;       //TCTL1 = TCTL1 ^ 0x10; /* invert OL2 to toggle next OC2 edge */
 0129           ;       TFLG1 = 0x20;   /* Clear flag OC2F */
 0129 C620              ldab #32
 012B F71023            stab 0x1023
 012E           ;       asm("   rti");  /* This is an interrupt service routine */
 012E 3B                                rti
 012F           
 012F           ; }
 012F           L16:
 012F                   .dbline 0 ; func end
 012F 39                rts
 0130           ;  lreg1 -> -4,x
 0130           ;  lreg2 -> -8,x
 0130           ;  IX -> 0,x
 0130           ;          ?temp -> +2,x
 0130           ;          ?temp -> +6,x
 0130           _cnts2::
 0130 BD0000            jsr __enterb
 0133 88                .byte 0x88
 0134           ; void cnts2 (void)
 0134           ; {
 0134           ;       OC2hi=T_counts * (float)per_on2/100;
 0134 FC0002            ldd _per_on2
 0137 04                lsrd
 0138 BD0000            jsr __d2lreg
 013B BD0000            jsr __long2fp
 013E BD0000            jsr __fpmov
 0141 18CE02F2          ldy #L23
 0145 BD0000            jsr __tofp1
 0148 BD0000            jsr __fpmul
 014B FC0002            ldd _per_on2
 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 __fpmov
 0167 FC0000            ldd _T_counts
 016A 04                lsrd
 016B BD0000            jsr __d2lreg
 016E BD0000            jsr __long2fp
 0171 BD0000            jsr __pshfp2 ; spill
 0174 BD0000            jsr __fpmov
 0177 18CE02F2          ldy #L23
 017B BD0000            jsr __tofp1
 017E BD0000            jsr __fpmul
 0181 FC0000            ldd _T_counts
 0184 8400              anda #0
 0186 C401              andb #1
 0188 BD0000            jsr __d2lreg
 018B BD0000            jsr __pshfp1 ; spill
 018E BD0000            jsr __long2fp
 0191 BD0000            jsr __fpmov
 0194 BD0000            jsr __pulfp1 ; reload
 0197 BD0000            jsr __fpadd
 019A BD0000            jsr __pulfp2 ; reload
 019D BD0000            jsr __fpmul
 01A0 18CE02EE          ldy #L24
 01A4 BD0000            jsr __tofp2
 01A7 BD0000            jsr __fpdiv
 01AA EC00              ldd 0,x
 01AC C30002            addd #2
 01AF 188F              xgdy
 01B1 BD0000            jsr __fromfp1
 01B4 EC00              ldd 0,x
 01B6 C30002            addd #2
 01B9 188F              xgdy
 01BB BD0000            jsr __tofp1
 01BE 18CE02EA          ldy #L25
 01C2 BD0000            jsr __tofp2
 01C5 BD0000            jsr __fpcmp
 01C8 2D1E              blt L21
 01CA EC00              ldd 0,x
 01CC C30002            addd #2
 01CF 188F              xgdy
 01D1 BD0000            jsr __tofp1
 01D4 18CE02EA          ldy #L25
 01D8 BD0000            jsr __tofp2
 01DB BD0000            jsr __fpsub
 01DE BD0000            jsr __fp2int
 01E1 C38000            addd #0x8000
 01E4 ED06              std 6,x
 01E6 200F              bra L22
 01E8           L21:
 01E8 EC00              ldd 0,x
 01EA C30002            addd #2
 01ED 188F              xgdy
 01EF BD0000            jsr __tofp1
 01F2 BD0000            jsr __fp2int
 01F5 ED06              std 6,x
 01F7           L22:
 01F7 EC06              ldd 6,x
 01F9 FD0006            std _OC2hi
 01FC           ;       OC2lo=T_counts - OC2hi;
 01FC FC0000            ldd _T_counts
 01FF B30006            subd _OC2hi
 0202 FD0004            std _OC2lo
 0205           ; }
 0205           L19:
 0205 8F                xgdx
 0206 C30008            addd #8
 0209 8F                xgdx
 020A 35                txs
 020B 38                pulx
 020C                   .dbline 0 ; func end
 020C 39                rts
 020D           ;  lreg1 -> -4,x
 020D           ;  lreg2 -> -8,x
 020D           ;  IX -> 0,x
 020D           ;          ?temp -> +2,x
 020D           ;          ?temp -> +6,x
 020D           _cnts3::
 020D BD0000            jsr __enterb
 0210 88                .byte 0x88
 0211           ; 
 0211           ; void cnts3 (void)
 0211           ; {
 0211           ;       OC3hi=T_counts * (float)per_on3/100;
 0211 FC0004            ldd _per_on3
 0214 04                lsrd
 0215 BD0000            jsr __d2lreg
 0218 BD0000            jsr __long2fp
 021B BD0000            jsr __fpmov
 021E 18CE02F2          ldy #L23
 0222 BD0000            jsr __tofp1
 0225 BD0000            jsr __fpmul
 0228 FC0004            ldd _per_on3
 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 __fpmov
 0244 FC0000            ldd _T_counts
 0247 04                lsrd
 0248 BD0000            jsr __d2lreg
 024B BD0000            jsr __long2fp
 024E BD0000            jsr __pshfp2 ; spill
 0251 BD0000            jsr __fpmov
 0254 18CE02F2          ldy #L23
 0258 BD0000            jsr __tofp1
 025B BD0000            jsr __fpmul
 025E FC0000            ldd _T_counts
 0261 8400              anda #0
 0263 C401              andb #1
 0265 BD0000            jsr __d2lreg
 0268 BD0000            jsr __pshfp1 ; spill
 026B BD0000            jsr __long2fp
 026E BD0000            jsr __fpmov
 0271 BD0000            jsr __pulfp1 ; reload
 0274 BD0000            jsr __fpadd
 0277 BD0000            jsr __pulfp2 ; reload
 027A BD0000            jsr __fpmul
 027D 18CE02EE          ldy #L24
 0281 BD0000            jsr __tofp2
 0284 BD0000            jsr __fpdiv
 0287 EC00              ldd 0,x
 0289 C30002            addd #2
 028C 188F              xgdy
 028E BD0000            jsr __fromfp1
 0291 EC00              ldd 0,x
 0293 C30002            addd #2
 0296 188F              xgdy
 0298 BD0000            jsr __tofp1
 029B 18CE02EA          ldy #L25
 029F BD0000            jsr __tofp2
 02A2 BD0000            jsr __fpcmp
 02A5 2D1E              blt L28
 02A7 EC00              ldd 0,x
 02A9 C30002            addd #2
 02AC 188F              xgdy
 02AE BD0000            jsr __tofp1
 02B1 18CE02EA          ldy #L25
 02B5 BD0000            jsr __tofp2
 02B8 BD0000            jsr __fpsub
 02BB BD0000            jsr __fp2int
 02BE C38000            addd #0x8000
 02C1 ED06              std 6,x
 02C3 200F              bra L29
 02C5           L28:
 02C5 EC00              ldd 0,x
 02C7 C30002            addd #2
 02CA 188F              xgdy
 02CC BD0000            jsr __tofp1
 02CF BD0000            jsr __fp2int
 02D2 ED06              std 6,x
 02D4           L29:
 02D4 EC06              ldd 6,x
 02D6 FD0002            std _OC3hi
 02D9           ;       OC3lo=T_counts - OC3hi;
 02D9 FC0000            ldd _T_counts
 02DC B30002            subd _OC3hi
 02DF FD0000            std _OC3lo
 02E2           ; }
 02E2           L26:
 02E2 8F                xgdx
 02E3 C30008            addd #8
 02E6 8F                xgdx
 02E7 35                txs
 02E8 38                pulx
 02E9                   .dbline 0 ; func end
 02E9 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
 02EA           L25:
 02EA 47000000          .word 0x4700,0x0
 02EE           L24:
 02EE 42C80000          .word 0x42c8,0x0
 02F2           L23:
 02F2 40000000          .word 0x4000,0x0
 02F6           L11:
 02F6 48454C50204D450A00        .byte 'H,'E,'L,'P,32,'M,'E,10,0
 02FF           L4:
 02FF 25782020202578202020257820202020  .byte 37,'x,32,32,32,37,'x,32,32,32,37,'x,32,32,32,32
 030F 25780A00          .byte 37,'x,10,0
