;*************************************************************
;Name:          Robot Driver Program
;
;Author:        Dan Kohn
;
;Date:          10/28/2005
;
;Instructions:  Do Not turn on Robot Arm until program 
;               is running! Then turn it on and press any
;               key. Robot will move in the pre-defined
;               sequence (s0..sx) and then repeat the 
;               sequence. Each step will last aprox 5 sec.
;


            org 100h

            mov al, all_stop    ;turn off all motors
            mov dx,378h
            out dx, al

		    mov dx, offset msg  ;print message
		    mov ah, 9
		    int 21h


            mov ah,00h          ;wait for 'any key'
            int 16h

            mov si, offset s0

next:       

            mov al, [si]
            mov dx,378h
            out dx, al

; wait 5 seconds (5 million microseconds)
            mov ah,00
            int 1ah
            add dx,005ah
            mov bx,dx
t_loop:     mov ah,00
            int 1ah
            cmp bx,dx
            jg t_loop:

            inc si              ;next situation
            cmp si, sx
            jb  next
            
            mov ah,01h          ;if q pressed end
            int 16h
            cmp al,'q'
            je  exit
            
            mov si, offset s0
            jmp next

exit:       ret

;                   7654_3210
s0          db      0000_1111b ;gripper open
s1          db      0000_0100b ;wrist cw
s2          db      0001_0111b ;elbow up
s3          db      0010_0111b ;base cw
;s4          db      0000_0011b ;shoulder up

s5          db      0000_0000b ;gripper close
s6          db      0000_0001b ;elbow down
s7          db      1000_0111b ;wrist ccw
;s8          db      0100_0111b ;shoulder down
s9          db      0000_0010b ;base ccw

sa          db      0000_0111b ;stop

sx = $


all_stop    equ     0000_0111b

msg         db "Turn on Robot Arm and then press any key to continue",10,13,"Press Q to stop robot at end of sequence. $"
