Err.... I don't fully know how this is exactly done...
just read the source code.
It would be a good idea to get the Amiga Hardware Reference Manual
(published by Addison-Wesley) as a reference, at least to the OCS/ECS
parts.
Regards,
-is