#include <windows.h>
#include <math.h>
#include <types.h>
#include "unreal.h"
#include "emu.h"
#include "rsp.h"
#include "resource.h"

#include "inline.cpp"
#include "fixed32.cpp"

#define RSP_DECODE_RS					((Instruction & 0x03E00000) >> 21)
#define RSP_DECODE_RT					((Instruction & 0x001F0000) >> 16)
#define RSP_DECODE_RD					((Instruction & 0x0000F800) >> 11)
#define RSP_DECODE_SA					((Instruction & 0x000007C0) >> 6)
#define RSP_DECODE_IMMED				((ushort)(Instruction & 0x0000FFFF))

#define RSP_DECODE_BASE					(RSP_DECODE_RS)
#define RSP_DECODE_SPECIAL				((Instruction & 0x3F))

#define RSP_DECODE_COP0					(RSP_DECODE_RS)
#define RSP_DECODE_COP2					(RSP_DECODE_RS)
#define RSP_DECODE_C2TYPE				(RSP_DECODE_RD)
#define RSP_DECODE_C2OFS				((schar)(Instruction & 0x7F))
#define RSP_DECODE_VECTOP				(RSP_DECODE_SPECIAL)

inline ushort RSP_Processor::RoundDown16(slong val)
{
	if (val & 0x8000)
		return (val >> 16) + 1;
	else
		return (val >> 16);
}

void RSP_Processor::ADDI(void)
{
	slong imm;
	int rt, rs;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	imm = SignExtend16(RSP_DECODE_IMMED);

	RSP_GPR[rt] = (ulong)RSP_GPR[rs] + (ulong)imm;
}

void RSP_Processor::ADDIU(void)
{
	slong imm;
	int rt, rs;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	imm = SignExtend16(RSP_DECODE_IMMED);

	RSP_GPR[rt] = (ulong)RSP_GPR[rs] + (ulong)imm;
}

void RSP_Processor::ADD(void)
{
	int rt, rs, rd;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;

	RSP_GPR[rd] = (slong)RSP_GPR[rs] + (slong)RSP_GPR[rt];
}

void RSP_Processor::ADDU(void)
{
	int rt, rs, rd;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;

	RSP_GPR[rd] = (ulong)RSP_GPR[rs] + (ulong)RSP_GPR[rt];
}

void RSP_Processor::SUB(void)
{
	int rt, rs, rd;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;

	RSP_GPR[rd] = (slong)RSP_GPR[rs] - (slong)RSP_GPR[rt];
}

void RSP_Processor::ANDI(void)
{
	ulong immediate;
	int rt, rs;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	immediate = (ulong)RSP_DECODE_IMMED;

	RSP_GPR[rt] = RSP_GPR[rs] & immediate;
}

void RSP_Processor::BLTZ(void)
{
    char rs;
    __int16 offset;
    rs = (char) ((Instruction & 0x03E00000) >> 21);
    offset = (__int16) (Instruction & 0x0000FFFF);

    if((RSP_GPR[rs]&0x80000000) != 0)
        NextPC+=(((__int32) offset) << 2)-4;
}

void RSP_Processor::BEQ(void)
{
	int rs, rt;
	slong offset;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	offset = SignExtend16(RSP_DECODE_IMMED);

	if (RSP_GPR[rt] == RSP_GPR[rs])
		NextPC += (((ulong)offset) << 2) - 4;
}

void RSP_Processor::BGEZALL(void)
{
    char rs;
    __int16 offset;
    rs = (char) ((Instruction & 0x03E00000) >> 21);
    offset = (__int16) (Instruction & 0x0000FFFF);

    if((RSP_GPR[rs]&0x80000000)>>31 == 0)
    {
        NextPC+=(((__int32) offset) << 2)-4;
        RSP_GPR[31] = NextPC+4;
    }
    else
    {
        sp_pc.PC+=4; /* nullify current instruction */
        NextPC+=4;
    }
}

void RSP_Processor::BGTZ(void)
{
	int rs;
	slong offset;

	rs = RSP_DECODE_RS;
	offset = SignExtend16(RSP_DECODE_IMMED);

	if ((slong)RSP_GPR[rs] > 0)
		NextPC += (((ulong)offset) << 2) - 4;
}

void RSP_Processor::BLEZ(void)
{
	int rs;
	slong offset;

	rs = RSP_DECODE_RS;
	offset = SignExtend16(RSP_DECODE_IMMED);

	if ((slong)RSP_GPR[rs] <= 0)
		NextPC += (((ulong)offset) << 2) - 4;
}

void RSP_Processor::BGEZ(void)
{
	int rs;
	slong offset;

	rs = RSP_DECODE_RS;
	offset = SignExtend16(RSP_DECODE_IMMED);

	if ((slong)RSP_GPR[rs] >= 0)
		NextPC += (((ulong)offset) << 2) - 4;
}

void RSP_Processor::BNE(void)
{
	int rs, rt;
	slong offset;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	offset = SignExtend16(RSP_DECODE_IMMED);

	if (RSP_GPR[rt] != RSP_GPR[rs])
		NextPC += (((ulong)offset) << 2) - 4;
}

void RSP_Processor::BREAK(void)
{
    // Stop the R4300i so we can add an event to the heap...
    running = FALSE;
    WaitForSingleObject(hDebugEvent, INFINITE);

    // Add the event if the INTR_BREAK flag is set...
    if (spreg.status & SP_STATUS_INTR_BREAK) EventAdd_SP();

    // Stop ourselves.
    RSP_running = FALSE;
	spreg.status |= SP_STATUS_HALT | SP_STATUS_BROKE;

    // Fire the R4300i back up.
    running = TRUE;
    SetEvent(hRunEvent);
}

void RSP_Processor::COP0(void)
{
	(this->*Cop0[RSP_DECODE_COP0])();
}

void RSP_Processor::COP2(void)
{
	(this->*Cop2[RSP_DECODE_COP2])();
}

void RSP_Processor::VECTOP(void)
{
	(this->*VectOp[RSP_DECODE_VECTOP])();
}

void RSP_Processor::J(void)
{
	__int32 target;
	target = (Instruction & 0x03FFFFFF);

	target = target << 2;
	target = (__int32) (target | (NextPC & 0xF0000000));  
	NextPC=((__int32) target-4);
}

