psp code updated for latest base, black level
[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 #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         emu_prepareDefaultConfig();
37         emu_ReadConfig(0, 0);
38         emu_Init();
39         menu_init();
40         // moved to emu_Loop(), after CPU clock change..
41         //mp3_init();
42
43         engineState = PGS_Menu;
44
45         for (;;)
46         {
47                 switch (engineState)
48                 {
49                         case PGS_Menu:
50 #ifndef GPROF
51                                 menu_loop();
52 #else
53                                 strcpy(romFileName, lastRomFile);
54                                 engineState = PGS_ReloadRom;
55 #endif
56                                 break;
57
58                         case PGS_ReloadRom:
59                                 if (emu_ReloadRom()) {
60                                         engineState = PGS_Running;
61                                         if (mp3_last_error != 0)
62                                                 engineState = PGS_Menu; // send to menu to display mp3 error
63                                 } else {
64                                         lprintf("PGS_ReloadRom == 0\n");
65                                         engineState = PGS_Menu;
66                                 }
67                                 break;
68
69                         case PGS_Suspending:
70                                 while (engineState == PGS_Suspending)
71                                         psp_wait_suspend();
72                                 break;
73
74                         case PGS_RestartRun:
75                                 engineState = PGS_Running;
76
77                         case PGS_Running:
78                                 if (psp_unhandled_suspend) {
79                                         psp_resume_suspend();
80                                         emu_HandleResume();
81                                 }
82                                 emu_Loop();
83 #ifdef GPROF
84                                 goto endloop;
85 #endif
86                                 break;
87
88                         case PGS_Quit:
89                                 goto endloop;
90
91                         default:
92                                 lprintf("engine got into unknown state (%i), exitting\n", engineState);
93                                 goto endloop;
94                 }
95         }
96
97         endloop:
98
99         mp3_deinit();
100         emu_Deinit();
101 #ifdef GPROF
102         gprof_cleanup();
103 #endif
104 #ifndef GCOV
105         psp_finish();
106 #endif
107
108         return 0;
109 }
110