main.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // (c) Copyright 2007 notaz, All rights reserved.
  2. // Free for non-commercial use.
  3. // For commercial use, separate licencing terms must be obtained.
  4. #include <string.h>
  5. #include "psp.h"
  6. #include "emu.h"
  7. #include "menu.h"
  8. #include "mp3.h"
  9. #include "../common/menu.h"
  10. #include "../common/emu.h"
  11. #include "../common/lprintf.h"
  12. #include "version.h"
  13. #ifdef GPROF
  14. #include <pspprof.h>
  15. #endif
  16. #ifdef GCOV
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. void dummy(void)
  20. {
  21. engineState = atoi(romFileName);
  22. setbuf(NULL, NULL);
  23. getenv(NULL);
  24. }
  25. #endif
  26. int pico_main(void)
  27. {
  28. lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n");
  29. psp_init();
  30. emu_ReadConfig(0, 0);
  31. emu_Init();
  32. menu_init();
  33. // moved to emu_Loop(), after CPU clock change..
  34. //mp3_init();
  35. engineState = PGS_Menu;
  36. for (;;)
  37. {
  38. switch (engineState)
  39. {
  40. case PGS_Menu:
  41. #ifndef GPROF
  42. menu_loop();
  43. #else
  44. strcpy(romFileName, currentConfig.lastRomFile);
  45. engineState = PGS_ReloadRom;
  46. #endif
  47. break;
  48. case PGS_ReloadRom:
  49. if (emu_ReloadRom()) {
  50. engineState = PGS_Running;
  51. if (mp3_last_error != 0)
  52. engineState = PGS_Menu; // send to menu to display mp3 error
  53. } else {
  54. lprintf("PGS_ReloadRom == 0\n");
  55. engineState = PGS_Menu;
  56. }
  57. break;
  58. case PGS_Suspending:
  59. while (engineState == PGS_Suspending)
  60. psp_wait_suspend();
  61. break;
  62. case PGS_RestartRun:
  63. engineState = PGS_Running;
  64. case PGS_Running:
  65. if (psp_unhandled_suspend) {
  66. psp_resume_suspend();
  67. emu_HandleResume();
  68. }
  69. emu_Loop();
  70. #ifdef GPROF
  71. goto endloop;
  72. #endif
  73. break;
  74. case PGS_Quit:
  75. goto endloop;
  76. default:
  77. lprintf("engine got into unknown state (%i), exitting\n", engineState);
  78. goto endloop;
  79. }
  80. }
  81. endloop:
  82. mp3_deinit();
  83. emu_Deinit();
  84. #ifdef GPROF
  85. gprof_cleanup();
  86. #endif
  87. #ifndef GCOV
  88. psp_finish();
  89. #endif
  90. return 0;
  91. }