psxmem: remove hard requirement for a mapping
[pcsx_rearmed.git] / libpcsxcore / psxhle.c
1 /***************************************************************************
2  *   Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team              *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
18  ***************************************************************************/
19
20 /*
21 * Internal PSX HLE functions.
22 */
23
24 #include "psxhle.h"
25
26 static void hleDummy() {
27         psxRegs.pc = psxRegs.GPR.n.ra;
28
29         psxBranchTest();
30 }
31
32 static void hleA0() {
33         u32 call = psxRegs.GPR.n.t1 & 0xff;
34
35         if (biosA0[call]) biosA0[call]();
36
37         psxBranchTest();
38 }
39
40 static void hleB0() {
41         u32 call = psxRegs.GPR.n.t1 & 0xff;
42
43         if (biosB0[call]) biosB0[call]();
44
45         psxBranchTest();
46 }
47
48 static void hleC0() {
49         u32 call = psxRegs.GPR.n.t1 & 0xff;
50
51         if (biosC0[call]) biosC0[call]();
52
53         psxBranchTest();
54 }
55
56 static void hleBootstrap() { // 0xbfc00000
57         SysPrintf("hleBootstrap\n");
58         CheckCdrom();
59         LoadCdrom();
60         SysPrintf("CdromLabel: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromLabel, psxRegs.pc, psxRegs.GPR.n.sp);
61 }
62
63 typedef struct {                   
64         u32 _pc0;      
65         u32 gp0;      
66         u32 t_addr;   
67         u32 t_size;   
68         u32 d_addr;   
69         u32 d_size;   
70         u32 b_addr;   
71         u32 b_size;   
72         u32 S_addr;
73         u32 s_size;
74         u32 _sp,_fp,_gp,ret,base;
75 } EXEC;
76
77 static void hleExecRet() {
78         EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0);
79
80         SysPrintf("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret);
81
82         psxRegs.GPR.n.ra = header->ret;
83         psxRegs.GPR.n.sp = header->_sp;
84         psxRegs.GPR.n.s8 = header->_fp;
85         psxRegs.GPR.n.gp = header->_gp;
86         psxRegs.GPR.n.s0 = header->base;
87
88         psxRegs.GPR.n.v0 = 1;
89         psxRegs.pc = psxRegs.GPR.n.ra;
90 }
91
92 void (*psxHLEt[256])() = {
93         hleDummy, hleA0, hleB0, hleC0,
94         hleBootstrap, hleExecRet,
95         hleDummy, hleDummy
96 };