Make globals static to avoid conflicts with mouse code.
Make functions static. Only read one byte from bus per run.
Basics of mouse support.