You would need to use a timer which has configurable up down direction base od dir input. Its not trivial to solve it even with the counter.
For the moment the simolefic library will support an interrupt approach, but this is just a simple implementation and it is definitely not the optimal one . The code is already implemented in the dev branch. Here is an example: