| 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 | #if 0 |
| 27 | #define PSXHLE_LOG SysPrintf |
| 28 | #else |
| 29 | #define PSXHLE_LOG(...) |
| 30 | #endif |
| 31 | |
| 32 | static void hleDummy() { |
| 33 | log_unhandled("hleDummy called @%08x ra=%08x\n", |
| 34 | psxRegs.pc - 4, psxRegs.GPR.n.ra); |
| 35 | psxRegs.pc = psxRegs.GPR.n.ra; |
| 36 | psxRegs.cycle += 1000; |
| 37 | |
| 38 | psxBranchTest(); |
| 39 | } |
| 40 | |
| 41 | static void hleA0() { |
| 42 | u32 call = psxRegs.GPR.n.t1 & 0xff; |
| 43 | |
| 44 | if (biosA0[call]) biosA0[call](); |
| 45 | |
| 46 | psxBranchTest(); |
| 47 | } |
| 48 | |
| 49 | static void hleB0() { |
| 50 | u32 call = psxRegs.GPR.n.t1 & 0xff; |
| 51 | |
| 52 | if (biosB0[call]) biosB0[call](); |
| 53 | |
| 54 | psxBranchTest(); |
| 55 | } |
| 56 | |
| 57 | static void hleC0() { |
| 58 | u32 call = psxRegs.GPR.n.t1 & 0xff; |
| 59 | |
| 60 | if (biosC0[call]) biosC0[call](); |
| 61 | |
| 62 | psxBranchTest(); |
| 63 | } |
| 64 | |
| 65 | static void hleBootstrap() { // 0xbfc00000 |
| 66 | PSXHLE_LOG("hleBootstrap\n"); |
| 67 | CheckCdrom(); |
| 68 | LoadCdrom(); |
| 69 | PSXHLE_LOG("CdromLabel: \"%s\": PC = %8.8lx (SP = %8.8lx)\n", CdromLabel, psxRegs.pc, psxRegs.GPR.n.sp); |
| 70 | } |
| 71 | |
| 72 | typedef struct { |
| 73 | u32 _pc0; |
| 74 | u32 gp0; |
| 75 | u32 t_addr; |
| 76 | u32 t_size; |
| 77 | u32 d_addr; |
| 78 | u32 d_size; |
| 79 | u32 b_addr; |
| 80 | u32 b_size; |
| 81 | u32 S_addr; |
| 82 | u32 s_size; |
| 83 | u32 _sp,_fp,_gp,ret,base; |
| 84 | } EXEC; |
| 85 | |
| 86 | static void hleExecRet() { |
| 87 | EXEC *header = (EXEC*)PSXM(psxRegs.GPR.n.s0); |
| 88 | |
| 89 | PSXHLE_LOG("ExecRet %x: %x\n", psxRegs.GPR.n.s0, header->ret); |
| 90 | |
| 91 | psxRegs.GPR.n.ra = SWAP32(header->ret); |
| 92 | psxRegs.GPR.n.sp = SWAP32(header->_sp); |
| 93 | psxRegs.GPR.n.fp = SWAP32(header->_fp); |
| 94 | psxRegs.GPR.n.gp = SWAP32(header->_gp); |
| 95 | psxRegs.GPR.n.s0 = SWAP32(header->base); |
| 96 | |
| 97 | psxRegs.GPR.n.v0 = 1; |
| 98 | psxRegs.pc = psxRegs.GPR.n.ra; |
| 99 | } |
| 100 | |
| 101 | void (* const psxHLEt[24])() = { |
| 102 | hleDummy, hleA0, hleB0, hleC0, |
| 103 | hleBootstrap, hleExecRet, psxBiosException, hleDummy, |
| 104 | hleExc0_0_1, hleExc0_0_2, |
| 105 | hleExc0_1_1, hleExc0_1_2, hleExc0_2_2_syscall, |
| 106 | hleExc1_0_1, hleExc1_0_2, |
| 107 | hleExc1_1_1, hleExc1_1_2, |
| 108 | hleExc1_2_1, hleExc1_2_2, |
| 109 | hleExc1_3_1, hleExc1_3_2, |
| 110 | hleExc3_0_2_defint, |
| 111 | hleExcPadCard1, hleExcPadCard2, |
| 112 | }; |