                        .module individualtest.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 0028              .word 40
                        .area data
 0004           _per_on3::
 0004                   .blkb 2
                        .area idata
 0004 0023              .word 35
                        .area data
 0006           _cntflag::
 0006                   .blkb 2
                        .area idata
 0006 0000              .word 0
                        .area data
                        .area text
                ;  IX -> 0,x
                ;          ?temp -> +2,x
                ;          waste -> +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           ; #define linetrack *(unsigned char volatile *) (0XB5A0)
 0004           ; 
 0004           ; 
 0004           ; /* Declarations */
 0004           ; unsigned int OC2hi, OC2lo, OC3hi, OC3lo;      /* Duty cycle data */
 0004           ; unsigned int T_counts=0x4e20, per_on2=40, per_on3=35, 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           ; //void RTIINTR (void);
 0004           ; 
 0004           ; 
 0004           ; void main(void)
 0004           ; {
 0004           ;       int waste=0;
 0004 CC0000            ldd #0
 0007 ED04              std 4,x
 0009           ;       
 0009           ;       setbaud(BAUD9600);
 0009 CC0030            ldd #48
 000C BD0000            jsr _setbaud
 000F           ;       INTR_OFF();
 000F 0F                                sei
 0010           
 0010           ;       /* set up jump vector for buffalo */
 0010           ;       asm("   ldaa #$7e");
 0010 867E                              ldaa #$7e
 0012           
 0012           ;       asm("   staa $dc");
 0012 97DC                              staa $dc
 0014           
 0014           ;       //asm(" staa $eb");
 0014           ;       asm("   staa $d9");
 0014 97D9                              staa $d9
 0016           
 0016           ;       asm("   ldd #_rtoc2");
 0016 CC00D4                            ldd #_rtoc2
 0019           
 0019           ;       asm("   std $dd");
 0019 DDDD                              std $dd
 001B           
 001B           ;       asm("   ldd #_rtoc3");
 001B CC010A                            ldd #_rtoc3
 001E           
 001E           ;       asm("   std $da");
 001E DDDA                              std $da
 0020           
 0020           ;       /*asm(" ldd #_RTIINTR");
 0020           ;       asm("   std $ec");*/
 0020           ;       OC2hi = 0x3e8;
 0020 CC03E8            ldd #1000
 0023 FD0006            std _OC2hi
 0026           ;       OC2lo = 0x3e8;
 0026 CC03E8            ldd #1000
 0029 FD0004            std _OC2lo
 002C           ;       OC3hi = 0x3e8;
 002C CC03E8            ldd #1000
 002F FD0002            std _OC3hi
 0032           ;       OC3lo = 0x3e8;
 0032 CC03E8            ldd #1000
 0035 FD0000            std _OC3lo
 0038           ;       /*TMSK2=0x40;
 0038           ;       PACTL=PACTL&0xFC;
 0038           ;       PACTL=PACTL|0x00;*/
 0038           ;       
 0038           ;       initoc();
 0038 BD00B9            jsr _initoc
 003B           ;       motcont =0x03;
 003B C603              ldab #3
 003D F7B590            stab 0xb590
 0040 CC0000            ldd #0
 0043 ED04              std 4,x
 0045           L4:
 0045 BD0140            jsr _cnts2
 0048 BD021D            jsr _cnts3
 004B CC0314            ldd #L8
 004E BD0000            jsr _printf
 0051           L5:
 0051           ; 	
 0051           ; 	for (waste = 0; waste < 5; waste++){
 0051 EC04              ldd 4,x
 0053 C30001            addd #1
 0056 ED04              std 4,x
 0058 EC04              ldd 4,x
 005A 1A830005          cpd #5
 005E 2DE5              blt L4
 0060 204D              bra L10
 0062           L9:
 0062           ; 		 cnts2();
 0062           ; 		 cnts3();
 0062           ; 		 printf("FUCK YOU\n");
 0062           ; 		 }
 0062           ; 	while(1)
 0062           ; 	{	 
 0062           ; 		
 0062           ; 	 printf("%x  %x    %x\n",linetrack,TMSK1,PORTA);	
 0062           	; vol
 0062 F61000            ldab 0x1000
 0065 4F                clra
 0066 37                pshb
 0067 36                psha
 0068                   ; vol
 0068 F61022            ldab 0x1022
 006B 4F                clra
 006C 37                pshb
 006D 36                psha
 006E                   ; vol
 006E F6B5A0            ldab 0xb5a0
 0071 4F                clra
 0072 37                pshb
 0073 36                psha
 0074 CC0306            ldd #L12
 0077 BD0000            jsr _printf
 007A BD0000            jsr __movspb
 007D 06                .byte 6
 007E           ;                switch (linetrack & 0x01)
 007E                   ; vol
 007E F6B5A0            ldab 0xb5a0
 0081 4F                clra
 0082 8400              anda #0
 0084 C401              andb #1
 0086 ED02              std 2,x
 0088 1A830001          cpd #1
 008C 2702              beq L16
 008E 2019              bra L13
 0090           X0:
 0090           ; 		 {
 0090           L16:
 0090           ; 		 
 0090           ; 		case 0x01:
 0090           ; 			motcont = 0x03;
 0090 C603              ldab #3
 0092 F7B590            stab 0xb590
 0095           ;                       per_on2=35;
 0095 CC0023            ldd #35
 0098 FD0002            std _per_on2
 009B           ;                       per_on3=35;
 009B CC0023            ldd #35
 009E FD0004            std _per_on3
 00A1           ;                       cnts2();
 00A1 BD0140            jsr _cnts2
 00A4           ;                       cnts3();
 00A4 BD021D            jsr _cnts3
 00A7           ;                       break;
 00A7 2006              bra L14
 00A9           L13:
 00A9           ; 		 
 00A9           ; 		 default: 
 00A9           ; 		    TMSK1 = 0x00;
 00A9 7F1022            clr 0x1022
 00AC           ;                       PORTA = 0x00;
 00AC 7F1000            clr 0x1000
 00AF           ;                       break;
 00AF           L14:
 00AF           L10:
 00AF 20B1              bra L9
 00B1           X1:
 00B1           ; 		}	
 00B1           ; 		
 00B1           ; 		 
 00B1           ; 			 	 
 00B1           ;     }
 00B1           ; 
 00B1           ; 	
 00B1           ; }
 00B1           L3:
 00B1 8F                xgdx
 00B2 C30006            addd #6
 00B5 8F                xgdx
 00B6 35                txs
 00B7 38                pulx
 00B8                   .dbline 0 ; func end
 00B8 39                rts
 00B9           _initoc::
 00B9           ; 
 00B9           ; void initoc(void)
 00B9           ; /* Initialize OC2 */
 00B9           ; {
 00B9           ; 	TOC2 = TCNT;
 00B9           	; vol
 00B9 FC100E            ldd 0x100e
 00BC FD1018            std 0x1018
 00BF           ;       TOC3 = TCNT;
 00BF                   ; vol
 00BF FC100E            ldd 0x100e
 00C2 FD101A            std 0x101a
 00C5           ;       TCTL1 = 0x00;
 00C5 7F1020            clr 0x1020
 00C8           ;       TFLG1 = 0x60;
 00C8 C660              ldab #96
 00CA F71023            stab 0x1023
 00CD           ;       TMSK1 = 0x60;
 00CD C660              ldab #96
 00CF F71022            stab 0x1022
 00D2           ;       INTR_ON();
 00D2 0E                                cli
 00D3           
 00D3           ; }
 00D3           L17:
 00D3                   .dbline 0 ; func end
 00D3 39                rts
 00D4           _rtoc2::
 00D4           ; 
 00D4           ; void rtoc2(void)
 00D4           ; /* Interrupt Service Routine for OC2 PWM */
 00D4           ; {   
 00D4           ; 	if ((PORTA & 0X40) == 0){ 
 00D4 18CE1000          ldy #0x1000
 00D8 181F004002        brclr 0,y,#64,X2
 00DD 2013              bra L19
 00DF           X2:
 00DF           ; 		TOC2 = TOC2 + OC2hi;
 00DF           	; vol
 00DF FC1018            ldd 0x1018
 00E2 F30006            addd _OC2hi
 00E5 FD1018            std 0x1018
 00E8           ;               PORTA = PORTA | 0x40;
 00E8 18CE1000          ldy #0x1000
 00EC 181C0040          bset 0,y,#64
 00F0           ;               }
 00F0 2011              bra L20
 00F2           L19:
 00F2           ; 	else{
 00F2           ; 		TOC2 = TOC2 + OC2lo;
 00F2           	; vol
 00F2 FC1018            ldd 0x1018
 00F5 F30004            addd _OC2lo
 00F8 FD1018            std 0x1018
 00FB           ;               PORTA = PORTA & 0xBF;
 00FB 18CE1000          ldy #0x1000
 00FF 181D0040          bclr 0,y,#0x40
 0103           ;               }
 0103           L20:
 0103           ; 	//TCTL1 = TCTL1 ^ 0x40;	/* invert OL2 to toggle next OC2 edge */
 0103           ; 	TFLG1 = 0x40;	/* Clear flag OC2F */
 0103 C640              ldab #64
 0105 F71023            stab 0x1023
 0108           ;       asm("   rti");  /* This is an interrupt service routine */
 0108 3B                                rti
 0109           
 0109           ; }
 0109           L18:
 0109                   .dbline 0 ; func end
 0109 39                rts
 010A           _rtoc3::
 010A           ; 
 010A           ; void rtoc3(void)
 010A           ; {	
 010A           ; 	if ((PORTA & 0X20) == 0) {
 010A 18CE1000          ldy #0x1000
 010E 181F002002        brclr 0,y,#32,X3
 0113 2013              bra L22
 0115           X3:
 0115           ; 		TOC3 = TOC3 + OC3hi;
 0115           	; vol
 0115 FC101A            ldd 0x101a
 0118 F30002            addd _OC3hi
 011B FD101A            std 0x101a
 011E           ;               PORTA = PORTA | 0x20;
 011E 18CE1000          ldy #0x1000
 0122 181C0020          bset 0,y,#32
 0126           ;       }       
 0126 2011              bra L23
 0128           L22:
 0128           ; 	else{
 0128           ; 		TOC3 = TOC3 + OC3lo;
 0128           	; vol
 0128 FC101A            ldd 0x101a
 012B F30000            addd _OC3lo
 012E FD101A            std 0x101a
 0131           ;               PORTA = PORTA & 0xDF;
 0131 18CE1000          ldy #0x1000
 0135 181D0020          bclr 0,y,#0x20
 0139           ;       }
 0139           L23:
 0139           ; 	//TCTL1 = TCTL1 ^ 0x10;	/* invert OL2 to toggle next OC2 edge */
 0139           ; 	TFLG1 = 0x20;	/* Clear flag OC2F */
 0139 C620              ldab #32
 013B F71023            stab 0x1023
 013E           ;       asm("   rti");  /* This is an interrupt service routine */
 013E 3B                                rti
 013F           
 013F           ; }
 013F           L21:
 013F                   .dbline 0 ; func end
 013F 39                rts
 0140           ;  lreg1 -> -4,x
 0140           ;  lreg2 -> -8,x
 0140           ;  IX -> 0,x
 0140           ;          ?temp -> +2,x
 0140           ;          ?temp -> +6,x
 0140           _cnts2::
 0140 BD0000            jsr __enterb
 0143 88                .byte 0x88
 0144           ; void cnts2 (void)
 0144           ; {
 0144           ;       OC2hi=T_counts * (float)per_on2/100;
 0144 FC0002            ldd _per_on2
 0147 04                lsrd
 0148 BD0000            jsr __d2lreg
 014B BD0000            jsr __long2fp
 014E BD0000            jsr __fpmov
 0151 18CE0302          ldy #L28
 0155 BD0000            jsr __tofp1
 0158 BD0000            jsr __fpmul
 015B FC0002            ldd _per_on2
 015E 8400              anda #0
 0160 C401              andb #1
 0162 BD0000            jsr __d2lreg
 0165 BD0000            jsr __pshfp1 ; spill
 0168 BD0000            jsr __long2fp
 016B BD0000            jsr __fpmov
 016E BD0000            jsr __pulfp1 ; reload
 0171 BD0000            jsr __fpadd
 0174 BD0000            jsr __fpmov
 0177 FC0000            ldd _T_counts
 017A 04                lsrd
 017B BD0000            jsr __d2lreg
 017E BD0000            jsr __long2fp
 0181 BD0000            jsr __pshfp2 ; spill
 0184 BD0000            jsr __fpmov
 0187 18CE0302          ldy #L28
 018B BD0000            jsr __tofp1
 018E BD0000            jsr __fpmul
 0191 FC0000            ldd _T_counts
 0194 8400              anda #0
 0196 C401              andb #1
 0198 BD0000            jsr __d2lreg
 019B BD0000            jsr __pshfp1 ; spill
 019E BD0000            jsr __long2fp
 01A1 BD0000            jsr __fpmov
 01A4 BD0000            jsr __pulfp1 ; reload
 01A7 BD0000            jsr __fpadd
 01AA BD0000            jsr __pulfp2 ; reload
 01AD BD0000            jsr __fpmul
 01B0 18CE02FE          ldy #L29
 01B4 BD0000            jsr __tofp2
 01B7 BD0000            jsr __fpdiv
 01BA EC00              ldd 0,x
 01BC C30002            addd #2
 01BF 188F              xgdy
 01C1 BD0000            jsr __fromfp1
 01C4 EC00              ldd 0,x
 01C6 C30002            addd #2
 01C9 188F              xgdy
 01CB BD0000            jsr __tofp1
 01CE 18CE02FA          ldy #L30
 01D2 BD0000            jsr __tofp2
 01D5 BD0000            jsr __fpcmp
 01D8 2D1E              blt L26
 01DA EC00              ldd 0,x
 01DC C30002            addd #2
 01DF 188F              xgdy
 01E1 BD0000            jsr __tofp1
 01E4 18CE02FA          ldy #L30
 01E8 BD0000            jsr __tofp2
 01EB BD0000            jsr __fpsub
 01EE BD0000            jsr __fp2int
 01F1 C38000            addd #0x8000
 01F4 ED06              std 6,x
 01F6 200F              bra L27
 01F8           L26:
 01F8 EC00              ldd 0,x
 01FA C30002            addd #2
 01FD 188F              xgdy
 01FF BD0000            jsr __tofp1
 0202 BD0000            jsr __fp2int
 0205 ED06              std 6,x
 0207           L27:
 0207 EC06              ldd 6,x
 0209 FD0006            std _OC2hi
 020C           ;       OC2lo=T_counts - OC2hi;
 020C FC0000            ldd _T_counts
 020F B30006            subd _OC2hi
 0212 FD0004            std _OC2lo
 0215           ; }
 0215           L24:
 0215 8F                xgdx
 0216 C30008            addd #8
 0219 8F                xgdx
 021A 35                txs
 021B 38                pulx
 021C                   .dbline 0 ; func end
 021C 39                rts
 021D           ;  lreg1 -> -4,x
 021D           ;  lreg2 -> -8,x
 021D           ;  IX -> 0,x
 021D           ;          ?temp -> +2,x
 021D           ;          ?temp -> +6,x
 021D           _cnts3::
 021D BD0000            jsr __enterb
 0220 88                .byte 0x88
 0221           ; 
 0221           ; void cnts3 (void)
 0221           ; {
 0221           ;       OC3hi=T_counts * (float)per_on3/100;
 0221 FC0004            ldd _per_on3
 0224 04                lsrd
 0225 BD0000            jsr __d2lreg
 0228 BD0000            jsr __long2fp
 022B BD0000            jsr __fpmov
 022E 18CE0302          ldy #L28
 0232 BD0000            jsr __tofp1
 0235 BD0000            jsr __fpmul
 0238 FC0004            ldd _per_on3
 023B 8400              anda #0
 023D C401              andb #1
 023F BD0000            jsr __d2lreg
 0242 BD0000            jsr __pshfp1 ; spill
 0245 BD0000            jsr __long2fp
 0248 BD0000            jsr __fpmov
 024B BD0000            jsr __pulfp1 ; reload
 024E BD0000            jsr __fpadd
 0251 BD0000            jsr __fpmov
 0254 FC0000            ldd _T_counts
 0257 04                lsrd
 0258 BD0000            jsr __d2lreg
 025B BD0000            jsr __long2fp
 025E BD0000            jsr __pshfp2 ; spill
 0261 BD0000            jsr __fpmov
 0264 18CE0302          ldy #L28
 0268 BD0000            jsr __tofp1
 026B BD0000            jsr __fpmul
 026E FC0000            ldd _T_counts
 0271 8400              anda #0
 0273 C401              andb #1
 0275 BD0000            jsr __d2lreg
 0278 BD0000            jsr __pshfp1 ; spill
 027B BD0000            jsr __long2fp
 027E BD0000            jsr __fpmov
 0281 BD0000            jsr __pulfp1 ; reload
 0284 BD0000            jsr __fpadd
 0287 BD0000            jsr __pulfp2 ; reload
 028A BD0000            jsr __fpmul
 028D 18CE02FE          ldy #L29
 0291 BD0000            jsr __tofp2
 0294 BD0000            jsr __fpdiv
 0297 EC00              ldd 0,x
 0299 C30002            addd #2
 029C 188F              xgdy
 029E BD0000            jsr __fromfp1
 02A1 EC00              ldd 0,x
 02A3 C30002            addd #2
 02A6 188F              xgdy
 02A8 BD0000            jsr __tofp1
 02AB 18CE02FA          ldy #L30
 02AF BD0000            jsr __tofp2
 02B2 BD0000            jsr __fpcmp
 02B5 2D1E              blt L33
 02B7 EC00              ldd 0,x
 02B9 C30002            addd #2
 02BC 188F              xgdy
 02BE BD0000            jsr __tofp1
 02C1 18CE02FA          ldy #L30
 02C5 BD0000            jsr __tofp2
 02C8 BD0000            jsr __fpsub
 02CB BD0000            jsr __fp2int
 02CE C38000            addd #0x8000
 02D1 ED06              std 6,x
 02D3 200F              bra L34
 02D5           L33:
 02D5 EC00              ldd 0,x
 02D7 C30002            addd #2
 02DA 188F              xgdy
 02DC BD0000            jsr __tofp1
 02DF BD0000            jsr __fp2int
 02E2 ED06              std 6,x
 02E4           L34:
 02E4 EC06              ldd 6,x
 02E6 FD0002            std _OC3hi
 02E9           ;       OC3lo=T_counts - OC3hi;
 02E9 FC0000            ldd _T_counts
 02EC B30002            subd _OC3hi
 02EF FD0000            std _OC3lo
 02F2           ; }     
 02F2           L31:
 02F2 8F                xgdx
 02F3 C30008            addd #8
 02F6 8F                xgdx
 02F7 35                txs
 02F8 38                pulx
 02F9                   .dbline 0 ; func end
 02F9 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
 02FA           L30:
 02FA 47000000          .word 0x4700,0x0
 02FE           L29:
 02FE 42C80000          .word 0x42c8,0x0
 0302           L28:
 0302 40000000          .word 0x4000,0x0
 0306           L12:
 0306 2578202025782020202025780A00      .byte 37,'x,32,32,37,'x,32,32,32,32,37,'x,10,0
 0314           L8:
 0314 4655434B20594F550A00      .byte 'F,'U,'C,'K,32,'Y,'O,'U,10,0
