2009-03-23 09:10:32 +00:00
|
|
|
/*====================================================================
|
|
|
|
|
|
|
|
filename: opcodes.h
|
|
|
|
project: GameCube DSP Tool (gcdsp)
|
|
|
|
created: 2005.03.04
|
|
|
|
mail: duddie@walla.com
|
|
|
|
|
|
|
|
Copyright (c) 2005 Duddie
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
====================================================================*/
|
|
|
|
|
|
|
|
#ifndef _GDSP_OPCODES_HELPER_H
|
|
|
|
#define _GDSP_OPCODES_HELPER_H
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
|
2009-04-01 20:22:43 +00:00
|
|
|
#include "DSPInterpreter.h"
|
|
|
|
|
2009-03-23 09:10:32 +00:00
|
|
|
#include "gdsp_memory.h"
|
|
|
|
#include "gdsp_interpreter.h"
|
|
|
|
#include "gdsp_registers.h"
|
|
|
|
#include "gdsp_ext_op.h"
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// --- SR
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline void dsp_SR_set_flag(int flag)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
g_dsp.r[R_SR] |= (1 << flag);
|
|
|
|
}
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline bool dsp_SR_is_flag_set(int flag)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
2009-04-05 16:58:15 +00:00
|
|
|
return (g_dsp.r[R_SR] & (1 << flag)) != 0;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// --- reg
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
inline u16 dsp_op_read_reg(u8 reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
2009-03-30 03:27:31 +00:00
|
|
|
u16 val;
|
2009-03-23 09:10:32 +00:00
|
|
|
|
|
|
|
switch (reg & 0x1f)
|
|
|
|
{
|
|
|
|
case 0x0c:
|
|
|
|
case 0x0d:
|
|
|
|
case 0x0e:
|
|
|
|
case 0x0f:
|
|
|
|
val = dsp_reg_load_stack(reg - 0x0c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
val = g_dsp.r[reg];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
return val;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
inline void dsp_op_write_reg(u8 reg, u16 val)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
switch (reg & 0x1f)
|
|
|
|
{
|
|
|
|
case 0x0c:
|
|
|
|
case 0x0d:
|
|
|
|
case 0x0e:
|
|
|
|
case 0x0f:
|
|
|
|
dsp_reg_store_stack(reg - 0x0c, val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_dsp.r[reg] = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// --- prod
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
inline s64 dsp_get_long_prod()
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
#if PROFILE
|
|
|
|
ProfilerAddDelta(g_dsp.err_pc, 1);
|
|
|
|
#endif
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
s64 val;
|
|
|
|
s64 low_prod;
|
|
|
|
val = (s8)g_dsp.r[0x16];
|
2009-03-23 09:10:32 +00:00
|
|
|
val <<= 32;
|
|
|
|
low_prod = g_dsp.r[0x15];
|
|
|
|
low_prod += g_dsp.r[0x17];
|
|
|
|
low_prod <<= 16;
|
|
|
|
low_prod |= g_dsp.r[0x14];
|
|
|
|
val += low_prod;
|
2009-04-05 21:04:46 +00:00
|
|
|
return val;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
inline void dsp_set_long_prod(s64 val)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
#if PROFILE
|
|
|
|
ProfilerAddDelta(g_dsp.err_pc, 1);
|
|
|
|
#endif
|
|
|
|
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x14] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
val >>= 16;
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x15] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
val >>= 16;
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x16] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
g_dsp.r[0x17] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
// --- acc
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s64 dsp_get_long_acc(int reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
#if PROFILE
|
|
|
|
ProfilerAddDelta(g_dsp.err_pc, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_assert_(reg < 2);
|
2009-04-05 21:04:46 +00:00
|
|
|
s64 high = (s64)(s8)g_dsp.r[0x10 + reg] << 32;
|
|
|
|
u32 mid_low = ((u32)g_dsp.r[0x1e + reg] << 16) | g_dsp.r[0x1c + reg];
|
|
|
|
return high | mid_low;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline void dsp_set_long_acc(int _reg, s64 val)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
#if PROFILE
|
|
|
|
ProfilerAddDelta(g_dsp.err_pc, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_assert_(_reg < 2);
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x1c + _reg] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
val >>= 16;
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x1e + _reg] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
val >>= 16;
|
2009-03-30 03:27:31 +00:00
|
|
|
g_dsp.r[0x10 + _reg] = (u16)val;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s16 dsp_get_acc_l(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
_assert_(_reg < 2);
|
2009-04-05 16:58:15 +00:00
|
|
|
return g_dsp.r[0x1c + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s16 dsp_get_acc_m(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
_assert_(_reg < 2);
|
2009-04-05 16:58:15 +00:00
|
|
|
return g_dsp.r[0x1e + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s16 dsp_get_acc_h(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
_assert_(_reg < 2);
|
2009-04-05 16:58:15 +00:00
|
|
|
return g_dsp.r[0x10 + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// --- acx
|
|
|
|
//
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s64 dsp_get_long_acx(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
#if PROFILE
|
|
|
|
ProfilerAddDelta(g_dsp.err_pc, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_assert_(_reg < 2);
|
2009-03-30 03:27:31 +00:00
|
|
|
s64 val = (s16)g_dsp.r[0x1a + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
val <<= 16;
|
2009-03-30 03:27:31 +00:00
|
|
|
s64 low_acc = g_dsp.r[0x18 + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
val |= low_acc;
|
2009-04-05 16:58:15 +00:00
|
|
|
return val;
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s16 dsp_get_ax_l(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
_assert_(_reg < 2);
|
2009-04-05 16:58:15 +00:00
|
|
|
return g_dsp.r[0x18 + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 16:58:15 +00:00
|
|
|
inline s16 dsp_get_ax_h(int _reg)
|
2009-03-23 09:10:32 +00:00
|
|
|
{
|
|
|
|
_assert_(_reg < 2);
|
2009-04-05 16:58:15 +00:00
|
|
|
return g_dsp.r[0x1a + _reg];
|
2009-03-23 09:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|