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