psp code updated for latest base, black level
[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();
6fc57144 36 emu_prepareDefaultConfig();
7d4906bf 37 emu_ReadConfig(0, 0);
1820b5a7 38 emu_Init();
39 menu_init();
110df09c 40 // moved to emu_Loop(), after CPU clock change..
41 //mp3_init();
1820b5a7 42
43 engineState = PGS_Menu;
44
45 for (;;)
46 {
47 switch (engineState)
48 {
49 case PGS_Menu:
2445b7cb 50#ifndef GPROF
1820b5a7 51 menu_loop();
110df09c 52#else
6fc57144 53 strcpy(romFileName, lastRomFile);
110df09c 54 engineState = PGS_ReloadRom;
55#endif
1820b5a7 56 break;
57
58 case PGS_ReloadRom:
4b167c12 59 if (emu_ReloadRom()) {
1820b5a7 60 engineState = PGS_Running;
4b167c12 61 if (mp3_last_error != 0)
62 engineState = PGS_Menu; // send to menu to display mp3 error
63 } else {
1820b5a7 64 lprintf("PGS_ReloadRom == 0\n");
65 engineState = PGS_Menu;
66 }
1820b5a7 67 break;
68
7d0143a2 69 case PGS_Suspending:
ea08c296 70 while (engineState == PGS_Suspending)
71 psp_wait_suspend();
7d0143a2 72 break;
73
1820b5a7 74 case PGS_RestartRun:
75 engineState = PGS_Running;
76
77 case PGS_Running:
ea08c296 78 if (psp_unhandled_suspend) {
79 psp_resume_suspend();
80 emu_HandleResume();
81 }
7d4906bf 82 emu_Loop();
2445b7cb 83#ifdef GPROF
110df09c 84 goto endloop;
85#endif
1820b5a7 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
110df09c 99 mp3_deinit();
1820b5a7 100 emu_Deinit();
2445b7cb 101#ifdef GPROF
110df09c 102 gprof_cleanup();
103#endif
2445b7cb 104#ifndef GCOV
1820b5a7 105 psp_finish();
110df09c 106#endif
1820b5a7 107
108 return 0;
109}
110