ABC turbo
[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
16#ifdef GPROF
17#include <pspprof.h>
18#endif
19
20#ifdef GCOV
21#include <stdio.h>
22#include <stdlib.h>
23
24void dummy(void)
25{
26 engineState = atoi(romFileName);
27 setbuf(NULL, NULL);
28 getenv(NULL);
29}
30#endif
31
32int pico_main(void)
33{
34 psp_init();
35
36 emu_prepareDefaultConfig();
37 emu_ReadConfig(0, 0);
38 config_readlrom(PicoConfigFile);
39
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#ifndef GPROF
53 menu_loop();
54#else
55 strcpy(romFileName, 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_Suspending:
72 while (engineState == PGS_Suspending || engineState == PGS_SuspendAck) {
73 if (engineState == PGS_Suspending)
74 engineState = PGS_SuspendAck;
75 psp_wait_suspend();
76 }
77 break;
78
79 case PGS_RestartRun:
80 engineState = PGS_Running;
81
82 case PGS_Running:
83 if (psp_unhandled_suspend) {
84 psp_resume_suspend();
85 emu_HandleResume();
86 }
87 emu_Loop();
88#ifdef GPROF
89 goto endloop;
90#endif
91 break;
92
93 case PGS_Quit:
94 goto endloop;
95
96 default:
97 lprintf("engine got into unknown state (%i), exitting\n", engineState);
98 goto endloop;
99 }
100 }
101
102 endloop:
103
104 mp3_deinit();
105 emu_Deinit();
106#ifdef GPROF
107 gprof_cleanup();
108#endif
109#ifndef GCOV
110 psp_finish();
111#endif
112
113 return 0;
114}
115