first version for replacing input fifo with circular buffer. not debugged yet.