This simple code make it so that Mario can't swim in water more than one time without touching the ground.
Note that it's still possible to have him swim more or less high using the directional buttons, though.
It works by modifying controller-related RAM addresses, so look up the code before combining it with another controller-related gimmick.
EDITS & UPDATES:
- fixed issue about not being able to dismount Yoshi while in water.
- fixed issues with "level paused", "message box active" and "sprites locked" flags.