Behavioral and cortical mechanisms for spatial coding and action planning