Code:
//in 0 -> start
//in 1 -> x-state
//in 2 -> y-state
//out 0 -> ready indicator
//out 1 -> x
//out 2 -> y
//out 3 -> grab
//out 4 -> nail
//eax -> first parameter
//ebx -> second parameter
DATA;
MoveX: //moves to eax
mov port1,eax;
loopX:
mov ebx,port1;
cmp ebx,eax;
jne loopX;
ret;
MoveY: //moves to eax
mov port2,eax;
loopY:
mov ebx,port2;
cmp ebx,eax;
jne loopY;
ret;
Wait: //waits half a second
timer eax;
add eax,0.5;
loopWait:
timer ebx;
cmp eax,ebx;
jg loopWait;
ret;
MoveStack: //moves to stack 1,2,3 or 4, saved in eax
mov ebx,95; //constant
sub eax,1; //IMPORTANT!! stack 1 is actually ZERO!!
mul ebx,eax;
mov eax,30;
add eax,ebx;
call MoveX;
ret;
Pick: //picks an item from the stack in eax
call MoveStack;
mov eax,30;
call MoveY;
call Wait;
mov port3,1;
call Wait;
mov eax,0;
call MoveY;
ret;
Stack: //stacks an item to stack in eax
call MoveStack;
mov eax,30;
call MoveY;
call Wait;
mov port3,0;
call Wait;
mov eax,0;
call MoveY;
ret;
Nail: //nails an item to stack in eax
call MoveStack;
mov eax,30;
call MoveY;
call Wait;
mov port3,0;
call Wait;
mov port4,1;
call Wait;
mov port4,0;
mov eax,0;
call MoveY;
ret;
mov ebx,95;
CODE;
init:
mov port0,0;
mov eax,30;
call MoveX;
mov eax,0;
call MoveY;
mov port3,0;
mov port4,0;
mov port0,1;
jmp idl;
idl:
mov eax,port0;
cmp eax,1;
je process1;
cmp eax,2;
je process2;
jmp idl;
//process1:
//pick item 4
//nail pick on 3
//pick item 3
//stack pick on 2
//pick item 1
//nail pick on 2
process1:
mov port0,0;
mov eax,4;
call Pick;
mov eax,3;
call Nail;
mov eax,3;
call Pick;
mov eax,2;
call Stack;
mov eax,1;
call Pick;
mov eax,2;
call Nail;
mov port0,1;
jmp idl;
process2:
mov port0,0;
mov eax,1;
call Pick;
mov eax,4;
call Stack;
mov eax,1;
call Pick;
mov eax,3;
call Stack;
mov port0,1;
jmp idl;