long PAD__init(long flags) { SysPrintf("start PAD_init()\r\n"); PadFlags |= flags; /* Read Configuration here */ SysPrintf("end PAD_init()\r\n"); return PSE_PAD_ERR_SUCCESS; }
long CDR__close(void) { SysPrintf("start CDR_close()\r\n"); fclose(CD.cd); free(CD.tl); SysPrintf("end CDR_close()\r\n"); return 0; }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd != 1 && mcd != 2) return; if (mcd == 1) { data = Mcd1Data; cardh1[1] |= 8; // mark as new } if (mcd == 2) { data = Mcd2Data; cardh2[1] |= 8; } McdDisable[mcd - 1] = 0; if (str == NULL || strcmp(str, "none") == 0) { McdDisable[mcd - 1] = 1; return; } if (*str == 0) return; f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } }
void emu_on_new_cd(int show_hud_msg) { ClearAllCheats(); parse_cwcheat(); if (Config.HLE) { SysPrintf("note: running with HLE BIOS, expect compatibility problems\n"); SysPrintf("----------------------------------------------------------\n"); } if (show_hud_msg) { snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG); hud_new_msg = 3; } }
long PAD__open(void) { SysPrintf("start PAD1_open()\r\n"); return 0; }
long CDR__open(void) { char str[256]; SysPrintf("start CDR_open()\r\n"); // newCD("/cd/cd.bin"); strcpy(str, CDConfiguration.dn); strcat(str, "/"); strcat(str, CDConfiguration.fn); newCD(str); SysPrintf("end CDR_open()\r\n"); return 0; }
void psxMemReset() { FILE *f = NULL; char Bios[256]; memset(psxM, 0, 0x00200000); memset(psxP, 0, 0x00010000); if(!Config.HLE) { sprintf(Bios, "%s%s", Config.BiosDir, Config.Bios); f = fopen(Bios, "rb"); if (f == NULL) { SysPrintf ("BIOS NOT FOUND: %s", Bios); gp2x_timer_delay(2000); memset(psxR, 0, 0x80000); Config.HLE = 1; } else { fread(psxR, 1, 0x80000, f); fclose(f); } } else { memset(psxR, 0, 0x80000); } }
int SaveStateGz(gzFile f, long* gzsize) { int Size; unsigned char pMemGpuPic[SZ_GPUPIC]; //if (f == NULL) return -1; gzwrite(f, (void *)PcsxrHeader, sizeof(PcsxrHeader)); gzwrite(f, (void *)&SaveVersion, sizeof(u32)); gzwrite(f, (void *)&Config.HLE, sizeof(boolean)); if (gzsize)GPU_getScreenPic(pMemGpuPic); // Not necessary with ephemeral saves gzwrite(f, pMemGpuPic, SZ_GPUPIC); if (Config.HLE) psxBiosFreeze(1); gzwrite(f, psxM, 0x00200000); gzwrite(f, psxR, 0x00080000); gzwrite(f, psxH, 0x00010000); gzwrite(f, (void *)&psxRegs, sizeof(psxRegs)); // gpu if (!gpufP)gpufP = (GPUFreeze_t *)malloc(sizeof(GPUFreeze_t)); gpufP->ulFreezeVersion = 1; GPU_freeze(1, gpufP); gzwrite(f, gpufP, sizeof(GPUFreeze_t)); // SPU Plugin cannot change during run, so we query size info just once per session if (!spufP) { spufP = (SPUFreeze_t *)malloc(offsetof(SPUFreeze_t, SPUPorts)); // only first 3 elements (up to Size) SPU_freeze(2, spufP); Size = spufP->Size; SysPrintf("SPUFreezeSize %i/(%i)\n", Size, offsetof(SPUFreeze_t, SPUPorts)); free(spufP); spufP = (SPUFreeze_t *) malloc(Size); spufP->Size = Size; if (spufP->Size <= 0) { gzclose(f); free(spufP); spufP = NULL; return 1; // error } } // spu gzwrite(f, &(spufP->Size), 4); SPU_freeze(1, spufP); gzwrite(f, spufP, spufP->Size); sioFreeze(f, 1); cdrFreeze(f, 1); psxHwFreeze(f, 1); psxRcntFreeze(f, 1); mdecFreeze(f, 1); if(gzsize)*gzsize = gztell(f); gzclose(f); return 0; }
void psxException(u32 code, u32 bd) { // Set the Cause psxRegs.CP0.n.Cause = (psxRegs.CP0.n.Cause & 0x300) | code; // Set the EPC & PC if (bd) { #ifdef PSXCPU_LOG PSXCPU_LOG("bd set!!!\n"); #endif SysPrintf("bd set!!!\n"); psxRegs.CP0.n.Cause |= 0x80000000; psxRegs.CP0.n.EPC = (psxRegs.pc - 4); } else psxRegs.CP0.n.EPC = (psxRegs.pc); if (psxRegs.CP0.n.Status & 0x400000) psxRegs.pc = 0xbfc00180; else psxRegs.pc = 0x80000080; // Set the Status psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status &~0x3f) | ((psxRegs.CP0.n.Status & 0xf) << 2); if (Config.HLE) psxBiosException(); }
static void __fastcall _rcntTestTarget( int i ) { if( psxCounters[i].count < psxCounters[i].target ) return; PSXCNT_LOG("IOP Counter[%d] target 0x%I64x >= 0x%I64x (mode: %x)\n", i, psxCounters[i].count, psxCounters[i].target, psxCounters[i].mode); if (psxCounters[i].mode & IOPCNT_INT_TARGET) { // Target interrupt if(psxCounters[i].mode & 0x80) psxCounters[i].mode &= ~0x0400; // Interrupt flag psxCounters[i].mode |= 0x0800; // Target flag psxHu32(0x1070) |= psxCounters[i].interrupt; } if (psxCounters[i].mode & 0x08) { // Reset on target psxCounters[i].count -= psxCounters[i].target; if(!(psxCounters[i].mode & 0x40)) { SysPrintf("Counter %x repeat intr not set on zero ret, ignoring target\n", i); psxCounters[i].target |= IOPCNT_FUTURE_TARGET; } } else psxCounters[i].target |= IOPCNT_FUTURE_TARGET; }
void psxRcnt5Wmode(u32 value) { PSXCNT_LOG("IOP Counter[5] writeMode = %lx\n", value); psxCounters[5].mode = value; psxCounters[5].mode|= 0x0400; switch(value & 0x6000) { case 0x0000: psxCounters[5].rate = 1; break; case 0x2000: psxCounters[5].rate = 8; break; case 0x4000: psxCounters[5].rate = 16; break; case 0x6000: psxCounters[5].rate = 256; break; } // Need to set a rate and target if((psxCounters[5].mode & 0x7) == 0x7 || (psxCounters[5].mode & 0x7) == 0x1) { SysPrintf("Gate set on IOP C5, disabling\n"); psxCounters[5].mode |= IOPCNT_STOPPED; } psxCounters[5].count = 0; psxCounters[5].sCycleT = psxRegs.cycle; psxCounters[5].target &= 0xffffffff; _rcntSet( 5 ); }
mem16_t __fastcall _ext_memRead16(u32 mem) { switch (p) { case 1: // hwm return hwRead16(mem); case 2: // psh return psxHwRead16(mem); case 4: // b80 MEM_LOG("b800000 Memory read16 address %x\n", mem); return 0; case 5: // ba0 return ba0R16(mem); case 6: // gsm return gsRead16(mem); case 7: // dev9 { mem16_t retval = DEV9read16(mem & ~0xa4000000); SysPrintf("DEV9 read16 %8.8lx: %4.4lx\n", mem & ~0xa4000000, retval); return retval; } case 8: // spu2 return SPU2read(mem); } MEM_LOG("Unknown Memory read16 from address %8.8x\n", mem); cpuTlbMissR(mem, cpuRegs.branch); return 0; }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; if (*str == 0) { sprintf(str, "%s/.pcsxr/memcards/card%d.mcd", getenv("HOME"), mcd); // TODO: maybe just whine and quit.. SysPrintf(_("No memory card value was specified - using a default card %s\n"), str); } f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } // flag indicating entries have not yet been read (i.e. new card plugged) cardh[1] |= MCDST_CHANGED; }
void ClosePlugins() { int ret; ret = CDR_close(); if (ret < 0) { SysPrintf("Error Closing CDR Plugin\n"); return; } ret = SPU_close(); if (ret < 0) { SysPrintf("Error Closing SPU Plugin\n"); return; } ret = PAD1_close(); if (ret < 0) { SysPrintf("Error Closing PAD1 Plugin\n"); return; } ret = PAD2_close(); if (ret < 0) { SysPrintf("Error Closing PAD2 Plugin\n"); return; } ret = GPU_close(); if (ret < 0) { SysPrintf("Error Closing GPU Plugin\n"); return; } if (Config.UseNet) { NET_pause(); } }
int emu_core_init(void) { SysPrintf("Starting PCSX-ReARMed " REV "\n"); if (EmuInit() == -1) { SysPrintf("PSX emulator couldn't be initialized.\n"); return -1; } LoadMcds(Config.Mcd1, Config.Mcd2); #ifdef DEBUG if (Config.Debug) StartDebugger(); #endif return 0; }
void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; if (*str == 0) { sprintf(str, "memcards/card%d.mcd", mcd); SysPrintf(_("No memory card value was specified - creating a default card %s\n"), str); } f = fopen(str, "rb"); if (f == NULL) { SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); CreateMcd(str); f = fopen(str, "rb"); if (f != NULL) { struct stat buf; if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } else SysMessage(_("Memory card %s failed to load!\n"), str); } else { struct stat buf; SysPrintf(_("Loading memory card %s\n"), str); if (stat(str, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) fseek(f, 3904, SEEK_SET); } fread(data, 1, MCD_SIZE, f); fclose(f); } }
static void PrintTracks(void) { int i; for (i = 1; i <= numtracks; i++) { SysPrintf(_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), i, (ti[i].type == DATA ? "DATA" : "AUDIO"), ti[i].start[0], ti[i].start[1], ti[i].start[2], ti[i].length[0], ti[i].length[1], ti[i].length[2]); } }
int LoadCdromFile(const char *filename, EXE_HEADER *head) { struct iso_directory_record *dir; u8 time[4],*buf; u8 mdir[4096], exename[256]; u32 size, addr; void *psxaddr; if (sscanf(filename, "cdrom:\\%255s", exename) <= 0) { // Some games omit backslash (NFS4) if (sscanf(filename, "cdrom:%255s", exename) <= 0) { SysPrintf("LoadCdromFile: EXE NAME PARSING ERROR (%s (%u))\n", filename, strlen(filename)); exit (1); } } time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); READTRACK(); // skip head and sub, and go to the root directory record dir = (struct iso_directory_record *)&buf[12 + 156]; mmssdd(dir->extent, (char*)time); READDIR(mdir); if (GetCdromFile(mdir, time, exename) == -1) return -1; READTRACK(); memcpy(head, buf + 12, sizeof(EXE_HEADER)); size = head->t_size; addr = head->t_addr; // Cache clear/invalidate dynarec/int. Fixes startup of Casper/X-Files and possibly others. psxCpu->Clear(addr, size / 4); psxRegs.ICache_valid = FALSE; while (size) { incTime(); READTRACK(); psxaddr = (void *)PSXM(addr); assert(psxaddr != NULL); memcpy(psxaddr, buf + 12, 2048); size -= 2048; addr += 2048; } return 0; }
void ResetPlugins() { int ret; CDR_shutdown(); GPU_shutdown(); SPU_shutdown(); PAD1_shutdown(); PAD2_shutdown(); if (Config.UseNet) NET_shutdown(); ret = CDR_init(); if (ret < 0) { SysPrintf("CDRinit error: %d\n", ret); return; } ret = GPU_init(); if (ret < 0) { SysPrintf("GPUinit error: %d\n", ret); return; } ret = SPU_init(); if (ret < 0) { SysPrintf("SPUinit error: %d\n", ret); return; } ret = PAD1_init(1); if (ret < 0) { SysPrintf("PAD1init error: %d\n", ret); return; } ret = PAD2_init(2); if (ret < 0) { SysPrintf("PAD2init error: %d\n", ret); return; } if (Config.UseNet) { ret = NET_init(); if (ret < 0) { SysPrintf("NETinit error: %d\n", ret); return; } } NetOpened = 0; }
int emu_core_init(void) { SysPrintf("Starting PCSX-ReARMed " REV "\n"); #ifndef NO_FRONTEND check_profile(); check_memcards(); #endif if (EmuInit() == -1) { SysPrintf("PSX emulator couldn't be initialized.\n"); return -1; } LoadMcds(Config.Mcd1, Config.Mcd2); if (Config.Debug) { StartDebugger(); } return 0; }
void SysMessage(const char *fmt, ...) { va_list list; char msg[512]; va_start(list, fmt); vsnprintf(msg, sizeof(msg), fmt, list); va_end(list); if (msg[strlen(msg) - 1] == '\n') msg[strlen(msg) - 1] = 0; SysPrintf("%s\n", msg); }
void SysMessage(const char *fmt, ...) { va_list list; char msg[512]; int ret; va_start(list, fmt); ret = vsnprintf(msg, sizeof(msg), fmt, list); va_end(list); if (ret < sizeof(msg) && msg[ret - 1] == '\n') msg[ret - 1] = 0; SysPrintf("%s\n", msg); }
static void hleExecRet() { EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0); SysPrintf("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); psxRegs.GPR.n.ra = header->ret; psxRegs.GPR.n.sp = header->_sp; psxRegs.GPR.n.s8 = header->_fp; psxRegs.GPR.n.gp = header->_gp; psxRegs.GPR.n.s0 = header->base; psxRegs.GPR.n.v0 = 1; psxRegs.pc = psxRegs.GPR.n.ra; }
int LoadPlugins() { long ret; char Plugin[MAXPATHLEN]; ReleasePlugins(); if (UsingIso()) { LoadCDRplugin(NULL); } else { sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr); if (LoadCDRplugin("psx-cdr.dll") == -1) return -1; } sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Gpu); if (LoadGPUplugin("psx-gpu.dll") == -1) return -1; sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Spu); if (LoadSPUplugin("psx-spu.dll") == -1) return -1; sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad1); if (LoadPAD1plugin("psx-pad1.dll") == -1) return -1; sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad2); if (LoadPAD2plugin("psx-pad2.dll") == -1) return -1; #ifdef ENABLE_SIO1API sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Sio1); if (LoadSIO1plugin(Plugin) == -1) return -1; #endif ret = CDR_init(); if (ret < 0) { SysMessage (_("Error initializing CD-ROM plugin: %d"), ret); return -1; } ret = GPU_init(); if (ret < 0) { SysMessage (_("Error initializing GPU plugin: %d"), ret); return -1; } ret = SPU_init(); if (ret < 0) { SysMessage (_("Error initializing SPU plugin: %d"), ret); return -1; } ret = PAD1_init(1); if (ret < 0) { SysMessage (_("Error initializing Controller 1 plugin: %d"), ret); return -1; } ret = PAD2_init(2); if (ret < 0) { SysMessage (_("Error initializing Controller 2 plugin: %d"), ret); return -1; } #ifdef ENABLE_SIO1API ret = SIO1_init(); if (ret < 0) { SysMessage (_("Error initializing SIO1 plugin: %d"), ret); return -1; } #endif SysPrintf("%s", _("Plugins loaded.\n")); return 0; }
void __fastcall _ext_memWrite32(u32 mem, u32 value) { switch (p) { case 2: // psh psxHwWrite32(mem, value); return; case 6: // gsm gsWrite32(mem, value); return; case 7: // dev9 DEV9write32(mem & ~0xa4000000, value); SysPrintf("DEV9 write32 %8.8lx: %8.8lx\n", mem & ~0xa4000000, value); return; } MEM_LOG("Unknown Memory write32 to address %x with data %8.8x\n", mem, value); cpuTlbMissW(mem, cpuRegs.branch); }
void __Log(char *fmt, ...) { va_list list; #ifdef LOG_STDOUT char tmp[1024]; #endif va_start(list, fmt); #ifndef LOG_STDOUT vfprintf(emuLog, fmt, list); #else vsprintf(tmp, fmt, list); SysPrintf(tmp); #endif va_end(list); }
// This function is invoked by the front-end when opening an ISO // file for playback static long CALLBACK ISOopen(void) { u32 modeTest = 0; if (cdHandle != NULL) { return 0; // it's already open } cdHandle = fopen(GetIsoFile(), "rb"); if (cdHandle == NULL) { return -1; } SysPrintf(_("Loaded CD Image: %s"), GetIsoFile()); cddaBigEndian = FALSE; subChanMixed = FALSE; subChanRaw = FALSE; isMode1ISO = FALSE; if (parseccd(GetIsoFile()) == 0) { SysPrintf("[+ccd]"); } else if (parsemds(GetIsoFile()) == 0) { SysPrintf("[+mds]"); } else if (parsecue(GetIsoFile()) == 0) { SysPrintf("[+cue]"); } else if (parsetoc(GetIsoFile()) == 0) { SysPrintf("[+toc]"); } else { //guess whether it is mode1/2048 fseek(cdHandle, 0, SEEK_END); if(ftell(cdHandle) % 2048 == 0) { fseek(cdHandle, 0, SEEK_SET); fread(&modeTest, 4, 1, cdHandle); if(SWAP32(modeTest)!=0xffffff00) isMode1ISO = TRUE; } fseek(cdHandle, 0, SEEK_SET); } if (!subChanMixed && opensubfile(GetIsoFile()) == 0) { SysPrintf("[+sub]"); } SysPrintf(".\n"); PrintTracks(); return 0; }
int LoadSBI(const char *filename) { FILE *sbihandle; char buffer[16], sbifile[MAXPATHLEN]; if (filename == NULL) { if (CdromId[0] == '\0') return -1; // Generate filename in the format of SLUS_123.45.sbi buffer[0] = toupper(CdromId[0]); buffer[1] = toupper(CdromId[1]); buffer[2] = toupper(CdromId[2]); buffer[3] = toupper(CdromId[3]); buffer[4] = '_'; buffer[5] = CdromId[4]; buffer[6] = CdromId[5]; buffer[7] = CdromId[6]; buffer[8] = '.'; buffer[9] = CdromId[7]; buffer[10] = CdromId[8]; buffer[11] = '.'; buffer[12] = 's'; buffer[13] = 'b'; buffer[14] = 'i'; buffer[15] = '\0'; sprintf(sbifile, "%s%s", Config.PatchesDir, buffer); filename = sbifile; } sbihandle = fopen(filename, "rb"); if (sbihandle == NULL) return -1; // init sbicount = 0; // 4-byte SBI header fread(buffer, 1, 4, sbihandle); while (!feof(sbihandle)) { fread(sbitime[sbicount++], 1, 3, sbihandle); fread(buffer, 1, 11, sbihandle); } fclose(sbihandle); SysPrintf(_("Loaded SBI file: %s.\n"), filename); return 0; }
static void CreateMemcard(char *filename, char *conf_mcd) { gchar *mcd; struct stat buf; mcd = g_build_filename(getenv("HOME"), MEMCARD_DIR, filename, NULL); strcpy(conf_mcd, mcd); /* Only create a memory card if an existing one does not exist */ if (stat(mcd, &buf) == -1) { SysPrintf(_("Creating memory card: %s\n"), mcd); CreateMcd(mcd); } g_free (mcd); }
int emu_save_state(int slot) { char fname[MAXPATHLEN]; int ret; ret = get_state_filename(fname, sizeof(fname), slot); if (ret != 0) return ret; ret = SaveState(fname); #if defined(__arm__) && !defined(__ARM_ARCH_7A__) /* XXX GPH hack */ sync(); #endif SysPrintf("* %s \"%s\" [%d]\n", ret == 0 ? "saved" : "failed to save", fname, slot); return ret; }