void RSP_Processor::JAL(void)
{
	__int32 target;
	target = (Instruction & 0x03FFFFFF);
	target = target << 2;
	target = (__int32) (target | (NextPC & 0xF0000000));  

	/* Set Link Address for return */
	RSP_GPR[31] = NextPC+4;

	NextPC=((__int32) target-4);
}

void RSP_Processor::JR(void)
{
	NextPC = SP_IMEM_BASE + ((RSP_GPR[RSP_DECODE_RS] - 4) & 0x0FFC);
}

void RSP_Processor::LBU(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong)offset);
	RSP_GPR[rt] = (uchar)RSP_Read8(SP_DMEM_BASE + (temp & 0x0FFF));
}

void RSP_Processor::SB(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong) offset);
	RSP_Write8(SP_DMEM_BASE + (temp & 0x0FFF), (uchar)RSP_GPR[rt]);
}

void RSP_Processor::LB(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong) offset);
	RSP_GPR[rt] = (slong)RSP_Read8(SP_DMEM_BASE + (temp & 0x0FFF));
}

void RSP_Processor::LH(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong) offset);
	RSP_GPR[rt] = (slong)RSP_Read16(SP_DMEM_BASE + (temp & 0x0FFF));
}

void RSP_Processor::SH(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong) offset);
	RSP_Write16(SP_DMEM_BASE + (temp & 0x0FFF), (ushort)RSP_GPR[rt]);
}

void RSP_Processor::LHU(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong)offset);
	RSP_GPR[rt] = RSP_Read16(SP_DMEM_BASE + (temp & 0x0FFF));
}

void RSP_Processor::LW(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong) offset);
	RSP_GPR[rt] = RSP_Read32(SP_DMEM_BASE + (temp & 0x0FFF));
}

void RSP_Processor::LUI(void)
{
	RSP_GPR[RSP_DECODE_RT] = RSP_DECODE_IMMED << 16;
}

void RSP_Processor::LWC2(void)
{
	schar ofs;
    int rt, type;
    slong offset;

    rt = RSP_DECODE_RT;
	type = RSP_DECODE_C2TYPE;

	ofs = RSP_DECODE_C2OFS;
	if (ofs & 0x40) ofs |= 0x80;		// Extend sign bit.
	offset = (slong)ofs << VectorShiftTable[type];
	offset += RSP_GPR[RSP_DECODE_BASE];

    switch (type)
    {
		case C2VEC_B:
			Set_VectB(rt, RSP_DECODE_SA >> 1, RSP_Read8(SP_DMEM_BASE + (offset & 0x0FFF)));
            break;

        case C2VEC_S:
			Set_VectS(rt, RSP_DECODE_SA >> 2, RSP_Read16(SP_DMEM_BASE + (offset & 0x0FFF)));
            break;

        case C2VEC_L:
			Set_VectL(rt, RSP_DECODE_SA >> 3, RSP_Read32(SP_DMEM_BASE + (offset & 0x0FFF)));
            break;

		case C2VEC_D:
			switch (RSP_DECODE_SA >> 1)
			{
				case 0:
					Set_VectL(rt, 0, RSP_Read32(SP_DMEM_BASE + (offset & 0x0FFF)));
					Set_VectL(rt, 1, RSP_Read32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF)));
					break;

				case 8:
					Set_VectL(rt, 2, RSP_Read32(SP_DMEM_BASE + (offset & 0x0FFF)));
					Set_VectL(rt, 3, RSP_Read32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF)));
					break;
			}
			break;

		case C2VEC_Q:
			Set_VectL(rt, 0, RSP_Read32(SP_DMEM_BASE + (offset & 0x0FFF)));
			Set_VectL(rt, 1, RSP_Read32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF)));
			Set_VectL(rt, 2, RSP_Read32(SP_DMEM_BASE + ((offset + 8) & 0x0FFF)));
			Set_VectL(rt, 3, RSP_Read32(SP_DMEM_BASE + ((offset + 12) & 0x0FFF)));
			break;

		case C2VEC_R:
			MessageBox(NULL,"LRV","OPCODE",MB_OK);
			break;

		case C2VEC_P:
			MessageBox(NULL,"LPV","OPCODE",MB_OK);
			break;
		
		case C2VEC_U:
			MessageBox(NULL,"LUV","OPCODE",MB_OK);
			break;
		
		case C2VEC_H:
			MessageBox(NULL,"LHV","OPCODE",MB_OK);
			break;
		
		case C2VEC_F:
			MessageBox(NULL,"LFV","OPCODE",MB_OK);
			break;
		
		case C2VEC_W:
			MessageBox(NULL,"LWV","OPCODE",MB_OK);
			break;
		
		case C2VEC_T:
			MessageBox(NULL,"LTV","OPCODE",MB_OK);
			break;
	}
}

void RSP_Processor::SWC2(void)
{
	schar ofs;
    int rt, type;
    slong offset;

    rt = RSP_DECODE_RT;
	type = RSP_DECODE_C2TYPE;

	ofs = RSP_DECODE_C2OFS;
	if (ofs & 0x40) ofs |= 0x80;		// Extend sign bit.
	offset = (slong)ofs << VectorShiftTable[type];
	offset += RSP_GPR[RSP_DECODE_BASE];

    switch (type)
    {
        case C2VEC_B:
			RSP_Write8(SP_DMEM_BASE + (offset & 0x0FFF), Get_VectB(rt, RSP_DECODE_SA >> 1));
            break;

        case C2VEC_S:
			RSP_Write16(SP_DMEM_BASE + (offset & 0x0FFF), Get_VectS(rt, RSP_DECODE_SA >> 2));
            break;

        case C2VEC_L:
			RSP_Write32(SP_DMEM_BASE + (offset & 0x0FFF), Get_VectL(rt, RSP_DECODE_SA >> 3));
            break;

		case C2VEC_D:
			switch (RSP_DECODE_SA >> 1)
			{
				case 0:
					RSP_Write32(SP_DMEM_BASE + (offset & 0x0FFF),       Get_VectL(rt, 0));
					RSP_Write32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF), Get_VectL(rt, 1));
					break;

				case 8:
					RSP_Write32(SP_DMEM_BASE + (offset & 0x0FFF),       Get_VectL(rt, 2));
					RSP_Write32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF), Get_VectL(rt, 3));
					break;
			}
			break;

		case C2VEC_Q:
			RSP_Write32(SP_DMEM_BASE + (offset & 0x0FFF),        Get_VectL(rt, 0));
			RSP_Write32(SP_DMEM_BASE + ((offset + 4) & 0x0FFF),  Get_VectL(rt, 1));
			RSP_Write32(SP_DMEM_BASE + ((offset + 8) & 0x0FFF),  Get_VectL(rt, 2));
			RSP_Write32(SP_DMEM_BASE + ((offset + 12) & 0x0FFF), Get_VectL(rt, 3));
			break;

		case C2VEC_R:
			MessageBox(NULL,"SRV","OPCODE",MB_OK);
			break;

		case C2VEC_P:
			MessageBox(NULL,"SPV","OPCODE",MB_OK);
			break;
		
		case C2VEC_U:
			MessageBox(NULL,"SUV","OPCODE",MB_OK);
			break;
		
		case C2VEC_H:
			MessageBox(NULL,"SHV","OPCODE",MB_OK);
			break;
		
		case C2VEC_F:
			MessageBox(NULL,"SFV","OPCODE",MB_OK);
			break;
		
		case C2VEC_W:
			MessageBox(NULL,"SWV","OPCODE",MB_OK);
			break;
		
		case C2VEC_T:
			MessageBox(NULL,"STV","OPCODE",MB_OK);
			break;
	}
}

