Steal some PIF-logic from MAME/MESS.