cff531af |
1 | /* |
2 | * PicoDrive |
3 | * (C) notaz, 2007,2008 |
4 | * |
5 | * This work is licensed under the terms of MAME license. |
6 | * See COPYING file in the top-level directory. |
7 | */ |
8b99ab90 |
8 | |
110df09c |
9 | #include <string.h> |
1820b5a7 |
10 | #include "psp.h" |
11 | #include "emu.h" |
12 | #include "menu.h" |
4b167c12 |
13 | #include "mp3.h" |
1820b5a7 |
14 | #include "../common/menu.h" |
7d4906bf |
15 | #include "../common/emu.h" |
c060a9ab |
16 | #include "../common/config.h" |
1820b5a7 |
17 | #include "../common/lprintf.h" |
18 | |
2445b7cb |
19 | #ifdef GPROF |
110df09c |
20 | #include <pspprof.h> |
21 | #endif |
22 | |
2445b7cb |
23 | #ifdef GCOV |
110df09c |
24 | #include <stdio.h> |
25 | #include <stdlib.h> |
26 | |
27 | void dummy(void) |
1820b5a7 |
28 | { |
713c9224 |
29 | engineState = atoi(rom_fname_reload); |
110df09c |
30 | setbuf(NULL, NULL); |
31 | getenv(NULL); |
32 | } |
33 | #endif |
4b167c12 |
34 | |
2445b7cb |
35 | int pico_main(void) |
110df09c |
36 | { |
1820b5a7 |
37 | psp_init(); |
651b1a25 |
38 | |
6fc57144 |
39 | emu_prepareDefaultConfig(); |
7d4906bf |
40 | emu_ReadConfig(0, 0); |
651b1a25 |
41 | config_readlrom(PicoConfigFile); |
42 | |
1820b5a7 |
43 | emu_Init(); |
44 | menu_init(); |
110df09c |
45 | // moved to emu_Loop(), after CPU clock change.. |
46 | //mp3_init(); |
1820b5a7 |
47 | |
48 | engineState = PGS_Menu; |
49 | |
50 | for (;;) |
51 | { |
52 | switch (engineState) |
53 | { |
54 | case PGS_Menu: |
2445b7cb |
55 | #ifndef GPROF |
1820b5a7 |
56 | menu_loop(); |
110df09c |
57 | #else |
713c9224 |
58 | strcpy(rom_fname_reload, rom_fname_loaded); |
110df09c |
59 | engineState = PGS_ReloadRom; |
60 | #endif |
1820b5a7 |
61 | break; |
62 | |
63 | case PGS_ReloadRom: |
a47dd663 |
64 | if (emu_reload_rom(rom_fname_reload)) { |
1820b5a7 |
65 | engineState = PGS_Running; |
4b167c12 |
66 | if (mp3_last_error != 0) |
67 | engineState = PGS_Menu; // send to menu to display mp3 error |
68 | } else { |
1820b5a7 |
69 | lprintf("PGS_ReloadRom == 0\n"); |
70 | engineState = PGS_Menu; |
71 | } |
1820b5a7 |
72 | break; |
73 | |
7d0143a2 |
74 | case PGS_Suspending: |
2b02d6e5 |
75 | while (engineState == PGS_Suspending) |
ea08c296 |
76 | psp_wait_suspend(); |
2b02d6e5 |
77 | break; |
78 | |
79 | case PGS_SuspendWake: |
80 | psp_unhandled_suspend = 0; |
81 | psp_resume_suspend(); |
82 | emu_HandleResume(); |
83 | engineState = engineStateSuspend; |
7d0143a2 |
84 | break; |
85 | |
1820b5a7 |
86 | case PGS_RestartRun: |
87 | engineState = PGS_Running; |
88 | |
89 | case PGS_Running: |
ea08c296 |
90 | if (psp_unhandled_suspend) { |
2b02d6e5 |
91 | psp_unhandled_suspend = 0; |
ea08c296 |
92 | psp_resume_suspend(); |
93 | emu_HandleResume(); |
2b02d6e5 |
94 | break; |
ea08c296 |
95 | } |
f2cf8472 |
96 | pemu_loop(); |
2445b7cb |
97 | #ifdef GPROF |
110df09c |
98 | goto endloop; |
99 | #endif |
1820b5a7 |
100 | break; |
101 | |
102 | case PGS_Quit: |
103 | goto endloop; |
104 | |
105 | default: |
106 | lprintf("engine got into unknown state (%i), exitting\n", engineState); |
107 | goto endloop; |
108 | } |
109 | } |
110 | |
111 | endloop: |
112 | |
110df09c |
113 | mp3_deinit(); |
1820b5a7 |
114 | emu_Deinit(); |
2445b7cb |
115 | #ifdef GPROF |
110df09c |
116 | gprof_cleanup(); |
117 | #endif |
2445b7cb |
118 | #ifndef GCOV |
1820b5a7 |
119 | psp_finish(); |
110df09c |
120 | #endif |
1820b5a7 |
121 | |
122 | return 0; |
123 | } |
124 | |