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