	.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
_main::
	jsr __enterb
	.byte 0xc
; #include <stdio.h>
; #include <hc11.h>
; 
; #define topofrobot *(unsigned char volatile *)	(0xB590)
; #define	limitswitches *(unsigned char volatile *) (0xB5C0)
; 
; 
; void main (void)
; {
;    int helper=0, ball_deploy=0, raise_var=0, counter=0, stop=0;
	ldd #0
	std 10,x
	ldd #0
	std 2,x
	ldd #0
	std 8,x
	ldd #0
	std 6,x
	ldd #0
	std 4,x
; // enable the robot arm
; // this allows the displays to be active and motors to be going forward
;    topofrobot = 0x07;
	ldab #7
	stab 0xb590
;    helper = limitswitches & 0x30; 
	; vol
	ldab 0xb5c0
	clra
	anda #0
	andb #48
	std 10,x
	jmp L5
X0:
; while (1)
; {   
L7:
; while (stop == 0)
; {
;   
; 
;    if ( helper == 0x10 )  // crane is at ball station and ready to lower
	ldd 10,x
	cpd #16
	beq X2
	jmp L10
X2:
;    { 
	bra L13
L12:
; 	  while ( helper != 0x20 ) // while crane isnt down
; 	  {
;    	   		
; 			topofrobot = 0x57; // turn on magnets and motor 
	ldab #87
	stab 0xb590
;    			helper = limitswitches & 0x30; // reset helper
	; vol
	ldab 0xb5c0
	clra
	anda #0
	andb #48
	std 10,x
; 	  		if ( helper == 0x20 )	// when crane is down
	ldd 10,x
	cpd #32
	bne L15
; 	  		{
	bra L18
L17:
	ldab #79
	stab 0xb590
	; vol
	ldab 0xb5c0
	clra
	anda #0
	andb #48
	std 10,x
	ldd #1
	std 8,x
L18:
; 	   	   	   while ( helper != 0x10 )     // when crane is not in up position
	ldd 10,x
	cpd #16
	bne L17
; 			   {
; 			  
; 			   		 topofrobot = 0x4F; 	  	   		// bring crane back up
; 	  		   		 helper = limitswitches & 0x30;
; 			   		 raise_var = 1;
; 			   }
; 			}		
L15:
; 	   if ( raise_var == 1 )
	ldd 8,x
	cpd #1
	bne L20
; 	   {
; 	   raise_var = 0;
	ldd #0
	std 8,x
; 	   break;
	bra L23
L20:
L13:
	ldd 10,x
	cpd #32
	bne L12
	bra L23
L22:
	ldab #3
	stab 0xb590
	ldd 6,x
	addd #1
	std 6,x
L23:
; 	   }
; 	   }
; 	 while (counter <= 1000)
	ldd 6,x
	cpd #1000
	ble L22
; 	 {
; 	
;       topofrobot = 0x03; 					//when crane is back up, turn 
; 	  counter ++;
; 	 }
; 	 counter = 0; 			   							//everything off but leave wheels forward 
	ldd #0
	std 6,x
;    }
L10:
	ldab #3
	stab 0xb590
L8:
	ldd 4,x
	bne X3
	jmp L7
X3:
L5:
	bra L8
X1:
;    topofrobot = 0x03;
; }   
; }
; }	
L3:
	xgdx
	addd #12
	xgdx
	txs
	pulx
	.dbline 0 ; func end
	rts
