From 80c2304e511b5463b5046f7ff1c49103c786755f Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 17 Nov 2010 01:08:49 +0200 Subject: [PATCH] minimal working gtk-less build ..only works with external plugins --- .gitignore | 3 + Makefile | 28 ++++ frontend/Cheat.h | 1 + frontend/config.h | 8 + frontend/gtk/gtk.h | 13 ++ frontend/main.c | 388 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 441 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 frontend/Cheat.h create mode 100644 frontend/config.h create mode 100644 frontend/gtk/gtk.h create mode 100644 frontend/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3c2904ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +tags +cscope.out diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..8810b266 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +CROSS_COMPILE= +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld + +CFLAGS += -Wall -ggdb -Ifrontend +LDFLAGS += -lz -lpthread -ldl +TARGET = pcsx + +all: $(TARGET) + +# core +OBJS += libpcsxcore/cdriso.o libpcsxcore/cdrom.o libpcsxcore/cheat.o libpcsxcore/debug.o \ + libpcsxcore/decode_xa.o libpcsxcore/disr3000a.o libpcsxcore/gte.o libpcsxcore/mdec.o \ + libpcsxcore/misc.o libpcsxcore/plugins.o libpcsxcore/ppf.o libpcsxcore/psxbios.o \ + libpcsxcore/psxcommon.o libpcsxcore/psxcounters.o libpcsxcore/psxdma.o libpcsxcore/psxhle.o \ + libpcsxcore/psxhw.o libpcsxcore/psxinterpreter.o libpcsxcore/psxmem.o libpcsxcore/r3000a.o \ + libpcsxcore/sio.o libpcsxcore/socket.o libpcsxcore/spu.o +# gui +OBJS += gui/Config.o gui/Plugin.o + +OBJS += frontend/main.o + +$(TARGET): $(OBJS) + $(CC) -o $@ $^ $(LDFLAGS) + +clean: + $(RM) $(TARGET) $(OBJS) + diff --git a/frontend/Cheat.h b/frontend/Cheat.h new file mode 100644 index 00000000..2997587d --- /dev/null +++ b/frontend/Cheat.h @@ -0,0 +1 @@ +/* dummy */ diff --git a/frontend/config.h b/frontend/config.h new file mode 100644 index 00000000..84e40f6a --- /dev/null +++ b/frontend/config.h @@ -0,0 +1,8 @@ +#define MAXPATHLEN 256 +#define NOPSXREC +#define __LINUX__ +#define PACKAGE_NAME "pcsx" +#define PACKAGE_VERSION "1.9" +#define DEF_PLUGIN_DIR "." +#define EMU_LOG printf + diff --git a/frontend/gtk/gtk.h b/frontend/gtk/gtk.h new file mode 100644 index 00000000..a605c82c --- /dev/null +++ b/frontend/gtk/gtk.h @@ -0,0 +1,13 @@ +#ifndef __G_FAKE_TYPES_H__ +#define __G_FAKE_TYPES_H__ + +/* fake gtk types to avoid code drift from upstream PCSX */ +typedef char gchar; +typedef short gshort; +typedef long glong; +typedef int gint; +typedef gint gboolean; + +#define g_free free + +#endif diff --git a/frontend/main.c b/frontend/main.c new file mode 100644 index 00000000..28446d34 --- /dev/null +++ b/frontend/main.c @@ -0,0 +1,388 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../gui/Linux.h" +#include "../libpcsxcore/misc.h" + +int UseGui; + +static void make_path(char *buf, size_t size, const char *dir, const char *fname) +{ + if (fname) + snprintf(buf, size, ".%s%s", dir, fname); + else + snprintf(buf, size, ".%s", dir); +} +#define MAKE_PATH(buf, dir, fname) \ + make_path(buf, sizeof(buf), dir, fname) + +static void create_profile_dir(const char *directory) { + char path[MAXPATHLEN]; + + MAKE_PATH(path, directory, NULL); + mkdir(path, S_IRWXU | S_IRWXG); +} + +static void CheckSubDir() { + // make sure that ~/.pcsx exists + create_profile_dir(PCSX_DOT_DIR); + + create_profile_dir(BIOS_DIR); + create_profile_dir(MEMCARD_DIR); + create_profile_dir(STATES_DIR); + create_profile_dir(PLUGINS_DIR); + create_profile_dir(PLUGINS_CFG_DIR); + create_profile_dir(CHEATS_DIR); + create_profile_dir(PATCHES_DIR); +} + +static void CreateMemcard(char *filename, char *conf_mcd) { + struct stat buf; + + make_path(conf_mcd, MAXPATHLEN, MEMCARD_DIR, filename); + + /* Only create a memory card if an existing one does not exist */ + if (stat(conf_mcd, &buf) == -1) { + SysPrintf(_("Creating memory card: %s\n"), conf_mcd); + CreateMcd(conf_mcd); + } +} + +int main(int argc, char *argv[]) +{ + char file[MAXPATHLEN] = ""; + char path[MAXPATHLEN]; + int runcd = 0; + int loadst = 0; + int i; + + // what is the name of the config file? + // it may be redefined by -cfg on the command line + strcpy(cfgfile_basename, "pcsx.cfg"); + + SetIsoFile(NULL); + Config.PsxOut = 1; + + // read command line options + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-nogui")) UseGui = FALSE; + else if (!strcmp(argv[i], "-psxout")) Config.PsxOut = 1; + else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]); + else if (!strcmp(argv[i], "-cfg")) { + if (i+1 >= argc) break; + strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */ + printf("Using config file %s.\n", cfgfile_basename); + } + else if (!strcmp(argv[i], "-cdfile")) { + char isofilename[MAXPATHLEN]; + + if (i+1 >= argc) break; + strncpy(isofilename, argv[++i], MAXPATHLEN); + if (isofilename[0] != '/') { + getcwd(path, MAXPATHLEN); + if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) { + strcat(path, "/"); + strcat(path, isofilename); + strcpy(isofilename, path); + } else + isofilename[0] = 0; + } + + SetIsoFile(isofilename); + runcd = 1; + } + else if (!strcmp(argv[i], "-h") || + !strcmp(argv[i], "-help") || + !strcmp(argv[i], "--help")) { + printf(PACKAGE_NAME " " PACKAGE_VERSION "\n"); + printf("%s\n", _( + " pcsx [options] [file]\n" + "\toptions:\n" + "\t-cdfile FILE\tRuns a CD image file\n" + "\t-nogui\t\tDon't open the GTK GUI\n" + "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n" + "\t-psxout\t\tEnable PSX output\n" + "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n" + "\t-h -help\tDisplay this message\n" + "\tfile\t\tLoads file\n")); + return 0; + } else { + strncpy(file, argv[i], MAXPATHLEN); + if (file[0] != '/') { + getcwd(path, MAXPATHLEN); + if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) { + strcat(path, "/"); + strcat(path, file); + strcpy(file, path); + } else + file[0] = 0; + } + } + } + + memset(&Config, 0, sizeof(PcsxConfig)); + strcpy(Config.Net, "Disabled"); + + CheckSubDir(); +// ScanAllPlugins(); + + // try to load config + // if the config file doesn't exist + if (LoadConfig() == -1) { + // Uh oh, no config file found, use some defaults + Config.PsxAuto = 1; + + snprintf(Config.BiosDir, sizeof(Config.BiosDir), "." BIOS_DIR); + snprintf(Config.PluginsDir, sizeof(Config.PluginsDir), "." PLUGINS_DIR); + + // Update available plugins, but not GUI + //UpdatePluginsBIOS(); + + // Pick some defaults, if they're available +/* + set_default_plugin(GpuConfS.plist[0], Config.Gpu); + set_default_plugin(SpuConfS.plist[0], Config.Spu); + set_default_plugin(CdrConfS.plist[0], Config.Cdr); + set_default_plugin(Pad1ConfS.plist[0], Config.Pad1); + set_default_plugin(Pad2ConfS.plist[0], Config.Pad2); + set_default_plugin(BiosConfS.plist[0], Config.Bios); +*/ + // create & load default memcards if they don't exist + CreateMemcard("card1.mcd", Config.Mcd1); + CreateMemcard("card2.mcd", Config.Mcd2); + + LoadMcds(Config.Mcd1, Config.Mcd2); + + SaveConfig(); + } + + snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR); +/* + // switch to plugin dotdir + // this lets plugins work without modification! + gchar *plugin_default_dir = g_build_filename(getenv("HOME"), PLUGINS_DIR, NULL); + chdir(plugin_default_dir); + g_free(plugin_default_dir); +*/ + if (SysInit() == -1) return 1; + + // if !gui + { + // the following only occurs if the gui isn't started + if (LoadPlugins() == -1) { + SysMessage("Failed loading plugins!"); + return 1; + } + + if (OpenPlugins() == -1) { + return 1; + } + + SysReset(); + CheckCdrom(); + + if (file[0] != '\0') { + Load(file); + } else { + if (runcd) { + if (LoadCdrom() == -1) { + ClosePlugins(); + printf(_("Could not load CD-ROM!\n")); + return -1; + } + } + } + + // If a state has been specified, then load that + if (loadst) { + StatesC = loadst - 1; + char *state_filename = get_state_filename(StatesC); + LoadState(state_filename); + free(state_filename); + } + + psxCpu->Execute(); + } + + return 0; +} + +int SysInit() { + emuLog = stdout; + + if (EmuInit() == -1) { + printf("PSX emulator couldn't be initialized.\n"); + return -1; + } + + LoadMcds(Config.Mcd1, Config.Mcd2); /* TODO Do we need to have this here, or in the calling main() function?? */ + + if (Config.Debug) { + StartDebugger(); + } + + return 0; +} + +void SysRunGui() { + printf("SysRunGui\n"); +} + +void StartGui() { + printf("StartGui\n"); +} + +void SysReset() { + EmuReset(); +} + +void SysClose() { + EmuShutdown(); + ReleasePlugins(); + + StopDebugger(); + + if (emuLog != NULL) fclose(emuLog); +} + +void SysUpdate() { + PADhandleKey(PAD1_keypressed()); + PADhandleKey(PAD2_keypressed()); +} + +void UpdateMenuSlots() { +} + +void OnFile_Exit() { + printf("OnFile_Exit\n"); + exit(0); +} + +void state_save(gchar *state_filename) { + char Text[MAXPATHLEN + 20]; + + GPU_updateLace(); + + if (SaveState(state_filename) == 0) + sprintf(Text, _("Saved state %s."), state_filename); + else + sprintf(Text, _("Error saving state %s!"), state_filename); + + GPU_displayText(Text); +} + +void state_load(gchar *state_filename) { + int ret; + char Text[MAXPATHLEN + 20]; + FILE *fp; + + // check if the state file actually exists + fp = fopen(state_filename, "rb"); + if (fp == NULL) { + // file does not exist + return; + } + + fclose(fp); + + ret = CheckState(state_filename); + + if (ret == 0) { + SysReset(); + ret = LoadState(state_filename); + } + + if (ret == 0) { + // Check the CD-ROM is valid + if (CheckCdrom() == -1) { + ClosePlugins(); + SysRunGui(); + return; + } + + sprintf(Text, _("Loaded state %s."), state_filename); + } else { + sprintf(Text, _("Error loading state %s!"), state_filename); + } + GPU_displayText(Text); +} + +char *get_state_filename(int i) { + char SStateFile[256]; + char trimlabel[33]; + int j; + + strncpy(trimlabel, CdromLabel, 32); + trimlabel[32] = 0; + for (j = 31; j >= 0; j--) + if (trimlabel[j] == ' ') + trimlabel[j] = 0; + else + continue; + + snprintf(SStateFile, sizeof(SStateFile), "." STATES_DIR "%.32s-%.9s.%3.3d", + trimlabel, CdromId, i); + + return strdup(SStateFile); +} + +void SysPrintf(const char *fmt, ...) { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (Config.PsxOut) { + static char linestart = 1; + int l = strlen(msg); + + printf(linestart ? " * %s" : "%s", msg); + + if (l > 0 && msg[l - 1] == '\n') { + linestart = 1; + } else { + linestart = 0; + } + } + + fprintf(emuLog, "%s", msg); +} + +void SysMessage(const char *fmt, ...) { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + if (msg[strlen(msg) - 1] == '\n') + msg[strlen(msg) - 1] = 0; + + fprintf(stderr, "%s\n", msg); +} + +void *SysLoadLibrary(const char *lib) { + return dlopen(lib, RTLD_NOW); +} + +void *SysLoadSym(void *lib, const char *sym) { + return dlsym(lib, sym); +} + +const char *SysLibError() { + return dlerror(); +} + +void SysCloseLibrary(void *lib) { + dlclose(lib); +} + + -- 2.39.5