63b796ca |
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 | |
fe9e3b25 |
6 | #include <string.h> |
2951214e |
7 | #include "psp.h" |
8 | #include "emu.h" |
9 | #include "menu.h" |
a6df06b7 |
10 | #include "mp3.h" |
2951214e |
11 | #include "../common/menu.h" |
703e4c7b |
12 | #include "../common/emu.h" |
8a091e48 |
13 | #include "../common/config.h" |
2951214e |
14 | #include "../common/lprintf.h" |
15 | |
93c0d147 |
16 | #ifdef GPROF |
fe9e3b25 |
17 | #include <pspprof.h> |
18 | #endif |
19 | |
93c0d147 |
20 | #ifdef GCOV |
fe9e3b25 |
21 | #include <stdio.h> |
22 | #include <stdlib.h> |
23 | |
24 | void dummy(void) |
2951214e |
25 | { |
fe9e3b25 |
26 | engineState = atoi(romFileName); |
27 | setbuf(NULL, NULL); |
28 | getenv(NULL); |
29 | } |
30 | #endif |
a6df06b7 |
31 | |
93c0d147 |
32 | int pico_main(void) |
fe9e3b25 |
33 | { |
2951214e |
34 | psp_init(); |
bf7e9c61 |
35 | |
960a8e27 |
36 | emu_prepareDefaultConfig(); |
703e4c7b |
37 | emu_ReadConfig(0, 0); |
bf7e9c61 |
38 | config_readlrom(PicoConfigFile); |
39 | |
2951214e |
40 | emu_Init(); |
41 | menu_init(); |
fe9e3b25 |
42 | // moved to emu_Loop(), after CPU clock change.. |
43 | //mp3_init(); |
2951214e |
44 | |
45 | engineState = PGS_Menu; |
46 | |
47 | for (;;) |
48 | { |
49 | switch (engineState) |
50 | { |
51 | case PGS_Menu: |
93c0d147 |
52 | #ifndef GPROF |
2951214e |
53 | menu_loop(); |
fe9e3b25 |
54 | #else |
960a8e27 |
55 | strcpy(romFileName, lastRomFile); |
fe9e3b25 |
56 | engineState = PGS_ReloadRom; |
57 | #endif |
2951214e |
58 | break; |
59 | |
60 | case PGS_ReloadRom: |
a6df06b7 |
61 | if (emu_ReloadRom()) { |
2951214e |
62 | engineState = PGS_Running; |
a6df06b7 |
63 | if (mp3_last_error != 0) |
64 | engineState = PGS_Menu; // send to menu to display mp3 error |
65 | } else { |
2951214e |
66 | lprintf("PGS_ReloadRom == 0\n"); |
67 | engineState = PGS_Menu; |
68 | } |
2951214e |
69 | break; |
70 | |
426ecc58 |
71 | case PGS_Suspending: |
4b811a8a |
72 | while (engineState == PGS_Suspending || engineState == PGS_SuspendAck) { |
73 | if (engineState == PGS_Suspending) |
74 | engineState = PGS_SuspendAck; |
677b5dd8 |
75 | psp_wait_suspend(); |
4b811a8a |
76 | } |
426ecc58 |
77 | break; |
78 | |
2951214e |
79 | case PGS_RestartRun: |
80 | engineState = PGS_Running; |
81 | |
82 | case PGS_Running: |
677b5dd8 |
83 | if (psp_unhandled_suspend) { |
84 | psp_resume_suspend(); |
85 | emu_HandleResume(); |
86 | } |
703e4c7b |
87 | emu_Loop(); |
93c0d147 |
88 | #ifdef GPROF |
fe9e3b25 |
89 | goto endloop; |
90 | #endif |
2951214e |
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 | |
fe9e3b25 |
104 | mp3_deinit(); |
2951214e |
105 | emu_Deinit(); |
93c0d147 |
106 | #ifdef GPROF |
fe9e3b25 |
107 | gprof_cleanup(); |
108 | #endif |
93c0d147 |
109 | #ifndef GCOV |
2951214e |
110 | psp_finish(); |
fe9e3b25 |
111 | #endif |
2951214e |
112 | |
113 | return 0; |
114 | } |
115 | |