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