Just sketch out the relationships of the two inputs and you'll see that you have a very simple state machine. You have four states and depending on which input changes you can transition from any state to one of two of the other three states. Depending on the transition, you either count up or count down. Your count gives you position and the rate at which you are counting gives you the speed.