*/
#include <stddef.h>
+#include <assert.h>
#include "misc.h"
#include "cdrom.h"
#include "mdec.h"
0x02000000, 0x00000000, 0x01ff03ff,
};
-static void fake_bios_gpu_setup(void)
+void BiosLikeGPUSetup()
{
int i;
GPU_writeData(gpu_data_def[i]);
}
+static void SetBootRegs(u32 pc, u32 gp, u32 sp)
+{
+ //printf("%s %08x %08x %08x\n", __func__, pc, gp, sp);
+ psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
+
+ psxRegs.pc = pc;
+ psxRegs.GPR.n.gp = gp;
+ psxRegs.GPR.n.sp = sp ? sp : 0x801fff00;
+
+ psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);
+}
+
+void BiosBootBypass() {
+ assert(psxRegs.pc == 0x80030000);
+
+ // skip BIOS logos and region check
+ psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
+ psxRegs.pc = psxRegs.GPR.n.ra;
+}
+
int LoadCdrom() {
EXE_HEADER tmpHead;
struct iso_directory_record *dir;
u8 mdir[4096];
char exename[256];
- // not the best place to do it, but since BIOS boot logo killer
- // is just below, do it here
- fake_bios_gpu_setup();
-
- if (!Config.HLE && !Config.SlowBoot) {
- // skip BIOS logos
- psxRegs.pc = psxRegs.GPR.n.ra;
- return 0;
+ if (!Config.HLE) {
+ if (!BiosBooted) return 0; // custom BIOS
+ if (psxRegs.pc != 0x80030000) return 0; // BiosBootBypass'ed
+ if (Config.SlowBoot) return 0;
}
time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10);
if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") == -1) {
// if SYSTEM.CNF is missing, start an existing PSX.EXE
if (GetCdromFile(mdir, time, "PSX.EXE;1") == -1) return -1;
+ strcpy(exename, "PSX.EXE;1");
READTRACK();
}
memcpy(&tmpHead, buf + 12, sizeof(EXE_HEADER));
- psxRegs.pc = SWAP32(tmpHead.pc0);
- psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
- psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
- if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00;
+ SysPrintf("manual booting '%s'\n", exename);
+ SetBootRegs(SWAP32(tmpHead.pc0), SWAP32(tmpHead.gp0), SWAP32(tmpHead.s_addr));
tmpHead.t_size = SWAP32(tmpHead.t_size);
tmpHead.t_addr = SWAP32(tmpHead.t_addr);
fread_to_ram(mem, section_size, 1, tmpFile);
psxCpu->Clear(section_address, section_size / 4);
}
- psxRegs.pc = SWAP32(tmpHead.pc0);
- psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
- psxRegs.GPR.n.sp = SWAP32(tmpHead.s_addr);
- if (psxRegs.GPR.n.sp == 0)
- psxRegs.GPR.n.sp = 0x801fff00;
+ SetBootRegs(SWAP32(tmpHead.pc0), SWAP32(tmpHead.gp0),
+ SWAP32(tmpHead.s_addr));
retval = 0;
break;
case CPE_EXE:
int SaveState(const char *file) {
void *f;
GPUFreeze_t *gpufP;
+ SPUFreezeHdr_t *spufH;
SPUFreeze_t *spufP;
int Size;
unsigned char *pMem;
f = SaveFuncs.open(file, "wb");
if (f == NULL) return -1;
- new_dyna_before_save();
+ psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
SaveFuncs.write(f, (void *)PcsxHeader, 32);
SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32));
free(gpufP);
// spu
- spufP = (SPUFreeze_t *) malloc(16);
- SPU_freeze(2, spufP, psxRegs.cycle);
- Size = spufP->Size; SaveFuncs.write(f, &Size, 4);
- free(spufP);
+ spufH = malloc(sizeof(*spufH));
+ SPU_freeze(2, (SPUFreeze_t *)spufH, psxRegs.cycle);
+ Size = spufH->Size; SaveFuncs.write(f, &Size, 4);
+ free(spufH);
spufP = (SPUFreeze_t *) malloc(Size);
SPU_freeze(1, spufP, psxRegs.cycle);
SaveFuncs.write(f, spufP, Size);
SaveFuncs.close(f);
- new_dyna_after_save();
-
return 0;
}
if (Config.HLE)
psxBiosInit();
- psxCpu->Reset();
SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR);
-
SaveFuncs.read(f, psxM, 0x00200000);
SaveFuncs.read(f, psxR, 0x00080000);
SaveFuncs.read(f, psxH, 0x00010000);
SaveFuncs.read(f, &psxRegs, offsetof(psxRegisters, gteBusyCycle));
psxRegs.gteBusyCycle = psxRegs.cycle;
+ psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);
+
if (Config.HLE)
psxBiosFreeze(0);
SysClose(); return -1;
}
psxCpu->Reset();
+ psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);
}
return 0;