extend mmap wrapper functionality
[libpicofe.git] / psp / main.c
CommitLineData
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"
8a091e48 13#include "../common/config.h"
2951214e 14#include "../common/lprintf.h"
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
24void dummy(void)
2951214e 25{
049a6b3e 26 engineState = atoi(rom_fname_reload);
fe9e3b25 27 setbuf(NULL, NULL);
28 getenv(NULL);
29}
30#endif
a6df06b7 31
93c0d147 32int pico_main(void)
fe9e3b25 33{
2951214e 34 psp_init();
bf7e9c61 35
960a8e27 36 emu_prepareDefaultConfig();
703e4c7b 37 emu_ReadConfig(0, 0);
bf7e9c61 38 config_readlrom(PicoConfigFile);
39
2951214e 40 emu_Init();
41 menu_init();
fe9e3b25 42 // moved to emu_Loop(), after CPU clock change..
43 //mp3_init();
2951214e 44
45 engineState = PGS_Menu;
46
47 for (;;)
48 {
49 switch (engineState)
50 {
51 case PGS_Menu:
93c0d147 52#ifndef GPROF
2951214e 53 menu_loop();
fe9e3b25 54#else
049a6b3e 55 strcpy(rom_fname_reload, rom_fname_loaded);
fe9e3b25 56 engineState = PGS_ReloadRom;
57#endif
2951214e 58 break;
59
60 case PGS_ReloadRom:
ee0f881e 61 if (emu_reload_rom(rom_fname_reload)) {
2951214e 62 engineState = PGS_Running;
a6df06b7 63 if (mp3_last_error != 0)
64 engineState = PGS_Menu; // send to menu to display mp3 error
65 } else {
2951214e 66 lprintf("PGS_ReloadRom == 0\n");
67 engineState = PGS_Menu;
68 }
2951214e 69 break;
70
426ecc58 71 case PGS_Suspending:
dfa8d77a 72 while (engineState == PGS_Suspending)
677b5dd8 73 psp_wait_suspend();
dfa8d77a 74 break;
75
76 case PGS_SuspendWake:
77 psp_unhandled_suspend = 0;
78 psp_resume_suspend();
79 emu_HandleResume();
80 engineState = engineStateSuspend;
426ecc58 81 break;
82
2951214e 83 case PGS_RestartRun:
84 engineState = PGS_Running;
85
86 case PGS_Running:
677b5dd8 87 if (psp_unhandled_suspend) {
dfa8d77a 88 psp_unhandled_suspend = 0;
677b5dd8 89 psp_resume_suspend();
90 emu_HandleResume();
dfa8d77a 91 break;
677b5dd8 92 }
93c18cb4 93 pemu_loop();
93c0d147 94#ifdef GPROF
fe9e3b25 95 goto endloop;
96#endif
2951214e 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
fe9e3b25 110 mp3_deinit();
2951214e 111 emu_Deinit();
93c0d147 112#ifdef GPROF
fe9e3b25 113 gprof_cleanup();
114#endif
93c0d147 115#ifndef GCOV
2951214e 116 psp_finish();
fe9e3b25 117#endif
2951214e 118
119 return 0;
120}
121