2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
// Additional copyrights go to Duddie and Tratax (c) 2004
|
|
|
|
|
|
|
|
|
|
|
|
#include "DSPInterpreter.h"
|
|
|
|
|
|
|
|
#include "DSPCore.h"
|
|
|
|
#include "DSPIntUtil.h"
|
|
|
|
|
|
|
|
namespace DSPInterpreter {
|
|
|
|
|
|
|
|
// MRR $D, $S
|
|
|
|
// 0001 11dd ddds ssss
|
|
|
|
// Move value from register $S to register $D.
|
2010-12-29 02:12:06 +00:00
|
|
|
// todo: Perform additional operation depending on destination register.
|
2010-03-24 05:05:25 +00:00
|
|
|
void mrr(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 sreg = opc & 0x1f;
|
|
|
|
u8 dreg = (opc >> 5) & 0x1f;
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
u16 val = dsp_op_read_reg(sreg);
|
|
|
|
dsp_op_write_reg(dreg, val);
|
2009-07-16 10:25:27 +00:00
|
|
|
dsp_conditional_extend_accum(dreg);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LRI $D, #I
|
|
|
|
// 0000 0000 100d dddd
|
|
|
|
// iiii iiii iiii iiii
|
|
|
|
// Load immediate value I to register $D.
|
2010-03-08 21:25:35 +00:00
|
|
|
//
|
2009-07-16 10:25:27 +00:00
|
|
|
// DSPSpy discovery: This, and possibly other instructions that load a
|
|
|
|
// register, has a different behaviour in S40 mode if loaded to AC0.M: The
|
|
|
|
// value gets sign extended to the whole accumulator! This does not happen in
|
|
|
|
// S16 mode.
|
2010-03-24 05:05:25 +00:00
|
|
|
void lri(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 reg = opc & DSP_REG_MASK;
|
2009-07-06 02:10:26 +00:00
|
|
|
u16 imm = dsp_fetch_code();
|
|
|
|
dsp_op_write_reg(reg, imm);
|
|
|
|
dsp_conditional_extend_accum(reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// LRIS $(0x18+D), #I
|
|
|
|
// 0000 1ddd iiii iiii
|
|
|
|
// Load immediate value I (8-bit sign extended) to accumulator register.
|
2010-03-24 05:05:25 +00:00
|
|
|
void lris(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 reg = ((opc >> 8) & 0x7) + DSP_REG_AXL0;
|
|
|
|
u16 imm = (s8)opc;
|
2009-07-06 02:10:26 +00:00
|
|
|
dsp_op_write_reg(reg, imm);
|
|
|
|
dsp_conditional_extend_accum(reg);
|
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
//----
|
2009-07-06 02:10:26 +00:00
|
|
|
|
|
|
|
// NX
|
|
|
|
// 1000 -000 xxxx xxxx
|
|
|
|
// No operation, but can be extended with extended opcode.
|
2010-03-08 21:25:35 +00:00
|
|
|
// This opcode is supposed to do nothing - it's used if you want to use
|
|
|
|
// an opcode extension but not do anything. At least according to duddie.
|
2010-03-24 05:05:25 +00:00
|
|
|
void nx(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2009-08-19 21:37:24 +00:00
|
|
|
zeroWriteBackLog();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
//----
|
|
|
|
|
|
|
|
// DAR $arD
|
2009-07-06 02:10:26 +00:00
|
|
|
// 0000 0000 0000 01dd
|
|
|
|
// Decrement address register $arD.
|
2010-03-24 05:05:25 +00:00
|
|
|
void dar(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.ar[opc & 0x3] = dsp_decrement_addr_reg(opc & 0x3);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
// IAR $arD
|
2009-07-06 02:10:26 +00:00
|
|
|
// 0000 0000 0000 10dd
|
|
|
|
// Increment address register $arD.
|
2010-03-24 05:05:25 +00:00
|
|
|
void iar(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.ar[opc & 0x3] = dsp_increment_addr_reg(opc & 0x3);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
// SUBARN $arD
|
2010-01-24 00:31:20 +00:00
|
|
|
// 0000 0000 0000 11dd
|
2010-03-08 21:25:35 +00:00
|
|
|
// Subtract indexing register $ixD from an addressing register $arD.
|
|
|
|
// used only in IPL-NTSC ucode
|
2010-03-24 05:05:25 +00:00
|
|
|
void subarn(const UDSPInstruction opc)
|
2010-03-08 21:25:35 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 dreg = opc & 0x3;
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.ar[dreg] = dsp_decrease_addr_reg(dreg, (s16)g_dsp._r.ix[dreg]);
|
2010-03-08 21:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ADDARN $arD, $ixS
|
|
|
|
// 0000 0000 0001 ssdd
|
|
|
|
// Adds indexing register $ixS to an addressing register $arD.
|
|
|
|
// It is critical for the Zelda ucode that this one wraps correctly.
|
2010-03-24 05:05:25 +00:00
|
|
|
void addarn(const UDSPInstruction opc)
|
2010-01-24 00:31:20 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 dreg = opc & 0x3;
|
|
|
|
u8 sreg = (opc >> 2) & 0x3;
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.ar[dreg] = dsp_increase_addr_reg(dreg, (s16)g_dsp._r.ix[sreg]);
|
2010-01-24 00:31:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
//----
|
|
|
|
|
2009-07-06 02:10:26 +00:00
|
|
|
// SBCLR #I
|
2010-03-08 21:25:35 +00:00
|
|
|
// 0001 0011 aaaa aiii
|
2009-07-06 02:10:26 +00:00
|
|
|
// bit of status register $sr. Bit number is calculated by adding 6 to
|
|
|
|
// immediate value I.
|
2010-03-24 05:05:25 +00:00
|
|
|
void sbclr(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 bit = (opc & 0x7) + 6;
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr &= ~(1 << bit);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SBSET #I
|
2010-03-08 21:25:35 +00:00
|
|
|
// 0001 0010 aaaa aiii
|
2009-07-06 02:10:26 +00:00
|
|
|
// Set bit of status register $sr. Bit number is calculated by adding 6 to
|
|
|
|
// immediate value I.
|
2010-03-24 05:05:25 +00:00
|
|
|
void sbset(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
u8 bit = (opc & 0x7) + 6;
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr |= (1 << bit);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is a bunch of flag setters, flipping bits in SR. So far so good,
|
|
|
|
// but it's harder to know exactly what effect they have.
|
2010-03-24 05:05:25 +00:00
|
|
|
void srbith(const UDSPInstruction opc)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2009-08-19 21:37:24 +00:00
|
|
|
zeroWriteBackLog();
|
2010-03-24 05:05:25 +00:00
|
|
|
switch ((opc >> 8) & 0xf)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2009-07-16 10:25:27 +00:00
|
|
|
// M0/M2 change the multiplier mode (it can multiply by 2 for free).
|
2009-07-06 02:10:26 +00:00
|
|
|
case 0xa: // M2
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr &= ~SR_MUL_MODIFY;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
case 0xb: // M0
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr |= SR_MUL_MODIFY;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// If set, treat multiplicands as unsigned.
|
|
|
|
// If clear, treat them as signed.
|
|
|
|
case 0xc: // CLR15
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr &= ~SR_MUL_UNSIGNED;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
case 0xd: // SET15
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr |= SR_MUL_UNSIGNED;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Automatic 40-bit sign extension when loading ACx.M.
|
2009-07-16 10:25:27 +00:00
|
|
|
// SET40 changes something very important: see the LRI instruction above.
|
|
|
|
case 0xe: // SET16 (CLR40)
|
2010-12-29 02:12:06 +00:00
|
|
|
g_dsp._r.sr &= ~SR_40_MODE_BIT;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-29 02:12:06 +00:00
|
|
|
case 0xf: // SET40
|
|
|
|
g_dsp._r.sr |= SR_40_MODE_BIT;
|
2009-07-06 02:10:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 21:25:35 +00:00
|
|
|
//----
|
|
|
|
|
2010-03-24 05:05:25 +00:00
|
|
|
void unknown(const UDSPInstruction opc)
|
2010-03-08 21:25:35 +00:00
|
|
|
{
|
2010-03-24 05:05:25 +00:00
|
|
|
ERROR_LOG(DSPLLE, "LLE: Unrecognized opcode 0x%04x, pc 0x%04x", opc, g_dsp.pc);
|
2010-03-08 21:25:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-06 02:10:26 +00:00
|
|
|
} // namespace
|