main.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // (c) Copyright 2006 notaz, All rights reserved.
  2. // Free for non-commercial use.
  3. // For commercial use, separate licencing terms must be obtained.
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <strings.h>
  9. #include <linux/limits.h>
  10. #include "../gp2x/gp2x.h"
  11. #include "../gp2x/menu.h"
  12. #include "../common/menu.h"
  13. #include "../common/emu.h"
  14. #include "../common/config.h"
  15. #include "../gp2x/emu.h"
  16. #include "../gp2x/version.h"
  17. extern int select_exits;
  18. extern char *PicoConfigFile;
  19. static int load_state_slot = -1;
  20. int mmuhack_status = 0; // TODO rm
  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], "-selectexit") == 0) {
  33. select_exits = 1;
  34. }
  35. else if(strcasecmp(argv[x], "-loadstate") == 0) {
  36. if(x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); }
  37. }
  38. else {
  39. unrecognized = 1;
  40. break;
  41. }
  42. } else {
  43. /* External Frontend: ROM Name */
  44. FILE *f;
  45. strncpy(romFileName, argv[x], PATH_MAX);
  46. romFileName[PATH_MAX-1] = 0;
  47. f = fopen(romFileName, "rb");
  48. if (f) fclose(f);
  49. else unrecognized = 1;
  50. engineState = PGS_ReloadRom;
  51. break;
  52. }
  53. }
  54. if (unrecognized) {
  55. printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2008\n");
  56. printf("usage: %s [options] [romfile]\n", argv[0]);
  57. printf( "options:\n"
  58. "-menu <menu_path> launch a custom program on exit instead of default gp2xmenu\n"
  59. "-state <param> pass '-state param' to the menu program\n"
  60. "-config <file> use specified config file instead of default 'picoconfig.bin'\n"
  61. " see currentConfig_t structure in emu.h for the file format\n"
  62. "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n"
  63. "-loadstate <num> if ROM is specified, try loading slot <num>\n");
  64. }
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. g_argv = argv;
  69. emu_prepareDefaultConfig();
  70. emu_ReadConfig(0, 0);
  71. config_readlrom(PicoConfigFile);
  72. gp2x_init();
  73. emu_Init();
  74. menu_init();
  75. engineState = PGS_Menu;
  76. if (argc > 1)
  77. parse_cmd_line(argc, argv);
  78. if (engineState == PGS_ReloadRom)
  79. {
  80. if (emu_ReloadRom(romFileName)) {
  81. engineState = PGS_Running;
  82. if (load_state_slot >= 0) {
  83. state_slot = load_state_slot;
  84. emu_SaveLoadGame(1, 0);
  85. }
  86. }
  87. }
  88. for (;;)
  89. {
  90. switch (engineState)
  91. {
  92. case PGS_Menu:
  93. menu_loop();
  94. break;
  95. case PGS_ReloadRom:
  96. if (emu_ReloadRom(romFileName))
  97. engineState = PGS_Running;
  98. else {
  99. printf("PGS_ReloadRom == 0\n");
  100. engineState = PGS_Menu;
  101. }
  102. break;
  103. case PGS_RestartRun:
  104. engineState = PGS_Running;
  105. case PGS_Running:
  106. emu_Loop();
  107. break;
  108. case PGS_Quit:
  109. goto endloop;
  110. default:
  111. printf("engine got into unknown state (%i), exitting\n", engineState);
  112. goto endloop;
  113. }
  114. }
  115. endloop:
  116. emu_Deinit();
  117. return 0;
  118. }