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