                        .module ramptest.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 000A              .word 10
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 000A              .word 10
                        .area data
 0006           _cntflag::
 0006                   .blkb 2
                        .area idata
 0006 0000              .word 0
                        .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=10, per_on3=10, 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 CC00BA                            ldd #_rtoc2
 0010           
 0010           ;       asm("   std $dd");
 0010 DDDD                              std $dd
 0012           
 0012           ;       asm("   ldd #_rtoc3");
 0012 CC00F0                            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 FD0006            std _OC2hi
 001D           ;       OC2lo = 0x3e8;
 001D CC03E8            ldd #1000
 0020 FD0004            std _OC2lo
 0023           ;       OC3hi = 0x3e8;
 0023 CC03E8            ldd #1000
 0026 FD0002            std _OC3hi
 0029           ;       OC3lo = 0x3e8;
 0029 CC03E8            ldd #1000
 002C FD0000            std _OC3lo
 002F           ;       /*TMSK2=0x40;
 002F           ;       PACTL=PACTL&0xFC;
 002F           ;       PACTL=PACTL|0x00;*/
 002F           ;       
 002F           ;       initoc();
 002F BD009F            jsr _initoc
 0032           ;       cnts2();
 0032 BD0126            jsr _cnts2
 0035           ;     cnts3();
 0035 BD0203            jsr _cnts3
 0038           ;       motcont = 0x03;
 0038 C603              ldab #3
 003A F7B590            stab 0xb590
 003D 205D              bra L5
 003F           L4:
 003F           ; 	while(1)
 003F           ; 	{	
 003F           ; 		
 003F           ; 	if ((TFLG2 & 0x80) == 0x80){
 003F           	; vol
 003F F61025            ldab 0x1025
 0042 C480              andb #128
 0044 C180              cmpb #128
 0046 2654              bne L7
 0048           ;                TFLG2 = 0x80; 
 0048 C680              ldab #128
 004A F71025            stab 0x1025
 004D           ;                printf("%d    %d     %d\n", per_on2, per_on3,OC2hi);
 004D FC0006            ldd _OC2hi
 0050 37                pshb
 0051 36                psha
 0052 FC0004            ldd _per_on3
 0055 37                pshb
 0056 36                psha
 0057 FC0002            ldd _per_on2
 005A 37                pshb
 005B 36                psha
 005C CC02EC            ldd #L9
 005F BD0000            jsr _printf
 0062 BD0000            jsr __movspb
 0065 06                .byte 6
 0066           ;                per_on2 += 1;
 0066 FC0002            ldd _per_on2
 0069 C30001            addd #1
 006C FD0002            std _per_on2
 006F           ;                per_on3 += 1;
 006F FC0004            ldd _per_on3
 0072 C30001            addd #1
 0075 FD0004            std _per_on3
 0078           ;                
 0078           ;                if (per_on2>90)
 0078 FC0002            ldd _per_on2
 007B 1A83005A          cpd #90
 007F 2306              bls L10
 0081           ;                       per_on2 = 90;
 0081 CC005A            ldd #90
 0084 FD0002            std _per_on2
 0087           L10:
 0087           ; 		 if (per_on3>90)
 0087 FC0004            ldd _per_on3
 008A 1A83005A          cpd #90
 008E 2306              bls L12
 0090           ;                       per_on3 = 90;
 0090 CC005A            ldd #90
 0093 FD0004            std _per_on3
 0096           L12:
 0096           ; 			
 0096           ; 		 cnts2();
 0096 BD0126            jsr _cnts2
 0099           ;                cnts3();
 0099 BD0203            jsr _cnts3
 009C           ;       }        
 009C           L7:
 009C           L5:
 009C 20A1              bra L4
 009E           X0:
 009E           ;     }
 009E           ; 
 009E           ; 	
 009E           ; }
 009E           L3:
 009E                   .dbline 0 ; func end
 009E 39                rts
 009F           _initoc::
 009F           ; 
 009F           ; void initoc(void)
 009F           ; /* Initialize OC2 */
 009F           ; {
 009F           ; 	TOC2 = TCNT;
 009F           	; vol
 009F FC100E            ldd 0x100e
 00A2 FD1018            std 0x1018
 00A5           ;       TOC3 = TCNT;
 00A5                   ; vol
 00A5 FC100E            ldd 0x100e
 00A8 FD101A            std 0x101a
 00AB           ;       TCTL1 = 0x00;
 00AB 7F1020            clr 0x1020
 00AE           ;       TFLG1 = 0x60;
 00AE C660              ldab #96
 00B0 F71023            stab 0x1023
 00B3           ;       TMSK1 = 0x60;
 00B3 C660              ldab #96
 00B5 F71022            stab 0x1022
 00B8           ;       INTR_ON();
 00B8 0E                                cli
 00B9           
 00B9           ; }
 00B9           L14:
 00B9                   .dbline 0 ; func end
 00B9 39                rts
 00BA           _rtoc2::
 00BA           ; 
 00BA           ; void rtoc2(void)
 00BA           ; /* Interrupt Service Routine for OC2 PWM */
 00BA           ; {   
 00BA           ; 	if ((PORTA & 0X40) == 0x00){ 
 00BA 18CE1000          ldy #0x1000
 00BE 181F004002        brclr 0,y,#64,X1
 00C3 2013              bra L16
 00C5           X1:
 00C5           ; 		TOC2 = TOC2 + OC2hi;
 00C5           	; vol
 00C5 FC1018            ldd 0x1018
 00C8 F30006            addd _OC2hi
 00CB FD1018            std 0x1018
 00CE           ;               PORTA = PORTA | 0x40;
 00CE 18CE1000          ldy #0x1000
 00D2 181C0040          bset 0,y,#64
 00D6           ;               }
 00D6 2011              bra L17
 00D8           L16:
 00D8           ; 	else{
 00D8           ; 		TOC2 = TOC2 + OC2lo;
 00D8           	; vol
 00D8 FC1018            ldd 0x1018
 00DB F30004            addd _OC2lo
 00DE FD1018            std 0x1018
 00E1           ;               PORTA = PORTA & 0xBF;
 00E1 18CE1000          ldy #0x1000
 00E5 181D0040          bclr 0,y,#0x40
 00E9           ;               }
 00E9           L17:
 00E9           ; 	//TCTL1 = TCTL1 ^ 0x40;	/* invert OL2 to toggle next OC2 edge */
 00E9           ; 	TFLG1 = 0x40;	/* Clear flag OC2F */
 00E9 C640              ldab #64
 00EB F71023            stab 0x1023
 00EE           ;       asm("   rti");  /* This is an interrupt service routine */
 00EE 3B                                rti
 00EF           
 00EF           ; }
 00EF           L15:
 00EF                   .dbline 0 ; func end
 00EF 39                rts
 00F0           _rtoc3::
 00F0           ; 
 00F0           ; void rtoc3(void)
 00F0           ; {	
 00F0           ; 	if ((PORTA & 0X20) == 0x00) {
 00F0 18CE1000          ldy #0x1000
 00F4 181F002002        brclr 0,y,#32,X2
 00F9 2013              bra L19
 00FB           X2:
 00FB           ; 		TOC3 = TOC3 + OC3hi;
 00FB           	; vol
 00FB FC101A            ldd 0x101a
 00FE F30002            addd _OC3hi
 0101 FD101A            std 0x101a
 0104           ;               PORTA = PORTA | 0x20;
 0104 18CE1000          ldy #0x1000
 0108 181C0020          bset 0,y,#32
 010C           ;       }       
 010C 2011              bra L20
 010E           L19:
 010E           ; 	else{
 010E           ; 		TOC3 = TOC3 + OC3lo;
 010E           	; vol
 010E FC101A            ldd 0x101a
 0111 F30000            addd _OC3lo
 0114 FD101A            std 0x101a
 0117           ;               PORTA = PORTA & 0xDF;
 0117 18CE1000          ldy #0x1000
 011B 181D0020          bclr 0,y,#0x20
 011F           ;       }
 011F           L20:
 011F           ; 	//TCTL1 = TCTL1 ^ 0x10;	/* invert OL2 to toggle next OC2 edge */
 011F           ; 	TFLG1 = 0x20;	/* Clear flag OC2F */
 011F C620              ldab #32
 0121 F71023            stab 0x1023
 0124           ;       asm("   rti");  /* This is an interrupt service routine */
 0124 3B                                rti
 0125           
 0125           ; }
 0125           L18:
 0125                   .dbline 0 ; func end
 0125 39                rts
 0126           ;  lreg1 -> -4,x
 0126           ;  lreg2 -> -8,x
 0126           ;  IX -> 0,x
 0126           ;          ?temp -> +2,x
 0126           ;          ?temp -> +6,x
 0126           _cnts2::
 0126 BD0000            jsr __enterb
 0129 88                .byte 0x88
 012A           ; void cnts2 (void)
 012A           ; {
 012A           ;       OC2hi=T_counts * (float)per_on2/100;
 012A FC0002            ldd _per_on2
 012D 04                lsrd
 012E BD0000            jsr __d2lreg
 0131 BD0000            jsr __long2fp
 0134 BD0000            jsr __fpmov
 0137 18CE02E8          ldy #L25
 013B BD0000            jsr __tofp1
 013E BD0000            jsr __fpmul
 0141 FC0002            ldd _per_on2
 0144 8400              anda #0
 0146 C401              andb #1
 0148 BD0000            jsr __d2lreg
 014B BD0000            jsr __pshfp1 ; spill
 014E BD0000            jsr __long2fp
 0151 BD0000            jsr __fpmov
 0154 BD0000            jsr __pulfp1 ; reload
 0157 BD0000            jsr __fpadd
 015A BD0000            jsr __fpmov
 015D FC0000            ldd _T_counts
 0160 04                lsrd
 0161 BD0000            jsr __d2lreg
 0164 BD0000            jsr __long2fp
 0167 BD0000            jsr __pshfp2 ; spill
 016A BD0000            jsr __fpmov
 016D 18CE02E8          ldy #L25
 0171 BD0000            jsr __tofp1
 0174 BD0000            jsr __fpmul
 0177 FC0000            ldd _T_counts
 017A 8400              anda #0
 017C C401              andb #1
 017E BD0000            jsr __d2lreg
 0181 BD0000            jsr __pshfp1 ; spill
 0184 BD0000            jsr __long2fp
 0187 BD0000            jsr __fpmov
 018A BD0000            jsr __pulfp1 ; reload
 018D BD0000            jsr __fpadd
 0190 BD0000            jsr __pulfp2 ; reload
 0193 BD0000            jsr __fpmul
 0196 18CE02E4          ldy #L26
 019A BD0000            jsr __tofp2
 019D BD0000            jsr __fpdiv
 01A0 EC00              ldd 0,x
 01A2 C30002            addd #2
 01A5 188F              xgdy
 01A7 BD0000            jsr __fromfp1
 01AA EC00              ldd 0,x
 01AC C30002            addd #2
 01AF 188F              xgdy
 01B1 BD0000            jsr __tofp1
 01B4 18CE02E0          ldy #L27
 01B8 BD0000            jsr __tofp2
 01BB BD0000            jsr __fpcmp
 01BE 2D1E              blt L23
 01C0 EC00              ldd 0,x
 01C2 C30002            addd #2
 01C5 188F              xgdy
 01C7 BD0000            jsr __tofp1
 01CA 18CE02E0          ldy #L27
 01CE BD0000            jsr __tofp2
 01D1 BD0000            jsr __fpsub
 01D4 BD0000            jsr __fp2int
 01D7 C38000            addd #0x8000
 01DA ED06              std 6,x
 01DC 200F              bra L24
 01DE           L23:
 01DE EC00              ldd 0,x
 01E0 C30002            addd #2
 01E3 188F              xgdy
 01E5 BD0000            jsr __tofp1
 01E8 BD0000            jsr __fp2int
 01EB ED06              std 6,x
 01ED           L24:
 01ED EC06              ldd 6,x
 01EF FD0006            std _OC2hi
 01F2           ;       OC2lo=T_counts - OC2hi;
 01F2 FC0000            ldd _T_counts
 01F5 B30006            subd _OC2hi
 01F8 FD0004            std _OC2lo
 01FB           ; }
 01FB           L21:
 01FB 8F                xgdx
 01FC C30008            addd #8
 01FF 8F                xgdx
 0200 35                txs
 0201 38                pulx
 0202                   .dbline 0 ; func end
 0202 39                rts
 0203           ;  lreg1 -> -4,x
 0203           ;  lreg2 -> -8,x
 0203           ;  IX -> 0,x
 0203           ;          ?temp -> +2,x
 0203           ;          ?temp -> +6,x
 0203           _cnts3::
 0203 BD0000            jsr __enterb
 0206 88                .byte 0x88
 0207           ; 
 0207           ; void cnts3 (void)
 0207           ; {
 0207           ;       OC3hi=T_counts * (float)per_on3/100;
 0207 FC0004            ldd _per_on3
 020A 04                lsrd
 020B BD0000            jsr __d2lreg
 020E BD0000            jsr __long2fp
 0211 BD0000            jsr __fpmov
 0214 18CE02E8          ldy #L25
 0218 BD0000            jsr __tofp1
 021B BD0000            jsr __fpmul
 021E FC0004            ldd _per_on3
 0221 8400              anda #0
 0223 C401              andb #1
 0225 BD0000            jsr __d2lreg
 0228 BD0000            jsr __pshfp1 ; spill
 022B BD0000            jsr __long2fp
 022E BD0000            jsr __fpmov
 0231 BD0000            jsr __pulfp1 ; reload
 0234 BD0000            jsr __fpadd
 0237 BD0000            jsr __fpmov
 023A FC0000            ldd _T_counts
 023D 04                lsrd
 023E BD0000            jsr __d2lreg
 0241 BD0000            jsr __long2fp
 0244 BD0000            jsr __pshfp2 ; spill
 0247 BD0000            jsr __fpmov
 024A 18CE02E8          ldy #L25
 024E BD0000            jsr __tofp1
 0251 BD0000            jsr __fpmul
 0254 FC0000            ldd _T_counts
 0257 8400              anda #0
 0259 C401              andb #1
 025B BD0000            jsr __d2lreg
 025E BD0000            jsr __pshfp1 ; spill
 0261 BD0000            jsr __long2fp
 0264 BD0000            jsr __fpmov
 0267 BD0000            jsr __pulfp1 ; reload
 026A BD0000            jsr __fpadd
 026D BD0000            jsr __pulfp2 ; reload
 0270 BD0000            jsr __fpmul
 0273 18CE02E4          ldy #L26
 0277 BD0000            jsr __tofp2
 027A BD0000            jsr __fpdiv
 027D EC00              ldd 0,x
 027F C30002            addd #2
 0282 188F              xgdy
 0284 BD0000            jsr __fromfp1
 0287 EC00              ldd 0,x
 0289 C30002            addd #2
 028C 188F              xgdy
 028E BD0000            jsr __tofp1
 0291 18CE02E0          ldy #L27
 0295 BD0000            jsr __tofp2
 0298 BD0000            jsr __fpcmp
 029B 2D1E              blt L30
 029D EC00              ldd 0,x
 029F C30002            addd #2
 02A2 188F              xgdy
 02A4 BD0000            jsr __tofp1
 02A7 18CE02E0          ldy #L27
 02AB BD0000            jsr __tofp2
 02AE BD0000            jsr __fpsub
 02B1 BD0000            jsr __fp2int
 02B4 C38000            addd #0x8000
 02B7 ED06              std 6,x
 02B9 200F              bra L31
 02BB           L30:
 02BB EC00              ldd 0,x
 02BD C30002            addd #2
 02C0 188F              xgdy
 02C2 BD0000            jsr __tofp1
 02C5 BD0000            jsr __fp2int
 02C8 ED06              std 6,x
 02CA           L31:
 02CA EC06              ldd 6,x
 02CC FD0002            std _OC3hi
 02CF           ;       OC3lo=T_counts - OC3hi;
 02CF FC0000            ldd _T_counts
 02D2 B30002            subd _OC3hi
 02D5 FD0000            std _OC3lo
 02D8           ; }     
 02D8           L28:
 02D8 8F                xgdx
 02D9 C30008            addd #8
 02DC 8F                xgdx
 02DD 35                txs
 02DE 38                pulx
 02DF                   .dbline 0 ; func end
 02DF 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
 02E0           L27:
 02E0 47000000          .word 0x4700,0x0
 02E4           L26:
 02E4 42C80000          .word 0x42c8,0x0
 02E8           L25:
 02E8 40000000          .word 0x4000,0x0
 02EC           L9:
 02EC 2564202020202564202020202025640A  .byte 37,'d,32,32,32,32,37,'d,32,32,32,32,32,37,'d,10
 02FC 00                .byte 0
