See resp #13 for a link to info about bit manipulation and reading ports directly.