main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #include "../libpicofe/input.h"
  13. #include "../libpicofe/plat.h"
  14. #include "menu_pico.h"
  15. #include "emu.h"
  16. #include "config.h"
  17. #include <cpu/debug.h>
  18. #include <version.h>
  19. extern char *PicoConfigFile;
  20. static int load_state_slot = -1;
  21. char **g_argv;
  22. void parse_cmd_line(int argc, char *argv[])
  23. {
  24. int x, unrecognized = 0;
  25. for (x = 1; x < argc; x++)
  26. {
  27. if (argv[x][0] == '-')
  28. {
  29. if (strcasecmp(argv[x], "-config") == 0) {
  30. if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; }
  31. }
  32. else if (strcasecmp(argv[x], "-loadstate") == 0) {
  33. if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
  34. }
  35. else if (strcasecmp(argv[x], "-pdb") == 0) {
  36. if (x+1 < argc) { ++x; pdb_command(argv[x]); }
  37. }
  38. else if (strcasecmp(argv[x], "-pdb_connect") == 0) {
  39. if (x+2 < argc) { pdb_net_connect(argv[x+1], argv[x+2]); x += 2; }
  40. }
  41. else {
  42. unrecognized = 1;
  43. break;
  44. }
  45. } else {
  46. /* External Frontend: ROM Name */
  47. FILE *f;
  48. strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload));
  49. rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0;
  50. f = fopen(rom_fname_reload, "rb");
  51. if (f) fclose(f);
  52. else unrecognized = 1;
  53. engineState = PGS_ReloadRom;
  54. break;
  55. }
  56. }
  57. if (unrecognized) {
  58. printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009\n");
  59. printf("usage: %s [options] [romfile]\n", argv[0]);
  60. printf("options:\n"
  61. " -config <file> use specified config file instead of default 'config.cfg'\n"
  62. " -loadstate <num> if ROM is specified, try loading slot <num>\n");
  63. }
  64. }
  65. int main(int argc, char *argv[])
  66. {
  67. g_argv = argv;
  68. //plat_early_init();
  69. in_init();
  70. in_probe();
  71. plat_target_init();
  72. emu_prep_defconfig(); // depends on input
  73. emu_read_config(NULL, 0);
  74. emu_init();
  75. menu_init();
  76. engineState = PGS_Menu;
  77. if (argc > 1)
  78. parse_cmd_line(argc, argv);
  79. if (engineState == PGS_ReloadRom)
  80. {
  81. if (emu_reload_rom(rom_fname_reload)) {
  82. engineState = PGS_Running;
  83. if (load_state_slot >= 0) {
  84. state_slot = load_state_slot;
  85. emu_save_load_game(1, 0);
  86. }
  87. }
  88. }
  89. for (;;)
  90. {
  91. switch (engineState)
  92. {
  93. case PGS_Menu:
  94. menu_loop();
  95. break;
  96. case PGS_TrayMenu:
  97. menu_loop_tray();
  98. break;
  99. case PGS_ReloadRom:
  100. if (emu_reload_rom(rom_fname_reload))
  101. engineState = PGS_Running;
  102. else {
  103. printf("PGS_ReloadRom == 0\n");
  104. engineState = PGS_Menu;
  105. }
  106. break;
  107. case PGS_RestartRun:
  108. engineState = PGS_Running;
  109. /* vvv fallthrough */
  110. case PGS_Running:
  111. emu_loop();
  112. break;
  113. case PGS_Quit:
  114. goto endloop;
  115. default:
  116. printf("engine got into unknown state (%i), exitting\n", engineState);
  117. goto endloop;
  118. }
  119. }
  120. endloop:
  121. emu_finish();
  122. plat_target_finish();
  123. return 0;
  124. }