main.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * PicoDrive
  3. * (C) notaz, 2006-2010
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <strings.h>
  12. #ifdef USE_SDL
  13. #include <SDL.h>
  14. #endif
  15. #include "../libpicofe/input.h"
  16. #include "../libpicofe/plat.h"
  17. #include "menu_pico.h"
  18. #include "emu.h"
  19. #include "version.h"
  20. #include <cpu/debug.h>
  21. #ifdef USE_LIBRETRO_VFS
  22. #include "file_stream_transforms.h"
  23. #endif
  24. static int load_state_slot = -1;
  25. char **g_argv;
  26. void parse_cmd_line(int argc, char *argv[])
  27. {
  28. int x, unrecognized = 0;
  29. for (x = 1; x < argc; x++)
  30. {
  31. if (argv[x][0] == '-')
  32. {
  33. if (strcasecmp(argv[x], "-config") == 0) {
  34. if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; }
  35. }
  36. else if (strcasecmp(argv[x], "-loadstate") == 0
  37. || strcasecmp(argv[x], "-load") == 0)
  38. {
  39. if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
  40. }
  41. else if (strcasecmp(argv[x], "-pdb") == 0) {
  42. if (x+1 < argc) { ++x; pdb_command(argv[x]); }
  43. }
  44. else if (strcasecmp(argv[x], "-pdb_connect") == 0) {
  45. if (x+2 < argc) { pdb_net_connect(argv[x+1], argv[x+2]); x += 2; }
  46. }
  47. else {
  48. unrecognized = 1;
  49. break;
  50. }
  51. } else {
  52. FILE *f = fopen(argv[x], "rb");
  53. if (f) {
  54. fclose(f);
  55. rom_fname_reload = argv[x];
  56. engineState = PGS_ReloadRom;
  57. }
  58. else
  59. unrecognized = 1;
  60. break;
  61. }
  62. }
  63. if (unrecognized) {
  64. printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009,2013\n");
  65. printf("usage: %s [options] [romfile]\n", argv[0]);
  66. printf("options:\n"
  67. " -config <file> use specified config file instead of default 'config.cfg'\n"
  68. " -loadstate <num> if ROM is specified, try loading savestate slot <num>\n");
  69. exit(1);
  70. }
  71. }
  72. int main(int argc, char *argv[])
  73. {
  74. g_argv = argv;
  75. plat_early_init();
  76. in_init();
  77. //in_probe();
  78. plat_target_init();
  79. plat_init();
  80. menu_init();
  81. emu_prep_defconfig(); // depends on input
  82. emu_read_config(NULL, 0);
  83. emu_init();
  84. #ifdef GPERF
  85. ProfilerStart("gperf.out");
  86. #endif
  87. engineState = PGS_Menu;
  88. if (argc > 1)
  89. parse_cmd_line(argc, argv);
  90. if (engineState == PGS_ReloadRom)
  91. {
  92. if (emu_reload_rom(rom_fname_reload)) {
  93. engineState = PGS_Running;
  94. if (load_state_slot >= 0) {
  95. state_slot = load_state_slot;
  96. emu_save_load_game(1, 0);
  97. }
  98. }
  99. }
  100. for (;;)
  101. {
  102. switch (engineState)
  103. {
  104. case PGS_Menu:
  105. menu_loop();
  106. break;
  107. case PGS_TrayMenu:
  108. menu_loop_tray();
  109. break;
  110. case PGS_ReloadRom:
  111. if (emu_reload_rom(rom_fname_reload))
  112. engineState = PGS_Running;
  113. else {
  114. printf("PGS_ReloadRom == 0\n");
  115. engineState = PGS_Menu;
  116. }
  117. break;
  118. case PGS_RestartRun:
  119. engineState = PGS_Running;
  120. /* vvv fallthrough */
  121. case PGS_Running:
  122. emu_loop();
  123. break;
  124. case PGS_Quit:
  125. goto endloop;
  126. default:
  127. printf("engine got into unknown state (%i), exitting\n", engineState);
  128. goto endloop;
  129. }
  130. }
  131. endloop:
  132. #ifdef GPERF
  133. ProfilerStop();
  134. #endif
  135. emu_finish();
  136. plat_finish();
  137. plat_target_finish();
  138. return 0;
  139. }