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