further unification and refactoring

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@710 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-07-23 20:06:18 +00:00
parent 71769e27e9
commit 93c18cb44b
11 changed files with 187 additions and 306 deletions

View file

@ -16,6 +16,7 @@
#include "config.h"
#include "plat.h"
#include "input.h"
#include "posix.h"
#include <pico/pico_int.h>
#include <pico/patch.h>
@ -34,6 +35,7 @@ char *PicoConfigFile = "config.cfg";
currentConfig_t currentConfig, defaultConfig;
int state_slot = 0;
int config_slot = 0, config_slot_current = 0;
int pico_pen_x = 320/2, pico_pen_y = 240/2;
int pico_inp_mode = 0;
int engineState = PGS_Menu;
@ -41,6 +43,7 @@ int engineState = PGS_Menu;
char rom_fname_reload[512] = { 0, };
char rom_fname_loaded[512] = { 0, };
int rom_loaded = 0;
int reset_timing = 0;
unsigned char *movie_data = NULL;
static int movie_size = 0;
@ -109,7 +112,7 @@ int emu_findBios(int region, char **bios_file)
for (i = 0; i < count; i++)
{
emu_getMainDir(bios_path, sizeof(bios_path));
plat_get_root_dir(bios_path, sizeof(bios_path));
strcat(bios_path, files[i]);
strcat(bios_path, ".bin");
f = fopen(bios_path, "rb");
@ -519,7 +522,7 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext)
for (; p >= rom_fname_loaded && *p != PATH_SEP_C; p--); p++;
*dst = 0;
if (prefix) {
int len = emu_getMainDir(dst, 512);
int len = plat_get_root_dir(dst, 512);
strcpy(dst + len, prefix);
prefix_len = len + strlen(prefix);
}
@ -536,7 +539,7 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext)
static void make_config_cfg(char *cfg)
{
int len;
len = emu_getMainDir(cfg, 512);
len = plat_get_root_dir(cfg, 512);
strncpy(cfg + len, PicoConfigFile, 512-6-1-len);
if (config_slot != 0)
{
@ -957,9 +960,22 @@ void emu_changeFastForward(int set_on)
}
}
void emu_RunEventsPico(unsigned int events)
static void emu_msg_tray_open(void)
{
if (events & (1 << 3)) {
plat_status_msg("CD tray opened");
}
void emu_reset_game(void)
{
PicoReset();
reset_timing = 1;
}
void run_events_pico(unsigned int events)
{
int lim_x;
if (events & PEV_PICO_SWINP) {
pico_inp_mode++;
if (pico_inp_mode > 2)
pico_inp_mode = 0;
@ -971,18 +987,44 @@ void emu_RunEventsPico(unsigned int events)
break;
}
}
if (events & (1 << 4)) {
if (events & PEV_PICO_PPREV) {
PicoPicohw.page--;
if (PicoPicohw.page < 0)
PicoPicohw.page = 0;
plat_status_msg("Page %i", PicoPicohw.page);
}
if (events & (1 << 5)) {
if (events & PEV_PICO_PNEXT) {
PicoPicohw.page++;
if (PicoPicohw.page > 6)
PicoPicohw.page = 6;
plat_status_msg("Page %i", PicoPicohw.page);
}
if (pico_inp_mode == 0)
return;
/* handle other input modes */
if (PicoPad[0] & 1) pico_pen_y--;
if (PicoPad[0] & 2) pico_pen_y++;
if (PicoPad[0] & 4) pico_pen_x--;
if (PicoPad[0] & 8) pico_pen_x++;
PicoPad[0] &= ~0x0f; // release UDLR
lim_x = (Pico.video.reg[12]&1) ? 319 : 255;
if (pico_pen_y < 8)
pico_pen_y = 8;
if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)
pico_pen_y = 224 - PICO_PEN_ADJUST_Y;
if (pico_pen_x < 0)
pico_pen_x = 0;
if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
pico_pen_x = lim_x - PICO_PEN_ADJUST_X;
PicoPicohw.pen_pos[0] = pico_pen_x;
if (!(Pico.video.reg[12] & 1))
PicoPicohw.pen_pos[0] += pico_pen_x / 4;
PicoPicohw.pen_pos[0] += 0x3c;
PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
}
static void do_turbo(int *pad, int acts)
@ -1009,7 +1051,7 @@ static void do_turbo(int *pad, int acts)
*pad |= turbo_pad & (acts >> 8);
}
static void run_ui_events(unsigned int which)
static void run_events_ui(unsigned int which)
{
if (which & (PEV_STATE_LOAD|PEV_STATE_SAVE))
{
@ -1096,18 +1138,58 @@ void emu_update_input(void)
if ((events ^ prevEvents) & PEV_FF) {
emu_changeFastForward(events & PEV_FF);
plat_update_volume(0, 0);
// reset_timing = 1;
reset_timing = 1;
}
events &= ~prevEvents;
// TODO if (PicoAHW == PAHW_PICO)
// RunEventsPico(events);
if (PicoAHW == PAHW_PICO)
run_events_pico(events);
if (events)
run_ui_events(events);
run_events_ui(events);
if (movie_data)
update_movie();
prevEvents = (allActions[0] | allActions[1]) & PEV_MASK;
}
static void mkdir_path(char *path_with_reserve, int pos, const char *name)
{
strcpy(path_with_reserve + pos, name);
if (plat_is_dir(path_with_reserve))
return;
if (mkdir(path_with_reserve, 0777) < 0)
lprintf("failed to create: %s\n", path_with_reserve);
}
void emu_init(void)
{
char dir[256];
int pos;
/* make dirs for saves */
pos = plat_get_root_dir(dir, sizeof(dir) - 4);
mkdir_path(dir, pos, "mds");
mkdir_path(dir, pos, "srm");
mkdir_path(dir, pos, "brm");
PicoInit();
PicoMessage = plat_status_msg_busy_next;
PicoMCDopenTray = emu_msg_tray_open;
PicoMCDcloseTray = menu_loop_tray;
}
void emu_finish(void)
{
// save SRAM
if ((currentConfig.EmuOpt & EOPT_USE_SRAM) && SRam.changed) {
emu_SaveLoadGame(0, 1);
SRam.changed = 0;
}
if (!(currentConfig.EmuOpt & EOPT_NO_AUTOSVCFG))
emu_writelrom();
PicoExit();
}

View file

@ -71,6 +71,11 @@ extern int rom_loaded;
extern int state_slot;
extern int config_slot, config_slot_current;
extern unsigned char *movie_data;
extern int reset_timing;
#define PICO_PEN_ADJUST_X 4
#define PICO_PEN_ADJUST_Y 2
extern int pico_pen_x, pico_pen_y;
extern int pico_inp_mode;
extern char rom_fname_reload[512]; // ROM to try loading on next PGS_ReloadRom
@ -91,8 +96,12 @@ enum TPicoGameState {
};
void emu_init(void);
void emu_finish(void);
int emu_ReloadRom(char *rom_fname);
int emu_SaveLoadGame(int load, int sram);
void emu_reset_game(void);
int emu_ReadConfig(int game, int no_defaults);
int emu_WriteConfig(int game);

View file

@ -26,6 +26,9 @@
#define PEVB_SSLOT_NEXT 24
#define PEVB_MENU 23
#define PEVB_FF 22
#define PEVB_PICO_PNEXT 21
#define PEVB_PICO_PPREV 20
#define PEVB_PICO_SWINP 19
#define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN)
#define PEV_VOL_UP (1 << PEVB_VOL_UP)
@ -36,8 +39,11 @@
#define PEV_SSLOT_NEXT (1 << PEVB_SSLOT_NEXT)
#define PEV_MENU (1 << PEVB_MENU)
#define PEV_FF (1 << PEVB_FF)
#define PEV_PICO_PNEXT (1 << PEVB_PICO_PNEXT)
#define PEV_PICO_PPREV (1 << PEVB_PICO_PPREV)
#define PEV_PICO_SWINP (1 << PEVB_PICO_SWINP)
#define PEV_MASK 0x7fc00000
#define PEV_MASK 0x7ff80000
enum {

View file

@ -69,7 +69,7 @@ int main(int argc, char *argv[])
/* in_init() must go before config, config accesses in_ fwk */
in_init();
emu_prepareDefaultConfig();
pemu_prep_defconfig();
emu_ReadConfig(0, 0);
config_readlrom(PicoConfigFile);
@ -77,7 +77,7 @@ int main(int argc, char *argv[])
in_probe();
in_debug_dump();
emu_Init();
emu_init();
menu_init();
engineState = PGS_Menu;
@ -117,7 +117,7 @@ int main(int argc, char *argv[])
engineState = PGS_Running;
case PGS_Running:
emu_Loop();
pemu_loop();
break;
case PGS_Quit:
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
endloop:
emu_Deinit();
emu_finish();
plat_finish();
return 0;

View file

@ -997,7 +997,7 @@ static void draw_savestate_bg(int slot)
}
/* do a frame and fetch menu bg */
emu_forcedFrame(POPT_EN_SOFTSCALE);
pemu_forced_frame(POPT_EN_SOFTSCALE);
plat_video_menu_enter(1);
memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
@ -1286,18 +1286,18 @@ me_bind_action me_ctrl_actions[15] =
// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
me_bind_action emuctrl_actions[] =
{
{ "Load State ", 1 << PEVB_STATE_LOAD },
{ "Save State ", 1 << PEVB_STATE_SAVE },
{ "Prev Save Slot ", 1 << PEVB_SSLOT_PREV },
{ "Next Save Slot ", 1 << PEVB_SSLOT_NEXT },
{ "Switch Renderer ", 1 << PEVB_SWITCH_RND },
{ "Volume Down ", 1 << PEVB_VOL_DOWN },
{ "Volume Up ", 1 << PEVB_VOL_UP },
{ "Fast forward ", 1 << PEVB_FF },
{ "Enter Menu ", 1 << PEVB_MENU },
{ "Pico Next page ", 1 << 21 }, /* TODO */
{ "Pico Prev page ", 1 << 20 },
{ "Pico Switch input", 1 << 19 },
{ "Load State ", PEV_STATE_LOAD },
{ "Save State ", PEV_STATE_SAVE },
{ "Prev Save Slot ", PEV_SSLOT_PREV },
{ "Next Save Slot ", PEV_SSLOT_NEXT },
{ "Switch Renderer ", PEV_SWITCH_RND },
{ "Volume Down ", PEV_VOL_DOWN },
{ "Volume Up ", PEV_VOL_UP },
{ "Fast forward ", PEV_FF },
{ "Enter Menu ", PEV_MENU },
{ "Pico Next page ", PEV_PICO_PNEXT },
{ "Pico Prev page ", PEV_PICO_PPREV },
{ "Pico Switch input", PEV_PICO_SWINP },
{ NULL, 0 }
};
@ -1727,17 +1727,17 @@ extern void SekStepM68k(void);
static void mplayer_loop(void)
{
emu_startSound();
pemu_sound_start();
while (1)
{
PDebugZ80Frame();
if (in_menu_wait_any(0) & PBTN_MA3)
break;
emu_waitSound();
pemu_sound_wait();
}
emu_endSound();
pemu_sound_stop();
}
static void draw_text_debug(const char *str, int skip, int from)
@ -1776,7 +1776,7 @@ static void draw_frame_debug(void)
if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
emu_forcedFrame(0);
pemu_forced_frame(0);
smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xffff);
smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff);
}
@ -1793,7 +1793,7 @@ static void debug_menu_loop(void)
{
case 0: plat_video_menu_begin();
tmp = PDebugMain();
emu_platformDebugCat(tmp);
plat_debug_cat(tmp);
draw_text_debug(tmp, 0, 0);
if (dumped) {
smalltext_out16(g_screen_width - 6 * me_sfont_h,
@ -1803,7 +1803,7 @@ static void debug_menu_loop(void)
break;
case 1: draw_frame_debug(); break;
case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);
emu_forcedFrame(0);
pemu_forced_frame(0);
menu_darken_bg(g_screen_ptr, g_screen_width * g_screen_height, 0);
PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width +
g_screen_width/2 - 320/2, g_screen_width); break;
@ -1896,7 +1896,7 @@ static int main_menu_handler(menu_id id, int keys)
break;
case MA_MAIN_RESET_GAME:
if (rom_loaded) {
emu_ResetGame();
emu_reset_game();
return 1;
}
break;

View file

@ -4,20 +4,14 @@ extern "C" {
/* stuff to be implemented by platform code */
extern char cpu_clk_name[];
/* TODO rename all these */
extern const char * const keyNames[]; // TODO rm
void emu_prepareDefaultConfig(void);
void emu_platformDebugCat(char *str);
void emu_forcedFrame(int opts);
void emu_startSound(void);
void emu_endSound(void);
void emu_waitSound(void);
void emu_ResetGame(void); // TODO mv rm?
void emu_Init(void);
void emu_Deinit(void);
void emu_Loop(void);
int emu_getMainDir(char *dst, int len);
void pemu_prep_defconfig(void);
void pemu_loop(void);
void pemu_forced_frame(int opts);
void pemu_sound_start(void);
void pemu_sound_stop(void);
void pemu_sound_wait(void);
void menu_romload_prepare(const char *rom_name);
void menu_romload_end(void);
@ -25,6 +19,9 @@ void plat_early_init(void);
void plat_init(void);
void plat_finish(void);
/* return the dir/ where configs, saves, bios, etc. are found */
int plat_get_root_dir(char *dst, int len);
/* to be used while emulation is starting or running */
void plat_status_msg(const char *format, ...);
@ -49,6 +46,7 @@ void plat_sleep_ms(int ms);
unsigned int plat_get_ticks_ms(void);
const char *plat_get_credits(void);
void plat_debug_cat(char *str);
#ifdef __cplusplus
} // extern "C"