void RSP_Processor::MFC0(void)
{
	int rt, rd;

	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	if(rd<=15)
	{
		RSP_GPR[rt] = *Cop0_Addr[rd];
	}
	else
	{
		MessageBox(NULL,"MFC0 - TBD","OPCODE",MB_OK);
	}
}


void RSP_Processor::MTC0(void)
{
	int rt, rd;

	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	if(rd<=15)
	{
		(*Cop0_Regs[rd])(RSP_GPR[rt]);
	}
	else
	{
		MessageBox(NULL,"MTC0 - TBD","OPCODE",MB_OK);
	}
}

void RSP_Processor::MFC2(void)
{
	int rt, rd, sa;
	uchar hi, lo;

	rt = RSP_DECODE_RT;
	rd = RSP_DECODE_RD;
	sa = (RSP_DECODE_SA >> 1) & 0x0F;

	hi = Get_VectB(rd, sa);
	if (sa != 15) lo = Get_VectB(rd, sa + 1); else lo = 0;

	RSP_GPR[rt] = (hi << 8) | lo;
}

void RSP_Processor::MTC2(void)
{
	int rt, rd, sa;
	uchar hi, lo;

	rt = RSP_DECODE_RT;
	rd = RSP_DECODE_RD;
	sa = (RSP_DECODE_SA >> 1) & 0x0F;

	hi = (RSP_GPR[rt] & 0x0000FF00) >> 8;
	lo = (RSP_GPR[rt] & 0x000000FF);

	Set_VectB(rd, sa, hi);
	if (sa != 15) Set_VectB(rd, sa + 1, lo);
}

void RSP_Processor::CFC2(void)
{
	int rt, rd;

	rt = RSP_DECODE_RT;
	rd = RSP_DECODE_RD & 0x03;

	RSP_GPR[rt] = VFlags[rd];
}

void RSP_Processor::CTC2(void)
{
	int rt, rd;

	rt = RSP_DECODE_RT;
	rd = RSP_DECODE_RD & 0x03;

	VFlags[rd] = RSP_GPR[rt];
}

void RSP_Processor::ORI(void)
{
	ulong immediate;
	int rt, rs;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	immediate = (ulong)RSP_DECODE_IMMED;

	RSP_GPR[rt] = (RSP_GPR[rs] | immediate);
}

void RSP_Processor::XORI(void)
{
	ulong immediate;
	int rt, rs;

	rt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS;
	immediate = (ulong)RSP_DECODE_IMMED;

	RSP_GPR[rt] = (RSP_GPR[rs] ^ immediate);
}

void RSP_Processor::REGIMM(void)
{
    (this->*RegIMM[(Instruction & 0x001F0000) >> 16])();
}

void RSP_Processor::SPECIAL(void) 
{
	(this->*Special[RSP_DECODE_SPECIAL])();
}

void RSP_Processor::SW(void)
{
	int base, rt;
	slong offset;
	ulong temp;

	base = RSP_DECODE_BASE;
	rt = RSP_DECODE_RT;
	offset = SignExtend16(RSP_DECODE_IMMED);

	temp = ((ulong)RSP_GPR[base]) + ((ulong)offset);
	RSP_Write32(SP_DMEM_BASE + (temp & 0x0FFF), RSP_GPR[rt]);
}

void RSP_Processor::SRA(void)
{
	int rd, rt, sa;

	sa = RSP_DECODE_SA;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	//fill with 0's
	RSP_GPR[rd] = (signed __int64) (((slong) RSP_GPR[rt]) >> sa);
}

void RSP_Processor::SRL(void)
{
	int rd, rt, sa;

	sa = RSP_DECODE_SA;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	//fill with 0's
	RSP_GPR[rd] = (unsigned __int64) (((ulong) RSP_GPR[rt]) >> sa);
}

void RSP_Processor::SLL()
{
	int rd, rt, sa;

	sa = RSP_DECODE_SA;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	RSP_GPR[rd] = ((ulong)(RSP_GPR[rt] << sa));
}

void RSP_Processor::SRLV()
{
	int rd, rt, rs;

	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	RSP_GPR[rd] = (unsigned __int64) ( ((ulong)RSP_GPR[rt]) >> RSP_GPR[rs] );
}

void RSP_Processor::SLLV()
{
	int rd, rt, rs;

	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	RSP_GPR[rd] = ((ulong)(RSP_GPR[rt] << RSP_GPR[rs]));
}

void RSP_Processor::SRAV(void)
{
	int rd, rt, rs;

	rs = RSP_DECODE_RS;
	rd = RSP_DECODE_RD;
	rt = RSP_DECODE_RT;

	//fill with 0's
	RSP_GPR[rd] = (signed __int64) (((slong) RSP_GPR[rt]) >> RSP_GPR[rs]);
}

