First Phase (Chaos, CHAOS!) Space to attack with the hammer in whatever direction Mario is facing. Second Phase (True Form) Z to attack with Hammer X to attack with Jump Up Arrow to move up Down Arrow to move down
Make sure to double click the flag. Credit where it's due.