Modify GPIO register logic to make it more compact and easier to follow

1) Tried to remove register write functions where possible and move the logic
   into the main write function.
2) Rewrote reset to not use the register write functions.  Instead, it
   updates the register variables directly and directly resets any
   derived state variables.  I think this is closer to how real hardware
   works, and is less error-prone.
3) Some other general cleanup to reduce clutter.