diff --git a/programs/emulator/dgen-sdl-1.33/main.cpp b/programs/emulator/dgen-sdl-1.33/main.cpp index 69a71236f..0756cfe1e 100644 --- a/programs/emulator/dgen-sdl-1.33/main.cpp +++ b/programs/emulator/dgen-sdl-1.33/main.cpp @@ -31,6 +31,10 @@ #include #endif +#ifndef MAX_PATH +#define MAX_PATH 1024 +#endif + #ifdef __MINGW32__ static long dgen_mingw_detach = 1; #endif @@ -427,8 +431,34 @@ int main(int argc, char *argv[]) samples = (dgen_soundsegs * (rate / dgen_hz)); pd_sound_init(rate, samples); } + + char path_buf[MAX_PATH]; + char *p = path_buf; + int r; - rom = argv[optind]; + path_buf[0] = '\0'; + + for (r = optind; r < argc; ++r) { + if (r > optind) { // Append a space in later iterations + if (p - path_buf < sizeof(path_buf) - 2) *p++ = ' '; + } + + char *src = argv[r]; + while (*src && (p - path_buf < sizeof(path_buf) - 1)) { + *p++ = *src++; + } + *p = '\0'; + + if (access(path_buf, F_OK) == 0) { + rom = path_buf; // Point rom to the static buffer + optind = r; // Update optind + break; + } + } + + if (!rom && optind < argc) { + rom = argv[optind]; + } // Create the megadrive object. megad = new md(dgen_pal, dgen_region); if ((megad == NULL) || (!megad->okay())) {