Rewrite raw memcard threading code. Intended to fix issue 7484.

Could these Event changes be put in a separate commit?