LEGO publiced firmware for NXT Intelligent Brick as Open Source.
There are sveral developer packages, which contains documentation for NXT:
What are the possibilities of Mindstorms programming?
http://bricxcc.sourceforge.net/