summaryrefslogtreecommitdiff
path: root/libpcsxcore/misc.c
diff options
context:
space:
mode:
authorSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2010-09-26 01:39:01 +0000
committerSND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2010-09-26 01:39:01 +0000
commit2ac114fd69d0b748d3cf527b49cc152b6c141483 (patch)
tree93f578cfa75ac03a6a4e13bf6524e539c528eab0 /libpcsxcore/misc.c
parent60cf0fcf61b20eed515819ecfd302c208ba88e57 (diff)
downloadpcsxr-2ac114fd69d0b748d3cf527b49cc152b6c141483.tar.gz
coff binary support (experimental).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@57729 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'libpcsxcore/misc.c')
-rw-r--r--libpcsxcore/misc.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c
index ef315214..349e4543 100644
--- a/libpcsxcore/misc.c
+++ b/libpcsxcore/misc.c
@@ -390,7 +390,10 @@ static void LoadLibPS() {
int Load(const char *ExePath) {
FILE *tmpFile;
EXE_HEADER tmpHead;
- int type;
+ FILHDR coffHead;
+ AOUTHDR optHead;
+ SCNHDR section;
+ int type, i;
int retval = 0;
u8 opcode;
u32 section_address, section_size;
@@ -408,9 +411,9 @@ int Load(const char *ExePath) {
type = PSXGetFileType(tmpFile);
switch (type) {
case PSX_EXE:
- fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile);
+ fread(&tmpHead, sizeof(EXE_HEADER), 1, tmpFile);
fseek(tmpFile, 0x800, SEEK_SET);
- fread((void *)PSXM(SWAP32(tmpHead.t_addr)), SWAP32(tmpHead.t_size),1,tmpFile);
+ fread(PSXM(SWAP32(tmpHead.t_addr)), SWAP32(tmpHead.t_size), 1, tmpFile);
fclose(tmpFile);
psxRegs.pc = SWAP32(tmpHead.pc0);
psxRegs.GPR.n.gp = SWAP32(tmpHead.gp0);
@@ -419,6 +422,7 @@ int Load(const char *ExePath) {
psxRegs.GPR.n.sp = 0x801fff00;
retval = 0;
break;
+
case CPE_EXE:
fseek(tmpFile, 6, SEEK_SET); /* Something tells me we should go to 4 and read the "08 00" here... */
do {
@@ -448,10 +452,27 @@ int Load(const char *ExePath) {
}
} while (opcode != 0 && retval == 0);
break;
+
case COFF_EXE:
- SysPrintf(_("COFF files not supported.\n"));
- retval = -1;
+ fread(&coffHead, sizeof(coffHead), 1, tmpFile);
+ fread(&optHead, sizeof(optHead), 1, tmpFile);
+
+ psxRegs.pc = SWAP32(optHead.entry);
+ psxRegs.GPR.n.sp = 0x801fff00;
+
+ for (i = 0; i < SWAP16(coffHead.f_nscns); i++) {
+ fseek(tmpFile, sizeof(FILHDR) + SWAP16(coffHead.f_opthdr) + sizeof(section) * i, SEEK_SET);
+ fread(&section, sizeof(section), 1, tmpFile);
+
+ if (section.s_scnptr != 0) {
+ fseek(tmpFile, SWAP32(section.s_scnptr), SEEK_SET);
+ fread(PSXM(SWAP32(section.s_paddr)), SWAP32(section.s_size), 1, tmpFile);
+ } else {
+ memset(PSXM(SWAP32(section.s_paddr)), 0, SWAP32(section.s_size));
+ }
+ }
break;
+
case INVALID_EXE:
SysPrintf(_("This file does not appear to be a valid PSX file.\n"));
retval = -1;