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