WARNING: EXTCODE CODE AREA DO NOT CONTAIN RELOCATED ADDRESSES.
THIS WILL BE REMEDIED IN A LATER RELEASE.
                        .module robot.c
                        .area memory(abs)
                        .org 0x3e5e
 3E5E            _IRQ_TOF_vector::
 3E5E  118C              .word _TOF_isr
                        .area data
                        .area memory(abs)
                        .org 0x3e52
 3E52            _IRQ_ATD0_vector::
 3E52  12F2              .word _ATD0_Interrupt
                        .area data
                        .area memory(abs)
                        .org 0x3e50
 3E50            _IRQ_ATD1_vector::
 3E50  133F              .word _ATD1_Interrupt
                        .area data
                        .area memory(abs)
                        .org 0x3e64
 3E64            _IRQ_OC5_vector::
 3E64  1434              .word _OC5_ISR
                        .area data
                        .area text
                ;           time -> -8,x
                ;              i -> -4,x
                ;              t -> -2,x
 102A            _main::
 102A  34                pshx
 102B  B775              tfr s,x
 102D  1B98              leas -8,sp
 102F            ; //*****************************************************************************
 102F            ; // Name:                              2007 Robot Code
 102F            ; // Vers:                          0.1
 102F            ; // Last Revised:              1/27/07 10:16pm
 102F            ; //*****************************************************************************                                       
 102F            ; 
 102F            ; #include<mc9S12dp256.h>
 102F            ; #include<stdio.h>
 102F            ; 
 102F            ; //define 16 bit PWM registers
 102F            ; #define PWMPERW1 _LP(0xB4) 
 102F            ; #define PWMPERW3 _LP(0xB6)
 102F            ; #define PWMPERW5 _LP(0xB8)
 102F            ; #define PWMPERW7 _LP(0xBA)
 102F            ; 
 102F            ; #define PWMDTYW1 _LP(0xBC)
 102F            ; #define PWMDTYW3 _LP(0xBE)
 102F            ; #define PWMDTYW5 _LP(0xC0)
 102F            ; #define PWMDTYW7 _LP(0xC2)
 102F            ; 
 102F            ; // Function Prototypes
 102F            ; void init_pwm(void);
 102F            ; void init_timer(void);
 102F            ; void ob_led(int);
 102F            ; void pause(int);
 102F            ; void s_pause(int pause_time);
 102F            ; void init_tof(void);
 102F            ; void init_atd0(void);
 102F            ; void Speaker(void);
 102F            ; void stop(void);
 102F            ; void forward(void);
 102F            ; void reverse(void);
 102F            ; void left(void);
 102F            ; void right(void);
 102F            ; 
 102F            ; //General 
 102F            ; #define CLI asm("CLI")
 102F            ; #define SEI asm("SEI")
 102F            ; 
 102F            ; //TOF Interrupt Setup
 102F            ; void TOF_isr(void); 
 102F            ; #pragma interrupt_handler TOF_isr
 102F            ; #pragma abs_address: 0x3e5e
 102F            ; void (*IRQ_TOF_vector[])()={TOF_isr};
 102F            ; #pragma end_abs_address
 102F            ; 
 102F            ; //ATD0 Interrupt Setup
 102F            ; void ATD0_Interrupt();
 102F            ; #pragma interrupt_handler ATD0_Interrupt()
 102F            ; #pragma abs_address: 0x3E52
 102F            ; void (*IRQ_ATD0_vector[])()={ATD0_Interrupt};
 102F            ; #pragma end_abs_address
 102F            ; 
 102F            ; //ATD1 Interrupt Setup
 102F            ; void ATD1_Interrupt();
 102F            ; #pragma interrupt_handler ATD1_Interrupt()
 102F            ; #pragma abs_address: 0x3E50
 102F            ; void (*IRQ_ATD1_vector[])()={ATD1_Interrupt};
 102F            ; #pragma end_abs_address
 102F            ; 
 102F            ; //OC5 Interrupt Setup
 102F            ; void OC5_ISR();
 102F            ; #pragma interrupt_handler OC5_ISR()
 102F            ; #pragma abs_address: 0x3E64
 102F            ; void (*IRQ_OC5_vector[])()={OC5_ISR};
 102F            ; #pragma end_abs_address
 102F            ; 
 102F            ; //declare global variable
 102F            ; long int t_counts;
 102F            ; long int t_tenths;
 102F            ; long int t_hundredths;
 102F            ; unsigned int atd0[8];
 102F            ; int atd1[8];
 102F            ; int dela;
 102F            ; 
 102F            ; void main(void)
 102F            ; {
 102F            ; 
 102F            ;    int t,i;
 102F            ;    long int time;
 102F            ;    
 102F            ;    init_pwm();
 102F  1610BC            jsr _init_pwm
 1032            ;    init_tof();
 1032  161178            jsr _init_tof
 1035            ;    init_atd0();
 1035  1612DE            jsr _init_atd0
 1038            ;    init_atd1();
 1038  16132B            jsr _init_atd1
 103B            ;    pause(1);
 103B  CC0001            ldd #1
 103E  161258            jsr _pause
 1041            ;    ATD0CTL5 = 0x30;
 1041  C630              ldab #48
 1043  7B0085            stab 0x85
 1046            ;    ATD1CTL5 = 0x30;
 1046  C630              ldab #48
 1048  7B0125            stab 0x125
 104B  200E              bra L5
 104D            L4:
 104D  EC1E              ldd -2,x
 104F  161081            jsr _ob_led
 1052  CC000A            ldd #10
 1055  161258            jsr _pause
 1058  161139            jsr _reverse
 105B            L5:
 105B            ; 
 105B            ;    while(1)
 105B  20F0              bra L4
 105D            X0:
 105D            ;    {
 105D            ;      // t++;
 105D            ; 	 // if (t>15)
 105D            ; 	  //   t=0;
 105D            ;       		 
 105D            ;       ob_led(t);
 105D            ; 	  pause(10);
 105D            ; 	 // for (i=0;i<=7;i++)
 105D            ; 	  //{
 105D            ; 	    // printf ("atd0[%u] = %u   atd1[%u] = %u\n\r",i,atd0[i],i,atd1[i]);
 105D            ; 	 // }
 105D            ; 	  //printf("%ld %ld\n\r",t_tenths,t_hundredths);
 105D            ; 	 // 
 105D            ; 	 // if (atd0[4]<100)
 105D            ; 	  //{
 105D            ; 	   //  printf ("forward\n\r");
 105D            ; 	    // forward();
 105D            ; 	  //}
 105D            ; 	  //else
 105D            ; 	//  {
 105D            ; 	 //    printf ("reverse\n\r");
 105D            ; 	//     reverse();
 105D            ; 	 // }
 105D            ;      // printf("\n\r");	  
 105D            ; 	  
 105D            ; 	  reverse();
 105D            ; 	  
 105D            ; 	  
 105D            ; //	  Speaker();
 105D            ; //	  printf ("Timer = %ld \n\r",t_tenths);
 105D            ;    }
 105D            ; }
 105D            L3:
 105D  B757              tfr x,s
 105F  30                pulx
 1060                    .dbline 0 ; func end
 1060  3D                rts
 1061            L8:
 1061  003F              .word 63
 1063  0006              .word 6
 1065  005B              .word 91
 1067  004F              .word 79
 1069  0066              .word 102
 106B  006D              .word 109
 106D  007D              .word 125
 106F  0007              .word 7
 1071  007F              .word 127
 1073  006F              .word 111
 1075  0077              .word 119
 1077  007C              .word 124
 1079  0039              .word 57
 107B  005E              .word 94
 107D  0079              .word 121
 107F  0071              .word 113
 1081            ;            out -> -32,x
 1081            ;              t -> 2,x
 1081            _ob_led::
 1081  3B                pshd
 1082  34                pshx
 1083  B775              tfr s,x
 1085  1BF1DE            leas -34,sp
 1088            ; 
 1088            ; 
 1088            ; // Display value passed to function on on board 7-seg LED of MiniDragon Board
 1088            ; void ob_led(int t)               
 1088            ; {
 1088            ; 
 1088            ;   int out[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
 1088  19E1E0            leay -32,x
 108B  B7C6              xgdy
 108D  CD1061            ldy #L8
 1090  34                pshx
 1091  B745              tfr d,x
 1093  CC0010            ldd #16
 1096            X1:
 1096  18027131          movw 2,y+,2,x+
 109A  0434F9            dbne d,X1
 109D  30                pulx
 109E            ;     0x39,0x5e,0x79,0x71};
 109E            ;   
 109E            ;   DDRH=0xff;
 109E  C6FF              ldab #255
 10A0  7B0262            stab 0x262
 10A3            ;   
 10A3            ;   PTH=out[t];
 10A3  19E1E0            leay -32,x
 10A6  6DE1DE            sty -34,x
 10A9  EC02              ldd 2,x
 10AB  59                lsld
 10AC  E3E1DE            addd -34,x
 10AF  B7C6              xgdy
 10B1  EC40              ldd 0,y
 10B3  7B0260            stab 0x260
 10B6            ; 
 10B6            ;   
 10B6            ; }
 10B6            L7:
 10B6  B757              tfr x,s
 10B8  30                pulx
 10B9  1B82              leas 2,sp
 10BB                    .dbline 0 ; func end
 10BB  3D                rts
 10BC            _init_pwm::
 10BC            ; 
 10BC            ; // Set up 4-16bit PWM 
 10BC            ; void init_pwm()
 10BC            ; {
 10BC            ;   PWMTST = 0x00; 		   			  // turn off all PWM special Modes
 10BC  7900A6            clr 0xa6
 10BF            ;   PWMCAE = 0x00;                                        // PWM left aligned output mode 
 10BF  7900A4            clr 0xa4
 10C2            ;   PWMCTL = 0xf0;                                        // Use Concatenated Mode (16-bit)
 10C2  C6F0              ldab #240
 10C4  7B00A5            stab 0xa5
 10C7            ;   
 10C7            ;   
 10C7            ;   PWMPRCLK = 0x33;                                      // E/8 for A and B       
 10C7  C633              ldab #51
 10C9  7B00A3            stab 0xa3
 10CC            ;   
 10CC            ;   PWMCLK = 0x00;                                        // PW Chan 1, 5 clock A
 10CC  7900A2            clr 0xa2
 10CF            ;                                                                         // PW chan 3, 7 clock B
 10CF            ;                                                                         
 10CF            ;   PWMPOL= 0xaa;                                                 // High Polarity for all channels
 10CF  C6AA              ldab #170
 10D1  7B00A1            stab 0xa1
 10D4            ;   DDRP= 0xaa;                                           // Set Port P to output 
 10D4  C6AA              ldab #170
 10D6  7B025A            stab 0x25a
 10D9            ; 
 10D9            ;   PWMPERW1 = 60000;                                     //stop (7.5%) all motors
 10D9  CCEA60            ldd #0xea60
 10DC  7C00B4            std 0xb4
 10DF            ;   PWMDTYW1 = 4500;
 10DF  CC1194            ldd #4500
 10E2  7C00BC            std 0xbc
 10E5            ;   
 10E5            ;   PWMPERW3 = 60000;                                   
 10E5  CCEA60            ldd #0xea60
 10E8  7C00B6            std 0xb6
 10EB            ;   PWMDTYW3 = 4500;
 10EB  CC1194            ldd #4500
 10EE  7C00BE            std 0xbe
 10F1            ;   
 10F1            ;   PWMPERW5 = 60000;                                   
 10F1  CCEA60            ldd #0xea60
 10F4  7C00B8            std 0xb8
 10F7            ;   PWMDTYW5 = 4500;
 10F7  CC1194            ldd #4500
 10FA  7C00C0            std 0xc0
 10FD            ; 
 10FD            ;   PWMPERW7 = 60000;                                    
 10FD  CCEA60            ldd #0xea60
 1100  7C00BA            std 0xba
 1103            ;   PWMDTYW7 = 4500;
 1103  CC1194            ldd #4500
 1106  7C00C2            std 0xc2
 1109            ;   PWME= 0xaa;                                           // Enable ALL PWM Channels
 1109  C6AA              ldab #170
 110B  7B00A0            stab 0xa0
 110E            ; 
 110E            ; }
 110E            L9:
 110E                    .dbline 0 ; func end
 110E  3D                rts
 110F            _stop::
 110F            ; 
 110F            ; // Stop
 110F            ; void stop(void)
 110F            ; {
 110F            ;    PWME = 0x00;
 110F  7900A0            clr 0xa0
 1112            ;    PWMDTYW1 = 4500;
 1112  CC1194            ldd #4500
 1115  7C00BC            std 0xbc
 1118            ;    PWMDTYW3 = 4500;
 1118  CC1194            ldd #4500
 111B  7C00BE            std 0xbe
 111E            ;    PWME = 0xaa;
 111E  C6AA              ldab #170
 1120  7B00A0            stab 0xa0
 1123            ; }
 1123            L10:
 1123                    .dbline 0 ; func end
 1123  3D                rts
 1124            _forward::
 1124            ;    
 1124            ; // forward
 1124            ; void forward(void)
 1124            ; {
 1124            ;    PWME = 0x00;
 1124  7900A0            clr 0xa0
 1127            ;    PWMDTYW1 = 3000;
 1127  CC0BB8            ldd #3000
 112A  7C00BC            std 0xbc
 112D            ;    PWMDTYW3 = 6000;
 112D  CC1770            ldd #6000
 1130  7C00BE            std 0xbe
 1133            ;    PWME = 0xaa;
 1133  C6AA              ldab #170
 1135  7B00A0            stab 0xa0
 1138            ; }
 1138            L11:
 1138                    .dbline 0 ; func end
 1138  3D                rts
 1139            _reverse::
 1139            ; // reverse
 1139            ; void reverse(void)
 1139            ; {
 1139            ;    PWME = 0x00;
 1139  7900A0            clr 0xa0
 113C            ;    PWMDTYW1 = 6000;
 113C  CC1770            ldd #6000
 113F  7C00BC            std 0xbc
 1142            ;    PWMDTYW3 = 3000;
 1142  CC0BB8            ldd #3000
 1145  7C00BE            std 0xbe
 1148            ;    PWME = 0xaa;
 1148  C6AA              ldab #170
 114A  7B00A0            stab 0xa0
 114D            ; }
 114D            L12:
 114D                    .dbline 0 ; func end
 114D  3D                rts
 114E            _right::
 114E            ;    
 114E            ; // right
 114E            ; void right(void)
 114E            ; {
 114E            ;    PWME = 0x00;
 114E  7900A0            clr 0xa0
 1151            ;    PWMDTYW1 = 6000;
 1151  CC1770            ldd #6000
 1154  7C00BC            std 0xbc
 1157            ;    PWMDTYW3 = 6000;
 1157  CC1770            ldd #6000
 115A  7C00BE            std 0xbe
 115D            ;    PWME = 0xaa;
 115D  C6AA              ldab #170
 115F  7B00A0            stab 0xa0
 1162            ; }
 1162            L13:
 1162                    .dbline 0 ; func end
 1162  3D                rts
 1163            _left::
 1163            ; 
 1163            ; // left
 1163            ; void left(void)
 1163            ; {
 1163            ;    PWME = 0x00;
 1163  7900A0            clr 0xa0
 1166            ;    PWMDTY1 = 3000;
 1166  CC0BB8            ldd #3000
 1169  7B00BD            stab 0xbd
 116C            ;    PWMDTY3 = 3000;
 116C  CC0BB8            ldd #3000
 116F  7B00BF            stab 0xbf
 1172            ;    PWME = 0xaa;
 1172  C6AA              ldab #170
 1174  7B00A0            stab 0xa0
 1177            ; }
 1177            L14:
 1177                    .dbline 0 ; func end
 1177  3D                rts
 1178            _init_tof::
 1178            ; 
 1178            ; //Initialize Timer Overflow 
 1178            ; void init_tof()
 1178            ; {
 1178            ;    SEI;
 1178  1410                      SEI
 117A            
 117A            ;    TSCR1 = 0x80;                                        //turn on Timer
 117A  C680              ldab #128
 117C  7B0046            stab 0x46
 117F            ;    TFLG2 = 0x80;                                        //clear TOF flag
 117F  C680              ldab #128
 1181  7B004F            stab 0x4f
 1184            ;    TSCR2 = 0x80;                                        //turn on TOF interrupt
 1184  C680              ldab #128
 1186  7B004D            stab 0x4d
 1189            ;    CLI;
 1189  10EF                      CLI
 118B            
 118B            ; }
 118B            L15:
 118B                    .dbline 0 ; func end
 118B  3D                rts
 118C            ;  lreg1 -> -4,x
 118C            ;  lreg2 -> -8,x
 118C            _TOF_isr::
 118C  34                pshx
 118D  B775              tfr s,x
 118F  1B98              leas -8,sp
 1191            ; 
 1191            ; //Timer Overflow Counter (ISR)
 1191            ; void TOF_isr(void)  
 1191            ; {
 1191            ;    t_counts++;
 1191  CD16F7            ldy #_t_counts
 1194  1802401C          movw 0,y,-4,x
 1198  1802421E          movw 2,y,-2,x
 119C  CD144F            ldy #L17
 119F  18024018          movw 0,y,-8,x
 11A3  1802421A          movw 2,y,-6,x
 11A7  161507            jsr __ladd
 11AA  CD16F7            ldy #_t_counts
 11AD  18021C40          movw -4,x,0,y
 11B1  18021E42          movw -2,x,2,y
 11B5            ;    if ((t_counts%38)==0)
 11B5  CD16F7            ldy #_t_counts
 11B8  1802401C          movw 0,y,-4,x
 11BC  1802421E          movw 2,y,-2,x
 11C0  CD144B            ldy #L20
 11C3  18024018          movw 0,y,-8,x
 11C7  1802421A          movw 2,y,-6,x
 11CB  1615D6            jsr __lmod
 11CE  CD1447            ldy #L21
 11D1  18024018          movw 0,y,-8,x
 11D5  1802421A          movw 2,y,-6,x
 11D9  1616A8            jsr __lcmp
 11DC  2624              bne L18
 11DE            ;    {
 11DE            ;         t_tenths++;
 11DE  CD16F3            ldy #_t_tenths
 11E1  1802401C          movw 0,y,-4,x
 11E5  1802421E          movw 2,y,-2,x
 11E9  CD144F            ldy #L17
 11EC  18024018          movw 0,y,-8,x
 11F0  1802421A          movw 2,y,-6,x
 11F4  161507            jsr __ladd
 11F7  CD16F3            ldy #_t_tenths
 11FA  18021C40          movw -4,x,0,y
 11FE  18021E42          movw -2,x,2,y
 1202            ;    }
 1202            L18:
 1202            ;    if ((t_counts%4)==0)
 1202  CD16F7            ldy #_t_counts
 1205  1802401C          movw 0,y,-4,x
 1209  1802421E          movw 2,y,-2,x
 120D  CD1443            ldy #L24
 1210  18024018          movw 0,y,-8,x
 1214  1802421A          movw 2,y,-6,x
 1218  1615D6            jsr __lmod
 121B  CD1447            ldy #L21
 121E  18024018          movw 0,y,-8,x
 1222  1802421A          movw 2,y,-6,x
 1226  1616A8            jsr __lcmp
 1229  2624              bne L22
 122B            ;    {
 122B            ;       t_hundredths++;
 122B  CD16EF            ldy #_t_hundredths
 122E  1802401C          movw 0,y,-4,x
 1232  1802421E          movw 2,y,-2,x
 1236  CD144F            ldy #L17
 1239  18024018          movw 0,y,-8,x
 123D  1802421A          movw 2,y,-6,x
 1241  161507            jsr __ladd
 1244  CD16EF            ldy #_t_hundredths
 1247  18021C40          movw -4,x,0,y
 124B  18021E42          movw -2,x,2,y
 124F            ;    }
 124F            L22:
 124F            ;    
 124F            ;    TFLG2 = 0x80;
 124F  C680              ldab #128
 1251  7B004F            stab 0x4f
 1254            ; }
 1254            L16:
 1254  B757              tfr x,s
 1256  30                pulx
 1257                    .dbline 0 ; func end
 1257  0B                rti
 1258            ;  lreg1 -> -4,x
 1258            ;  lreg2 -> -8,x
 1258            ;       end_time -> -12,x
 1258            ;     pause_time -> 2,x
 1258            _pause::
 1258  3B                pshd
 1259  34                pshx
 125A  B775              tfr s,x
 125C  1B94              leas -12,sp
 125E            ; 
 125E            ; //pause for pause_time*0.1 sec
 125E            ; void pause(int pause_time)
 125E            ; {
 125E            ;    long int end_time;
 125E            ;    end_time = t_tenths + pause_time;
 125E  CD16F3            ldy #_t_tenths
 1261  1802401C          movw 0,y,-4,x
 1265  1802421E          movw 2,y,-2,x
 1269  EC02              ldd 2,x
 126B  1614BF            jsr __d2lreg2
 126E  161507            jsr __ladd
 1271  1914              leay -12,x
 1273  18021C40          movw -4,x,0,y
 1277  18021E42          movw -2,x,2,y
 127B            L26:
 127B            L27:
 127B            ; //   printf ("%ld = %ld + %d\n\r",end_time,t_tenths,pause_time);
 127B            ;    while(end_time>t_tenths)
 127B  1914              leay -12,x
 127D  1802401C          movw 0,y,-4,x
 1281  1802421E          movw 2,y,-2,x
 1285  CD16F3            ldy #_t_tenths
 1288  18024018          movw 0,y,-8,x
 128C  1802421A          movw 2,y,-6,x
 1290  1616A8            jsr __lcmp
 1293  2EE6              bgt L26
 1295            ;    {
 1295            ;    }
 1295            ; }
 1295            L25:
 1295  B757              tfr x,s
 1297  30                pulx
 1298  1B82              leas 2,sp
 129A                    .dbline 0 ; func end
 129A  3D                rts
 129B            ;  lreg1 -> -4,x
 129B            ;  lreg2 -> -8,x
 129B            ;       end_time -> -12,x
 129B            ;     pause_time -> 2,x
 129B            _s_pause::
 129B  3B                pshd
 129C  34                pshx
 129D  B775              tfr s,x
 129F  1B94              leas -12,sp
 12A1            ; 
 12A1            ; //pause for pause_time*0.01 sec
 12A1            ; void s_pause(int pause_time)
 12A1            ; {
 12A1            ;    long int end_time;
 12A1            ;    end_time = t_hundredths + pause_time;
 12A1  CD16EF            ldy #_t_hundredths
 12A4  1802401C          movw 0,y,-4,x
 12A8  1802421E          movw 2,y,-2,x
 12AC  EC02              ldd 2,x
 12AE  1614BF            jsr __d2lreg2
 12B1  161507            jsr __ladd
 12B4  1914              leay -12,x
 12B6  18021C40          movw -4,x,0,y
 12BA  18021E42          movw -2,x,2,y
 12BE            L30:
 12BE            L31:
 12BE            ; //   printf ("%ld = %ld + %d\n\r",end_time,t_tenths,pause_time);
 12BE            ;    while(end_time>t_hundredths)
 12BE  1914              leay -12,x
 12C0  1802401C          movw 0,y,-4,x
 12C4  1802421E          movw 2,y,-2,x
 12C8  CD16EF            ldy #_t_hundredths
 12CB  18024018          movw 0,y,-8,x
 12CF  1802421A          movw 2,y,-6,x
 12D3  1616A8            jsr __lcmp
 12D6  2EE6              bgt L30
 12D8            ;    {
 12D8            ;    }
 12D8            ; }
 12D8            L29:
 12D8  B757              tfr x,s
 12DA  30                pulx
 12DB  1B82              leas 2,sp
 12DD                    .dbline 0 ; func end
 12DD  3D                rts
 12DE            _init_atd0::
 12DE            ; 
 12DE            ; // ******************* Initialize ATD *******************
 12DE            ; void init_atd0()
 12DE            ; {
 12DE            ;    SEI;
 12DE  1410                      SEI
 12E0            
 12E0            ;    ATD0CTL2 = 0xC2;
 12E0  C6C2              ldab #194
 12E2  7B0082            stab 0x82
 12E5            ;    ATD0CTL3 = 0x40;
 12E5  C640              ldab #64
 12E7  7B0083            stab 0x83
 12EA            ;    ATD0CTL4 = 0xE7;
 12EA  C6E7              ldab #231
 12EC  7B0084            stab 0x84
 12EF            ;    CLI;
 12EF  10EF                      CLI
 12F1            
 12F1            ; }
 12F1            L33:
 12F1                    .dbline 0 ; func end
 12F1  3D                rts
 12F2            _ATD0_Interrupt::
 12F2            ; 
 12F2            ; /********************************************************************/
 12F2            ; /* This code is primarily taken from example 7.3.5 in the text      */
 12F2            ; /* and then converted to act as an ISR                              */
 12F2            ; /********************************************************************/
 12F2            ;   	  
 12F2            ; void ATD0_Interrupt(void)
 12F2            ; {
 12F2            ; /*print results to PC screen for testing             */
 12F2            ;    atd0[0]= ATD0DR0H;	
 12F2            	; vol
 12F2  F60090            ldab 0x90
 12F5  87                clra
 12F6  7C16DF            std _atd0
 12F9            ;    atd0[1]= ATD0DR1H;
 12F9                    ; vol
 12F9  F60092            ldab 0x92
 12FC  87                clra
 12FD  7C16E1            std _atd0+2
 1300            ;    atd0[2]= ATD0DR2H;
 1300                    ; vol
 1300  F60094            ldab 0x94
 1303  87                clra
 1304  7C16E3            std _atd0+4
 1307            ;    atd0[3]= ATD0DR3H;
 1307                    ; vol
 1307  F60096            ldab 0x96
 130A  87                clra
 130B  7C16E5            std _atd0+6
 130E            ;    atd0[4]= ATD0DR4H;
 130E                    ; vol
 130E  F60098            ldab 0x98
 1311  87                clra
 1312  7C16E7            std _atd0+8
 1315            ;    atd0[5]= ATD0DR5H;
 1315                    ; vol
 1315  F6009A            ldab 0x9a
 1318  87                clra
 1319  7C16E9            std _atd0+10
 131C            ;    atd0[6]= ATD0DR6H;
 131C                    ; vol
 131C  F6009C            ldab 0x9c
 131F  87                clra
 1320  7C16EB            std _atd0+12
 1323            ;    atd0[7]= ATD0DR7H;         
 1323                    ; vol
 1323  F6009E            ldab 0x9e
 1326  87                clra
 1327  7C16ED            std _atd0+14
 132A            ; // printf("%x %x %x %x\n\r", ATD0DR0L, ATD0DR1L, ATD0DR2L, ATD0DR3L); 
 132A            ; }
 132A            L34:
 132A                    .dbline 0 ; func end
 132A  0B                rti
 132B            _init_atd1::
 132B            ; 
 132B            ; // ******************* Initialize ATD *******************
 132B            ; void init_atd1()
 132B            ; {
 132B            ;    SEI;
 132B  1410                      SEI
 132D            
 132D            ;    ATD1CTL2 = 0xC2;
 132D  C6C2              ldab #194
 132F  7B0122            stab 0x122
 1332            ;    ATD1CTL3 = 0x40;
 1332  C640              ldab #64
 1334  7B0123            stab 0x123
 1337            ;    ATD1CTL4 = 0xE7;
 1337  C6E7              ldab #231
 1339  7B0124            stab 0x124
 133C            ;    CLI;
 133C  10EF                      CLI
 133E            
 133E            ; }
 133E            L42:
 133E                    .dbline 0 ; func end
 133E  3D                rts
 133F            _ATD1_Interrupt::
 133F            ; 
 133F            ; /********************************************************************/
 133F            ; /* This code is primarily taken from example 7.3.5 in the text      */
 133F            ; /* and then converted to act as an ISR                              */
 133F            ; /********************************************************************/
 133F            ;   	  
 133F            ; void ATD1_Interrupt(void)
 133F            ; {
 133F            ; /*print results to PC screen for testing             */
 133F            ;    atd1[0]= ATD1DR0H;	
 133F            	; vol
 133F  F60130            ldab 0x130
 1342  87                clra
 1343  7C16CF            std _atd1
 1346            ;    atd1[1]= ATD1DR1H;
 1346                    ; vol
 1346  F60132            ldab 0x132
 1349  87                clra
 134A  7C16D1            std _atd1+2
 134D            ;    atd1[2]= ATD1DR2H;
 134D                    ; vol
 134D  F60134            ldab 0x134
 1350  87                clra
 1351  7C16D3            std _atd1+4
 1354            ;    atd1[3]= ATD1DR3H;
 1354                    ; vol
 1354  F60136            ldab 0x136
 1357  87                clra
 1358  7C16D5            std _atd1+6
 135B            ;    atd1[4]= ATD1DR4H;
 135B                    ; vol
 135B  F60138            ldab 0x138
 135E  87                clra
 135F  7C16D7            std _atd1+8
 1362            ;    atd1[5]= ATD1DR5H;
 1362                    ; vol
 1362  F6013A            ldab 0x13a
 1365  87                clra
 1366  7C16D9            std _atd1+10
 1369            ;    atd1[6]= ATD1DR6H;
 1369                    ; vol
 1369  F6013C            ldab 0x13c
 136C  87                clra
 136D  7C16DB            std _atd1+12
 1370            ;    atd1[7]= ATD1DR7H;         
 1370                    ; vol
 1370  F6013E            ldab 0x13e
 1373  87                clra
 1374  7C16DD            std _atd1+14
 1377            ; // printf("%x %x %x %x\n\r", ATD0DR0L, ATD0DR1L, ATD0DR2L, ATD0DR3L); 
 1377            ; }
 1377            L43:
 1377                    .dbline 0 ; func end
 1377  0B                rti
 1378            L52:
 1378  BAB9              .word 47801
 137A  A65D              .word 42589
 137C  9430              .word 37936
 137E  8BE9              .word 35817
 1380  7C90              .word 31888
 1382  6EF9              .word 28409
 1384  62D7              .word 25303
 1386  5D5C              .word 23900
 1388            L53:
 1388  0005              .word 5
 138A  0005              .word 5
 138C  0005              .word 5
 138E  0005              .word 5
 1390  0005              .word 5
 1392  0005              .word 5
 1394  0005              .word 5
 1396  0005              .word 5
 1398            ;              i -> -36,x
 1398            ;            dur -> -34,x
 1398            ;          score -> -18,x
 1398            ;              j -> -2,x
 1398            _Speaker::
 1398  34                pshx
 1399  B775              tfr s,x
 139B  1BF1DA            leas -38,sp
 139E            ; 
 139E            ; //*****************************************************************************
 139E            ; #define  C5  47801
 139E            ; #define  C5S 45126
 139E            ; #define  D5    42589
 139E            ; #define        D5S 40193
 139E            ; #define        E5  37936
 139E            ; #define  F5    35817
 139E            ; #define  F5S 33784
 139E            ; #define        G5      31888
 139E            ; #define  G5S 30084
 139E            ; #define  A5    28409
 139E            ; #define  A5S 26824
 139E            ; #define  B5    25303
 139E            ; #define  C6    23900
 139E            ; #define  C6S 22542
 139E            ; #define  D6  21276
 139E            ; #define  D6S 20096
 139E            ; #define  E6  18825
 139E            ; #define  F6  17895
 139E            ; #define  F6S 16892
 139E            ; #define  G6    15944
 139E            ; #define  G6S 15051
 139E            ; #define  A6  14204
 139E            ; #define  A6S 13404
 139E            ; #define  B6  12658
 139E            ; 
 139E            ; 
 139E            ; #define  notes  8
 139E            ; #define  toggle 0x04
 139E            ; 
 139E            ; void Speaker (void)
 139E            ; {
 139E            ;    int j;
 139E            ;    int i;
 139E            ;    unsigned int score[notes] = {C5,D5,E5,F5,G5,A5,B5,C6};
 139E  19E1EE            leay -18,x
 13A1  B7C6              xgdy
 13A3  CD1378            ldy #L52
 13A6  34                pshx
 13A7  B745              tfr d,x
 13A9  CC0008            ldd #8
 13AC            X2:
 13AC  18027131          movw 2,y+,2,x+
 13B0  0434F9            dbne d,X2
 13B3  30                pulx
 13B4            ;    unsigned int dur[notes] = {5,5,5,5,5,5,5,5};
 13B4  19E1DE            leay -34,x
 13B7  B7C6              xgdy
 13B9  CD1388            ldy #L53
 13BC  34                pshx
 13BD  B745              tfr d,x
 13BF  CC0008            ldd #8
 13C2            X3:
 13C2  18027131          movw 2,y+,2,x+
 13C6  0434F9            dbne d,X3
 13C9  30                pulx
 13CA            ; 
 13CA            ; //   TSCR1 = 0x90;   //Enable TCNT, fast timer flag clear
 13CA            ; //   TSCR2 = 0x83;   //Set TCNT prescaler to 8
 13CA            ;    TFLG1 = 0x20;   //Clear all TxF flags
 13CA  C620              ldab #32
 13CC  7B004E            stab 0x4e
 13CF            ;    TIE  |= 0x20;   //Enable TC5 interrupt
 13CF  1C004C20          bset 0x4c,#32
 13D3            ;    TIOS |= 0x20;   //Enable OC5 function
 13D3  1C004020          bset 0x40,#32
 13D7            ;    TCTL1 = toggle; //Select toggle option as OC5 pin action
 13D7  C604              ldab #4
 13D9  7B0048            stab 0x48
 13DC            ;    j = 0;
 13DC  CC0000            ldd #0
 13DF  6C1E              std -2,x
 13E1            ;    dela = score[0];
 13E1  ECE1EE            ldd -18,x
 13E4  7C16CD            std _dela
 13E7            ;    TC5 = TCNT + dela;      //Play the first note
 13E7                    ; vol
 13E7  FC0044            ldd 0x44
 13EA  F316CD            addd _dela
 13ED  7C005A            std 0x5a
 13F0  202D              bra L55
 13F2            L54:
 13F2  19E1EE            leay -18,x
 13F5  6DE1DA            sty -38,x
 13F8  EC1E              ldd -2,x
 13FA  59                lsld
 13FB  E3E1DA            addd -38,x
 13FE  B7C6              xgdy
 1400  EC40              ldd 0,y
 1402  7C16CD            std _dela
 1405  19E1DE            leay -34,x
 1408  6DE1DA            sty -38,x
 140B  EC1E              ldd -2,x
 140D  59                lsld
 140E  E3E1DA            addd -38,x
 1411  B7C6              xgdy
 1413  EC40              ldd 0,y
 1415  16129B            jsr _s_pause
 1418  EC1E              ldd -2,x
 141A  C30001            addd #1
 141D  6C1E              std -2,x
 141F            L55:
 141F            ;    while(j < notes)
 141F  EC1E              ldd -2,x
 1421  8C0008            cpd #8
 1424  2DCC              blt L54
 1426            ;    {
 1426            ;       dela = score[j];     //Play the jth note
 1426            ;         s_pause(dur[j]);
 1426            ;         j++;
 1426            ;    }
 1426            ; 
 1426            ;    TIE  &= ~0x20;   //Disable TC5 interrupt
 1426  1D004C20          bclr 0x4c,#0x20
 142A            ; //   TSCR1 = 0x00;   //Turn off the Timer System
 142A            ;    PTT = 0x00;     //Blank Port T
 142A  790240            clr 0x240
 142D            ;    TCTL1 = 0;
 142D  790048            clr 0x48
 1430            ; }
 1430            L51:
 1430  B757              tfr x,s
 1432  30                pulx
 1433                    .dbline 0 ; func end
 1433  3D                rts
 1434            _OC5_ISR::
 1434            ; 
 1434            ; //******************************** OC5_ISR *************************************
 1434            ; 
 1434            ; #pragma interrupt_handler OC5_ISR()
 1434            ; void OC5_ISR ()
 1434            ; {
 1434            ;    TC5 += dela;
 1434            	; vol
 1434  FC005A            ldd 0x5a
 1437  F316CD            addd _dela
 143A  7C005A            std 0x5a
 143D            ;    TFLG1 = 0x20;
 143D  C620              ldab #32
 143F  7B004E            stab 0x4e
 1442            ; }
 1442            L57:
 1442                    .dbline 0 ; func end
 1442  0B                rti
                        .area bss
 16CD            _dela::
 16CD                    .blkb 2
 16CF            _atd1::
 16CF                    .blkb 16
 16DF            _atd0::
 16DF                    .blkb 16
 16EF            _t_hundredths::
 16EF                    .blkb 4
 16F3            _t_tenths::
 16F3                    .blkb 4
 16F7            _t_counts::
 16F7                    .blkb 4
                        .area text
