Verbatim copy from https://github.com/libretro/picodrive/ commit 9ae88ef15f , so look there for the history of libretro specific changes. Unfortunately there is too much noise and divergence to merge this in a proper way.
9ae88ef15f