Add main_common to reduce duplication of code.

Right now it's a few lines, but it might expand in the future. I don't
know if it's appropriate to do init_emulator in this function, as it
feels redundant, but it might do that later after some discussion