bad56a9a8cfddaf0a3bd2ba865639542f2a14ce7
[libpicofe.git] / 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 #define GPROF 0
17 #define GCOV 0
18
19 #if GPROF
20 #include <pspprof.h>
21 #endif
22
23 #if GCOV
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 void dummy(void)
28 {
29         engineState = atoi(romFileName);
30         setbuf(NULL, NULL);
31         getenv(NULL);
32 }
33 #endif
34
35 int main()
36 {
37         lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n");
38         psp_init();
39         emu_ReadConfig(0, 0);
40         emu_Init();
41         menu_init();
42         // moved to emu_Loop(), after CPU clock change..
43         //mp3_init();
44
45         engineState = PGS_Menu;
46
47         for (;;)
48         {
49                 switch (engineState)
50                 {
51                         case PGS_Menu:
52 #if !GPROF
53                                 menu_loop();
54 #else
55                                 strcpy(romFileName, currentConfig.lastRomFile);
56                                 engineState = PGS_ReloadRom;
57 #endif
58                                 break;
59
60                         case PGS_ReloadRom:
61                                 if (emu_ReloadRom()) {
62                                         engineState = PGS_Running;
63                                         if (mp3_last_error != 0)
64                                                 engineState = PGS_Menu; // send to menu to display mp3 error
65                                 } else {
66                                         lprintf("PGS_ReloadRom == 0\n");
67                                         engineState = PGS_Menu;
68                                 }
69                                 break;
70
71                         case PGS_RestartRun:
72                                 engineState = PGS_Running;
73
74                         case PGS_Running:
75                                 emu_Loop();
76 #if GPROF
77                                 goto endloop;
78 #endif
79                                 break;
80
81                         case PGS_Quit:
82                                 goto endloop;
83
84                         default:
85                                 lprintf("engine got into unknown state (%i), exitting\n", engineState);
86                                 goto endloop;
87                 }
88         }
89
90         endloop:
91
92         mp3_deinit();
93         emu_Deinit();
94 #if GPROF
95         gprof_cleanup();
96 #endif
97 #if !GCOV
98         psp_finish();
99 #endif
100
101         return 0;
102 }
103