void RSP_Processor::AND(void)
{
	RSP_GPR[RSP_DECODE_RD] = RSP_GPR[RSP_DECODE_RS] & RSP_GPR[RSP_DECODE_RT];
}

void RSP_Processor::OR(void)
{
	RSP_GPR[RSP_DECODE_RD] = RSP_GPR[RSP_DECODE_RS] | RSP_GPR[RSP_DECODE_RT];
}

void RSP_Processor::NOR(void)
{
	RSP_GPR[RSP_DECODE_RD] = !(RSP_GPR[RSP_DECODE_RS] | RSP_GPR[RSP_DECODE_RT]);
}

void RSP_Processor::XOR(void)
{
	RSP_GPR[RSP_DECODE_RD] = RSP_GPR[RSP_DECODE_RS] ^ RSP_GPR[RSP_DECODE_RT];
}

void RSP_Processor::VNOOP(void)
{
	// Do nothing... (right? :) )
}

void RSP_Processor::VMOV(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD & 0x07;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x07;

	Set_VectS(vd, vs, Get_VectS(vt, rs));
}

void RSP_Processor::VXOR(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, (Get_VectS(vs, 0) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) ^ Get_VectS(vt, rs)));
			break;
	}
}

void RSP_Processor::VNXOR(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 0)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 3)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 4)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, 7)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) ^ Get_VectS(vt, rs)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) ^ Get_VectS(vt, rs)));
			break;
	}
}

void RSP_Processor::VAND(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 0)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 1)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 0)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 2)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 3)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 2)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 3)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 4)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 5)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 4)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, 6)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, 7)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, 6)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, 7)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, (Get_VectS(vs, 0) & Get_VectS(vt, rs)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) & Get_VectS(vt, rs)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) & Get_VectS(vt, rs)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) & Get_VectS(vt, rs)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) & Get_VectS(vt, rs)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) & Get_VectS(vt, rs)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) & Get_VectS(vt, rs)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) & Get_VectS(vt, rs)));
			break;
	}
}

void RSP_Processor::VNAND(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 0)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 1)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 0)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 2)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 3)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 2)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 3)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 4)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 5)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 4)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, 6)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, 7)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, 6)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, 7)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) & Get_VectS(vt, rs)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) & Get_VectS(vt, rs)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) & Get_VectS(vt, rs)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) & Get_VectS(vt, rs)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) & Get_VectS(vt, rs)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) & Get_VectS(vt, rs)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) & Get_VectS(vt, rs)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) & Get_VectS(vt, rs)));
			break;
	}
}

void RSP_Processor::VOR(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 0)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 1)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 0)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 1)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 0)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 2)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 3)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 2)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 3)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 2)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 4)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 5)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 4)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 5)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 4)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, 6)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, 7)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, 6)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, 7)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, 6)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, 7)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, (Get_VectS(vs, 0) | Get_VectS(vt, rs)));
			Set_VectS(vd, 1, (Get_VectS(vs, 1) | Get_VectS(vt, rs)));
			Set_VectS(vd, 2, (Get_VectS(vs, 2) | Get_VectS(vt, rs)));
			Set_VectS(vd, 3, (Get_VectS(vs, 3) | Get_VectS(vt, rs)));
			Set_VectS(vd, 4, (Get_VectS(vs, 4) | Get_VectS(vt, rs)));
			Set_VectS(vd, 5, (Get_VectS(vs, 5) | Get_VectS(vt, rs)));
			Set_VectS(vd, 6, (Get_VectS(vs, 6) | Get_VectS(vt, rs)));
			Set_VectS(vd, 7, (Get_VectS(vs, 7) | Get_VectS(vt, rs)));
			break;
	}
}

void RSP_Processor::VNOR(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 3)));
			break;

		case 0x03:		// [1q]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x04:		// [0h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 0)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 1)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 0)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 1)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 0)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 1)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 0)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 1)));
			break;

		case 0x05:		// [1h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 2)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 3)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 2)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 3)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 2)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 3)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 2)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 3)));
			break;

		case 0x06:		// [2h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 4)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 5)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 4)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 5)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 4)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 5)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 4)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 5)));
			break;

		case 0x07:		// [3h]
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, 6)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, 7)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, 6)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, 7)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, 6)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, 7)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, 6)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, 7)));
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			Set_VectS(vd, 0, !(Get_VectS(vs, 0) | Get_VectS(vt, rs)));
			Set_VectS(vd, 1, !(Get_VectS(vs, 1) | Get_VectS(vt, rs)));
			Set_VectS(vd, 2, !(Get_VectS(vs, 2) | Get_VectS(vt, rs)));
			Set_VectS(vd, 3, !(Get_VectS(vs, 3) | Get_VectS(vt, rs)));
			Set_VectS(vd, 4, !(Get_VectS(vs, 4) | Get_VectS(vt, rs)));
			Set_VectS(vd, 5, !(Get_VectS(vs, 5) | Get_VectS(vt, rs)));
			Set_VectS(vd, 6, !(Get_VectS(vs, 6) | Get_VectS(vt, rs)));
			Set_VectS(vd, 7, !(Get_VectS(vs, 7) | Get_VectS(vt, rs)));
			break;
	}
}

//
// VADD: Add two vectors and clamp at 7FFFh if overflow.
//

void RSP_Processor::VADD(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x03:		// [1q]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x04:		// [0h]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 0); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 1); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x05:		// [1h]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 2); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 3); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x06:		// [2h]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 4); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 5); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x07:		// [3h]
			temp = Get_VectS(vs, 0) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, 6); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, 7); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = Get_VectS(vs, 0) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 0, (ushort)temp);
			temp = Get_VectS(vs, 1) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 1, (ushort)temp);
			temp = Get_VectS(vs, 2) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 2, (ushort)temp);
			temp = Get_VectS(vs, 3) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 3, (ushort)temp);
			temp = Get_VectS(vs, 4) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 4, (ushort)temp);
			temp = Get_VectS(vs, 5) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 5, (ushort)temp);
			temp = Get_VectS(vs, 6) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 6, (ushort)temp);
			temp = Get_VectS(vs, 7) + Get_VectS(vt, rs); if (temp > 0x7FFF) temp = 0x7FFF; Set_VectS(vd, 7, (ushort)temp);
			break;
	}
}

//
// VSUB: Subtract two vectors (vs - vt) and clamp at 8000h if underflow.  Modify result if any VFlags[0] are set.
//

