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" |
2951214e |
13 | #include "../common/lprintf.h" |
16e89bed |
14 | #include "version.h" |
2951214e |
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 | { |
16e89bed |
34 | lprintf("\nPicoDrive v" VERSION " " __DATE__ " " __TIME__ "\n"); |
2951214e |
35 | psp_init(); |
bf7e9c61 |
36 | |
960a8e27 |
37 | emu_prepareDefaultConfig(); |
703e4c7b |
38 | emu_ReadConfig(0, 0); |
bf7e9c61 |
39 | config_readlrom(PicoConfigFile); |
40 | |
2951214e |
41 | emu_Init(); |
42 | menu_init(); |
fe9e3b25 |
43 | // moved to emu_Loop(), after CPU clock change.. |
44 | //mp3_init(); |
2951214e |
45 | |
46 | engineState = PGS_Menu; |
47 | |
48 | for (;;) |
49 | { |
50 | switch (engineState) |
51 | { |
52 | case PGS_Menu: |
93c0d147 |
53 | #ifndef GPROF |
2951214e |
54 | menu_loop(); |
fe9e3b25 |
55 | #else |
960a8e27 |
56 | strcpy(romFileName, lastRomFile); |
fe9e3b25 |
57 | engineState = PGS_ReloadRom; |
58 | #endif |
2951214e |
59 | break; |
60 | |
61 | case PGS_ReloadRom: |
a6df06b7 |
62 | if (emu_ReloadRom()) { |
2951214e |
63 | engineState = PGS_Running; |
a6df06b7 |
64 | if (mp3_last_error != 0) |
65 | engineState = PGS_Menu; // send to menu to display mp3 error |
66 | } else { |
2951214e |
67 | lprintf("PGS_ReloadRom == 0\n"); |
68 | engineState = PGS_Menu; |
69 | } |
2951214e |
70 | break; |
71 | |
426ecc58 |
72 | case PGS_Suspending: |
677b5dd8 |
73 | while (engineState == PGS_Suspending) |
74 | psp_wait_suspend(); |
426ecc58 |
75 | break; |
76 | |
2951214e |
77 | case PGS_RestartRun: |
78 | engineState = PGS_Running; |
79 | |
80 | case PGS_Running: |
677b5dd8 |
81 | if (psp_unhandled_suspend) { |
82 | psp_resume_suspend(); |
83 | emu_HandleResume(); |
84 | } |
703e4c7b |
85 | emu_Loop(); |
93c0d147 |
86 | #ifdef GPROF |
fe9e3b25 |
87 | goto endloop; |
88 | #endif |
2951214e |
89 | break; |
90 | |
91 | case PGS_Quit: |
92 | goto endloop; |
93 | |
94 | default: |
95 | lprintf("engine got into unknown state (%i), exitting\n", engineState); |
96 | goto endloop; |
97 | } |
98 | } |
99 | |
100 | endloop: |
101 | |
fe9e3b25 |
102 | mp3_deinit(); |
2951214e |
103 | emu_Deinit(); |
93c0d147 |
104 | #ifdef GPROF |
fe9e3b25 |
105 | gprof_cleanup(); |
106 | #endif |
93c0d147 |
107 | #ifndef GCOV |
2951214e |
108 | psp_finish(); |
fe9e3b25 |
109 | #endif |
2951214e |
110 | |
111 | return 0; |
112 | } |
113 | |