core: move central play loop to a separate function