Spanish vehicle purchase queries

The thing doesn’t currently have a permiso de circulaciĆ³n, and is stored off-road. Is the former legal? If I buy it, how do I get the permiso so I can drive it away? Am I automatically given one on the cambio de titularidad? The current owner hasn’t transferred titularidad @DGT from the previous owner (the…