main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/config.h"
  12. #include "../common/lprintf.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. psp_init();
  29. emu_prepareDefaultConfig();
  30. emu_ReadConfig(0, 0);
  31. config_readlrom(PicoConfigFile);
  32. emu_Init();
  33. menu_init();
  34. // moved to emu_Loop(), after CPU clock change..
  35. //mp3_init();
  36. engineState = PGS_Menu;
  37. for (;;)
  38. {
  39. switch (engineState)
  40. {
  41. case PGS_Menu:
  42. #ifndef GPROF
  43. menu_loop();
  44. #else
  45. strcpy(romFileName, loadedRomFName);
  46. engineState = PGS_ReloadRom;
  47. #endif
  48. break;
  49. case PGS_ReloadRom:
  50. if (emu_ReloadRom(romFileName)) {
  51. engineState = PGS_Running;
  52. if (mp3_last_error != 0)
  53. engineState = PGS_Menu; // send to menu to display mp3 error
  54. } else {
  55. lprintf("PGS_ReloadRom == 0\n");
  56. engineState = PGS_Menu;
  57. }
  58. break;
  59. case PGS_Suspending:
  60. while (engineState == PGS_Suspending)
  61. psp_wait_suspend();
  62. break;
  63. case PGS_SuspendWake:
  64. psp_unhandled_suspend = 0;
  65. psp_resume_suspend();
  66. emu_HandleResume();
  67. engineState = engineStateSuspend;
  68. break;
  69. case PGS_RestartRun:
  70. engineState = PGS_Running;
  71. case PGS_Running:
  72. if (psp_unhandled_suspend) {
  73. psp_unhandled_suspend = 0;
  74. psp_resume_suspend();
  75. emu_HandleResume();
  76. break;
  77. }
  78. emu_Loop();
  79. #ifdef GPROF
  80. goto endloop;
  81. #endif
  82. break;
  83. case PGS_Quit:
  84. goto endloop;
  85. default:
  86. lprintf("engine got into unknown state (%i), exitting\n", engineState);
  87. goto endloop;
  88. }
  89. }
  90. endloop:
  91. mp3_deinit();
  92. emu_Deinit();
  93. #ifdef GPROF
  94. gprof_cleanup();
  95. #endif
  96. #ifndef GCOV
  97. psp_finish();
  98. #endif
  99. return 0;
  100. }