2009-08-18 15:57:41 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-18 15:57:41 +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.
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-18 15:57:41 +00:00
|
|
|
// 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.
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-18 15:57:41 +00:00
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-18 15:57:41 +00:00
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
2009-06-28 10:00:25 +00:00
|
|
|
#include "DSPIntUtil.h"
|
|
|
|
#include "DSPMemoryMap.h"
|
2009-07-24 16:04:29 +00:00
|
|
|
#include "DSPIntExtOps.h"
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
// Extended opcodes do not exist on their own. These opcodes can only be
|
|
|
|
// attached to opcodes that allow extending (8 lower bits of opcode not used by
|
|
|
|
// opcode). Extended opcodes do not modify program counter $pc register.
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-05-01 19:07:29 +00:00
|
|
|
// Most of the suffixes increment or decrement one or more addressing registers
|
2010-01-13 11:09:20 +00:00
|
|
|
// (the first four, ARx). The increment/decrement is either 1, or the
|
|
|
|
// corresponding "index" register (the second four, IXx). The addressing
|
|
|
|
// registers will wrap in odd ways, dictated by the corresponding wrapping
|
|
|
|
// register, WP0-3.
|
2009-05-01 19:07:29 +00:00
|
|
|
|
2010-01-13 11:09:20 +00:00
|
|
|
// The following should be applied as a decrement (and is applied by
|
|
|
|
// dsp_decrement_addr_reg):
|
2009-05-01 19:07:29 +00:00
|
|
|
// ar[i] = (ar[i] & wp[i]) == 0 ? ar[i] | wp[i] : ar[i] - 1;
|
|
|
|
// I have not found the corresponding algorithms for increments yet.
|
|
|
|
// It's gotta be fairly simple though. See R3123, R3125 in Google Code.
|
2009-06-07 11:06:40 +00:00
|
|
|
// (May have something to do with (ar[i] ^ wp[i]) == 0)
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-06-21 13:11:47 +00:00
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
namespace DSPInterpreter
|
|
|
|
{
|
2009-05-01 20:06:24 +00:00
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
namespace Ext
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
|
|
|
|
2009-09-28 16:39:29 +00:00
|
|
|
inline bool IsSameMemArea(u16 a, u16 b)
|
|
|
|
{
|
2009-09-29 18:10:54 +00:00
|
|
|
//LM: tested on WII
|
|
|
|
if ((a>>10)==(b>>10))
|
2009-09-28 16:39:29 +00:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
// DR $arR
|
|
|
|
// xxxx xxxx 0000 01rr
|
|
|
|
// Decrement addressing register $arR.
|
|
|
|
void dr(const UDSPInstruction& opc) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, opc.hex & 0x3, dsp_decrement_addr_reg(opc.hex & 0x3));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IR $arR
|
|
|
|
// xxxx xxxx 0000 10rr
|
|
|
|
// Increment addressing register $arR.
|
|
|
|
void ir(const UDSPInstruction& opc) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, opc.hex & 0x3, dsp_increment_addr_reg(opc.hex & 0x3));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
// NR $arR
|
|
|
|
// xxxx xxxx 0000 11rr
|
|
|
|
// Add corresponding indexing register $ixR to addressing register $arR.
|
|
|
|
void nr(const UDSPInstruction& opc) {
|
|
|
|
u8 reg = opc.hex & 0x3;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
|
|
|
writeToBackLog(0, reg, dsp_increase_addr_reg(reg, (s16)g_dsp.r[DSP_REG_IX0 + reg]));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MV $axD, $acS.l
|
|
|
|
// xxxx xxxx 0001 ddss
|
|
|
|
// Move value of $acS.l to the $axD.l.
|
|
|
|
void mv(const UDSPInstruction& opc)
|
|
|
|
{
|
2009-08-10 09:20:12 +00:00
|
|
|
u8 sreg = opc.hex & 0x3;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 2) & 0x3);
|
|
|
|
|
2010-02-22 00:22:04 +00:00
|
|
|
writeToBackLog(0, dreg + DSP_REG_AXL0, g_dsp.r[sreg + DSP_REG_ACL0]);
|
2009-08-10 09:20:12 +00:00
|
|
|
}
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2009-04-12 19:56:59 +00:00
|
|
|
// S @$D, $acD.l
|
|
|
|
// xxxx xxxx 001s s0dd
|
|
|
|
// Store value of $(acS.l) in the memory pointed by register $D.
|
|
|
|
// Post increment register $D.
|
|
|
|
void s(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 dreg = opc.hex & 0x3;
|
2010-02-22 00:22:04 +00:00
|
|
|
u8 sreg = ((opc.hex >> 3) & 0x3) + DSP_REG_ACL0;
|
2009-04-12 19:56:59 +00:00
|
|
|
|
|
|
|
dsp_dmem_write(g_dsp.r[dreg], g_dsp.r[sreg]);
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_increment_addr_reg(dreg));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SN @$D, $acD.l
|
|
|
|
// xxxx xxxx 001s s1dd
|
|
|
|
// Store value of register $acS in the memory pointed by register $D.
|
|
|
|
// Add indexing register $ixD to register $D.
|
|
|
|
void sn(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 dreg = opc.hex & 0x3;
|
2010-02-22 00:22:04 +00:00
|
|
|
u8 sreg = ((opc.hex >> 3) & 0x3) + DSP_REG_ACL0;
|
2009-04-12 19:56:59 +00:00
|
|
|
|
|
|
|
dsp_dmem_write(g_dsp.r[dreg], g_dsp.r[sreg]);
|
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_increase_addr_reg(dreg, (s16)g_dsp.r[DSP_REG_IX0 + dreg]));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// L axD.l, @$S
|
|
|
|
// xxxx xxxx 01dd d0ss
|
|
|
|
// Load $axD with value from memory pointed by register $S.
|
|
|
|
// Post increment register $S.
|
|
|
|
void l(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 sreg = opc.hex & 0x3;
|
2009-08-10 09:20:12 +00:00
|
|
|
u8 dreg = ((opc.hex >> 3) & 0x7) + DSP_REG_AXL0;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2010-02-21 13:23:29 +00:00
|
|
|
// 40bit sign extension if target is acm.D (important for zelda type ucodes)
|
|
|
|
if ((dreg >= DSP_REG_ACM0) && (g_dsp.r[DSP_REG_SR] & SR_40_MODE_BIT))
|
|
|
|
{
|
|
|
|
u16 val = dsp_dmem_read(g_dsp.r[sreg]);
|
|
|
|
writeToBackLog(0, dreg - DSP_REG_ACM0 + DSP_REG_ACH0, (val & 0x8000) ? 0xFFFF : 0x0000);
|
|
|
|
writeToBackLog(1, dreg, val);
|
|
|
|
writeToBackLog(2, dreg - DSP_REG_ACM0 + DSP_REG_ACL0, 0);
|
|
|
|
writeToBackLog(3, sreg, dsp_increment_addr_reg(sreg));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increment_addr_reg(sreg));
|
|
|
|
}
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LN axD.l, @$S
|
|
|
|
// xxxx xxxx 01dd d0ss
|
|
|
|
// Load $axD with value from memory pointed by register $S.
|
|
|
|
// Add indexing register register $ixS to register $S.
|
|
|
|
void ln(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 sreg = opc.hex & 0x3;
|
|
|
|
u8 dreg = ((opc.hex >> 3) & 0x7) + DSP_REG_AXL0;
|
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// LS $axD.l, $acS.m
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 000s
|
2009-07-31 15:21:35 +00:00
|
|
|
// Load register $axD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar0. Store value from register $acS.m to memory location pointed by
|
|
|
|
// register $ar3. Increment both $ar0 and $ar3.
|
|
|
|
void ls(const UDSPInstruction& opc)
|
2009-04-12 19:56:59 +00:00
|
|
|
{
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2010-01-13 00:11:29 +00:00
|
|
|
u8 sreg = DSP_REG_AR3;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[sreg], g_dsp.r[areg]);
|
2009-04-12 19:56:59 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(1, sreg, dsp_increment_addr_reg(sreg));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increment_addr_reg(DSP_REG_AR0));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// LSN $acD.l, $acS.m
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 010s
|
2009-07-31 15:21:35 +00:00
|
|
|
// Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar0. Store value from register $acS.m to memory location pointed by
|
|
|
|
// register $ar3. Add corresponding indexing register $ix0 to addressing
|
|
|
|
// register $ar0 and increment $ar3.
|
|
|
|
void lsn(const UDSPInstruction& opc)
|
2009-04-12 19:56:59 +00:00
|
|
|
{
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2010-01-13 00:11:29 +00:00
|
|
|
u8 sreg = DSP_REG_AR3;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[sreg], g_dsp.r[areg]);
|
2009-04-12 19:56:59 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(1, sreg, dsp_increment_addr_reg(sreg));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increase_addr_reg(DSP_REG_AR0, (s16)g_dsp.r[DSP_REG_IX0]));
|
2009-04-12 19:56:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// LSM $acD.l, $acS.m
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 100s
|
2009-07-31 15:21:35 +00:00
|
|
|
// Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar0. Store value from register $acS.m to memory location pointed by
|
|
|
|
// register $ar3. Add corresponding indexing register $ix3 to addressing
|
|
|
|
// register $ar3 and increment $ar0.
|
|
|
|
void lsm(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2010-01-13 00:11:29 +00:00
|
|
|
u8 sreg = DSP_REG_AR3;
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
|
|
|
dsp_dmem_write(g_dsp.r[sreg], g_dsp.r[areg]);
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(1, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increment_addr_reg(DSP_REG_AR0));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// LSMN $acD.l, $acS.m
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 110s
|
2009-07-31 15:21:35 +00:00
|
|
|
// Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar0. Store value from register $acS.m to memory location pointed by
|
|
|
|
// register $ar3. Add corresponding indexing register $ix0 to addressing
|
|
|
|
// register $ar0 and add corresponding indexing register $ix3 to addressing
|
|
|
|
// register $ar3.
|
|
|
|
void lsnm(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2010-01-13 00:11:29 +00:00
|
|
|
u8 sreg = DSP_REG_AR3;
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
|
|
|
dsp_dmem_write(g_dsp.r[sreg], g_dsp.r[areg]);
|
2009-07-24 16:04:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(1, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increase_addr_reg(DSP_REG_AR0, (s16)g_dsp.r[DSP_REG_IX0]));
|
2009-07-24 16:04:29 +00:00
|
|
|
}
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// SL $acS.m, $acD.l
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 001s
|
|
|
|
// Store value from register $acS.m to memory location pointed by register
|
2009-07-31 15:21:35 +00:00
|
|
|
// $ar0. Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar3. Increment both $ar0 and $ar3.
|
|
|
|
void sl(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2010-01-13 00:11:29 +00:00
|
|
|
const u8 sreg = DSP_REG_AR3;
|
2009-07-24 16:04:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[DSP_REG_AR0], g_dsp.r[areg]);
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increment_addr_reg(sreg));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increment_addr_reg(DSP_REG_AR0));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// SLN $acS.m, $acD.l
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 011s
|
|
|
|
// Store value from register $acS.m to memory location pointed by register
|
2009-07-31 15:21:35 +00:00
|
|
|
// $ar0. Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar3. Add corresponding indexing register $ix0 to addressing register $ar0
|
|
|
|
// and increment $ar3.
|
|
|
|
void sln(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2010-01-13 00:11:29 +00:00
|
|
|
const u8 sreg = DSP_REG_AR3;
|
2009-07-24 16:04:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[DSP_REG_AR0], g_dsp.r[areg]);
|
2009-08-19 21:37:24 +00:00
|
|
|
|
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increment_addr_reg(sreg));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increase_addr_reg(DSP_REG_AR0, (s16)g_dsp.r[DSP_REG_IX0]));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// SLM $acS.m, $acD.l
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 101s
|
|
|
|
// Store value from register $acS.m to memory location pointed by register
|
2009-07-31 15:21:35 +00:00
|
|
|
// $ar0. Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar3. Add corresponding indexing register $ix3 to addressing register $ar3
|
|
|
|
// and increment $ar0.
|
|
|
|
void slm(const UDSPInstruction& opc)
|
|
|
|
{
|
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2010-01-13 00:11:29 +00:00
|
|
|
const u8 sreg = DSP_REG_AR3;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[DSP_REG_AR0], g_dsp.r[areg]);
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increment_addr_reg(DSP_REG_AR0));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 15:21:35 +00:00
|
|
|
// SLMN $acS.m, $acD.l
|
2009-07-24 16:04:29 +00:00
|
|
|
// xxxx xxxx 10dd 111s
|
|
|
|
// Store value from register $acS.m to memory location pointed by register
|
2009-07-31 15:21:35 +00:00
|
|
|
// $ar0. Load register $acD.l with value from memory pointed by register
|
2009-07-24 16:04:29 +00:00
|
|
|
// $ar3. Add corresponding indexing register $ix0 to addressing register $ar0
|
|
|
|
// and add corresponding indexing register $ix3 to addressing register $ar3.
|
|
|
|
void slnm(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 areg = (opc.hex & 0x1) + DSP_REG_ACM0;
|
2009-08-19 21:37:24 +00:00
|
|
|
u8 dreg = ((opc.hex >> 4) & 0x3) + DSP_REG_AXL0;
|
2010-01-13 00:11:29 +00:00
|
|
|
const u8 sreg = DSP_REG_AR3;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
dsp_dmem_write(g_dsp.r[DSP_REG_AR0], g_dsp.r[areg]);
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, dreg, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
writeToBackLog(1, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(2, DSP_REG_AR0, dsp_increase_addr_reg(DSP_REG_AR0, (s16)g_dsp.r[DSP_REG_IX0]));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
// Not in duddie's doc
|
|
|
|
// LD $ax0.d $ax1.r @$arS
|
|
|
|
// xxxx xxxx 11dr 00ss
|
|
|
|
void ld(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
2009-07-26 16:36:22 +00:00
|
|
|
u8 dreg = (opc.hex >> 5) & 0x1;
|
|
|
|
u8 rreg = (opc.hex >> 4) & 0x1;
|
2009-04-12 10:21:40 +00:00
|
|
|
u8 sreg = opc.hex & 0x3;
|
2009-07-24 16:04:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (sreg != DSP_REG_AR3) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[sreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, sreg, dsp_increment_addr_reg(sreg));
|
2009-07-26 16:36:22 +00:00
|
|
|
} else {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, rreg + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[dreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[dreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, dreg, dsp_increment_addr_reg(dreg));
|
2009-07-26 16:36:22 +00:00
|
|
|
}
|
2009-08-19 21:37:24 +00:00
|
|
|
|
|
|
|
writeToBackLog(3, DSP_REG_AR3, dsp_increment_addr_reg(DSP_REG_AR3));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
// Not in duddie's doc
|
|
|
|
// LDN $ax0.d $ax1.r @$arS
|
|
|
|
// xxxx xxxx 11dr 01ss
|
|
|
|
void ldn(const UDSPInstruction& opc)
|
|
|
|
{
|
2009-07-26 16:36:22 +00:00
|
|
|
u8 dreg = (opc.hex >> 5) & 0x1;
|
|
|
|
u8 rreg = (opc.hex >> 4) & 0x1;
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 sreg = opc.hex & 0x3;
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (sreg != DSP_REG_AR3) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[sreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2009-07-26 16:36:22 +00:00
|
|
|
} else {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, rreg + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[dreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[dreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, dreg, dsp_increase_addr_reg(dreg, (s16)g_dsp.r[DSP_REG_IX0 + dreg]));
|
2009-07-26 16:36:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(3, DSP_REG_AR3, dsp_increment_addr_reg(DSP_REG_AR3));
|
2009-07-24 16:04:29 +00:00
|
|
|
}
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-07-26 16:36:22 +00:00
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
// Not in duddie's doc
|
|
|
|
// LDM $ax0.d $ax1.r @$arS
|
|
|
|
// xxxx xxxx 11dr 10ss
|
|
|
|
void ldm(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
2009-07-26 16:36:22 +00:00
|
|
|
u8 dreg = (opc.hex >> 5) & 0x1;
|
|
|
|
u8 rreg = (opc.hex >> 4) & 0x1;
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 sreg = opc.hex & 0x3;
|
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (sreg != DSP_REG_AR3) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[sreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, sreg, dsp_increment_addr_reg(sreg));
|
2009-07-26 16:36:22 +00:00
|
|
|
} else {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, rreg + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[dreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[dreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, dreg, dsp_increment_addr_reg(dreg));
|
2009-07-26 16:36:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(3, DSP_REG_AR3,
|
|
|
|
dsp_increase_addr_reg(DSP_REG_AR3, (s16)g_dsp.r[DSP_REG_IX0 + DSP_REG_AR3]));
|
2009-04-12 10:21:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
// Not in duddie's doc
|
|
|
|
// LDNM $ax0.d $ax1.r @$arS
|
|
|
|
// xxxx xxxx 11dr 11ss
|
|
|
|
void ldnm(const UDSPInstruction& opc)
|
|
|
|
{
|
2009-07-27 16:41:11 +00:00
|
|
|
u8 dreg = (opc.hex >> 5) & 0x1;
|
2009-07-26 16:36:22 +00:00
|
|
|
u8 rreg = (opc.hex >> 4) & 0x1;
|
2009-07-24 16:04:29 +00:00
|
|
|
u8 sreg = opc.hex & 0x3;
|
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (sreg != DSP_REG_AR3) {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[sreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[sreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, sreg, dsp_increase_addr_reg(sreg, (s16)g_dsp.r[DSP_REG_IX0 + sreg]));
|
2009-07-26 16:36:22 +00:00
|
|
|
} else {
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(0, rreg + DSP_REG_AXL0, dsp_dmem_read(g_dsp.r[dreg]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2010-01-13 00:11:29 +00:00
|
|
|
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
2009-09-28 16:39:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[dreg]));
|
|
|
|
else
|
2010-01-13 00:11:29 +00:00
|
|
|
writeToBackLog(1, rreg + DSP_REG_AXH0, dsp_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
2009-09-28 16:39:29 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(2, dreg, dsp_increase_addr_reg(dreg, (s16)g_dsp.r[DSP_REG_IX0 + dreg]));
|
2009-07-26 16:36:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
writeToBackLog(3, DSP_REG_AR3,
|
|
|
|
dsp_increase_addr_reg(DSP_REG_AR3, (s16)g_dsp.r[DSP_REG_IX0 + DSP_REG_AR3]));
|
2009-07-24 16:04:29 +00:00
|
|
|
}
|
2009-04-12 10:21:40 +00:00
|
|
|
|
2009-08-19 21:37:24 +00:00
|
|
|
|
2009-07-24 16:04:29 +00:00
|
|
|
void nop(const UDSPInstruction& opc)
|
2009-04-12 10:21:40 +00:00
|
|
|
{
|
|
|
|
}
|
2009-07-24 16:04:29 +00:00
|
|
|
|
|
|
|
} // end namespace ext
|
|
|
|
} // end namespace DSPInterpeter
|
|
|
|
|
2010-01-12 21:38:39 +00:00
|
|
|
|
2010-01-13 11:09:20 +00:00
|
|
|
// The ext ops are calculated in parallel with the actual op. That means that
|
|
|
|
// both the main op and the ext op see the same register state as input. The
|
|
|
|
// output is simple as long as the main and ext ops don't change the same
|
|
|
|
// register. If they do the output is the bitwise or of the result of both the
|
|
|
|
// main and ext ops.
|
2010-01-12 21:38:39 +00:00
|
|
|
|
2010-01-13 11:09:20 +00:00
|
|
|
// The ext op are writing their output into the backlog which is
|
|
|
|
// being applied to the real registers after the main op was executed
|
2009-08-20 07:01:04 +00:00
|
|
|
void applyWriteBackLog()
|
2009-08-19 21:37:24 +00:00
|
|
|
{
|
2010-01-12 21:38:39 +00:00
|
|
|
// always make sure to have an extra entry at the end w/ -1 to avoid
|
|
|
|
// infinitive loops
|
|
|
|
for (int i = 0; writeBackLogIdx[i] != -1; i++) {
|
2009-08-20 07:01:04 +00:00
|
|
|
dsp_op_write_reg(writeBackLogIdx[i], g_dsp.r[writeBackLogIdx[i]] | writeBackLog[i]);
|
|
|
|
// Clear back log
|
|
|
|
writeBackLogIdx[i] = -1;
|
2009-08-19 21:37:24 +00:00
|
|
|
}
|
2009-08-20 07:01:04 +00:00
|
|
|
}
|
2009-07-24 16:04:29 +00:00
|
|
|
|
2010-01-13 11:09:20 +00:00
|
|
|
// This function is being called in the main op after all input regs were read
|
|
|
|
// and before it writes into any regs. This way we can always use bitwise or to
|
|
|
|
// apply the ext command output, because if the main op didn't change the value
|
|
|
|
// then 0 | ext output = ext output and if it did then bitwise or is still the
|
|
|
|
// right thing to do
|
2009-08-19 21:37:24 +00:00
|
|
|
void zeroWriteBackLog()
|
|
|
|
{
|
2010-01-12 21:38:39 +00:00
|
|
|
// always make sure to have an extra entry at the end w/ -1 to avoid
|
|
|
|
// infinitive loops
|
|
|
|
for (int i = 0; writeBackLogIdx[i] != -1; i++)
|
2009-08-20 07:01:04 +00:00
|
|
|
dsp_op_write_reg(writeBackLogIdx[i], 0);
|
2009-08-19 21:37:24 +00:00
|
|
|
}
|
2009-08-20 07:01:04 +00:00
|
|
|
|