X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fmain.c;h=6ac16b8f4d8fac53d2d6bce18dad2a1e5393e260;hb=fa8d133192876a802fbac43c0a0bfe4f5f85b682;hp=f21ebd78f3d8f1af96d6ed5c89fcfad989bc0622;hpb=720ee7f6244cb51cc123a7fd16832161db9a3b4d;p=libpicofe.git diff --git a/gp2x/main.c b/gp2x/main.c index f21ebd7..6ac16b8 100644 --- a/gp2x/main.c +++ b/gp2x/main.c @@ -1,48 +1,39 @@ -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2006-2009 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. #include +#include #include -#include #include -#include -#include "gp2x.h" -#include "menu.h" +#include "../common/menu.h" +#include "../common/emu.h" +#include "../common/config.h" +#include "../common/input.h" +#include "../common/plat.h" #include "emu.h" #include "version.h" -#include "squidgehack.h" -#include "cpuctrl.h" - -extern char *ext_menu, *ext_state; -extern int select_exits; extern char *PicoConfigFile; -int mmuhack_status = 0; +static int load_state_slot = -1; char **g_argv; void parse_cmd_line(int argc, char *argv[]) { int x, unrecognized = 0; - for(x = 1; x < argc; x++) + for (x = 1; x < argc; x++) { - if(argv[x][0] == '-') + if (argv[x][0] == '-') { - if(strcasecmp(argv[x], "-menu") == 0) { - if(x+1 < argc) { ++x; ext_menu = argv[x]; } /* External Frontend: Program Name */ - } - else if(strcasecmp(argv[x], "-state") == 0) { - if(x+1 < argc) { ++x; ext_state = argv[x]; } /* External Frontend: Arguments */ + if (strcasecmp(argv[x], "-config") == 0) { + if (x+1 < argc) { ++x; PicoConfigFile = argv[x]; } } - else if(strcasecmp(argv[x], "-config") == 0) { - if(x+1 < argc) { ++x; PicoConfigFile = argv[x]; } - } - else if(strcasecmp(argv[x], "-selectexit") == 0) { - select_exits = 1; + else if (strcasecmp(argv[x], "-loadstate") == 0) { + if (x+1 < argc) { ++x; load_state_slot = atoi(argv[x]); } } else { unrecognized = 1; @@ -51,9 +42,9 @@ void parse_cmd_line(int argc, char *argv[]) } else { /* External Frontend: ROM Name */ FILE *f; - strncpy(romFileName, argv[x], PATH_MAX); - romFileName[PATH_MAX-1] = 0; - f = fopen(romFileName, "rb"); + strncpy(rom_fname_reload, argv[x], sizeof(rom_fname_reload)); + rom_fname_reload[sizeof(rom_fname_reload) - 1] = 0; + f = fopen(rom_fname_reload, "rb"); if (f) fclose(f); else unrecognized = 1; engineState = PGS_ReloadRom; @@ -62,14 +53,11 @@ void parse_cmd_line(int argc, char *argv[]) } if (unrecognized) { - printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006\n"); + printf("\n\n\nPicoDrive v" VERSION " (c) notaz, 2006-2009\n"); printf("usage: %s [options] [romfile]\n", argv[0]); - printf( "options:\n" - "-menu launch a custom program on exit instead of default gp2xmenu\n" - "-state pass '-state param' to the menu program\n" - "-config use specified config file instead of default 'picoconfig.bin'\n" - " see currentConfig_t structure in emu.h for the file format\n" - "-selectexit pressing SELECT will exit the emu and start 'menu_path'\n"); + printf("options:\n" + " -config use specified config file instead of default 'config.cfg'\n" + " -loadstate if ROM is specified, try loading slot \n"); } } @@ -78,29 +66,37 @@ int main(int argc, char *argv[]) { g_argv = argv; - emu_ReadConfig(0); - gp2x_init(); - if (currentConfig.EmuOpt&0x10) { - int ret = mmuhack(); - printf("squidge hack code finished and returned %i\n", ret); fflush(stdout); - mmuhack_status = ret; - } - cpuctrl_init(); - Reset940(1); - Pause940(1); - if (currentConfig.EmuOpt&0x100) { - printf("setting RAM timings.. "); fflush(stdout); - // craigix: --trc 6 --tras 4 --twr 1 --tmrd 1 --trfc 1 --trp 2 --trcd 2 - set_RAM_Timings(6, 4, 1, 1, 1, 2, 2); - printf("done.\n"); fflush(stdout); - } + plat_early_init(); + + /* in_init() must go before config, config accesses in_ fwk */ + in_init(); + emu_prepareDefaultConfig(); + emu_ReadConfig(0, 0); + config_readlrom(PicoConfigFile); + + plat_init(); + in_probe(); + in_debug_dump(); + emu_Init(); + menu_init(); engineState = PGS_Menu; if (argc > 1) parse_cmd_line(argc, argv); + if (engineState == PGS_ReloadRom) + { + if (emu_ReloadRom(rom_fname_reload)) { + engineState = PGS_Running; + if (load_state_slot >= 0) { + state_slot = load_state_slot; + emu_SaveLoadGame(1, 0); + } + } + } + for (;;) { switch (engineState) @@ -110,7 +106,7 @@ int main(int argc, char *argv[]) break; case PGS_ReloadRom: - if (emu_ReloadRom()) + if (emu_ReloadRom(rom_fname_reload)) engineState = PGS_Running; else { printf("PGS_ReloadRom == 0\n"); @@ -118,13 +114,16 @@ int main(int argc, char *argv[]) } break; + case PGS_RestartRun: + engineState = PGS_Running; + case PGS_Running: emu_Loop(); break; case PGS_Quit: goto endloop; - + default: printf("engine got into unknown state (%i), exitting\n", engineState); goto endloop; @@ -134,10 +133,7 @@ int main(int argc, char *argv[]) endloop: emu_Deinit(); - cpuctrl_deinit(); - gp2x_deinit(); - if(mmuhack_status) - mmuunhack(); + plat_finish(); return 0; }