void RSP_Processor::VSUB(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 0); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 1); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 2); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 3); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x03:		// [1q]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 4); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 5); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 6); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 7); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x04:		// [0h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 0); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 1); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 0); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 1); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 0); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 1); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x05:		// [1h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 2); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 3); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 2); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 3); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 2); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 3); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x06:		// [2h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 4); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 5); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 4); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 5); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 4); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 5); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x07:		// [3h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 6); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 7); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 6); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 7); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 6); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 7); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, rs); if ((slong)VDest[0] < (slong)0xFFFF8000) VDest[0] = 0x8000;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, rs); if ((slong)VDest[1] < (slong)0xFFFF8000) VDest[1] = 0x8000;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, rs); if ((slong)VDest[2] < (slong)0xFFFF8000) VDest[2] = 0x8000;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, rs); if ((slong)VDest[3] < (slong)0xFFFF8000) VDest[3] = 0x8000;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, rs); if ((slong)VDest[4] < (slong)0xFFFF8000) VDest[4] = 0x8000;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, rs); if ((slong)VDest[5] < (slong)0xFFFF8000) VDest[5] = 0x8000;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, rs); if ((slong)VDest[6] < (slong)0xFFFF8000) VDest[6] = 0x8000;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, rs); if ((slong)VDest[7] < (slong)0xFFFF8000) VDest[7] = 0x8000;
			break;
	}

	if (VFlags[0])
	{
		if (VFlags[0] & 0x01) VDest[0]--;
		if (VFlags[0] & 0x02) VDest[1]--;
		if (VFlags[0] & 0x04) VDest[2]--;
		if (VFlags[0] & 0x08) VDest[3]--;
		if (VFlags[0] & 0x10) VDest[4]--;
		if (VFlags[0] & 0x20) VDest[5]--;
		if (VFlags[0] & 0x40) VDest[6]--;
		if (VFlags[0] & 0x80) VDest[7]--;

		VFlags[0] = 0x00000000;
	}

	Set_VectS(vd, 0, VDest[0]);
	Set_VectS(vd, 1, VDest[1]);
	Set_VectS(vd, 2, VDest[2]);
	Set_VectS(vd, 3, VDest[3]);
	Set_VectS(vd, 4, VDest[4]);
	Set_VectS(vd, 5, VDest[5]);
	Set_VectS(vd, 6, VDest[6]);
	Set_VectS(vd, 7, VDest[7]);
}

//
// VSUBC: Subtract two vectors, no clamping, and set VFlags[0] if wraparound.
//

void RSP_Processor::VSUBC(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 0); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 1); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 2); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 3); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x03:		// [1q]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 4); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 5); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 6); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 7); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x04:		// [0h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 0); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 1); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 0); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 1); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 0); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 1); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 0); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 1); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x05:		// [1h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 2); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 3); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 2); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 3); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 2); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 3); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 2); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 3); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x06:		// [2h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 4); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 5); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 4); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 5); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 4); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 5); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 4); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 5); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x07:		// [3h]
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, 6); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, 7); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, 6); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, 7); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, 6); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, 7); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, 6); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, 7); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			VDest[0] = Get_VectS(vs, 0) - Get_VectS(vt, rs); if ((ushort)VDest[0] > (ushort)Get_VectS(vs, 0)) VFlags[0] |= 0x01;
			VDest[1] = Get_VectS(vs, 1) - Get_VectS(vt, rs); if ((ushort)VDest[1] > (ushort)Get_VectS(vs, 1)) VFlags[0] |= 0x02;
			VDest[2] = Get_VectS(vs, 2) - Get_VectS(vt, rs); if ((ushort)VDest[2] > (ushort)Get_VectS(vs, 2)) VFlags[0] |= 0x04;
			VDest[3] = Get_VectS(vs, 3) - Get_VectS(vt, rs); if ((ushort)VDest[3] > (ushort)Get_VectS(vs, 3)) VFlags[0] |= 0x08;
			VDest[4] = Get_VectS(vs, 4) - Get_VectS(vt, rs); if ((ushort)VDest[4] > (ushort)Get_VectS(vs, 4)) VFlags[0] |= 0x10;
			VDest[5] = Get_VectS(vs, 5) - Get_VectS(vt, rs); if ((ushort)VDest[5] > (ushort)Get_VectS(vs, 5)) VFlags[0] |= 0x20;
			VDest[6] = Get_VectS(vs, 6) - Get_VectS(vt, rs); if ((ushort)VDest[6] > (ushort)Get_VectS(vs, 6)) VFlags[0] |= 0x40;
			VDest[7] = Get_VectS(vs, 7) - Get_VectS(vt, rs); if ((ushort)VDest[7] > (ushort)Get_VectS(vs, 7)) VFlags[0] |= 0x80;
			break;
	}

	Set_VectS(vd, 0, VDest[0]);
	Set_VectS(vd, 1, VDest[1]);
	Set_VectS(vd, 2, VDest[2]);
	Set_VectS(vd, 3, VDest[3]);
	Set_VectS(vd, 4, VDest[4]);
	Set_VectS(vd, 5, VDest[5]);
	Set_VectS(vd, 6, VDest[6]);
	Set_VectS(vd, 7, VDest[7]);

	VFlags[0] |= 0x0000FF00;
}

//
// VSUT: ???  N64 tests show VSUT zeros out the entire destination vector regs, but DIS_STRINGS.TXT says:
//
//	vsut   $v%d, $v%s, $v%t
//	vector sut (vt - vs).
//

void RSP_Processor::VSUT(void)
{
	int vd;

	vd = RSP_DECODE_SA;

	Set_VectS(vd, 0, 0);
	Set_VectS(vd, 1, 0);
	Set_VectS(vd, 2, 0);
	Set_VectS(vd, 3, 0);
	Set_VectS(vd, 4, 0);
	Set_VectS(vd, 5, 0);
	Set_VectS(vd, 6, 0);
	Set_VectS(vd, 7, 0);
}

//
// VRCPH: Store previous "high_source" into destination, then store the source into "recip_hi".
//
// "high_source" is S15 no fractional portion, and "recip_hi" is 16 bit, no fractional portion.
//

