Hardware abstraction: refactoring

Unfortunately, this is a reorganization of so hugely interwoven code that I was not able to split this into agreeably sized chunks. I'm truly sorry.

This is a cleanup of all hardware-dependent behavior. It had to leave the "ui/" subdirectory, since it was never really conceptually part of our UI code. I tried to entangle lots of things, and I opted to distribute matters a bit over files. This way, it is pretty obvious where implementations for new devices should go.

That said, this is a major reorganization. A few parts are still left to be done - yes, I'm looking at you, uimanager.lua!

This needs testing (and most probably has bugs) on all devices, I only tested emulator for now. So please do not merge yet, but rather report what is broken on various devices. Thank you very much!

Oh, and I plan to add a bit of developer documentation for the code structure implemented here.