2008-11-14 20:47:53 +00:00
|
|
|
/*
|
2015-11-10 05:21:49 +00:00
|
|
|
* RSP Compiler plug in for Project64 (A Nintendo 64 emulator).
|
2008-11-14 20:47:53 +00:00
|
|
|
*
|
|
|
|
* (c) Copyright 2001 jabo (jabo@emulation64.com) and
|
|
|
|
* zilmar (zilmar@emulation64.com)
|
|
|
|
*
|
|
|
|
* pj64 homepage: www.pj64.net
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute Project64 in both binary and
|
|
|
|
* source form, for non-commercial purposes, is hereby granted without fee,
|
|
|
|
* providing that this license information and copyright notice appear with
|
|
|
|
* all copies and any derived work.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event shall the authors be held liable for any damages
|
|
|
|
* arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Project64 is freeware for PERSONAL USE only. Commercial users should
|
|
|
|
* seek permission of the copyright holders first. Commercial use includes
|
|
|
|
* charging money for Project64 or software derived from Project64.
|
|
|
|
*
|
|
|
|
* The copyright holders request that bug fixes and improvements to the code
|
|
|
|
* should be forwarded to them so if they want them.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "rsp.h"
|
|
|
|
#include "x86.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "RSP registers.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#define PUTDST8(dest,value) (*((BYTE *)(dest))=(BYTE)(value)); dest += 1;
|
|
|
|
#define PUTDST16(dest,value) (*((WORD *)(dest))=(WORD)(value)); dest += 2;
|
|
|
|
#define PUTDST32(dest,value) (*((DWORD *)(dest))=(DWORD)(value)); dest += 4;
|
2015-10-30 19:48:30 +00:00
|
|
|
#define PUTDSTPTR(dest, value) \
|
|
|
|
*(void **)(dest) = (void *)(value); dest += sizeof(void *);
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
char * sse_Strings[8] = {
|
|
|
|
"xmm0", "xmm1", "xmm2", "xmm3",
|
|
|
|
"xmm4", "xmm5", "xmm6", "xmm7"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define sse_Name(Reg) (sse_Strings[(Reg)])
|
|
|
|
|
|
|
|
void SseMoveAlignedVariableToReg(void *Variable, char *VariableName, int sseReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movaps %s, xmmword ptr [%s]",sse_Name(sseReg), VariableName);
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x05; break;
|
|
|
|
case x86_XMM1: x86Command = 0x0D; break;
|
|
|
|
case x86_XMM2: x86Command = 0x15; break;
|
|
|
|
case x86_XMM3: x86Command = 0x1D; break;
|
|
|
|
case x86_XMM4: x86Command = 0x25; break;
|
|
|
|
case x86_XMM5: x86Command = 0x2D; break;
|
|
|
|
case x86_XMM6: x86Command = 0x35; break;
|
|
|
|
case x86_XMM7: x86Command = 0x3D; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x280f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, Variable);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveAlignedN64MemToReg(int sseReg, int AddrReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movaps %s, xmmword ptr [Dmem+%s]",sse_Name(sseReg), x86_Name(AddrReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x80; break;
|
|
|
|
case x86_XMM1: x86Command = 0x88; break;
|
|
|
|
case x86_XMM2: x86Command = 0x90; break;
|
|
|
|
case x86_XMM3: x86Command = 0x98; break;
|
|
|
|
case x86_XMM4: x86Command = 0xA0; break;
|
|
|
|
case x86_XMM5: x86Command = 0xA8; break;
|
|
|
|
case x86_XMM6: x86Command = 0xB0; break;
|
|
|
|
case x86_XMM7: x86Command = 0xB8; break;
|
|
|
|
}
|
|
|
|
switch (AddrReg) {
|
|
|
|
case x86_EAX: x86Command += 0x00; break;
|
|
|
|
case x86_EBX: x86Command += 0x03; break;
|
|
|
|
case x86_ECX: x86Command += 0x01; break;
|
|
|
|
case x86_EDX: x86Command += 0x02; break;
|
|
|
|
case x86_ESI: x86Command += 0x06; break;
|
|
|
|
case x86_EDI: x86Command += 0x07; break;
|
|
|
|
case x86_ESP: x86Command += 0x04; break;
|
|
|
|
case x86_EBP: x86Command += 0x05; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x280f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, RSPInfo.DMEM);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveAlignedRegToVariable(int sseReg, void *Variable, char *VariableName) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movaps xmmword ptr [%s], %s",VariableName, sse_Name(sseReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x05; break;
|
|
|
|
case x86_XMM1: x86Command = 0x0D; break;
|
|
|
|
case x86_XMM2: x86Command = 0x15; break;
|
|
|
|
case x86_XMM3: x86Command = 0x1D; break;
|
|
|
|
case x86_XMM4: x86Command = 0x25; break;
|
|
|
|
case x86_XMM5: x86Command = 0x2D; break;
|
|
|
|
case x86_XMM6: x86Command = 0x35; break;
|
|
|
|
case x86_XMM7: x86Command = 0x3D; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x290f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, Variable);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveAlignedRegToN64Mem(int sseReg, int AddrReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movaps xmmword ptr [Dmem+%s], %s",x86_Name(AddrReg),sse_Name(sseReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x80; break;
|
|
|
|
case x86_XMM1: x86Command = 0x88; break;
|
|
|
|
case x86_XMM2: x86Command = 0x90; break;
|
|
|
|
case x86_XMM3: x86Command = 0x98; break;
|
|
|
|
case x86_XMM4: x86Command = 0xA0; break;
|
|
|
|
case x86_XMM5: x86Command = 0xA8; break;
|
|
|
|
case x86_XMM6: x86Command = 0xB0; break;
|
|
|
|
case x86_XMM7: x86Command = 0xB8; break;
|
|
|
|
}
|
|
|
|
switch (AddrReg) {
|
|
|
|
case x86_EAX: x86Command += 0x00; break;
|
|
|
|
case x86_EBX: x86Command += 0x03; break;
|
|
|
|
case x86_ECX: x86Command += 0x01; break;
|
|
|
|
case x86_EDX: x86Command += 0x02; break;
|
|
|
|
case x86_ESI: x86Command += 0x06; break;
|
|
|
|
case x86_EDI: x86Command += 0x07; break;
|
|
|
|
case x86_ESP: x86Command += 0x04; break;
|
|
|
|
case x86_EBP: x86Command += 0x05; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x290f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, RSPInfo.DMEM);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveUnalignedVariableToReg(void *Variable, char *VariableName, int sseReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movups %s, xmmword ptr [%s]",sse_Name(sseReg), VariableName);
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x05; break;
|
|
|
|
case x86_XMM1: x86Command = 0x0D; break;
|
|
|
|
case x86_XMM2: x86Command = 0x15; break;
|
|
|
|
case x86_XMM3: x86Command = 0x1D; break;
|
|
|
|
case x86_XMM4: x86Command = 0x25; break;
|
|
|
|
case x86_XMM5: x86Command = 0x2D; break;
|
|
|
|
case x86_XMM6: x86Command = 0x35; break;
|
|
|
|
case x86_XMM7: x86Command = 0x3D; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x100f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, Variable);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveUnalignedN64MemToReg(int sseReg, int AddrReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movups %s, xmmword ptr [Dmem+%s]",sse_Name(sseReg), x86_Name(AddrReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x80; break;
|
|
|
|
case x86_XMM1: x86Command = 0x88; break;
|
|
|
|
case x86_XMM2: x86Command = 0x90; break;
|
|
|
|
case x86_XMM3: x86Command = 0x98; break;
|
|
|
|
case x86_XMM4: x86Command = 0xA0; break;
|
|
|
|
case x86_XMM5: x86Command = 0xA8; break;
|
|
|
|
case x86_XMM6: x86Command = 0xB0; break;
|
|
|
|
case x86_XMM7: x86Command = 0xB8; break;
|
|
|
|
}
|
|
|
|
switch (AddrReg) {
|
|
|
|
case x86_EAX: x86Command += 0x00; break;
|
|
|
|
case x86_EBX: x86Command += 0x03; break;
|
|
|
|
case x86_ECX: x86Command += 0x01; break;
|
|
|
|
case x86_EDX: x86Command += 0x02; break;
|
|
|
|
case x86_ESI: x86Command += 0x06; break;
|
|
|
|
case x86_EDI: x86Command += 0x07; break;
|
|
|
|
case x86_ESP: x86Command += 0x04; break;
|
|
|
|
case x86_EBP: x86Command += 0x05; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x100f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, RSPInfo.DMEM);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveUnalignedRegToVariable(int sseReg, void *Variable, char *VariableName) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movups xmmword ptr [%s], %s",VariableName, sse_Name(sseReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x05; break;
|
|
|
|
case x86_XMM1: x86Command = 0x0D; break;
|
|
|
|
case x86_XMM2: x86Command = 0x15; break;
|
|
|
|
case x86_XMM3: x86Command = 0x1D; break;
|
|
|
|
case x86_XMM4: x86Command = 0x25; break;
|
|
|
|
case x86_XMM5: x86Command = 0x2D; break;
|
|
|
|
case x86_XMM6: x86Command = 0x35; break;
|
|
|
|
case x86_XMM7: x86Command = 0x3D; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x110f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, Variable);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveUnalignedRegToN64Mem(int sseReg, int AddrReg) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movups xmmword ptr [Dmem+%s], %s",x86_Name(AddrReg),sse_Name(sseReg));
|
|
|
|
|
|
|
|
switch (sseReg) {
|
|
|
|
case x86_XMM0: x86Command = 0x80; break;
|
|
|
|
case x86_XMM1: x86Command = 0x88; break;
|
|
|
|
case x86_XMM2: x86Command = 0x90; break;
|
|
|
|
case x86_XMM3: x86Command = 0x98; break;
|
|
|
|
case x86_XMM4: x86Command = 0xA0; break;
|
|
|
|
case x86_XMM5: x86Command = 0xA8; break;
|
|
|
|
case x86_XMM6: x86Command = 0xB0; break;
|
|
|
|
case x86_XMM7: x86Command = 0xB8; break;
|
|
|
|
}
|
|
|
|
switch (AddrReg) {
|
|
|
|
case x86_EAX: x86Command += 0x00; break;
|
|
|
|
case x86_EBX: x86Command += 0x03; break;
|
|
|
|
case x86_ECX: x86Command += 0x01; break;
|
|
|
|
case x86_EDX: x86Command += 0x02; break;
|
|
|
|
case x86_ESI: x86Command += 0x06; break;
|
|
|
|
case x86_EDI: x86Command += 0x07; break;
|
|
|
|
case x86_ESP: x86Command += 0x04; break;
|
|
|
|
case x86_EBP: x86Command += 0x05; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x110f);
|
|
|
|
PUTDST8(RecompPos, x86Command);
|
2015-10-30 19:48:30 +00:00
|
|
|
PUTDSTPTR(RecompPos, RSPInfo.DMEM);
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SseMoveRegToReg(int Dest, int Source) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" movaps %s, %s", sse_Name(Dest), sse_Name(Source));
|
|
|
|
|
|
|
|
switch (Dest) {
|
|
|
|
case x86_XMM0: x86Command = 0x00; break;
|
|
|
|
case x86_XMM1: x86Command = 0x08; break;
|
|
|
|
case x86_XMM2: x86Command = 0x10; break;
|
|
|
|
case x86_XMM3: x86Command = 0x18; break;
|
|
|
|
case x86_XMM4: x86Command = 0x20; break;
|
|
|
|
case x86_XMM5: x86Command = 0x28; break;
|
|
|
|
case x86_XMM6: x86Command = 0x30; break;
|
|
|
|
case x86_XMM7: x86Command = 0x38; break;
|
|
|
|
}
|
|
|
|
switch (Source) {
|
|
|
|
case x86_XMM0: x86Command += 0x00; break;
|
|
|
|
case x86_XMM1: x86Command += 0x01; break;
|
|
|
|
case x86_XMM2: x86Command += 0x02; break;
|
|
|
|
case x86_XMM3: x86Command += 0x03; break;
|
|
|
|
case x86_XMM4: x86Command += 0x04; break;
|
|
|
|
case x86_XMM5: x86Command += 0x05; break;
|
|
|
|
case x86_XMM6: x86Command += 0x06; break;
|
|
|
|
case x86_XMM7: x86Command += 0x07; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTDST16(RecompPos,0x280f);
|
|
|
|
PUTDST8(RecompPos, 0xC0 | x86Command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SseXorRegToReg(int Dest, int Source) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" xorps %s, %s", sse_Name(Dest), sse_Name(Source));
|
|
|
|
|
|
|
|
switch (Dest) {
|
|
|
|
case x86_XMM0: x86Command = 0x00; break;
|
|
|
|
case x86_XMM1: x86Command = 0x08; break;
|
|
|
|
case x86_XMM2: x86Command = 0x10; break;
|
|
|
|
case x86_XMM3: x86Command = 0x18; break;
|
|
|
|
case x86_XMM4: x86Command = 0x20; break;
|
|
|
|
case x86_XMM5: x86Command = 0x28; break;
|
|
|
|
case x86_XMM6: x86Command = 0x30; break;
|
2015-01-14 09:48:47 +00:00
|
|
|
case x86_XMM7: x86Command = 0x38; break;
|
2008-11-14 20:47:53 +00:00
|
|
|
}
|
|
|
|
switch (Source) {
|
|
|
|
case x86_XMM0: x86Command += 0x00; break;
|
|
|
|
case x86_XMM1: x86Command += 0x01; break;
|
|
|
|
case x86_XMM2: x86Command += 0x02; break;
|
|
|
|
case x86_XMM3: x86Command += 0x03; break;
|
|
|
|
case x86_XMM4: x86Command += 0x04; break;
|
|
|
|
case x86_XMM5: x86Command += 0x05; break;
|
|
|
|
case x86_XMM6: x86Command += 0x06; break;
|
|
|
|
case x86_XMM7: x86Command += 0x07; break;
|
|
|
|
}
|
|
|
|
PUTDST16(RecompPos,0x570f);
|
|
|
|
PUTDST8(RecompPos, 0xC0 | x86Command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SseShuffleReg(int Dest, int Source, BYTE Immed) {
|
2015-01-29 08:57:13 +00:00
|
|
|
BYTE x86Command = 0;
|
2008-11-14 20:47:53 +00:00
|
|
|
|
|
|
|
CPU_Message(" shufps %s, %s, %02X", sse_Name(Dest), sse_Name(Source), Immed);
|
|
|
|
|
|
|
|
switch (Dest) {
|
|
|
|
case x86_XMM0: x86Command = 0x00; break;
|
|
|
|
case x86_XMM1: x86Command = 0x08; break;
|
|
|
|
case x86_XMM2: x86Command = 0x10; break;
|
|
|
|
case x86_XMM3: x86Command = 0x18; break;
|
|
|
|
case x86_XMM4: x86Command = 0x20; break;
|
|
|
|
case x86_XMM5: x86Command = 0x28; break;
|
|
|
|
case x86_XMM6: x86Command = 0x30; break;
|
|
|
|
case x86_XMM7: x86Command = 0x38; break;
|
|
|
|
}
|
|
|
|
switch (Source) {
|
|
|
|
case x86_XMM0: x86Command += 0x00; break;
|
|
|
|
case x86_XMM1: x86Command += 0x01; break;
|
|
|
|
case x86_XMM2: x86Command += 0x02; break;
|
|
|
|
case x86_XMM3: x86Command += 0x03; break;
|
|
|
|
case x86_XMM4: x86Command += 0x04; break;
|
|
|
|
case x86_XMM5: x86Command += 0x05; break;
|
|
|
|
case x86_XMM6: x86Command += 0x06; break;
|
|
|
|
case x86_XMM7: x86Command += 0x07; break;
|
|
|
|
}
|
|
|
|
PUTDST16(RecompPos,0xC60f);
|
|
|
|
PUTDST8(RecompPos, 0xC0 | x86Command);
|
|
|
|
PUTDST8(RecompPos, Immed);
|
|
|
|
}
|