                        .module ROBOTARMTEST.c
                        .area text
                ;  IX -> 0,x
                ;    ball_deploy -> +2,x
                ;           stop -> +4,x
                ;        counter -> +6,x
                ;      raise_var -> +8,x
                ;         helper -> +10,x
 0000           _main::
 0000 BD0000            jsr __enterb
 0003 0C                .byte 0xc
 0004           ; #include <stdio.h>
 0004           ; #include <hc11.h>
 0004           ; 
 0004           ; #define topofrobot *(unsigned char volatile *)        (0xB590)
 0004           ; #define       limitswitches *(unsigned char volatile *) (0xB5C0)
 0004           ; 
 0004           ; 
 0004           ; void main (void)
 0004           ; {
 0004           ;    int helper=0, ball_deploy=0, raise_var=0, counter=0, stop=0;
 0004 CC0000            ldd #0
 0007 ED0A              std 10,x
 0009 CC0000            ldd #0
 000C ED02              std 2,x
 000E CC0000            ldd #0
 0011 ED08              std 8,x
 0013 CC0000            ldd #0
 0016 ED06              std 6,x
 0018 CC0000            ldd #0
 001B ED04              std 4,x
 001D           ; // enable the robot arm
 001D           ; // this allows the displays to be active and motors to be going forward
 001D           ;    topofrobot = 0x07;
 001D C607              ldab #7
 001F F7B590            stab 0xb590
 0022           ;    helper = limitswitches & 0x30; 
 0022                   ; vol
 0022 F6B5C0            ldab 0xb5c0
 0025 4F                clra
 0026 8400              anda #0
 0028 C430              andb #48
 002A ED0A              std 10,x
 002C 7E00AF            jmp L5
 002F           X0:
 002F           ; while (1)
 002F           ; {   
 002F           L7:
 002F           ; while (stop == 0)
 002F           ; {
 002F           ;   
 002F           ; 
 002F           ;    if ( helper == 0x10 )  // crane is at ball station and ready to lower
 002F EC0A              ldd 10,x
 0031 1A830010          cpd #16
 0035 2703              beq X2
 0037 7E00A3            jmp L10
 003A           X2:
 003A           ;    { 
 003A 2044              bra L13
 003C           L12:
 003C           ; 	  while ( helper != 0x20 ) // while crane isnt down
 003C           ; 	  {
 003C           ;    	   		
 003C           ; 			topofrobot = 0x57; // turn on magnets and motor 
 003C C657              ldab #87
 003E F7B590            stab 0xb590
 0041           ;                       helper = limitswitches & 0x30; // reset helper
 0041                   ; vol
 0041 F6B5C0            ldab 0xb5c0
 0044 4F                clra
 0045 8400              anda #0
 0047 C430              andb #48
 0049 ED0A              std 10,x
 004B           ;                       if ( helper == 0x20 )   // when crane is down
 004B EC0A              ldd 10,x
 004D 1A830020          cpd #32
 0051 261E              bne L15
 0053           ;                       {
 0053 2014              bra L18
 0055           L17:
 0055 C64F              ldab #79
 0057 F7B590            stab 0xb590
 005A                   ; vol
 005A F6B5C0            ldab 0xb5c0
 005D 4F                clra
 005E 8400              anda #0
 0060 C430              andb #48
 0062 ED0A              std 10,x
 0064 CC0001            ldd #1
 0067 ED08              std 8,x
 0069           L18:
 0069           ; 	   	   	   while ( helper != 0x10 )     // when crane is not in up position
 0069 EC0A              ldd 10,x
 006B 1A830010          cpd #16
 006F 26E4              bne L17
 0071           ;                          {
 0071           ;                         
 0071           ;                                        topofrobot = 0x4F;                             // bring crane back up
 0071           ;                                        helper = limitswitches & 0x30;
 0071           ;                                        raise_var = 1;
 0071           ;                          }
 0071           ;                       }               
 0071           L15:
 0071           ; 	   if ( raise_var == 1 )
 0071 EC08              ldd 8,x
 0073 1A830001          cpd #1
 0077 2607              bne L20
 0079           ;          {
 0079           ;          raise_var = 0;
 0079 CC0000            ldd #0
 007C ED08              std 8,x
 007E           ;          break;
 007E 2016              bra L23
 0080           L20:
 0080           L13:
 0080 EC0A              ldd 10,x
 0082 1A830020          cpd #32
 0086 26B4              bne L12
 0088 200C              bra L23
 008A           L22:
 008A C603              ldab #3
 008C F7B590            stab 0xb590
 008F EC06              ldd 6,x
 0091 C30001            addd #1
 0094 ED06              std 6,x
 0096           L23:
 0096           ; 	   }
 0096           ; 	   }
 0096           ; 	 while (counter <= 1000)
 0096 EC06              ldd 6,x
 0098 1A8303E8          cpd #1000
 009C 2FEC              ble L22
 009E           ;        {
 009E           ;       
 009E           ;       topofrobot = 0x03;                                      //when crane is back up, turn 
 009E           ;         counter ++;
 009E           ;        }
 009E           ;        counter = 0;                                                                           //everything off but leave wheels forward 
 009E CC0000            ldd #0
 00A1 ED06              std 6,x
 00A3           ;    }
 00A3           L10:
 00A3 C603              ldab #3
 00A5 F7B590            stab 0xb590
 00A8           L8:
 00A8 EC04              ldd 4,x
 00AA 2603              bne X3
 00AC 7E002F            jmp L7
 00AF           X3:
 00AF           L5:
 00AF 20F7              bra L8
 00B1           X1:
 00B1           ;    topofrobot = 0x03;
 00B1           ; }   
 00B1           ; }
 00B1           ; }	
 00B1           L3:
 00B1 8F                xgdx
 00B2 C3000C            addd #12
 00B5 8F                xgdx
 00B6 35                txs
 00B7 38                pulx
 00B8                   .dbline 0 ; func end
 00B8 39                rts
