update for recent /gp2x changes
[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"
c060a9ab 13#include "../common/config.h"
1820b5a7 14#include "../common/lprintf.h"
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{
713c9224 26 engineState = atoi(rom_fname_reload);
110df09c 27 setbuf(NULL, NULL);
28 getenv(NULL);
29}
30#endif
4b167c12 31
2445b7cb 32int pico_main(void)
110df09c 33{
1820b5a7 34 psp_init();
651b1a25 35
6fc57144 36 emu_prepareDefaultConfig();
7d4906bf 37 emu_ReadConfig(0, 0);
651b1a25 38 config_readlrom(PicoConfigFile);
39
1820b5a7 40 emu_Init();
41 menu_init();
110df09c 42 // moved to emu_Loop(), after CPU clock change..
43 //mp3_init();
1820b5a7 44
45 engineState = PGS_Menu;
46
47 for (;;)
48 {
49 switch (engineState)
50 {
51 case PGS_Menu:
2445b7cb 52#ifndef GPROF
1820b5a7 53 menu_loop();
110df09c 54#else
713c9224 55 strcpy(rom_fname_reload, rom_fname_loaded);
110df09c 56 engineState = PGS_ReloadRom;
57#endif
1820b5a7 58 break;
59
60 case PGS_ReloadRom:
a47dd663 61 if (emu_reload_rom(rom_fname_reload)) {
1820b5a7 62 engineState = PGS_Running;
4b167c12 63 if (mp3_last_error != 0)
64 engineState = PGS_Menu; // send to menu to display mp3 error
65 } else {
1820b5a7 66 lprintf("PGS_ReloadRom == 0\n");
67 engineState = PGS_Menu;
68 }
1820b5a7 69 break;
70
7d0143a2 71 case PGS_Suspending:
2b02d6e5 72 while (engineState == PGS_Suspending)
ea08c296 73 psp_wait_suspend();
2b02d6e5 74 break;
75
76 case PGS_SuspendWake:
77 psp_unhandled_suspend = 0;
78 psp_resume_suspend();
79 emu_HandleResume();
80 engineState = engineStateSuspend;
7d0143a2 81 break;
82
1820b5a7 83 case PGS_RestartRun:
84 engineState = PGS_Running;
85
86 case PGS_Running:
ea08c296 87 if (psp_unhandled_suspend) {
2b02d6e5 88 psp_unhandled_suspend = 0;
ea08c296 89 psp_resume_suspend();
90 emu_HandleResume();
2b02d6e5 91 break;
ea08c296 92 }
f2cf8472 93 pemu_loop();
2445b7cb 94#ifdef GPROF
110df09c 95 goto endloop;
96#endif
1820b5a7 97 break;
98
99 case PGS_Quit:
100 goto endloop;
101
102 default:
103 lprintf("engine got into unknown state (%i), exitting\n", engineState);
104 goto endloop;
105 }
106 }
107
108 endloop:
109
110df09c 110 mp3_deinit();
1820b5a7 111 emu_Deinit();
2445b7cb 112#ifdef GPROF
110df09c 113 gprof_cleanup();
114#endif
2445b7cb 115#ifndef GCOV
1820b5a7 116 psp_finish();
110df09c 117#endif
1820b5a7 118
119 return 0;
120}
121