void RSP_Processor::VRCPH(void)
{
	int vd, ved, vs, ves;

	vd  = RSP_DECODE_SA;
	ved = RSP_DECODE_RD & 0x07;
	vs  = RSP_DECODE_RT;
	ves = RSP_DECODE_RS & 0x07;

	// Write the current "high_source" variable to the destination vector.
	Set_VectS(vd, ved, high_source);

	// Now store away the "recip_hi" portion.
	recip_hi = Get_VectS(vs, ves);
}

/*
// VRCPL: Do: destvect = low portion of [0.4999847412109375 / ((recip_hi << 16) | source_vect)],
//		then store the high portion into "high_source".
*/

//
// VRCPL: Do: destvect = low portion of [0.4999963 / ((recip_hi << 16) | source_vect)],
//		then store the high portion into "high_source".
// 
// "high_source" is S15 no fractional portion, "source_vect" is .16 bit, all fractional.
//

void RSP_Processor::VRCPL(void)
{
	int vd, ved, vs, ves;
	Fixed32 recip_fp, final_recip;
	double temp;

	vd  = RSP_DECODE_SA;
	ved = RSP_DECODE_RD & 0x07;
	vs  = RSP_DECODE_RT;
	ves = RSP_DECODE_RS & 0x07;

	// Get the source vector and build a 16.16 fixed point.
	recip_fp = (((long)recip_hi) << 16) | Get_VectS(vs, ves);

	// Handle division by zero...
	if (recip_fp == 0x00000000)
	{
		final_recip = 0x7FFFFFFF;
	}
	else
	{
		// Now do the ~.5 reciprocal.
		temp = 0.4999963 / FIXED_TO_DOUBLE(recip_fp);
		final_recip = DOUBLE_TO_FIXED(temp);
	}

	// Store the integer portion into "high_source" for later use.
	high_source = FIXED_TO_INT(final_recip);

	// Finally, truncate integer portion and store to destination vector.
	Set_VectS(vd, ved, (ushort)final_recip);
}

//
// VMUDN: Multiply two vectors, store result in accumulator.
//

void RSP_Processor::VMUDN(void)
{
	int vd, vs, vt, rs;
	ulong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x03:		// [1q]
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x04:		// [0h]
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x05:		// [1h]
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x06:		// [2h]
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x07:		// [3h]
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 0); AccumN[0] = (ushort)temp; AccumH[0] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 1); AccumN[1] = (ushort)temp; AccumH[1] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 2); AccumN[2] = (ushort)temp; AccumH[2] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 3); AccumN[3] = (ushort)temp; AccumH[3] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 4); AccumN[4] = (ushort)temp; AccumH[4] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 5); AccumN[5] = (ushort)temp; AccumH[5] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 6); AccumN[6] = (ushort)temp; AccumH[6] = (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 7); AccumN[7] = (ushort)temp; AccumH[7] = (ushort)(temp >> 16);
			break;
	}

	Set_VectS(vd, 0, AccumN[0]);
	Set_VectS(vd, 1, AccumN[1]);
	Set_VectS(vd, 2, AccumN[2]);
	Set_VectS(vd, 3, AccumN[3]);
	Set_VectS(vd, 4, AccumN[4]);
	Set_VectS(vd, 5, AccumN[5]);
	Set_VectS(vd, 6, AccumN[6]);
	Set_VectS(vd, 7, AccumN[7]);
}

//
// VMADN: Multiply two vectors and add multiply to accumulator, setting destination to new accumulator.
//

void RSP_Processor::VMADN(void)
{
	int vd, vs, vt, rs;
	ulong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x03:		// [1q]
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x04:		// [0h]
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x05:		// [1h]
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x06:		// [2h]
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x07:		// [3h]
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 0); if ((ushort)(temp + AccumN[0]) < (ushort)temp) AccumH[0]++; AccumN[0] += (ushort)temp; AccumH[0] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 1); if ((ushort)(temp + AccumN[1]) < (ushort)temp) AccumH[1]++; AccumN[1] += (ushort)temp; AccumH[1] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 2); if ((ushort)(temp + AccumN[2]) < (ushort)temp) AccumH[2]++; AccumN[2] += (ushort)temp; AccumH[2] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 3); if ((ushort)(temp + AccumN[3]) < (ushort)temp) AccumH[3]++; AccumN[3] += (ushort)temp; AccumH[3] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 4); if ((ushort)(temp + AccumN[4]) < (ushort)temp) AccumH[4]++; AccumN[4] += (ushort)temp; AccumH[4] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 5); if ((ushort)(temp + AccumN[5]) < (ushort)temp) AccumH[5]++; AccumN[5] += (ushort)temp; AccumH[5] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 6); if ((ushort)(temp + AccumN[6]) < (ushort)temp) AccumH[6]++; AccumN[6] += (ushort)temp; AccumH[6] += (ushort)(temp >> 16);
			temp = (ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 7); if ((ushort)(temp + AccumN[7]) < (ushort)temp) AccumH[7]++; AccumN[7] += (ushort)temp; AccumH[7] += (ushort)(temp >> 16);
			break;
	}

	Set_VectS(vd, 0, AccumN[0]);
	Set_VectS(vd, 1, AccumN[1]);
	Set_VectS(vd, 2, AccumN[2]);
	Set_VectS(vd, 3, AccumN[3]);
	Set_VectS(vd, 4, AccumN[4]);
	Set_VectS(vd, 5, AccumN[5]);
	Set_VectS(vd, 6, AccumN[6]);
	Set_VectS(vd, 7, AccumN[7]);
}

//
// VMUDH: Multiply two vectors, clipping value at 7FFFh if it overflows, 8000h if it underflows, setting accumulator to result.
//

void RSP_Processor::VMUDH(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	// Zap "normal" accumulators.
	AccumN[0] = 0x0000;
	AccumN[1] = 0x0000;
	AccumN[2] = 0x0000;
	AccumN[3] = 0x0000;
	AccumN[4] = 0x0000;
	AccumN[5] = 0x0000;
	AccumN[6] = 0x0000;
	AccumN[7] = 0x0000;

	switch (rs)
	{
		case 0x00:		// None
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x03:		// [1q]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x04:		// [0h]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x05:		// [1h]
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x06:		// [2h]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x07:		// [3h]
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 0); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[0] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 1); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[1] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 2); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[2] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 3); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[3] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 4); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[4] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 5); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[5] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 6); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[6] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 7); if (temp > 0x7FFF) temp = 0x7FFF; else if ((slong)temp < (slong)0xFFFF8000) temp = 0x8000; AccumH[7] = (ushort)temp;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

//
// VMADH: Multiply two vectors, clipping value at 7FFFh if it overflows, 8000h if it underflows, adding to accumulator and
//	setting destination to accumulator.
//

void RSP_Processor::VMADH(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x03:		// [1q]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x04:		// [0h]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x05:		// [1h]
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x06:		// [2h]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x07:		// [3h]
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 0); if ((slong)temp + (slong)SignExtend16(AccumH[0]) > 0x7FFF) AccumH[0] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[0]) < (slong)0xFFFF8000) AccumH[0] = 0x8000; else AccumH[0] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 1); if ((slong)temp + (slong)SignExtend16(AccumH[1]) > 0x7FFF) AccumH[1] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[1]) < (slong)0xFFFF8000) AccumH[1] = 0x8000; else AccumH[1] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 2); if ((slong)temp + (slong)SignExtend16(AccumH[2]) > 0x7FFF) AccumH[2] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[2]) < (slong)0xFFFF8000) AccumH[2] = 0x8000; else AccumH[2] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 3); if ((slong)temp + (slong)SignExtend16(AccumH[3]) > 0x7FFF) AccumH[3] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[3]) < (slong)0xFFFF8000) AccumH[3] = 0x8000; else AccumH[3] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 4); if ((slong)temp + (slong)SignExtend16(AccumH[4]) > 0x7FFF) AccumH[4] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[4]) < (slong)0xFFFF8000) AccumH[4] = 0x8000; else AccumH[4] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 5); if ((slong)temp + (slong)SignExtend16(AccumH[5]) > 0x7FFF) AccumH[5] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[5]) < (slong)0xFFFF8000) AccumH[5] = 0x8000; else AccumH[5] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 6); if ((slong)temp + (slong)SignExtend16(AccumH[6]) > 0x7FFF) AccumH[6] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[6]) < (slong)0xFFFF8000) AccumH[6] = 0x8000; else AccumH[6] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 7); if ((slong)temp + (slong)SignExtend16(AccumH[7]) > 0x7FFF) AccumH[7] = 0x7FFF; else if ((slong)temp + (slong)SignExtend16(AccumH[7]) < (slong)0xFFFF8000) AccumH[7] = 0x8000; else AccumH[7] += (ushort)temp;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

//
// VMUDL: Unsigned multiply of two vectors, storing upper 16 bits to accumulator and writing accumulator to destination.
//

void RSP_Processor::VMUDL(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	// Zap "high" accumulators.
	AccumH[0] = 0x0000;
	AccumH[1] = 0x0000;
	AccumH[2] = 0x0000;
	AccumH[3] = 0x0000;
	AccumH[4] = 0x0000;
	AccumH[5] = 0x0000;
	AccumH[6] = 0x0000;
	AccumH[7] = 0x0000;

	switch (rs)
	{
		case 0x00:		// None
			AccumN[0] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			AccumN[0] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x03:		// [1q]
			AccumN[0] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x04:		// [0h]
			AccumN[0] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x05:		// [1h]
			AccumN[0] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x06:		// [2h]
			AccumN[0] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x07:		// [3h]
			AccumN[0] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			AccumN[0] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] = ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;
	}

	Set_VectS(vd, 0, AccumN[0]);
	Set_VectS(vd, 1, AccumN[1]);
	Set_VectS(vd, 2, AccumN[2]);
	Set_VectS(vd, 3, AccumN[3]);
	Set_VectS(vd, 4, AccumN[4]);
	Set_VectS(vd, 5, AccumN[5]);
	Set_VectS(vd, 6, AccumN[6]);
	Set_VectS(vd, 7, AccumN[7]);
}

//
// VMADL: Unsigned multiply of two vectors, adding upper 16 bits of result to accumulator and setting destination register
//	to accumulator.
//

void RSP_Processor::VMADL(void)
{
	int vd, vs, vt, rs;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			AccumN[0] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			AccumN[0] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x03:		// [1q]
			AccumN[0] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x04:		// [0h]
			AccumN[0] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 0) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 1) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x05:		// [1h]
			AccumN[0] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 2) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 3) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x06:		// [2h]
			AccumN[0] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 4) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 5) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x07:		// [3h]
			AccumN[0] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, 6) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, 7) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			AccumN[0] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 0)) >> 16;
			AccumN[1] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 1)) >> 16;
			AccumN[2] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 2)) >> 16;
			AccumN[3] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 3)) >> 16;
			AccumN[4] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 4)) >> 16;
			AccumN[5] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 5)) >> 16;
			AccumN[6] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 6)) >> 16;
			AccumN[7] += ((ushort)Get_VectS(vt, rs) * (ushort)Get_VectS(vs, 7)) >> 16;
			break;
	}

	Set_VectS(vd, 0, AccumN[0]);
	Set_VectS(vd, 1, AccumN[1]);
	Set_VectS(vd, 2, AccumN[2]);
	Set_VectS(vd, 3, AccumN[3]);
	Set_VectS(vd, 4, AccumN[4]);
	Set_VectS(vd, 5, AccumN[5]);
	Set_VectS(vd, 6, AccumN[6]);
	Set_VectS(vd, 7, AccumN[7]);
}

//
// VMUDM: Signed multiply of two vectors, storing upper 16 bits of result to accumulator and destination.
//

void RSP_Processor::VMUDM(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x03:		// [1q]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x04:		// [0h]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x05:		// [1h]
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x06:		// [2h]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x07:		// [3h]
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 0); AccumH[0] = (ushort)(temp >> 16); AccumN[0] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 1); AccumH[1] = (ushort)(temp >> 16); AccumN[1] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 2); AccumH[2] = (ushort)(temp >> 16); AccumN[2] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 3); AccumH[3] = (ushort)(temp >> 16); AccumN[3] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 4); AccumH[4] = (ushort)(temp >> 16); AccumN[4] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 5); AccumH[5] = (ushort)(temp >> 16); AccumN[5] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 6); AccumH[6] = (ushort)(temp >> 16); AccumN[6] = (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 7); AccumH[7] = (ushort)(temp >> 16); AccumN[7] = (ushort)temp;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

//
// VMADM: Signed multiply of two vectors, adding upper 16 bits of result to accumulator, then setting destination register
//	to accumulator.
//

void RSP_Processor::VMADM(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x03:		// [1q]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x04:		// [0h]
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 0) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 1) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x05:		// [1h]
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 2) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 3) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x06:		// [2h]
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 4) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 5) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x07:		// [3h]
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, 6) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, 7) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 0); AccumH[0] += (ushort)(temp >> 16); AccumN[0] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 1); AccumH[1] += (ushort)(temp >> 16); AccumN[1] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 2); AccumH[2] += (ushort)(temp >> 16); AccumN[2] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 3); AccumH[3] += (ushort)(temp >> 16); AccumN[3] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 4); AccumH[4] += (ushort)(temp >> 16); AccumN[4] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 5); AccumH[5] += (ushort)(temp >> 16); AccumN[5] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 6); AccumH[6] += (ushort)(temp >> 16); AccumN[6] += (ushort)temp;
			temp = Get_VectS(vt, rs) * Get_VectS(vs, 7); AccumH[7] += (ushort)(temp >> 16); AccumN[7] += (ushort)temp;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

//
// VMULF: Signed multiply of two vectors, except multiplier is multiplied by 2 before the multiply operation.  The final
//  result is then rounded down by 16 bits.  The final result is stored in the destination vector and high accumulator
//	for use later.
//
//  The multiply's result is also truncated to the lower 16 bits and XORed by 8000h.  This result is then stored in the
//  normal accumulator for use later.
//
//  Note: Instead of multiplying the multiplier by 2, we shift left by 1 for speed.
//

void RSP_Processor::VMULF(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x03:		// [1q]
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x04:		// [0h]
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x05:		// [1h]
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x06:		// [2h]
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x07:		// [3h]
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 0); AccumH[0] = RoundDown16(temp); AccumN[0] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 1); AccumH[1] = RoundDown16(temp); AccumN[1] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 2); AccumH[2] = RoundDown16(temp); AccumN[2] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 3); AccumH[3] = RoundDown16(temp); AccumN[3] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 4); AccumH[4] = RoundDown16(temp); AccumN[4] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 5); AccumH[5] = RoundDown16(temp); AccumN[5] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 6); AccumH[6] = RoundDown16(temp); AccumN[6] = ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 7); AccumH[7] = RoundDown16(temp); AccumN[7] = ((ushort)temp) ^ 0x8000;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

//
// VMACF: Signed multiply accumulate of two vectors.  This is identical to VMULF except the results are added to the
//  accumulators.  Again, the multiplier is multiplied by 2 before the multiply operation.  The final result is then 
//  rounded down by 16 bits.  The final result is added to the high accumulator and stored to the destination vector.
//
//  The multiply's result is also truncated to the lower 16 bits and XORed by 8000h.  This result is then added to the
//  normal accumulator for use later.
//
//  Note: Instead of multiplying the multiplier by 2, we shift left by 1 for speed.
//

void RSP_Processor::VMACF(void)
{
	int vd, vs, vt, rs;
	slong temp;

	vd = RSP_DECODE_SA;
	vs = RSP_DECODE_RD;
	vt = RSP_DECODE_RT;
	rs = RSP_DECODE_RS & 0x0F;

	switch (rs)
	{
		case 0x00:		// None
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x01:		// ???
			break;

		case 0x02:		// [0q]
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x03:		// [1q]
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x04:		// [0h]
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 0)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 1)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x05:		// [1h]
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 2)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 3)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x06:		// [2h]
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 4)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 5)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x07:		// [3h]
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 6)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, 7)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;

		case 0x08:		// [0]
		case 0x09:		// [1]
		case 0x0A:		// [2]
		case 0x0B:		// [3]
		case 0x0C:		// [4]
		case 0x0D:		// [5]
		case 0x0E:		// [6]
		case 0x0F:		// [7]
			rs -= 0x08;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 0); AccumH[0] += RoundDown16(temp); AccumN[0] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 1); AccumH[1] += RoundDown16(temp); AccumN[1] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 2); AccumH[2] += RoundDown16(temp); AccumN[2] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 3); AccumH[3] += RoundDown16(temp); AccumN[3] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 4); AccumH[4] += RoundDown16(temp); AccumN[4] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 5); AccumH[5] += RoundDown16(temp); AccumN[5] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 6); AccumH[6] += RoundDown16(temp); AccumN[6] += ((ushort)temp) ^ 0x8000;
			temp = ((Get_VectS(vt, rs)) << 1) * Get_VectS(vs, 7); AccumH[7] += RoundDown16(temp); AccumN[7] += ((ushort)temp) ^ 0x8000;
			break;
	}

	Set_VectS(vd, 0, AccumH[0]);
	Set_VectS(vd, 1, AccumH[1]);
	Set_VectS(vd, 2, AccumH[2]);
	Set_VectS(vd, 3, AccumH[3]);
	Set_VectS(vd, 4, AccumH[4]);
	Set_VectS(vd, 5, AccumH[5]);
	Set_VectS(vd, 6, AccumH[6]);
	Set_VectS(vd, 7, AccumH[7]);
}

void RSP_Processor::Reserved_Instruction(void)
{
    char buf[128], tmp[64];

	sp_pc.PC -= 4;

    // Check to see if this is just a breakpoint opcode.
    if (HasBreakpoint(sp_pc.PC))
    {
        sprintf(buf, "Encountered breakpoint at %08X", sp_pc.PC);
        MessageBox(NULL, buf, NULL, MB_OK);
    }
    else
    {
		if (!stop_on_unhandled) return;

		raw_opcode_addr = sp_pc.PC;
		MakeDebugOpcode();
		RSP_OpcodePrint(tmp);

		sprintf(buf, "Unhandled RSP Opcode (%08X): %s (%02X %02X %02X %02X)", sp_pc.PC, tmp, raw_opcode[0], raw_opcode[1], raw_opcode[2],
			raw_opcode[3]);
		MessageBox(NULL, buf, NULL, MB_OK);
	}

	NextPC = sp_pc.PC;
    RSP_running = FALSE;

    if (inDebugger) PostMessage(MainhWnd, WM_COMMAND, ID_DEBUG_REFRESH, 0);
}
