Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/attic/PsxHawk.Core/loader.cpp
2 views
1
/*
2
this file contains stuff which isn't realistic emulation but is used for loading and bootstrapping things
3
*/
4
5
#include <stdio.h>
6
#include <string.h>
7
#include <assert.h>
8
9
#include "types.h"
10
#include "loader.h"
11
#include "asm.h"
12
13
void Load_BIOS(PSX& psx, const char* path)
14
{
15
FILE* inf = fopen(path,"rb");
16
fread(psx.bios,1,BIOS_SIZE,inf);
17
fclose(inf);
18
}
19
20
bool Load_EXE_Check(const char* fname)
21
{
22
//check for the PSX EXE signature
23
FILE* inf = fopen(fname, "rb");
24
char tmp[8] = {0};
25
fread(tmp,1,8,inf);
26
fclose(inf);
27
return !memcmp(tmp, "PS-X EXE", 8);
28
}
29
30
//TODO - we could load other format EXEs as well, not just PSX-EXE (psxjin appears to do this? check PSXGetFileType and Load() in misc.cpp)
31
void Load_EXE(PSX& psx, const wchar_t* fname)
32
{
33
FILE* inf = _wfopen(fname, L"rb");
34
PSX_EXE_Header header;
35
fread(&header,sizeof(PSX_EXE_Header),1,inf);
36
37
//load the text section to main memory
38
u32 text_destination = header.text_load_addr & RAM_MASK; //convert from virtual address to physical
39
fseek(inf, header.text_exe_offset + 0x800, SEEK_SET); //image addresses are relative to the image section of the file (past the 0x800 header)
40
fread(psx.ram+text_destination,1,header.text_size,inf);
41
42
//now, mednafen patches the bios to run its own routine loaded to PIO which loads the program from fake memory.
43
//i have a better idea. lets patch it with a special escape code which will run the bootstrapping code in C
44
psx.patch(0xBFC06990, ASM_BREAK(PSX::eFakeBreakOp_BootEXE));
45
psx.exeBootHeader = header;
46
47
//patch the kernel image section of the bios with traps for our bios hacks
48
psx.patch(0xBFC10000, ASM_BREAK(PSX::eFakeBreakOp_BiosHack)); //im not sure why we have to include these two. they must get chosen for some other reason to get patched into the kernel
49
psx.patch(0xBFC10010, ASM_BREAK(PSX::eFakeBreakOp_BiosHack)); //..
50
psx.patch(0xBFC10020, ASM_BREAK(PSX::eFakeBreakOp_BiosHack)); //this should correspond to 0xA0 in kernel area
51
psx.patch(0xBFC10030, ASM_BREAK(PSX::eFakeBreakOp_BiosHack)); //this should correspond to 0xB0 in kernel area
52
53
}
54