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