--- 0419           L24:
--- 0419 00000004          .word 0,4
--- 041D           L21:
--- 041D 00000000          .word 0,0
--- 0421           L20:
--- 0421 00000026          .word 0,38
--- 0425           L17:
--- 0425 00000001          .word 0,1
                        .module putchar_dp256.c
                        .area text
                ;              c -> 3,x
 1453            _putchar::
 1453  3B                pshd
 1454  34                pshx
 1455  B775              tfr s,x
 1457            ; #include <stdio.h>
 1457            ; #define _SCI
 1457            ; #include <hcs12dp256.h>
 1457            ; extern int _textmode;
 1457            ; int putchar(char c)
 1457            ; {
 1457            ;      if (_textmode && c == '\n')
 1457  FC16FB            ldd __textmode
 145A  270C              beq L7
 145C  E603              ldab 3,x
 145E  C10A              cmpb #10
 1460  2606              bne L7
 1462            ;       putchar('\r');
 1462  CC000D            ldd #13
 1465  161453            jsr _putchar
 1468            L6:
 1468            L7:
 1468            ;      while ((SC0SR1 & TDRE) == 0)
 1468  1F00CC80FB        brclr 0xcc,#128,L6
 146D            ;        ;
 146D            ;      SC0DRL = c;
 146D  180D0300CF        movb 3,x,0xcf
 1472            ;      return c;
 1472  E603              ldab 3,x
 1474  87                clra
 1475            L3:
 1475  B757              tfr x,s
 1477  30                pulx
 1478  1B82              leas 2,sp
 147A                    .dbline 0 ; func end
 147A  3D                rts
