1 /******************************************************************************/
2 /* Mednafen Sega Saturn Emulation Module */
3 /******************************************************************************/
4 /* scu_dsp_mvi.cpp - SCU DSP MVI Instructions Emulation
5 ** Copyright (C) 2015-2018 Mednafen Team
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software Foundation, Inc.,
19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #include "ss.h"
23 #include "scu.h"
24
25 #pragma GCC optimize("Os")
26
27 namespace MDFN_IEN_SS
28 {
29 #include "scu_dsp_common.inc"
30
31 template<bool looped, unsigned dest, unsigned cond>
MVIInstr(void)32 static NO_INLINE NO_CLONE void MVIInstr(void)
33 {
34 const uint32 instr = DSP_InstrPre<looped>();
35 uint32 imm;
36
37 if(cond & 0x40)
38 imm = sign_x_to_s32(19, instr);
39 else
40 imm = sign_x_to_s32(25, instr);
41
42 if(DSP_TestCond<cond>())
43 {
44 if(DSP.PRAMDMABufCount && (dest == 0x6 || dest == 0x7))
45 {
46 DSP.PC--;
47 //
48 DSP_FinishPRAMDMA();
49 }
50
51 switch(dest)
52 {
53 default:
54 SS_DBG(SS_DBG_WARNING | SS_DBG_SCU, "[SCU] MVI unknown dest 0x%01x --- Instr=0x%08x, Next_Instr=0x%08x, PC=0x%02x\n", dest, instr, (unsigned)(DSP.NextInstr >> 32), DSP.PC);
55 break;
56
57 case 0x0:
58 case 0x1:
59 case 0x2:
60 case 0x3:
61 DSP.DataRAM[dest][DSP.CT[dest]] = imm;
62 DSP.CT[dest] = (DSP.CT[dest] + 1) & 0x3F;
63 break;
64
65 case 0x4: DSP.RX = imm; break;
66 case 0x5: DSP.P.T = (int32)imm; break;
67
68 case 0x6: DSP.RAO = imm; break;
69
70 case 0x7: DSP.WAO = imm; break;
71
72 case 0xA: if(!looped || DSP.LOP == 0x0FFF) { DSP.LOP = imm & 0x0FFF; } break;
73
74 case 0xC:
75 DSP.TOP = DSP.PC - 1;
76 DSP.PC = imm & 0xFF;
77 //
78 if(DSP.PRAMDMABufCount)
79 DSP_FinishPRAMDMA();
80 break;
81 }
82 }
83 }
84
85
86 MDFN_HIDE extern void (*const DSP_MVIFuncTable[2][16][128])(void) =
87 {
88 #include "scu_dsp_mvitab.inc"
89 };
90
91 }
92
93