From b6562bb8bde57368f86d5c628be86f6a5c0981f1 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 22 Jul 2010 20:58:54 +0200 Subject: Remove the USF plugin as it is non-DFSG free. rm -r src/usf/ --- src/usf/Makefile | 43 - src/usf/audio.c | 112 - src/usf/audio.h | 13 - src/usf/audio_hle.h | 140 -- src/usf/audio_hle_main.c | 83 - src/usf/audio_ucode1.c | 755 ------ src/usf/audio_ucode2.c | 904 ------- src/usf/audio_ucode3.c | 666 ------ src/usf/audio_ucode3mp3.c | 588 ----- src/usf/config.h | 63 - src/usf/cpu.c | 640 ----- src/usf/cpu.h | 108 - src/usf/dma.c | 177 -- src/usf/dma.h | 34 - src/usf/exception.c | 228 -- src/usf/exception.h | 75 - src/usf/interpreter_cpu.c | 738 ------ src/usf/interpreter_cpu.h | 37 - src/usf/interpreter_ops.c | 1362 ----------- src/usf/interpreter_ops.h | 210 -- src/usf/main.c | 41 - src/usf/main.h | 10 - src/usf/memory.c | 1890 --------------- src/usf/memory.h | 84 - src/usf/opcode.h | 274 --- src/usf/pif.c | 97 - src/usf/pif.h | 31 - src/usf/psftag.c | 528 ----- src/usf/psftag.h | 57 - src/usf/recompiler_cpu.c | 2780 ---------------------- src/usf/recompiler_cpu.h | 240 -- src/usf/recompiler_fpu_ops.c | 1089 --------- src/usf/recompiler_ops.c | 4657 ------------------------------------- src/usf/recompiler_ops.h | 196 -- src/usf/registers.c | 1054 --------- src/usf/registers.h | 403 ---- src/usf/rsp.c | 1065 --------- src/usf/rsp.h | 423 ---- src/usf/rsp_interpreter_cpu.c | 1706 -------------- src/usf/rsp_mmx.c | 143 -- src/usf/rsp_recompiler_analysis.c | 1780 -------------- src/usf/rsp_recompiler_cpu.c | 954 -------- src/usf/rsp_recompiler_cpu.h | 116 - src/usf/rsp_recompiler_ops.c | 4619 ------------------------------------ src/usf/rsp_recompiler_ops.h | 158 -- src/usf/rsp_registers.h | 149 -- src/usf/rsp_sse.c | 84 - src/usf/rsp_x86.c | 1366 ----------- src/usf/rsp_x86.h | 552 ----- src/usf/tlb.c | 200 -- src/usf/tlb.h | 108 - src/usf/types.h | 77 - src/usf/usf.c | 522 ----- src/usf/usf.h | 27 - src/usf/x86.c | 810 ------- src/usf/x86.h | 544 ----- src/usf/x86_fpu.c | 529 ----- 57 files changed, 36339 deletions(-) delete mode 100644 src/usf/Makefile delete mode 100644 src/usf/audio.c delete mode 100644 src/usf/audio.h delete mode 100644 src/usf/audio_hle.h delete mode 100644 src/usf/audio_hle_main.c delete mode 100644 src/usf/audio_ucode1.c delete mode 100644 src/usf/audio_ucode2.c delete mode 100644 src/usf/audio_ucode3.c delete mode 100644 src/usf/audio_ucode3mp3.c delete mode 100644 src/usf/config.h delete mode 100644 src/usf/cpu.c delete mode 100644 src/usf/cpu.h delete mode 100644 src/usf/dma.c delete mode 100644 src/usf/dma.h delete mode 100644 src/usf/exception.c delete mode 100644 src/usf/exception.h delete mode 100644 src/usf/interpreter_cpu.c delete mode 100644 src/usf/interpreter_cpu.h delete mode 100644 src/usf/interpreter_ops.c delete mode 100644 src/usf/interpreter_ops.h delete mode 100644 src/usf/main.c delete mode 100644 src/usf/main.h delete mode 100644 src/usf/memory.c delete mode 100644 src/usf/memory.h delete mode 100644 src/usf/opcode.h delete mode 100644 src/usf/pif.c delete mode 100644 src/usf/pif.h delete mode 100644 src/usf/psftag.c delete mode 100644 src/usf/psftag.h delete mode 100644 src/usf/recompiler_cpu.c delete mode 100644 src/usf/recompiler_cpu.h delete mode 100644 src/usf/recompiler_fpu_ops.c delete mode 100644 src/usf/recompiler_ops.c delete mode 100644 src/usf/recompiler_ops.h delete mode 100644 src/usf/registers.c delete mode 100644 src/usf/registers.h delete mode 100644 src/usf/rsp.c delete mode 100644 src/usf/rsp.h delete mode 100644 src/usf/rsp_interpreter_cpu.c delete mode 100644 src/usf/rsp_mmx.c delete mode 100644 src/usf/rsp_recompiler_analysis.c delete mode 100644 src/usf/rsp_recompiler_cpu.c delete mode 100644 src/usf/rsp_recompiler_cpu.h delete mode 100644 src/usf/rsp_recompiler_ops.c delete mode 100644 src/usf/rsp_recompiler_ops.h delete mode 100644 src/usf/rsp_registers.h delete mode 100644 src/usf/rsp_sse.c delete mode 100644 src/usf/rsp_x86.c delete mode 100644 src/usf/rsp_x86.h delete mode 100644 src/usf/tlb.c delete mode 100644 src/usf/tlb.h delete mode 100644 src/usf/types.h delete mode 100644 src/usf/usf.c delete mode 100644 src/usf/usf.h delete mode 100644 src/usf/x86.c delete mode 100644 src/usf/x86.h delete mode 100644 src/usf/x86_fpu.c (limited to 'src') diff --git a/src/usf/Makefile b/src/usf/Makefile deleted file mode 100644 index a17bdb6..0000000 --- a/src/usf/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -PLUGIN = usf${PLUGIN_SUFFIX} - -SRCS = audio.c \ - audio_hle_main.c \ - audio_ucode1.c \ - audio_ucode2.c \ - audio_ucode3.c \ - audio_ucode3mp3.c \ - cpu.c \ - dma.c \ - exception.c \ - interpreter_cpu.c \ - interpreter_ops.c \ - main.c \ - memory.c \ - pif.c \ - psftag.c \ - recompiler_cpu.c \ - recompiler_fpu_ops.c \ - recompiler_ops.c \ - registers.c \ - rsp.c \ - rsp_interpreter_cpu.c \ - rsp_mmx.c \ - rsp_recompiler_analysis.c \ - rsp_recompiler_cpu.c \ - rsp_recompiler_ops.c \ - rsp_sse.c \ - rsp_x86.c \ - tlb.c \ - usf.c \ - x86.c \ - x86_fpu.c - -include ../../buildsys.mk -include ../../extra.mk - -plugindir := ${plugindir}/${INPUT_PLUGIN_DIR} - -CFLAGS += ${PLUGIN_CFLAGS} -O0 -CXXFLAGS += ${PLUGIN_CFLAGS} -O0 -CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} -I../.. -Ispu/ -I. -LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${MOWGLI_LIBS} -lz diff --git a/src/usf/audio.c b/src/usf/audio.c deleted file mode 100644 index 403009a..0000000 --- a/src/usf/audio.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "usf.h" -#include "audio_hle.h" -#include "memory.h" -#include "audio.h" -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -extern InputPlayback * pcontext; -int32_t SampleRate = 0; -static int16_t samplebuf[16384]; - -void OpenSound(void) -{ - if (pcontext->output->open_audio(FMT_S16_NE, SampleRate, 2) == 0) { - cpu_running = 0; - printf("Fail Starting audio\n"); - g_thread_exit(NULL); - } else { - } -} - -void AddBuffer(unsigned char *buf, unsigned int length) { - int32_t i = 0, out = 0; - double vol = 1.0; - - if(!cpu_running) - return; - - if(is_seeking) { - play_time += (((double)(length >> 2) / (double)SampleRate) * 1000.0); - if(play_time > (double)seek_time) { - is_seeking = 0; - } - return; - } - - if(play_time > track_time) { - vol = 1.0f - (((double)play_time - (double)track_time) / (double)fade_time); - } - - for(out = i = 0; i < (length >> 1); i+=2) - { - samplebuf[out++] = (int16_t)(vol * (double)((int16_t*)buf)[i+1]); - samplebuf[out++] = (int16_t)(vol * (double)((int16_t*)buf)[i]); - } - - pcontext->playing = play_time < (track_time + fade_time); - pcontext->eof = play_time >= (track_time + fade_time); - - play_time += (((double)(length >> 2) / (double)SampleRate) * 1000.0); - - pcontext->output->write_audio (samplebuf, length); - - if(play_time > (track_time + fade_time)) - { - cpu_running = 0; - } - -} - -void AiLenChanged(void) { - int32_t length = 0; - uint32_t address = (AI_DRAM_ADDR_REG & 0x00FFFFF8); - - length = AI_LEN_REG & 0x3FFF8; - - while(is_paused && !is_seeking && cpu_running) - g_usleep(10000); - - - AddBuffer(RDRAM+address, length); - - if(length && !(AI_STATUS_REG&0x80000000)) { - const float VSyncTiming = 789000.0f; - double BytesPerSecond = 48681812.0 / (AI_DACRATE_REG + 1) * 4; - double CountsPerSecond = (double)((((double)VSyncTiming) * (double)60.0)) * 2.0; - double CountsPerByte = (double)CountsPerSecond / (double)BytesPerSecond; - unsigned int IntScheduled = (unsigned int)((double)AI_LEN_REG * CountsPerByte); - - ChangeTimer(AiTimer,IntScheduled); - } - - if(enableFIFOfull) { - if(AI_STATUS_REG&0x40000000) - AI_STATUS_REG|=0x80000000; - } - - AI_STATUS_REG|=0x40000000; - -} - -unsigned int AiReadLength(void) { - AI_LEN_REG = 0; - return AI_LEN_REG; -} - -void AiDacrateChanged(unsigned int value) { - AI_DACRATE_REG = value; - SampleRate = 48681812 / (AI_DACRATE_REG + 1); - -} diff --git a/src/usf/audio.h b/src/usf/audio.h deleted file mode 100644 index e5dc94a..0000000 --- a/src/usf/audio.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _AUDIO_H_ -#define _AUDIO_H_ - -#include "usf.h" -#include "cpu.h" -#include "memory.h" - -uint32_t AiReadLength(void); -void AiLenChanged(void); -void AiDacrateChanged(uint32_t value); -void OpenSound(void); - -#endif diff --git a/src/usf/audio_hle.h b/src/usf/audio_hle.h deleted file mode 100644 index 2f0e3cb..0000000 --- a/src/usf/audio_hle.h +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Mupen64 hle rsp - hle.c - * Copyright (C) 2002 Hacktarux - * - * Mupen64 homepage: http://mupen64.emulation64.com - * email address: hacktarux@yahoo.fr - * - * If you want to contribute to the project please contact - * me first (maybe someone is already making what you are - * planning to do). - * - * - * This program is free software; you can redistribute it and/ - * or modify it under the terms of the GNU General Public Li- - * cence as published by the Free Software Foundation; either - * version 2 of the Licence, or any later version. - * - * This program is distributed in the hope that it will be use- - * ful, but WITHOUT ANY WARRANTY; without even the implied war- - * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public Licence for more details. - * - * You should have received a copy of the GNU General Public - * Licence along with this program; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, - * USA. - * -**/ - -#ifndef HLE_H -#define HLE_H - -#ifndef _BIG_ENDIAN -#define S 0 -#define S8 0 -#else -#define S 1 -#define S8 3 -#endif - -// types -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; - -typedef signed char s8; -typedef signed short s16; -typedef signed int s32; -typedef signed long long s64; - -/* - * Audio flags - */ - -#define A_INIT 0x01 -#define A_CONTINUE 0x00 -#define A_LOOP 0x02 -#define A_OUT 0x02 -#define A_LEFT 0x02 -#define A_RIGHT 0x00 -#define A_VOL 0x04 -#define A_RATE 0x00 -#define A_AUX 0x08 -#define A_NOAUX 0x00 -#define A_MAIN 0x00 -#define A_MIX 0x10 - -typedef struct -{ - unsigned int type; - unsigned int flags; - - unsigned int ucode_boot; - unsigned int ucode_boot_size; - - unsigned int ucode; - unsigned int ucode_size; - - unsigned int ucode_data; - unsigned int ucode_data_size; - - unsigned int dram_stack; - unsigned int dram_stack_size; - - unsigned int output_buff; - unsigned int output_buff_size; - - unsigned int data_ptr; - unsigned int data_size; - - unsigned int yield_data_ptr; - unsigned int yield_data_size; -} OSTask_t; - -extern u32 inst1, inst2; -//extern u16 AudioInBuffer, AudioOutBuffer, AudioCount; -//extern u16 AudioAuxA, AudioAuxC, AudioAuxE; -extern u32 loopval; // Value set by A_SETLOOP : Possible conflict with SETVOLUME??? -//extern u32 UCData, UDataLen; - -extern u32 SEGMENTS[0x10]; // 0x0320 -// T8 = 0x360 -extern u16 AudioInBuffer; // 0x0000(T8) -extern u16 AudioOutBuffer; // 0x0002(T8) -extern u16 AudioCount; // 0x0004(T8) -extern s16 Vol_Left; // 0x0006(T8) -extern s16 Vol_Right; // 0x0008(T8) -extern u16 AudioAuxA; // 0x000A(T8) -extern u16 AudioAuxC; // 0x000C(T8) -extern u16 AudioAuxE; // 0x000E(T8) -extern u32 loopval; // 0x0010(T8) // Value set by A_SETLOOP : Possible conflict with SETVOLUME??? -extern s16 VolTrg_Left; // 0x0010(T8) -extern s32 VolRamp_Left; // m_LeftVolTarget -//u16 VolRate_Left; // m_LeftVolRate -extern s16 VolTrg_Right; // m_RightVol -extern s32 VolRamp_Right; // m_RightVolTarget -//u16 VolRate_Right; // m_RightVolRate -extern s16 Env_Dry; // 0x001C(T8) -extern s16 Env_Wet; // 0x001E(T8) - - -extern u8 BufferSpace[0x10000]; - -extern short hleMixerWorkArea[256]; -extern u16 adpcmtable[0x88]; -extern int firstHLE, goldeneye; - - -extern int audio_ucode(OSTask_t *task); -//extern unsigned char *RDRAM,*DMEM, *IMEM, *ROM; -//extern unsigned int N64MEM_Pages[0x80]; -#include "usf.h" -#include "memory.h" -#include "cpu.h" - - - - -#endif diff --git a/src/usf/audio_hle_main.c b/src/usf/audio_hle_main.c deleted file mode 100644 index e7c25f2..0000000 --- a/src/usf/audio_hle_main.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include "usf.h" -#include "audio_hle.h" -#include "memory.h" -#include "audio.h" -// "Mupen64 HLE RSP plugin v0.2 with Azimers code by Hacktarux" - - -static int audio_ucode_detect ( OSTask_t *task ) -{ - - if ( (*(uint8_t*) ( N64MEM + task->ucode_data )) != 0x1 ) - { - if ( (*(uint8_t*) ( N64MEM + task->ucode_data )) == 0xF ) - return 4; - else - return 3; - } - else - { - if ( (*(uint32_t*) (N64MEM + task->ucode_data + 0x30 )) == 0xF0000F00 ) { - if ((*(uint32_t*) (N64MEM + task->ucode_data + 0x28 )) == 0x1dc8138c) - return 5; //goldeneye - else - return 1; - - } - else - return 2; - } -} - -extern void ( *ABI1[0x20] ) (); -extern void ( *ABI2[0x20] ) (); -extern void ( *ABI3[0x20] ) (); - -void ( *ABI[0x20] ) (); - -u32 inst1, inst2; - -int audio_ucode ( OSTask_t *task ) -{ - - unsigned int i; - - goldeneye = 0; - - switch ( audio_ucode_detect ( task ) ) - { - case 1: // mario ucode - memcpy ( ABI, ABI1, sizeof ( ABI[0] ) *0x20 ); - //cprintf("Ucode1\n"); - break; - case 2: // banjo kazooie ucode - memcpy ( ABI, ABI2, sizeof ( ABI[0] ) *0x20 ); - //cprintf("Ucode2\n"); - break; - case 3: // zelda ucode - memcpy ( ABI, ABI3, sizeof ( ABI[0] ) *0x20 ); - //cprintf("Ucode3\n"); - break; - case 5: - goldeneye = 1; - memcpy ( ABI, ABI1, sizeof ( ABI[0] ) *0x20 ); - break; - default: - { - - return -1; - } - } - - for ( i = 0; i < ( task->data_size/4 ); i += 2 ) - { - inst1 = (*(uint32_t*) ( N64MEM + task->data_ptr + ( i*4 ) )); - inst2 = (*(uint32_t*) ( N64MEM + task->data_ptr + ( ( i+1 ) *4 ) )); - //printf("%x\t%x\n",inst1 >> 24,inst1); - ABI[inst1 >> 24](); - - } - - return 0; -} diff --git a/src/usf/audio_ucode1.c b/src/usf/audio_ucode1.c deleted file mode 100644 index 7f2f1e1..0000000 --- a/src/usf/audio_ucode1.c +++ /dev/null @@ -1,755 +0,0 @@ -#include "usf.h" -#include "audio_hle.h" - - -static void SPNOOP () { - //MessageBox (NULL, "Unknown Audio Command in ABI 1", "Audio HLE Error", MB_OK); -} - -#ifdef __cplusplus -extern "C" { -#endif - -u32 SEGMENTS[0x10]; // 0x0320 -// T8 = 0x360 -u16 AudioInBuffer; // 0x0000(T8) -u16 AudioOutBuffer; // 0x0002(T8) -u16 AudioCount; // 0x0004(T8) -s16 Vol_Left; // 0x0006(T8) -s16 Vol_Right; // 0x0008(T8) -u16 AudioAuxA; // 0x000A(T8) -u16 AudioAuxC; // 0x000C(T8) -u16 AudioAuxE; // 0x000E(T8) -u32 loopval; // 0x0010(T8) // Value set by A_SETLOOP : Possible conflict with SETVOLUME??? -s16 VolTrg_Left; // 0x0010(T8) -s32 VolRamp_Left; // m_LeftVolTarget -//u16 VolRate_Left; // m_LeftVolRate -s16 VolTrg_Right; // m_RightVol -s32 VolRamp_Right; // m_RightVolTarget -//u16 VolRate_Right; // m_RightVolRate -s16 Env_Dry; // 0x001C(T8) -s16 Env_Wet; // 0x001E(T8) -int firstHLE = 0, goldeneye = 0; - -u8 BufferSpace[0x10000]; - -short hleMixerWorkArea[256]; -u16 adpcmtable[0x88]; - - -u16 ResampleLUT [0x200] = { - 0x0C39, 0x66AD, 0x0D46, 0xFFDF, 0x0B39, 0x6696, 0x0E5F, 0xFFD8, - 0x0A44, 0x6669, 0x0F83, 0xFFD0, 0x095A, 0x6626, 0x10B4, 0xFFC8, - 0x087D, 0x65CD, 0x11F0, 0xFFBF, 0x07AB, 0x655E, 0x1338, 0xFFB6, - 0x06E4, 0x64D9, 0x148C, 0xFFAC, 0x0628, 0x643F, 0x15EB, 0xFFA1, - 0x0577, 0x638F, 0x1756, 0xFF96, 0x04D1, 0x62CB, 0x18CB, 0xFF8A, - 0x0435, 0x61F3, 0x1A4C, 0xFF7E, 0x03A4, 0x6106, 0x1BD7, 0xFF71, - 0x031C, 0x6007, 0x1D6C, 0xFF64, 0x029F, 0x5EF5, 0x1F0B, 0xFF56, - 0x022A, 0x5DD0, 0x20B3, 0xFF48, 0x01BE, 0x5C9A, 0x2264, 0xFF3A, - 0x015B, 0x5B53, 0x241E, 0xFF2C, 0x0101, 0x59FC, 0x25E0, 0xFF1E, - 0x00AE, 0x5896, 0x27A9, 0xFF10, 0x0063, 0x5720, 0x297A, 0xFF02, - 0x001F, 0x559D, 0x2B50, 0xFEF4, 0xFFE2, 0x540D, 0x2D2C, 0xFEE8, - 0xFFAC, 0x5270, 0x2F0D, 0xFEDB, 0xFF7C, 0x50C7, 0x30F3, 0xFED0, - 0xFF53, 0x4F14, 0x32DC, 0xFEC6, 0xFF2E, 0x4D57, 0x34C8, 0xFEBD, - 0xFF0F, 0x4B91, 0x36B6, 0xFEB6, 0xFEF5, 0x49C2, 0x38A5, 0xFEB0, - 0xFEDF, 0x47ED, 0x3A95, 0xFEAC, 0xFECE, 0x4611, 0x3C85, 0xFEAB, - 0xFEC0, 0x4430, 0x3E74, 0xFEAC, 0xFEB6, 0x424A, 0x4060, 0xFEAF, - 0xFEAF, 0x4060, 0x424A, 0xFEB6, 0xFEAC, 0x3E74, 0x4430, 0xFEC0, - 0xFEAB, 0x3C85, 0x4611, 0xFECE, 0xFEAC, 0x3A95, 0x47ED, 0xFEDF, - 0xFEB0, 0x38A5, 0x49C2, 0xFEF5, 0xFEB6, 0x36B6, 0x4B91, 0xFF0F, - 0xFEBD, 0x34C8, 0x4D57, 0xFF2E, 0xFEC6, 0x32DC, 0x4F14, 0xFF53, - 0xFED0, 0x30F3, 0x50C7, 0xFF7C, 0xFEDB, 0x2F0D, 0x5270, 0xFFAC, - 0xFEE8, 0x2D2C, 0x540D, 0xFFE2, 0xFEF4, 0x2B50, 0x559D, 0x001F, - 0xFF02, 0x297A, 0x5720, 0x0063, 0xFF10, 0x27A9, 0x5896, 0x00AE, - 0xFF1E, 0x25E0, 0x59FC, 0x0101, 0xFF2C, 0x241E, 0x5B53, 0x015B, - 0xFF3A, 0x2264, 0x5C9A, 0x01BE, 0xFF48, 0x20B3, 0x5DD0, 0x022A, - 0xFF56, 0x1F0B, 0x5EF5, 0x029F, 0xFF64, 0x1D6C, 0x6007, 0x031C, - 0xFF71, 0x1BD7, 0x6106, 0x03A4, 0xFF7E, 0x1A4C, 0x61F3, 0x0435, - 0xFF8A, 0x18CB, 0x62CB, 0x04D1, 0xFF96, 0x1756, 0x638F, 0x0577, - 0xFFA1, 0x15EB, 0x643F, 0x0628, 0xFFAC, 0x148C, 0x64D9, 0x06E4, - 0xFFB6, 0x1338, 0x655E, 0x07AB, 0xFFBF, 0x11F0, 0x65CD, 0x087D, - 0xFFC8, 0x10B4, 0x6626, 0x095A, 0xFFD0, 0x0F83, 0x6669, 0x0A44, - 0xFFD8, 0x0E5F, 0x6696, 0x0B39, 0xFFDF, 0x0D46, 0x66AD, 0x0C39 -}; -#ifdef __cplusplus -} -#endif - - -static void CLEARBUFF () { - u32 addr = (u32)(inst1 & 0xffff); - u32 count = (u32)(inst2 & 0xffff); - addr &= 0xFFFC; - memset(BufferSpace+addr, 0, (count+3)&0xFFFC); -} - - -static void ENVMIXER () { - - u8 flags = (u8)((inst1 >> 16) & 0xff); - u32 addy = (inst2 & 0xFFFFFF); - short *inp=(short *)(BufferSpace+AudioInBuffer); - short *out=(short *)(BufferSpace+AudioOutBuffer); - short *aux1=(short *)(BufferSpace+AudioAuxA); - short *aux2=(short *)(BufferSpace+AudioAuxC); - short *aux3=(short *)(BufferSpace+AudioAuxE); - s32 MainR; - s32 MainL; - s32 AuxR; - s32 AuxL; - int i1,o1,a1,a2=0,a3=0; - unsigned short AuxIncRate=1; - short zero[8]; - s32 LVol, RVol; - s32 LAcc, RAcc; - s32 LTrg, RTrg; - s16 Wet, Dry; - u32 ptr = 0; - s32 RRamp, LRamp; - s32 LAdderStart, RAdderStart, LAdderEnd, RAdderEnd; - s32 oMainR, oMainL, oAuxR, oAuxL; - int x = 0, y = 0; - - memset(zero,0,16); - - if (flags & A_INIT) { - - if(goldeneye) { - //Vol_Left = Vol_Right; - // VolTrg_Left = VolTrg_Right; - Vol_Left = (Vol_Right >> 8) << 8; - VolTrg_Left = (VolTrg_Right >> 8) << 8; - //Vol_Right = (Vol_Right & 0xff) << 8; - //VolTrg_Right = (VolTrg_Right & 0xff) << 8; - } - - LVol = ((Vol_Left * (s32)VolRamp_Left)); - RVol = ((Vol_Right * (s32)VolRamp_Right)); - - Wet = (s16)Env_Wet; - Dry = (s16)Env_Dry; // Save Wet/Dry values - LTrg = (VolTrg_Left << 16); - RTrg = (VolTrg_Right << 16); // Save Current Left/Right Targets - LAdderStart = Vol_Left << 16; - RAdderStart = Vol_Right << 16; - LAdderEnd = LVol ; - RAdderEnd = RVol ; - RRamp = VolRamp_Right; - LRamp = VolRamp_Left; - } else { - // Load LVol, RVol, LAcc, and RAcc (all 32bit) - // Load Wet, Dry, LTrg, RTrg - memcpy((u8*)hleMixerWorkArea, (u8*)RDRAM+addy, 80); - Wet = *(s16 *)(hleMixerWorkArea + 0); // 0-1 - Dry = *(s16 *)(hleMixerWorkArea + 2); // 2-3 - LTrg = *(s32 *)(hleMixerWorkArea + 4); // 4-5 - RTrg = *(s32 *)(hleMixerWorkArea + 6); // 6-7 - LRamp= *(s32 *)(hleMixerWorkArea + 8); // 8-9 (hleMixerWorkArea is a 16bit pointer) - RRamp= *(s32 *)(hleMixerWorkArea + 10); // 10-11 - LAdderEnd = *(s32 *)(hleMixerWorkArea + 12); // 12-13 - RAdderEnd = *(s32 *)(hleMixerWorkArea + 14); // 14-15 - LAdderStart = *(s32 *)(hleMixerWorkArea + 16); // 12-13 - RAdderStart = *(s32 *)(hleMixerWorkArea + 18); // 14-15 - } - - if(!(flags&A_AUX)) { - AuxIncRate=0; - aux2=aux3=zero; - } - - oMainL = (Dry * (LTrg>>16) + 0x4000) >> 15; - oAuxL = (Wet * (LTrg>>16) + 0x4000) >> 15; - oMainR = (Dry * (RTrg>>16) + 0x4000) >> 15; - oAuxR = (Wet * (RTrg>>16) + 0x4000) >> 15; - - for (y = 0; y < AudioCount; y += 0x10) { - - if (LAdderStart != LTrg) { - LAcc = LAdderStart; - LVol = (LAdderEnd - LAdderStart) >> 3; - LAdderEnd = ((s64)LAdderEnd * (s64)LRamp) >> 16; - LAdderStart = ((s64)LAcc * (s64)LRamp) >> 16; - } else { - LAcc = LTrg; - LVol = 0; - } - - if (RAdderStart != RTrg) { - RAcc = RAdderStart; - RVol = (RAdderEnd - RAdderStart) >> 3; - RAdderEnd = ((s64)RAdderEnd * (s64)RRamp) >> 16; - RAdderStart = ((s64)RAcc * (s64)RRamp) >> 16; - } else { - RAcc = RTrg; - RVol = 0; - } - - for (x = 0; x < 8; x++) { - i1=(int)inp[ptr^1]; - o1=(int)out[ptr^1]; - a1=(int)aux1[ptr^1]; - if (AuxIncRate) { - a2=(int)aux2[ptr^1]; - a3=(int)aux3[ptr^1]; - } - - LAcc += LVol; - RAcc += RVol; - - if (LVol <= 0) { // Decrementing - if (LAcc < LTrg) { - LAcc = LTrg; - LAdderStart = LTrg; - MainL = oMainL; - AuxL = oAuxL; - } else { - MainL = (Dry * ((s32)LAcc>>16) + 0x4000) >> 15; - AuxL = (Wet * ((s32)LAcc>>16) + 0x4000) >> 15; - } - } else { - if (LAcc > LTrg) { - LAcc = LTrg; - LAdderStart = LTrg; - MainL = oMainL; - AuxL = oAuxL; - } else { - MainL = (Dry * ((s32)LAcc>>16) + 0x4000) >> 15; - AuxL = (Wet * ((s32)LAcc>>16) + 0x4000) >> 15; - } - } - - if (RVol <= 0) { // Decrementing - if (RAcc < RTrg) { - RAcc = RTrg; - RAdderStart = RTrg; - MainR = oMainR; - AuxR = oAuxR; - } else { - MainR = (Dry * ((s32)RAcc>>16) + 0x4000) >> 15; - AuxR = (Wet * ((s32)RAcc>>16) + 0x4000) >> 15; - } - } else { - if (RAcc > RTrg) { - RAcc = RTrg; - RAdderStart = RTrg; - MainR = oMainR; - AuxR = oAuxR; - } else { - MainR = (Dry * ((s32)RAcc>>16) + 0x4000) >> 15; - AuxR = (Wet * ((s32)RAcc>>16) + 0x4000) >> 15; - } - } - - o1+=((i1*MainR)+0x4000)>>15; - a1+=((i1*MainL)+0x4000)>>15; - - if(o1>32767) o1=32767; - else if(o1<-32768) o1=-32768; - - if(a1>32767) a1=32767; - else if(a1<-32768) a1=-32768; - - out[ptr^1]=o1; - aux1[ptr^1]=a1; - if (AuxIncRate) { - a2+=((i1*AuxR)+0x4000)>>15; - a3+=((i1*AuxL)+0x4000)>>15; - - if(a2>32767) a2=32767; - else if(a2<-32768) a2=-32768; - - if(a3>32767) a3=32767; - else if(a3<-32768) a3=-32768; - - aux2[ptr^1]=a2; - aux3[ptr^1]=a3; - } - ptr++; - } - } - - *(s16 *)(hleMixerWorkArea + 0) = Wet; // 0-1 - *(s16 *)(hleMixerWorkArea + 2) = Dry; // 2-3 - *(s32 *)(hleMixerWorkArea + 4) = LTrg; // 4-5 - *(s32 *)(hleMixerWorkArea + 6) = RTrg; // 6-7 - *(s32 *)(hleMixerWorkArea + 8) = LRamp; // 8-9 (hleMixerWorkArea is a 16bit pointer) - *(s32 *)(hleMixerWorkArea + 10) = RRamp; // 10-11 - *(s32 *)(hleMixerWorkArea + 12) = LAdderEnd; // 12-13 - *(s32 *)(hleMixerWorkArea + 14) = RAdderEnd; // 14-15 - *(s32 *)(hleMixerWorkArea + 16) = LAdderStart; // 12-13 - *(s32 *)(hleMixerWorkArea + 18) = RAdderStart; // 14-15 - - memcpy((u8*)RDRAM+addy,(u8*)hleMixerWorkArea,80); -} - -static void RESAMPLE () { - unsigned int Accum=0; - unsigned int location; - s16 *lut/*, *lut2*/; - short *dst; - s16 *src; - s32 temp; - s32 accum,addy; - u32 srcPtr, dstPtr; - unsigned char Flags; - unsigned int Pitch; - int x = 0, i = 0; - - dst=(short *)(BufferSpace); - src=(s16 *)(BufferSpace); - srcPtr=(AudioInBuffer/2); - dstPtr=(AudioOutBuffer/2); - - - addy = (inst2 & 0xffffff);// + SEGMENTS[(inst2>>24)&0xf]; - Flags=(u8)((inst1>>16)&0xff); - Pitch=((inst1&0xffff))<<1; - - srcPtr -= 4; - - if ((Flags & 0x1) == 0) { - for (x=0; x < 4; x++) - src[(srcPtr+x)^1] = *(u16 *)(N64MEM+(addy+(x*2))); - - Accum = *(u16 *)(N64MEM+addy+10); - } else { - for (x=0; x < 4; x++) - src[(srcPtr+x)^1] = 0; - } - - - for(i = 0; i < ((AudioCount+0xf)&0xFFF0)/2;i++) { - - location = (Accum >> 0xa) << 0x3; - lut = (s16 *)(((u8 *)ResampleLUT) + location); - - temp = ((s32)*(s16*)(src+((srcPtr+0)^1))*((s32)((s16)lut[0]))); - accum = (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+1)^1))*((s32)((s16)lut[1]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+2)^1))*((s32)((s16)lut[2]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+3)^1))*((s32)((s16)lut[3]))); - accum += (s32)(temp >> 15); - - if (accum > 32767) accum = 32767; - if (accum < -32768) accum = -32768; - - dst[dstPtr^1] = (accum); - dstPtr++; - Accum += Pitch; - srcPtr += (Accum>>16); - Accum&=0xffff; - } - for (x = 0; x < 4; x++) - *(u16 *)(N64MEM+(addy+(x*2))) = src[(srcPtr+x)^1]; - - *(u16 *)(N64MEM+addy+10) = Accum; -} -static void SETVOL () { -// Might be better to unpack these depending on the flags... - u8 flags = (u8)((inst1 >> 16) & 0xff); - u16 vol = (s16)(inst1 & 0xffff); - u16 voltarg =(u16)((inst2 >> 16)&0xffff); - u16 volrate = (u16)((inst2 & 0xffff)); - - if (flags & A_AUX) { - Env_Dry = (s16)vol; // m_MainVol - Env_Wet = (s16)volrate; // m_AuxVol - return; - } - - if(flags & A_VOL) { // Set the Source(start) Volumes - if(flags & A_LEFT) { - Vol_Left = (s16)vol; // m_LeftVolume - } else { // A_RIGHT - Vol_Right = (s16)vol; // m_RightVolume - } - return; - } - - if(flags & A_LEFT) { // Set the Ramping values Target, Ramp - VolTrg_Left = *(s16 *)&inst1; // m_LeftVol - if(goldeneye) - VolRamp_Left = voltarg; - else - VolRamp_Left = (s32)volrate;//*(s32 *)&inst2;//(u16)(inst2) | (s32)(s16)(inst2 << 0x10); - } else { // A_RIGHT - VolTrg_Right = *(s16 *)&inst1; // m_RightVol - if(goldeneye) - VolRamp_Right = voltarg; - else - VolRamp_Right = (s32)volrate;//*(s32 *)&inst2;//(u16)(inst2 >> 0x10) | (s32)(s16)(inst2 << 0x10); - } -} - -static void UNKNOWN () {} - -static void SETLOOP () { - loopval = (inst2 & 0xffffff); -} - -static void ADPCM () { // Work in progress! :) - unsigned short inPtr=0; - unsigned char icode; - unsigned char code; - int vscale; - unsigned short index; - unsigned short j; - int a[8]; - short *book1,*book2; - int l1,l2; - int inp1[8]; - int inp2[8]; - short *out, count; - - unsigned char Flags=(u8)(inst1>>16)&0xff; - unsigned int Address=(inst2 & 0xffffff); - - out=(short *)(BufferSpace+AudioOutBuffer); - count=(short)AudioCount; - - memset(out,0,32); - - if(!(Flags&0x1)) - { - if(Flags&0x2) { - memcpy((u8*)out,(u8*)RDRAM+Address,32); - } else { - memcpy((u8*)out,(u8*)RDRAM+Address,32); - } - } - - l1=out[15]; - l2=out[14]; - out+=16; - while(count>0) - { - // the first interation through, these values are - // either 0 in the case of A_INIT, from a special - // area of memory in the case of A_LOOP or just - // the values we calculated the last time - - code=BufferSpace[(AudioInBuffer+inPtr)^3]; - index=code&0xf; - index<<=4; // index into the adpcm code table - book1=(short *)&adpcmtable[index]; - book2=book1+8; - code>>=4; // upper nibble is scale - vscale=(0x8000>>((12-code)-1)); // very strange. 0x8000 would be .5 in 16:16 format - // so this appears to be a fractional scale based - // on the 12 based inverse of the scale value. note - // that this could be negative, in which case we do - // not use the calculated vscale value... see the - // if(code>12) check below - - inPtr++; // coded adpcm data lies next - j=0; - while(j<8) // loop of 8, for 8 coded nibbles from 4 bytes - // which yields 8 short pcm values - { - icode=BufferSpace[(AudioInBuffer+inPtr)^3]; - inPtr++; - - inp1[j]=(s16)((icode&0xf0)<<8); // this will in effect be signed - if(code<12) - inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - j++; - - inp1[j]=(s16)((icode&0xf)<<12); - if(code<12) - inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - j++; - } - j=0; - while(j<8) - { - icode=BufferSpace[(AudioInBuffer+inPtr)^3]; - inPtr++; - - inp2[j]=(short)((icode&0xf0)<<8); // this will in effect be signed - if(code<12) - inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - j++; - - inp2[j]=(short)((icode&0xf)<<12); - if(code<12) - inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - j++; - } - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp1[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp1[0]; - a[1]+=(int)inp1[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp1[0]; - a[2]+=(int)book2[0]*inp1[1]; - a[2]+=(int)inp1[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp1[0]; - a[3]+=(int)book2[1]*inp1[1]; - a[3]+=(int)book2[0]*inp1[2]; - a[3]+=(int)inp1[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp1[0]; - a[4]+=(int)book2[2]*inp1[1]; - a[4]+=(int)book2[1]*inp1[2]; - a[4]+=(int)book2[0]*inp1[3]; - a[4]+=(int)inp1[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp1[0]; - a[5]+=(int)book2[3]*inp1[1]; - a[5]+=(int)book2[2]*inp1[2]; - a[5]+=(int)book2[1]*inp1[3]; - a[5]+=(int)book2[0]*inp1[4]; - a[5]+=(int)inp1[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp1[0]; - a[6]+=(int)book2[4]*inp1[1]; - a[6]+=(int)book2[3]*inp1[2]; - a[6]+=(int)book2[2]*inp1[3]; - a[6]+=(int)book2[1]*inp1[4]; - a[6]+=(int)book2[0]*inp1[5]; - a[6]+=(int)inp1[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp1[0]; - a[7]+=(int)book2[5]*inp1[1]; - a[7]+=(int)book2[4]*inp1[2]; - a[7]+=(int)book2[3]*inp1[3]; - a[7]+=(int)book2[2]*inp1[4]; - a[7]+=(int)book2[1]*inp1[5]; - a[7]+=(int)book2[0]*inp1[6]; - a[7]+=(int)inp1[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - l1=a[6]; - l2=a[7]; - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp2[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp2[0]; - a[1]+=(int)inp2[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp2[0]; - a[2]+=(int)book2[0]*inp2[1]; - a[2]+=(int)inp2[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp2[0]; - a[3]+=(int)book2[1]*inp2[1]; - a[3]+=(int)book2[0]*inp2[2]; - a[3]+=(int)inp2[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp2[0]; - a[4]+=(int)book2[2]*inp2[1]; - a[4]+=(int)book2[1]*inp2[2]; - a[4]+=(int)book2[0]*inp2[3]; - a[4]+=(int)inp2[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp2[0]; - a[5]+=(int)book2[3]*inp2[1]; - a[5]+=(int)book2[2]*inp2[2]; - a[5]+=(int)book2[1]*inp2[3]; - a[5]+=(int)book2[0]*inp2[4]; - a[5]+=(int)inp2[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp2[0]; - a[6]+=(int)book2[4]*inp2[1]; - a[6]+=(int)book2[3]*inp2[2]; - a[6]+=(int)book2[2]*inp2[3]; - a[6]+=(int)book2[1]*inp2[4]; - a[6]+=(int)book2[0]*inp2[5]; - a[6]+=(int)inp2[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp2[0]; - a[7]+=(int)book2[5]*inp2[1]; - a[7]+=(int)book2[4]*inp2[2]; - a[7]+=(int)book2[3]*inp2[3]; - a[7]+=(int)book2[2]*inp2[4]; - a[7]+=(int)book2[1]*inp2[5]; - a[7]+=(int)book2[0]*inp2[6]; - a[7]+=(int)inp2[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - l1=a[6]; - l2=a[7]; - - count-=32; - } - out-=16; - - memcpy((u8*)RDRAM+Address,(u8*) out, 32); -} - -static void LOADBUFF () { // memcpy causes static... endianess issue :( - u32 v0; - if (AudioCount == 0) - return; - v0 = (inst2 & 0xfffffc); - - memcpy(BufferSpace+(AudioInBuffer&0xFFFC), (u8*)RDRAM+v0, (AudioCount+3)&0xFFFC); - -} - -static void SAVEBUFF () { // memcpy causes static... endianess issue :( - u32 v0; - if (AudioCount == 0) - return; - v0 = (inst2 & 0xfffffc); - - memcpy((unsigned char*)RDRAM+v0, BufferSpace+(AudioOutBuffer&0xFFFC), (AudioCount+3)&0xFFFC); -} - -static void SETBUFF () { // Should work ;-) - if ((inst1 >> 0x10) & 0x8) { // A_AUX - Auxillary Sound Buffer Settings - AudioAuxA = (u16)(inst1); - AudioAuxC = (u16)((inst2 >> 0x10)); - AudioAuxE = (u16)(inst2); - } else { // A_MAIN - Main Sound Buffer Settings - AudioInBuffer = (u16)(inst1); // 0x00 - AudioOutBuffer = (u16)((inst2 >> 0x10)); // 0x02 - AudioCount = (u16)(inst2); // 0x04 - } -} - -static void DMEMMOVE () { // Doesn't sound just right?... will fix when HLE is ready - 03-11-01 - u32 v0, v1; - u32 cnt; - u32 count = ((inst2+3) & 0xfffc); - if ((inst2 & 0xffff)==0) - return; - v0 = (inst1 & 0xFFFF); - v1 = (inst2 >> 0x10); - - for (cnt = 0; cnt < count; cnt++) { - *(u8 *)(BufferSpace+((cnt+v1)^3)) = *(u8 *)(BufferSpace+((cnt+v0)^3)); - } -} - -static void LOADADPCM () { // Loads an ADPCM table - Works 100% Now 03-13-01 - u32 v0, x; - v0 = (inst2 & 0xffffff); - - for (x = 0; x < ((inst1 & 0xffff) >> 0x4); x++) { - - u16 *table = (u16 *)(N64MEM+v0+(x<<4)); - - adpcmtable[0x1+(x<<3)] = table[0]; - adpcmtable[0x0+(x<<3)] = table[1]; - - adpcmtable[0x3+(x<<3)] = table[2]; - adpcmtable[0x2+(x<<3)] = table[3]; - - adpcmtable[0x5+(x<<3)] = table[4]; - adpcmtable[0x4+(x<<3)] = table[5]; - - adpcmtable[0x7+(x<<3)] = table[6]; - adpcmtable[0x6+(x<<3)] = table[7]; - - } -} - - -static void INTERLEAVE () { // Works... - 3-11-01 - u32 inL, inR; - u16 *inSrcR; - u16 *inSrcL; - u16 Left, Right; - u16 *outbuff = (u16 *)(AudioOutBuffer+BufferSpace); - int x; - - inL = inst2 & 0xFFFF; - inR = (inst2 >> 16) & 0xFFFF; - - inSrcR = (u16 *)(BufferSpace+inR); - inSrcL = (u16 *)(BufferSpace+inL); - - for (x = 0; x < (AudioCount/4); x++) { - Left=*(inSrcL++); - Right=*(inSrcR++); - - *(outbuff++)=*(inSrcR++); - *(outbuff++)=*(inSrcL++); - *(outbuff++)=(u16)Right; - *(outbuff++)=(u16)Left; - } -} - - -static void MIXER () { // Fixed a sign issue... 03-14-01 - u32 dmemin = (u16)(inst2 >> 0x10); - u32 dmemout = (u16)(inst2 & 0xFFFF); - s32 gain = (s16)(inst1 & 0xFFFF); - s32 temp; - int x; - - if (AudioCount == 0) - return; - - for (x = 0; x < AudioCount; x+=2) { // I think I can do this a lot easier - temp = (*(s16 *)(BufferSpace+dmemin+x) * gain) >> 15; - temp += *(s16 *)(BufferSpace+dmemout+x); - - if ((s32)temp > 32767) - temp = 32767; - if ((s32)temp < -32768) - temp = -32768; - - *(u16 *)(BufferSpace+dmemout+x) = (u16)(temp & 0xFFFF); - } -} - - -void (*ABI1[0x20])() = { // TOP Performace Hogs: MIXER, RESAMPLE, ENVMIXER - SPNOOP , ADPCM , CLEARBUFF, ENVMIXER , LOADBUFF, RESAMPLE , SAVEBUFF, UNKNOWN, - SETBUFF, SETVOL, DMEMMOVE , LOADADPCM , MIXER , INTERLEAVE, UNKNOWN , SETLOOP, - SPNOOP , SPNOOP, SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP, - SPNOOP , SPNOOP, SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP -}; diff --git a/src/usf/audio_ucode2.c b/src/usf/audio_ucode2.c deleted file mode 100644 index 551265c..0000000 --- a/src/usf/audio_ucode2.c +++ /dev/null @@ -1,904 +0,0 @@ -#include -#include -#include "usf.h" -#include "audio_hle.h" -#include "memory.h" - - - - -extern u8 BufferSpace[0x10000]; - -static void SPNOOP () { - char buff[0x100]; -} - -extern u16 AudioInBuffer; // 0x0000(T8) -extern u16 AudioOutBuffer; // 0x0002(T8) -extern u16 AudioCount; // 0x0004(T8) -extern u32 loopval; // 0x0010(T8) -extern u32 SEGMENTS[0x10]; -extern u16 adpcmtable[0x88]; -extern u16 ResampleLUT [0x200]; - -bool isMKABI = false; -bool isZeldaABI = false; - -#define PageRAM2(x) ((uintptr_t) (RDRAM + (x))) -#define memcpyfn64(a,b,c) memcpy((a),(void*)((uintptr_t)RDRAM + (uintptr_t)(b)),(c)) -#define memcpy2n64(a,b,c) memcpy((void*)((uintptr_t)RDRAM + (uintptr_t)(a)),(b),(c)) - -static void LOADADPCM2 () { // Loads an ADPCM table - Works 100% Now 03-13-01 - u32 v0; - v0 = (inst2 & 0xffffff);// + SEGMENTS[(inst2>>24)&0xf]; - u32 x; - - for (x = 0; x < ((inst1&0xffff)>>0x4); x++) { - u16 *table = (u16*)PageRAM2(v0+(x*16)); - - - adpcmtable[0x1+(x<<3)] = table[0]; - adpcmtable[0x0+(x<<3)] = table[1]; - - adpcmtable[0x3+(x<<3)] = table[2]; - adpcmtable[0x2+(x<<3)] = table[3]; - - adpcmtable[0x5+(x<<3)] = table[4]; - adpcmtable[0x4+(x<<3)] = table[5]; - - adpcmtable[0x7+(x<<3)] = table[6]; - adpcmtable[0x6+(x<<3)] = table[7]; - // table += 8; - } -} - -static void SETLOOP2 () { - loopval = inst2 & 0xffffff; // No segment? -} - -static void SETBUFF2 () { - AudioInBuffer = (u16)(inst1); // 0x00 - AudioOutBuffer = (u16)((inst2 >> 0x10)); // 0x02 - AudioCount = (u16)(inst2); // 0x04 -} - -static void ADPCM2 () { // Verified to be 100% Accurate... - unsigned char Flags=(u8)(inst1>>16)&0xff; - //WORD Gain=(u16)(inst1&0xffff); - unsigned int Address=(inst2 & 0xffffff);// + SEGMENTS[(inst2>>24)&0xf]; - unsigned short inPtr=0; - //short *out=(s16 *)(testbuff+(AudioOutBuffer>>2)); - short *out=(short *)(BufferSpace+AudioOutBuffer); - //BYTE *in=(unsigned char *)(BufferSpace+AudioInBuffer); - short count=(short)AudioCount; - unsigned char icode; - unsigned char code; - int vscale; - unsigned short index; - unsigned short j; - int a[8]; - short *book1,*book2; - - u8 srange; - u8 inpinc; - u8 mask1; - u8 mask2; - u8 shifter; - - memset(out,0,32); - - if (Flags & 0x4) { // Tricky lil Zelda MM and ABI2!!! hahaha I know your secrets! :DDD - srange = 0xE; - inpinc = 0x5; - mask1 = 0xC0; - mask2 = 0x30; - shifter = 10; - } else { - srange = 0xC; - inpinc = 0x9; - mask1 = 0xf0; - mask2 = 0x0f; - shifter = 12; - } - - if(!(Flags&0x1)) - { - if(Flags&0x2) - {/* - for(int i=0;i<16;i++) - { - out[i]=*(short *)&rsp.RDRAM[(loopval+i*2)^2]; - }*/ - memcpyfn64((u8 *)out,(u8 *)loopval,32); - } - else - {/* - for(int i=0;i<16;i++) - { - out[i]=*(short *)&rsp.RDRAM[(Address+i*2)^2]; - }*/ - - memcpyfn64((u8 *)out,(u8 *)Address,32); - } - } - - int l1=out[15]; - int l2=out[14]; - int inp1[8]; - int inp2[8]; - out+=16; - while(count>0) { - code=BufferSpace[(AudioInBuffer+inPtr)^3]; - index=code&0xf; - index<<=4; - book1=(short *)&adpcmtable[index]; - book2=book1+8; - code>>=4; - vscale=(0x8000>>((srange-code)-1)); - - inPtr++; - j=0; - - while(j<8) { - icode=BufferSpace[(AudioInBuffer+inPtr)^3]; - inPtr++; - - inp1[j]=(s16)((icode&mask1) << 8); // this will in effect be signed - if(code>16); - //else int catchme=1; - j++; - - inp1[j]=(s16)((icode&mask2)<>16); - //else int catchme=1; - j++; - - if (Flags & 4) { - inp1[j]=(s16)((icode&0xC) << 12); // this will in effect be signed - if(code < 0xE) inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - //else int catchme=1; - j++; - - inp1[j]=(s16)((icode&0x3) << 14); - if(code < 0xE) inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - //else int catchme=1; - j++; - } // end flags - } // end while - - - - j=0; - while(j<8) { - icode=BufferSpace[(AudioInBuffer+inPtr)^3]; - inPtr++; - - inp2[j]=(s16)((icode&mask1) << 8); - if(code>16); - //else int catchme=1; - j++; - - inp2[j]=(s16)((icode&mask2)<>16); - //else int catchme=1; - j++; - - if (Flags & 4) { - inp2[j]=(s16)((icode&0xC) << 12); - if(code < 0xE) inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - //else int catchme=1; - j++; - - inp2[j]=(s16)((icode&0x3) << 14); - if(code < 0xE) inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - //else int catchme=1; - j++; - } // end flags - } - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp1[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp1[0]; - a[1]+=(int)inp1[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp1[0]; - a[2]+=(int)book2[0]*inp1[1]; - a[2]+=(int)inp1[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp1[0]; - a[3]+=(int)book2[1]*inp1[1]; - a[3]+=(int)book2[0]*inp1[2]; - a[3]+=(int)inp1[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp1[0]; - a[4]+=(int)book2[2]*inp1[1]; - a[4]+=(int)book2[1]*inp1[2]; - a[4]+=(int)book2[0]*inp1[3]; - a[4]+=(int)inp1[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp1[0]; - a[5]+=(int)book2[3]*inp1[1]; - a[5]+=(int)book2[2]*inp1[2]; - a[5]+=(int)book2[1]*inp1[3]; - a[5]+=(int)book2[0]*inp1[4]; - a[5]+=(int)inp1[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp1[0]; - a[6]+=(int)book2[4]*inp1[1]; - a[6]+=(int)book2[3]*inp1[2]; - a[6]+=(int)book2[2]*inp1[3]; - a[6]+=(int)book2[1]*inp1[4]; - a[6]+=(int)book2[0]*inp1[5]; - a[6]+=(int)inp1[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp1[0]; - a[7]+=(int)book2[5]*inp1[1]; - a[7]+=(int)book2[4]*inp1[2]; - a[7]+=(int)book2[3]*inp1[3]; - a[7]+=(int)book2[2]*inp1[4]; - a[7]+=(int)book2[1]*inp1[5]; - a[7]+=(int)book2[0]*inp1[6]; - a[7]+=(int)inp1[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - l1=a[6]; - l2=a[7]; - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp2[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp2[0]; - a[1]+=(int)inp2[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp2[0]; - a[2]+=(int)book2[0]*inp2[1]; - a[2]+=(int)inp2[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp2[0]; - a[3]+=(int)book2[1]*inp2[1]; - a[3]+=(int)book2[0]*inp2[2]; - a[3]+=(int)inp2[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp2[0]; - a[4]+=(int)book2[2]*inp2[1]; - a[4]+=(int)book2[1]*inp2[2]; - a[4]+=(int)book2[0]*inp2[3]; - a[4]+=(int)inp2[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp2[0]; - a[5]+=(int)book2[3]*inp2[1]; - a[5]+=(int)book2[2]*inp2[2]; - a[5]+=(int)book2[1]*inp2[3]; - a[5]+=(int)book2[0]*inp2[4]; - a[5]+=(int)inp2[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp2[0]; - a[6]+=(int)book2[4]*inp2[1]; - a[6]+=(int)book2[3]*inp2[2]; - a[6]+=(int)book2[2]*inp2[3]; - a[6]+=(int)book2[1]*inp2[4]; - a[6]+=(int)book2[0]*inp2[5]; - a[6]+=(int)inp2[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp2[0]; - a[7]+=(int)book2[5]*inp2[1]; - a[7]+=(int)book2[4]*inp2[2]; - a[7]+=(int)book2[3]*inp2[3]; - a[7]+=(int)book2[2]*inp2[4]; - a[7]+=(int)book2[1]*inp2[5]; - a[7]+=(int)book2[0]*inp2[6]; - a[7]+=(int)inp2[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - l1=a[6]; - l2=a[7]; - - count-=32; - } - out-=16; - memcpy2n64((u8 *)Address,(u8 *)out,32); -} - -static void CLEARBUFF2 () { - u16 addr = (u16)(inst1 & 0xffff); - u16 count = (u16)(inst2 & 0xffff); - if (count > 0) - memset(BufferSpace+addr, 0, count); -} - -static void LOADBUFF2 () { // Needs accuracy verification... - u32 v0; - u32 cnt = (((inst1 >> 0xC)+3)&0xFFC); - v0 = (inst2 & 0xfffffc);// + SEGMENTS[(inst2>>24)&0xf]; - - memcpyfn64 ((u8 *)BufferSpace+(inst1&0xfffc), (u8 *)v0, (cnt+3)&0xFFFC); -} - -static void SAVEBUFF2 () { // Needs accuracy verification... - u32 v0; - u32 cnt = (((inst1 >> 0xC)+3)&0xFFC); - v0 = (inst2 & 0xfffffc);// + SEGMENTS[(inst2>>24)&0xf]; - memcpy2n64 ((u8 *)v0, (u8 *)BufferSpace+(inst1&0xfffc), (cnt+3)&0xFFFC); -} - - -static void MIXER2 () { // Needs accuracy verification... - u16 dmemin = (u16)(inst2 >> 0x10); - u16 dmemout = (u16)(inst2 & 0xFFFF); - u32 count = ((inst1 >> 12) & 0xFF0); - s32 gain = (s16)(inst1 & 0xFFFF)*2; - s32 temp; - unsigned int x; - - for (x=0; x < count; x+=2) { // I think I can do this a lot easier - - temp = (*(s16 *)(BufferSpace+dmemin+x) * gain) >> 16; - temp += *(s16 *)(BufferSpace+dmemout+x); - - if ((s32)temp > 32767) - temp = 32767; - if ((s32)temp < -32768) - temp = -32768; - - *(u16 *)(BufferSpace+dmemout+x) = (u16)(temp & 0xFFFF); - } -} - - - -static void RESAMPLE2 () { - unsigned char Flags=(u8)((inst1>>16)&0xff); - unsigned int Pitch=((inst1&0xffff))<<1; - u32 addy = (inst2 & 0xffffff);// + SEGMENTS[(inst2>>24)&0xf]; - unsigned int Accum=0; - unsigned int location; - s16 *lut; - short *dst; - s16 *src; - dst=(short *)(BufferSpace); - src=(s16 *)(BufferSpace); - u32 srcPtr=(AudioInBuffer/2); - u32 dstPtr=(AudioOutBuffer/2); - s32 temp; - s32 accum; - int x, i; - - if (addy > (1024*1024*8)) - addy = (inst2 & 0xffffff); - - srcPtr -= 4; - - if ((Flags & 0x1) == 0) { - for (x=0; x < 4; x++) - src[(srcPtr+x)^1] = *(u16*)(PageRAM2(addy+(x^1))); - Accum = *(u16 *)(PageRAM2(addy+10)); - } else { - for (x=0; x < 4; x++) - src[(srcPtr+x)^1] = 0;//*(u16 *)(rsp.RDRAM+((addy+x)^2)); - } - - for(i=0;i < ((AudioCount+0xf)&0xFFF0)/2;i++) { - location = (((Accum * 0x40) >> 0x10) * 8); - //location = (Accum >> 0xa) << 0x3; - lut = (s16 *)(((u8 *)ResampleLUT) + location); - - temp = ((s32)*(s16*)(src+((srcPtr+0)^1))*((s32)((s16)lut[0]))); - accum = (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+1)^1))*((s32)((s16)lut[1]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+2)^1))*((s32)((s16)lut[2]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+3)^1))*((s32)((s16)lut[3]))); - accum += (s32)(temp >> 15); - - if (accum > 32767) accum = 32767; - if (accum < -32768) accum = -32768; - - dst[dstPtr^1] = (s16)(accum); - dstPtr++; - Accum += Pitch; - srcPtr += (Accum>>16); - Accum&=0xffff; - } - for (x=0; x < 4; x++) - *(u16*)(PageRAM2(addy+(x^1))) = src[(srcPtr+x)^1]; - - *(u16 *)(PageRAM2(addy+10)) = Accum; - -} - -static void DMEMMOVE2 () { // Needs accuracy verification... - u32 v0, v1; - u32 cnt; - if ((inst2 & 0xffff)==0) - return; - v0 = (inst1 & 0xFFFF); - v1 = (inst2 >> 0x10); - //assert ((v1 & 0x3) == 0); - //assert ((v0 & 0x3) == 0); - u32 count = ((inst2+3) & 0xfffc); - //v0 = (v0) & 0xfffc; - //v1 = (v1) & 0xfffc; - - //memcpy (dmem+v1, dmem+v0, count-1); - for (cnt = 0; cnt < count; cnt++) { - *(u8 *)(BufferSpace+((cnt+v1)^3)) = *(u8 *)(BufferSpace+((cnt+v0)^3)); - } -} - -u32 t3, s5, s6; -u16 env[8]; - -static void ENVSETUP1 () { - u32 tmp; - - //fprintf (dfile, "ENVSETUP1: inst1 = %08X, inst2 = %08X\n", inst1, inst2); - t3 = inst1 & 0xFFFF; - tmp = (inst1 >> 0x8) & 0xFF00; - env[4] = (u16)tmp; - tmp += t3; - env[5] = (u16)tmp; - s5 = inst2 >> 0x10; - s6 = inst2 & 0xFFFF; - //fprintf (dfile, " t3 = %X / s5 = %X / s6 = %X / env[4] = %X / env[5] = %X\n", t3, s5, s6, env[4], env[5]); -} - -static void ENVSETUP2 () { - u32 tmp; - - //fprintf (dfile, "ENVSETUP2: inst1 = %08X, inst2 = %08X\n", inst1, inst2); - tmp = (inst2 >> 0x10); - env[0] = (u16)tmp; - tmp += s5; - env[1] = (u16)tmp; - tmp = inst2 & 0xffff; - env[2] = (u16)tmp; - tmp += s6; - env[3] = (u16)tmp; - //fprintf (dfile, " env[0] = %X / env[1] = %X / env[2] = %X / env[3] = %X\n", env[0], env[1], env[2], env[3]); -} - -static void ENVMIXER2 () { - //fprintf (dfile, "ENVMIXER: inst1 = %08X, inst2 = %08X\n", inst1, inst2); - - s16 *bufft6, *bufft7, *buffs0, *buffs1; - s16 *buffs3; - s32 count; - u32 adder; - - s16 vec9, vec10; - - s16 v2[8]; - - //__asm int 3; - - buffs3 = (s16 *)(BufferSpace + ((inst1 >> 0x0c)&0x0ff0)); - bufft6 = (s16 *)(BufferSpace + ((inst2 >> 0x14)&0x0ff0)); - bufft7 = (s16 *)(BufferSpace + ((inst2 >> 0x0c)&0x0ff0)); - buffs0 = (s16 *)(BufferSpace + ((inst2 >> 0x04)&0x0ff0)); - buffs1 = (s16 *)(BufferSpace + ((inst2 << 0x04)&0x0ff0)); - - v2[0] = 0 - (s16)((inst1 & 0x2) >> 1); - v2[1] = 0 - (s16)((inst1 & 0x1)); - v2[2] = 0 - (s16)((inst1 & 0x8) >> 1); - v2[3] = 0 - (s16)((inst1 & 0x4) >> 1); - - count = (inst1 >> 8) & 0xff; - - if (!isMKABI) { - s5 *= 2; s6 *= 2; t3 *= 2; - adder = 0x10; - } else { - inst1 = 0; - adder = 0x8; - t3 = 0; - } - - - while (count > 0) { - int temp, x; - for (x=0; x < 0x8; x++) { - vec9 = (s16)(((s32)buffs3[x^1] * (u32)env[0]) >> 0x10) ^ v2[0]; - vec10 = (s16)(((s32)buffs3[x^1] * (u32)env[2]) >> 0x10) ^ v2[1]; - temp = bufft6[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - bufft6[x^1] = temp; - temp = bufft7[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - bufft7[x^1] = temp; - vec9 = (s16)(((s32)vec9 * (u32)env[4]) >> 0x10) ^ v2[2]; - vec10 = (s16)(((s32)vec10 * (u32)env[4]) >> 0x10) ^ v2[3]; - if (inst1 & 0x10) { - temp = buffs0[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs0[x^1] = temp; - temp = buffs1[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs1[x^1] = temp; - } else { - temp = buffs0[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs0[x^1] = temp; - temp = buffs1[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs1[x^1] = temp; - } - } - - if (!isMKABI) - for (x=0x8; x < 0x10; x++) { - vec9 = (s16)(((s32)buffs3[x^1] * (u32)env[1]) >> 0x10) ^ v2[0]; - vec10 = (s16)(((s32)buffs3[x^1] * (u32)env[3]) >> 0x10) ^ v2[1]; - temp = bufft6[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - bufft6[x^1] = temp; - temp = bufft7[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - bufft7[x^1] = temp; - vec9 = (s16)(((s32)vec9 * (u32)env[5]) >> 0x10) ^ v2[2]; - vec10 = (s16)(((s32)vec10 * (u32)env[5]) >> 0x10) ^ v2[3]; - if (inst1 & 0x10) { - temp = buffs0[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs0[x^1] = temp; - temp = buffs1[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs1[x^1] = temp; - } else { - temp = buffs0[x^1] + vec9; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs0[x^1] = temp; - temp = buffs1[x^1] + vec10; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - buffs1[x^1] = temp; - } - } - bufft6 += adder; bufft7 += adder; - buffs0 += adder; buffs1 += adder; - buffs3 += adder; count -= adder; - env[0] += (u16)s5; env[1] += (u16)s5; - env[2] += (u16)s6; env[3] += (u16)s6; - env[4] += (u16)t3; env[5] += (u16)t3; - } -} - -static void DUPLICATE2() { - unsigned short Count = (inst1 >> 16) & 0xff; - unsigned short In = inst1&0xffff; - unsigned short Out = (inst2>>16); - - unsigned short buff[64]; - - memcpy(buff,BufferSpace+In,128); - - while(Count) { - memcpy(BufferSpace+Out,buff,128); - Out+=128; - Count--; - } -} -/* -static void INTERL2 () { // Make your own... - short Count = inst1 & 0xffff; - unsigned short Out = inst2 & 0xffff; - unsigned short In = (inst2 >> 16); - - short *src,*dst,tmp; - src=(short *)&BufferSpace[In]; - dst=(short *)&BufferSpace[Out]; - while(Count) - { - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - *(dst++)=*(src++); - src++; - Count-=8; - } -} -*/ - -static void INTERL2 () { - short Count = inst1 & 0xffff; - unsigned short Out = inst2 & 0xffff; - unsigned short In = (inst2 >> 16); - - unsigned char *src,*dst/*,tmp*/; - src=(unsigned char *)(BufferSpace);//[In]; - dst=(unsigned char *)(BufferSpace);//[Out]; - while(Count) { - *(short *)(dst+(Out^3)) = *(short *)(src+(In^3)); - Out += 2; - In += 4; - Count--; - } -} - -static void INTERLEAVE2 () { // Needs accuracy verification... - u32 inL, inR; - u16 *outbuff; - u16 *inSrcR; - u16 *inSrcL; - u16 Left, Right; - u32 count; - u32 x; - count = ((inst1 >> 12) & 0xFF0); - if (count == 0) { - outbuff = (u16 *)(AudioOutBuffer+BufferSpace); - count = AudioCount; - } else { - outbuff = (u16 *)((inst1&0xFFFF)+BufferSpace); - } - - inR = inst2 & 0xFFFF; - inL = (inst2 >> 16) & 0xFFFF; - - inSrcR = (u16 *)(BufferSpace+inR); - inSrcL = (u16 *)(BufferSpace+inL); - - for (x = 0; x < (count/4); x++) { - Left=*(inSrcL++); - Right=*(inSrcR++); - - *(outbuff++)=*(inSrcR++); - *(outbuff++)=*(inSrcL++); - *(outbuff++)=(u16)Right; - *(outbuff++)=(u16)Left; - } -} - -static void ADDMIXER () { - short Count = (inst1 >> 12) & 0x00ff0; - u16 InBuffer = (inst2 >> 16); - u16 OutBuffer = inst2 & 0xffff; - int cntr; - - s16 *inp, *outp; - s32 temp; - inp = (s16 *)(BufferSpace + InBuffer); - outp = (s16 *)(BufferSpace + OutBuffer); - for (cntr = 0; cntr < Count; cntr+=2) { - temp = *outp + *inp; - if (temp > 32767) temp = 32767; if (temp < -32768) temp = -32768; - outp++; inp++; - } -} - -static void HILOGAIN () { - u16 cnt = inst1 & 0xffff; - u16 out = (inst2 >> 16) & 0xffff; - s16 hi = (s16)((inst1 >> 4) & 0xf000); - u16 lo = (inst1 >> 20) & 0xf; - s16 *src; - - src = (s16 *)(BufferSpace+out); - s32 tmp, val; - - while(cnt) { - val = (s32)*src; - //tmp = ((val * (s32)hi) + ((u64)(val * lo) << 16) >> 16); - tmp = ((val * (s32)hi) >> 16) + (u32)(val * lo); - if ((s32)tmp > 32767) tmp = 32767; - else if ((s32)tmp < -32768) tmp = -32768; - *src = tmp; - src++; - cnt -= 2; - } -} - -static void FILTER2 () { - static int cnt = 0; - static s16 *lutt6; - static s16 *lutt5; - - u32 addy = inst2&0xFFFFFF; - - u8 *save = (u8*)PageRAM2(addy&0xFFFFFF); //+RDRAM - u8 t4 = (u8)((inst1 >> 0x10) & 0xFF); - int x; - - if (t4 > 1) { // Then set the cnt variable - cnt = (inst1 & 0xFFFF); - lutt6 = (s16 *)PageRAM2(addy&0xFFFFFF); -// memcpy (dmem+0xFE0, rsp.RDRAM+(inst2&0xFFFFFF), 0x10); - return; - } - - if (t4 == 0) { -// memcpy (dmem+0xFB0, rsp.RDRAM+(inst2&0xFFFFFF), 0x20); - lutt5 = (short *)PageRAM2((addy+0x10)&0xFFFFFF); - } - - lutt5 = (short *)PageRAM2((addy+0x10)&0xFFFFFF); - -// lutt5 = (short *)(dmem + 0xFC0); -// lutt6 = (short *)(dmem + 0xFE0); - for (x = 0; x < 8; x++) { - s32 a; - a = (lutt5[x] + lutt6[x]) >> 1; - lutt5[x] = lutt6[x] = (short)a; - } - short *inp1, *inp2; - s32 out1[8]; - s16 outbuff[0x3c0], *outp; - u32 inPtr = (u32)(inst1&0xffff); - outp = outbuff; - inp1 = (short *)(save); - inp2 = (short *)(BufferSpace+inPtr); - - for (x = 0; x < cnt; x+=0x10) { - out1[1] = inp1[0]*lutt6[6]; - out1[1] += inp1[3]*lutt6[7]; - out1[1] += inp1[2]*lutt6[4]; - out1[1] += inp1[5]*lutt6[5]; - out1[1] += inp1[4]*lutt6[2]; - out1[1] += inp1[7]*lutt6[3]; - out1[1] += inp1[6]*lutt6[0]; - out1[1] += inp2[1]*lutt6[1]; // 1 - - out1[0] = inp1[3]*lutt6[6]; - out1[0] += inp1[2]*lutt6[7]; - out1[0] += inp1[5]*lutt6[4]; - out1[0] += inp1[4]*lutt6[5]; - out1[0] += inp1[7]*lutt6[2]; - out1[0] += inp1[6]*lutt6[3]; - out1[0] += inp2[1]*lutt6[0]; - out1[0] += inp2[0]*lutt6[1]; - - out1[3] = inp1[2]*lutt6[6]; - out1[3] += inp1[5]*lutt6[7]; - out1[3] += inp1[4]*lutt6[4]; - out1[3] += inp1[7]*lutt6[5]; - out1[3] += inp1[6]*lutt6[2]; - out1[3] += inp2[1]*lutt6[3]; - out1[3] += inp2[0]*lutt6[0]; - out1[3] += inp2[3]*lutt6[1]; - - out1[2] = inp1[5]*lutt6[6]; - out1[2] += inp1[4]*lutt6[7]; - out1[2] += inp1[7]*lutt6[4]; - out1[2] += inp1[6]*lutt6[5]; - out1[2] += inp2[1]*lutt6[2]; - out1[2] += inp2[0]*lutt6[3]; - out1[2] += inp2[3]*lutt6[0]; - out1[2] += inp2[2]*lutt6[1]; - - out1[5] = inp1[4]*lutt6[6]; - out1[5] += inp1[7]*lutt6[7]; - out1[5] += inp1[6]*lutt6[4]; - out1[5] += inp2[1]*lutt6[5]; - out1[5] += inp2[0]*lutt6[2]; - out1[5] += inp2[3]*lutt6[3]; - out1[5] += inp2[2]*lutt6[0]; - out1[5] += inp2[5]*lutt6[1]; - - out1[4] = inp1[7]*lutt6[6]; - out1[4] += inp1[6]*lutt6[7]; - out1[4] += inp2[1]*lutt6[4]; - out1[4] += inp2[0]*lutt6[5]; - out1[4] += inp2[3]*lutt6[2]; - out1[4] += inp2[2]*lutt6[3]; - out1[4] += inp2[5]*lutt6[0]; - out1[4] += inp2[4]*lutt6[1]; - - out1[7] = inp1[6]*lutt6[6]; - out1[7] += inp2[1]*lutt6[7]; - out1[7] += inp2[0]*lutt6[4]; - out1[7] += inp2[3]*lutt6[5]; - out1[7] += inp2[2]*lutt6[2]; - out1[7] += inp2[5]*lutt6[3]; - out1[7] += inp2[4]*lutt6[0]; - out1[7] += inp2[7]*lutt6[1]; - - out1[6] = inp2[1]*lutt6[6]; - out1[6] += inp2[0]*lutt6[7]; - out1[6] += inp2[3]*lutt6[4]; - out1[6] += inp2[2]*lutt6[5]; - out1[6] += inp2[5]*lutt6[2]; - out1[6] += inp2[4]*lutt6[3]; - out1[6] += inp2[7]*lutt6[0]; - out1[6] += inp2[6]*lutt6[1]; - outp[1] = /*CLAMP*/((out1[1]+0x4000) >> 0xF); - outp[0] = /*CLAMP*/((out1[0]+0x4000) >> 0xF); - outp[3] = /*CLAMP*/((out1[3]+0x4000) >> 0xF); - outp[2] = /*CLAMP*/((out1[2]+0x4000) >> 0xF); - outp[5] = /*CLAMP*/((out1[5]+0x4000) >> 0xF); - outp[4] = /*CLAMP*/((out1[4]+0x4000) >> 0xF); - outp[7] = /*CLAMP*/((out1[7]+0x4000) >> 0xF); - outp[6] = /*CLAMP*/((out1[6]+0x4000) >> 0xF); - inp1 = inp2; - inp2 += 8; - outp += 8; - } -// memcpy (rsp.RDRAM+(inst2&0xFFFFFF), dmem+0xFB0, 0x20); - memcpy (save, inp2-8, 0x10); - memcpy (BufferSpace+(inst1&0xffff), outbuff, cnt); -} - -static void SEGMENT2 () { - if (isZeldaABI) { - FILTER2 (); - return; - } - if ((inst1 & 0xffffff) == 0) { - isMKABI = true; - //SEGMENTS[(inst2>>24)&0xf] = (inst2 & 0xffffff); - } else { - isMKABI = false; - isZeldaABI = true; - FILTER2 (); - } -} - -static void UNKNOWN () { -} - -void (*ABI2[0x20])() = { - SPNOOP , ADPCM2, CLEARBUFF2, UNKNOWN, ADDMIXER, RESAMPLE2, UNKNOWN, SEGMENT2, - SETBUFF2 , DUPLICATE2, DMEMMOVE2, LOADADPCM2, MIXER2, INTERLEAVE2, HILOGAIN, SETLOOP2, - SPNOOP, INTERL2 , ENVSETUP1, ENVMIXER2, LOADBUFF2, SAVEBUFF2, ENVSETUP2, SPNOOP, - HILOGAIN , SPNOOP, DUPLICATE2 , UNKNOWN , SPNOOP , SPNOOP , SPNOOP , SPNOOP -}; - -/* NOTES: - - FILTER/SEGMENT - Still needs to be finished up... add FILTER? - UNKNOWWN #27 - Is this worth doing? Looks like a pain in the ass just for WaveRace64 -*/ diff --git a/src/usf/audio_ucode3.c b/src/usf/audio_ucode3.c deleted file mode 100644 index 7611c59..0000000 --- a/src/usf/audio_ucode3.c +++ /dev/null @@ -1,666 +0,0 @@ -#include -#include -#include "usf.h" -#include "audio_hle.h" -#include "memory.h" - - -static void SPNOOP () { - //char buff[0x100]; - //sprintf (buff, "Unknown/Unimplemented Audio Command %i in ABI 3", (int)(inst1 >> 24)); - //printf( "Audio HLE Error: %s\n", buff ); -} - -extern u16 ResampleLUT [0x200]; - -extern u32 loopval; - -extern s16 Env_Dry; -extern s16 Env_Wet; -extern s16 Vol_Left; -extern s16 Vol_Right; -extern s16 VolTrg_Left; -extern s32 VolRamp_Left; -//extern u16 VolRate_Left; -extern s16 VolTrg_Right; -extern s32 VolRamp_Right; -//extern u16 VolRate_Right; - - -extern short hleMixerWorkArea[256]; -extern u16 adpcmtable[0x88]; - -extern u8 BufferSpace[0x10000]; - -/* -static void SETVOL3 () { // Swapped Rate_Left and Vol - u8 Flags = (u8)(inst1 >> 0x10); - if (Flags & 0x4) { // 288 - if (Flags & 0x2) { // 290 - VolTrg_Left = *(s16*)&inst1; - VolRamp_Left = *(s32*)&inst2; - } else { - VolTrg_Right = *(s16*)&inst1; - VolRamp_Right = *(s32*)&inst2; - } - } else { - Vol_Left = *(s16*)&inst1; - Env_Dry = (s16)(*(s32*)&inst2 >> 0x10); - Env_Wet = *(s16*)&inst2; - } -} -*/ -static void SETVOL3 () { - u8 Flags = (u8)(inst1 >> 0x10); - if (Flags & 0x4) { // 288 - if (Flags & 0x2) { // 290 - Vol_Left = *(s16*)&inst1; // 0x50 - Env_Dry = (s16)(*(s32*)&inst2 >> 0x10); // 0x4E - Env_Wet = *(s16*)&inst2; // 0x4C - } else { - VolTrg_Right = *(s16*)&inst1; // 0x46 - //VolRamp_Right = (u16)(inst2 >> 0x10) | (s32)(s16)(inst2 << 0x10); - VolRamp_Right = *(s32*)&inst2; // 0x48/0x4A - } - } else { - VolTrg_Left = *(s16*)&inst1; // 0x40 - VolRamp_Left = *(s32*)&inst2; // 0x42/0x44 - } -} - -static void ENVMIXER3 () { - u8 flags; - u32 addy; - - short *inp=(short *)(BufferSpace+0x4F0); - short *out=(short *)(BufferSpace+0x9D0); - short *aux1=(short *)(BufferSpace+0xB40); - short *aux2=(short *)(BufferSpace+0xCB0); - short *aux3=(short *)(BufferSpace+0xE20); - s32 MainR; - s32 MainL; - s32 AuxR; - s32 AuxL; - - int i1,o1,a1,a2,a3,y; - //WORD AuxIncRate=1; - short zero[8]; - memset(zero,0,16); - - flags = (u8)((inst1 >> 16) & 0xff); - addy = (inst2 & 0xFFFFFF); - - s32 LAdder, LAcc, LVol; - s32 RAdder, RAcc, RVol; - s16 RSig, LSig; // Most significant part of the Ramp Value - s16 Wet, Dry; - s16 LTrg, RTrg; - - - Vol_Right = (*(s16 *)&inst1); - - if (flags & A_INIT) { - LAdder = VolRamp_Left / 8; - LAcc = 0; - LVol = Vol_Left; - LSig = (s16)(VolRamp_Left >> 16); - - RAdder = VolRamp_Right / 8; - RAcc = 0; - RVol = Vol_Right; - RSig = (s16)(VolRamp_Right >> 16); - - Wet = (s16)Env_Wet; Dry = (s16)Env_Dry; // Save Wet/Dry values - LTrg = VolTrg_Left; RTrg = VolTrg_Right; // Save Current Left/Right Targets - } else { - memcpy((u8 *)hleMixerWorkArea, N64MEM+addy, 80); - Wet = *(s16 *)(hleMixerWorkArea + 0); // 0-1 - Dry = *(s16 *)(hleMixerWorkArea + 2); // 2-3 - LTrg = *(s16 *)(hleMixerWorkArea + 4); // 4-5 - RTrg = *(s16 *)(hleMixerWorkArea + 6); // 6-7 - LAdder = *(s32 *)(hleMixerWorkArea + 8); // 8-9 (hleMixerWorkArea is a 16bit pointer) - RAdder = *(s32 *)(hleMixerWorkArea + 10); // 10-11 - LAcc = *(s32 *)(hleMixerWorkArea + 12); // 12-13 - RAcc = *(s32 *)(hleMixerWorkArea + 14); // 14-15 - LVol = *(s32 *)(hleMixerWorkArea + 16); // 16-17 - RVol = *(s32 *)(hleMixerWorkArea + 18); // 18-19 - LSig = *(s16 *)(hleMixerWorkArea + 20); // 20-21 - RSig = *(s16 *)(hleMixerWorkArea + 22); // 22-23 - //u32 test = *(s32 *)(hleMixerWorkArea + 24); // 22-23 - //if (test != 0x13371337) - // __asm int 3; - } - - - //if(!(flags&A_AUX)) { - // AuxIncRate=0; - // aux2=aux3=zero; - //} - - for (y = 0; y < (0x170/2); y++) { - - // Left - LAcc += LAdder; - LVol += (LAcc >> 16); - LAcc &= 0xFFFF; - - // Right - RAcc += RAdder; - RVol += (RAcc >> 16); - RAcc &= 0xFFFF; -// **************************************************************** - // Clamp Left - if (LSig >= 0) { // VLT - if (LVol > LTrg) { - LVol = LTrg; - } - } else { // VGE - if (LVol < LTrg) { - LVol = LTrg; - } - } - - // Clamp Right - if (RSig >= 0) { // VLT - if (RVol > RTrg) { - RVol = RTrg; - } - } else { // VGE - if (RVol < RTrg) { - RVol = RTrg; - } - } -// **************************************************************** - MainL = ((Dry * LVol) + 0x4000) >> 15; - MainR = ((Dry * RVol) + 0x4000) >> 15; - - o1 = out [y^1]; - a1 = aux1[y^1]; - i1 = inp [y^1]; - - o1+=((i1*MainL)+0x4000)>>15; - a1+=((i1*MainR)+0x4000)>>15; - -// **************************************************************** - - if(o1>32767) o1=32767; - else if(o1<-32768) o1=-32768; - - if(a1>32767) a1=32767; - else if(a1<-32768) a1=-32768; - -// **************************************************************** - - out[y^1]=o1; - aux1[y^1]=a1; - -// **************************************************************** - //if (!(flags&A_AUX)) { - a2 = aux2[y^1]; - a3 = aux3[y^1]; - - AuxL = ((Wet * LVol) + 0x4000) >> 15; - AuxR = ((Wet * RVol) + 0x4000) >> 15; - - a2+=((i1*AuxL)+0x4000)>>15; - a3+=((i1*AuxR)+0x4000)>>15; - - if(a2>32767) a2=32767; - else if(a2<-32768) a2=-32768; - - if(a3>32767) a3=32767; - else if(a3<-32768) a3=-32768; - - aux2[y^1]=a2; - aux3[y^1]=a3; - } - //} - - *(s16 *)(hleMixerWorkArea + 0) = Wet; // 0-1 - *(s16 *)(hleMixerWorkArea + 2) = Dry; // 2-3 - *(s16 *)(hleMixerWorkArea + 4) = LTrg; // 4-5 - *(s16 *)(hleMixerWorkArea + 6) = RTrg; // 6-7 - *(s32 *)(hleMixerWorkArea + 8) = LAdder; // 8-9 (hleMixerWorkArea is a 16bit pointer) - *(s32 *)(hleMixerWorkArea + 10) = RAdder; // 10-11 - *(s32 *)(hleMixerWorkArea + 12) = LAcc; // 12-13 - *(s32 *)(hleMixerWorkArea + 14) = RAcc; // 14-15 - *(s32 *)(hleMixerWorkArea + 16) = LVol; // 16-17 - *(s32 *)(hleMixerWorkArea + 18) = RVol; // 18-19 - *(s16 *)(hleMixerWorkArea + 20) = LSig; // 20-21 - *(s16 *)(hleMixerWorkArea + 22) = RSig; // 22-23 - //*(u32 *)(hleMixerWorkArea + 24) = 0x13371337; // 22-23 - memcpy(N64MEM+addy, (u8 *)hleMixerWorkArea,80); -} - -static void CLEARBUFF3 () { - u16 addr = (u16)(inst1 & 0xffff); - u16 count = (u16)(inst2 & 0xffff); - memset(BufferSpace+addr+0x4f0, 0, count); -} - -static void MIXER3 () { // Needs accuracy verification... - u16 dmemin = (u16)(inst2 >> 0x10) + 0x4f0; - u16 dmemout = (u16)(inst2 & 0xFFFF) + 0x4f0; - s32 gain = (s16)(inst1 & 0xFFFF)*2; - s32 temp; - int x; - - for (x = 0; x < 0x170; x+=2) { // I think I can do this a lot easier - temp = (*(s16 *)(BufferSpace+dmemin+x) * gain) >> 16; - temp += *(s16 *)(BufferSpace+dmemout+x); - - if ((s32)temp > 32767) - temp = 32767; - if ((s32)temp < -32768) - temp = -32768; - - *(u16 *)(BufferSpace+dmemout+x) = (u16)(temp & 0xFFFF); - } -} - -static void LOADBUFF3 () { - u32 v0; - u32 cnt = (((inst1 >> 0xC)+3)&0xFFC); - v0 = (inst2 & 0xfffffc); - u32 src = (inst1&0xffc)+0x4f0; - memcpy (BufferSpace+src, (u8 *)N64MEM+v0, cnt); -} - -static void SAVEBUFF3 () { - u32 v0; - u32 cnt = (((inst1 >> 0xC)+3)&0xFFC); - v0 = (inst2 & 0xfffffc); - u32 src = (inst1&0xffc)+0x4f0; - memcpy (N64MEM+v0, (u8 *)BufferSpace+src, cnt); -} - -static void LOADADPCM3 () { // Loads an ADPCM table - Works 100% Now 03-13-01 - u32 v0, x; - v0 = (inst2 & 0xffffff); - - u16 *table = (u16 *)(RDRAM+v0); - for (x = 0; x < ((inst1&0xffff)>>0x4); x++) { - adpcmtable[0x1+(x<<3)] = table[0]; - adpcmtable[0x0+(x<<3)] = table[1]; - - adpcmtable[0x3+(x<<3)] = table[2]; - adpcmtable[0x2+(x<<3)] = table[3]; - - adpcmtable[0x5+(x<<3)] = table[4]; - adpcmtable[0x4+(x<<3)] = table[5]; - - adpcmtable[0x7+(x<<3)] = table[6]; - adpcmtable[0x6+(x<<3)] = table[7]; - table += 8; - } -} - -static void DMEMMOVE3 () { // Needs accuracy verification... - u32 v0, v1; - u32 cnt; - v0 = (inst1 & 0xFFFF) + 0x4f0; - v1 = (inst2 >> 0x10) + 0x4f0; - u32 count = ((inst2+3) & 0xfffc); - - for (cnt = 0; cnt < count; cnt++) { - *(u8 *)(BufferSpace+((cnt+v1)^3)) = *(u8 *)(BufferSpace+((cnt+v0)^3)); - } -} - -static void SETLOOP3 () { - loopval = (inst2 & 0xffffff); -} - -static void ADPCM3 () { // Verified to be 100% Accurate... - short count = 0; - unsigned char icode, code, Flags; - int vscale, a[8]; - unsigned short index, j, inPtr; - short *book1,*book2,*out; - unsigned int Address; - - Flags=(u8)(inst2>>0x1c)&0xff; - Address=(inst1 & 0xffffff); - inPtr=(inst2>>12)&0xf; - - out=(short *)(BufferSpace+(inst2&0xfff)+0x4f0); - count=(short)((inst2 >> 16)&0xfff); - - - memset(out,0,32); - - if(!(Flags&0x1)) - { - if(Flags&0x2) - { - memcpy(out,&RDRAM[loopval],32); - } - else - { - memcpy(out,&RDRAM[Address],32); - } - } - - int l1=out[15]; - int l2=out[14]; - int inp1[8]; - int inp2[8]; - out+=16; - while(count>0) - { - // the first interation through, these values are - // either 0 in the case of A_INIT, from a special - // area of memory in the case of A_LOOP or just - // the values we calculated the last time - - code=BufferSpace[(0x4f0+inPtr)^3]; - index=code&0xf; - index<<=4; // index into the adpcm code table - book1=(short *)&adpcmtable[index]; - book2=book1+8; - code>>=4; // upper nibble is scale - vscale=(0x8000>>((12-code)-1)); // very strange. 0x8000 would be .5 in 16:16 format - // so this appears to be a fractional scale based - // on the 12 based inverse of the scale value. note - // that this could be negative, in which case we do - // not use the calculated vscale value... see the - // if(code>12) check below - - inPtr++; // coded adpcm data lies next - j=0; - while(j<8) // loop of 8, for 8 coded nibbles from 4 bytes - // which yields 8 short pcm values - { - icode=BufferSpace[(0x4f0+inPtr)^3]; - inPtr++; - - inp1[j]=(s16)((icode&0xf0)<<8); // this will in effect be signed - if(code<12) - inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - j++; - - inp1[j]=(s16)((icode&0xf)<<12); - if(code<12) - inp1[j]=((int)((int)inp1[j]*(int)vscale)>>16); - j++; - } - j=0; - while(j<8) - { - icode=BufferSpace[(0x4f0+inPtr)^3]; - inPtr++; - - inp2[j]=(short)((icode&0xf0)<<8); // this will in effect be signed - if(code<12) - inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - j++; - - inp2[j]=(short)((icode&0xf)<<12); - if(code<12) - inp2[j]=((int)((int)inp2[j]*(int)vscale)>>16); - j++; - } - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp1[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp1[0]; - a[1]+=(int)inp1[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp1[0]; - a[2]+=(int)book2[0]*inp1[1]; - a[2]+=(int)inp1[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp1[0]; - a[3]+=(int)book2[1]*inp1[1]; - a[3]+=(int)book2[0]*inp1[2]; - a[3]+=(int)inp1[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp1[0]; - a[4]+=(int)book2[2]*inp1[1]; - a[4]+=(int)book2[1]*inp1[2]; - a[4]+=(int)book2[0]*inp1[3]; - a[4]+=(int)inp1[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp1[0]; - a[5]+=(int)book2[3]*inp1[1]; - a[5]+=(int)book2[2]*inp1[2]; - a[5]+=(int)book2[1]*inp1[3]; - a[5]+=(int)book2[0]*inp1[4]; - a[5]+=(int)inp1[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp1[0]; - a[6]+=(int)book2[4]*inp1[1]; - a[6]+=(int)book2[3]*inp1[2]; - a[6]+=(int)book2[2]*inp1[3]; - a[6]+=(int)book2[1]*inp1[4]; - a[6]+=(int)book2[0]*inp1[5]; - a[6]+=(int)inp1[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp1[0]; - a[7]+=(int)book2[5]*inp1[1]; - a[7]+=(int)book2[4]*inp1[2]; - a[7]+=(int)book2[3]*inp1[3]; - a[7]+=(int)book2[2]*inp1[4]; - a[7]+=(int)book2[1]*inp1[5]; - a[7]+=(int)book2[0]*inp1[6]; - a[7]+=(int)inp1[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - - l1=a[6]; - l2=a[7]; - - a[0]= (int)book1[0]*(int)l1; - a[0]+=(int)book2[0]*(int)l2; - a[0]+=(int)inp2[0]*(int)2048; - - a[1] =(int)book1[1]*(int)l1; - a[1]+=(int)book2[1]*(int)l2; - a[1]+=(int)book2[0]*inp2[0]; - a[1]+=(int)inp2[1]*(int)2048; - - a[2] =(int)book1[2]*(int)l1; - a[2]+=(int)book2[2]*(int)l2; - a[2]+=(int)book2[1]*inp2[0]; - a[2]+=(int)book2[0]*inp2[1]; - a[2]+=(int)inp2[2]*(int)2048; - - a[3] =(int)book1[3]*(int)l1; - a[3]+=(int)book2[3]*(int)l2; - a[3]+=(int)book2[2]*inp2[0]; - a[3]+=(int)book2[1]*inp2[1]; - a[3]+=(int)book2[0]*inp2[2]; - a[3]+=(int)inp2[3]*(int)2048; - - a[4] =(int)book1[4]*(int)l1; - a[4]+=(int)book2[4]*(int)l2; - a[4]+=(int)book2[3]*inp2[0]; - a[4]+=(int)book2[2]*inp2[1]; - a[4]+=(int)book2[1]*inp2[2]; - a[4]+=(int)book2[0]*inp2[3]; - a[4]+=(int)inp2[4]*(int)2048; - - a[5] =(int)book1[5]*(int)l1; - a[5]+=(int)book2[5]*(int)l2; - a[5]+=(int)book2[4]*inp2[0]; - a[5]+=(int)book2[3]*inp2[1]; - a[5]+=(int)book2[2]*inp2[2]; - a[5]+=(int)book2[1]*inp2[3]; - a[5]+=(int)book2[0]*inp2[4]; - a[5]+=(int)inp2[5]*(int)2048; - - a[6] =(int)book1[6]*(int)l1; - a[6]+=(int)book2[6]*(int)l2; - a[6]+=(int)book2[5]*inp2[0]; - a[6]+=(int)book2[4]*inp2[1]; - a[6]+=(int)book2[3]*inp2[2]; - a[6]+=(int)book2[2]*inp2[3]; - a[6]+=(int)book2[1]*inp2[4]; - a[6]+=(int)book2[0]*inp2[5]; - a[6]+=(int)inp2[6]*(int)2048; - - a[7] =(int)book1[7]*(int)l1; - a[7]+=(int)book2[7]*(int)l2; - a[7]+=(int)book2[6]*inp2[0]; - a[7]+=(int)book2[5]*inp2[1]; - a[7]+=(int)book2[4]*inp2[2]; - a[7]+=(int)book2[3]*inp2[3]; - a[7]+=(int)book2[2]*inp2[4]; - a[7]+=(int)book2[1]*inp2[5]; - a[7]+=(int)book2[0]*inp2[6]; - a[7]+=(int)inp2[7]*(int)2048; - - for(j=0;j<8;j++) - { - a[j^1]>>=11; - if(a[j^1]>32767) a[j^1]=32767; - else if(a[j^1]<-32768) a[j^1]=-32768; - *(out++)=a[j^1]; - } - l1=a[6]; - l2=a[7]; - - count-=32; - } - out-=16; - memcpy(&RDRAM[Address],out,32); -} - -static void RESAMPLE3 () { - s32 temp; - s32 accum; - s16 *lut; - short *dst; - s16 *src; - unsigned char Flags; - u32 dstPtr, srcPtr, x, addy, Pitch, location, Accum, i; - Flags=(u8)((inst2>>0x1e)); - Pitch=((inst2>>0xe)&0xffff)<<1; - addy = (inst1 & 0xffffff); - Accum=0; - dst=(short *)(BufferSpace); - src=(s16 *)(BufferSpace); - srcPtr=((((inst2>>2)&0xfff)+0x4f0)/2); - - srcPtr -= 4; - - if (inst2 & 0x3) { - dstPtr = 0x660/2; - } else { - dstPtr = 0x4f0/2; - } - - if ((Flags & 0x1) == 0) { - for (x=0; x < 4; x++) //memcpy (src+srcPtr, rsp.RDRAM+addy, 0x8); - src[(srcPtr+x)^1] = ((u16 *)RDRAM)[((addy/2)+x)^1]; - Accum = *(u16 *)(RDRAM+addy+10); - } else { - for (x=0; x < 4; x++) - src[(srcPtr+x)^1] = 0;//*(u16 *)(rsp.RDRAM+((addy+x)^2)); - } - - //if ((Flags & 0x2)) - // __asm int 3; - - for(i=0;i < 0x170/2;i++) { - location = (((Accum * 0x40) >> 0x10) * 8); - //location = (Accum >> 0xa) << 0x3; - lut = (s16 *)(((u8 *)ResampleLUT) + location); - - temp = ((s32)*(s16*)(src+((srcPtr+0)^1))*((s32)((s16)lut[0]))); - accum = (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+1)^1))*((s32)((s16)lut[1]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+2)^1))*((s32)((s16)lut[2]))); - accum += (s32)(temp >> 15); - - temp = ((s32)*(s16*)(src+((srcPtr+3)^1))*((s32)((s16)lut[3]))); - accum += (s32)(temp >> 15); - - if (accum > 32767) accum = 32767; - if (accum < -32768) accum = -32768; - - dst[dstPtr^1] = (accum); - dstPtr++; - Accum += Pitch; - srcPtr += (Accum>>16); - Accum&=0xffff; - } - for (x=0; x < 4; x++) - ((u16 *)RDRAM)[((addy/2)+x)^1] = src[(srcPtr+x)^1]; - *(u16 *)(RDRAM+addy+10) = Accum; -} - -static void INTERLEAVE3 () { // Needs accuracy verification... - //u32 inL, inR; - int x = 0; - u16 *inSrcR; - u16 *inSrcL; - u16 Left, Right; - - u16 *outbuff = (u16 *)(BufferSpace + 0x4f0);//(u16 *)(AudioOutBuffer+dmem); - - inSrcR = (u16 *)(BufferSpace+0xb40); - inSrcL = (u16 *)(BufferSpace+0x9d0); - - for (x = 0; x < (0x170/4); x++) { - Left=*(inSrcL++); - Right=*(inSrcR++); - - *(outbuff++)=*(inSrcR++); - *(outbuff++)=*(inSrcL++); - *(outbuff++)=(u16)Right; - *(outbuff++)=(u16)Left; - } -} - -static void WHATISTHIS () { -} - -u32 setaddr; -static void MP3ADDY () { - setaddr = (inst2 & 0xffffff); -} - -void rsp_run(); -void mp3setup (unsigned int inst1, unsigned int inst2, unsigned int t8); - -extern u32 base, dmembase; -extern char *pDMEM; - -void MP3 (); - -static void DISABLE () { -} - - -void (*ABI3[0x20])() = { - DISABLE , ADPCM3 , CLEARBUFF3, ENVMIXER3 , LOADBUFF3, RESAMPLE3 , SAVEBUFF3, MP3, - MP3ADDY, SETVOL3, DMEMMOVE3 , LOADADPCM3 , MIXER3 , INTERLEAVE3, WHATISTHIS , SETLOOP3, - SPNOOP , SPNOOP, SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP, - SPNOOP , SPNOOP, SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP , SPNOOP -}; diff --git a/src/usf/audio_ucode3mp3.c b/src/usf/audio_ucode3mp3.c deleted file mode 100644 index 72d2e45..0000000 --- a/src/usf/audio_ucode3mp3.c +++ /dev/null @@ -1,588 +0,0 @@ -#include -#include "usf.h" -#include "audio_hle.h" -#include "memory.h" - - - -static u16 DeWindowLUT [0x420] = { - 0x0000, 0xFFF3, 0x005D, 0xFF38, 0x037A, 0xF736, 0x0B37, 0xC00E, - 0x7FFF, 0x3FF2, 0x0B37, 0x08CA, 0x037A, 0x00C8, 0x005D, 0x000D, - 0x0000, 0xFFF3, 0x005D, 0xFF38, 0x037A, 0xF736, 0x0B37, 0xC00E, - 0x7FFF, 0x3FF2, 0x0B37, 0x08CA, 0x037A, 0x00C8, 0x005D, 0x000D, - 0x0000, 0xFFF2, 0x005F, 0xFF1D, 0x0369, 0xF697, 0x0A2A, 0xBCE7, - 0x7FEB, 0x3CCB, 0x0C2B, 0x082B, 0x0385, 0x00AF, 0x005B, 0x000B, - 0x0000, 0xFFF2, 0x005F, 0xFF1D, 0x0369, 0xF697, 0x0A2A, 0xBCE7, - 0x7FEB, 0x3CCB, 0x0C2B, 0x082B, 0x0385, 0x00AF, 0x005B, 0x000B, - 0x0000, 0xFFF1, 0x0061, 0xFF02, 0x0354, 0xF5F9, 0x0905, 0xB9C4, - 0x7FB0, 0x39A4, 0x0D08, 0x078C, 0x038C, 0x0098, 0x0058, 0x000A, - 0x0000, 0xFFF1, 0x0061, 0xFF02, 0x0354, 0xF5F9, 0x0905, 0xB9C4, - 0x7FB0, 0x39A4, 0x0D08, 0x078C, 0x038C, 0x0098, 0x0058, 0x000A, - 0x0000, 0xFFEF, 0x0062, 0xFEE6, 0x033B, 0xF55C, 0x07C8, 0xB6A4, - 0x7F4D, 0x367E, 0x0DCE, 0x06EE, 0x038F, 0x0080, 0x0056, 0x0009, - 0x0000, 0xFFEF, 0x0062, 0xFEE6, 0x033B, 0xF55C, 0x07C8, 0xB6A4, - 0x7F4D, 0x367E, 0x0DCE, 0x06EE, 0x038F, 0x0080, 0x0056, 0x0009, - 0x0000, 0xFFEE, 0x0063, 0xFECA, 0x031C, 0xF4C3, 0x0671, 0xB38C, - 0x7EC2, 0x335D, 0x0E7C, 0x0652, 0x038E, 0x006B, 0x0053, 0x0008, - 0x0000, 0xFFEE, 0x0063, 0xFECA, 0x031C, 0xF4C3, 0x0671, 0xB38C, - 0x7EC2, 0x335D, 0x0E7C, 0x0652, 0x038E, 0x006B, 0x0053, 0x0008, - 0x0000, 0xFFEC, 0x0064, 0xFEAC, 0x02F7, 0xF42C, 0x0502, 0xB07C, - 0x7E12, 0x3041, 0x0F14, 0x05B7, 0x038A, 0x0056, 0x0050, 0x0007, - 0x0000, 0xFFEC, 0x0064, 0xFEAC, 0x02F7, 0xF42C, 0x0502, 0xB07C, - 0x7E12, 0x3041, 0x0F14, 0x05B7, 0x038A, 0x0056, 0x0050, 0x0007, - 0x0000, 0xFFEB, 0x0064, 0xFE8E, 0x02CE, 0xF399, 0x037A, 0xAD75, - 0x7D3A, 0x2D2C, 0x0F97, 0x0520, 0x0382, 0x0043, 0x004D, 0x0007, - 0x0000, 0xFFEB, 0x0064, 0xFE8E, 0x02CE, 0xF399, 0x037A, 0xAD75, - 0x7D3A, 0x2D2C, 0x0F97, 0x0520, 0x0382, 0x0043, 0x004D, 0x0007, - 0xFFFF, 0xFFE9, 0x0063, 0xFE6F, 0x029E, 0xF30B, 0x01D8, 0xAA7B, - 0x7C3D, 0x2A1F, 0x1004, 0x048B, 0x0377, 0x0030, 0x004A, 0x0006, - 0xFFFF, 0xFFE9, 0x0063, 0xFE6F, 0x029E, 0xF30B, 0x01D8, 0xAA7B, - 0x7C3D, 0x2A1F, 0x1004, 0x048B, 0x0377, 0x0030, 0x004A, 0x0006, - 0xFFFF, 0xFFE7, 0x0062, 0xFE4F, 0x0269, 0xF282, 0x001F, 0xA78D, - 0x7B1A, 0x271C, 0x105D, 0x03F9, 0x036A, 0x001F, 0x0046, 0x0006, - 0xFFFF, 0xFFE7, 0x0062, 0xFE4F, 0x0269, 0xF282, 0x001F, 0xA78D, - 0x7B1A, 0x271C, 0x105D, 0x03F9, 0x036A, 0x001F, 0x0046, 0x0006, - 0xFFFF, 0xFFE4, 0x0061, 0xFE2F, 0x022F, 0xF1FF, 0xFE4C, 0xA4AF, - 0x79D3, 0x2425, 0x10A2, 0x036C, 0x0359, 0x0010, 0x0043, 0x0005, - 0xFFFF, 0xFFE4, 0x0061, 0xFE2F, 0x022F, 0xF1FF, 0xFE4C, 0xA4AF, - 0x79D3, 0x2425, 0x10A2, 0x036C, 0x0359, 0x0010, 0x0043, 0x0005, - 0xFFFF, 0xFFE2, 0x005E, 0xFE10, 0x01EE, 0xF184, 0xFC61, 0xA1E1, - 0x7869, 0x2139, 0x10D3, 0x02E3, 0x0346, 0x0001, 0x0040, 0x0004, - 0xFFFF, 0xFFE2, 0x005E, 0xFE10, 0x01EE, 0xF184, 0xFC61, 0xA1E1, - 0x7869, 0x2139, 0x10D3, 0x02E3, 0x0346, 0x0001, 0x0040, 0x0004, - 0xFFFF, 0xFFE0, 0x005B, 0xFDF0, 0x01A8, 0xF111, 0xFA5F, 0x9F27, - 0x76DB, 0x1E5C, 0x10F2, 0x025E, 0x0331, 0xFFF3, 0x003D, 0x0004, - 0xFFFF, 0xFFE0, 0x005B, 0xFDF0, 0x01A8, 0xF111, 0xFA5F, 0x9F27, - 0x76DB, 0x1E5C, 0x10F2, 0x025E, 0x0331, 0xFFF3, 0x003D, 0x0004, - 0xFFFF, 0xFFDE, 0x0057, 0xFDD0, 0x015B, 0xF0A7, 0xF845, 0x9C80, - 0x752C, 0x1B8E, 0x1100, 0x01DE, 0x0319, 0xFFE7, 0x003A, 0x0003, - 0xFFFF, 0xFFDE, 0x0057, 0xFDD0, 0x015B, 0xF0A7, 0xF845, 0x9C80, - 0x752C, 0x1B8E, 0x1100, 0x01DE, 0x0319, 0xFFE7, 0x003A, 0x0003, - 0xFFFE, 0xFFDB, 0x0053, 0xFDB0, 0x0108, 0xF046, 0xF613, 0x99EE, - 0x735C, 0x18D1, 0x10FD, 0x0163, 0x0300, 0xFFDC, 0x0037, 0x0003, - 0xFFFE, 0xFFDB, 0x0053, 0xFDB0, 0x0108, 0xF046, 0xF613, 0x99EE, - 0x735C, 0x18D1, 0x10FD, 0x0163, 0x0300, 0xFFDC, 0x0037, 0x0003, - 0xFFFE, 0xFFD8, 0x004D, 0xFD90, 0x00B0, 0xEFF0, 0xF3CC, 0x9775, - 0x716C, 0x1624, 0x10EA, 0x00EE, 0x02E5, 0xFFD2, 0x0033, 0x0003, - 0xFFFE, 0xFFD8, 0x004D, 0xFD90, 0x00B0, 0xEFF0, 0xF3CC, 0x9775, - 0x716C, 0x1624, 0x10EA, 0x00EE, 0x02E5, 0xFFD2, 0x0033, 0x0003, - 0xFFFE, 0xFFD6, 0x0047, 0xFD72, 0x0051, 0xEFA6, 0xF16F, 0x9514, - 0x6F5E, 0x138A, 0x10C8, 0x007E, 0x02CA, 0xFFC9, 0x0030, 0x0003, - 0xFFFE, 0xFFD6, 0x0047, 0xFD72, 0x0051, 0xEFA6, 0xF16F, 0x9514, - 0x6F5E, 0x138A, 0x10C8, 0x007E, 0x02CA, 0xFFC9, 0x0030, 0x0003, - 0xFFFE, 0xFFD3, 0x0040, 0xFD54, 0xFFEC, 0xEF68, 0xEEFC, 0x92CD, - 0x6D33, 0x1104, 0x1098, 0x0014, 0x02AC, 0xFFC0, 0x002D, 0x0002, - 0xFFFE, 0xFFD3, 0x0040, 0xFD54, 0xFFEC, 0xEF68, 0xEEFC, 0x92CD, - 0x6D33, 0x1104, 0x1098, 0x0014, 0x02AC, 0xFFC0, 0x002D, 0x0002, - 0x0030, 0xFFC9, 0x02CA, 0x007E, 0x10C8, 0x138A, 0x6F5E, 0x9514, - 0xF16F, 0xEFA6, 0x0051, 0xFD72, 0x0047, 0xFFD6, 0xFFFE, 0x0003, - 0x0030, 0xFFC9, 0x02CA, 0x007E, 0x10C8, 0x138A, 0x6F5E, 0x9514, - 0xF16F, 0xEFA6, 0x0051, 0xFD72, 0x0047, 0xFFD6, 0xFFFE, 0x0003, - 0x0033, 0xFFD2, 0x02E5, 0x00EE, 0x10EA, 0x1624, 0x716C, 0x9775, - 0xF3CC, 0xEFF0, 0x00B0, 0xFD90, 0x004D, 0xFFD8, 0xFFFE, 0x0003, - 0x0033, 0xFFD2, 0x02E5, 0x00EE, 0x10EA, 0x1624, 0x716C, 0x9775, - 0xF3CC, 0xEFF0, 0x00B0, 0xFD90, 0x004D, 0xFFD8, 0xFFFE, 0x0003, - 0x0037, 0xFFDC, 0x0300, 0x0163, 0x10FD, 0x18D1, 0x735C, 0x99EE, - 0xF613, 0xF046, 0x0108, 0xFDB0, 0x0053, 0xFFDB, 0xFFFE, 0x0003, - 0x0037, 0xFFDC, 0x0300, 0x0163, 0x10FD, 0x18D1, 0x735C, 0x99EE, - 0xF613, 0xF046, 0x0108, 0xFDB0, 0x0053, 0xFFDB, 0xFFFE, 0x0003, - 0x003A, 0xFFE7, 0x0319, 0x01DE, 0x1100, 0x1B8E, 0x752C, 0x9C80, - 0xF845, 0xF0A7, 0x015B, 0xFDD0, 0x0057, 0xFFDE, 0xFFFF, 0x0003, - 0x003A, 0xFFE7, 0x0319, 0x01DE, 0x1100, 0x1B8E, 0x752C, 0x9C80, - 0xF845, 0xF0A7, 0x015B, 0xFDD0, 0x0057, 0xFFDE, 0xFFFF, 0x0004, - 0x003D, 0xFFF3, 0x0331, 0x025E, 0x10F2, 0x1E5C, 0x76DB, 0x9F27, - 0xFA5F, 0xF111, 0x01A8, 0xFDF0, 0x005B, 0xFFE0, 0xFFFF, 0x0004, - 0x003D, 0xFFF3, 0x0331, 0x025E, 0x10F2, 0x1E5C, 0x76DB, 0x9F27, - 0xFA5F, 0xF111, 0x01A8, 0xFDF0, 0x005B, 0xFFE0, 0xFFFF, 0x0004, - 0x0040, 0x0001, 0x0346, 0x02E3, 0x10D3, 0x2139, 0x7869, 0xA1E1, - 0xFC61, 0xF184, 0x01EE, 0xFE10, 0x005E, 0xFFE2, 0xFFFF, 0x0004, - 0x0040, 0x0001, 0x0346, 0x02E3, 0x10D3, 0x2139, 0x7869, 0xA1E1, - 0xFC61, 0xF184, 0x01EE, 0xFE10, 0x005E, 0xFFE2, 0xFFFF, 0x0005, - 0x0043, 0x0010, 0x0359, 0x036C, 0x10A2, 0x2425, 0x79D3, 0xA4AF, - 0xFE4C, 0xF1FF, 0x022F, 0xFE2F, 0x0061, 0xFFE4, 0xFFFF, 0x0005, - 0x0043, 0x0010, 0x0359, 0x036C, 0x10A2, 0x2425, 0x79D3, 0xA4AF, - 0xFE4C, 0xF1FF, 0x022F, 0xFE2F, 0x0061, 0xFFE4, 0xFFFF, 0x0006, - 0x0046, 0x001F, 0x036A, 0x03F9, 0x105D, 0x271C, 0x7B1A, 0xA78D, - 0x001F, 0xF282, 0x0269, 0xFE4F, 0x0062, 0xFFE7, 0xFFFF, 0x0006, - 0x0046, 0x001F, 0x036A, 0x03F9, 0x105D, 0x271C, 0x7B1A, 0xA78D, - 0x001F, 0xF282, 0x0269, 0xFE4F, 0x0062, 0xFFE7, 0xFFFF, 0x0006, - 0x004A, 0x0030, 0x0377, 0x048B, 0x1004, 0x2A1F, 0x7C3D, 0xAA7B, - 0x01D8, 0xF30B, 0x029E, 0xFE6F, 0x0063, 0xFFE9, 0xFFFF, 0x0006, - 0x004A, 0x0030, 0x0377, 0x048B, 0x1004, 0x2A1F, 0x7C3D, 0xAA7B, - 0x01D8, 0xF30B, 0x029E, 0xFE6F, 0x0063, 0xFFE9, 0xFFFF, 0x0007, - 0x004D, 0x0043, 0x0382, 0x0520, 0x0F97, 0x2D2C, 0x7D3A, 0xAD75, - 0x037A, 0xF399, 0x02CE, 0xFE8E, 0x0064, 0xFFEB, 0x0000, 0x0007, - 0x004D, 0x0043, 0x0382, 0x0520, 0x0F97, 0x2D2C, 0x7D3A, 0xAD75, - 0x037A, 0xF399, 0x02CE, 0xFE8E, 0x0064, 0xFFEB, 0x0000, 0x0007, - 0x0050, 0x0056, 0x038A, 0x05B7, 0x0F14, 0x3041, 0x7E12, 0xB07C, - 0x0502, 0xF42C, 0x02F7, 0xFEAC, 0x0064, 0xFFEC, 0x0000, 0x0007, - 0x0050, 0x0056, 0x038A, 0x05B7, 0x0F14, 0x3041, 0x7E12, 0xB07C, - 0x0502, 0xF42C, 0x02F7, 0xFEAC, 0x0064, 0xFFEC, 0x0000, 0x0008, - 0x0053, 0x006B, 0x038E, 0x0652, 0x0E7C, 0x335D, 0x7EC2, 0xB38C, - 0x0671, 0xF4C3, 0x031C, 0xFECA, 0x0063, 0xFFEE, 0x0000, 0x0008, - 0x0053, 0x006B, 0x038E, 0x0652, 0x0E7C, 0x335D, 0x7EC2, 0xB38C, - 0x0671, 0xF4C3, 0x031C, 0xFECA, 0x0063, 0xFFEE, 0x0000, 0x0009, - 0x0056, 0x0080, 0x038F, 0x06EE, 0x0DCE, 0x367E, 0x7F4D, 0xB6A4, - 0x07C8, 0xF55C, 0x033B, 0xFEE6, 0x0062, 0xFFEF, 0x0000, 0x0009, - 0x0056, 0x0080, 0x038F, 0x06EE, 0x0DCE, 0x367E, 0x7F4D, 0xB6A4, - 0x07C8, 0xF55C, 0x033B, 0xFEE6, 0x0062, 0xFFEF, 0x0000, 0x000A, - 0x0058, 0x0098, 0x038C, 0x078C, 0x0D08, 0x39A4, 0x7FB0, 0xB9C4, - 0x0905, 0xF5F9, 0x0354, 0xFF02, 0x0061, 0xFFF1, 0x0000, 0x000A, - 0x0058, 0x0098, 0x038C, 0x078C, 0x0D08, 0x39A4, 0x7FB0, 0xB9C4, - 0x0905, 0xF5F9, 0x0354, 0xFF02, 0x0061, 0xFFF1, 0x0000, 0x000B, - 0x005B, 0x00AF, 0x0385, 0x082B, 0x0C2B, 0x3CCB, 0x7FEB, 0xBCE7, - 0x0A2A, 0xF697, 0x0369, 0xFF1D, 0x005F, 0xFFF2, 0x0000, 0x000B, - 0x005B, 0x00AF, 0x0385, 0x082B, 0x0C2B, 0x3CCB, 0x7FEB, 0xBCE7, - 0x0A2A, 0xF697, 0x0369, 0xFF1D, 0x005F, 0xFFF2, 0x0000, 0x000D, - 0x005D, 0x00C8, 0x037A, 0x08CA, 0x0B37, 0x3FF2, 0x7FFF, 0xC00E, - 0x0B37, 0xF736, 0x037A, 0xFF38, 0x005D, 0xFFF3, 0x0000, 0x000D, - 0x005D, 0x00C8, 0x037A, 0x08CA, 0x0B37, 0x3FF2, 0x7FFF, 0xC00E, - 0x0B37, 0xF736, 0x037A, 0xFF38, 0x005D, 0xFFF3, 0x0000, 0x0000 -}; - -//static u16 myVector[32][8]; - -static u8 mp3data[0x1000]; - -static s32 v[32]; - -static void MP3AB0 () { - // Part 2 - 100% Accurate - const u16 LUT2[8] = { 0xFEC4, 0xF4FA, 0xC5E4, 0xE1C4, - 0x1916, 0x4A50, 0xA268, 0x78AE }; - const u16 LUT3[4] = { 0xFB14, 0xD4DC, 0x31F2, 0x8E3A }; - int i; - - for (i = 0; i < 8; i++) { - v[16+i] = v[0+i] + v[8+i]; - v[24+i] = ((v[0+i] - v[8+i]) * LUT2[i]) >> 0x10; - } - - // Part 3: 4-wide butterflies - - for (i=0; i < 4; i++) { - v[0+i] = v[16+i] + v[20+i]; - v[4+i] = ((v[16+i] - v[20+i]) * LUT3[i]) >> 0x10; - - v[8+i] = v[24+i] + v[28+i]; - v[12+i] = ((v[24+i] - v[28+i]) * LUT3[i]) >> 0x10; - } - - // Part 4: 2-wide butterflies - 100% Accurate - - for (i = 0; i < 16; i+=4) { - v[16+i] = v[0+i] + v[2+i]; - v[18+i] = ((v[0+i] - v[2+i]) * 0xEC84) >> 0x10; - - v[17+i] = v[1+i] + v[3+i]; - v[19+i] = ((v[1+i] - v[3+i]) * 0x61F8) >> 0x10; - } -} - -static void InnerLoop (); - - u32 inPtr, outPtr; - - u32 t6;// = 0x08A0; // I think these are temporary storage buffers - u32 t5;// = 0x0AC0; - u32 t4;// = (inst1 & 0x1E); - -void MP3 () { - // Initialization Code - u32 readPtr; // s5 - u32 writePtr; // s6 - //u32 Count = 0x0480; // s4 - u32 tmp; - //u32 inPtr, outPtr; - int cnt, cnt2; - - t6 = 0x08A0; // I think these are temporary storage buffers - t5 = 0x0AC0; - t4 = (inst1 & 0x1E); - - writePtr = inst2 & 0xFFFFFF; - readPtr = writePtr; - memcpy (mp3data+0xCE8, N64MEM+(readPtr), 8); // Just do that for efficiency... may remove and use directly later anyway - readPtr += 8; // This must be a header byte or whatnot - - for (cnt = 0; cnt < 0x480; cnt += 0x180) { - memcpy (mp3data+0xCF0, N64MEM+(readPtr), 0x180); // DMA: 0xCF0 <- RDRAM[s5] : 0x180 - inPtr = 0xCF0; // s7 - outPtr = 0xE70; // s3 -// --------------- Inner Loop Start -------------------- - for (cnt2 = 0; cnt2 < 0x180; cnt2 += 0x40) { - t6 &= 0xFFE0; - t5 &= 0xFFE0; - t6 |= t4; - t5 |= t4; - InnerLoop (); - t4 = (t4-2)&0x1E; - tmp = t6; - t6 = t5; - t5 = tmp; - //outPtr += 0x40; - inPtr += 0x40; - } -// --------------- Inner Loop End -------------------- - memcpy ((u8*)N64MEM+writePtr, mp3data+0xe70, 0x180); - writePtr += 0x180; - readPtr += 0x180; - } -} - - - -static void InnerLoop () { - // Part 1: 100% Accurate - - int i; - v[0] = *(s16 *)(mp3data+inPtr+(0x00^2)); v[31] = *(s16 *)(mp3data+inPtr+(0x3E^2)); v[0] += v[31]; - v[1] = *(s16 *)(mp3data+inPtr+(0x02^2)); v[30] = *(s16 *)(mp3data+inPtr+(0x3C^2)); v[1] += v[30]; - v[2] = *(s16 *)(mp3data+inPtr+(0x06^2)); v[28] = *(s16 *)(mp3data+inPtr+(0x38^2)); v[2] += v[28]; - v[3] = *(s16 *)(mp3data+inPtr+(0x04^2)); v[29] = *(s16 *)(mp3data+inPtr+(0x3A^2)); v[3] += v[29]; - - v[4] = *(s16 *)(mp3data+inPtr+(0x0E^2)); v[24] = *(s16 *)(mp3data+inPtr+(0x30^2)); v[4] += v[24]; - v[5] = *(s16 *)(mp3data+inPtr+(0x0C^2)); v[25] = *(s16 *)(mp3data+inPtr+(0x32^2)); v[5] += v[25]; - v[6] = *(s16 *)(mp3data+inPtr+(0x08^2)); v[27] = *(s16 *)(mp3data+inPtr+(0x36^2)); v[6] += v[27]; - v[7] = *(s16 *)(mp3data+inPtr+(0x0A^2)); v[26] = *(s16 *)(mp3data+inPtr+(0x34^2)); v[7] += v[26]; - - v[8] = *(s16 *)(mp3data+inPtr+(0x1E^2)); v[16] = *(s16 *)(mp3data+inPtr+(0x20^2)); v[8] += v[16]; - v[9] = *(s16 *)(mp3data+inPtr+(0x1C^2)); v[17] = *(s16 *)(mp3data+inPtr+(0x22^2)); v[9] += v[17]; - v[10]= *(s16 *)(mp3data+inPtr+(0x18^2)); v[19] = *(s16 *)(mp3data+inPtr+(0x26^2)); v[10]+= v[19]; - v[11]= *(s16 *)(mp3data+inPtr+(0x1A^2)); v[18] = *(s16 *)(mp3data+inPtr+(0x24^2)); v[11]+= v[18]; - - v[12]= *(s16 *)(mp3data+inPtr+(0x10^2)); v[23] = *(s16 *)(mp3data+inPtr+(0x2E^2)); v[12]+= v[23]; - v[13]= *(s16 *)(mp3data+inPtr+(0x12^2)); v[22] = *(s16 *)(mp3data+inPtr+(0x2C^2)); v[13]+= v[22]; - v[14]= *(s16 *)(mp3data+inPtr+(0x16^2)); v[20] = *(s16 *)(mp3data+inPtr+(0x28^2)); v[14]+= v[20]; - v[15]= *(s16 *)(mp3data+inPtr+(0x14^2)); v[21] = *(s16 *)(mp3data+inPtr+(0x2A^2)); v[15]+= v[21]; - - // Part 2-4 - - MP3AB0 (); - - // Part 5 - 1-Wide Butterflies - 100% Accurate but need SSVs!!! - - u32 t0 = t6 + 0x100; - u32 t1 = t6 + 0x200; - u32 t2 = t5 + 0x100; - u32 t3 = t5 + 0x200; - /*RSP_GPR[0x8].W = t0; - RSP_GPR[0x9].W = t1; - RSP_GPR[0xA].W = t2; - RSP_GPR[0xB].W = t3; - - RSP_Vect[0].DW[1] = 0xB504A57E00016A09; - RSP_Vect[0].DW[0] = 0x0002D4130005A827; -*/ - if ((t1 | t2 | t3 | t5 | t6) & 0x1) -// __asm int 3; - do {} while (0); - - // 0x13A8 - v[1] = 0; - v[11] = ((v[16] - v[17]) * 0xB504) >> 0x10; - - v[16] = -v[16] -v[17]; - v[2] = v[18] + v[19]; - // ** Store v[11] -> (T6 + 0)** - *(s16 *)(mp3data+((t6+(short)0x0))) = (short)v[11]; - - - v[11] = -v[11]; - // ** Store v[16] -> (T3 + 0)** - *(s16 *)(mp3data+((t3+(short)0x0))) = (short)v[16]; - // ** Store v[11] -> (T5 + 0)** - *(s16 *)(mp3data+((t5+(short)0x0))) = (short)v[11]; - // 0x13E8 - Verified.... - v[2] = -v[2]; - // ** Store v[2] -> (T2 + 0)** - *(s16 *)(mp3data+((t2+(short)0x0))) = (short)v[2]; - v[3] = (((v[18] - v[19]) * 0x16A09) >> 0x10) + v[2]; - // ** Store v[3] -> (T0 + 0)** - *(s16 *)(mp3data+((t0+(short)0x0))) = (short)v[3]; - // 0x1400 - Verified - v[4] = -v[20] -v[21]; - v[6] = v[22] + v[23]; - v[5] = ((v[20] - v[21]) * 0x16A09) >> 0x10; - // ** Store v[4] -> (T3 + 0xFF80) - *(s16 *)(mp3data+((t3+(short)0xFF80))) = (short)v[4]; - v[7] = ((v[22] - v[23]) * 0x2D413) >> 0x10; - v[5] = v[5] - v[4]; - v[7] = v[7] - v[5]; - v[6] = v[6] + v[6]; - v[5] = v[5] - v[6]; - v[4] = -v[4] - v[6]; - // *** Store v[7] -> (T1 + 0xFF80) - *(s16 *)(mp3data+((t1+(short)0xFF80))) = (short)v[7]; - // *** Store v[4] -> (T2 + 0xFF80) - *(s16 *)(mp3data+((t2+(short)0xFF80))) = (short)v[4]; - // *** Store v[5] -> (T0 + 0xFF80) - *(s16 *)(mp3data+((t0+(short)0xFF80))) = (short)v[5]; - v[8] = v[24] + v[25]; - - - v[9] = ((v[24] - v[25]) * 0x16A09) >> 0x10; - v[2] = v[8] + v[9]; - v[11] = ((v[26] - v[27]) * 0x2D413) >> 0x10; - v[13] = ((v[28] - v[29]) * 0x2D413) >> 0x10; - - v[10] = v[26] + v[27]; v[10] = v[10] + v[10]; - v[12] = v[28] + v[29]; v[12] = v[12] + v[12]; - v[14] = v[30] + v[31]; - v[3] = v[8] + v[10]; - v[14] = v[14] + v[14]; - v[13] = (v[13] - v[2]) + v[12]; - v[15] = (((v[30] - v[31]) * 0x5A827) >> 0x10) - (v[11] + v[2]); - v[14] = -(v[14] + v[14]) + v[3]; - v[17] = v[13] - v[10]; - v[9] = v[9] + v[14]; - // ** Store v[9] -> (T6 + 0x40) - *(s16 *)(mp3data+((t6+(short)0x40))) = (short)v[9]; - v[11] = v[11] - v[13]; - // ** Store v[17] -> (T0 + 0xFFC0) - *(s16 *)(mp3data+((t0+(short)0xFFC0))) = (short)v[17]; - v[12] = v[8] - v[12]; - // ** Store v[11] -> (T0 + 0x40) - *(s16 *)(mp3data+((t0+(short)0x40))) = (short)v[11]; - v[8] = -v[8]; - // ** Store v[15] -> (T1 + 0xFFC0) - *(s16 *)(mp3data+((t1+(short)0xFFC0))) = (short)v[15]; - v[10] = -v[10] -v[12]; - // ** Store v[12] -> (T2 + 0x40) - *(s16 *)(mp3data+((t2+(short)0x40))) = (short)v[12]; - // ** Store v[8] -> (T3 + 0xFFC0) - *(s16 *)(mp3data+((t3+(short)0xFFC0))) = (short)v[8]; - // ** Store v[14] -> (T5 + 0x40) - *(s16 *)(mp3data+((t5+(short)0x40))) = (short)v[14]; - // ** Store v[10] -> (T2 + 0xFFC0) - *(s16 *)(mp3data+((t2+(short)0xFFC0))) = (short)v[10]; - // 0x14FC - Verified... - - // Part 6 - 100% Accurate - - v[0] = *(s16 *)(mp3data+inPtr+(0x00^2)); v[31] = *(s16 *)(mp3data+inPtr+(0x3E^2)); v[0] -= v[31]; - v[1] = *(s16 *)(mp3data+inPtr+(0x02^2)); v[30] = *(s16 *)(mp3data+inPtr+(0x3C^2)); v[1] -= v[30]; - v[2] = *(s16 *)(mp3data+inPtr+(0x06^2)); v[28] = *(s16 *)(mp3data+inPtr+(0x38^2)); v[2] -= v[28]; - v[3] = *(s16 *)(mp3data+inPtr+(0x04^2)); v[29] = *(s16 *)(mp3data+inPtr+(0x3A^2)); v[3] -= v[29]; - - v[4] = *(s16 *)(mp3data+inPtr+(0x0E^2)); v[24] = *(s16 *)(mp3data+inPtr+(0x30^2)); v[4] -= v[24]; - v[5] = *(s16 *)(mp3data+inPtr+(0x0C^2)); v[25] = *(s16 *)(mp3data+inPtr+(0x32^2)); v[5] -= v[25]; - v[6] = *(s16 *)(mp3data+inPtr+(0x08^2)); v[27] = *(s16 *)(mp3data+inPtr+(0x36^2)); v[6] -= v[27]; - v[7] = *(s16 *)(mp3data+inPtr+(0x0A^2)); v[26] = *(s16 *)(mp3data+inPtr+(0x34^2)); v[7] -= v[26]; - - v[8] = *(s16 *)(mp3data+inPtr+(0x1E^2)); v[16] = *(s16 *)(mp3data+inPtr+(0x20^2)); v[8] -= v[16]; - v[9] = *(s16 *)(mp3data+inPtr+(0x1C^2)); v[17] = *(s16 *)(mp3data+inPtr+(0x22^2)); v[9] -= v[17]; - v[10]= *(s16 *)(mp3data+inPtr+(0x18^2)); v[19] = *(s16 *)(mp3data+inPtr+(0x26^2)); v[10]-= v[19]; - v[11]= *(s16 *)(mp3data+inPtr+(0x1A^2)); v[18] = *(s16 *)(mp3data+inPtr+(0x24^2)); v[11]-= v[18]; - - v[12]= *(s16 *)(mp3data+inPtr+(0x10^2)); v[23] = *(s16 *)(mp3data+inPtr+(0x2E^2)); v[12]-= v[23]; - v[13]= *(s16 *)(mp3data+inPtr+(0x12^2)); v[22] = *(s16 *)(mp3data+inPtr+(0x2C^2)); v[13]-= v[22]; - v[14]= *(s16 *)(mp3data+inPtr+(0x16^2)); v[20] = *(s16 *)(mp3data+inPtr+(0x28^2)); v[14]-= v[20]; - v[15]= *(s16 *)(mp3data+inPtr+(0x14^2)); v[21] = *(s16 *)(mp3data+inPtr+(0x2A^2)); v[15]-= v[21]; - - //0, 1, 3, 2, 7, 6, 4, 5, 7, 6, 4, 5, 0, 1, 3, 2 - const u16 LUT6[16] = { 0xFFB2, 0xFD3A, 0xF10A, 0xF854, - 0xBDAE, 0xCDA0, 0xE76C, 0xDB94, - 0x1920, 0x4B20, 0xAC7C, 0x7C68, - 0xABEC, 0x9880, 0xDAE8, 0x839C }; - for (i = 0; i < 16; i++) { - v[0+i] = (v[0+i] * LUT6[i]) >> 0x10; - } - v[0] = v[0] + v[0]; v[1] = v[1] + v[1]; - v[2] = v[2] + v[2]; v[3] = v[3] + v[3]; v[4] = v[4] + v[4]; - v[5] = v[5] + v[5]; v[6] = v[6] + v[6]; v[7] = v[7] + v[7]; - v[12] = v[12] + v[12]; v[13] = v[13] + v[13]; v[15] = v[15] + v[15]; - - MP3AB0 (); - - // Part 7: - 100% Accurate + SSV - Unoptimized - - v[0] = ( v[17] + v[16] ) >> 1; - v[1] = ((v[17] * (int)((short)0xA57E * 2)) + (v[16] * 0xB504)) >> 0x10; - v[2] = -v[18] -v[19]; - v[3] = ((v[18] - v[19]) * 0x16A09) >> 0x10; - v[4] = v[20] + v[21] + v[0]; - v[5] = (((v[20] - v[21]) * 0x16A09) >> 0x10) + v[1]; - v[6] = (((v[22] + v[23]) << 1) + v[0]) - v[2]; - v[7] = (((v[22] - v[23]) * 0x2D413) >> 0x10) + v[0] + v[1] + v[3]; - // 0x16A8 - // Save v[0] -> (T3 + 0xFFE0) - *(s16 *)(mp3data+((t3+(short)0xFFE0))) = (short)-v[0]; - v[8] = v[24] + v[25]; - v[9] = ((v[24] - v[25]) * 0x16A09) >> 0x10; - v[10] = ((v[26] + v[27]) << 1) + v[8]; - v[11] = (((v[26] - v[27]) * 0x2D413) >> 0x10) + v[8] + v[9]; - v[12] = v[4] - ((v[28] + v[29]) << 1); - // ** Store v12 -> (T2 + 0x20) - *(s16 *)(mp3data+((t2+(short)0x20))) = (short)v[12]; - v[13] = (((v[28] - v[29]) * 0x2D413) >> 0x10) - v[12] - v[5]; - v[14] = v[30] + v[31]; - v[14] = v[14] + v[14]; - v[14] = v[14] + v[14]; - v[14] = v[6] - v[14]; - v[15] = (((v[30] - v[31]) * 0x5A827) >> 0x10) - v[7]; - // Store v14 -> (T5 + 0x20) - *(s16 *)(mp3data+((t5+(short)0x20))) = (short)v[14]; - v[14] = v[14] + v[1]; - // Store v[14] -> (T6 + 0x20) - *(s16 *)(mp3data+((t6+(short)0x20))) = (short)v[14]; - // Store v[15] -> (T1 + 0xFFE0) - *(s16 *)(mp3data+((t1+(short)0xFFE0))) = (short)v[15]; - v[9] = v[9] + v[10]; - v[1] = v[1] + v[6]; - v[6] = v[10] - v[6]; - v[1] = v[9] - v[1]; - // Store v[6] -> (T5 + 0x60) - *(s16 *)(mp3data+((t5+(short)0x60))) = (short)v[6]; - v[10] = v[10] + v[2]; - v[10] = v[4] - v[10]; - // Store v[10] -> (T2 + 0xFFA0) - *(s16 *)(mp3data+((t2+(short)0xFFA0))) = (short)v[10]; - v[12] = v[2] - v[12]; - // Store v[12] -> (T2 + 0xFFE0) - *(s16 *)(mp3data+((t2+(short)0xFFE0))) = (short)v[12]; - v[5] = v[4] + v[5]; - v[4] = v[8] - v[4]; - // Store v[4] -> (T2 + 0x60) - *(s16 *)(mp3data+((t2+(short)0x60))) = (short)v[4]; - v[0] = v[0] - v[8]; - // Store v[0] -> (T3 + 0xFFA0) - *(s16 *)(mp3data+((t3+(short)0xFFA0))) = (short)v[0]; - v[7] = v[7] - v[11]; - // Store v[7] -> (T1 + 0xFFA0) - *(s16 *)(mp3data+((t1+(short)0xFFA0))) = (short)v[7]; - v[11] = v[11] - v[3]; - // Store v[1] -> (T6 + 0x60) - *(s16 *)(mp3data+((t6+(short)0x60))) = (short)v[1]; - v[11] = v[11] - v[5]; - // Store v[11] -> (T0 + 0x60) - *(s16 *)(mp3data+((t0+(short)0x60))) = (short)v[11]; - v[3] = v[3] - v[13]; - // Store v[3] -> (T0 + 0x20) - *(s16 *)(mp3data+((t0+(short)0x20))) = (short)v[3]; - v[13] = v[13] + v[2]; - // Store v[13] -> (T0 + 0xFFE0) - *(s16 *)(mp3data+((t0+(short)0xFFE0))) = (short)v[13]; - //v[2] = ; - v[2] = (v[5] - v[2]) - v[9]; - // Store v[2] -> (T0 + 0xFFA0) - *(s16 *)(mp3data+((t0+(short)0xFFA0))) = (short)v[2]; - // 0x7A8 - Verified... - - // Step 8 - Dewindowing - - //u64 *DW = (u64 *)&DeWindowLUT[0x10-(t4>>1)]; - u32 offset = 0x10-(t4>>1); - - u32 addptr = t6 & 0xFFE0; - offset = 0x10-(t4>>1); - - s32 v2=0, v4=0, v6=0, v8=0; - //s32 z2=0, z4=0, z6=0, z8=0; - - offset = 0x10-(t4>>1);// + x*0x40; - int x; - for (x = 0; x < 8; x++) { - v2 = v4 = v6 = v8 = 0; - - //addptr = t1; - - for (i = 7; i >= 0; i--) { - v2 += ((int)*(s16 *)(mp3data+(addptr)+0x00) * (short)DeWindowLUT[offset+0x00] + 0x4000) >> 0xF; - v4 += ((int)*(s16 *)(mp3data+(addptr)+0x10) * (short)DeWindowLUT[offset+0x08] + 0x4000) >> 0xF; - v6 += ((int)*(s16 *)(mp3data+(addptr)+0x20) * (short)DeWindowLUT[offset+0x20] + 0x4000) >> 0xF; - v8 += ((int)*(s16 *)(mp3data+(addptr)+0x30) * (short)DeWindowLUT[offset+0x28] + 0x4000) >> 0xF; - addptr+=2; offset++; - } - s32 v0 = v2 + v4; - s32 v18 = v6 + v8; - //Clamp(v0); - //Clamp(v18); - // clamp??? - *(s16 *)(mp3data+(outPtr^2)) = v0; - *(s16 *)(mp3data+((outPtr+2)^2)) = v18; - outPtr+=4; - addptr += 0x30; - offset += 0x38; - } - - offset = 0x10-(t4>>1) + 8*0x40; - v2 = v4 = 0; - for (i = 0; i < 4; i++) { - v2 += ((int)*(s16 *)(mp3data+(addptr)+0x00) * (short)DeWindowLUT[offset+0x00] + 0x4000) >> 0xF; - v2 += ((int)*(s16 *)(mp3data+(addptr)+0x10) * (short)DeWindowLUT[offset+0x08] + 0x4000) >> 0xF; - addptr+=2; offset++; - v4 += ((int)*(s16 *)(mp3data+(addptr)+0x00) * (short)DeWindowLUT[offset+0x00] + 0x4000) >> 0xF; - v4 += ((int)*(s16 *)(mp3data+(addptr)+0x10) * (short)DeWindowLUT[offset+0x08] + 0x4000) >> 0xF; - addptr+=2; offset++; - } - s32 mult6 = *(s32 *)(mp3data+0xCE8); - s32 mult4 = *(s32 *)(mp3data+0xCEC); - if (t4 & 0x2) { - v2 = (v2 * *(u32 *)(mp3data+0xCE8)) >> 0x10; - *(s16 *)(mp3data+(outPtr^2)) = v2; - } else { - v4 = (v4 * *(u32 *)(mp3data+0xCE8)) >> 0x10; - *(s16 *)(mp3data+(outPtr^2)) = v4; - mult4 = *(u32 *)(mp3data+0xCE8); - } - addptr -= 0x50; - - for (x = 0; x < 8; x++) { - v2 = v4 = v6 = v8 = 0; - - offset = (0x22F-(t4>>1) + x*0x40); - - for (i = 0; i < 4; i++) { - v2 += ((int)*(s16 *)(mp3data+(addptr )+0x20) * (short)DeWindowLUT[offset+0x00] + 0x4000) >> 0xF; - v2 -= ((int)*(s16 *)(mp3data+((addptr+2))+0x20) * (short)DeWindowLUT[offset+0x01] + 0x4000) >> 0xF; - v4 += ((int)*(s16 *)(mp3data+(addptr )+0x30) * (short)DeWindowLUT[offset+0x08] + 0x4000) >> 0xF; - v4 -= ((int)*(s16 *)(mp3data+((addptr+2))+0x30) * (short)DeWindowLUT[offset+0x09] + 0x4000) >> 0xF; - v6 += ((int)*(s16 *)(mp3data+(addptr )+0x00) * (short)DeWindowLUT[offset+0x20] + 0x4000) >> 0xF; - v6 -= ((int)*(s16 *)(mp3data+((addptr+2))+0x00) * (short)DeWindowLUT[offset+0x21] + 0x4000) >> 0xF; - v8 += ((int)*(s16 *)(mp3data+(addptr )+0x10) * (short)DeWindowLUT[offset+0x28] + 0x4000) >> 0xF; - v8 -= ((int)*(s16 *)(mp3data+((addptr+2))+0x10) * (short)DeWindowLUT[offset+0x29] + 0x4000) >> 0xF; - addptr+=4; offset+=2; - } - s32 v0 = v2 + v4; - s32 v18 = v6 + v8; - //Clamp(v0); - //Clamp(v18); - // clamp??? - *(s16 *)(mp3data+((outPtr+2)^2)) = v0; - *(s16 *)(mp3data+((outPtr+4)^2)) = v18; - outPtr+=4; - addptr -= 0x50; - } - - int tmp = outPtr; - s32 hi0 = mult6; - s32 hi1 = mult4; - s32 v; - /* - if (hi0 & 0xffff) - __asm int 3; - if (hi1 & 0xffff) - __asm int 3;*/ - hi0 = (int)hi0 >> 0x10; - hi1 = (int)hi1 >> 0x10; - for (i = 0; i < 8; i++) { - // v0 - v = (*(s16 *)(mp3data+((tmp-0x40)^2)) * hi0); - if (v > 32767) v = 32767; else if (v < -32767) v = -32767; - *(s16 *)((u8 *)mp3data+((tmp-0x40)^2)) = (s16)v; - // v17 - v = (*(s16 *)(mp3data+((tmp-0x30)^2)) * hi0); - if (v > 32767) v = 32767; else if (v < -32767) v = -32767; - *(s16 *)((u8 *)mp3data+((tmp-0x30)^2)) = v; - // v2 - v = (*(s16 *)(mp3data+((tmp-0x1E)^2)) * hi1); - if (v > 32767) v = 32767; else if (v < -32767) v = -32767; - *(s16 *)((u8 *)mp3data+((tmp-0x1E)^2)) = v; - // v4 - v = (*(s16 *)(mp3data+((tmp-0xE)^2)) * hi1); - if (v > 32767) v = 32767; else if (v < -32767) v = -32767; - *(s16 *)((u8 *)mp3data+((tmp-0xE)^2)) = v; - tmp += 2; - } -} diff --git a/src/usf/config.h b/src/usf/config.h deleted file mode 100644 index ab09878..0000000 --- a/src/usf/config.h +++ /dev/null @@ -1,63 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.in by autoheader. */ - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "lazyusf" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "lazyusf" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "lazyusf 1.0.0" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "lazyusf" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "1.0.0" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "1.0.0" - -/* Define to 1 if the X Window System is missing or not being used. */ -/* #undef X_DISPLAY_MISSING */ diff --git a/src/usf/cpu.c b/src/usf/cpu.c deleted file mode 100644 index 8cb4966..0000000 --- a/src/usf/cpu.c +++ /dev/null @@ -1,640 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 -#include "main.h" -#include "cpu.h" -#include "usf.h" -#include "audio.h" -#include "audio_hle.h" -#include "recompiler_cpu.h" -#include "x86.h" -#include "registers.h" -#include "rsp.h" - -#include - -#include -#include -#include -extern InputPlayback * pcontext; -extern GThread * decode_thread; - -uint32_t NextInstruction = 0, JumpToLocation = 0, AudioIntrReg = 0; -CPU_ACTION * CPU_Action = 0; -SYSTEM_TIMERS * Timers = 0; -OPCODE Opcode; -uint32_t CPURunning = 0, SPHack = 0; -uint32_t * WaitMode = 0, CPU_Type = CPU_Recompiler; - - -void ChangeCompareTimer(void) { - uint32_t NextCompare = COMPARE_REGISTER - COUNT_REGISTER; - if ((NextCompare & 0x80000000) != 0) { NextCompare = 0x7FFFFFFF; } - if (NextCompare == 0) { NextCompare = 0x1; } - ChangeTimer(CompareTimer,NextCompare); -} - -void ChangeTimer(int32_t Type, int32_t Value) { - if (Value == 0) { - Timers->NextTimer[Type] = 0; - Timers->Active[Type] = 0; - return; - } - Timers->NextTimer[Type] = Value - Timers->Timer; - Timers->Active[Type] = 1; - CheckTimer(); -} - -void CheckTimer (void) { - int32_t count; - - for (count = 0; count < MaxTimers; count++) { - if (!Timers->Active[count]) { continue; } - if (!(count == CompareTimer && Timers->NextTimer[count] == 0x7FFFFFFF)) { - Timers->NextTimer[count] += Timers->Timer; - } - } - Timers->CurrentTimerType = -1; - Timers->Timer = 0x7FFFFFFF; - for (count = 0; count < MaxTimers; count++) { - if (!Timers->Active[count]) { continue; } - if (Timers->NextTimer[count] >= Timers->Timer) { continue; } - Timers->Timer = Timers->NextTimer[count]; - Timers->CurrentTimerType = count; - } - if (Timers->CurrentTimerType == -1) { - DisplayError("No active timers ???\nEmulation Stoped"); - StopEmulation(); - } - for (count = 0; count < MaxTimers; count++) { - if (!Timers->Active[count]) { continue; } - if (!(count == CompareTimer && Timers->NextTimer[count] == 0x7FFFFFFF)) { - Timers->NextTimer[count] -= Timers->Timer; - } - } - - if (Timers->NextTimer[CompareTimer] == 0x7FFFFFFF) { - uint32_t NextCompare = COMPARE_REGISTER - COUNT_REGISTER; - if ((NextCompare & 0x80000000) == 0 && NextCompare != 0x7FFFFFFF) { - ChangeCompareTimer(); - } - } -} - - - -void CloseCpu (void) { - uint32_t count = 0; - - if(!MemChunk) return; - if (!cpu_running) { return; } - - cpu_running = 0; - g_print("cpu_running = %d\n", cpu_running); - - for (count = 0; count < 3; count ++ ) { - CPU_Action->CloseCPU = 1; - CPU_Action->DoSomething = 1; - } - - CPURunning = 0; -} - -int32_t DelaySlotEffectsCompare (uint32_t PC, uint32_t Reg1, uint32_t Reg2) { - OPCODE Command; - - if (!r4300i_LW_VAddr(PC + 4, (uint32_t*)&Command.Hex)) { - return 1; - } - - switch (Command.op) { - case R4300i_SPECIAL: - switch (Command.funct) { - case R4300i_SPECIAL_SLL: - case R4300i_SPECIAL_SRL: - case R4300i_SPECIAL_SRA: - case R4300i_SPECIAL_SLLV: - case R4300i_SPECIAL_SRLV: - case R4300i_SPECIAL_SRAV: - case R4300i_SPECIAL_MFHI: - case R4300i_SPECIAL_MTHI: - case R4300i_SPECIAL_MFLO: - case R4300i_SPECIAL_MTLO: - case R4300i_SPECIAL_DSLLV: - case R4300i_SPECIAL_DSRLV: - case R4300i_SPECIAL_DSRAV: - case R4300i_SPECIAL_ADD: - case R4300i_SPECIAL_ADDU: - case R4300i_SPECIAL_SUB: - case R4300i_SPECIAL_SUBU: - case R4300i_SPECIAL_AND: - case R4300i_SPECIAL_OR: - case R4300i_SPECIAL_XOR: - case R4300i_SPECIAL_NOR: - case R4300i_SPECIAL_SLT: - case R4300i_SPECIAL_SLTU: - case R4300i_SPECIAL_DADD: - case R4300i_SPECIAL_DADDU: - case R4300i_SPECIAL_DSUB: - case R4300i_SPECIAL_DSUBU: - case R4300i_SPECIAL_DSLL: - case R4300i_SPECIAL_DSRL: - case R4300i_SPECIAL_DSRA: - case R4300i_SPECIAL_DSLL32: - case R4300i_SPECIAL_DSRL32: - case R4300i_SPECIAL_DSRA32: - if (Command.rd == 0) { return 0; } - if (Command.rd == Reg1) { return 1; } - if (Command.rd == Reg2) { return 1; } - break; - case R4300i_SPECIAL_MULT: - case R4300i_SPECIAL_MULTU: - case R4300i_SPECIAL_DIV: - case R4300i_SPECIAL_DIVU: - case R4300i_SPECIAL_DMULT: - case R4300i_SPECIAL_DMULTU: - case R4300i_SPECIAL_DDIV: - case R4300i_SPECIAL_DDIVU: - break; - default: - return 1; - } - break; - case R4300i_CP0: - switch (Command.rs) { - case R4300i_COP0_MT: break; - case R4300i_COP0_MF: - if (Command.rt == 0) { return 0; } - if (Command.rt == Reg1) { return 1; } - if (Command.rt == Reg2) { return 1; } - break; - default: - if ( (Command.rs & 0x10 ) != 0 ) { - switch( Opcode.funct ) { - case R4300i_COP0_CO_TLBR: break; - case R4300i_COP0_CO_TLBWI: break; - case R4300i_COP0_CO_TLBWR: break; - case R4300i_COP0_CO_TLBP: break; - default: - return 1; - } - return 1; - } - } - break; - case R4300i_CP1: - switch (Command.fmt) { - case R4300i_COP1_MF: - if (Command.rt == 0) { return 0; } - if (Command.rt == Reg1) { return 1; } - if (Command.rt == Reg2) { return 1; } - break; - case R4300i_COP1_CF: break; - case R4300i_COP1_MT: break; - case R4300i_COP1_CT: break; - case R4300i_COP1_S: break; - case R4300i_COP1_D: break; - case R4300i_COP1_W: break; - case R4300i_COP1_L: break; - return 1; - } - break; - case R4300i_ANDI: - case R4300i_ORI: - case R4300i_XORI: - case R4300i_LUI: - case R4300i_ADDI: - case R4300i_ADDIU: - case R4300i_SLTI: - case R4300i_SLTIU: - case R4300i_DADDI: - case R4300i_DADDIU: - case R4300i_LB: - case R4300i_LH: - case R4300i_LW: - case R4300i_LWL: - case R4300i_LWR: - case R4300i_LDL: - case R4300i_LDR: - case R4300i_LBU: - case R4300i_LHU: - case R4300i_LD: - case R4300i_LWC1: - case R4300i_LDC1: - if (Command.rt == 0) { return 0; } - if (Command.rt == Reg1) { return 1; } - if (Command.rt == Reg2) { return 1; } - break; - case R4300i_CACHE: break; - case R4300i_SB: break; - case R4300i_SH: break; - case R4300i_SW: break; - case R4300i_SWR: break; - case R4300i_SWL: break; - case R4300i_SWC1: break; - case R4300i_SDC1: break; - case R4300i_SD: break; - default: - - return 1; - } - return 0; -} - -int32_t DelaySlotEffectsJump (uint32_t JumpPC) { - OPCODE Command; - - if (!r4300i_LW_VAddr(JumpPC, &Command.Hex)) { return 1; } - - switch (Command.op) { - case R4300i_SPECIAL: - switch (Command.funct) { - case R4300i_SPECIAL_JR: return DelaySlotEffectsCompare(JumpPC,Command.rs,0); - case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC,Command.rs,31); - } - break; - case R4300i_REGIMM: - switch (Command.rt) { - case R4300i_REGIMM_BLTZ: - case R4300i_REGIMM_BGEZ: - case R4300i_REGIMM_BLTZL: - case R4300i_REGIMM_BGEZL: - case R4300i_REGIMM_BLTZAL: - case R4300i_REGIMM_BGEZAL: - return DelaySlotEffectsCompare(JumpPC,Command.rs,0); - } - break; - case R4300i_JAL: - case R4300i_SPECIAL_JALR: return DelaySlotEffectsCompare(JumpPC,31,0); break; - case R4300i_J: return 0; - case R4300i_BEQ: - case R4300i_BNE: - case R4300i_BLEZ: - case R4300i_BGTZ: - return DelaySlotEffectsCompare(JumpPC,Command.rs,Command.rt); - case R4300i_CP1: - switch (Command.fmt) { - case R4300i_COP1_BC: - switch (Command.ft) { - case R4300i_COP1_BC_BCF: - case R4300i_COP1_BC_BCT: - case R4300i_COP1_BC_BCFL: - case R4300i_COP1_BC_BCTL: - { - int32_t EffectDelaySlot; - OPCODE NewCommand; - - if (!r4300i_LW_VAddr(JumpPC + 4, &NewCommand.Hex)) { return 1; } - - EffectDelaySlot = 0; - if (NewCommand.op == R4300i_CP1) { - if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - } - return EffectDelaySlot; - } - break; - } - break; - } - break; - case R4300i_BEQL: - case R4300i_BNEL: - case R4300i_BLEZL: - case R4300i_BGTZL: - return DelaySlotEffectsCompare(JumpPC,Command.rs,Command.rt); - } - return 1; -} - -void DoSomething ( void ) { - if (CPU_Action->CloseCPU) { - //StopEmulation(); - cpu_running = 0; - //printf("Stopping?\n"); - if(!(fake_seek_stopping&3)) - g_thread_exit(NULL); - } - if (CPU_Action->CheckInterrupts) { - CPU_Action->CheckInterrupts = 0; - CheckInterrupts(); - } - if (CPU_Action->DoInterrupt) { - CPU_Action->DoInterrupt = 0; - DoIntrException(0); - } - - - CPU_Action->DoSomething = 0; - - if (CPU_Action->DoInterrupt) { CPU_Action->DoSomething = 1; } -} - -void InPermLoop (void) { - // *** Changed ***/ - if (CPU_Action->DoInterrupt) { return; } - - /* Interrupts enabled */ - if (( STATUS_REGISTER & STATUS_IE ) == 0 ) { goto InterruptsDisabled; } - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { goto InterruptsDisabled; } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { goto InterruptsDisabled; } - if (( STATUS_REGISTER & 0xFF00) == 0) { goto InterruptsDisabled; } - - /* check sound playing */ - - /* check RSP running */ - /* check RDP running */ - if (Timers->Timer >= 0) { - COUNT_REGISTER += Timers->Timer + 1; - Timers->Timer = -1; - } - return; - -InterruptsDisabled: - DisplayError("Stuck in Permanent Loop"); - StopEmulation(); -} - -void ReadFromMem(const void * source, void * target, uint32_t length, uint32_t *offset) { - memcpy((uint8_t*)target,((uint8_t*)source)+*offset,length); - *offset+=length; -} - - -uint32_t Machine_LoadStateFromRAM(void * savestatespace) { - uint8_t LoadHeader[0x40]; - uint32_t Value, count, SaveRDRAMSize, offset=0; - - ReadFromMem( savestatespace,&Value,sizeof(Value),&offset); - if (Value != 0x23D8A6C8) { return 0; } - ReadFromMem( savestatespace,&SaveRDRAMSize,sizeof(SaveRDRAMSize),&offset); - ReadFromMem( savestatespace,&LoadHeader,0x40,&offset); - - if (CPU_Type != CPU_Interpreter) { - ResetRecompCode(); - } - - Timers->CurrentTimerType = -1; - Timers->Timer = 0; - for (count = 0; count < MaxTimers; count ++) { Timers->Active[count] = 0; } - - //fix rdram size - if (SaveRDRAMSize != RdramSize) { - // dothis :) - } - - RdramSize = SaveRDRAMSize; - - ReadFromMem( savestatespace,&Value,sizeof(Value),&offset); - ChangeTimer(ViTimer,Value); - ReadFromMem( savestatespace,&PROGRAM_COUNTER,sizeof(PROGRAM_COUNTER),&offset); - ReadFromMem( savestatespace,GPR,sizeof(int64_t)*32,&offset); - ReadFromMem( savestatespace,FPR,sizeof(int64_t)*32,&offset); - ReadFromMem( savestatespace,CP0,sizeof(uint32_t)*32,&offset); - ReadFromMem( savestatespace,FPCR,sizeof(uint32_t)*32,&offset); - ReadFromMem( savestatespace,&HI,sizeof(int64_t),&offset); - ReadFromMem( savestatespace,&LO,sizeof(int64_t),&offset); - ReadFromMem( savestatespace,RegRDRAM,sizeof(uint32_t)*10,&offset); - ReadFromMem( savestatespace,RegSP,sizeof(uint32_t)*10,&offset); - ReadFromMem( savestatespace,RegDPC,sizeof(uint32_t)*10,&offset); - ReadFromMem( savestatespace,RegMI,sizeof(uint32_t)*4,&offset); - ReadFromMem( savestatespace,RegVI,sizeof(uint32_t)*14,&offset); - ReadFromMem( savestatespace,RegAI,sizeof(uint32_t)*6,&offset); - ReadFromMem( savestatespace,RegPI,sizeof(uint32_t)*13,&offset); - ReadFromMem( savestatespace,RegRI,sizeof(uint32_t)*8,&offset); - ReadFromMem( savestatespace,RegSI,sizeof(uint32_t)*4,&offset); - ReadFromMem( savestatespace,tlb,sizeof(TLB)*32,&offset); - ReadFromMem( savestatespace,(uint8_t*)PIF_Ram,0x40,&offset); - ReadFromMem( savestatespace,RDRAM,SaveRDRAMSize,&offset); - ReadFromMem( savestatespace,DMEM,0x1000,&offset); - ReadFromMem( savestatespace,IMEM,0x1000,&offset); - - CP0[32] = 0; - - SetupTLB(); - ChangeCompareTimer(); - AI_STATUS_REG = 0; - AiDacrateChanged(AI_DACRATE_REG); - -// StartAiInterrupt(); - - SetFpuLocations(); // important if FR=1 - - return 1; -} -extern int32_t RSP_Cpu; -extern int32_t SampleRate; -void StartEmulationFromSave ( void * savestate ) { - uint32_t count = 0; - if(use_interpreter) - CPU_Type = CPU_Interpreter; - - //printf("Starting generic Cpu\n"); - - //CloseCpu(); - memset(N64MEM, 0, RdramSize); - - memset(DMEM, 0, 0x1000); - memset(IMEM, 0, 0x1000); - memset(TLB_Map, 0, 0x100000 * sizeof(uintptr_t) + 0x10000); - if(!use_interpreter) { - memset(JumpTable, 0, 0x200000 * sizeof(uintptr_t)); - memset(RecompCode, 0xcc, NormalCompileBufferSize); // fill with Breakpoints - memset(DelaySlotTable, 0, ((0x1000000) >> 0xA)); - } - - memset(CPU_Action,0,sizeof(CPU_Action)); - WrittenToRom = 0; - - InitilizeTLB(); - - SetupRegisters(Registers); - - BuildInterpreter(); - RecompPos = RecompCode; - - Timers->CurrentTimerType = -1; - Timers->Timer = 0; - - for (count = 0; count < MaxTimers; count ++) { Timers->Active[count] = 0; } - ChangeTimer(ViTimer,5000); - ChangeCompareTimer(); - ViFieldNumber = 0; - CPURunning = 1; - *WaitMode = 0; - - init_rsp(); - - Machine_LoadStateFromRAM(savestate); - - SampleRate = 48681812 / (AI_DACRATE_REG + 1); - - OpenSound(); - - pcontext->set_params(pcontext, NULL, 0, SampleRate * 4, SampleRate, 2); - - if(enableFIFOfull) { - const float VSyncTiming = 789000.0f; - double BytesPerSecond = 48681812.0 / (AI_DACRATE_REG + 1) * 4; - double CountsPerSecond = (double)(((double)VSyncTiming) * (double)60.0); - double CountsPerByte = (double)CountsPerSecond / (double)BytesPerSecond; - uint32_t IntScheduled = (uint32_t)((double)AI_LEN_REG * CountsPerByte); - - ChangeTimer(AiTimer,IntScheduled); - AI_STATUS_REG|=0x40000000; - } - - cpu_stopped = 0; - cpu_running = 1; - fake_seek_stopping = 0; - - switch (CPU_Type) { - case CPU_Interpreter: StartInterpreterCPU(); break; - case CPU_Recompiler: StartRecompilerCPU(); break; - default: - DisplayError("Unhandled CPU %d",CPU_Type); - } - -} - - -void RefreshScreen (void ){ - ChangeTimer(ViTimer, 300000); - -} - -void RunRsp (void) { - if ( ( SP_STATUS_REG & SP_STATUS_HALT ) == 0) { - if ( ( SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) { - - uint32_t Task = *( uint32_t *)(DMEM + 0xFC0); - - switch (Task) { - case 1: { - MI_INTR_REG |= 0x20; - - SP_STATUS_REG |= (0x0203 ); - if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) - MI_INTR_REG |= 1; - - CheckInterrupts(); - - DPC_STATUS_REG &= ~0x0002; - return; - - } - break; - case 2: { - - if(use_audiohle && !is_seeking) { - OSTask_t *task = (OSTask_t*)(DMEM + 0xFC0); - if(audio_ucode(task)) - break; - - } else - break; - - SP_STATUS_REG |= (0x0203 ); - if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) { - MI_INTR_REG |= 1; - CheckInterrupts(); - } - - return; - - } - break; - default: - - break; - } - - if(!is_seeking) - real_run_rsp(100); - SP_STATUS_REG |= (0x0203 ); - if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) { - MI_INTR_REG |= 1; - CheckInterrupts(); - } - - } - } -} - -void TimerDone (void) { - switch (Timers->CurrentTimerType) { - case CompareTimer: - if(enablecompare) - FAKE_CAUSE_REGISTER |= CAUSE_IP7; - //CheckInterrupts(); - ChangeCompareTimer(); - break; - case ViTimer: - RefreshScreen(); - MI_INTR_REG |= MI_INTR_VI; - CheckInterrupts(); - //CompileCheckInterrupts(); - *WaitMode=0; - break; - case AiTimer: - ChangeTimer(AiTimer,0); - AI_STATUS_REG=0; - AudioIntrReg|=4; - //CheckInterrupts(); - break; - } - CheckTimer(); -} - -void Int3() { - asm("int $3"); -} - -void _Emms() { - asm("emms"); -} - - - -#include - -void controlfp(uint32_t control) { - uint32_t OldControl = 0; - - _FPU_GETCW(OldControl); - OldControl &= ~(_FPU_RC_ZERO | _FPU_RC_UP | _FPU_RC_DOWN | _FPU_RC_NEAREST); - - OldControl |= control; - - _FPU_SETCW(OldControl); - -} - diff --git a/src/usf/cpu.h b/src/usf/cpu.h deleted file mode 100644 index 48510fe..0000000 --- a/src/usf/cpu.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#ifndef _CPU_H_ -#define _CPU_H_ - -#include "interpreter_cpu.h" -#include "interpreter_ops.h" -#include "recompiler_cpu.h" -#include "registers.h" -#include "recompiler_ops.h" -#include "tlb.h" -#include "memory.h" -#include "dma.h" -#include "exception.h" -#include "pif.h" -#include "opcode.h" -#include "usf.h" - -#ifdef __LP64__ -#define USEX86 -#define EXTREGS -#endif - -typedef struct { - int32_t DoSomething; - int32_t CloseCPU; - int32_t CheckInterrupts; - int32_t DoInterrupt; -} CPU_ACTION; - -#define MaxTimers 3 -#define CompareTimer 0 -#define ViTimer 1 -#define AiTimer 2 - -typedef struct { - int32_t NextTimer[MaxTimers]; - int32_t Active[MaxTimers]; - int32_t CurrentTimerType; - int32_t Timer; -} SYSTEM_TIMERS; - -void ChangeCompareTimer ( void ); -void ChangeTimer ( int32_t Type, int32_t Value ); -void CheckTimer ( void ); -void CloseCpu ( void ); -int32_t DelaySlotEffectsCompare ( uint32_t PC, uint32_t Reg1, uint32_t Reg2 ); -int32_t DelaySlotEffectsJump (uint32_t JumpPC); -void DoSomething ( void ); -void InPermLoop ( void ); -void InitiliazeCPUFlags ( void ); -void RefreshScreen ( void ); -void RunRsp ( void ); -void StartEmulation ( void ); -void TimerDone ( void ); -void RecompileTimerDone ( void ); -void controlfp (uint32_t mask); -void StartEmulationFromSave ( void * savestate ); - -#define NORMAL 0 -#define DO_DELAY_SLOT 1 -#define DO_END_DELAY_SLOT 2 -#define DELAY_SLOT 3 -#define END_DELAY_SLOT 4 -#define LIKELY_DELAY_SLOT 5 -#define JUMP 6 -#define DELAY_SLOT_DONE 7 -#define LIKELY_DELAY_SLOT_DONE 8 -#define END_BLOCK 9 - -enum SaveType { - Auto, - Eeprom_4K, - Eeprom_16K, - Sram, - FlashRam -}; - - -extern uint32_t NextInstruction, JumpToLocation, ManualPaused, CPU_Paused, CountPerOp, AudioIntrReg, * WaitMode, CPU_Type; -extern CPU_ACTION * CPU_Action; -extern SYSTEM_TIMERS * Timers; -extern OPCODE Opcode; -extern uint32_t CPURunning; -#endif diff --git a/src/usf/dma.c b/src/usf/dma.c deleted file mode 100644 index a4e078a..0000000 --- a/src/usf/dma.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" - -void PI_DMA_READ (void) { - - PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - MI_INTR_REG |= MI_INTR_PI; - CheckInterrupts(); - return; -} - -#include -extern FILE *fil; -void PI_DMA_WRITE (void) { - uint32_t i; - PI_STATUS_REG |= PI_STATUS_DMA_BUSY; - //fprintf(fil,"PI DMA from %08x to %08x len %08x\n", PI_CART_ADDR_REG, PI_DRAM_ADDR_REG, PI_WR_LEN_REG); - if ( PI_DRAM_ADDR_REG + PI_WR_LEN_REG + 1 > RdramSize) { - PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - MI_INTR_REG |= MI_INTR_PI; - CheckInterrupts(); - return; - } - - if ( PI_CART_ADDR_REG >= 0x08000000 && PI_CART_ADDR_REG <= 0x08010000) { - return; - } - - if ( PI_CART_ADDR_REG >= 0x10000000 && PI_CART_ADDR_REG <= 0x1FBFFFFF) { - PI_CART_ADDR_REG -= 0x10000000; - for (i = 0; i < PI_WR_LEN_REG + 1; i ++) { - *(N64MEM+((PI_DRAM_ADDR_REG + i) ^ 3)) = *PageROM((PI_CART_ADDR_REG + i) ^ 3); - } - PI_CART_ADDR_REG += 0x10000000; - - PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - MI_INTR_REG |= MI_INTR_PI; - CheckInterrupts(); - CheckTimer(); - return; - } - - PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; - MI_INTR_REG |= MI_INTR_PI; - CheckInterrupts(); -} - - -void SI_DMA_READ (void) { - - if ((int32_t)SI_DRAM_ADDR_REG > (int32_t)RdramSize) { - return; - } - - PifRamRead(); - SI_DRAM_ADDR_REG &= 0xFFFFFFF8; - if ((int32_t)SI_DRAM_ADDR_REG < 0) { - int32_t count, RdramPos; - - RdramPos = (int32_t)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { continue; } - N64MEM[RdramPos ^3] = PIF_Ram[count]; - } - } else { - int32_t count, RdramPos; - - RdramPos = (uint32_t)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { continue; } - N64MEM[RdramPos ^3] = PIF_Ram[count]; - } - } - - MI_INTR_REG |= MI_INTR_SI; - SI_STATUS_REG |= SI_STATUS_INTERRUPT; - CheckInterrupts(); -} - - -void SI_DMA_WRITE (void) { - - if ((int32_t)SI_DRAM_ADDR_REG > (int32_t)RdramSize) { - return; - } - - SI_DRAM_ADDR_REG &= 0xFFFFFFF8; - if ((int32_t)SI_DRAM_ADDR_REG < 0) { - int32_t count, RdramPos; - - RdramPos = (int32_t)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { PIF_Ram[count] = 0; continue; } - PIF_Ram[count] = N64MEM[RdramPos ^3]; - } - } else { - int32_t count, RdramPos; - - RdramPos = (int32_t)SI_DRAM_ADDR_REG; - for (count = 0; count < 0x40; count++, RdramPos++) { - if (RdramPos < 0) { PIF_Ram[count] = 0; continue; } - PIF_Ram[count] = N64MEM[RdramPos ^3]; - } - } - - PifRamWrite(); - - MI_INTR_REG |= MI_INTR_SI; - SI_STATUS_REG |= SI_STATUS_INTERRUPT; - CheckInterrupts(); - -} - -void SP_DMA_READ (void) { - SP_DRAM_ADDR_REG &= 0x1FFFFFFF; - - if (SP_DRAM_ADDR_REG > RdramSize) { - SP_DMA_BUSY_REG = 0; - SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; - return; - } - - if (SP_RD_LEN_REG + 1 + (SP_MEM_ADDR_REG & 0xFFF) > 0x1000) { - return; - } - - memcpy( DMEM + (SP_MEM_ADDR_REG & 0x1FFF), N64MEM + SP_DRAM_ADDR_REG, - SP_RD_LEN_REG + 1 ); - - SP_DMA_BUSY_REG = 0; - SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; - MI_INTR_REG &= ~MI_INTR_SP; - CheckInterrupts(); - CheckTimer(); -} - -void SP_DMA_WRITE (void) { - if (SP_DRAM_ADDR_REG > RdramSize) { - return; - } - - if (SP_WR_LEN_REG + 1 + (SP_MEM_ADDR_REG & 0xFFF) > 0x1000) { - return; - } - - memcpy( N64MEM + SP_DRAM_ADDR_REG, DMEM + (SP_MEM_ADDR_REG & 0x1FFF), - SP_WR_LEN_REG + 1); - - SP_DMA_BUSY_REG = 0; - SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; -} - diff --git a/src/usf/dma.h b/src/usf/dma.h deleted file mode 100644 index aae1c71..0000000 --- a/src/usf/dma.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -void PI_DMA_READ ( void ); -void PI_DMA_WRITE ( void ); -void SI_DMA_READ ( void ); -void SI_DMA_WRITE ( void ); -void SP_DMA_READ ( void ); -void SP_DMA_WRITE ( void ); - - - diff --git a/src/usf/exception.c b/src/usf/exception.c deleted file mode 100644 index b48b50d..0000000 --- a/src/usf/exception.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" -#include "recompiler_cpu.h" -#include "x86.h" - -void CheckInterrupts ( void ) { - - MI_INTR_REG &= ~MI_INTR_AI; - MI_INTR_REG |= (AudioIntrReg & MI_INTR_AI); - if ((MI_INTR_MASK_REG & MI_INTR_REG) != 0) { - FAKE_CAUSE_REGISTER |= CAUSE_IP2; - } else { - FAKE_CAUSE_REGISTER &= ~CAUSE_IP2; - } - - if (( STATUS_REGISTER & STATUS_IE ) == 0 ) { return; } - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { return; } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { return; } - - if (( STATUS_REGISTER & FAKE_CAUSE_REGISTER & 0xFF00) != 0) { - if (!CPU_Action->DoInterrupt) { - CPU_Action->DoSomething = 1; - CPU_Action->DoInterrupt = 1; - } - } -} - -void DoAddressError ( uint32_t DelaySlot, uint32_t BadVaddr, uint32_t FromRead) { - if (FromRead) { - CAUSE_REGISTER = EXC_RADE; - } else { - CAUSE_REGISTER = EXC_WADE; - } - BAD_VADDR_REGISTER = BadVaddr; - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER = PROGRAM_COUNTER - 4; - } else { - EPC_REGISTER = PROGRAM_COUNTER; - } - STATUS_REGISTER |= STATUS_EXL; - PROGRAM_COUNTER = 0x80000180; -} - -void DoBreakException ( uint32_t DelaySlot) { - CAUSE_REGISTER = EXC_BREAK; - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER = PROGRAM_COUNTER - 4; - } else { - EPC_REGISTER = PROGRAM_COUNTER; - } - STATUS_REGISTER |= STATUS_EXL; - PROGRAM_COUNTER = 0x80000180; -} - -void DoCopUnusableException ( uint32_t DelaySlot, uint32_t Coprocessor ) { - CAUSE_REGISTER = EXC_CPU; - if (Coprocessor == 1) { CAUSE_REGISTER |= 0x10000000; } - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER = PROGRAM_COUNTER - 4; - } else { - EPC_REGISTER = PROGRAM_COUNTER; - } - STATUS_REGISTER |= STATUS_EXL; - PROGRAM_COUNTER = 0x80000180; -} - -void DoIntrException ( uint32_t DelaySlot ) { - - if (( STATUS_REGISTER & STATUS_IE ) == 0 ) { return; } - if (( STATUS_REGISTER & STATUS_EXL ) != 0 ) { return; } - if (( STATUS_REGISTER & STATUS_ERL ) != 0 ) { return; } - CAUSE_REGISTER = FAKE_CAUSE_REGISTER; - CAUSE_REGISTER |= EXC_INT; - EPC_REGISTER = PROGRAM_COUNTER; - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER -= 4; - } - STATUS_REGISTER |= STATUS_EXL; - PROGRAM_COUNTER = 0x80000180; -} - -/* -#ifdef USEX64 -void CompileDoIntrException(void) { - uint8_t * Jump, * Jump2; - - MoveVariableToX86reg(&STATUS_REGISTER, x86_TEMPD); - AndConstToX86Reg(x86_TEMPD,7); - CompConstToX86reg(x86_TEMPD,1); - JneLabel8(0); - Jump = RecompPos - 1; - Push(x86_RAX); - - MoveVariableToX86reg(&FAKE_CAUSE_REGISTER, x86_EAX); - OrConstToX86Reg(EXC_INT, x86_EAX); - - CompConstToX86reg(x86_ECX,0); - MoveVariableToX86reg(&PROGRAM_COUNTER, x86_ECX); - JeLabel8(0); - Jump2 = RecompPos - 1; - OrConstToX86Reg(CAUSE_BD, x86_EAX); - SubConstFromX86Reg(x86_ECX,4); - - SetJump8(Jump2, RecompPos); - - MoveX86regToVariable(x86_ECX, &EPC_REGISTER); - MoveX86regToVariable(x86_EAX, &CAUSE_REGISTER); - - OrConstToVariable(STATUS_EXL, &STATUS_REGISTER); - MoveConstToVariable(0x80000180, &PROGRAM_COUNTER); - Pop(x86_RAX); - SetJump8(Jump, RecompPos); - -} -#endif - -#ifdef USEX64 -void CompileCheckInterrupts(void) { - uint8_t * Jump, * Jump2, * Jump3; - - BreakPoint(); - Push(x86_EAX); - Push(x86_EDX); - - MoveVariableToX86reg(&MI_INTR_REG, x86_EAX); - MoveVariableToX86reg(&FAKE_CAUSE_REGISTER, x86_EDX); - AndConstToX86Reg(x86_EAX, ~MI_INTR_AI); - OrConstToX86Reg(CAUSE_IP2, x86_EDX); - TestVariableToX86Reg(x86_EAX, &MI_INTR_MASK_REG); - JnzLabel8(0); - Jump = RecompPos - 1; - AndConstToX86Reg(x86_EDX, ~CAUSE_IP2); - SetJump8(Jump, RecompPos); - - MoveVariableToX86reg(&STATUS_REGISTER, x86_TEMPD); - AndConstToX86Reg(x86_TEMPD,7); - CompConstToX86reg(x86_TEMPD,1); - JneLabel8(0); - Jump2 = RecompPos - 1; - - MoveVariableToX86reg(&STATUS_REGISTER, x86_TEMPD); - AddX86RegToX86Reg(x86_TEMPD, x86_EDX); - AndConstToX86Reg(x86_TEMPD,0xFF00); - - CompConstToVariable(0, &CPU_Action->DoInterrupt); - JneLabel8(0); - Jump = RecompPos - 1; - - MoveConstToVariable(1, &CPU_Action->DoInterrupt); - MoveConstToVariable(1, &CPU_Action->DoSomething); - - SetJump8(Jump, RecompPos); - SetJump8(Jump2, RecompPos); - - MoveX86regToVariable(x86_EAX, &MI_INTR_REG); - MoveX86regToVariable(x86_EDX, &FAKE_CAUSE_REGISTER); - Pop(x86_EDX); - Pop(x86_EAX); -} -#endif -*/ - -void DoTLBMiss ( uint32_t DelaySlot, uint32_t BadVaddr ) { - - CAUSE_REGISTER = EXC_RMISS; - BAD_VADDR_REGISTER = BadVaddr; - CONTEXT_REGISTER &= 0xFF80000F; - CONTEXT_REGISTER |= (BadVaddr >> 9) & 0x007FFFF0; - ENTRYHI_REGISTER = (BadVaddr & 0xFFFFE000); - if ((STATUS_REGISTER & STATUS_EXL) == 0) { - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER = PROGRAM_COUNTER - 4; - } else { - EPC_REGISTER = PROGRAM_COUNTER; - } - if (AddressDefined(BadVaddr)) { - PROGRAM_COUNTER = 0x80000180; - } else { - PROGRAM_COUNTER = 0x80000000; - } - STATUS_REGISTER |= STATUS_EXL; - } else { - PROGRAM_COUNTER = 0x80000180; - } -} - -void DoSysCallException ( uint32_t DelaySlot) { - CAUSE_REGISTER = EXC_SYSCALL; - if (DelaySlot) { - CAUSE_REGISTER |= CAUSE_BD; - EPC_REGISTER = PROGRAM_COUNTER - 4; - } else { - EPC_REGISTER = PROGRAM_COUNTER; - } - STATUS_REGISTER |= STATUS_EXL; - PROGRAM_COUNTER = 0x80000180; -} diff --git a/src/usf/exception.h b/src/usf/exception.h deleted file mode 100644 index 476a1d7..0000000 --- a/src/usf/exception.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#define EXC_CODE(x) ((x)<<2) -#define EXC_INT EXC_CODE(0) /* interrupt */ -#define EXC_MOD EXC_CODE(1) /* TLB mod */ -#define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */ -#define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */ -#define EXC_RADE EXC_CODE(4) /* Read Address Error */ -#define EXC_WADE EXC_CODE(5) /* Write Address Error */ -#define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */ -#define EXC_DBE EXC_CODE(7) /* Data Bus Error */ -#define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */ -#define EXC_BREAK EXC_CODE(9) /* BREAKpoint */ -#define EXC_II EXC_CODE(10)/* Illegal Instruction */ -#define EXC_CPU EXC_CODE(11)/* CoProcessor Unusable */ -#define EXC_OV EXC_CODE(12)/* OVerflow */ -#define EXC_TRAP EXC_CODE(13)/* Trap exception */ -#define EXC_VCEI EXC_CODE(14)/* Virt. Coherency on Inst. fetch */ -#define EXC_FPE EXC_CODE(15)/* Floating Point Exception */ -#define EXC_WATCH EXC_CODE(23)/* Watchpoint reference */ -#define EXC_VCED EXC_CODE(31)/* Virt. Coherency on data read */ - -#define Exception_Name(Except)\ - (Except) == EXC_INT ? "interrupt" :\ - (Except) == EXC_MOD ? "TLB mod" :\ - (Except) == EXC_RMISS ? "Read TLB Miss" :\ - (Except) == EXC_WMISS ? "Write TLB Miss" :\ - (Except) == EXC_RADE ? "Read Address Error" :\ - (Except) == EXC_WADE ? "Write Address Error" :\ - (Except) == EXC_IBE ? "Instruction Bus Error" :\ - (Except) == EXC_DBE ? "Data Bus Error" :\ - (Except) == EXC_SYSCALL ? "SYSCALL" :\ - (Except) == EXC_BREAK ? "Break" :\ - (Except) == EXC_II ? "Illegal Instruction" :\ - (Except) == EXC_CPU ? "CoProcessor Unusable" :\ - (Except) == EXC_OV ? "OVerflow" :\ - (Except) == EXC_TRAP ? "Trap exception" :\ - (Except) == EXC_VCEI ? "Virt. Coherency on Inst. fetch" :\ - (Except) == EXC_FPE ? "Floating Point Exception" :\ - (Except) == EXC_WATCH ? "Watchpoint reference" :\ - (Except) == EXC_VCED ? "Virt. Coherency on data read" :\ - "Unkown" - -void AiCheckInterrupts ( void ); -void CheckInterrupts ( void ); -void DoAddressError ( uint32_t DelaySlot, uint32_t BadVaddr, uint32_t FromRead ); -void DoBreakException ( uint32_t DelaySlot ); -void DoCopUnusableException ( uint32_t DelaySlot, uint32_t Coprocessor ); -void DoIntrException ( uint32_t DelaySlot ); -void DoTLBMiss ( uint32_t DelaySlot, uint32_t BadVaddr ); -void DoSysCallException ( uint32_t DelaySlot); - diff --git a/src/usf/interpreter_cpu.c b/src/usf/interpreter_cpu.c deleted file mode 100644 index f0eb7ed..0000000 --- a/src/usf/interpreter_cpu.c +++ /dev/null @@ -1,738 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 -#include -#include "main.h" -#include "cpu.h" -#include "usf.h" -#include "memory.h" - -#include - -void (* R4300i_Opcode[64])(); -void (* R4300i_Special[64])(); -void (* R4300i_Regimm[32])(); -void (* R4300i_CoP0[32])(); -void (* R4300i_CoP0_Function[64])(); -void (* R4300i_CoP1[32])(); -void (* R4300i_CoP1_BC[32])(); -void (* R4300i_CoP1_S[64])(); -void (* R4300i_CoP1_D[64])(); -void (* R4300i_CoP1_W[64])(); -void (* R4300i_CoP1_L[64])(); - -void R4300i_opcode_SPECIAL (void) { - ((void (*)()) R4300i_Special[ Opcode.funct ])(); -} - -void R4300i_opcode_REGIMM (void) { - ((void (*)()) R4300i_Regimm[ Opcode.rt ])(); -} - -void R4300i_opcode_COP0 (void) { - ((void (*)()) R4300i_CoP0[ Opcode.rs ])(); -} - -void R4300i_opcode_COP0_CO (void) { - ((void (*)()) R4300i_CoP0_Function[ Opcode.funct ])(); -} - -void R4300i_opcode_COP1 (void) { - ((void (*)()) R4300i_CoP1[ Opcode.fmt ])(); -} - -void R4300i_opcode_COP1_BC (void) { - ((void (*)()) R4300i_CoP1_BC[ Opcode.ft ])(); -} - -void R4300i_opcode_COP1_S (void) { - controlfp(RoundingModel); - ((void (*)()) R4300i_CoP1_S[ Opcode.funct ])(); -} - -void R4300i_opcode_COP1_D (void) { - controlfp(RoundingModel); - ((void (*)()) R4300i_CoP1_D[ Opcode.funct ])(); -} - -void R4300i_opcode_COP1_W (void) { - ((void (*)()) R4300i_CoP1_W[ Opcode.funct ])(); -} - -void R4300i_opcode_COP1_L (void) { - ((void (*)()) R4300i_CoP1_L[ Opcode.funct ])(); -} - - -void BuildInterpreter (void ) { - R4300i_Opcode[ 0] = R4300i_opcode_SPECIAL; - R4300i_Opcode[ 1] = R4300i_opcode_REGIMM; - R4300i_Opcode[ 2] = r4300i_J; - R4300i_Opcode[ 3] = r4300i_JAL; - R4300i_Opcode[ 4] = r4300i_BEQ; - R4300i_Opcode[ 5] = r4300i_BNE; - R4300i_Opcode[ 6] = r4300i_BLEZ; - R4300i_Opcode[ 7] = r4300i_BGTZ; - R4300i_Opcode[ 8] = r4300i_ADDI; - R4300i_Opcode[ 9] = r4300i_ADDIU; - R4300i_Opcode[10] = r4300i_SLTI; - R4300i_Opcode[11] = r4300i_SLTIU; - R4300i_Opcode[12] = r4300i_ANDI; - R4300i_Opcode[13] = r4300i_ORI; - R4300i_Opcode[14] = r4300i_XORI; - R4300i_Opcode[15] = r4300i_LUI; - R4300i_Opcode[16] = R4300i_opcode_COP0; - R4300i_Opcode[17] = R4300i_opcode_COP1; - R4300i_Opcode[18] = R4300i_UnknownOpcode; - R4300i_Opcode[19] = R4300i_UnknownOpcode; - R4300i_Opcode[20] = r4300i_BEQL; - R4300i_Opcode[21] = r4300i_BNEL; - R4300i_Opcode[22] = r4300i_BLEZL; - R4300i_Opcode[23] = r4300i_BGTZL; - R4300i_Opcode[24] = R4300i_UnknownOpcode; - R4300i_Opcode[25] = r4300i_DADDIU; - R4300i_Opcode[26] = r4300i_LDL; - R4300i_Opcode[27] = r4300i_LDR; - R4300i_Opcode[28] = R4300i_UnknownOpcode; - R4300i_Opcode[29] = R4300i_UnknownOpcode; - R4300i_Opcode[30] = R4300i_UnknownOpcode; - R4300i_Opcode[31] = R4300i_UnknownOpcode; - R4300i_Opcode[32] = r4300i_LB; - R4300i_Opcode[33] = r4300i_LH; - R4300i_Opcode[34] = r4300i_LWL; - R4300i_Opcode[35] = r4300i_LW; - R4300i_Opcode[36] = r4300i_LBU; - R4300i_Opcode[37] = r4300i_LHU; - R4300i_Opcode[38] = r4300i_LWR; - R4300i_Opcode[39] = r4300i_LWU; - R4300i_Opcode[40] = r4300i_SB; - R4300i_Opcode[41] = r4300i_SH; - R4300i_Opcode[42] = r4300i_SWL; - R4300i_Opcode[43] = r4300i_SW; - R4300i_Opcode[44] = r4300i_SDL; - R4300i_Opcode[45] = r4300i_SDR; - R4300i_Opcode[46] = r4300i_SWR; - R4300i_Opcode[47] = r4300i_CACHE; - R4300i_Opcode[48] = r4300i_LL; - R4300i_Opcode[49] = r4300i_LWC1; - R4300i_Opcode[50] = R4300i_UnknownOpcode; - R4300i_Opcode[51] = R4300i_UnknownOpcode; - R4300i_Opcode[52] = R4300i_UnknownOpcode; - R4300i_Opcode[53] = r4300i_LDC1; - R4300i_Opcode[54] = R4300i_UnknownOpcode; - R4300i_Opcode[55] = r4300i_LD; - R4300i_Opcode[56] = r4300i_SC; - R4300i_Opcode[57] = r4300i_SWC1; - R4300i_Opcode[58] = R4300i_UnknownOpcode; - R4300i_Opcode[59] = R4300i_UnknownOpcode; - R4300i_Opcode[60] = R4300i_UnknownOpcode; - R4300i_Opcode[61] = r4300i_SDC1; - R4300i_Opcode[62] = R4300i_UnknownOpcode; - R4300i_Opcode[63] = r4300i_SD; - - R4300i_Special[ 0] = r4300i_SPECIAL_SLL; - R4300i_Special[ 1] = R4300i_UnknownOpcode; - R4300i_Special[ 2] = r4300i_SPECIAL_SRL; - R4300i_Special[ 3] = r4300i_SPECIAL_SRA; - R4300i_Special[ 4] = r4300i_SPECIAL_SLLV; - R4300i_Special[ 5] = R4300i_UnknownOpcode; - R4300i_Special[ 6] = r4300i_SPECIAL_SRLV; - R4300i_Special[ 7] = r4300i_SPECIAL_SRAV; - R4300i_Special[ 8] = r4300i_SPECIAL_JR; - R4300i_Special[ 9] = r4300i_SPECIAL_JALR; - R4300i_Special[10] = R4300i_UnknownOpcode; - R4300i_Special[11] = R4300i_UnknownOpcode; - R4300i_Special[12] = r4300i_SPECIAL_SYSCALL; - R4300i_Special[13] = r4300i_SPECIAL_BREAK; - R4300i_Special[14] = R4300i_UnknownOpcode; - R4300i_Special[15] = r4300i_SPECIAL_SYNC; - R4300i_Special[16] = r4300i_SPECIAL_MFHI; - R4300i_Special[17] = r4300i_SPECIAL_MTHI; - R4300i_Special[18] = r4300i_SPECIAL_MFLO; - R4300i_Special[19] = r4300i_SPECIAL_MTLO; - R4300i_Special[20] = r4300i_SPECIAL_DSLLV; - R4300i_Special[21] = R4300i_UnknownOpcode; - R4300i_Special[22] = r4300i_SPECIAL_DSRLV; - R4300i_Special[23] = r4300i_SPECIAL_DSRAV; - R4300i_Special[24] = r4300i_SPECIAL_MULT; - R4300i_Special[25] = r4300i_SPECIAL_MULTU; - R4300i_Special[26] = r4300i_SPECIAL_DIV; - R4300i_Special[27] = r4300i_SPECIAL_DIVU; - R4300i_Special[28] = r4300i_SPECIAL_DMULT; - R4300i_Special[29] = r4300i_SPECIAL_DMULTU; - R4300i_Special[30] = r4300i_SPECIAL_DDIV; - R4300i_Special[31] = r4300i_SPECIAL_DDIVU; - R4300i_Special[32] = r4300i_SPECIAL_ADD; - R4300i_Special[33] = r4300i_SPECIAL_ADDU; - R4300i_Special[34] = r4300i_SPECIAL_SUB; - R4300i_Special[35] = r4300i_SPECIAL_SUBU; - R4300i_Special[36] = r4300i_SPECIAL_AND; - R4300i_Special[37] = r4300i_SPECIAL_OR; - R4300i_Special[38] = r4300i_SPECIAL_XOR; - R4300i_Special[39] = r4300i_SPECIAL_NOR; - R4300i_Special[40] = R4300i_UnknownOpcode; - R4300i_Special[41] = R4300i_UnknownOpcode; - R4300i_Special[42] = r4300i_SPECIAL_SLT; - R4300i_Special[43] = r4300i_SPECIAL_SLTU; - R4300i_Special[44] = r4300i_SPECIAL_DADD; - R4300i_Special[45] = r4300i_SPECIAL_DADDU; - R4300i_Special[46] = r4300i_SPECIAL_DSUB; - R4300i_Special[47] = r4300i_SPECIAL_DSUBU; - R4300i_Special[48] = R4300i_UnknownOpcode; - R4300i_Special[49] = R4300i_UnknownOpcode; - R4300i_Special[50] = R4300i_UnknownOpcode; - R4300i_Special[51] = R4300i_UnknownOpcode; - R4300i_Special[52] = r4300i_SPECIAL_TEQ; - R4300i_Special[53] = R4300i_UnknownOpcode; - R4300i_Special[54] = R4300i_UnknownOpcode; - R4300i_Special[55] = R4300i_UnknownOpcode; - R4300i_Special[56] = r4300i_SPECIAL_DSLL; - R4300i_Special[57] = R4300i_UnknownOpcode; - R4300i_Special[58] = r4300i_SPECIAL_DSRL; - R4300i_Special[59] = r4300i_SPECIAL_DSRA; - R4300i_Special[60] = r4300i_SPECIAL_DSLL32; - R4300i_Special[61] = R4300i_UnknownOpcode; - R4300i_Special[62] = r4300i_SPECIAL_DSRL32; - R4300i_Special[63] = r4300i_SPECIAL_DSRA32; - - R4300i_Regimm[ 0] = r4300i_REGIMM_BLTZ; - R4300i_Regimm[ 1] = r4300i_REGIMM_BGEZ; - R4300i_Regimm[ 2] = r4300i_REGIMM_BLTZL; - R4300i_Regimm[ 3] = r4300i_REGIMM_BGEZL; - R4300i_Regimm[ 4] = R4300i_UnknownOpcode; - R4300i_Regimm[ 5] = R4300i_UnknownOpcode; - R4300i_Regimm[ 6] = R4300i_UnknownOpcode; - R4300i_Regimm[ 7] = R4300i_UnknownOpcode; - R4300i_Regimm[ 8] = R4300i_UnknownOpcode; - R4300i_Regimm[ 9] = R4300i_UnknownOpcode; - R4300i_Regimm[10] = R4300i_UnknownOpcode; - R4300i_Regimm[11] = R4300i_UnknownOpcode; - R4300i_Regimm[12] = R4300i_UnknownOpcode; - R4300i_Regimm[13] = R4300i_UnknownOpcode; - R4300i_Regimm[14] = R4300i_UnknownOpcode; - R4300i_Regimm[15] = R4300i_UnknownOpcode; - R4300i_Regimm[16] = r4300i_REGIMM_BLTZAL; - R4300i_Regimm[17] = r4300i_REGIMM_BGEZAL; - R4300i_Regimm[18] = R4300i_UnknownOpcode; - R4300i_Regimm[19] = R4300i_UnknownOpcode; - R4300i_Regimm[20] = R4300i_UnknownOpcode; - R4300i_Regimm[21] = R4300i_UnknownOpcode; - R4300i_Regimm[22] = R4300i_UnknownOpcode; - R4300i_Regimm[23] = R4300i_UnknownOpcode; - R4300i_Regimm[24] = R4300i_UnknownOpcode; - R4300i_Regimm[25] = R4300i_UnknownOpcode; - R4300i_Regimm[26] = R4300i_UnknownOpcode; - R4300i_Regimm[27] = R4300i_UnknownOpcode; - R4300i_Regimm[28] = R4300i_UnknownOpcode; - R4300i_Regimm[29] = R4300i_UnknownOpcode; - R4300i_Regimm[30] = R4300i_UnknownOpcode; - R4300i_Regimm[31] = R4300i_UnknownOpcode; - - R4300i_CoP0[ 0] = r4300i_COP0_MF; - R4300i_CoP0[ 1] = R4300i_UnknownOpcode; - R4300i_CoP0[ 2] = R4300i_UnknownOpcode; - R4300i_CoP0[ 3] = R4300i_UnknownOpcode; - R4300i_CoP0[ 4] = r4300i_COP0_MT; - R4300i_CoP0[ 5] = R4300i_UnknownOpcode; - R4300i_CoP0[ 6] = R4300i_UnknownOpcode; - R4300i_CoP0[ 7] = R4300i_UnknownOpcode; - R4300i_CoP0[ 8] = R4300i_UnknownOpcode; - R4300i_CoP0[ 9] = R4300i_UnknownOpcode; - R4300i_CoP0[10] = R4300i_UnknownOpcode; - R4300i_CoP0[11] = R4300i_UnknownOpcode; - R4300i_CoP0[12] = R4300i_UnknownOpcode; - R4300i_CoP0[13] = R4300i_UnknownOpcode; - R4300i_CoP0[14] = R4300i_UnknownOpcode; - R4300i_CoP0[15] = R4300i_UnknownOpcode; - R4300i_CoP0[16] = R4300i_opcode_COP0_CO; - R4300i_CoP0[17] = R4300i_opcode_COP0_CO; - R4300i_CoP0[18] = R4300i_opcode_COP0_CO; - R4300i_CoP0[19] = R4300i_opcode_COP0_CO; - R4300i_CoP0[20] = R4300i_opcode_COP0_CO; - R4300i_CoP0[21] = R4300i_opcode_COP0_CO; - R4300i_CoP0[22] = R4300i_opcode_COP0_CO; - R4300i_CoP0[23] = R4300i_opcode_COP0_CO; - R4300i_CoP0[24] = R4300i_opcode_COP0_CO; - R4300i_CoP0[25] = R4300i_opcode_COP0_CO; - R4300i_CoP0[26] = R4300i_opcode_COP0_CO; - R4300i_CoP0[27] = R4300i_opcode_COP0_CO; - R4300i_CoP0[28] = R4300i_opcode_COP0_CO; - R4300i_CoP0[29] = R4300i_opcode_COP0_CO; - R4300i_CoP0[30] = R4300i_opcode_COP0_CO; - R4300i_CoP0[31] = R4300i_opcode_COP0_CO; - - R4300i_CoP0_Function[ 0] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[ 1] = r4300i_COP0_CO_TLBR; - R4300i_CoP0_Function[ 2] = r4300i_COP0_CO_TLBWI; - R4300i_CoP0_Function[ 3] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[ 4] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[ 5] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[ 6] = r4300i_COP0_CO_TLBWR; - R4300i_CoP0_Function[ 7] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[ 8] = r4300i_COP0_CO_TLBP; - R4300i_CoP0_Function[ 9] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[10] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[11] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[12] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[13] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[14] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[15] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[16] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[17] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[18] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[19] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[20] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[21] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[22] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[23] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[24] = r4300i_COP0_CO_ERET; - R4300i_CoP0_Function[25] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[26] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[27] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[28] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[29] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[30] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[31] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[32] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[33] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[34] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[35] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[36] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[37] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[38] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[39] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[40] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[41] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[42] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[43] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[44] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[45] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[46] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[47] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[48] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[49] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[50] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[51] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[52] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[53] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[54] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[55] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[56] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[57] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[58] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[59] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[60] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[61] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[62] = R4300i_UnknownOpcode; - R4300i_CoP0_Function[63] = R4300i_UnknownOpcode; - - R4300i_CoP1[ 0] = r4300i_COP1_MF; - R4300i_CoP1[ 1] = r4300i_COP1_DMF; - R4300i_CoP1[ 2] = r4300i_COP1_CF; - R4300i_CoP1[ 3] = R4300i_UnknownOpcode; - R4300i_CoP1[ 4] = r4300i_COP1_MT; - R4300i_CoP1[ 5] = r4300i_COP1_DMT; - R4300i_CoP1[ 6] = r4300i_COP1_CT; - R4300i_CoP1[ 7] = R4300i_UnknownOpcode; - R4300i_CoP1[ 8] = R4300i_opcode_COP1_BC; - R4300i_CoP1[ 9] = R4300i_UnknownOpcode; - R4300i_CoP1[10] = R4300i_UnknownOpcode; - R4300i_CoP1[11] = R4300i_UnknownOpcode; - R4300i_CoP1[12] = R4300i_UnknownOpcode; - R4300i_CoP1[13] = R4300i_UnknownOpcode; - R4300i_CoP1[14] = R4300i_UnknownOpcode; - R4300i_CoP1[15] = R4300i_UnknownOpcode; - R4300i_CoP1[16] = R4300i_opcode_COP1_S; - R4300i_CoP1[17] = R4300i_opcode_COP1_D; - R4300i_CoP1[18] = R4300i_UnknownOpcode; - R4300i_CoP1[19] = R4300i_UnknownOpcode; - R4300i_CoP1[20] = R4300i_opcode_COP1_W; - R4300i_CoP1[21] = R4300i_opcode_COP1_L; - R4300i_CoP1[22] = R4300i_UnknownOpcode; - R4300i_CoP1[23] = R4300i_UnknownOpcode; - R4300i_CoP1[24] = R4300i_UnknownOpcode; - R4300i_CoP1[25] = R4300i_UnknownOpcode; - R4300i_CoP1[26] = R4300i_UnknownOpcode; - R4300i_CoP1[27] = R4300i_UnknownOpcode; - R4300i_CoP1[28] = R4300i_UnknownOpcode; - R4300i_CoP1[29] = R4300i_UnknownOpcode; - R4300i_CoP1[30] = R4300i_UnknownOpcode; - R4300i_CoP1[31] = R4300i_UnknownOpcode; - - R4300i_CoP1_BC[ 0] = r4300i_COP1_BCF; - R4300i_CoP1_BC[ 1] = r4300i_COP1_BCT; - R4300i_CoP1_BC[ 2] = r4300i_COP1_BCFL; - R4300i_CoP1_BC[ 3] = r4300i_COP1_BCTL; - R4300i_CoP1_BC[ 4] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[ 5] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[ 6] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[ 7] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[ 8] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[ 9] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[10] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[11] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[12] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[13] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[14] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[15] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[16] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[17] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[18] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[19] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[20] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[21] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[22] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[23] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[24] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[25] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[26] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[27] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[28] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[29] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[30] = R4300i_UnknownOpcode; - R4300i_CoP1_BC[31] = R4300i_UnknownOpcode; - - R4300i_CoP1_S[ 0] = r4300i_COP1_S_ADD; - R4300i_CoP1_S[ 1] = r4300i_COP1_S_SUB; - R4300i_CoP1_S[ 2] = r4300i_COP1_S_MUL; - R4300i_CoP1_S[ 3] = r4300i_COP1_S_DIV; - R4300i_CoP1_S[ 4] = r4300i_COP1_S_SQRT; - R4300i_CoP1_S[ 5] = r4300i_COP1_S_ABS; - R4300i_CoP1_S[ 6] = r4300i_COP1_S_MOV; - R4300i_CoP1_S[ 7] = r4300i_COP1_S_NEG; - R4300i_CoP1_S[ 8] = R4300i_UnknownOpcode; - R4300i_CoP1_S[ 9] = r4300i_COP1_S_TRUNC_L; - R4300i_CoP1_S[10] = r4300i_COP1_S_CEIL_L; //added by Witten - R4300i_CoP1_S[11] = r4300i_COP1_S_FLOOR_L; //added by Witten - R4300i_CoP1_S[12] = r4300i_COP1_S_ROUND_W; - R4300i_CoP1_S[13] = r4300i_COP1_S_TRUNC_W; - R4300i_CoP1_S[14] = r4300i_COP1_S_CEIL_W; //added by Witten - R4300i_CoP1_S[15] = r4300i_COP1_S_FLOOR_W; - R4300i_CoP1_S[16] = R4300i_UnknownOpcode; - R4300i_CoP1_S[17] = R4300i_UnknownOpcode; - R4300i_CoP1_S[18] = R4300i_UnknownOpcode; - R4300i_CoP1_S[19] = R4300i_UnknownOpcode; - R4300i_CoP1_S[20] = R4300i_UnknownOpcode; - R4300i_CoP1_S[21] = R4300i_UnknownOpcode; - R4300i_CoP1_S[22] = R4300i_UnknownOpcode; - R4300i_CoP1_S[23] = R4300i_UnknownOpcode; - R4300i_CoP1_S[24] = R4300i_UnknownOpcode; - R4300i_CoP1_S[25] = R4300i_UnknownOpcode; - R4300i_CoP1_S[26] = R4300i_UnknownOpcode; - R4300i_CoP1_S[27] = R4300i_UnknownOpcode; - R4300i_CoP1_S[28] = R4300i_UnknownOpcode; - R4300i_CoP1_S[29] = R4300i_UnknownOpcode; - R4300i_CoP1_S[30] = R4300i_UnknownOpcode; - R4300i_CoP1_S[31] = R4300i_UnknownOpcode; - R4300i_CoP1_S[32] = R4300i_UnknownOpcode; - R4300i_CoP1_S[33] = r4300i_COP1_S_CVT_D; - R4300i_CoP1_S[34] = R4300i_UnknownOpcode; - R4300i_CoP1_S[35] = R4300i_UnknownOpcode; - R4300i_CoP1_S[36] = r4300i_COP1_S_CVT_W; - R4300i_CoP1_S[37] = r4300i_COP1_S_CVT_L; - R4300i_CoP1_S[38] = R4300i_UnknownOpcode; - R4300i_CoP1_S[39] = R4300i_UnknownOpcode; - R4300i_CoP1_S[40] = R4300i_UnknownOpcode; - R4300i_CoP1_S[41] = R4300i_UnknownOpcode; - R4300i_CoP1_S[42] = R4300i_UnknownOpcode; - R4300i_CoP1_S[43] = R4300i_UnknownOpcode; - R4300i_CoP1_S[44] = R4300i_UnknownOpcode; - R4300i_CoP1_S[45] = R4300i_UnknownOpcode; - R4300i_CoP1_S[46] = R4300i_UnknownOpcode; - R4300i_CoP1_S[47] = R4300i_UnknownOpcode; - R4300i_CoP1_S[48] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[49] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[50] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[51] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[52] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[53] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[54] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[55] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[56] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[57] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[58] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[59] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[60] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[61] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[62] = r4300i_COP1_S_CMP; - R4300i_CoP1_S[63] = r4300i_COP1_S_CMP; - - R4300i_CoP1_D[ 0] = r4300i_COP1_D_ADD; - R4300i_CoP1_D[ 1] = r4300i_COP1_D_SUB; - R4300i_CoP1_D[ 2] = r4300i_COP1_D_MUL; - R4300i_CoP1_D[ 3] = r4300i_COP1_D_DIV; - R4300i_CoP1_D[ 4] = r4300i_COP1_D_SQRT; - R4300i_CoP1_D[ 5] = r4300i_COP1_D_ABS; - R4300i_CoP1_D[ 6] = r4300i_COP1_D_MOV; - R4300i_CoP1_D[ 7] = r4300i_COP1_D_NEG; - R4300i_CoP1_D[ 8] = R4300i_UnknownOpcode; - R4300i_CoP1_D[ 9] = r4300i_COP1_D_TRUNC_L; //added by Witten - R4300i_CoP1_D[10] = r4300i_COP1_D_CEIL_L; //added by Witten - R4300i_CoP1_D[11] = r4300i_COP1_D_FLOOR_L; //added by Witten - R4300i_CoP1_D[12] = r4300i_COP1_D_ROUND_W; - R4300i_CoP1_D[13] = r4300i_COP1_D_TRUNC_W; - R4300i_CoP1_D[14] = r4300i_COP1_D_CEIL_W; //added by Witten - R4300i_CoP1_D[15] = r4300i_COP1_D_FLOOR_W; //added by Witten - R4300i_CoP1_D[16] = R4300i_UnknownOpcode; - R4300i_CoP1_D[17] = R4300i_UnknownOpcode; - R4300i_CoP1_D[18] = R4300i_UnknownOpcode; - R4300i_CoP1_D[19] = R4300i_UnknownOpcode; - R4300i_CoP1_D[20] = R4300i_UnknownOpcode; - R4300i_CoP1_D[21] = R4300i_UnknownOpcode; - R4300i_CoP1_D[22] = R4300i_UnknownOpcode; - R4300i_CoP1_D[23] = R4300i_UnknownOpcode; - R4300i_CoP1_D[24] = R4300i_UnknownOpcode; - R4300i_CoP1_D[25] = R4300i_UnknownOpcode; - R4300i_CoP1_D[26] = R4300i_UnknownOpcode; - R4300i_CoP1_D[27] = R4300i_UnknownOpcode; - R4300i_CoP1_D[28] = R4300i_UnknownOpcode; - R4300i_CoP1_D[29] = R4300i_UnknownOpcode; - R4300i_CoP1_D[30] = R4300i_UnknownOpcode; - R4300i_CoP1_D[31] = R4300i_UnknownOpcode; - R4300i_CoP1_D[32] = r4300i_COP1_D_CVT_S; - R4300i_CoP1_D[33] = R4300i_UnknownOpcode; - R4300i_CoP1_D[34] = R4300i_UnknownOpcode; - R4300i_CoP1_D[35] = R4300i_UnknownOpcode; - R4300i_CoP1_D[36] = r4300i_COP1_D_CVT_W; - R4300i_CoP1_D[37] = r4300i_COP1_D_CVT_L; - R4300i_CoP1_D[38] = R4300i_UnknownOpcode; - R4300i_CoP1_D[39] = R4300i_UnknownOpcode; - R4300i_CoP1_D[40] = R4300i_UnknownOpcode; - R4300i_CoP1_D[41] = R4300i_UnknownOpcode; - R4300i_CoP1_D[42] = R4300i_UnknownOpcode; - R4300i_CoP1_D[43] = R4300i_UnknownOpcode; - R4300i_CoP1_D[44] = R4300i_UnknownOpcode; - R4300i_CoP1_D[45] = R4300i_UnknownOpcode; - R4300i_CoP1_D[46] = R4300i_UnknownOpcode; - R4300i_CoP1_D[47] = R4300i_UnknownOpcode; - R4300i_CoP1_D[48] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[49] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[50] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[51] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[52] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[53] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[54] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[55] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[56] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[57] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[58] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[59] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[60] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[61] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[62] = r4300i_COP1_D_CMP; - R4300i_CoP1_D[63] = r4300i_COP1_D_CMP; - - R4300i_CoP1_W[ 0] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 1] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 2] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 3] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 4] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 5] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 6] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 7] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 8] = R4300i_UnknownOpcode; - R4300i_CoP1_W[ 9] = R4300i_UnknownOpcode; - R4300i_CoP1_W[10] = R4300i_UnknownOpcode; - R4300i_CoP1_W[11] = R4300i_UnknownOpcode; - R4300i_CoP1_W[12] = R4300i_UnknownOpcode; - R4300i_CoP1_W[13] = R4300i_UnknownOpcode; - R4300i_CoP1_W[14] = R4300i_UnknownOpcode; - R4300i_CoP1_W[15] = R4300i_UnknownOpcode; - R4300i_CoP1_W[16] = R4300i_UnknownOpcode; - R4300i_CoP1_W[17] = R4300i_UnknownOpcode; - R4300i_CoP1_W[18] = R4300i_UnknownOpcode; - R4300i_CoP1_W[19] = R4300i_UnknownOpcode; - R4300i_CoP1_W[20] = R4300i_UnknownOpcode; - R4300i_CoP1_W[21] = R4300i_UnknownOpcode; - R4300i_CoP1_W[22] = R4300i_UnknownOpcode; - R4300i_CoP1_W[23] = R4300i_UnknownOpcode; - R4300i_CoP1_W[24] = R4300i_UnknownOpcode; - R4300i_CoP1_W[25] = R4300i_UnknownOpcode; - R4300i_CoP1_W[26] = R4300i_UnknownOpcode; - R4300i_CoP1_W[27] = R4300i_UnknownOpcode; - R4300i_CoP1_W[28] = R4300i_UnknownOpcode; - R4300i_CoP1_W[29] = R4300i_UnknownOpcode; - R4300i_CoP1_W[30] = R4300i_UnknownOpcode; - R4300i_CoP1_W[31] = R4300i_UnknownOpcode; - R4300i_CoP1_W[32] = r4300i_COP1_W_CVT_S; - R4300i_CoP1_W[33] = r4300i_COP1_W_CVT_D; - R4300i_CoP1_W[34] = R4300i_UnknownOpcode; - R4300i_CoP1_W[35] = R4300i_UnknownOpcode; - R4300i_CoP1_W[36] = R4300i_UnknownOpcode; - R4300i_CoP1_W[37] = R4300i_UnknownOpcode; - R4300i_CoP1_W[38] = R4300i_UnknownOpcode; - R4300i_CoP1_W[39] = R4300i_UnknownOpcode; - R4300i_CoP1_W[40] = R4300i_UnknownOpcode; - R4300i_CoP1_W[41] = R4300i_UnknownOpcode; - R4300i_CoP1_W[42] = R4300i_UnknownOpcode; - R4300i_CoP1_W[43] = R4300i_UnknownOpcode; - R4300i_CoP1_W[44] = R4300i_UnknownOpcode; - R4300i_CoP1_W[45] = R4300i_UnknownOpcode; - R4300i_CoP1_W[46] = R4300i_UnknownOpcode; - R4300i_CoP1_W[47] = R4300i_UnknownOpcode; - R4300i_CoP1_W[48] = R4300i_UnknownOpcode; - R4300i_CoP1_W[49] = R4300i_UnknownOpcode; - R4300i_CoP1_W[50] = R4300i_UnknownOpcode; - R4300i_CoP1_W[51] = R4300i_UnknownOpcode; - R4300i_CoP1_W[52] = R4300i_UnknownOpcode; - R4300i_CoP1_W[53] = R4300i_UnknownOpcode; - R4300i_CoP1_W[54] = R4300i_UnknownOpcode; - R4300i_CoP1_W[55] = R4300i_UnknownOpcode; - R4300i_CoP1_W[56] = R4300i_UnknownOpcode; - R4300i_CoP1_W[57] = R4300i_UnknownOpcode; - R4300i_CoP1_W[58] = R4300i_UnknownOpcode; - R4300i_CoP1_W[59] = R4300i_UnknownOpcode; - R4300i_CoP1_W[60] = R4300i_UnknownOpcode; - R4300i_CoP1_W[61] = R4300i_UnknownOpcode; - R4300i_CoP1_W[62] = R4300i_UnknownOpcode; - R4300i_CoP1_W[63] = R4300i_UnknownOpcode; - - R4300i_CoP1_L[ 0] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 1] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 2] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 3] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 4] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 5] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 6] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 7] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 8] = R4300i_UnknownOpcode; - R4300i_CoP1_L[ 9] = R4300i_UnknownOpcode; - R4300i_CoP1_L[10] = R4300i_UnknownOpcode; - R4300i_CoP1_L[11] = R4300i_UnknownOpcode; - R4300i_CoP1_L[12] = R4300i_UnknownOpcode; - R4300i_CoP1_L[13] = R4300i_UnknownOpcode; - R4300i_CoP1_L[14] = R4300i_UnknownOpcode; - R4300i_CoP1_L[15] = R4300i_UnknownOpcode; - R4300i_CoP1_L[16] = R4300i_UnknownOpcode; - R4300i_CoP1_L[17] = R4300i_UnknownOpcode; - R4300i_CoP1_L[18] = R4300i_UnknownOpcode; - R4300i_CoP1_L[19] = R4300i_UnknownOpcode; - R4300i_CoP1_L[20] = R4300i_UnknownOpcode; - R4300i_CoP1_L[21] = R4300i_UnknownOpcode; - R4300i_CoP1_L[22] = R4300i_UnknownOpcode; - R4300i_CoP1_L[23] = R4300i_UnknownOpcode; - R4300i_CoP1_L[24] = R4300i_UnknownOpcode; - R4300i_CoP1_L[25] = R4300i_UnknownOpcode; - R4300i_CoP1_L[26] = R4300i_UnknownOpcode; - R4300i_CoP1_L[27] = R4300i_UnknownOpcode; - R4300i_CoP1_L[28] = R4300i_UnknownOpcode; - R4300i_CoP1_L[29] = R4300i_UnknownOpcode; - R4300i_CoP1_L[30] = R4300i_UnknownOpcode; - R4300i_CoP1_L[31] = R4300i_UnknownOpcode; - R4300i_CoP1_L[32] = r4300i_COP1_L_CVT_S; - R4300i_CoP1_L[33] = r4300i_COP1_L_CVT_D; - R4300i_CoP1_L[34] = R4300i_UnknownOpcode; - R4300i_CoP1_L[35] = R4300i_UnknownOpcode; - R4300i_CoP1_L[36] = R4300i_UnknownOpcode; - R4300i_CoP1_L[37] = R4300i_UnknownOpcode; - R4300i_CoP1_L[38] = R4300i_UnknownOpcode; - R4300i_CoP1_L[39] = R4300i_UnknownOpcode; - R4300i_CoP1_L[40] = R4300i_UnknownOpcode; - R4300i_CoP1_L[41] = R4300i_UnknownOpcode; - R4300i_CoP1_L[42] = R4300i_UnknownOpcode; - R4300i_CoP1_L[43] = R4300i_UnknownOpcode; - R4300i_CoP1_L[44] = R4300i_UnknownOpcode; - R4300i_CoP1_L[45] = R4300i_UnknownOpcode; - R4300i_CoP1_L[46] = R4300i_UnknownOpcode; - R4300i_CoP1_L[47] = R4300i_UnknownOpcode; - R4300i_CoP1_L[48] = R4300i_UnknownOpcode; - R4300i_CoP1_L[49] = R4300i_UnknownOpcode; - R4300i_CoP1_L[50] = R4300i_UnknownOpcode; - R4300i_CoP1_L[51] = R4300i_UnknownOpcode; - R4300i_CoP1_L[52] = R4300i_UnknownOpcode; - R4300i_CoP1_L[53] = R4300i_UnknownOpcode; - R4300i_CoP1_L[54] = R4300i_UnknownOpcode; - R4300i_CoP1_L[55] = R4300i_UnknownOpcode; - R4300i_CoP1_L[56] = R4300i_UnknownOpcode; - R4300i_CoP1_L[57] = R4300i_UnknownOpcode; - R4300i_CoP1_L[58] = R4300i_UnknownOpcode; - R4300i_CoP1_L[59] = R4300i_UnknownOpcode; - R4300i_CoP1_L[60] = R4300i_UnknownOpcode; - R4300i_CoP1_L[61] = R4300i_UnknownOpcode; - R4300i_CoP1_L[62] = R4300i_UnknownOpcode; - R4300i_CoP1_L[63] = R4300i_UnknownOpcode; -} - - -void ExecuteInterpreterOpCode (void) { - - - if (*WaitMode) Timers->Timer = -1; - - if (!r4300i_LW_VAddr(PROGRAM_COUNTER, &Opcode.Hex)) { - DoTLBMiss(NextInstruction == JUMP,PROGRAM_COUNTER); - NextInstruction = NORMAL; - return; - } - - COUNT_REGISTER += 2; - Timers->Timer -= 2; - - RANDOM_REGISTER -= 1; - if ((int32_t)RANDOM_REGISTER < (int32_t)WIRED_REGISTER) { - RANDOM_REGISTER = 31; - } - - R4300i_Opcode[ Opcode.op ](); - - if (GPR[0].DW != 0) { - GPR[0].DW = 0; - } - - switch (NextInstruction) { - case NORMAL: - PROGRAM_COUNTER += 4; - break; - case DELAY_SLOT: - NextInstruction = JUMP; - PROGRAM_COUNTER += 4; - break; - case JUMP: - PROGRAM_COUNTER = JumpToLocation; - NextInstruction = NORMAL; - if ((int32_t)Timers->Timer < 0) { TimerDone(); } - if (CPU_Action->DoSomething) { DoSomething(); } - - } -} - -void StartInterpreterCPU (void ) { - NextInstruction = NORMAL; - - while(cpu_running) { - ExecuteInterpreterOpCode(); - } - - cpu_stopped = 1; - -} - -void TestInterpreterJump (uint32_t PC, uint32_t TargetPC, int32_t Reg1, int32_t Reg2) { - if (PC != TargetPC) { return; } - if (DelaySlotEffectsCompare(PC,Reg1,Reg2)) { return; } - if (CPU_Type != CPU_Interpreter) { return; } - InPermLoop(); -} diff --git a/src/usf/interpreter_cpu.h b/src/usf/interpreter_cpu.h deleted file mode 100644 index 22f9bc2..0000000 --- a/src/usf/interpreter_cpu.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 - -void BuildInterpreter ( void ); -void ExecuteInterpreterOpCode ( void ); -void StartInterpreterCPU ( void ); -void TestInterpreterJump ( uint32_t PC, uint32_t TargetPC, int32_t Reg1, int32_t Reg2 ); - - - - - -extern void (* R4300i_Opcode[64])(); diff --git a/src/usf/interpreter_ops.c b/src/usf/interpreter_ops.c deleted file mode 100644 index 65c94f3..0000000 --- a/src/usf/interpreter_ops.c +++ /dev/null @@ -1,1362 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 -#include -#include -#include -#include "main.h" -#include "cpu.h" - -int32_t RoundingModel = _FPU_RC_NEAREST; - -#define ADDRESS_ERROR_EXCEPTION(Address,FromRead) \ - DoAddressError(NextInstruction == JUMP,Address,FromRead);\ - NextInstruction = JUMP;\ - JumpToLocation = PROGRAM_COUNTER;\ - return; - -//#define TEST_COP1_USABLE_EXCEPTION -#define TEST_COP1_USABLE_EXCEPTION \ - if ((STATUS_REGISTER & STATUS_CU1) == 0) {\ - DoCopUnusableException(NextInstruction == JUMP,1);\ - NextInstruction = JUMP;\ - JumpToLocation = PROGRAM_COUNTER;\ - return;\ - } - -#define TLB_READ_EXCEPTION(Address) \ - DoTLBMiss(NextInstruction == JUMP,Address);\ - NextInstruction = JUMP;\ - JumpToLocation = PROGRAM_COUNTER;\ - return; - -/************************* OpCode functions *************************/ -void r4300i_J (void) { - NextInstruction = DELAY_SLOT; - JumpToLocation = (PROGRAM_COUNTER & 0xF0000000) + (Opcode.target << 2); - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,0,0); -} - -void r4300i_JAL (void) { - NextInstruction = DELAY_SLOT; - JumpToLocation = (PROGRAM_COUNTER & 0xF0000000) + (Opcode.target << 2); - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,0,0); - GPR[31].DW= (int32_t)(PROGRAM_COUNTER + 8); -} - -void r4300i_BEQ (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW == GPR[Opcode.rt].DW) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,Opcode.rt); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BNE (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW != GPR[Opcode.rt].DW) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,Opcode.rt); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BLEZ (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW <= 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BGTZ (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW > 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_ADDI (void) { - if (Opcode.rt == 0) { return; } - GPR[Opcode.rt].DW = (GPR[Opcode.rs].W[0] + ((int16_t)Opcode.immediate)); -} - -void r4300i_ADDIU (void) { - GPR[Opcode.rt].DW = (GPR[Opcode.rs].W[0] + ((int16_t)Opcode.immediate)); -} - -void r4300i_SLTI (void) { - if (GPR[Opcode.rs].DW < (int64_t)((int16_t)Opcode.immediate)) { - GPR[Opcode.rt].DW = 1; - } else { - GPR[Opcode.rt].DW = 0; - } -} - -void r4300i_SLTIU (void) { - int32_t imm32 = (int16_t)Opcode.immediate; - int64_t imm64; - - imm64 = imm32; - GPR[Opcode.rt].DW = GPR[Opcode.rs].UDW < (uint64_t)imm64?1:0; -} - -void r4300i_ANDI (void) { - GPR[Opcode.rt].DW = GPR[Opcode.rs].DW & Opcode.immediate; -} - -void r4300i_ORI (void) { - GPR[Opcode.rt].DW = GPR[Opcode.rs].DW | Opcode.immediate; -} - -void r4300i_XORI (void) { - GPR[Opcode.rt].DW = GPR[Opcode.rs].DW ^ Opcode.immediate; -} - -void r4300i_LUI (void) { - if (Opcode.rt == 0) { return; } - GPR[Opcode.rt].DW = (int32_t)((int16_t)Opcode.offset << 16); -} - -void r4300i_BEQL (void) { - if (GPR[Opcode.rs].DW == GPR[Opcode.rt].DW) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,Opcode.rt); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BNEL (void) { - if (GPR[Opcode.rs].DW != GPR[Opcode.rt].DW) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,Opcode.rt); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BLEZL (void) { - if (GPR[Opcode.rs].DW <= 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_BGTZL (void) { - if (GPR[Opcode.rs].DW > 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_DADDIU (void) { - GPR[Opcode.rt].DW = GPR[Opcode.rs].DW + (int64_t)((int16_t)Opcode.immediate); -} - -uint64_t LDL_MASK[8] = { 0ULL,0xFFULL,0xFFFFULL,0xFFFFFFULL,0xFFFFFFFFULL,0xFFFFFFFFFFULL, 0xFFFFFFFFFFFFULL, 0xFFFFFFFFFFFFFFULL }; -int32_t LDL_SHIFT[8] = { 0, 8, 16, 24, 32, 40, 48, 56 }; - -void r4300i_LDL (void) { - uint32_t Offset, Address; - uint64_t Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 7; - - if (!r4300i_LD_VAddr((Address & ~7),&Value)) { - return; - } - GPR[Opcode.rt].DW = GPR[Opcode.rt].DW & LDL_MASK[Offset]; - GPR[Opcode.rt].DW += Value << LDL_SHIFT[Offset]; -} - -uint64_t LDR_MASK[8] = { 0xFFFFFFFFFFFFFF00ULL, 0xFFFFFFFFFFFF0000ULL, - 0xFFFFFFFFFF000000ULL, 0xFFFFFFFF00000000ULL, - 0xFFFFFF0000000000ULL, 0xFFFF000000000000ULL, - 0xFF00000000000000ULL, 0 }; -int32_t LDR_SHIFT[8] = { 56, 48, 40, 32, 24, 16, 8, 0 }; - -void r4300i_LDR (void) { - uint32_t Offset, Address; - uint64_t Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 7; - - if (!r4300i_LD_VAddr((Address & ~7),&Value)) { - return; - } - - GPR[Opcode.rt].DW = GPR[Opcode.rt].DW & LDR_MASK[Offset]; - GPR[Opcode.rt].DW += Value >> LDR_SHIFT[Offset]; - -} - -void r4300i_LB (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if (Opcode.rt == 0) { return; } - if (!r4300i_LB_VAddr(Address,&GPR[Opcode.rt].UB[0])) { - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].DW = GPR[Opcode.rt].B[0]; - } -} - -void r4300i_LH (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (!r4300i_LH_VAddr(Address,&GPR[Opcode.rt].UHW[0])) { - //if (ShowTLBMisses) { - DisplayError("LH TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].DW = GPR[Opcode.rt].HW[0]; - } -} - -uint32_t LWL_MASK[4] = { 0,0xFF,0xFFFF,0xFFFFFF }; -int32_t LWL_SHIFT[4] = { 0, 8, 16, 24}; - -void r4300i_LWL (void) { - uint32_t Offset, Address, Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 3; - - if (!r4300i_LW_VAddr((Address & ~3),&Value)) { - return; - } - - GPR[Opcode.rt].DW = (int32_t)(GPR[Opcode.rt].W[0] & LWL_MASK[Offset]); - GPR[Opcode.rt].DW += (int32_t)(Value << LWL_SHIFT[Offset]); -} - -void r4300i_LW (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - - -// if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - - if (Opcode.rt == 0) { return; } - - - if (!r4300i_LW_VAddr(Address,&GPR[Opcode.rt].UW[0])) { - //if (ShowTLBMisses) { - printf("LW TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].DW = GPR[Opcode.rt].W[0]; - } -} - -void r4300i_LBU (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if (!r4300i_LB_VAddr(Address,&GPR[Opcode.rt].UB[0])) { - //if (ShowTLBMisses) { - DisplayError("LBU TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].UDW = GPR[Opcode.rt].UB[0]; - } -} - -void r4300i_LHU (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (!r4300i_LH_VAddr(Address,&GPR[Opcode.rt].UHW[0])) { - //if (ShowTLBMisses) { - DisplayError("LHU TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].UDW = GPR[Opcode.rt].UHW[0]; - } -} - -uint32_t LWR_MASK[4] = { 0xFFFFFF00, 0xFFFF0000, 0xFF000000, 0 }; -int32_t LWR_SHIFT[4] = { 24, 16 ,8, 0 }; - -void r4300i_LWR (void) { - uint32_t Offset, Address, Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 3; - - if (!r4300i_LW_VAddr((Address & ~3),&Value)) { - return; - } - - GPR[Opcode.rt].DW = (int32_t)(GPR[Opcode.rt].W[0] & LWR_MASK[Offset]); - GPR[Opcode.rt].DW += (int32_t)(Value >> LWR_SHIFT[Offset]); -} - -void r4300i_LWU (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (Opcode.rt == 0) { return; } - - if (!r4300i_LW_VAddr(Address,&GPR[Opcode.rt].UW[0])) { - //if (ShowTLBMisses) { - DisplayError("LWU TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].UDW = GPR[Opcode.rt].UW[0]; - } -} - -void r4300i_SB (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if (!r4300i_SB_VAddr(Address,GPR[Opcode.rt].UB[0])) { - } -} - -void r4300i_SH (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 1) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - if (!r4300i_SH_VAddr(Address,GPR[Opcode.rt].UHW[0])) { - } -} - -uint32_t SWL_MASK[4] = { 0,0xFF000000,0xFFFF0000,0xFFFFFF00 }; -int32_t SWL_SHIFT[4] = { 0, 8, 16, 24 }; - -void r4300i_SWL (void) { - uint32_t Offset, Address, Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 3; - - if (!r4300i_LW_VAddr((Address & ~3),&Value)) { - return; - } - - Value &= SWL_MASK[Offset]; - Value += GPR[Opcode.rt].UW[0] >> SWL_SHIFT[Offset]; - - if (!r4300i_SW_VAddr((Address & ~0x03),Value)) { - } -} - - -void r4300i_SW (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - if (!r4300i_SW_VAddr(Address,GPR[Opcode.rt].UW[0])) { - } - //TranslateVaddr(&Address); - //if (Address == 0x00090AA0) { - // LogMessage("%X: Write %X to %X",PROGRAM_COUNTER,GPR[Opcode.rt].UW[0],GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset); - //} -} - -uint64_t SDL_MASK[8] = { 0,0xFF00000000000000ULL, - 0xFFFF000000000000ULL, - 0xFFFFFF0000000000ULL, - 0xFFFFFFFF00000000ULL, - 0xFFFFFFFFFF000000ULL, - 0xFFFFFFFFFFFF0000ULL, - 0xFFFFFFFFFFFFFF00ULL - }; -int32_t SDL_SHIFT[8] = { 0, 8, 16, 24, 32, 40, 48, 56 }; - -void r4300i_SDL (void) { - uint32_t Offset, Address; - uint64_t Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 7; - - if (!r4300i_LD_VAddr((Address & ~7),&Value)) { - return; - } - - Value &= SDL_MASK[Offset]; - Value += GPR[Opcode.rt].UDW >> SDL_SHIFT[Offset]; - - if (!r4300i_SD_VAddr((Address & ~7),Value)) { - } -} - -uint64_t SDR_MASK[8] = { 0x00FFFFFFFFFFFFFFULL, - 0x0000FFFFFFFFFFFFULL, - 0x000000FFFFFFFFFFULL, - 0x00000000FFFFFFFFULL, - 0x0000000000FFFFFFULL, - 0x000000000000FFFFULL, - 0x00000000000000FFULL, - 0x0000000000000000ULL - }; -int32_t SDR_SHIFT[8] = { 56,48,40,32,24,16,8,0 }; - -void r4300i_SDR (void) { - uint32_t Offset, Address; - uint64_t Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 7; - - if (!r4300i_LD_VAddr((Address & ~7),&Value)) { - return; - } - - Value &= SDR_MASK[Offset]; - Value += GPR[Opcode.rt].UDW << SDR_SHIFT[Offset]; - - if (!r4300i_SD_VAddr((Address & ~7),Value)) { - } -} - -uint32_t SWR_MASK[4] = { 0x00FFFFFF,0x0000FFFF,0x000000FF,0x00000000 }; -int32_t SWR_SHIFT[4] = { 24, 16 , 8, 0 }; - -void r4300i_SWR (void) { - uint32_t Offset, Address, Value; - - Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - Offset = Address & 3; - - if (!r4300i_LW_VAddr((Address & ~3),&Value)) { - return; - } - - Value &= SWR_MASK[Offset]; - Value += GPR[Opcode.rt].UW[0] << SWR_SHIFT[Offset]; - - if (!r4300i_SW_VAddr((Address & ~0x03),Value)) { - } -} - -void r4300i_CACHE (void) { -} - -void r4300i_LL (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - uintptr_t ll = 0; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - - if (Opcode.rt == 0) { return; } - - if (!r4300i_LW_VAddr(Address,&GPR[Opcode.rt].UW[0])) { - //if (ShowTLBMisses) { - DisplayError("LW TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } else { - GPR[Opcode.rt].DW = GPR[Opcode.rt].W[0]; - } - LLBit = 1; - LLAddr = Address; - ll = LLAddr; - TranslateVaddr(&ll); - LLAddr = ll; - -} - -void r4300i_LWC1 (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (uint32_t)((int16_t)Opcode.offset); - TEST_COP1_USABLE_EXCEPTION - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (!r4300i_LW_VAddr(Address,&*(uint32_t *)FPRFloatLocation[Opcode.ft])) { - //if (ShowTLBMisses) { - DisplayError("LWC1 TLB: %X",Address); - //} - TLB_READ_EXCEPTION(Address); - } -} - -void r4300i_SC (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - if (LLBit == 1) { - if (!r4300i_SW_VAddr(Address,GPR[Opcode.rt].UW[0])) { - DisplayError("SW TLB: %X",Address); - } - } - GPR[Opcode.rt].UW[0] = LLBit; -} - -void r4300i_LD (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (!r4300i_LD_VAddr(Address,&GPR[Opcode.rt].UDW)) { - } -} - - -void r4300i_LDC1 (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - - TEST_COP1_USABLE_EXCEPTION - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,1); } - if (!r4300i_LD_VAddr(Address,&*(uint64_t *)FPRDoubleLocation[Opcode.ft])) { - } -} - -void r4300i_SWC1 (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - TEST_COP1_USABLE_EXCEPTION - if ((Address & 3) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - - if (!r4300i_SW_VAddr(Address,*(uint32_t *)FPRFloatLocation[Opcode.ft])) { - } -} - -void r4300i_SDC1 (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - - TEST_COP1_USABLE_EXCEPTION - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - if (!r4300i_SD_VAddr(Address,*(int64_t *)FPRDoubleLocation[Opcode.ft])) { - } -} - -void r4300i_SD (void) { - uint32_t Address = GPR[Opcode.base].UW[0] + (int16_t)Opcode.offset; - if ((Address & 7) != 0) { ADDRESS_ERROR_EXCEPTION(Address,0); } - if (!r4300i_SD_VAddr(Address,GPR[Opcode.rt].UDW)) { - } -} -/********************** R4300i OpCodes: Special **********************/ -void r4300i_SPECIAL_SLL (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].W[0] << Opcode.sa); -} - -void r4300i_SPECIAL_SRL (void) { - GPR[Opcode.rd].DW = (int32_t)(GPR[Opcode.rt].UW[0] >> Opcode.sa); -} - -void r4300i_SPECIAL_SRA (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].W[0] >> Opcode.sa); -} - -void r4300i_SPECIAL_SLLV (void) { - if (Opcode.rd == 0) { return; } - GPR[Opcode.rd].DW = (GPR[Opcode.rt].W[0] << (GPR[Opcode.rs].UW[0] & 0x1F)); -} - -void r4300i_SPECIAL_SRLV (void) { - GPR[Opcode.rd].DW = (int32_t)(GPR[Opcode.rt].UW[0] >> (GPR[Opcode.rs].UW[0] & 0x1F)); -} - -void r4300i_SPECIAL_SRAV (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].W[0] >> (GPR[Opcode.rs].UW[0] & 0x1F)); -} - -void r4300i_SPECIAL_JR (void) { - NextInstruction = DELAY_SLOT; - JumpToLocation = GPR[Opcode.rs].UW[0]; -} - -void r4300i_SPECIAL_JALR (void) { - NextInstruction = DELAY_SLOT; - JumpToLocation = GPR[Opcode.rs].UW[0]; - GPR[Opcode.rd].DW = (int32_t)(PROGRAM_COUNTER + 8); -} - -void r4300i_SPECIAL_SYSCALL (void) { - DoSysCallException(NextInstruction == JUMP); - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER; -} - -void r4300i_SPECIAL_BREAK (void) { - *WaitMode=1; -} - -void r4300i_SPECIAL_SYNC (void) { -} - -void r4300i_SPECIAL_MFHI (void) { - GPR[Opcode.rd].DW = HI.DW; -} - -void r4300i_SPECIAL_MTHI (void) { - HI.DW = GPR[Opcode.rs].DW; -} - -void r4300i_SPECIAL_MFLO (void) { - GPR[Opcode.rd].DW = LO.DW; -} - -void r4300i_SPECIAL_MTLO (void) { - LO.DW = GPR[Opcode.rs].DW; -} - -void r4300i_SPECIAL_DSLLV (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rt].DW << (GPR[Opcode.rs].UW[0] & 0x3F); -} - -void r4300i_SPECIAL_DSRLV (void) { - GPR[Opcode.rd].UDW = GPR[Opcode.rt].UDW >> (GPR[Opcode.rs].UW[0] & 0x3F); -} - -void r4300i_SPECIAL_DSRAV (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rt].DW >> (GPR[Opcode.rs].UW[0] & 0x3F); -} - -void r4300i_SPECIAL_MULT (void) { - HI.DW = (int64_t)(GPR[Opcode.rs].W[0]) * (int64_t)(GPR[Opcode.rt].W[0]); - LO.DW = HI.W[0]; - HI.DW = HI.W[1]; -} - -void r4300i_SPECIAL_MULTU (void) { - HI.DW = (uint64_t)(GPR[Opcode.rs].UW[0]) * (uint64_t)(GPR[Opcode.rt].UW[0]); - LO.DW = HI.W[0]; - HI.DW = HI.W[1]; -} - -void r4300i_SPECIAL_DIV (void) { - if ( GPR[Opcode.rt].UDW != 0 ) { - LO.DW = GPR[Opcode.rs].W[0] / GPR[Opcode.rt].W[0]; - HI.DW = GPR[Opcode.rs].W[0] % GPR[Opcode.rt].W[0]; - } else { - } -} - -void r4300i_SPECIAL_DIVU (void) { - if ( GPR[Opcode.rt].UDW != 0 ) { - LO.DW = (int32_t)(GPR[Opcode.rs].UW[0] / GPR[Opcode.rt].UW[0]); - HI.DW = (int32_t)(GPR[Opcode.rs].UW[0] % GPR[Opcode.rt].UW[0]); - } else { - } -} - -void r4300i_SPECIAL_DMULT (void) { - MIPS_DWORD Tmp[3]; - - LO.UDW = (uint64_t)GPR[Opcode.rs].UW[0] * (uint64_t)GPR[Opcode.rt].UW[0]; - Tmp[0].UDW = (int64_t)GPR[Opcode.rs].W[1] * (int64_t)(uint64_t)GPR[Opcode.rt].UW[0]; - Tmp[1].UDW = (int64_t)(uint64_t)GPR[Opcode.rs].UW[0] * (int64_t)GPR[Opcode.rt].W[1]; - HI.UDW = (int64_t)GPR[Opcode.rs].W[1] * (int64_t)GPR[Opcode.rt].W[1]; - - Tmp[2].UDW = (uint64_t)LO.UW[1] + (uint64_t)Tmp[0].UW[0] + (uint64_t)Tmp[1].UW[0]; - LO.UDW += ((uint64_t)Tmp[0].UW[0] + (uint64_t)Tmp[1].UW[0]) << 32; - HI.UDW += (uint64_t)Tmp[0].W[1] + (uint64_t)Tmp[1].W[1] + Tmp[2].UW[1]; -} - -void r4300i_SPECIAL_DMULTU (void) { - MIPS_DWORD Tmp[3]; - - LO.UDW = (uint64_t)GPR[Opcode.rs].UW[0] * (uint64_t)GPR[Opcode.rt].UW[0]; - Tmp[0].UDW = (uint64_t)GPR[Opcode.rs].UW[1] * (uint64_t)GPR[Opcode.rt].UW[0]; - Tmp[1].UDW = (uint64_t)GPR[Opcode.rs].UW[0] * (uint64_t)GPR[Opcode.rt].UW[1]; - HI.UDW = (uint64_t)GPR[Opcode.rs].UW[1] * (uint64_t)GPR[Opcode.rt].UW[1]; - - Tmp[2].UDW = (uint64_t)LO.UW[1] + (uint64_t)Tmp[0].UW[0] + (uint64_t)Tmp[1].UW[0]; - LO.UDW += ((uint64_t)Tmp[0].UW[0] + (uint64_t)Tmp[1].UW[0]) << 32; - HI.UDW += (uint64_t)Tmp[0].UW[1] + (uint64_t)Tmp[1].UW[1] + Tmp[2].UW[1]; -} - -void r4300i_SPECIAL_DDIV (void) { - if ( GPR[Opcode.rt].UDW != 0 ) { - LO.DW = GPR[Opcode.rs].DW / GPR[Opcode.rt].DW; - HI.DW = GPR[Opcode.rs].DW % GPR[Opcode.rt].DW; - } else { - } -} - -void r4300i_SPECIAL_DDIVU (void) { - if ( GPR[Opcode.rt].UDW != 0 ) { - LO.UDW = GPR[Opcode.rs].UDW / GPR[Opcode.rt].UDW; - HI.UDW = GPR[Opcode.rs].UDW % GPR[Opcode.rt].UDW; - } else { - } -} - -void r4300i_SPECIAL_ADD (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].W[0] + GPR[Opcode.rt].W[0]; -} - -void r4300i_SPECIAL_ADDU (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].W[0] + GPR[Opcode.rt].W[0]; -} - -void r4300i_SPECIAL_SUB (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].W[0] - GPR[Opcode.rt].W[0]; -} - -void r4300i_SPECIAL_SUBU (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].W[0] - GPR[Opcode.rt].W[0]; -} - -void r4300i_SPECIAL_AND (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW & GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_OR (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW | GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_XOR (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW ^ GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_NOR (void) { - GPR[Opcode.rd].DW = ~(GPR[Opcode.rs].DW | GPR[Opcode.rt].DW); -} - -void r4300i_SPECIAL_SLT (void) { - if (GPR[Opcode.rs].DW < GPR[Opcode.rt].DW) { - GPR[Opcode.rd].DW = 1; - } else { - GPR[Opcode.rd].DW = 0; - } -} - -void r4300i_SPECIAL_SLTU (void) { - if (GPR[Opcode.rs].UDW < GPR[Opcode.rt].UDW) { - GPR[Opcode.rd].DW = 1; - } else { - GPR[Opcode.rd].DW = 0; - } -} - -void r4300i_SPECIAL_DADD (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW + GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_DADDU (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW + GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_DSUB (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW - GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_DSUBU (void) { - GPR[Opcode.rd].DW = GPR[Opcode.rs].DW - GPR[Opcode.rt].DW; -} - -void r4300i_SPECIAL_TEQ (void) { - if (GPR[Opcode.rs].DW == GPR[Opcode.rt].DW) { - } -} - -void r4300i_SPECIAL_DSLL (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].DW << Opcode.sa); -} - -void r4300i_SPECIAL_DSRL (void) { - GPR[Opcode.rd].UDW = (GPR[Opcode.rt].UDW >> Opcode.sa); -} - -void r4300i_SPECIAL_DSRA (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].DW >> Opcode.sa); -} - -void r4300i_SPECIAL_DSLL32 (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].DW << (Opcode.sa + 32)); -} - -void r4300i_SPECIAL_DSRL32 (void) { - GPR[Opcode.rd].UDW = (GPR[Opcode.rt].UDW >> (Opcode.sa + 32)); -} - -void r4300i_SPECIAL_DSRA32 (void) { - GPR[Opcode.rd].DW = (GPR[Opcode.rt].DW >> (Opcode.sa + 32)); -} - -/********************** R4300i OpCodes: RegImm **********************/ -void r4300i_REGIMM_BLTZ (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW < 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_REGIMM_BGEZ (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW >= 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_REGIMM_BLTZL (void) { - if (GPR[Opcode.rs].DW < 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_REGIMM_BGEZL (void) { - if (GPR[Opcode.rs].DW >= 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_REGIMM_BLTZAL (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW < 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } - GPR[31].DW= (int32_t)(PROGRAM_COUNTER + 8); -} - -void r4300i_REGIMM_BGEZAL (void) { - NextInstruction = DELAY_SLOT; - if (GPR[Opcode.rs].DW >= 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - TestInterpreterJump(PROGRAM_COUNTER,JumpToLocation,Opcode.rs,0); - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } - GPR[31].DW = (int32_t)(PROGRAM_COUNTER + 8); -} -/************************** COP0 functions **************************/ -void r4300i_COP0_MF (void) { - GPR[Opcode.rt].DW = (int32_t)CP0[Opcode.rd]; -} - -void r4300i_COP0_MT (void) { - switch (Opcode.rd) { - case 0: //Index - case 2: //EntryLo0 - case 3: //EntryLo1 - case 5: //PageMask - case 6: //Wired - case 10: //Entry Hi - case 14: //EPC - case 16: //Config - case 18: //WatchLo - case 19: //WatchHi - case 28: //Tag lo - case 29: //Tag Hi - case 30: //ErrEPC - CP0[Opcode.rd] = GPR[Opcode.rt].UW[0]; - break; - case 4: //Context - CP0[Opcode.rd] = GPR[Opcode.rt].UW[0] & 0xFF800000; - break; - case 9: //Count - CP0[Opcode.rd]= GPR[Opcode.rt].UW[0]; - ChangeCompareTimer(); - break; - case 11: //Compare - CP0[Opcode.rd] = GPR[Opcode.rt].UW[0]; - FAKE_CAUSE_REGISTER &= ~CAUSE_IP7; - ChangeCompareTimer(); - break; - case 12: //Status - if ((CP0[Opcode.rd] ^ GPR[Opcode.rt].UW[0]) != 0) { - CP0[Opcode.rd] = GPR[Opcode.rt].UW[0]; - SetFpuLocations(); - } else { - CP0[Opcode.rd] = GPR[Opcode.rt].UW[0]; - } - if ((CP0[Opcode.rd] & 0x18) != 0) { - } - CheckInterrupts(); - break; - case 13: //cause - CP0[Opcode.rd] &= 0xFFFFCFF; - break; - default: - R4300i_UnknownOpcode(); - } - -} - -/************************** COP0 CO functions ***********************/ -void r4300i_COP0_CO_TLBR (void) { - TLB_Read(); -} - -void r4300i_COP0_CO_TLBWI (void) { - WriteTLBEntry(INDEX_REGISTER & 0x1F); -} - -void r4300i_COP0_CO_TLBWR (void) { - WriteTLBEntry(RANDOM_REGISTER & 0x1F); -} - -void r4300i_COP0_CO_TLBP (void) { - TLB_Probe(); -} - -void r4300i_COP0_CO_ERET (void) { - NextInstruction = JUMP; - if ((STATUS_REGISTER & STATUS_ERL) != 0) { - JumpToLocation = ERROREPC_REGISTER; - STATUS_REGISTER &= ~STATUS_ERL; - } else { - JumpToLocation = EPC_REGISTER; - STATUS_REGISTER &= ~STATUS_EXL; - } - LLBit = 0; - CheckInterrupts(); -} - -/************************** COP1 functions **************************/ -void r4300i_COP1_MF (void) { - TEST_COP1_USABLE_EXCEPTION - GPR[Opcode.rt].DW = *(int32_t *)FPRFloatLocation[Opcode.fs]; -} - -void r4300i_COP1_DMF (void) { - TEST_COP1_USABLE_EXCEPTION - GPR[Opcode.rt].DW = *(int64_t *)FPRDoubleLocation[Opcode.fs]; -} - -void r4300i_COP1_CF (void) { - TEST_COP1_USABLE_EXCEPTION - if (Opcode.fs != 31 && Opcode.fs != 0) { - return; - } - GPR[Opcode.rt].DW = (int32_t)FPCR[Opcode.fs]; -} - -void r4300i_COP1_MT (void) { - TEST_COP1_USABLE_EXCEPTION - *(int32_t *)FPRFloatLocation[Opcode.fs] = GPR[Opcode.rt].W[0]; -} - -void r4300i_COP1_DMT (void) { - TEST_COP1_USABLE_EXCEPTION - *(int64_t *)FPRDoubleLocation[Opcode.fs] = GPR[Opcode.rt].DW; -} - -void r4300i_COP1_CT (void) { - TEST_COP1_USABLE_EXCEPTION - if (Opcode.fs == 31) { - FPCR[Opcode.fs] = GPR[Opcode.rt].W[0]; - switch((FPCR[Opcode.fs] & 3)) { - case 0: RoundingModel = _FPU_RC_NEAREST; break; - case 1: RoundingModel = _FPU_RC_ZERO; break; - case 2: RoundingModel = _FPU_RC_UP; break; - case 3: RoundingModel = _FPU_RC_DOWN; break; - } - return; - } -} - -/************************* COP1: BC1 functions ***********************/ -void r4300i_COP1_BCF (void) { - TEST_COP1_USABLE_EXCEPTION - NextInstruction = DELAY_SLOT; - if ((FPCR[31] & FPCSR_C) == 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_COP1_BCT (void) { - TEST_COP1_USABLE_EXCEPTION - NextInstruction = DELAY_SLOT; - if ((FPCR[31] & FPCSR_C) != 0) { - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - } else { - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_COP1_BCFL (void) { - TEST_COP1_USABLE_EXCEPTION - if ((FPCR[31] & FPCSR_C) == 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} - -void r4300i_COP1_BCTL (void) { - TEST_COP1_USABLE_EXCEPTION - if ((FPCR[31] & FPCSR_C) != 0) { - NextInstruction = DELAY_SLOT; - JumpToLocation = PROGRAM_COUNTER + ((int16_t)Opcode.offset << 2) + 4; - } else { - NextInstruction = JUMP; - JumpToLocation = PROGRAM_COUNTER + 8; - } -} -/************************** COP1: S functions ************************/ -__inline void Float_RoundToInteger32( int32_t * Dest, float * Source ) { - *Dest = (int32_t)*Source; -} - -__inline void Float_RoundToInteger64( int64_t * Dest, float * Source ) { - *Dest = (int64_t)*Source; -} - -void r4300i_COP1_S_ADD (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (*(float *)FPRFloatLocation[Opcode.fs] + *(float *)FPRFloatLocation[Opcode.ft]); -} - -void r4300i_COP1_S_SUB (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (*(float *)FPRFloatLocation[Opcode.fs] - *(float *)FPRFloatLocation[Opcode.ft]); -} - -void r4300i_COP1_S_MUL (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (*(float *)FPRFloatLocation[Opcode.fs] * *(float *)FPRFloatLocation[Opcode.ft]); -} - -void r4300i_COP1_S_DIV (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (*(float *)FPRFloatLocation[Opcode.fs] / *(float *)FPRFloatLocation[Opcode.ft]); -} - -void r4300i_COP1_S_SQRT (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (float)sqrt(*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_ABS (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (float)fabs(*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_MOV (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = *(float *)FPRFloatLocation[Opcode.fs]; -} - -void r4300i_COP1_S_NEG (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (*(float *)FPRFloatLocation[Opcode.fs] * -1.0f); -} - -void r4300i_COP1_S_TRUNC_L (void) { - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_RC_CHOP,_MCW_RC); - Float_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CEIL_L (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_RC_UP,_MCW_RC); - Float_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_FLOOR_L (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_FPU_RC_DOWN,_MCW_RC); - Float_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_ROUND_W (void) { - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_FPU_RC_NEAREST,_MCW_RC); - Float_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_TRUNC_W (void) { - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_RC_CHOP,_MCW_RC); - Float_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CEIL_W (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_RC_UP,_MCW_RC); - Float_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_FLOOR_W (void) { - TEST_COP1_USABLE_EXCEPTION - //_controlfp(_FPU_RC_DOWN,_MCW_RC); - Float_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CVT_D (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(double *)FPRDoubleLocation[Opcode.fd] = (double)(*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CVT_W (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - Float_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CVT_L (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - Float_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(float *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_S_CMP (void) { - int32_t less, equal, unorded, condition; - float Temp0, Temp1; - - TEST_COP1_USABLE_EXCEPTION - - Temp0 = *(float *)FPRFloatLocation[Opcode.fs]; - Temp1 = *(float *)FPRFloatLocation[Opcode.ft]; - - if(0) { - //if (_isnan(Temp0) || _isnan(Temp1)) { - less = 0; - equal = 0; - unorded = 1; - if ((Opcode.funct & 8) != 0) { - } - } else { - less = Temp0 < Temp1; - equal = Temp0 == Temp1; - unorded = 0; - } - - condition = ((Opcode.funct & 4) && less) | ((Opcode.funct & 2) && equal) | - ((Opcode.funct & 1) && unorded); - - if (condition) { - FPCR[31] |= FPCSR_C; - } else { - FPCR[31] &= ~FPCSR_C; - } - -} - -/************************** COP1: D functions ************************/ -__inline void Double_RoundToInteger32( int32_t * Dest, double * Source ) { - *Dest = (int32_t)*Source; -} - -__inline void Double_RoundToInteger64( int64_t * Dest, double * Source ) { - *Dest = (int64_t)*Source; -} - -void r4300i_COP1_D_ADD (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = *(double *)FPRDoubleLocation[Opcode.fs] + *(double *)FPRDoubleLocation[Opcode.ft]; -} - -void r4300i_COP1_D_SUB (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = *(double *)FPRDoubleLocation[Opcode.fs] - *(double *)FPRDoubleLocation[Opcode.ft]; -} - -void r4300i_COP1_D_MUL (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = *(double *)FPRDoubleLocation[Opcode.fs] * *(double *)FPRDoubleLocation[Opcode.ft]; -} - -void r4300i_COP1_D_DIV (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = *(double *)FPRDoubleLocation[Opcode.fs] / *(double *)FPRDoubleLocation[Opcode.ft]; -} - -void r4300i_COP1_D_SQRT (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = (double)sqrt(*(double *)FPRDoubleLocation[Opcode.fs]); -} - -void r4300i_COP1_D_ABS (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = fabs(*(double *)FPRDoubleLocation[Opcode.fs]); -} - -void r4300i_COP1_D_MOV (void) { - TEST_COP1_USABLE_EXCEPTION - *(int64_t *)FPRDoubleLocation[Opcode.fd] = *(int64_t *)FPRDoubleLocation[Opcode.fs]; -} - -void r4300i_COP1_D_NEG (void) { - TEST_COP1_USABLE_EXCEPTION - *(double *)FPRDoubleLocation[Opcode.fd] = (*(double *)FPRDoubleLocation[Opcode.fs] * -1.0); -} - -void r4300i_COP1_D_TRUNC_L (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_ZERO); - Double_RoundToInteger64(&*(int64_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_CEIL_L (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_UP); - Double_RoundToInteger64(&*(int64_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_FLOOR_L (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_DOWN); - Double_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(double *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_D_ROUND_W (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_NEAREST); - Double_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_TRUNC_W (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_ZERO); - Double_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_CEIL_W (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_UP); - Double_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_FLOOR_W (void) { //added by Witten - TEST_COP1_USABLE_EXCEPTION - controlfp(_FPU_RC_DOWN); - Double_RoundToInteger32(&*(int32_t *)FPRDoubleLocation[Opcode.fd],&*(double *)FPRFloatLocation[Opcode.fs]); -} - -void r4300i_COP1_D_CVT_S (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (float)*(double *)FPRDoubleLocation[Opcode.fs]; -} - -void r4300i_COP1_D_CVT_W (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - Double_RoundToInteger32(&*(int32_t *)FPRFloatLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs] ); -} - -void r4300i_COP1_D_CVT_L (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - Double_RoundToInteger64(&*(int64_t *)FPRDoubleLocation[Opcode.fd],&*(double *)FPRDoubleLocation[Opcode.fs]); -} - -void r4300i_COP1_D_CMP (void) { - int32_t less, equal, unorded, condition; - MIPS_DWORD Temp0, Temp1; - - TEST_COP1_USABLE_EXCEPTION - - Temp0.DW = *(int64_t *)FPRDoubleLocation[Opcode.fs]; - Temp1.DW = *(int64_t *)FPRDoubleLocation[Opcode.ft]; - - if(0) { - //if (_isnan(Temp0.D) || _isnan(Temp1.D)) { - less = 0; - equal = 0; - unorded = 1; - if ((Opcode.funct & 8) != 0) { - } - } else { - less = Temp0.D < Temp1.D; - equal = Temp0.D == Temp1.D; - unorded = 0; - } - - condition = ((Opcode.funct & 4) && less) | ((Opcode.funct & 2) && equal) | - ((Opcode.funct & 1) && unorded); - - if (condition) { - FPCR[31] |= FPCSR_C; - } else { - FPCR[31] &= ~FPCSR_C; - } -} - -/************************** COP1: W functions ************************/ -void r4300i_COP1_W_CVT_S (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (float)*(int32_t *)FPRFloatLocation[Opcode.fs]; -} - -void r4300i_COP1_W_CVT_D (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(double *)FPRDoubleLocation[Opcode.fd] = (double)*(int32_t *)FPRFloatLocation[Opcode.fs]; -} - -/************************** COP1: L functions ************************/ -void r4300i_COP1_L_CVT_S (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(float *)FPRFloatLocation[Opcode.fd] = (float)*(int64_t *)FPRDoubleLocation[Opcode.fs]; -} - -void r4300i_COP1_L_CVT_D (void) { - TEST_COP1_USABLE_EXCEPTION - controlfp(RoundingModel); - *(double *)FPRDoubleLocation[Opcode.fd] = (double)*(int64_t *)FPRDoubleLocation[Opcode.fs]; -} - -/************************** Other functions **************************/ -void R4300i_UnknownOpcode (void) { - DisplayError("Unkniown X86 Opcode.\tPC:%08x\tOp:%08x\n", PROGRAM_COUNTER,Opcode.Hex); - StopEmulation(); -} diff --git a/src/usf/interpreter_ops.h b/src/usf/interpreter_ops.h deleted file mode 100644 index 01a6bbd..0000000 --- a/src/usf/interpreter_ops.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -/************************* OpCode functions *************************/ -void r4300i_J ( void ); -void r4300i_JAL ( void ); -void r4300i_BNE ( void ); -void r4300i_BEQ ( void ); -void r4300i_BLEZ ( void ); -void r4300i_BGTZ ( void ); -void r4300i_ADDI ( void ); -void r4300i_ADDIU ( void ); -void r4300i_SLTI ( void ); -void r4300i_SLTIU ( void ); -void r4300i_ANDI ( void ); -void r4300i_ORI ( void ); -void r4300i_XORI ( void ); -void r4300i_LUI ( void ); -void r4300i_BEQL ( void ); -void r4300i_BNEL ( void ); -void r4300i_BLEZL ( void ); -void r4300i_BGTZL ( void ); -void r4300i_DADDIU ( void ); -void r4300i_LDL ( void ); -void r4300i_LDR ( void ); -void r4300i_LB ( void ); -void r4300i_LH ( void ); -void r4300i_LWL ( void ); -void r4300i_LW ( void ); -void r4300i_LBU ( void ); -void r4300i_LHU ( void ); -void r4300i_LWR ( void ); -void r4300i_LWU ( void ); -void r4300i_SB ( void ); -void r4300i_SH ( void ); -void r4300i_SWL ( void ); -void r4300i_SW ( void ); -void r4300i_SDL ( void ); -void r4300i_SDR ( void ); -void r4300i_SWR ( void ); -void r4300i_CACHE ( void ); -void r4300i_LL ( void ); -void r4300i_LWC1 ( void ); -void r4300i_LDC1 ( void ); -void r4300i_LD ( void ); -void r4300i_SC ( void ); -void r4300i_SWC1 ( void ); -void r4300i_SDC1 ( void ); -void r4300i_SD ( void ); - -/********************** R4300i OpCodes: Special **********************/ -void r4300i_SPECIAL_SLL ( void ); -void r4300i_SPECIAL_SRL ( void ); -void r4300i_SPECIAL_SRA ( void ); -void r4300i_SPECIAL_SLLV ( void ); -void r4300i_SPECIAL_SRLV ( void ); -void r4300i_SPECIAL_SRAV ( void ); -void r4300i_SPECIAL_JR ( void ); -void r4300i_SPECIAL_JALR ( void ); -void r4300i_SPECIAL_SYSCALL ( void ); -void r4300i_SPECIAL_BREAK ( void ); -void r4300i_SPECIAL_SYNC ( void ); -void r4300i_SPECIAL_MFHI ( void ); -void r4300i_SPECIAL_MTHI ( void ); -void r4300i_SPECIAL_MFLO ( void ); -void r4300i_SPECIAL_MTLO ( void ); -void r4300i_SPECIAL_DSLLV ( void ); -void r4300i_SPECIAL_DSRLV ( void ); -void r4300i_SPECIAL_DSRAV ( void ); -void r4300i_SPECIAL_MULT ( void ); -void r4300i_SPECIAL_MULTU ( void ); -void r4300i_SPECIAL_DIV ( void ); -void r4300i_SPECIAL_DIVU ( void ); -void r4300i_SPECIAL_DMULT ( void ); -void r4300i_SPECIAL_DMULTU ( void ); -void r4300i_SPECIAL_DDIV ( void ); -void r4300i_SPECIAL_DDIVU ( void ); -void r4300i_SPECIAL_ADD ( void ); -void r4300i_SPECIAL_ADDU ( void ); -void r4300i_SPECIAL_SUB ( void ); -void r4300i_SPECIAL_SUBU ( void ); -void r4300i_SPECIAL_AND ( void ); -void r4300i_SPECIAL_OR ( void ); -void r4300i_SPECIAL_XOR ( void ); -void r4300i_SPECIAL_NOR ( void ); -void r4300i_SPECIAL_SLT ( void ); -void r4300i_SPECIAL_SLTU ( void ); -void r4300i_SPECIAL_DADD ( void ); -void r4300i_SPECIAL_DADDU ( void ); -void r4300i_SPECIAL_DSUB ( void ); -void r4300i_SPECIAL_DSUBU ( void ); -void r4300i_SPECIAL_TEQ ( void ); -void r4300i_SPECIAL_DSLL ( void ); -void r4300i_SPECIAL_DSRL ( void ); -void r4300i_SPECIAL_DSRA ( void ); -void r4300i_SPECIAL_DSLL32 ( void ); -void r4300i_SPECIAL_DSRL32 ( void ); -void r4300i_SPECIAL_DSRA32 ( void ); - -/********************** R4300i OpCodes: RegImm **********************/ -void r4300i_REGIMM_BLTZ ( void ); -void r4300i_REGIMM_BGEZ ( void ); -void r4300i_REGIMM_BLTZL ( void ); -void r4300i_REGIMM_BGEZL ( void ); -void r4300i_REGIMM_BLTZAL ( void ); -void r4300i_REGIMM_BGEZAL ( void ); - -/************************** COP0 functions **************************/ -void r4300i_COP0_MF ( void ); -void r4300i_COP0_MT ( void ); - -/************************** COP0 CO functions ***********************/ -void r4300i_COP0_CO_TLBR ( void ); -void r4300i_COP0_CO_TLBWI ( void ); -void r4300i_COP0_CO_TLBWR ( void ); -void r4300i_COP0_CO_TLBP ( void ); -void r4300i_COP0_CO_ERET ( void ); - -/************************** COP1 functions **************************/ -void r4300i_COP1_MF ( void ); -void r4300i_COP1_DMF ( void ); -void r4300i_COP1_CF ( void ); -void r4300i_COP1_MT ( void ); -void r4300i_COP1_DMT ( void ); -void r4300i_COP1_CT ( void ); - -/************************* COP1: BC1 functions ***********************/ -void r4300i_COP1_BCF ( void ); -void r4300i_COP1_BCT ( void ); -void r4300i_COP1_BCFL ( void ); -void r4300i_COP1_BCTL ( void ); - -/************************** COP1: S functions ************************/ -void r4300i_COP1_S_ADD ( void ); -void r4300i_COP1_S_SUB ( void ); -void r4300i_COP1_S_MUL ( void ); -void r4300i_COP1_S_DIV ( void ); -void r4300i_COP1_S_SQRT ( void ); -void r4300i_COP1_S_ABS ( void ); -void r4300i_COP1_S_MOV ( void ); -void r4300i_COP1_S_NEG ( void ); -void r4300i_COP1_S_TRUNC_L ( void ); -void r4300i_COP1_S_CEIL_L ( void ); //added by Witten -void r4300i_COP1_S_FLOOR_L ( void ); //added by Witten -void r4300i_COP1_S_ROUND_W ( void ); -void r4300i_COP1_S_TRUNC_W ( void ); -void r4300i_COP1_S_CEIL_W ( void ); //added by Witten -void r4300i_COP1_S_FLOOR_W ( void ); -void r4300i_COP1_S_CVT_D ( void ); -void r4300i_COP1_S_CVT_W ( void ); -void r4300i_COP1_S_CVT_L ( void ); -void r4300i_COP1_S_CMP ( void ); - -/************************** COP1: D functions ************************/ -void r4300i_COP1_D_ADD ( void ); -void r4300i_COP1_D_SUB ( void ); -void r4300i_COP1_D_MUL ( void ); -void r4300i_COP1_D_DIV ( void ); -void r4300i_COP1_D_SQRT ( void ); -void r4300i_COP1_D_ABS ( void ); -void r4300i_COP1_D_MOV ( void ); -void r4300i_COP1_D_NEG ( void ); -void r4300i_COP1_D_TRUNC_L ( void ); //added by Witten -void r4300i_COP1_D_CEIL_L ( void ); //added by Witten -void r4300i_COP1_D_FLOOR_L ( void ); //added by Witten -void r4300i_COP1_D_ROUND_W ( void ); -void r4300i_COP1_D_TRUNC_W ( void ); -void r4300i_COP1_D_CEIL_W ( void ); //added by Witten -void r4300i_COP1_D_FLOOR_W ( void ); //added by Witten -void r4300i_COP1_D_CVT_S ( void ); -void r4300i_COP1_D_CVT_W ( void ); -void r4300i_COP1_D_CVT_L ( void ); -void r4300i_COP1_D_CMP ( void ); - -/************************** COP1: W functions ************************/ -void r4300i_COP1_W_CVT_S ( void ); -void r4300i_COP1_W_CVT_D ( void ); - -/************************** COP1: L functions ************************/ -void r4300i_COP1_L_CVT_S ( void ); -void r4300i_COP1_L_CVT_D ( void ); - -/************************** Other functions **************************/ -void R4300i_UnknownOpcode ( void ); - -extern uint32_t SWL_MASK[4], SWR_MASK[4], LWL_MASK[4], LWR_MASK[4]; -extern int32_t SWL_SHIFT[4], SWR_SHIFT[4], LWL_SHIFT[4], LWR_SHIFT[4]; -extern int32_t RoundingModel; diff --git a/src/usf/main.c b/src/usf/main.c deleted file mode 100644 index e065a45..0000000 --- a/src/usf/main.c +++ /dev/null @@ -1,41 +0,0 @@ - -#include -#include -#include -#include -#include -#include "usf.h" -#include "cpu.h" -#include "memory.h" - - -int InitalizeApplication ( void ) -{ - - return 1; -} - -void StopEmulation(void) -{ - //asm("int $3"); - //printf("Arrivederci!\n\n"); - //Release_Memory(); - //exit(0); - cpu_running = 0; -} - -void DisplayError (char * Message, ...) { - char Msg[1000]; - va_list ap; - - va_start( ap, Message ); - vsprintf( Msg, Message, ap ); - va_end( ap ); - - printf("Error: %s\n", Msg); -} - -void UsfSleep(int32_t time) -{ - usleep(time * 1000); -} diff --git a/src/usf/main.h b/src/usf/main.h deleted file mode 100644 index f2e75b7..0000000 --- a/src/usf/main.h +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#define CPU_Default -1 -#define CPU_Interpreter 0 -#define CPU_Recompiler 1 - -int InitalizeApplication ( void ); -void DisplayError (char * Message, ...); -void StopEmulation(void); -void UsfSleep(int32_t); diff --git a/src/usf/memory.c b/src/usf/memory.c deleted file mode 100644 index 0570bbb..0000000 --- a/src/usf/memory.c +++ /dev/null @@ -1,1890 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 -#include -#include -#include -#include -#include -#include - -#include - - -#include "main.h" -#include "cpu.h" -#include "x86.h" -#include "audio.h" -#include "rsp.h" -#include "usf.h" - -uintptr_t *TLB_Map = 0; -uint8_t * MemChunk = 0; -uint32_t RdramSize = 0x800000, SystemRdramSize = 0x800000, RomFileSize = 0x4000000; -uint8_t * N64MEM = 0, * RDRAM = 0, * DMEM = 0, * IMEM = 0, * ROMPages[0x400], * savestatespace = 0, * NOMEM = 0; -void ** JumpTable = 0, ** DelaySlotTable = 0; -uint8_t * RecompCode = 0, * RecompPos = 0; - -uint32_t WrittenToRom = 0; -uint32_t WroteToRom = 0; -uint32_t TempValue = 0; -uint32_t MemoryState = 0; - -uint8_t EmptySpace = 0; - -uint8_t * PageROM(uint32_t addr) { - return (ROMPages[addr/0x10000])?ROMPages[addr/0x10000]+(addr%0x10000):&EmptySpace; -} - -/* MAP_32BIT is needed to make this work on amd64. --nenolod. */ -#ifndef MAP_32BIT -# define MAP_32BIT (0) -#endif - -#define PAGE_SIZE 4096 -void *malloc_exec(uint32_t bytes) -{ - void *ptr = NULL; - - ptr = mmap(0,bytes,PROT_EXEC|PROT_READ|PROT_WRITE,MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, 0, 0); - - return ptr; - -} - - -int32_t Allocate_Memory ( void ) { - //RdramSize = 0x800000; - - // Allocate the N64MEM and TLB_Map so that they are in each others 4GB range - // Also put the registers there :) - - - // the mmap technique works craptacular when the regions don't overlay - - MemChunk = mmap(NULL, 0x100000 * sizeof(uintptr_t) + 0x1D000 + RdramSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - - TLB_Map = (uintptr_t*)MemChunk; - if (TLB_Map == NULL) { - return 0; - } - - memset(TLB_Map, 0, 0x100000 * sizeof(uintptr_t) + 0x10000); - - N64MEM = mmap((uintptr_t)MemChunk + 0x100000 * sizeof(uintptr_t) + 0x10000, 0xD000 + RdramSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); - if(N64MEM == NULL) { - DisplayError("Failed to allocate N64MEM"); - return 0; - } - - memset(N64MEM, 0, RdramSize); - - NOMEM = mmap((uintptr_t)N64MEM + RdramSize, 0xD000, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); - - if(RdramSize == 0x400000) - { - // munmap(N64MEM + 0x400000, 0x400000); - } - - Registers = (N64_REGISTERS *)((uintptr_t)MemChunk + 0x100000 * sizeof(uintptr_t)); - TLBLoadAddress = (uint32_t *)((uintptr_t)Registers + 0x500); - Timers = (SYSTEM_TIMERS*)(TLBLoadAddress + 4); - WaitMode = (uint32_t *)(Timers + sizeof(SYSTEM_TIMERS)); - CPU_Action = (CPU_ACTION *)(WaitMode + 4); - RSP_GPR = (REGISTER32 *)(CPU_Action + sizeof(CPU_ACTION)); - DMEM = (uint8_t *)(RSP_GPR + (32 * 8)); - RSP_ACCUM = (REGISTER *)(DMEM + 0x2000); - RSP_Vect = (VECTOR *)((char*)RSP_ACCUM + (sizeof(REGISTER)*32)); - - - if(!use_interpreter) { - JumpTable = (void **)malloc(0x200000 * sizeof(uintptr_t)); - - if( JumpTable == NULL ) - return 0; - - memset(JumpTable, 0, 0x200000 * sizeof(uintptr_t)); - - RecompCode = malloc_exec(NormalCompileBufferSize); - - memset(RecompCode, 0xcc, NormalCompileBufferSize); // fill with Breakpoints - - DelaySlotTable = (void **) malloc((0x1000000) >> 0xA); - if( DelaySlotTable == NULL ) - return 0; - - memset(DelaySlotTable, 0, ((0x1000000) >> 0xA)); - - } else { - JumpTable = NULL; - RecompCode = NULL; - DelaySlotTable = NULL; - } - RDRAM = (uint8_t *)(N64MEM); - IMEM = DMEM + 0x1000; - - MemoryState = 1; - - return 1; -} - -int PreAllocate_Memory(void) { - int i = 0; - - // Moved the savestate allocation here :) (for better management later) - savestatespace = malloc(0x80275C); - - if(savestatespace == 0) - return 0; - - memset(savestatespace, 0, 0x80275C); - - for (i = 0; i < 0x400; i++) { - ROMPages[i] = 0; - } - - return 1; -} - -void Release_Memory ( void ) { - uint32_t i; - - for (i = 0; i < 0x400; i++) { - if (ROMPages[i]) { - free(ROMPages[i]); ROMPages[i] = 0; - } - } - printf("Freeing memory\n"); - - MemoryState = 0; - - if (MemChunk != 0) {munmap(MemChunk, 0x100000 * sizeof(uintptr_t)) + 0x1D000 + RdramSize; MemChunk=0;} - if (N64MEM != 0) {munmap(N64MEM, RdramSize); N64MEM=0;} - if (NOMEM != 0) {munmap(NOMEM, 0xD000); NOMEM=0;} - - if (DelaySlotTable != NULL) {free( DelaySlotTable); DelaySlotTable=NULL;} - if (JumpTable != NULL) {free( JumpTable); JumpTable=NULL;} - if (RecompCode != NULL){munmap( RecompCode, NormalCompileBufferSize); RecompCode=NULL;} - if (RSPRecompCode != NULL){munmap( RSPRecompCode, RSP_RECOMPMEM_SIZE + RSP_SECRECOMPMEM_SIZE); RSPRecompCode=NULL;} - - if (RSPJumpTables != NULL) {free( RSPJumpTables); RSPJumpTables=NULL;} - if (JumpTable != NULL) {free( JumpTable); JumpTable=NULL;} - - - if(savestatespace) - free(savestatespace); - savestatespace = NULL; - -} - - - -void Compile_LB ( int32_t Reg, uint32_t addr, uint32_t SignExtend ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - MoveConstToX86reg(0,Reg); - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - case 0x10000000: - - if (SignExtend) { - MoveSxVariableToX86regByte(Addr + N64MEM,Reg); - } else { - MoveZxVariableToX86regByte(Addr + N64MEM,Reg); - } - break; - default: - MoveConstToX86reg(0,Reg); - } -} - -void Compile_LH ( int32_t Reg, uint32_t addr, uint32_t SignExtend) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - MoveConstToX86reg(0,Reg); - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - case 0x10000000: - - if (SignExtend) { - MoveSxVariableToX86regHalf(Addr + N64MEM,Reg); - } else { - MoveZxVariableToX86regHalf(Addr + N64MEM,Reg); - } - break; - default: - MoveConstToX86reg(0,Reg); - } -} - -void Compile_LW ( int32_t Reg, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - MoveConstToX86reg(0,Reg); - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - case 0x10000000: - MoveVariableToX86reg(Addr + N64MEM,Reg); - break; - case 0x04000000: - if (Addr < 0x04002000) { - MoveVariableToX86reg(Addr + N64MEM,Reg); - break; - } - switch (Addr) { - case 0x04040010: MoveVariableToX86reg(&SP_STATUS_REG,Reg); break; - case 0x04040014: MoveVariableToX86reg(&SP_DMA_FULL_REG,Reg); break; - case 0x04040018: MoveVariableToX86reg(&SP_DMA_BUSY_REG,Reg); break; - case 0x04080000: MoveVariableToX86reg(&SP_PC_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04100000: MoveVariableToX86reg(Addr + N64MEM,Reg); break; - case 0x04300000: - switch (Addr) { - case 0x04300000: MoveVariableToX86reg(&MI_MODE_REG,Reg); break; - case 0x04300004: MoveVariableToX86reg(&MI_VERSION_REG,Reg); break; - case 0x04300008: MoveVariableToX86reg(&MI_INTR_REG,Reg); break; - case 0x0430000C: MoveVariableToX86reg(&MI_INTR_MASK_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04400000: - switch (Addr) { - case 0x04400010: - Pushad(); - Call_Direct(&UpdateCurrentHalfLine); - Popad(); - MoveVariableToX86reg(&HalfLine,Reg); - break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04500000: /* AI registers */ - switch (Addr) { - case 0x04500004: - Pushad(); - Call_Direct(AiReadLength); - MoveX86regToVariable(x86_EAX,&TempValue); - Popad(); - MoveVariableToX86reg(&TempValue,Reg); - break; - case 0x0450000C: MoveVariableToX86reg(&AI_STATUS_REG,Reg); break; - case 0x04500010: MoveVariableToX86reg(&AI_DACRATE_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04600000: - switch (Addr) { - case 0x04600010: MoveVariableToX86reg(&PI_STATUS_REG,Reg); break; - case 0x04600014: MoveVariableToX86reg(&PI_DOMAIN1_REG,Reg); break; - case 0x04600018: MoveVariableToX86reg(&PI_BSD_DOM1_PWD_REG,Reg); break; - case 0x0460001C: MoveVariableToX86reg(&PI_BSD_DOM1_PGS_REG,Reg); break; - case 0x04600020: MoveVariableToX86reg(&PI_BSD_DOM1_RLS_REG,Reg); break; - case 0x04600024: MoveVariableToX86reg(&PI_DOMAIN2_REG,Reg); break; - case 0x04600028: MoveVariableToX86reg(&PI_BSD_DOM2_PWD_REG,Reg); break; - case 0x0460002C: MoveVariableToX86reg(&PI_BSD_DOM2_PGS_REG,Reg); break; - case 0x04600030: MoveVariableToX86reg(&PI_BSD_DOM2_RLS_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04700000: - switch (Addr) { - case 0x0470000C: MoveVariableToX86reg(&RI_SELECT_REG,Reg); break; - case 0x04700010: MoveVariableToX86reg(&RI_REFRESH_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x04800000: - switch (Addr) { - case 0x04800018: MoveVariableToX86reg(&SI_STATUS_REG,Reg); break; - default: MoveConstToX86reg(0,Reg); break; - } - break; - case 0x1FC00000: MoveVariableToX86reg(Addr + N64MEM,Reg); break; - default: MoveConstToX86reg(((Addr & 0xFFFF) << 16) | (Addr & 0xFFFF),Reg); - } -} - -void Compile_SB_Const ( uint8_t Value, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveConstByteToVariable(Value,Addr + N64MEM); - break; - } -} - -void Compile_SB_Register ( int32_t x86Reg, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveX86regByteToVariable(x86Reg,Addr + N64MEM); - break; - } -} - -void Compile_SH_Const ( uint16_t Value, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveConstHalfToVariable(Value,Addr + N64MEM); - break; - } -} - -void Compile_SH_Register ( int32_t x86Reg, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveX86regHalfToVariable(x86Reg,Addr + N64MEM); - break; - } -} - -void Compile_SW_Const ( uint32_t Value, uint32_t addr ) { - uintptr_t Addr = addr; - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveConstToVariable(Value,Addr + N64MEM); - break; - case 0x03F00000: - switch (Addr) { - case 0x03F00000: MoveConstToVariable(Value,&RDRAM_CONFIG_REG); break; - case 0x03F00004: MoveConstToVariable(Value,&RDRAM_DEVICE_ID_REG); break; - case 0x03F00008: MoveConstToVariable(Value,&RDRAM_DELAY_REG); break; - case 0x03F0000C: MoveConstToVariable(Value,&RDRAM_MODE_REG); break; - case 0x03F00010: MoveConstToVariable(Value,&RDRAM_REF_INTERVAL_REG); break; - case 0x03F00014: MoveConstToVariable(Value,&RDRAM_REF_ROW_REG); break; - case 0x03F00018: MoveConstToVariable(Value,&RDRAM_RAS_INTERVAL_REG); break; - case 0x03F0001C: MoveConstToVariable(Value,&RDRAM_MIN_INTERVAL_REG); break; - case 0x03F00020: MoveConstToVariable(Value,&RDRAM_ADDR_SELECT_REG); break; - case 0x03F00024: MoveConstToVariable(Value,&RDRAM_DEVICE_MANUF_REG); break; - case 0x03F04004: break; - case 0x03F08004: break; - case 0x03F80004: break; - case 0x03F80008: break; - case 0x03F8000C: break; - case 0x03F80014: break; - } - break; - case 0x04000000: - if (Addr < 0x04002000) { - MoveConstToVariable(Value,Addr + N64MEM); - break; - } - switch (Addr) { - case 0x04040000: MoveConstToVariable(Value,&SP_MEM_ADDR_REG); break; - case 0x04040004: MoveConstToVariable(Value,&SP_DRAM_ADDR_REG); break; - case 0x04040008: - MoveConstToVariable(Value,&SP_RD_LEN_REG); - Pushad(); - Call_Direct(&SP_DMA_READ); - Popad(); - break; - case 0x04040010: - { - uint32_t ModValue = 0; - if ( ( Value & SP_CLR_HALT ) != 0 ) { ModValue |= SP_STATUS_HALT; } - if ( ( Value & SP_CLR_BROKE ) != 0 ) { ModValue |= SP_STATUS_BROKE; } - if ( ( Value & SP_CLR_SSTEP ) != 0 ) { ModValue |= SP_STATUS_SSTEP; } - if ( ( Value & SP_CLR_INTR_BREAK ) != 0 ) { ModValue |= SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_CLR_SIG0 ) != 0 ) { ModValue |= SP_STATUS_SIG0; } - if ( ( Value & SP_CLR_SIG1 ) != 0 ) { ModValue |= SP_STATUS_SIG1; } - if ( ( Value & SP_CLR_SIG2 ) != 0 ) { ModValue |= SP_STATUS_SIG2; } - if ( ( Value & SP_CLR_SIG3 ) != 0 ) { ModValue |= SP_STATUS_SIG3; } - if ( ( Value & SP_CLR_SIG4 ) != 0 ) { ModValue |= SP_STATUS_SIG4; } - if ( ( Value & SP_CLR_SIG5 ) != 0 ) { ModValue |= SP_STATUS_SIG5; } - if ( ( Value & SP_CLR_SIG6 ) != 0 ) { ModValue |= SP_STATUS_SIG6; } - if ( ( Value & SP_CLR_SIG7 ) != 0 ) { ModValue |= SP_STATUS_SIG7; } - - if (ModValue != 0) { - AndConstToVariable(~ModValue,&SP_STATUS_REG); - } - - ModValue = 0; - if ( ( Value & SP_SET_HALT ) != 0 ) { ModValue |= SP_STATUS_HALT; } - if ( ( Value & SP_SET_SSTEP ) != 0 ) { ModValue |= SP_STATUS_SSTEP; } - if ( ( Value & SP_SET_INTR_BREAK ) != 0) { ModValue |= SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_SET_SIG0 ) != 0 ) { ModValue |= SP_STATUS_SIG0; } - if ( ( Value & SP_SET_SIG1 ) != 0 ) { ModValue |= SP_STATUS_SIG1; } - if ( ( Value & SP_SET_SIG2 ) != 0 ) { ModValue |= SP_STATUS_SIG2; } - if ( ( Value & SP_SET_SIG3 ) != 0 ) { ModValue |= SP_STATUS_SIG3; } - if ( ( Value & SP_SET_SIG4 ) != 0 ) { ModValue |= SP_STATUS_SIG4; } - if ( ( Value & SP_SET_SIG5 ) != 0 ) { ModValue |= SP_STATUS_SIG5; } - if ( ( Value & SP_SET_SIG6 ) != 0 ) { ModValue |= SP_STATUS_SIG6; } - if ( ( Value & SP_SET_SIG7 ) != 0 ) { ModValue |= SP_STATUS_SIG7; } - if (ModValue != 0) { - OrConstToVariable(ModValue,&SP_STATUS_REG); - } - - if ( ( Value & SP_CLR_INTR ) != 0) { - AndConstToVariable(~MI_INTR_SP,&MI_INTR_REG); - Pushad(); - Call_Direct(RunRsp); - Call_Direct(CheckInterrupts); - Popad(); - } else { - Pushad(); - Call_Direct(RunRsp); - Popad(); - } - } - break; - case 0x0404001C: MoveConstToVariable(0,&SP_SEMAPHORE_REG); break; - case 0x04080000: MoveConstToVariable(Value & 0xFFC,&SP_PC_REG); break; - } - break; - case 0x04300000: - switch (Addr) { - case 0x04300000: - { - uint32_t ModValue = 0x7F; - if ( ( Value & MI_CLR_INIT ) != 0 ) { ModValue |= MI_MODE_INIT; } - if ( ( Value & MI_CLR_EBUS ) != 0 ) { ModValue |= MI_MODE_EBUS; } - if ( ( Value & MI_CLR_RDRAM ) != 0 ) { ModValue |= MI_MODE_RDRAM; } - if (ModValue != 0) { - AndConstToVariable(~ModValue,&MI_MODE_REG); - } - - ModValue = (Value & 0x7F); - if ( ( Value & MI_SET_INIT ) != 0 ) { ModValue |= MI_MODE_INIT; } - if ( ( Value & MI_SET_EBUS ) != 0 ) { ModValue |= MI_MODE_EBUS; } - if ( ( Value & MI_SET_RDRAM ) != 0 ) { ModValue |= MI_MODE_RDRAM; } - if (ModValue != 0) { - OrConstToVariable(ModValue,&MI_MODE_REG); - } - if ( ( Value & MI_CLR_DP_INTR ) != 0 ) { - AndConstToVariable(~MI_INTR_DP,&MI_INTR_REG); - } - } - break; - case 0x0430000C: - { - uint32_t ModValue; - ModValue = 0; - if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) { ModValue |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) { ModValue |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) { ModValue |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) { ModValue |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) { ModValue |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) { ModValue |= MI_INTR_MASK_DP; } - if (ModValue != 0) { - AndConstToVariable(~ModValue,&MI_INTR_MASK_REG); - } - - ModValue = 0; - if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) { ModValue |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) { ModValue |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) { ModValue |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) { ModValue |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) { ModValue |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) { ModValue |= MI_INTR_MASK_DP; } - if (ModValue != 0) { - OrConstToVariable(ModValue,&MI_INTR_MASK_REG); - } - } - break; - } - break; - case 0x04400000: - switch (Addr) { - case 0x04400000: - MoveConstToVariable(Value,&VI_STATUS_REG); - break; - case 0x04400004: MoveConstToVariable((Value & 0xFFFFFF),&VI_ORIGIN_REG); break; - case 0x04400008: - MoveConstToVariable(Value,&VI_WIDTH_REG); - break; - case 0x0440000C: MoveConstToVariable(Value,&VI_INTR_REG); break; - case 0x04400010: - AndConstToVariable(~MI_INTR_VI,&MI_INTR_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - case 0x04400014: MoveConstToVariable(Value,&VI_BURST_REG); break; - case 0x04400018: MoveConstToVariable(Value,&VI_V_SYNC_REG); break; - case 0x0440001C: MoveConstToVariable(Value,&VI_H_SYNC_REG); break; - case 0x04400020: MoveConstToVariable(Value,&VI_LEAP_REG); break; - case 0x04400024: MoveConstToVariable(Value,&VI_H_START_REG); break; - case 0x04400028: MoveConstToVariable(Value,&VI_V_START_REG); break; - case 0x0440002C: MoveConstToVariable(Value,&VI_V_BURST_REG); break; - case 0x04400030: MoveConstToVariable(Value,&VI_X_SCALE_REG); break; - case 0x04400034: MoveConstToVariable(Value,&VI_Y_SCALE_REG); break; - } - break; - case 0x04500000: /* AI registers */ - switch (Addr) { - case 0x04500000: MoveConstToVariable(Value,&AI_DRAM_ADDR_REG); break; - case 0x04500004: - MoveConstToVariable(Value,&AI_LEN_REG); - Pushad(); - //Pushad(); - //PushImm32(Value); - Call_Direct(AiLenChanged); - //AddConstToX86Reg(x86_ESP,8); - - Popad(); - break; - case 0x04500008: MoveConstToVariable((Value & 1),&AI_CONTROL_REG); break; - case 0x0450000C: - /* Clear Interrupt */; - AndConstToVariable(~MI_INTR_AI,&MI_INTR_REG); - AndConstToVariable(~MI_INTR_AI,&AudioIntrReg); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - case 0x04500010: - Addr|=0xa0000000; - MoveConstToVariable(Value,Addr + N64MEM); - break; - case 0x04500014: MoveConstToVariable(Value,&AI_BITRATE_REG); break; - } - break; - case 0x04600000: - switch (Addr) { - case 0x04600000: MoveConstToVariable(Value,&PI_DRAM_ADDR_REG); break; - case 0x04600004: MoveConstToVariable(Value,&PI_CART_ADDR_REG); break; - case 0x04600008: - MoveConstToVariable(Value,&PI_RD_LEN_REG); - Pushad(); - Call_Direct(&PI_DMA_READ); - Popad(); - break; - case 0x0460000C: - MoveConstToVariable(Value,&PI_WR_LEN_REG); - Pushad(); - Call_Direct(&PI_DMA_WRITE); - Popad(); - break; - case 0x04600010: - if ((Value & PI_CLR_INTR) != 0 ) { - AndConstToVariable(~MI_INTR_PI,&MI_INTR_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - } - break; - case 0x04600014: MoveConstToVariable((Value & 0xFF),&PI_DOMAIN1_REG); break; - case 0x04600018: MoveConstToVariable((Value & 0xFF),&PI_BSD_DOM1_PWD_REG); break; - case 0x0460001C: MoveConstToVariable((Value & 0xFF),&PI_BSD_DOM1_PGS_REG); break; - case 0x04600020: MoveConstToVariable((Value & 0xFF),&PI_BSD_DOM1_RLS_REG); break; - } - break; - case 0x04700000: - switch (Addr) { - case 0x04700000: MoveConstToVariable(Value,&RI_MODE_REG); break; - case 0x04700004: MoveConstToVariable(Value,&RI_CONFIG_REG); break; - case 0x04700008: MoveConstToVariable(Value,&RI_CURRENT_LOAD_REG); break; - case 0x0470000C: MoveConstToVariable(Value,&RI_SELECT_REG); break; - } - break; - case 0x04800000: - switch (Addr) { - case 0x04800000: MoveConstToVariable(Value,&SI_DRAM_ADDR_REG); break; - case 0x04800004: - MoveConstToVariable(Value,&SI_PIF_ADDR_RD64B_REG); - Pushad(); - Call_Direct(&SI_DMA_READ); - Popad(); - break; - case 0x04800010: - MoveConstToVariable(Value,&SI_PIF_ADDR_WR64B_REG); - Pushad(); - Call_Direct(&SI_DMA_WRITE); - Popad(); - break; - case 0x04800018: - AndConstToVariable(~MI_INTR_SI,&MI_INTR_REG); - AndConstToVariable(~SI_STATUS_INTERRUPT,&SI_STATUS_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - } - break; - } -} - -void Compile_SW_Register ( int32_t x86Reg, uint32_t addr ) { - uintptr_t Addr = addr; - - - if (!TranslateVaddr(&Addr)) { - return; - } - - switch (Addr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - MoveX86regToVariable(x86Reg,Addr + N64MEM); - break; - case 0x04000000: - switch (Addr) { - case 0x04040000: MoveX86regToVariable(x86Reg,&SP_MEM_ADDR_REG); break; - case 0x04040004: MoveX86regToVariable(x86Reg,&SP_DRAM_ADDR_REG); break; - case 0x04040008: - MoveX86regToVariable(x86Reg,&SP_RD_LEN_REG); - Pushad(); - Call_Direct(&SP_DMA_READ); - Popad(); - break; - case 0x0404000C: - MoveX86regToVariable(x86Reg,&SP_WR_LEN_REG); - Pushad(); - Call_Direct(&SP_DMA_WRITE); - Popad(); - break; - case 0x04040010: - MoveX86regToVariable(x86Reg,&RegModValue); - Pushad(); - Call_Direct(ChangeSpStatus); - Popad(); - break; - case 0x0404001C: MoveConstToVariable(0,&SP_SEMAPHORE_REG); break; - case 0x04080000: - MoveX86regToVariable(x86Reg,&SP_PC_REG); - AndConstToVariable(0xFFC,&SP_PC_REG); - break; - default: - if (Addr < 0x04002000) - MoveX86regToVariable(x86Reg,Addr + N64MEM); - } - break; - case 0x04100000: - break; - //MoveX86regToVariable(x86Reg,Addr + N64MEM); - case 0x04300000: - switch (Addr) { - case 0x04300000: - MoveX86regToVariable(x86Reg,&RegModValue); - Pushad(); - Call_Direct(ChangeMiIntrMask); - Popad(); - break; - case 0x0430000C: - MoveX86regToVariable(x86Reg,&RegModValue); - Pushad(); - Call_Direct(ChangeMiIntrMask); - Popad(); - break; - } - break; - - case 0x04400000: - switch (Addr) { - case 0x04400000: - // inserted in place of compiled stuff - MoveX86regToVariable(x86Reg,&VI_STATUS_REG); - break; - case 0x04400004: - MoveX86regToVariable(x86Reg,&VI_ORIGIN_REG); - AndConstToVariable(0xFFFFFF,&VI_ORIGIN_REG); - break; - case 0x04400008: - // inserted in place of compiled stuff - MoveX86regToVariable(x86Reg,&VI_WIDTH_REG); - break; - case 0x0440000C: MoveX86regToVariable(x86Reg,&VI_INTR_REG); break; - case 0x04400010: - AndConstToVariable(~MI_INTR_VI,&MI_INTR_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - case 0x04400014: MoveX86regToVariable(x86Reg,&VI_BURST_REG); break; - case 0x04400018: MoveX86regToVariable(x86Reg,&VI_V_SYNC_REG); break; - case 0x0440001C: MoveX86regToVariable(x86Reg,&VI_H_SYNC_REG); break; - case 0x04400020: MoveX86regToVariable(x86Reg,&VI_LEAP_REG); break; - case 0x04400024: MoveX86regToVariable(x86Reg,&VI_H_START_REG); break; - case 0x04400028: MoveX86regToVariable(x86Reg,&VI_V_START_REG); break; - case 0x0440002C: MoveX86regToVariable(x86Reg,&VI_V_BURST_REG); break; - case 0x04400030: MoveX86regToVariable(x86Reg,&VI_X_SCALE_REG); break; - case 0x04400034: MoveX86regToVariable(x86Reg,&VI_Y_SCALE_REG); break; - } - break; - case 0x04500000: /* AI registers */ - switch (Addr) { - case 0x04500000: MoveX86regToVariable(x86Reg,&AI_DRAM_ADDR_REG); break; - case 0x04500004: - MoveX86regToVariable(x86Reg,&AI_LEN_REG); - Pushad(); - //MoveX86RegToX86Reg(x86_ESP, x86_EAX); - //AndConstToX86Reg(x86_EAX, 8); - //SubX86RegToX86Reg(x86_ESP,x86_EAX); - //Push(x86_EAX); - Call_Direct(AiLenChanged); - //Pop(x86_EAX); - //AddX86RegToX86Reg(x86_ESP,x86_EAX); - Popad(); - break; - case 0x04500008: - MoveX86regToVariable(x86Reg,&AI_CONTROL_REG); - AndConstToVariable(1,&AI_CONTROL_REG); - case 0x0450000C: - /* Clear Interrupt */; - AndConstToVariable(~MI_INTR_AI,&MI_INTR_REG); - AndConstToVariable(~MI_INTR_AI,&AudioIntrReg); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - case 0x04500010: - MoveX86regToVariable(x86Reg,Addr + N64MEM); - break; - default: - MoveX86regToVariable(x86Reg,Addr + N64MEM); - } - break; - case 0x04600000: - switch (Addr) { - case 0x04600000: MoveX86regToVariable(x86Reg,&PI_DRAM_ADDR_REG); break; - case 0x04600004: MoveX86regToVariable(x86Reg,&PI_CART_ADDR_REG); break; - case 0x04600008: - MoveX86regToVariable(x86Reg,&PI_RD_LEN_REG); - Pushad(); - Call_Direct(&PI_DMA_READ); - Popad(); - break; - case 0x0460000C: - MoveX86regToVariable(x86Reg,&PI_WR_LEN_REG); - Pushad(); - Call_Direct(&PI_DMA_WRITE); - Popad(); - break; - case 0x04600010: - AndConstToVariable(~MI_INTR_PI,&MI_INTR_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - MoveX86regToVariable(x86Reg,&VI_ORIGIN_REG); - AndConstToVariable(0xFFFFFF,&VI_ORIGIN_REG); - case 0x04600014: - MoveX86regToVariable(x86Reg,&PI_DOMAIN1_REG); - AndConstToVariable(0xFF,&PI_DOMAIN1_REG); - break; - case 0x04600018: - MoveX86regToVariable(x86Reg,&PI_BSD_DOM1_PWD_REG); - AndConstToVariable(0xFF,&PI_BSD_DOM1_PWD_REG); - break; - case 0x0460001C: - MoveX86regToVariable(x86Reg,&PI_BSD_DOM1_PGS_REG); - AndConstToVariable(0xFF,&PI_BSD_DOM1_PGS_REG); - break; - case 0x04600020: - MoveX86regToVariable(x86Reg,&PI_BSD_DOM1_RLS_REG); - AndConstToVariable(0xFF,&PI_BSD_DOM1_RLS_REG); - break; - } - break; - case 0x04700000: - switch (Addr) { - case 0x04700010: MoveX86regToVariable(x86Reg,&RI_REFRESH_REG); break; - } - break; - case 0x04800000: - switch (Addr) { - case 0x04800000: MoveX86regToVariable(x86Reg,&SI_DRAM_ADDR_REG); break; - case 0x04800004: - MoveX86regToVariable(x86Reg,&SI_PIF_ADDR_RD64B_REG); - Pushad(); - Call_Direct(&SI_DMA_READ); - Popad(); - break; - case 0x04800010: - MoveX86regToVariable(x86Reg,&SI_PIF_ADDR_WR64B_REG); - Pushad(); - Call_Direct(&SI_DMA_WRITE); - Popad(); - break; - case 0x04800018: - AndConstToVariable(~MI_INTR_SI,&MI_INTR_REG); - AndConstToVariable(~SI_STATUS_INTERRUPT,&SI_STATUS_REG); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - } - break; - case 0x1FC00000: - MoveX86regToVariable(x86Reg,Addr + N64MEM); - break; - } -} - -int32_t r4300i_LB_NonMemory ( uint32_t PAddr, uint32_t * Value, uint32_t SignExtend ) { - if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - if (WrittenToRom) { return 0; } - if ((PAddr & 2) == 0) { PAddr = (PAddr + 4) ^ 2; } - if ((PAddr - 0x10000000) < RomFileSize) { - if (SignExtend) { - *Value = (char)*PageROM((PAddr - 0x10000000)^3); - - } else { - *Value = *PageROM((PAddr - 0x10000000)^3); - } - return 1; - } else { - *Value = 0; - return 0; - } - } - - switch (PAddr & 0xFFF00000) { - default: - * Value = 0; - return 0; - break; - } - return 1; -} - -uint32_t r4300i_LB_VAddr ( uint32_t VAddr, uint8_t * Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *Value = *(uint8_t *)(TLB_Map[VAddr >> 12] + (VAddr ^ 3)); - return 1; -} - -uint32_t r4300i_LD_VAddr ( uint32_t VAddr, uint64_t * Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *((uint32_t *)(Value) + 1) = *(uint32_t *)(TLB_Map[VAddr >> 12] + VAddr); - *((uint32_t *)(Value)) = *(uint32_t *)(TLB_Map[VAddr >> 12] + VAddr + 4); - return 1; -} - -int32_t r4300i_LH_NonMemory ( uint32_t PAddr, uint32_t * Value, int32_t SignExtend ) { - switch (PAddr & 0xFFF00000) { - default: - * Value = 0; - return 0; - break; - } - return 1; -} - -uint32_t r4300i_LH_VAddr ( uint32_t VAddr, uint16_t * Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *Value = *(uint16_t *)(TLB_Map[VAddr >> 12] + (VAddr ^ 2)); - return 1; -} - -int32_t r4300i_LW_NonMemory ( uint32_t PAddr, uint32_t * Value ) { - if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - if (WrittenToRom) { - *Value = WroteToRom; - //LogMessage("%X: Read crap from Rom %X from %X",PROGRAM_COUNTER,*Value,PAddr); - WrittenToRom = 0; - return 1; - } - if ((PAddr - 0x10000000) < RomFileSize) { - *Value = *(uint32_t *)PageROM((PAddr - 0x10000000)); - return 1; - } else { - *Value = PAddr & 0xFFFF; - *Value = (*Value << 16) | *Value; - return 0; - } - } - - switch (PAddr & 0xFFF00000) { - case 0x03F00000: - switch (PAddr) { - case 0x03F00000: * Value = RDRAM_CONFIG_REG; break; - case 0x03F00004: * Value = RDRAM_DEVICE_ID_REG; break; - case 0x03F00008: * Value = RDRAM_DELAY_REG; break; - case 0x03F0000C: * Value = RDRAM_MODE_REG; break; - case 0x03F00010: * Value = RDRAM_REF_INTERVAL_REG; break; - case 0x03F00014: * Value = RDRAM_REF_ROW_REG; break; - case 0x03F00018: * Value = RDRAM_RAS_INTERVAL_REG; break; - case 0x03F0001C: * Value = RDRAM_MIN_INTERVAL_REG; break; - case 0x03F00020: * Value = RDRAM_ADDR_SELECT_REG; break; - case 0x03F00024: * Value = RDRAM_DEVICE_MANUF_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04000000: - switch (PAddr) { - case 0x04040010: *Value = SP_STATUS_REG; break; - case 0x04040014: *Value = SP_DMA_FULL_REG; break; - case 0x04040018: *Value = SP_DMA_BUSY_REG; break; - case 0x04080000: *Value = SP_PC_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04100000: - switch (PAddr) { - case 0x0410000C: *Value = DPC_STATUS_REG; break; - case 0x04100010: *Value = DPC_CLOCK_REG; break; - case 0x04100014: *Value = DPC_BUFBUSY_REG; break; - case 0x04100018: *Value = DPC_PIPEBUSY_REG; break; - case 0x0410001C: *Value = DPC_TMEM_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04300000: - switch (PAddr) { - case 0x04300000: * Value = MI_MODE_REG; break; - case 0x04300004: * Value = MI_VERSION_REG; break; - case 0x04300008: * Value = MI_INTR_REG; break; - case 0x0430000C: * Value = MI_INTR_MASK_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04400000: - switch (PAddr) { - case 0x04400000: *Value = VI_STATUS_REG; break; - case 0x04400004: *Value = VI_ORIGIN_REG; break; - case 0x04400008: *Value = VI_WIDTH_REG; break; - case 0x0440000C: *Value = VI_INTR_REG; break; - case 0x04400010: - *Value = 0; - break; - case 0x04400014: *Value = VI_BURST_REG; break; - case 0x04400018: *Value = VI_V_SYNC_REG; break; - case 0x0440001C: *Value = VI_H_SYNC_REG; break; - case 0x04400020: *Value = VI_LEAP_REG; break; - case 0x04400024: *Value = VI_H_START_REG; break; - case 0x04400028: *Value = VI_V_START_REG ; break; - case 0x0440002C: *Value = VI_V_BURST_REG; break; - case 0x04400030: *Value = VI_X_SCALE_REG; break; - case 0x04400034: *Value = VI_Y_SCALE_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04500000: - switch (PAddr) { - case 0x04500004: *Value = AiReadLength(); break; - case 0x0450000C: *Value = AI_STATUS_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04600000: - switch (PAddr) { - case 0x04600010: *Value = PI_STATUS_REG; break; - case 0x04600014: *Value = PI_DOMAIN1_REG; break; - case 0x04600018: *Value = PI_BSD_DOM1_PWD_REG; break; - case 0x0460001C: *Value = PI_BSD_DOM1_PGS_REG; break; - case 0x04600020: *Value = PI_BSD_DOM1_RLS_REG; break; - case 0x04600024: *Value = PI_DOMAIN2_REG; break; - case 0x04600028: *Value = PI_BSD_DOM2_PWD_REG; break; - case 0x0460002C: *Value = PI_BSD_DOM2_PGS_REG; break; - case 0x04600030: *Value = PI_BSD_DOM2_RLS_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04700000: - switch (PAddr) { - case 0x04700000: * Value = RI_MODE_REG; break; - case 0x04700004: * Value = RI_CONFIG_REG; break; - case 0x04700008: * Value = RI_CURRENT_LOAD_REG; break; - case 0x0470000C: * Value = RI_SELECT_REG; break; - case 0x04700010: * Value = RI_REFRESH_REG; break; - case 0x04700014: * Value = RI_LATENCY_REG; break; - case 0x04700018: * Value = RI_RERROR_REG; break; - case 0x0470001C: * Value = RI_WERROR_REG; break; - default: - * Value = 0; - return 0; - } - break; - case 0x04800000: - switch (PAddr) { - case 0x04800018: *Value = SI_STATUS_REG; break; - default: - *Value = 0; - return 0; - } - break; - case 0x05000000: - *Value = PAddr & 0xFFFF; - *Value = (*Value << 16) | *Value; - return 0; - case 0x08000000: - *Value = 0; - break; - default: - *Value = PAddr & 0xFFFF; - *Value = (*Value << 16) | *Value; - return 0; - break; - } - return 1; -} - -void r4300i_LW_PAddr ( uint32_t PAddr, uint32_t * Value ) { - *Value = *(uint32_t *)(N64MEM+PAddr); -} - -uint32_t r4300i_LW_VAddr ( uint32_t VAddr, uint32_t * Value ) { - uintptr_t address = (TLB_Map[VAddr >> 12] + VAddr); - - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - - if((address - (uintptr_t)RDRAM) > RdramSize) { - address = address - (uintptr_t)RDRAM; - return r4300i_LW_NonMemory(address, Value); - } - *Value = *(uint32_t *)address; - return 1; -} - -int32_t r4300i_SB_NonMemory ( uint32_t PAddr, uint8_t Value ) { - switch (PAddr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - if (PAddr < RdramSize) { - - *(uint8_t *)(N64MEM+PAddr) = Value; - if (N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] == 0) { break; } - N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] = 0; - memset(JumpTable+((PAddr & 0xFFFFF000) >> 2),0,0x1000); - *(DelaySlotTable + ((PAddr & 0xFFFFF000) >> 12)) = NULL; - } - break; - default: - return 0; - break; - } - return 1; -} - -uint32_t r4300i_SB_VAddr ( uint32_t VAddr, uint8_t Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *(uint8_t *)(TLB_Map[VAddr >> 12] + (VAddr ^ 3)) = Value; - - return 1; -} - -int32_t r4300i_SH_NonMemory ( uint32_t PAddr, uint16_t Value ) { - switch (PAddr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - if (PAddr < RdramSize) { - *(uint16_t *)(N64MEM+PAddr) = Value; - if (N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] == 0) { break; } - N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] = 0; - memset(JumpTable+((PAddr & 0xFFFFF000) >> 2),0,0x1000); - *(DelaySlotTable + ((PAddr & 0xFFFFF000) >> 12)) = NULL; - } - break; - default: - return 0; - break; - } - return 1; -} - -uint32_t r4300i_SD_VAddr ( uint32_t VAddr, uint64_t Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *(uint32_t *)(TLB_Map[VAddr >> 12] + VAddr) = *((uint32_t *)(&Value) + 1); - *(uint32_t *)(TLB_Map[VAddr >> 12] + VAddr + 4) = *((uint32_t *)(&Value)); - return 1; -} - -uint32_t r4300i_SH_VAddr ( uint32_t VAddr, uint16_t Value ) { - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - *(uint16_t *)(TLB_Map[VAddr >> 12] + (VAddr ^ 2)) = Value; - return 1; -} - -int32_t r4300i_SW_NonMemory ( uint32_t PAddr, uint32_t Value ) { - if (PAddr >= 0x10000000 && PAddr < 0x16000000) { - if ((PAddr - 0x10000000) < RomFileSize) { - WrittenToRom = 1; - WroteToRom = Value; - } else { - return 0; - } - } - - switch (PAddr & 0xFFF00000) { - case 0x00000000: - case 0x00100000: - case 0x00200000: - case 0x00300000: - case 0x00400000: - case 0x00500000: - case 0x00600000: - case 0x00700000: - if (PAddr < RdramSize) { - *(uint32_t *)(N64MEM+PAddr) = Value; - if (N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] == 0) { break; } - N64_Blocks.NoOfRDRamBlocks[(PAddr & 0x00FFFFF0) >> 12] = 0; - memset(JumpTable+((PAddr & 0xFFFFF000) >> 2),0,0x1000); - *(DelaySlotTable + ((PAddr & 0xFFFFF000) >> 12)) = NULL; - } - break; - case 0x03F00000: - switch (PAddr) { - case 0x03F00000: RDRAM_CONFIG_REG = Value; break; - case 0x03F00004: RDRAM_DEVICE_ID_REG = Value; break; - case 0x03F00008: RDRAM_DELAY_REG = Value; break; - case 0x03F0000C: RDRAM_MODE_REG = Value; break; - case 0x03F00010: RDRAM_REF_INTERVAL_REG = Value; break; - case 0x03F00014: RDRAM_REF_ROW_REG = Value; break; - case 0x03F00018: RDRAM_RAS_INTERVAL_REG = Value; break; - case 0x03F0001C: RDRAM_MIN_INTERVAL_REG = Value; break; - case 0x03F00020: RDRAM_ADDR_SELECT_REG = Value; break; - case 0x03F00024: RDRAM_DEVICE_MANUF_REG = Value; break; - case 0x03F04004: break; - case 0x03F08004: break; - case 0x03F80004: break; - case 0x03F80008: break; - case 0x03F8000C: break; - case 0x03F80014: break; - default: - return 0; - } - break; - case 0x04000000: - if (PAddr < 0x04002000) { - *(uint32_t *)(N64MEM+PAddr) = Value; - if (PAddr < 0x04001000) { - if (N64_Blocks.NoOfDMEMBlocks == 0) { break; } - N64_Blocks.NoOfDMEMBlocks = 0; - } else { - if (N64_Blocks.NoOfIMEMBlocks == 0) { break; } - N64_Blocks.NoOfIMEMBlocks = 0; - } - memset(JumpTable+((PAddr & 0xFFFFF000) >> 2),0,0x1000); - *(DelaySlotTable + ((PAddr & 0xFFFFF000) >> 12)) = NULL; - return 1; - } - switch (PAddr) { - case 0x04040000: SP_MEM_ADDR_REG = Value; break; - case 0x04040004: SP_DRAM_ADDR_REG = Value; break; - case 0x04040008: - SP_RD_LEN_REG = Value; - SP_DMA_READ(); - break; - case 0x0404000C: - SP_WR_LEN_REG = Value; - SP_DMA_WRITE(); - break; - case 0x04040010: - if ( ( Value & SP_CLR_HALT ) != 0) { SP_STATUS_REG &= ~SP_STATUS_HALT; } - if ( ( Value & SP_SET_HALT ) != 0) { SP_STATUS_REG |= SP_STATUS_HALT; } - if ( ( Value & SP_CLR_BROKE ) != 0) { SP_STATUS_REG &= ~SP_STATUS_BROKE; } - if ( ( Value & SP_CLR_INTR ) != 0) { - MI_INTR_REG &= ~MI_INTR_SP; - CheckInterrupts(); - } - if ( ( Value & SP_CLR_SSTEP ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SSTEP; } - if ( ( Value & SP_SET_SSTEP ) != 0) { SP_STATUS_REG |= SP_STATUS_SSTEP; } - if ( ( Value & SP_CLR_INTR_BREAK ) != 0) { SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_SET_INTR_BREAK ) != 0) { SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } - if ( ( Value & SP_CLR_SIG0 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG0; } - if ( ( Value & SP_SET_SIG0 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG0; } - if ( ( Value & SP_CLR_SIG1 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG1; } - if ( ( Value & SP_SET_SIG1 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG1; } - if ( ( Value & SP_CLR_SIG2 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG2; } - if ( ( Value & SP_SET_SIG2 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG2; } - if ( ( Value & SP_CLR_SIG3 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG3; } - if ( ( Value & SP_SET_SIG3 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG3; } - if ( ( Value & SP_CLR_SIG4 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG4; } - if ( ( Value & SP_SET_SIG4 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG4; } - if ( ( Value & SP_CLR_SIG5 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG5; } - if ( ( Value & SP_SET_SIG5 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG5; } - if ( ( Value & SP_CLR_SIG6 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG6; } - if ( ( Value & SP_SET_SIG6 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG6; } - if ( ( Value & SP_CLR_SIG7 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG7; } - if ( ( Value & SP_SET_SIG7 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG7; } - - RunRsp(); - - break; - case 0x0404001C: SP_SEMAPHORE_REG = 0; break; - case 0x04080000: SP_PC_REG = Value & 0xFFC; break; - default: - return 0; - } - break; - case 0x04100000: - switch (PAddr) { - case 0x04100000: - DPC_START_REG = Value; - DPC_CURRENT_REG = Value; - break; - case 0x04100004: - DPC_END_REG = Value; - //if (ProcessRDPList) { ProcessRDPList(); } - break; - case 0x04100008: DPC_CURRENT_REG = Value; break; - case 0x0410000C: - if ( ( Value & DPC_CLR_XBUS_DMEM_DMA ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( Value & DPC_SET_XBUS_DMEM_DMA ) != 0) { DPC_STATUS_REG |= DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( Value & DPC_CLR_FREEZE ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_FREEZE; } - if ( ( Value & DPC_SET_FREEZE ) != 0) { DPC_STATUS_REG |= DPC_STATUS_FREEZE; } - if ( ( Value & DPC_CLR_FLUSH ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_FLUSH; } - if ( ( Value & DPC_SET_FLUSH ) != 0) { DPC_STATUS_REG |= DPC_STATUS_FLUSH; } - if ( ( Value & DPC_CLR_FREEZE ) != 0) - { - if ( ( SP_STATUS_REG & SP_STATUS_HALT ) == 0) - { - if ( ( SP_STATUS_REG & SP_STATUS_BROKE ) == 0 ) - { - RunRsp(); - } - } - } - break; - default: - return 0; - } - break; - case 0x04300000: - switch (PAddr) { - case 0x04300000: - MI_MODE_REG &= ~0x7F; - MI_MODE_REG |= (Value & 0x7F); - if ( ( Value & MI_CLR_INIT ) != 0 ) { MI_MODE_REG &= ~MI_MODE_INIT; } - if ( ( Value & MI_SET_INIT ) != 0 ) { MI_MODE_REG |= MI_MODE_INIT; } - if ( ( Value & MI_CLR_EBUS ) != 0 ) { MI_MODE_REG &= ~MI_MODE_EBUS; } - if ( ( Value & MI_SET_EBUS ) != 0 ) { MI_MODE_REG |= MI_MODE_EBUS; } - if ( ( Value & MI_CLR_DP_INTR ) != 0 ) { - MI_INTR_REG &= ~MI_INTR_DP; - CheckInterrupts(); - } - if ( ( Value & MI_CLR_RDRAM ) != 0 ) { MI_MODE_REG &= ~MI_MODE_RDRAM; } - if ( ( Value & MI_SET_RDRAM ) != 0 ) { MI_MODE_REG |= MI_MODE_RDRAM; } - break; - case 0x0430000C: - if ( ( Value & MI_INTR_MASK_CLR_SP ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_SET_SP ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_SP; } - if ( ( Value & MI_INTR_MASK_CLR_SI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_SET_SI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_SI; } - if ( ( Value & MI_INTR_MASK_CLR_AI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_SET_AI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_AI; } - if ( ( Value & MI_INTR_MASK_CLR_VI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_SET_VI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_VI; } - if ( ( Value & MI_INTR_MASK_CLR_PI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_SET_PI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_PI; } - if ( ( Value & MI_INTR_MASK_CLR_DP ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; } - if ( ( Value & MI_INTR_MASK_SET_DP ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_DP; } - break; - default: - return 0; - } - break; - case 0x04400000: - switch (PAddr) { - case 0x04400000: - //if (VI_STATUS_REG != Value) { - VI_STATUS_REG = Value; - // if (ViStatusChanged != NULL ) { ViStatusChanged(); } - //} - break; - case 0x04400004: - - VI_ORIGIN_REG = (Value & 0xFFFFFF); - //if (UpdateScreen != NULL ) { UpdateScreen(); } - break; - case 0x04400008: - //if (VI_WIDTH_REG != Value) { - VI_WIDTH_REG = Value; - // if (ViWidthChanged != NULL ) { ViWidthChanged(); } - //} - break; - case 0x0440000C: VI_INTR_REG = Value; break; - case 0x04400010: - MI_INTR_REG &= ~MI_INTR_VI; - CheckInterrupts(); - break; - case 0x04400014: VI_BURST_REG = Value; break; - case 0x04400018: VI_V_SYNC_REG = Value; break; - case 0x0440001C: VI_H_SYNC_REG = Value; break; - case 0x04400020: VI_LEAP_REG = Value; break; - case 0x04400024: VI_H_START_REG = Value; break; - case 0x04400028: VI_V_START_REG = Value; break; - case 0x0440002C: VI_V_BURST_REG = Value; break; - case 0x04400030: VI_X_SCALE_REG = Value; break; - case 0x04400034: VI_Y_SCALE_REG = Value; break; - default: - return 0; - } - break; - case 0x04500000: - switch (PAddr) { - case 0x04500000: AI_DRAM_ADDR_REG = Value; break; - case 0x04500004: - AI_LEN_REG = Value; - if (AiLenChanged != NULL) { AiLenChanged(); } - break; - case 0x04500008: AI_CONTROL_REG = (Value & 0x1); break; - case 0x0450000C: - /* Clear Interrupt */; - MI_INTR_REG &= ~MI_INTR_AI; - AudioIntrReg &= ~MI_INTR_AI; - CheckInterrupts(); - break; - case 0x04500010: - AI_DACRATE_REG = Value; - //if (AiDacrateChanged != NULL) { AiDacrateChanged(SYSTEM_NTSC); } - break; - case 0x04500014: AI_BITRATE_REG = Value; break; - default: - return 0; - } - break; - case 0x04600000: - switch (PAddr) { - case 0x04600000: PI_DRAM_ADDR_REG = Value; break; - case 0x04600004: PI_CART_ADDR_REG = Value; break; - case 0x04600008: - PI_RD_LEN_REG = Value; - PI_DMA_READ(); - break; - case 0x0460000C: - PI_WR_LEN_REG = Value; - PI_DMA_WRITE(); - break; - case 0x04600010: - //if ((Value & PI_SET_RESET) != 0 ) { DisplayError("reset Controller"); } - if ((Value & PI_CLR_INTR) != 0 ) { - MI_INTR_REG &= ~MI_INTR_PI; - CheckInterrupts(); - } - break; - case 0x04600014: PI_DOMAIN1_REG = (Value & 0xFF); break; - case 0x04600018: PI_BSD_DOM1_PWD_REG = (Value & 0xFF); break; - case 0x0460001C: PI_BSD_DOM1_PGS_REG = (Value & 0xFF); break; - case 0x04600020: PI_BSD_DOM1_RLS_REG = (Value & 0xFF); break; - default: - return 0; - } - break; - case 0x04700000: - switch (PAddr) { - case 0x04700000: RI_MODE_REG = Value; break; - case 0x04700004: RI_CONFIG_REG = Value; break; - case 0x04700008: RI_CURRENT_LOAD_REG = Value; break; - case 0x0470000C: RI_SELECT_REG = Value; break; - case 0x04700010: RI_REFRESH_REG = Value; break; - case 0x04700014: RI_LATENCY_REG = Value; break; - case 0x04700018: RI_RERROR_REG = Value; break; - case 0x0470001C: RI_WERROR_REG = Value; break; - default: - return 0; - } - break; - case 0x04800000: - switch (PAddr) { - case 0x04800000: SI_DRAM_ADDR_REG = Value; break; - case 0x04800004: - SI_PIF_ADDR_RD64B_REG = Value; - SI_DMA_READ (); - break; - case 0x04800010: - SI_PIF_ADDR_WR64B_REG = Value; - SI_DMA_WRITE(); - break; - case 0x04800018: - MI_INTR_REG &= ~MI_INTR_SI; - SI_STATUS_REG &= ~SI_STATUS_INTERRUPT; - CheckInterrupts(); - break; - default: - return 0; - } - break; - case 0x08000000: - if (PAddr != 0x08010000) { return 0; } - //WriteToFlashCommand(Value); - break; - case 0x1FC00000: - if (PAddr < 0x1FC007C0) { - return 0; - } else if (PAddr < 0x1FC00800) { - - if (PAddr == 0x1FC007FC) { - PifRamWrite(); - } - return 1; - } - return 0; - break; - default: - return 0; - break; - } - return 1; -} - -uint32_t r4300i_SW_VAddr ( uint32_t VAddr, uint32_t Value ) { - uintptr_t address = (TLB_Map[VAddr >> 12] + VAddr); - - if (TLB_Map[VAddr >> 12] == 0) { return 0; } - - if((address - (uintptr_t)RDRAM) > RdramSize) { - address = address - (uintptr_t)RDRAM; - return r4300i_SW_NonMemory(address, Value); - } - *(uint32_t *)address = Value; - return 1; -} - -void ResetRecompCode (void) { - uint32_t count; - RecompPos = RecompCode; - TargetIndex = 0; - - //Jump Table - for (count = 0; count < (RdramSize >> 12); count ++ ) { - if (N64_Blocks.NoOfRDRamBlocks[count] > 0) { - N64_Blocks.NoOfRDRamBlocks[count] = 0; - memset(JumpTable + (count << 10),0,0x1000); - *(DelaySlotTable + count) = NULL; - - } - } - - if (N64_Blocks.NoOfDMEMBlocks > 0) { - N64_Blocks.NoOfDMEMBlocks = 0; - memset(JumpTable + (0x04000000 >> 2),0,0x1000); - *(DelaySlotTable + (0x04000000 >> 12)) = NULL; - } - if (N64_Blocks.NoOfIMEMBlocks > 0) { - N64_Blocks.NoOfIMEMBlocks = 0; - memset(JumpTable + (0x04001000 >> 2),0,0x1000); - *(DelaySlotTable + (0x04001000 >> 12)) = NULL; - } -} - -#ifndef __USE_GNU -#define __USE_GNU -#endif -#include - -static struct sigaction act; -static struct sigaction oact; -static sigset_t sset; -void sig_handler(int signo, siginfo_t * info, ucontext_t * context); - -void InitExceptionHandler() { - - sigset_t blockset; - - sigemptyset(&blockset); - sigaddset(&blockset, SIGSEGV); - - pthread_sigmask(SIG_UNBLOCK, &blockset, NULL); - - sigemptyset(&sset); - sigaddset(&sset, SIGSEGV); - - act.sa_flags = SA_SIGINFO ; - act.sa_mask = sset; - act.sa_sigaction = (void (*)(int, siginfo_t*, void*)) sig_handler; - - if(sigaction(SIGSEGV, (const struct sigaction *) &act, &oact)) - printf("error setting up exception handler\n"); -} - -int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context); - -void sig_handler(int signo, siginfo_t * info, ucontext_t * context) -{ - int i = 0; - - if(signo==SIGSEGV) { - uintptr_t MemAddress = ((char *)info->si_addr - (char *)N64MEM); - - /* - A Hack to fix some crappy GCC thing when R15 gets overwritten. - R15 should _never_ be overwritten. >:( - */ -#ifdef USEX64 - if(context->uc_mcontext.gregs[REG_R15] != (uintptr_t)TLB_Map) { - context->uc_mcontext.gregs[REG_R15] = (uintptr_t)TLB_Map; - return; - } -#endif - i = r4300i_CPU_MemoryFilter64_2(MemAddress,context); - if(i==0) - return; - } - - return; -} - -static int32_t CONV_REG64(int32_t dest_reg) { - switch(dest_reg) { - case 0: return 13; break; - case 1: return 14; break; - case 2: return 12; break; - case 3: return 11; break; - case 6: return 9; break; - case 7: return 8; break; - case 8: return 0; break; - case 9: return 1; break; - case 10: return 2; break; - case 11: return 3; break; - case 12: return 4; break; - case 13: return 5; break; - case 14: return 6; break; - case 15: return 7; break; - default: - asm("int $3"); - - break; - } -} - - -#ifdef __LP64__ -int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context) { - uint8_t * ip = context->uc_mcontext.gregs[REG_RIP]; - - if(MemAddress == 0) { - return 1; - } - - if((*ip & 0x40) && (*(ip+1) == 0xf) && (*(ip+2) == 0xb7)) { - uint8_t dest_reg = (*(ip+3) % 0x40) / 8; - int32_t half = 0; - if(*ip & 4) dest_reg += 8; - r4300i_LH_NonMemory(MemAddress, &half, 1); - - context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = (int32_t)half; - - - context->uc_mcontext.gregs[REG_RIP]+=4; - - if((*(ip+3) & 0x7)==4) - context->uc_mcontext.gregs[REG_RIP]++; - - if((*(ip+3) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_RIP]+=4; - else if((*(ip+3) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_RIP]+=1; - - return 0; - - } else if((*ip & 0x40) && (*(ip+1) ==0x89)) { // MOV [Rxx + Rxx], Exx - uint8_t dest_reg = (*(ip+2) % 0x40) / 8; - uint64_t dest = 0; - - if(*ip & 4) dest_reg += 8; - - dest = context->uc_mcontext.gregs[CONV_REG64(dest_reg)]; - - r4300i_SW_NonMemory(MemAddress, dest); - - if((*(ip+2) & 0x7)==4) - context->uc_mcontext.gregs[REG_RIP]+=4; - else - context->uc_mcontext.gregs[REG_RIP]+=3; - - if((*(ip+2) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_RIP]+=4; - else if((*(ip+2) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_RIP]+=1; - - return 0; - - } else if((*ip & 0x40) && (*(ip+1) ==0xC7)) { // MOV [Rxx + Rxx], Imm32 - uint32_t imm32 = *(uint32_t*)(ip+4); - r4300i_SW_NonMemory(MemAddress, imm32); - context->uc_mcontext.gregs[REG_RIP]+=7; - - // 40 C7 04 07 0F 00 00 00 - - //if(*(ip+2)&0x4) - if((*(ip+2) & 0x7)==4) - context->uc_mcontext.gregs[REG_RIP]++; - if((*(ip+2) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_RIP]+=4; - else if((*(ip+2) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_RIP]+=1; - - return 0; - } else if ((*ip & 0x40) && (*(ip + 1) == 0x8B )) { - uint8_t dest_reg = (*(ip+2) % 0x40) / 8; - uint32_t word = 0; - - //41 8B BF 30 D0 00 01 - - if(*ip & 4) dest_reg += 8; - - - r4300i_LW_NonMemory(MemAddress, &word); - context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = word; - - //if(*(ip+2) & 0x4) - if((*(ip+2) & 0x7)==4) - context->uc_mcontext.gregs[REG_RIP]+=4; - else - context->uc_mcontext.gregs[REG_RIP]+=3; - - if((*(ip+2) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_RIP]+=4; - else if((*(ip+2) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_RIP]+=1; - - - return 0; - - } - - //asm("int $3"); - return 1; -} - -#else - -static int32_t CONV_REG(int32_t dest_reg) { - switch(dest_reg) { - case 0: return 5; break; - case 1: return 4; break; - case 2: return 3; break; - case 3: return 2; break; - case 6: return 1; break; - case 7: return 0; break; - default: - asm volatile("int $3"); - break; - } -} - -int r4300i_CPU_MemoryFilter64_2( uintptr_t MemAddress, ucontext_t * context) { - uint8_t * ip = context->uc_mcontext.gregs[REG_EIP]; - - if(MemAddress == 0) { - return 1; - } - - if((*(ip) == 0xf) && (*(ip+1) == 0xb7)) { - uint8_t dest_reg = (*(ip+2) % 0x40) / 8; - int32_t half = 0; - r4300i_LH_NonMemory(MemAddress, &half, 1); - - //((uint32_t*)(&lpEP->ContextRecord->Edi))[CONV_REG(dest_reg)] = (int32_t)half; - context->uc_mcontext.gregs[CONV_REG64(dest_reg)] = (int32_t)half; - - context->uc_mcontext.gregs[REG_EIP]+=3; - - if((*(ip+2) & 0x7)==4) - context->uc_mcontext.gregs[REG_EIP]++; - else if((*(ip+1) & 0x7)==5) - context->uc_mcontext.gregs[REG_EIP]+=4; - - - if((*(ip+2) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_EIP]+=4; - else if((*(ip+2) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_EIP]+=1; - - return 0; - - } else if((*(ip) ==0x89)) { // MOV [Rxx + Rxx], Exx - uint8_t dest_reg = (*(ip+1) % 0x40) / 8; - uint32_t dest = 0; - - dest = context->uc_mcontext.gregs[CONV_REG64(dest_reg)]; - - r4300i_SW_NonMemory(MemAddress, dest); - - if((*(ip+1) & 0x7)==4) - context->uc_mcontext.gregs[REG_EIP]+=3; - else - context->uc_mcontext.gregs[REG_EIP]+=2; - - if((*(ip+1) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_EIP]+=4; - else if((*(ip+1) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_EIP]+=1; - - return 0; - - } else if((*(ip) ==0xC7)) { // MOV [Rxx + Rxx], Imm32 - uint32_t imm32 = *(uint32_t*)(ip+2); - r4300i_SW_NonMemory(MemAddress, imm32); - context->uc_mcontext.gregs[REG_EIP]+=6; - - - // 40 C7 04 07 0F 00 00 00 - - //if(*(ip+2)&0x4) - if((*(ip+1) & 0x7)==4) - context->uc_mcontext.gregs[REG_EIP]++; - if((*(ip+1) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_EIP]+=4; - else if((*(ip+1) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_EIP]+=1; - - return 0; - } else if (*ip == 0x8B ) { - uint8_t dest_reg = CONV_REG((*(ip+1) % 0x40) / 8); - uint32_t word = 0; - uint32_t *dest = 0; - - dest = context->uc_mcontext.gregs[CONV_REG64(dest_reg)]; - r4300i_LW_NonMemory(MemAddress, &word); - *dest = word; - //*dest = 0; - //if(*(ip+2) & 0x4) - if((*(ip+1) & 0x7)==4) - context->uc_mcontext.gregs[REG_EIP]+=3; - else if((*(ip+1) & 0x7)==5) - context->uc_mcontext.gregs[REG_EIP]+=6; - else - context->uc_mcontext.gregs[REG_EIP]+=2; - - if((*(ip+1) & 0xC0) == 0x80) - context->uc_mcontext.gregs[REG_EIP]+=4; - else if((*(ip+1) & 0xC0) == 0x40) - context->uc_mcontext.gregs[REG_EIP]+=1; - - - return 0; - - } - - return 1; - -} - - -#endif diff --git a/src/usf/memory.h b/src/usf/memory.h deleted file mode 100644 index de6952a..0000000 --- a/src/usf/memory.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#define LargeCompileBufferSize 0x03200000 -#define NormalCompileBufferSize 0x01500000 - -#define RSP_RECOMPMEM_SIZE 0x400000 -#define RSP_SECRECOMPMEM_SIZE 0x200000 - -#define ROM_IN_MAPSPACE - -extern uint32_t RdramSize, SystemRdramSize, RomFileSize; -extern uintptr_t *TLB_Map; -extern uint8_t * MemChunk; - -extern uint8_t *N64MEM, *RDRAM, *DMEM, *IMEM, * ROMPages[0x400], *savestatespace, * NOMEM; -extern void ** JumpTable, ** DelaySlotTable; -extern uint8_t *RecompCode, *RecompPos; -extern uint32_t WrittenToRom, MemoryState; - -/* Memory Control */ -int Allocate_ROM ( void ); -int Allocate_Memory ( void ); -void Release_Memory ( void ); -int PreAllocate_Memory(void); - -void *malloc_exec(uint32_t bytes); -void *jmalloc(uint32_t bytes); - -/* CPU memory functions */ -//int r4300i_Command_MemoryFilter ( uint32_t dwExptCode, LPEXCEPTION_POINTERS lpEP ); -//int r4300i_CPU_MemoryFilter ( uint32_t dwExptCode, LPEXCEPTION_POINTERS lpEP ); -int32_t r4300i_LB_NonMemory ( uint32_t PAddr, uint32_t * Value, uint32_t SignExtend ); -uint32_t r4300i_LB_VAddr ( uint32_t VAddr, uint8_t * Value ); -uint32_t r4300i_LD_VAddr ( uint32_t VAddr, uint64_t * Value ); -int32_t r4300i_LH_NonMemory ( uint32_t PAddr, uint32_t * Value, int32_t SignExtend ); -uint32_t r4300i_LH_VAddr ( uint32_t VAddr, uint16_t * Value ); -int32_t r4300i_LW_NonMemory ( uint32_t PAddr, uint32_t * Value ); -void r4300i_LW_PAddr ( uint32_t PAddr, uint32_t * Value ); -uint32_t r4300i_LW_VAddr ( uint32_t VAddr, uint32_t * Value ); -int32_t r4300i_SB_NonMemory ( uint32_t PAddr, uint8_t Value ); -uint32_t r4300i_SB_VAddr ( uint32_t VAddr, uint8_t Value ); -uint32_t r4300i_SD_VAddr ( uint32_t VAddr, uint64_t Value ); -int32_t r4300i_SH_NonMemory ( uint32_t PAddr, uint16_t Value ); -uint32_t r4300i_SH_VAddr ( uint32_t VAddr, uint16_t Value ); -int32_t r4300i_SW_NonMemory ( uint32_t PAddr, uint32_t Value ); -uint32_t r4300i_SW_VAddr ( uint32_t VAddr, uint32_t Value ); - -/* Recompiler Memory Functions */ -void Compile_LB ( int32_t Reg, uint32_t Addr, uint32_t SignExtend ); -void Compile_LH ( int32_t Reg, uint32_t Addr, uint32_t SignExtend ); -void Compile_LW ( int32_t Reg, uint32_t Addr ); -void Compile_SB_Const ( uint8_t Value, uint32_t Addr ); -void Compile_SB_Register ( int32_t x86Reg, uint32_t Addr ); -void Compile_SH_Const ( uint16_t Value, uint32_t Addr ); -void Compile_SH_Register ( int32_t x86Reg, uint32_t Addr ); -void Compile_SW_Const ( uint32_t Value, uint32_t Addr ); -void Compile_SW_Register ( int32_t x86Reg, uint32_t Addr ); -void ResetRecompCode ( void ); -void InitExceptionHandler (); - -uint8_t * PageROM(uint32_t addr); diff --git a/src/usf/opcode.h b/src/usf/opcode.h deleted file mode 100644 index cf2fe39..0000000 --- a/src/usf/opcode.h +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#ifndef __OpCode -#define __OpCode - -#include "types.h" - -typedef struct { - union { - - uint32_t Hex; - uint8_t Ascii[4]; - - struct { - unsigned offset : 16; - unsigned rt : 5; - unsigned rs : 5; - unsigned op : 6; - }; - - struct { - unsigned immediate : 16; - unsigned : 5; - unsigned base : 5; - unsigned : 6; - }; - - struct { - unsigned target : 26; - unsigned : 6; - }; - - struct { - unsigned funct : 6; - unsigned sa : 5; - unsigned rd : 5; - unsigned : 5; - unsigned : 5; - unsigned : 6; - }; - - struct { - unsigned : 6; - unsigned fd : 5; - unsigned fs : 5; - unsigned ft : 5; - unsigned fmt : 5; - unsigned : 6; - }; - }; - -} OPCODE; - -//R4300i OpCodes -#define R4300i_SPECIAL 0 -#define R4300i_REGIMM 1 -#define R4300i_J 2 -#define R4300i_JAL 3 -#define R4300i_BEQ 4 -#define R4300i_BNE 5 -#define R4300i_BLEZ 6 -#define R4300i_BGTZ 7 -#define R4300i_ADDI 8 -#define R4300i_ADDIU 9 -#define R4300i_SLTI 10 -#define R4300i_SLTIU 11 -#define R4300i_ANDI 12 -#define R4300i_ORI 13 -#define R4300i_XORI 14 -#define R4300i_LUI 15 -#define R4300i_CP0 16 -#define R4300i_CP1 17 -#define R4300i_BEQL 20 -#define R4300i_BNEL 21 -#define R4300i_BLEZL 22 -#define R4300i_BGTZL 23 -#define R4300i_DADDI 24 -#define R4300i_DADDIU 25 -#define R4300i_LDL 26 -#define R4300i_LDR 27 -#define R4300i_LB 32 -#define R4300i_LH 33 -#define R4300i_LWL 34 -#define R4300i_LW 35 -#define R4300i_LBU 36 -#define R4300i_LHU 37 -#define R4300i_LWR 38 -#define R4300i_LWU 39 -#define R4300i_SB 40 -#define R4300i_SH 41 -#define R4300i_SWL 42 -#define R4300i_SW 43 -#define R4300i_SDL 44 -#define R4300i_SDR 45 -#define R4300i_SWR 46 -#define R4300i_CACHE 47 -#define R4300i_LL 48 -#define R4300i_LWC1 49 -#define R4300i_LWC2 0x32 -#define R4300i_LLD 0x34 -#define R4300i_LDC1 53 -#define R4300i_LDC2 0x36 -#define R4300i_LD 55 -#define R4300i_SC 0x38 -#define R4300i_SWC1 57 -#define R4300i_SWC2 0x3A -#define R4300i_SCD 0x3C -#define R4300i_SDC1 61 -#define R4300i_SDC2 62 -#define R4300i_SD 63 - -/* R4300i Special opcodes */ -#define R4300i_SPECIAL_SLL 0 -#define R4300i_SPECIAL_SRL 2 -#define R4300i_SPECIAL_SRA 3 -#define R4300i_SPECIAL_SLLV 4 -#define R4300i_SPECIAL_SRLV 6 -#define R4300i_SPECIAL_SRAV 7 -#define R4300i_SPECIAL_JR 8 -#define R4300i_SPECIAL_JALR 9 -#define R4300i_SPECIAL_SYSCALL 12 -#define R4300i_SPECIAL_BREAK 13 -#define R4300i_SPECIAL_SYNC 15 -#define R4300i_SPECIAL_MFHI 16 -#define R4300i_SPECIAL_MTHI 17 -#define R4300i_SPECIAL_MFLO 18 -#define R4300i_SPECIAL_MTLO 19 -#define R4300i_SPECIAL_DSLLV 20 -#define R4300i_SPECIAL_DSRLV 22 -#define R4300i_SPECIAL_DSRAV 23 -#define R4300i_SPECIAL_MULT 24 -#define R4300i_SPECIAL_MULTU 25 -#define R4300i_SPECIAL_DIV 26 -#define R4300i_SPECIAL_DIVU 27 -#define R4300i_SPECIAL_DMULT 28 -#define R4300i_SPECIAL_DMULTU 29 -#define R4300i_SPECIAL_DDIV 30 -#define R4300i_SPECIAL_DDIVU 31 -#define R4300i_SPECIAL_ADD 32 -#define R4300i_SPECIAL_ADDU 33 -#define R4300i_SPECIAL_SUB 34 -#define R4300i_SPECIAL_SUBU 35 -#define R4300i_SPECIAL_AND 36 -#define R4300i_SPECIAL_OR 37 -#define R4300i_SPECIAL_XOR 38 -#define R4300i_SPECIAL_NOR 39 -#define R4300i_SPECIAL_SLT 42 -#define R4300i_SPECIAL_SLTU 43 -#define R4300i_SPECIAL_DADD 44 -#define R4300i_SPECIAL_DADDU 45 -#define R4300i_SPECIAL_DSUB 46 -#define R4300i_SPECIAL_DSUBU 47 -#define R4300i_SPECIAL_TGE 48 -#define R4300i_SPECIAL_TGEU 49 -#define R4300i_SPECIAL_TLT 50 -#define R4300i_SPECIAL_TLTU 51 -#define R4300i_SPECIAL_TEQ 52 -#define R4300i_SPECIAL_TNE 54 -#define R4300i_SPECIAL_DSLL 56 -#define R4300i_SPECIAL_DSRL 58 -#define R4300i_SPECIAL_DSRA 59 -#define R4300i_SPECIAL_DSLL32 60 -#define R4300i_SPECIAL_DSRL32 62 -#define R4300i_SPECIAL_DSRA32 63 - -/* R4300i RegImm opcodes */ -#define R4300i_REGIMM_BLTZ 0 -#define R4300i_REGIMM_BGEZ 1 -#define R4300i_REGIMM_BLTZL 2 -#define R4300i_REGIMM_BGEZL 3 -#define R4300i_REGIMM_TGEI 0x08 -#define R4300i_REGIMM_TGEIU 0x09 -#define R4300i_REGIMM_TLTI 0x0A -#define R4300i_REGIMM_TLTIU 0x0B -#define R4300i_REGIMM_TEQI 0x0C -#define R4300i_REGIMM_TNEI 0x0E -#define R4300i_REGIMM_BLTZAL 0x10 -#define R4300i_REGIMM_BGEZAL 17 -#define R4300i_REGIMM_BLTZALL 0x12 -#define R4300i_REGIMM_BGEZALL 0x13 - -/* R4300i COP0 opcodes */ -#define R4300i_COP0_MF 0 -#define R4300i_COP0_MT 4 - -/* R4300i COP0 CO opcodes */ -#define R4300i_COP0_CO_TLBR 1 -#define R4300i_COP0_CO_TLBWI 2 -#define R4300i_COP0_CO_TLBWR 6 -#define R4300i_COP0_CO_TLBP 8 -#define R4300i_COP0_CO_ERET 24 - -/* R4300i COP1 opcodes */ -#define R4300i_COP1_MF 0 -#define R4300i_COP1_DMF 1 -#define R4300i_COP1_CF 2 -#define R4300i_COP1_MT 4 -#define R4300i_COP1_DMT 5 -#define R4300i_COP1_CT 6 -#define R4300i_COP1_BC 8 -#define R4300i_COP1_S 16 -#define R4300i_COP1_D 17 -#define R4300i_COP1_W 20 -#define R4300i_COP1_L 21 - -/* R4300i COP1 BC opcodes */ -#define R4300i_COP1_BC_BCF 0 -#define R4300i_COP1_BC_BCT 1 -#define R4300i_COP1_BC_BCFL 2 -#define R4300i_COP1_BC_BCTL 3 - -#define R4300i_COP1_FUNCT_ADD 0 -#define R4300i_COP1_FUNCT_SUB 1 -#define R4300i_COP1_FUNCT_MUL 2 -#define R4300i_COP1_FUNCT_DIV 3 -#define R4300i_COP1_FUNCT_SQRT 4 -#define R4300i_COP1_FUNCT_ABS 5 -#define R4300i_COP1_FUNCT_MOV 6 -#define R4300i_COP1_FUNCT_NEG 7 -#define R4300i_COP1_FUNCT_ROUND_L 8 -#define R4300i_COP1_FUNCT_TRUNC_L 9 -#define R4300i_COP1_FUNCT_CEIL_L 10 -#define R4300i_COP1_FUNCT_FLOOR_L 11 -#define R4300i_COP1_FUNCT_ROUND_W 12 -#define R4300i_COP1_FUNCT_TRUNC_W 13 -#define R4300i_COP1_FUNCT_CEIL_W 14 -#define R4300i_COP1_FUNCT_FLOOR_W 15 -#define R4300i_COP1_FUNCT_CVT_S 32 -#define R4300i_COP1_FUNCT_CVT_D 33 -#define R4300i_COP1_FUNCT_CVT_W 36 -#define R4300i_COP1_FUNCT_CVT_L 37 -#define R4300i_COP1_FUNCT_C_F 48 -#define R4300i_COP1_FUNCT_C_UN 49 -#define R4300i_COP1_FUNCT_C_EQ 50 -#define R4300i_COP1_FUNCT_C_UEQ 51 -#define R4300i_COP1_FUNCT_C_OLT 52 -#define R4300i_COP1_FUNCT_C_ULT 53 -#define R4300i_COP1_FUNCT_C_OLE 54 -#define R4300i_COP1_FUNCT_C_ULE 55 -#define R4300i_COP1_FUNCT_C_SF 56 -#define R4300i_COP1_FUNCT_C_NGLE 57 -#define R4300i_COP1_FUNCT_C_SEQ 58 -#define R4300i_COP1_FUNCT_C_NGL 59 -#define R4300i_COP1_FUNCT_C_LT 60 -#define R4300i_COP1_FUNCT_C_NGE 61 -#define R4300i_COP1_FUNCT_C_LE 62 -#define R4300i_COP1_FUNCT_C_NGT 63 - -#endif - - diff --git a/src/usf/pif.c b/src/usf/pif.c deleted file mode 100644 index 1e43118..0000000 --- a/src/usf/pif.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" - -// Skeletal support so USFs that read the controller won't fail (bad practice, though) - -void ProcessControllerCommand ( int32_t Control, uint8_t * Command); - -uint8_t *PIF_Ram = 0; - -void PifRamRead (void) { - int32_t Channel, CurPos; - - Channel = 0; - CurPos = 0; - - do { - switch(PIF_Ram[CurPos]) { - case 0x00: - Channel += 1; - if (Channel > 6) { CurPos = 0x40; } - break; - case 0xFE: CurPos = 0x40; break; - case 0xFF: break; - case 0xB4: case 0x56: case 0xB8: break; /* ??? */ - default: - if ((PIF_Ram[CurPos] & 0xC0) == 0) { - CurPos += PIF_Ram[CurPos] + (PIF_Ram[CurPos + 1] & 0x3F) + 1; - Channel += 1; - } else { - CurPos = 0x40; - } - break; - } - CurPos += 1; - } while( CurPos < 0x40 ); -} - -void PifRamWrite (void) { - int Channel, CurPos; - - Channel = 0; - - for (CurPos = 0; CurPos < 0x40; CurPos++){ - switch(PIF_Ram[CurPos]) { - case 0x00: - Channel += 1; - if (Channel > 6) { CurPos = 0x40; } - break; - case 0xFE: CurPos = 0x40; break; - case 0xFF: break; - case 0xB4: case 0x56: case 0xB8: break; /* ??? */ - default: - if ((PIF_Ram[CurPos] & 0xC0) == 0) { - if (Channel < 4) { - ProcessControllerCommand(Channel,&PIF_Ram[CurPos]); - } - CurPos += PIF_Ram[CurPos] + (PIF_Ram[CurPos + 1] & 0x3F) + 1; - Channel += 1; - } else - CurPos = 0x40; - - break; - } - } - PIF_Ram[0x3F] = 0; -} - -// always return failure -void ProcessControllerCommand ( int32_t Control, uint8_t * Command) { - Command[1] |= 0x80; -} - diff --git a/src/usf/pif.h b/src/usf/pif.h deleted file mode 100644 index 23082c1..0000000 --- a/src/usf/pif.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -extern uint8_t *PIF_Ram; - -int32_t GetCicChipID ( int8_t * RomData ); -int32_t LoadPifRom ( int32_t country ); -void PifRamWrite ( void ); -void PifRamRead ( void ); diff --git a/src/usf/psftag.c b/src/usf/psftag.c deleted file mode 100644 index 5665552..0000000 --- a/src/usf/psftag.c +++ /dev/null @@ -1,528 +0,0 @@ - -///////////////////////////////////////////////////////////////////////////// -// -// tag handling -// -///////////////////////////////////////////////////////////////////////////// - -#include -#include -#include - -#include "psftag.h" - -#if !defined(__WIN32__) && !defined(_MSC_VER) -#include -#else -#include -static void truncate(const char *filename, int size) { - - HANDLE f = CreateFile( - filename, - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL - ); - if(f == INVALID_HANDLE_VALUE) return; - SetFilePointer(f, size, NULL, FILE_BEGIN); - if(GetLastError() == NO_ERROR) SetEndOfFile(f); - CloseHandle(f); -} -#endif - -///////////////////////////////////////////////////////////////////////////// -/* -** Returns index, or -1 if not found -** Returns the index starting at the first non-whitespace character of -** the actual variable name -*/ -static int find_tag_var_start(const char *tagbuffer, const char *varname) { - int i, j; - if(!tagbuffer || !varname) return -1; - for(i = 0;;) { - /* - ** Find first non-whitespace - ** (this is the variable name on the current line) - */ - for(;; i++) { - unsigned u = ((unsigned)(tagbuffer[i])) & 0xFF; - /* If the tag ends here, we wouldn't have had any data anyway */ - if(!u) return -1; - if(u <= 0x20) continue; - break; - } - /* - ** Compare case-insensitively to the var name - */ - for(j = 0;; j++) { - unsigned ucmp = ((unsigned)(varname [ j])) & 0xFF; - unsigned u = ((unsigned)(tagbuffer[i + j])) & 0xFF; - /* if the varname ends, we'll break here and do the equals check */ - if(!ucmp) break; - /* If the tag ends here, we wouldn't have had any data anyway */ - if(!u) return -1; - /* lowercase */ - if(ucmp >= 'A' && ucmp <= 'Z') { ucmp -= 'A'; ucmp += 'a'; } - if(u >= 'A' && u <= 'Z') { u -= 'A'; u += 'a'; } - /* if they're unequal, break... */ - if(u != ucmp) break; - } - /* - ** Only if we exhausted the varname will we do the equals check - */ - if(!varname[j]) { - /* - ** Ensure that the next non-whitespace character in [i+j] is an '=' - */ - for(;; j++) { - unsigned u = ((unsigned)(tagbuffer[i + j])) & 0xFF; - /* If the tag ends here, we wouldn't have had any data anyway */ - if(!u) return -1; - /* quit at the first '=' - success! */ - if(u == '=') return i; - /* shouldn't be a newline here! */ - if(u == 0x0A) break; - /* ignore whitespace */ - if(u <= 0x20) continue; - /* any other character is an error */ - break; - } - } - i += j + 1; - /* - ** Find newline or end-of-tag - */ - for(;; i++) { - unsigned u = ((unsigned)(tagbuffer[i])) & 0xFF; - /* If the tag ends here, we wouldn't have had any data anyway */ - if(!u) return -1; - if(u == 0x0A) break; - } - } - return -1; -} - -/* -** Returns the index at which the current variable ends -** (Includes any ending newline and possibly whitespace after that) -** -** Buffer points to the first non-whitespace character of the variable name -*/ -static int find_tag_var_end(const char *tagbuffer) { - int i, j; - if(!tagbuffer) return 0; - for(i = 0;;) { - /* - ** Find first non-whitespace - ** (this is the variable name on the current line) - */ - for(;; i++) { - unsigned u = ((unsigned)(tagbuffer[i])) & 0xFF; - if(!u) return i; - if(u <= 0x20) continue; - break; - } - /* - ** Compare case-insensitively to the original var name - */ - for(j = 0;; j++) { - unsigned ucmp = ((unsigned)(tagbuffer[ j])) & 0xFF; - unsigned u = ((unsigned)(tagbuffer[i + j])) & 0xFF; - /* If the tag ends here, we wouldn't have had any data anyway */ - if(!u) return i; - /* lowercase */ - if(ucmp >= 'A' && ucmp <= 'Z') { ucmp -= 'A'; ucmp += 'a'; } - if(u >= 'A' && u <= 'Z') { u -= 'A'; u += 'a'; } - /* if they're both whitespace or '=', we win */ - if((u <= 0x20 || u == '=') && (ucmp <= 0x20 || ucmp == '=')) break; - /* if they're unequal, we lose */ - if(u != ucmp) return i; - /* otherwise, keep trying */ - } - /* - ** Ensure that the next non-whitespace character in [i+j] is an '=' - */ - for(;; j++) { - unsigned u = ((unsigned)(tagbuffer[i + j])) & 0xFF; - if(!u) return i; - /* quit at the first '=' */ - if(u == '=') break; - /* shouldn't be a newline here! */ - if(u == 0x0A) return i; - /* ignore whitespace */ - if(u <= 0x20) continue; - /* any other character is an error */ - break; - } - i += j + 1; - /* - ** Find newline or end-of-tag - */ - for(;; i++) { - unsigned u = ((unsigned)(tagbuffer[i])) & 0xFF; - if(!u) return i; - if(u == 0x0A) break; - } - } -} - -///////////////////////////////////////////////////////////////////////////// -/* -** Get tag variable -** The destination value buffer must be as big as the entire tag -*/ -int psftag_raw_getvar( - const char *tag, - const char *variable, - char *value_out, - int value_out_size -) { - char *v = value_out; - char *vmax = v + value_out_size; - char *v_linebegin; - int i, i_end; - // - // Safety check - // - if(value_out_size < 1) return -1; - /* - ** Default to empty string - */ - *v = 0; - /* - ** Find the variable start/end index - */ - i = find_tag_var_start(tag, variable); - if(i < 0) return -1; - i_end = i + find_tag_var_end(tag + i); - /* - ** Extract the variable data - */ - while(i < i_end) { - /* - ** Skip to first '=' - */ - while((tag[i] != '=') && (i < i_end)) { i++; } - if(i >= i_end) break; - /* - ** If this is not the first line, add a newline - */ - if(v > value_out) { - if(v < vmax) { *v++ = 0x0A; } - } - /* - ** Now that we're at a '=', skip past it - */ - i++; - if(i >= i_end) break; - /* - ** Skip past any whitespace except newlines - */ - for(; i < i_end; i++) { - unsigned u = ((unsigned)(tag[i])) & 0xFF; - if(u == 0x0A) break; - if(u <= 0x20) continue; - break; - } - if(i >= i_end) break; - /* - ** Consume line data - */ - v_linebegin = v; - while(i < i_end) { - unsigned u = ((unsigned)(tag[i++])) & 0xFF; - if(u == 0x0A) break; - if(v < vmax) { *v++ = u; } - } - /* - ** Eat end-of-line whitespace - */ - while(v > v_linebegin && (((unsigned)(v[-1]))&0xFF) <= 0x20) { - v--; - } - } - /* - ** Set variable end - */ - if(v >= vmax) { v = vmax - 1; } - *v = 0; - return 0; -} - -///////////////////////////////////////////////////////////////////////////// - -void psftag_raw_setvar( - char *tag, - int tag_max_size, - const char *variable, - const char *value -) { - int tag_l = strlen(tag); - int i, i_end, z; - int insert_i; - int insert_l; - int value_exists = 0; - int tag_max_usable_size = tag_max_size - 1; - // - // Safety check - // - if(tag_max_size < 1) return; - // - // We will assume we can at least use what's there - // - if(tag_max_usable_size < tag_l) { - tag_max_usable_size = tag_l; - tag_max_size = tag_l + 1; - } - /* - ** Determine the insertion length of the new variable - */ - { const char *v; - int nl = strlen(variable); - insert_l = nl + 2; - for(v = value; *v; v++) { - insert_l++; - if(*v == 0x0A) { - /* Value exists if it's multi-line */ - value_exists = 1; - insert_l += nl + 1; - } else if((((unsigned)(*v))&0xFF) > 0x20) { - /* Value exists if there are non-whitespace characters */ - value_exists = 1; - } - } - } - /* - ** If the value is blank, force the insert length to zero - */ - if(!value_exists) insert_l = 0; - /* - ** Find the variable start index - */ - i = find_tag_var_start(tag, variable); - /* - ** If not found, add a new variable - */ - if(i < 0) { - /* Insert position is at the end */ - insert_i = tag_l; - /* Eat trailing whitespace in the file */ - while(insert_i && (((unsigned)(tag[insert_i - 1]))&0xFF) <= 0x20) { insert_i--; } - /* Insert a newline if there's room and if there's stuff before */ - if(insert_i && (insert_i < tag_max_usable_size)) { tag[insert_i++] = 0x0A; } - /* Clamp insert length */ - if((insert_i + insert_l) > tag_max_usable_size) { insert_l = tag_max_usable_size - insert_i; } - z = insert_i + insert_l; - /* - ** Otherwise, find the variable end index - */ - } else { - int movel; - insert_i = i; - /* Clamp insert length */ - if((insert_i + insert_l) > tag_max_usable_size) { insert_l = tag_max_usable_size - insert_i; } - i_end = i + find_tag_var_end(tag + i); - /* Move remaining file data */ - movel = tag_l - i_end; - if(movel > (tag_max_usable_size-(insert_i+insert_l))) { movel = tag_max_usable_size - (insert_i+insert_l); } - /* perform the move */ - if(movel && ((insert_i+insert_l) != i_end)) { - memmove(tag+insert_i+insert_l, tag+i_end, movel); - } - z = insert_i+insert_l+movel; - } - /* Add terminating null ahead of time */ - if(z > tag_max_usable_size) z = tag_max_usable_size; - tag[z] = 0; - /* - ** Write the variable to index insert_i, max length insert_l - */ - insert_l += insert_i; - while(insert_i < insert_l) { - const char *v; - for(v = variable; (*v) && (insert_i < insert_l); v++) { - tag[insert_i++] = *v; - } - if(insert_i >= insert_l) break; - tag[insert_i++] = '='; - if(insert_i >= insert_l) break; - for(; (*value) && ((*value) != 0x0A) && (insert_i < insert_l); value++) { - tag[insert_i++] = *value; - } - if(insert_i >= insert_l) break; - tag[insert_i++] = 0x0A; - if(insert_i >= insert_l) break; - if(!(*value)) break; - if((*value) == 0x0A) value++; - } - -} - -///////////////////////////////////////////////////////////////////////////// - -#define TAGMAX (50000) -#define ERRORMAX (256) - -struct PSFTAG { - char str[TAGMAX + 1]; -}; - -/*void *psftag_create(void) { - struct PSFTAG *p = malloc(sizeof(struct PSFTAG)); - if(!p) return NULL; - p->str[0] = 0; - //p->errorstring[0] = 0; - return p; -} - -void psftag_delete(void *psftag) { - free(psftag); -}*/ - -///////////////////////////////////////////////////////////////////////////// - -/*const char *psftag_getlasterror(void *psftag) { - return ((struct PSFTAG*)psftag)->errorstring; -}*/ - -///////////////////////////////////////////////////////////////////////////// - -void psftag_getraw(void *psftag, char *raw_out, int raw_out_size) { - if(raw_out_size < 1) return; - strncpy(raw_out, ((struct PSFTAG*)psftag)->str, raw_out_size); - raw_out[raw_out_size - 1] = 0; -} - -void psftag_setraw(void *psftag, const char *raw_in) { - strncpy(((struct PSFTAG*)psftag)->str, raw_in, TAGMAX + 1); - ((struct PSFTAG*)psftag)->str[TAGMAX] = 0; -} - -///////////////////////////////////////////////////////////////////////////// - -int psftag_getvar(void *psftag, const char *variable, char *value_out, int value_out_size) { - return psftag_raw_getvar(((struct PSFTAG*)psftag)->str, variable, value_out, value_out_size); -} - -void psftag_setvar(void *psftag, const char *variable, const char *value) { - psftag_raw_setvar(((struct PSFTAG*)psftag)->str, TAGMAX + 1, variable, value); -} - -///////////////////////////////////////////////////////////////////////////// - -int psftag_readfromfile(void *psftag, const char *path) { - struct PSFTAG *t = (struct PSFTAG*)psftag; - FILE *f = NULL; - int l; - int rsize, exesize, tagstart; - char hdr[12]; - - f = fopen(path, "rb"); - if(!f) { - //strncpy(t->errorstring, strerror(errno), ERRORMAX); - //t->errorstring[ERRORMAX-1] = 0; - return -1; - } - - if(fread(hdr, 1, 12, f) != 12) goto invalidformat; - if(memcmp(hdr, "PSF", 3)) goto invalidformat; - - rsize = - ((((unsigned)(hdr[ 4])) & 0xFF) << 0) | - ((((unsigned)(hdr[ 5])) & 0xFF) << 8) | - ((((unsigned)(hdr[ 6])) & 0xFF) << 16) | - ((((unsigned)(hdr[ 7])) & 0xFF) << 24); - exesize = - ((((unsigned)(hdr[ 8])) & 0xFF) << 0) | - ((((unsigned)(hdr[ 9])) & 0xFF) << 8) | - ((((unsigned)(hdr[10])) & 0xFF) << 16) | - ((((unsigned)(hdr[11])) & 0xFF) << 24); - - tagstart = 16 + rsize + exesize; - - fseek(f, tagstart, SEEK_SET); - - if(fread(hdr, 1, 5, f) != 5) goto notpresent; - if(memcmp(hdr, "[TAG]", 5)) goto invalidformat; - - tagstart += 5; - fseek(f, 0, SEEK_END); - l = ftell(f); - fseek(f, tagstart, SEEK_SET); - l -= tagstart; - if(l < 0) l = 0; - if(l > TAGMAX) l = TAGMAX; - - memset(t->str, 0, TAGMAX + 1); - fread(t->str, 1, l, f); - - fclose(f); - return 0; - -invalidformat: -// strcpy(t->errorstring, "Invalid file format"); - goto error; -notpresent: -// strcpy(t->errorstring, "Tag not present"); - goto error; -error: - if(f) fclose(f); - return -1; -} - -///////////////////////////////////////////////////////////////////////////// - -int psftag_writetofile(void *psftag, const char *path) { - struct PSFTAG *t = (struct PSFTAG*)psftag; - FILE *f = NULL; - int l; - int rsize, exesize, tagstart; - char hdr[12]; - - f = fopen(path, "r+b"); - if(!f) { - //strncpy(t->errorstring, strerror(errno), ERRORMAX); - //t->errorstring[ERRORMAX-1] = 0; - return -1; - } - - if(fread(hdr, 1, 12, f) != 12) goto invalidformat; - if(memcmp(hdr, "PSF", 3)) goto invalidformat; - - rsize = - ((((unsigned)(hdr[ 4])) & 0xFF) << 0) | - ((((unsigned)(hdr[ 5])) & 0xFF) << 8) | - ((((unsigned)(hdr[ 6])) & 0xFF) << 16) | - ((((unsigned)(hdr[ 7])) & 0xFF) << 24); - exesize = - ((((unsigned)(hdr[ 8])) & 0xFF) << 0) | - ((((unsigned)(hdr[ 9])) & 0xFF) << 8) | - ((((unsigned)(hdr[10])) & 0xFF) << 16) | - ((((unsigned)(hdr[11])) & 0xFF) << 24); - - tagstart = 16 + rsize + exesize; - - fseek(f, tagstart, SEEK_SET); - - l = strlen(t->str); - - fwrite("[TAG]", 1, 5, f); - fwrite(t->str, 1, l, f); - fclose(f); - - truncate(path, tagstart + 5 + l); - - return 0; - -invalidformat: -// strcpy(t->errorstring, "Invalid file format"); - goto error; -error: - if(f) fclose(f); - return -1; -} - -///////////////////////////////////////////////////////////////////////////// diff --git a/src/usf/psftag.h b/src/usf/psftag.h deleted file mode 100644 index 7fbee5f..0000000 --- a/src/usf/psftag.h +++ /dev/null @@ -1,57 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// tag handling -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef __PSF_PSFTAG_H__ -#define __PSF_PSFTAG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -void *psftag_create(void); -void psftag_delete(void *psftag); - -int psftag_readfromfile(void *psftag, const char *path); -int psftag_writetofile(void *psftag, const char *path); -const char *psftag_getlasterror(void *psftag); - -// -// Retrieve a tag variable. -// Guarantees null termination of output. -// Returns 0 if the variable was found -// Otherwise, returns -1 and sets the output to an empty terminated string -// -int psftag_getvar(void *psftag, const char *variable, char *value_out, int value_out_size); - -// -// Set a tag variable. -// -void psftag_setvar(void *psftag, const char *variable, const char *value); - -void psftag_getraw(void *psftag, char *raw_out, int raw_out_size); -void psftag_setraw(void *psftag, const char *raw_in); - -// -// Retrieve a tag variable. The input tag data must be null-terminated. -// Guarantees null termination of output. -// Returns 0 if the variable was found -// Otherwise, returns -1 and sets the output to an empty terminated string -// -int psftag_raw_getvar(const char *tag, const char *variable, char *value_out, int value_out_size); - -// -// Set a tag variable. -// Provide the maximum growable tag size _including_ space for the null terminator. -// Note that this function assumes it can overwrite *tag up to the length of the -// existing string, regardless of tag_max_size. -// -void psftag_raw_setvar(char *tag, int tag_max_size, const char *variable, const char *value); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/usf/recompiler_cpu.c b/src/usf/recompiler_cpu.c deleted file mode 100644 index 7a86b94..0000000 --- a/src/usf/recompiler_cpu.c +++ /dev/null @@ -1,2780 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 -#include -#include "main.h" -#include "cpu.h" -#include "x86.h" -#include "usf.h" -#include "types.h" - - -void CreateSectionLinkage (BLOCK_SECTION * Section); -void DetermineLoop(BLOCK_SECTION * Section, uint32_t Test, uint32_t Test2, uint32_t TestID); -uint32_t DisplaySectionInformation (BLOCK_SECTION * Section, uint32_t ID, uint32_t Test); -BLOCK_SECTION * ExistingSection(BLOCK_SECTION * StartSection, uint32_t Addr, uint32_t Test); -void FillSectionInfo(BLOCK_SECTION * Section); -void FixConstants ( BLOCK_SECTION * Section, uint32_t Test,int * Changed ); -uint32_t GenerateX86Code (BLOCK_SECTION * Section, uint32_t Test ); -uint32_t GetNewTestValue( void ); -void InheritConstants(BLOCK_SECTION * Section); -uint32_t InheritParentInfo (BLOCK_SECTION * Section); -void InitilzeSection(BLOCK_SECTION * Section, BLOCK_SECTION * Parent, uint32_t StartAddr, uint32_t ID); -void InitilizeRegSet(REG_INFO * RegSet); -uint32_t IsAllParentLoops(BLOCK_SECTION * Section, BLOCK_SECTION * Parent, uint32_t IgnoreIfCompiled, uint32_t Test); -void MarkCodeBlock (uint32_t PAddr); -void SyncRegState (BLOCK_SECTION * Section, REG_INFO * SyncTo); - -N64_Blocks_t N64_Blocks; -uint32_t * TLBLoadAddress = 0, TargetIndex; -TARGET_INFO * TargetInfo = NULL; -BLOCK_INFO BlockInfo; - -void InitilizeInitialCompilerVariable ( void) -{ - memset(&BlockInfo,0,sizeof(BlockInfo)); -} - -void AddParent(BLOCK_SECTION * Section, BLOCK_SECTION * Parent){ - int NoOfParents, count; - - - if (Section == NULL) { return; } - if (Parent == NULL) { - InitilizeRegSet(&Section->RegStart); - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - return; - } - - if (Section->ParentSection != NULL) { - for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++) { - if (Section->ParentSection[NoOfParents] == Parent) { - return; - } - } - for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++); - NoOfParents += 1; - } else { - NoOfParents = 1; - } - - if (NoOfParents == 1) { - Section->ParentSection = malloc((NoOfParents + 1)*sizeof(void *)); - } else { - Section->ParentSection = realloc(Section->ParentSection,(NoOfParents + 1)*sizeof(void *)); - } - Section->ParentSection[NoOfParents - 1] = Parent; - Section->ParentSection[NoOfParents] = NULL; - - if (NoOfParents == 1) { - if (Parent->ContinueSection == Section) { - memcpy(&Section->RegStart,&Parent->Cont.RegSet,sizeof(REG_INFO)); - } else if (Parent->JumpSection == Section) { - memcpy(&Section->RegStart,&Parent->Jump.RegSet,sizeof(REG_INFO)); - } else { - } - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - } else { - if (Parent->ContinueSection == Section) { - for (count = 0; count < 32; count++) { - if (Section->RegStart.MIPS_RegState[count] != Parent->Cont.RegSet.MIPS_RegState[count]) { - Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN; - } - } - } - if (Parent->JumpSection == Section) { - for (count = 0; count < 32; count++) { - if (Section->RegStart.MIPS_RegState[count] != Parent->Jump.RegSet.MIPS_RegState[count]) { - Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN; - } - } - } - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - } -} - -void AnalyseBlock (void) { - int Changed; - - BLOCK_SECTION * Section = &BlockInfo.BlockInfo; - - BlockInfo.NoOfSections = 1; - InitilzeSection (Section, NULL, BlockInfo.StartVAddr, BlockInfo.NoOfSections); - CreateSectionLinkage (Section); - DetermineLoop(Section,GetNewTestValue(),GetNewTestValue(), Section->SectionID); - do { - Changed = 0; - FixConstants(Section,GetNewTestValue(),&Changed); - } while (Changed == 1); - -} - -int ConstantsType (int64_t Value) { - if (((Value >> 32) == -1) && ((Value & 0x80000000) != 0)) { return STATE_CONST_32; } - if (((Value >> 32) == 0) && ((Value & 0x80000000) == 0)) { return STATE_CONST_32; } - return STATE_CONST_64; -} - - -uint8_t * Compiler4300iBlock(void) { - uintptr_t StartAddress; - int count; - - //reset BlockInfo - if (BlockInfo.ExitInfo) - { - for (count = 0; count < BlockInfo.ExitCount; count ++) { - free(BlockInfo.ExitInfo[count]); - BlockInfo.ExitInfo[count] = NULL; - } - if (BlockInfo.ExitInfo) { free(BlockInfo.ExitInfo); } - BlockInfo.ExitInfo = NULL; - } - - memset(&BlockInfo,0,sizeof(BlockInfo)); - BlockInfo.CompiledLocation = RecompPos; - BlockInfo.StartVAddr = PROGRAM_COUNTER; - - AnalyseBlock(); - - StartAddress = BlockInfo.StartVAddr; - TranslateVaddr(&StartAddress); - - //BreakPoint(); - //MoveConstQwordToX86reg(Registers, x64_R14); - - MarkCodeBlock(StartAddress); - - while (GenerateX86Code(&BlockInfo.BlockInfo,GetNewTestValue())); - for (count = 0; count < BlockInfo.ExitCount; count ++) { - SetJump32(BlockInfo.ExitInfo[count]->JumpLoc,RecompPos); - NextInstruction = BlockInfo.ExitInfo[count]->NextInstruction; - CompileExit(BlockInfo.ExitInfo[count]->TargetPC,&BlockInfo.ExitInfo[count]->ExitRegSet, - BlockInfo.ExitInfo[count]->reason,1,NULL); - } - FreeSection (BlockInfo.BlockInfo.ContinueSection,&BlockInfo.BlockInfo); - FreeSection (BlockInfo.BlockInfo.JumpSection,&BlockInfo.BlockInfo); - for (count = 0; count < BlockInfo.ExitCount; count ++) { - free(BlockInfo.ExitInfo[count]); - BlockInfo.ExitInfo[count] = NULL; - } - if (BlockInfo.ExitInfo) { free(BlockInfo.ExitInfo); } - BlockInfo.ExitInfo = NULL; - BlockInfo.ExitCount = 0; - - return BlockInfo.CompiledLocation; -} - - -uint8_t * CompileDelaySlot(void) { - uintptr_t StartAddress = PROGRAM_COUNTER; - BLOCK_SECTION *Section, DelaySection; - uint8_t * Block = RecompPos; - int count, x86Reg; - - Section = &DelaySection; - - if ((StartAddress & 0xFFC) != 0) { - StopEmulation(); - } - if (!r4300i_LW_VAddr(StartAddress, &Opcode.Hex)) { - StopEmulation(); - } - - TranslateVaddr(&StartAddress); - - MarkCodeBlock(StartAddress); - - InitilzeSection (Section, NULL, PROGRAM_COUNTER, 0); - InitilizeRegSet(&Section->RegStart); - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - - BlockCycleCount += 2; - BlockRandomModifier += 1; - - switch (Opcode.op) { - case R4300i_SPECIAL: - switch (Opcode.funct) { - case R4300i_SPECIAL_BREAK: Compile_R4300i_SPECIAL_BREAK(Section); break; - case R4300i_SPECIAL_SLL: Compile_R4300i_SPECIAL_SLL(Section); break; - case R4300i_SPECIAL_SRL: Compile_R4300i_SPECIAL_SRL(Section); break; - case R4300i_SPECIAL_SRA: Compile_R4300i_SPECIAL_SRA(Section); break; - case R4300i_SPECIAL_SLLV: Compile_R4300i_SPECIAL_SLLV(Section); break; - case R4300i_SPECIAL_SRLV: Compile_R4300i_SPECIAL_SRLV(Section); break; - case R4300i_SPECIAL_SRAV: Compile_R4300i_SPECIAL_SRAV(Section); break; - case R4300i_SPECIAL_MFLO: Compile_R4300i_SPECIAL_MFLO(Section); break; - case R4300i_SPECIAL_MTLO: Compile_R4300i_SPECIAL_MTLO(Section); break; - case R4300i_SPECIAL_MFHI: Compile_R4300i_SPECIAL_MFHI(Section); break; - case R4300i_SPECIAL_MTHI: Compile_R4300i_SPECIAL_MTHI(Section); break; - case R4300i_SPECIAL_MULT: Compile_R4300i_SPECIAL_MULT(Section); break; - case R4300i_SPECIAL_DIV: Compile_R4300i_SPECIAL_DIV(Section); break; - case R4300i_SPECIAL_DIVU: Compile_R4300i_SPECIAL_DIVU(Section); break; - case R4300i_SPECIAL_MULTU: Compile_R4300i_SPECIAL_MULTU(Section); break; - case R4300i_SPECIAL_DMULTU: Compile_R4300i_SPECIAL_DMULTU(Section); break; - case R4300i_SPECIAL_DDIVU: Compile_R4300i_SPECIAL_DDIVU(Section); break; - case R4300i_SPECIAL_ADD: Compile_R4300i_SPECIAL_ADD(Section); break; - case R4300i_SPECIAL_ADDU: Compile_R4300i_SPECIAL_ADDU(Section); break; - case R4300i_SPECIAL_SUB: Compile_R4300i_SPECIAL_SUB(Section); break; - case R4300i_SPECIAL_SUBU: Compile_R4300i_SPECIAL_SUBU(Section); break; - case R4300i_SPECIAL_AND: Compile_R4300i_SPECIAL_AND(Section); break; - case R4300i_SPECIAL_OR: Compile_R4300i_SPECIAL_OR(Section); break; - case R4300i_SPECIAL_XOR: Compile_R4300i_SPECIAL_XOR(Section); break; - case R4300i_SPECIAL_SLT: Compile_R4300i_SPECIAL_SLT(Section); break; - case R4300i_SPECIAL_SLTU: Compile_R4300i_SPECIAL_SLTU(Section); break; - case R4300i_SPECIAL_DADD: Compile_R4300i_SPECIAL_DADD(Section); break; - case R4300i_SPECIAL_DADDU: Compile_R4300i_SPECIAL_DADDU(Section); break; - case R4300i_SPECIAL_DSLL32: Compile_R4300i_SPECIAL_DSLL32(Section); break; - case R4300i_SPECIAL_DSRA32: Compile_R4300i_SPECIAL_DSRA32(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_ADDI: Compile_R4300i_ADDI(Section); break; - case R4300i_ADDIU: Compile_R4300i_ADDIU(Section); break; - case R4300i_SLTI: Compile_R4300i_SLTI(Section); break; - case R4300i_SLTIU: Compile_R4300i_SLTIU(Section); break; - case R4300i_ANDI: Compile_R4300i_ANDI(Section); break; - case R4300i_ORI: Compile_R4300i_ORI(Section); break; - case R4300i_XORI: Compile_R4300i_XORI(Section); break; - case R4300i_LUI: Compile_R4300i_LUI(Section); break; - case R4300i_CP1: - switch (Opcode.rs) { - case R4300i_COP1_CF: Compile_R4300i_COP1_CF(Section); break; - case R4300i_COP1_MT: Compile_R4300i_COP1_MT(Section); break; - case R4300i_COP1_CT: Compile_R4300i_COP1_CT(Section); break; - case R4300i_COP1_MF: Compile_R4300i_COP1_MF(Section); break; - case R4300i_COP1_S: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_S_ADD(Section); break; - case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_S_SUB(Section); break; - case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_S_MUL(Section); break; - case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_S_DIV(Section); break; - case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_S_ABS(Section); break; - case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_S_NEG(Section); break; - case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_S_SQRT(Section); break; - case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_S_MOV(Section); break; - case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_S_CVT_D(Section); break; - case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_S_ROUND_W(Section); break; - case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_S_TRUNC_W(Section); break; - case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_S_FLOOR_W(Section); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - Compile_R4300i_COP1_S_CMP(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_D: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_D_ADD(Section); break; - case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_D_SUB(Section); break; - case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_D_MUL(Section); break; - case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_D_DIV(Section); break; - case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_D_ABS(Section); break; - case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_D_NEG(Section); break; - case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_D_SQRT(Section); break; - case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_D_MOV(Section); break; - case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_D_TRUNC_W(Section); break; - case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_D_CVT_S(Section); break; - case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_D_CVT_W(Section); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - Compile_R4300i_COP1_D_CMP(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_W: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_W_CVT_S(Section); break; - case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_W_CVT_D(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_LB: Compile_R4300i_LB(Section); break; - case R4300i_LH: Compile_R4300i_LH(Section); break; - case R4300i_LW: Compile_R4300i_LW(Section); break; - case R4300i_LBU: Compile_R4300i_LBU(Section); break; - case R4300i_LHU: Compile_R4300i_LHU(Section); break; - case R4300i_SB: Compile_R4300i_SB(Section); break; - case R4300i_SH: Compile_R4300i_SH(Section); break; - case R4300i_SW: Compile_R4300i_SW(Section); break; - case R4300i_SWR: Compile_R4300i_SWR(Section); break; - case R4300i_CACHE: Compile_R4300i_CACHE(Section); break; - case R4300i_LWC1: Compile_R4300i_LWC1(Section); break; - case R4300i_LDC1: Compile_R4300i_LDC1(Section); break; - case R4300i_LD: Compile_R4300i_LD(Section); break; - case R4300i_SWC1: Compile_R4300i_SWC1(Section); break; - case R4300i_SDC1: Compile_R4300i_SDC1(Section); break; - case R4300i_SD: Compile_R4300i_SD(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - - WriteBackRegisters(Section); - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - x86Reg = Map_TempReg(Section,x86_Any,-1,0); - MoveVariableToX86reg(&JumpToLocation,x86Reg); - MoveX86regToVariable(x86Reg,&PROGRAM_COUNTER); - MoveConstToVariable(NORMAL,&NextInstruction); - Ret(); - return Block; -} - -void CompileExit (uint32_t TargetPC, REG_INFO * ExitRegSet, int reason, int CompileNow, void (*x86Jmp)(uintptr_t Value)) { - BLOCK_SECTION Section; - uint8_t * Jump, * Jump2; - - if (!CompileNow) { - if (BlockInfo.ExitCount == 0) { - BlockInfo.ExitInfo = malloc(sizeof(void *)); - } else { - BlockInfo.ExitInfo = realloc(BlockInfo.ExitInfo,(BlockInfo.ExitCount + 1) * sizeof(void *)); - } - if (x86Jmp == NULL) { - StopEmulation(); - } - x86Jmp(0); - BlockInfo.ExitInfo[BlockInfo.ExitCount] = malloc(sizeof(EXIT_INFO)); - BlockInfo.ExitInfo[BlockInfo.ExitCount]->TargetPC = TargetPC; - BlockInfo.ExitInfo[BlockInfo.ExitCount]->ExitRegSet = *ExitRegSet; - BlockInfo.ExitInfo[BlockInfo.ExitCount]->reason = reason; - BlockInfo.ExitInfo[BlockInfo.ExitCount]->NextInstruction = NextInstruction; - BlockInfo.ExitInfo[BlockInfo.ExitCount]->JumpLoc = RecompPos - 4; - BlockInfo.ExitCount += 1; - return; - } - - InitilzeSection (&Section, NULL, (uint32_t)-1, 0); - memcpy(&Section.RegWorking, ExitRegSet, sizeof(REG_INFO)); - - - //if(TargetPC > 0x90000000) - //BreakPoint(); - - if (TargetPC != (uint32_t)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER); } - if (ExitRegSet->CycleCount != 0) { - AddConstToVariable(ExitRegSet->CycleCount,&CP0[9]); - SubConstFromVariable(ExitRegSet->CycleCount,&Timers->Timer); - } - if (ExitRegSet->RandomModifier != 0) { SubConstFromVariable(ExitRegSet->RandomModifier,&CP0[1]); } - WriteBackRegisters(&Section); - - switch (reason) { - case Normal: case Normal_NoSysCheck: - Section.RegWorking.RandomModifier = 0; - Section.RegWorking.CycleCount = 0; - if (reason == Normal) { CompileSystemCheck(0,(uint32_t)-1,Section.RegWorking); } - - if (TargetPC >= 0x80000000 && TargetPC < 0x90000000) { - uint32_t pAddr = TargetPC & 0x1FFFFFFF; - MoveConstToX86reg(pAddr,x86_ECX); - ShiftRightDoubleImmed(x86_ECX,x86_ECX,2); -#ifdef USEX64 - MoveVariableDispToX86Reg(JumpTable,x86_RCX,x86_RCX,8); -#else - MoveVariableDispToX86Reg(JumpTable,x86_ECX,x86_ECX,4); -#endif - Jump2 = NULL; - } else if (TargetPC >= 0x90000000 && TargetPC < 0xC0000000) { - } else { -#ifdef USEX64 - MoveConstToX86reg((TargetPC >> 12),x86_RCX); - MoveConstToX86reg(TargetPC,x86_EBX); - //MoveVariableDispToX86Reg(TLB_Map,x86_RCX,x86_RCX,8); - MoveX86RegDispToX86Reg(x86_RCX, x86_R15, x86_RCX, 8); - TestX86RegToX86Reg(x86_RCX,x86_RCX); - JeLabel8(0); - Jump2 = RecompPos - 1; - AddX86RegToX86Reg(x86_RCX,x86_EBX); - MoveConstQwordToX86reg((uintptr_t)N64MEM, x86_RBX); - SubX86RegToX86Reg(x86_RCX,x86_RBX); - ShiftRightDoubleImmed(x86_RCX,x86_RCX,2); - ShiftLeftDoubleImmed(x86_RCX,x86_RCX,3); - MoveConstQwordToX86reg((uintptr_t)JumpTable, x86_RBX); - AddX86RegToX86Reg(x86_RCX,x86_RBX); - MoveX86PointerToX86reg(x86_RCX,x86_RCX); -#else - MoveConstToX86reg((TargetPC >> 12),x86_ECX); - MoveConstToX86reg(TargetPC,x86_EBX); - MoveVariableDispToX86Reg(TLB_Map,x86_ECX,x86_ECX,4); - TestX86RegToX86Reg(x86_ECX,x86_ECX); - JeLabel8(0); - Jump2 = RecompPos - 1; - AddConstToX86Reg(x86_ECX,(int32_t)JumpTable - (int32_t)N64MEM); - MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_ECX); -#endif - } - if (TargetPC < 0x90000000 || TargetPC >= 0xC0000000) - { - JecxzLabel8(0); - Jump = RecompPos - 1; - // printf("TargetPC %08x\n", TargetPC); - - - JmpDirectReg(x86_ECX); - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - if (Jump2 != NULL) { - *((uint8_t *)(Jump2))=(uint8_t)(RecompPos - Jump2 - 1); - } - } - - Ret(); - break; - case DoCPU_Action: - Pushad(); - //BreakPoint(); - Call_Direct(DoSomething); - //RecompileDoSomething(); - Popad(); - Ret(); - break; - case DoBreak: - Ret(); - break; - case DoSysCall: - MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_EDI); - printf("extinjg 1\n"); - exit(0); - Pushad(); - Call_Direct(DoSysCallException); - Popad(); - Ret(); - break; - case COP1_Unuseable: - Pushad(); - MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_EDI); - MoveConstToX86reg(1,x86_ESI); - Call_Direct(DoCopUnusableException); - Popad(); - Ret(); - break; - case ExitResetRecompCode: - if (NextInstruction == JUMP || NextInstruction == DELAY_SLOT) { - BreakPoint(); - } - Pushad(); - BreakPoint(); - Call_Direct(ResetRecompCode); - Popad(); - Ret(); - break; - case TLBReadMiss: - MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_EDI); - MoveVariableToX86reg(TLBLoadAddress,x86_ESI); - Pushad(); -#ifdef USEX64 - Call_Direct(DoTLBMiss); -#else - Push(x86_EDX); - Push(x86_ECX); - Call_Direct(DoTLBMiss); - AddConstToX86Reg(x86_ESP, 0x8); -#endif - Popad(); - Ret(); - break; - } -} - -void CompileSystemCheck (uint32_t TimerModifier, uint32_t TargetPC, REG_INFO RegSet) { - BLOCK_SECTION Section; - uint8_t *Jump, *Jump2; - - CompConstToVariable(0,WaitMode); - JeLabel8(0); - Jump = RecompPos - 1; - MoveConstToVariable(-1, &Timers->Timer); - - SetJump8(Jump, RecompPos); - - // Timer - if (TimerModifier != 0) { - SubConstFromVariable(TimerModifier,&Timers->Timer); - } else { - CompConstToVariable(0,&Timers->Timer); - } - JnsLabel32(0); - Jump = RecompPos - 4; - Pushad(); - if (TargetPC != (uint32_t)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER); } - InitilzeSection (&Section, NULL, (uint32_t)-1, 0); - memcpy(&Section.RegWorking, &RegSet, sizeof(REG_INFO)); - WriteBackRegisters(&Section); - Call_Direct(TimerDone); - //Call_Direct(RecompileTimerDone); - //RecompileTimerDone(); - //RecompileTimerDone(); - - Popad(); - - //Interrupt - CompConstToVariable(0,&CPU_Action->DoSomething); - JeLabel32(0); - Jump2 = RecompPos - 4; - CompileExit(-1,&Section.RegWorking,DoCPU_Action,1,NULL); - - SetJump32(Jump2,RecompPos); - Ret(); - - SetJump32(Jump,RecompPos); - - //Interrupt 2 - CompConstToVariable(0,&CPU_Action->DoSomething); - JeLabel32(0); - Jump = RecompPos - 4; - if (TargetPC != (uint32_t)-1) { MoveConstToVariable(TargetPC,&PROGRAM_COUNTER); } - InitilzeSection (&Section, NULL, (uint32_t)-1, 0); - memcpy(&Section.RegWorking, &RegSet, sizeof(REG_INFO)); - WriteBackRegisters(&Section); - CompileExit(-1,&Section.RegWorking,DoCPU_Action,1,NULL); - SetJump32(Jump,RecompPos); - return; -} - -void CreateSectionLinkage (BLOCK_SECTION * Section) { - BLOCK_SECTION ** TargetSection[2]; - uint32_t * TargetPC[2], count; - - InheritConstants(Section); - //__try { - FillSectionInfo(Section); -/* } __except( r4300i_CPU_MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) { - DisplayError(GS(MSG_UNKNOWN_MEM_ACTION)); - ExitThread(0); - }*/ - - if (Section->Jump.TargetPC < Section->Cont.TargetPC) { - TargetSection[0] = (BLOCK_SECTION **)&Section->JumpSection; - TargetSection[1] = (BLOCK_SECTION **)&Section->ContinueSection; - TargetPC[0] = &Section->Jump.TargetPC; - TargetPC[1] = &Section->Cont.TargetPC; - } else { - TargetSection[0] = (BLOCK_SECTION **)&Section->ContinueSection; - TargetSection[1] = (BLOCK_SECTION **)&Section->JumpSection; - TargetPC[0] = &Section->Cont.TargetPC; - TargetPC[1] = &Section->Jump.TargetPC; - } - - for (count = 0; count < 2; count ++) { - if (*TargetPC[count] != (uint32_t)-1 && *TargetSection[count] == NULL) { - *TargetSection[count] = ExistingSection(BlockInfo.BlockInfo.ContinueSection,*TargetPC[count],GetNewTestValue()); - if (*TargetSection[count] == NULL) { - *TargetSection[count] = ExistingSection(BlockInfo.BlockInfo.JumpSection,*TargetPC[count],GetNewTestValue()); - } - if (*TargetSection[count] == NULL) { - BlockInfo.NoOfSections += 1; - *TargetSection[count] = malloc(sizeof(BLOCK_SECTION)); - InitilzeSection (*TargetSection[count], Section, *TargetPC[count], BlockInfo.NoOfSections); - CreateSectionLinkage(*TargetSection[count]); - } else { - AddParent(*TargetSection[count],Section); - } - } - } -} - -void DetermineLoop(BLOCK_SECTION * Section, uint32_t Test, uint32_t Test2, uint32_t TestID) { - if (Section == NULL) { return; } - if (Section->SectionID != TestID) { - if (Section->Test2 == Test2) { - return; - } - Section->Test2 = Test2; - DetermineLoop(Section->ContinueSection,Test,Test2,TestID); - DetermineLoop(Section->JumpSection,Test,Test2,TestID); - return; - } - if (Section->Test2 == Test2) { - Section->InLoop = 1; - return; - } - Section->Test2 = Test2; - DetermineLoop(Section->ContinueSection,Test,Test2,TestID); - DetermineLoop(Section->JumpSection,Test,Test2,TestID); - if (Section->Test == Test) { return; } - Section->Test = Test; - if (Section->ContinueSection != NULL) { - DetermineLoop(Section->ContinueSection,Test,GetNewTestValue(),((BLOCK_SECTION *)Section->ContinueSection)->SectionID); - } - if (Section->JumpSection != NULL) { - DetermineLoop(Section->JumpSection,Test,GetNewTestValue(),((BLOCK_SECTION *)Section->JumpSection)->SectionID); - } -} - -uint32_t DisplaySectionInformation (BLOCK_SECTION * Section, uint32_t ID, uint32_t Test) { - return 1; -} - -BLOCK_SECTION * ExistingSection(BLOCK_SECTION * StartSection, uint32_t Addr, uint32_t Test) { - BLOCK_SECTION * Section; - - if (StartSection == NULL) { return NULL; } - if (StartSection->StartPC == Addr) { return StartSection; } - if (StartSection->Test == Test) { return NULL; } - StartSection->Test = Test; - Section = ExistingSection(StartSection->JumpSection,Addr,Test); - if (Section != NULL) { return Section; } - Section = ExistingSection(StartSection->ContinueSection,Addr,Test); - if (Section != NULL) { return Section; } - return NULL; -} - -void FillSectionInfo(BLOCK_SECTION * Section) { - OPCODE Command; - - if (Section->CompiledLocation != NULL) { return; } - Section->CompilePC = Section->StartPC; - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - NextInstruction = NORMAL; - do { - if (!r4300i_LW_VAddr(Section->CompilePC, &Command.Hex)) { - //DisplayError(GS(MSG_FAIL_LOAD_WORD)); - StopEmulation(); - } - - switch (Command.op) { - case R4300i_SPECIAL: - switch (Command.funct) { - case R4300i_SPECIAL_SLL: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) << Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SRL: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) >> Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SRA: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo_S(Command.rt) >> Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SLLV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) << (MipsRegLo(Command.rs) & 0x1F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SRLV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) >> (MipsRegLo(Command.rs) & 0x1F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SRAV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x1F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_JR: - if (IsConst(Command.rs)) { - Section->Jump.TargetPC = MipsRegLo(Command.rs); - } else { - Section->Jump.TargetPC = (uint32_t)-1; - } - NextInstruction = DELAY_SLOT; - break; - case R4300i_SPECIAL_JALR: - MipsRegLo(Opcode.rd) = Section->CompilePC + 8; - MipsRegState(Opcode.rd) = STATE_CONST_32; - if (IsConst(Command.rs)) { - Section->Jump.TargetPC = MipsRegLo(Command.rs); - } else { - Section->Jump.TargetPC = (uint32_t)-1; - } - NextInstruction = DELAY_SLOT; - break; - case R4300i_SPECIAL_BREAK: break; - case R4300i_SPECIAL_SYSCALL: - //case R4300i_SPECIAL_BREAK: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - break; - case R4300i_SPECIAL_MFHI: MipsRegState(Command.rd) = STATE_UNKNOWN; break; - case R4300i_SPECIAL_MTHI: break; - case R4300i_SPECIAL_MFLO: MipsRegState(Command.rd) = STATE_UNKNOWN; break; - case R4300i_SPECIAL_MTLO: break; - case R4300i_SPECIAL_DSLLV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(QWORD)MipsRegLo_S(Command.rt) << (MipsRegLo(Command.rs) & 0x3F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRLV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(QWORD)MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x3F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRAV: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg_S(Command.rt):(int64_t)MipsRegLo_S(Command.rt) >> (MipsRegLo(Command.rs) & 0x3F); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_MULT: break; - case R4300i_SPECIAL_MULTU: break; - case R4300i_SPECIAL_DIV: break; - case R4300i_SPECIAL_DIVU: break; - case R4300i_SPECIAL_DMULT: break; - case R4300i_SPECIAL_DMULTU: break; - case R4300i_SPECIAL_DDIV: break; - case R4300i_SPECIAL_DDIVU: break; - case R4300i_SPECIAL_ADD: - case R4300i_SPECIAL_ADDU: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegLo(Command.rd) = MipsRegLo(Command.rs) + MipsRegLo(Command.rt); - MipsRegState(Command.rd) = STATE_CONST_32; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SUB: - case R4300i_SPECIAL_SUBU: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsRegLo(Command.rd) = MipsRegLo(Command.rs) - MipsRegLo(Command.rt); - MipsRegState(Command.rd) = STATE_CONST_32; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_AND: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) { - MipsReg(Command.rd) = MipsReg(Command.rt) & MipsReg(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_64; - } else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsReg(Command.rd) = MipsReg(Command.rt) & MipsRegLo(Command.rs); - } else { - MipsReg(Command.rd) = MipsRegLo(Command.rt) & MipsReg(Command.rs); - } - MipsRegState(Command.rd) = ConstantsType(MipsReg(Command.rd)); - } else { - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) & MipsRegLo(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_32; - } - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_OR: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) { - MipsReg(Command.rd) = MipsReg(Command.rt) | MipsReg(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_64; - } else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsReg(Command.rd) = MipsReg(Command.rt) | MipsRegLo(Command.rs); - } else { - MipsReg(Command.rd) = MipsRegLo(Command.rt) | MipsReg(Command.rs); - } - MipsRegState(Command.rd) = STATE_CONST_64; - } else { - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) | MipsRegLo(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_32; - } - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_XOR: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) { - MipsReg(Command.rd) = MipsReg(Command.rt) ^ MipsReg(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_64; - } else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsReg(Command.rd) = MipsReg(Command.rt) ^ MipsRegLo(Command.rs); - } else { - MipsReg(Command.rd) = MipsRegLo(Command.rt) ^ MipsReg(Command.rs); - } - MipsRegState(Command.rd) = STATE_CONST_64; - } else { - MipsRegLo(Command.rd) = MipsRegLo(Command.rt) ^ MipsRegLo(Command.rs); - MipsRegState(Command.rd) = STATE_CONST_32; - } - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_NOR: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) && Is64Bit(Command.rs)) { - MipsReg(Command.rd) = ~(MipsReg(Command.rt) | MipsReg(Command.rs)); - MipsRegState(Command.rd) = STATE_CONST_64; - } else if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsReg(Command.rd) = ~(MipsReg(Command.rt) | MipsRegLo(Command.rs)); - } else { - MipsReg(Command.rd) = ~(MipsRegLo(Command.rt) | MipsReg(Command.rs)); - } - MipsRegState(Command.rd) = STATE_CONST_64; - } else { - MipsRegLo(Command.rd) = ~(MipsRegLo(Command.rt) | MipsRegLo(Command.rs)); - MipsRegState(Command.rd) = STATE_CONST_32; - } - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SLT: - if (Command.rd == 0) { break; } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsRegLo(Command.rd) = (MipsRegLo_S(Command.rs) < MipsReg_S(Command.rt))?1:0; - } else { - MipsRegLo(Command.rd) = (MipsReg_S(Command.rs) < MipsRegLo_S(Command.rt))?1:0; - } - } else { - MipsRegLo(Command.rd) = (MipsRegLo_S(Command.rs) < MipsRegLo_S(Command.rt))?1:0; - } - MipsRegState(Command.rd) = STATE_CONST_32; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_SLTU: - if (Command.rd == 0) { break; } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - if (Is64Bit(Command.rt) || Is64Bit(Command.rs)) { - if (Is64Bit(Command.rt)) { - MipsRegLo(Command.rd) = (MipsRegLo(Command.rs) < MipsReg(Command.rt))?1:0; - } else { - MipsRegLo(Command.rd) = (MipsReg(Command.rs) < MipsRegLo(Command.rt))?1:0; - } - } else { - MipsRegLo(Command.rd) = (MipsRegLo(Command.rs) < MipsRegLo(Command.rt))?1:0; - } - MipsRegState(Command.rd) = STATE_CONST_32; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DADD: - case R4300i_SPECIAL_DADDU: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsReg(Command.rd) = - Is64Bit(Command.rs)?MipsReg(Command.rs):(int64_t)MipsRegLo_S(Command.rs) + - Is64Bit(Command.rt)?MipsReg(Command.rt):(int64_t)MipsRegLo_S(Command.rt); - MipsRegState(Command.rd) = STATE_CONST_64; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSUB: - case R4300i_SPECIAL_DSUBU: - if (Command.rd == 0) { break; } - if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt) && IsConst(Command.rs)) { - MipsReg(Command.rd) = - Is64Bit(Command.rs)?MipsReg(Command.rs):(int64_t)MipsRegLo_S(Command.rs) - - Is64Bit(Command.rt)?MipsReg(Command.rt):(int64_t)MipsRegLo_S(Command.rt); - MipsRegState(Command.rd) = STATE_CONST_64; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSLL: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(int64_t)MipsRegLo_S(Command.rt) << Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRL: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = Is64Bit(Command.rt)?MipsReg(Command.rt):(QWORD)MipsRegLo_S(Command.rt) >> Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRA: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg_S(Command.rd) = Is64Bit(Command.rt)?MipsReg_S(Command.rt):(int64_t)MipsRegLo_S(Command.rt) >> Command.sa; - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSLL32: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_64; - MipsReg(Command.rd) = MipsRegLo(Command.rt) << (Command.sa + 32); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRL32: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = (uint32_t)(MipsReg(Command.rt) >> (Command.sa + 32)); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - case R4300i_SPECIAL_DSRA32: - if (Command.rd == 0) { break; } - if (Section->InLoop && Command.rt == Command.rd) { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - if (IsConst(Command.rt)) { - MipsRegState(Command.rd) = STATE_CONST_32; - MipsRegLo(Command.rd) = (uint32_t)(MipsReg_S(Command.rt) >> (Command.sa + 32)); - } else { - MipsRegState(Command.rd) = STATE_UNKNOWN; - } - break; - default: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - break; - case R4300i_REGIMM: - switch (Command.rt) { - case R4300i_REGIMM_BLTZ: - case R4300i_REGIMM_BGEZ: - NextInstruction = DELAY_SLOT; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,Command.rs,0)) { - Section->Jump.PermLoop = 1; - } - } - break; - case R4300i_REGIMM_BLTZL: - case R4300i_REGIMM_BGEZL: - NextInstruction = LIKELY_DELAY_SLOT; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,Command.rs,0)) { - Section->Jump.PermLoop = 1; - } - } - break; - case R4300i_REGIMM_BLTZAL: - case R4300i_REGIMM_BGEZAL: - NextInstruction = DELAY_SLOT; - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,Command.rs,0)) { - Section->Jump.PermLoop = 1; - } - } - break; - default: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - break; - case R4300i_JAL: - NextInstruction = DELAY_SLOT; - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - Section->Jump.TargetPC = (Section->CompilePC & 0xF0000000) + (Command.target << 2); - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,31,0)) { - Section->Jump.PermLoop = 1; - } - } - break; - case R4300i_J: - NextInstruction = DELAY_SLOT; - Section->Jump.TargetPC = (Section->CompilePC & 0xF0000000) + (Command.target << 2); - if (Section->CompilePC == Section->Jump.TargetPC) { Section->Jump.PermLoop = 1; } - break; - case R4300i_BEQ: - case R4300i_BNE: - case R4300i_BLEZ: - case R4300i_BGTZ: - NextInstruction = DELAY_SLOT; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,Command.rs,Command.rt)) { - Section->Jump.PermLoop = 1; - } - } - break; - case R4300i_ADDI: - case R4300i_ADDIU: - if (Command.rt == 0) { break; } - if (Section->InLoop && Command.rs == Command.rt) { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - if (IsConst(Command.rs)) { - MipsRegLo(Command.rt) = MipsRegLo(Command.rs) + (short)Command.immediate; - MipsRegState(Command.rt) = STATE_CONST_32; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_SLTI: - if (Command.rt == 0) { break; } - if (IsConst(Command.rs)) { - if (Is64Bit(Command.rs)) { - MipsRegLo(Command.rt) = (MipsReg_S(Command.rs) < (int64_t)((short)Command.immediate))?1:0; - } else { - MipsRegLo(Command.rt) = (MipsRegLo_S(Command.rs) < (int)((short)Command.immediate))?1:0; - } - MipsRegState(Command.rt) = STATE_CONST_32; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_SLTIU: - if (Command.rt == 0) { break; } - if (IsConst(Command.rs)) { - if (Is64Bit(Command.rs)) { - MipsRegLo(Command.rt) = (MipsReg(Command.rs) < (int64_t)((short)Command.immediate))?1:0; - } else { - MipsRegLo(Command.rt) = (MipsRegLo(Command.rs) < (uint32_t)((short)Command.immediate))?1:0; - } - MipsRegState(Command.rt) = STATE_CONST_32; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_LUI: - if (Command.rt == 0) { break; } - MipsRegLo(Command.rt) = ((short)Command.offset << 16); - MipsRegState(Command.rt) = STATE_CONST_32; - break; - case R4300i_ANDI: - if (Command.rt == 0) { break; } - if (Section->InLoop && Command.rs == Command.rt) { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - if (IsConst(Command.rs)) { - MipsRegState(Command.rt) = STATE_CONST_32; - MipsRegLo(Command.rt) = MipsRegLo(Command.rs) & Command.immediate; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_ORI: - if (Command.rt == 0) { break; } - if (Section->InLoop && Command.rs == Command.rt) { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - if (IsConst(Command.rs)) { - MipsRegState(Command.rt) = STATE_CONST_32; - MipsRegLo(Command.rt) = MipsRegLo(Command.rs) | Command.immediate; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_XORI: - if (Command.rt == 0) { break; } - if (Section->InLoop && Command.rs == Command.rt) { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - if (IsConst(Command.rs)) { - MipsRegState(Command.rt) = STATE_CONST_32; - MipsRegLo(Command.rt) = MipsRegLo(Command.rs) ^ Command.immediate; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_CP0: - switch (Command.rs) { - case R4300i_COP0_MF: - if (Command.rt == 0) { break; } - MipsRegState(Command.rt) = STATE_UNKNOWN; - break; - case R4300i_COP0_MT: break; - default: - if ( (Command.rs & 0x10 ) != 0 ) { - switch( Command.funct ) { - case R4300i_COP0_CO_TLBR: break; - case R4300i_COP0_CO_TLBWI: break; - case R4300i_COP0_CO_TLBWR: break; - case R4300i_COP0_CO_TLBP: break; - case R4300i_COP0_CO_ERET: NextInstruction = END_BLOCK; break; - default: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - } else { - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - } - break; - case R4300i_CP1: - switch (Command.fmt) { - case R4300i_COP1_CF: - case R4300i_COP1_MF: - case R4300i_COP1_DMF: - if (Command.rt == 0) { break; } - MipsRegState(Command.rt) = STATE_UNKNOWN; - break; - case R4300i_COP1_BC: - switch (Command.ft) { - case R4300i_COP1_BC_BCF: - case R4300i_COP1_BC_BCT: - case R4300i_COP1_BC_BCFL: - case R4300i_COP1_BC_BCTL: - NextInstruction = DELAY_SLOT; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - int EffectDelaySlot; - OPCODE NewCommand; - - if (!r4300i_LW_VAddr(Section->CompilePC + 4, &NewCommand.Hex)) { - //DisplayError(GS(MSG_FAIL_LOAD_WORD)); - //ExitThread(0); - StopEmulation(); - } - - EffectDelaySlot = 0; - if (NewCommand.op == R4300i_CP1) { - if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - } - if (!EffectDelaySlot) { - Section->Jump.PermLoop = 1; - } - } - break; - } - break; - case R4300i_COP1_MT: break; - case R4300i_COP1_DMT: break; - case R4300i_COP1_CT: break; - case R4300i_COP1_S: break; - case R4300i_COP1_D: break; - case R4300i_COP1_W: break; - case R4300i_COP1_L: break; - default: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - break; - case R4300i_BEQL: - case R4300i_BNEL: - case R4300i_BLEZL: - case R4300i_BGTZL: - NextInstruction = LIKELY_DELAY_SLOT; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Jump.TargetPC = Section->CompilePC + ((short)Command.offset << 2) + 4; - if (Section->CompilePC == Section->Jump.TargetPC) { - if (!DelaySlotEffectsCompare(Section->CompilePC,Command.rs,Command.rt)) { - Section->Jump.PermLoop = 1; - } - } - break; - case R4300i_DADDI: - case R4300i_DADDIU: - if (Command.rt == 0) { break; } - if (Section->InLoop && Command.rs == Command.rt) { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - if (IsConst(Command.rs)) { - if (Is64Bit(Command.rs)) { - int imm32 = (short)Opcode.immediate; - int64_t imm64 = imm32; - MipsReg_S(Command.rt) = MipsRegLo_S(Command.rs) + imm64; - } else { - MipsReg_S(Command.rt) = MipsRegLo_S(Command.rs) + (short)Command.immediate; - } - MipsRegState(Command.rt) = STATE_CONST_64; - } else { - MipsRegState(Command.rt) = STATE_UNKNOWN; - } - break; - case R4300i_LDR: - case R4300i_LDL: - case R4300i_LB: - case R4300i_LH: - case R4300i_LWL: - case R4300i_LW: - case R4300i_LWU: - case R4300i_LL: - case R4300i_LBU: - case R4300i_LHU: - case R4300i_LWR: - case R4300i_SC: - if (Command.rt == 0) { break; } - MipsRegState(Command.rt) = STATE_UNKNOWN; - break; - case R4300i_SB: break; - case R4300i_SH: break; - case R4300i_SWL: break; - case R4300i_SW: break; - case R4300i_SWR: break; - case R4300i_SDL: break; - case R4300i_SDR: break; - case R4300i_CACHE: break; - case R4300i_LWC1: break; - case R4300i_SWC1: break; - case R4300i_LDC1: break; - case R4300i_LD: - if (Command.rt == 0) { break; } - MipsRegState(Command.rt) = STATE_UNKNOWN; - break; - case R4300i_SDC1: break; - case R4300i_SD: break; - default: - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - if (Command.Hex == 0x7C1C97C0) { break; } - if (Command.Hex == 0x7FFFFFFF) { break; } - if (Command.Hex == 0xF1F3F5F7) { break; } - if (Command.Hex == 0xC1200000) { break; } - if (Command.Hex == 0x4C5A5353) { break; } - } - - switch (NextInstruction) { - case NORMAL: - Section->CompilePC += 4; - break; - case DELAY_SLOT: - NextInstruction = DELAY_SLOT_DONE; - Section->CompilePC += 4; - break; - case LIKELY_DELAY_SLOT: - memcpy(&Section->Cont.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - NextInstruction = LIKELY_DELAY_SLOT_DONE; - Section->CompilePC += 4; - break; - case DELAY_SLOT_DONE: - memcpy(&Section->Cont.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - NextInstruction = END_BLOCK; - break; - case LIKELY_DELAY_SLOT_DONE: - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - NextInstruction = END_BLOCK; - break; - } - if ((Section->CompilePC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) { - if (NextInstruction != END_BLOCK && NextInstruction != NORMAL) { - // DisplayError("Branch running over delay slot ???\nNextInstruction == %d",NextInstruction); - Section->Cont.TargetPC = (uint32_t)-1; - Section->Jump.TargetPC = (uint32_t)-1; - } - NextInstruction = END_BLOCK; - Section->CompilePC -= 4; - } - } while (NextInstruction != END_BLOCK); - - if (Section->Cont.TargetPC != (uint32_t)-1) { - if ((Section->Cont.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) { - Section->Cont.TargetPC = (uint32_t)-1; - } - } - if (Section->Jump.TargetPC != (uint32_t)-1) { - if ((Section->Jump.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) { - Section->Jump.TargetPC = (uint32_t)-1; - } - } -} - -void FixConstants (BLOCK_SECTION * Section, uint32_t Test, int * Changed) { - BLOCK_SECTION * Parent; - int count, NoOfParents; - REG_INFO Original[2]; - - if (Section == NULL) { return; } - if (Section->Test == Test) { return; } - Section->Test = Test; - - InheritConstants(Section); - - memcpy(&Original[0],&Section->Cont.RegSet,sizeof(REG_INFO)); - memcpy(&Original[1],&Section->Jump.RegSet,sizeof(REG_INFO)); - - if (Section->ParentSection) { - for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++) { - Parent = Section->ParentSection[NoOfParents]; - if (Parent->ContinueSection == Section) { - for (count = 0; count < 32; count++) { - if (Section->RegStart.MIPS_RegState[count] != Parent->Cont.RegSet.MIPS_RegState[count]) { - Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN; - //*Changed = 1; - } - Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN; - } - } - if (Parent->JumpSection == Section) { - for (count = 0; count < 32; count++) { - if (Section->RegStart.MIPS_RegState[count] != Parent->Jump.RegSet.MIPS_RegState[count]) { - Section->RegStart.MIPS_RegState[count] = STATE_UNKNOWN; - //*Changed = 1; - } - } - } - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - } - } - FillSectionInfo(Section); - if (memcmp(&Original[0],&Section->Cont.RegSet,sizeof(REG_INFO)) != 0) { *Changed = 1; } - if (memcmp(&Original[1],&Section->Jump.RegSet,sizeof(REG_INFO)) != 0) { *Changed = 1; } - - if (Section->JumpSection) { FixConstants(Section->JumpSection,Test,Changed); } - if (Section->ContinueSection) { FixConstants(Section->ContinueSection,Test,Changed); } -} - -void FixRandomReg (void) { -// while ((int)Registers.CP0[1] < (int)Registers.CP0[6]) { -// Registers.CP0[1] += 32 - Registers.CP0[6]; -// } -} - -void FreeSection (BLOCK_SECTION * Section, BLOCK_SECTION * Parent) { - if (Section == NULL) { return; } - - if (Section->ParentSection) { - int NoOfParents, count; - - for (NoOfParents = 0;Section->ParentSection[NoOfParents] != NULL;NoOfParents++); - - for (count = 0; count < NoOfParents; count++) { - if (Section->ParentSection[count] == Parent) { - if (NoOfParents == 1) { - free(Section->ParentSection); - Section->ParentSection = NULL; - } else { - memmove(&Section->ParentSection[count],&Section->ParentSection[count + 1], - sizeof(void*) * (NoOfParents - count)); - Section->ParentSection = realloc(Section->ParentSection,NoOfParents*sizeof(void *)); - } - NoOfParents -= 1; - } - } - - if (Parent->JumpSection == Section) { Parent->JumpSection = NULL; } - if (Parent->ContinueSection == Section) { Parent->ContinueSection = NULL; } - - if (Section->ParentSection) { - for (count = 0; count < NoOfParents; count++) { - if (!IsAllParentLoops(Section,Section->ParentSection[count],0,GetNewTestValue())) { return; } - } - for (count = 0; count < NoOfParents; count++) { - Parent = Section->ParentSection[count]; - if (Parent->JumpSection == Section) { Parent->JumpSection = NULL; } - if (Parent->ContinueSection == Section) { Parent->ContinueSection = NULL; } - } - free(Section->ParentSection); - Section->ParentSection = NULL; - } - } - if (Section->ParentSection == NULL) { - FreeSection(Section->JumpSection,Section); - FreeSection(Section->ContinueSection,Section); - Section->JumpSection = NULL; - Section->ContinueSection = NULL; - free(Section); - Section = 0; - } -} - -void GenerateBasicSectionLinkage (BLOCK_SECTION * Section) { - //_asm int 3 -} - -void GenerateSectionLinkage (BLOCK_SECTION * Section) { - BLOCK_SECTION * TargetSection[2], *Parent; - JUMP_INFO * JumpInfo[2]; - uint8_t * Jump; - int count; - - TargetSection[0] = Section->ContinueSection; - TargetSection[1] = Section->JumpSection; - JumpInfo[0] = &Section->Cont; - JumpInfo[1] = &Section->Jump; - - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->LinkLocation == NULL && JumpInfo[count]->FallThrough == 0) { - JumpInfo[count]->TargetPC = -1; - } - } - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - //Handle Fall througth - Jump = NULL; - for (count = 0; count < 2; count ++) { - if (!JumpInfo[count]->FallThrough) { continue; } - JumpInfo[count]->FallThrough = 0; - if (JumpInfo[count]->LinkLocation != NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - } - MoveConstToVariable(JumpInfo[count]->TargetPC,&JumpToLocation); - if (JumpInfo[(count + 1) & 1]->LinkLocation == NULL) { break; } - JmpLabel8(0); - Jump = RecompPos - 1; - } - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->LinkLocation == NULL) { continue; } - JumpInfo[count]->FallThrough = 0; - if (JumpInfo[count]->LinkLocation != NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - } - MoveConstToVariable(JumpInfo[count]->TargetPC,&JumpToLocation); - if (JumpInfo[(count + 1) & 1]->LinkLocation == NULL) { break; } - JmpLabel8(0); - Jump = RecompPos - 1; - } - if (Jump != NULL) { - SetJump8(Jump,RecompPos); - } - MoveConstToVariable(Section->CompilePC + 4,&PROGRAM_COUNTER); - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - WriteBackRegisters(Section); - MoveConstToVariable(DELAY_SLOT,&NextInstruction); - Ret(); - return; - } - - if (TargetSection[0] != TargetSection[1] || TargetSection[0] == NULL) { - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->LinkLocation == NULL && JumpInfo[count]->FallThrough == 0) { - FreeSection(TargetSection[count],Section); - } else if (TargetSection[count] == NULL && JumpInfo[count]->FallThrough) { - if (JumpInfo[count]->LinkLocation != NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - } - if (JumpInfo[count]->TargetPC > (Section->CompilePC + 4)) { - CompileExit (JumpInfo[count]->TargetPC,&JumpInfo[count]->RegSet,Normal,1,NULL); - } else { - CompileExit (JumpInfo[count]->TargetPC,&JumpInfo[count]->RegSet,Normal,1,NULL); - } - JumpInfo[count]->FallThrough = 0; - } else if (TargetSection[count] != NULL && JumpInfo[count] != NULL) { - if (!JumpInfo[count]->FallThrough) { continue; } - if (JumpInfo[count]->TargetPC == TargetSection[count]->StartPC) { continue; } - if (JumpInfo[count]->LinkLocation != NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - } - CompileExit (JumpInfo[count]->TargetPC,&JumpInfo[count]->RegSet,Normal,1,NULL); - FreeSection(TargetSection[count],Section); - } - } - } else { - if (Section->Cont.LinkLocation == NULL && Section->Cont.FallThrough == 0) { Section->ContinueSection = NULL; } - if (Section->Jump.LinkLocation == NULL && Section->Jump.FallThrough == 0) { Section->JumpSection = NULL; } - if (Section->JumpSection == NULL && Section->ContinueSection == NULL) { - FreeSection(TargetSection[0],Section); - } - } - - TargetSection[0] = Section->ContinueSection; - TargetSection[1] = Section->JumpSection; - - for (count = 0; count < 2; count ++) { - if (TargetSection[count] == NULL) { continue; } - if (!JumpInfo[count]->FallThrough) { continue; } - - if (TargetSection[count]->CompiledLocation != NULL) { - //char Label[100]; - JumpInfo[count]->FallThrough = 0; - if (JumpInfo[count]->LinkLocation != NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - } - if (JumpInfo[count]->RegSet.RandomModifier != 0) { - SubConstFromVariable(JumpInfo[count]->RegSet.RandomModifier,&CP0[1]); - JumpInfo[count]->RegSet.RandomModifier = 0; - } - if (JumpInfo[count]->RegSet.CycleCount != 0) { - AddConstToVariable(JumpInfo[count]->RegSet.CycleCount,&CP0[9]); - } - if (JumpInfo[count]->TargetPC <= Section->CompilePC) { - uint32_t CycleCount = JumpInfo[count]->RegSet.CycleCount; - JumpInfo[count]->RegSet.CycleCount = 0; - - if (JumpInfo[count]->PermLoop) { - MoveConstToVariable(JumpInfo[count]->TargetPC,&PROGRAM_COUNTER); - Pushad(); - Call_Direct(InPermLoop); - Popad(); - CompileSystemCheck(0,-1,JumpInfo[count]->RegSet); - } else { - CompileSystemCheck(CycleCount,JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet); - } - } else { - if (JumpInfo[count]->RegSet.CycleCount != 0) { - SubConstFromVariable(JumpInfo[count]->RegSet.CycleCount,&Timers->Timer); - JumpInfo[count]->RegSet.CycleCount = 0; - } - } - memcpy(&Section->RegWorking, &JumpInfo[count]->RegSet,sizeof(REG_INFO)); - SyncRegState(Section,&TargetSection[count]->RegStart); - JmpLabel32(0); - SetJump32((uint32_t *)RecompPos - 1,TargetSection[count]->CompiledLocation); - } - } - //Section->CycleCount = 0; - //Section->RandomModifier = 0; - - for (count = 0; count < 2; count ++) { - int count2; - - if (TargetSection[count] == NULL) { continue; } - if (TargetSection[count]->ParentSection == NULL) { continue; } - - for (count2 = 0;TargetSection[count]->ParentSection[count2] != NULL;count2++) { - Parent = TargetSection[count]->ParentSection[count2]; - if (Parent->CompiledLocation != NULL) { continue; } - if (JumpInfo[count]->FallThrough) { - JumpInfo[count]->FallThrough = 0; - //JmpLabel32(JumpInfo[count]->BranchLabel,0); - JmpLabel32(0); - JumpInfo[count]->LinkLocation = RecompPos - 4; - } - } - } - - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->FallThrough) { - if (JumpInfo[count]->TargetPC < Section->CompilePC) { - uint32_t CycleCount = JumpInfo[count]->RegSet.CycleCount;; - - if (JumpInfo[count]->RegSet.RandomModifier != 0) { - SubConstFromVariable(JumpInfo[count]->RegSet.RandomModifier,&CP0[1]); - JumpInfo[count]->RegSet.RandomModifier = 0; - } - if (JumpInfo[count]->RegSet.CycleCount != 0) { - AddConstToVariable(JumpInfo[count]->RegSet.CycleCount,&CP0[9]); - } - JumpInfo[count]->RegSet.CycleCount = 0; - - CompileSystemCheck(CycleCount,JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet); - } - } - } - - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->FallThrough) { - GenerateX86Code(TargetSection[count],GetNewTestValue()); - } - } - - for (count = 0; count < 2; count ++) { - if (JumpInfo[count]->LinkLocation == NULL) { continue; } - if (TargetSection[count] == NULL) { - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - CompileExit (JumpInfo[count]->TargetPC,&JumpInfo[count]->RegSet,Normal,1,NULL); - continue; - } - if (JumpInfo[count]->TargetPC != TargetSection[count]->StartPC) { - //DisplayError("I need to add more code in GenerateSectionLinkage cause this is going to cause an exception"); - //_asm int 3 - } - if (TargetSection[count]->CompiledLocation == NULL) { - GenerateX86Code(TargetSection[count],GetNewTestValue()); - } else { - //char Label[100]; - - SetJump32(JumpInfo[count]->LinkLocation,RecompPos); - JumpInfo[count]->LinkLocation = NULL; - if (JumpInfo[count]->LinkLocation2 != NULL) { - SetJump32(JumpInfo[count]->LinkLocation2,RecompPos); - JumpInfo[count]->LinkLocation2 = NULL; - } - memcpy(&Section->RegWorking,&JumpInfo[count]->RegSet,sizeof(REG_INFO)); - if (JumpInfo[count]->RegSet.RandomModifier != 0) { - SubConstFromVariable(JumpInfo[count]->RegSet.RandomModifier,&CP0[1]); - JumpInfo[count]->RegSet.RandomModifier = 0; - } - if (JumpInfo[count]->RegSet.CycleCount != 0) { - AddConstToVariable(JumpInfo[count]->RegSet.CycleCount,&CP0[9]); - } - if (JumpInfo[count]->TargetPC <= Section->CompilePC) { - uint32_t CycleCount = JumpInfo[count]->RegSet.CycleCount; - JumpInfo[count]->RegSet.CycleCount = 0; - - if (JumpInfo[count]->PermLoop) { - MoveConstToVariable(JumpInfo[count]->TargetPC,&PROGRAM_COUNTER); - Pushad(); - Call_Direct(InPermLoop); - Popad(); - CompileSystemCheck(0,-1,JumpInfo[count]->RegSet); - } else { - CompileSystemCheck(CycleCount,JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet); - } - } else { - if (JumpInfo[count]->RegSet.CycleCount != 0) { - SubConstFromVariable(JumpInfo[count]->RegSet.CycleCount,&Timers->Timer); - JumpInfo[count]->RegSet.CycleCount = 0; - } - } - memcpy(&Section->RegWorking, &JumpInfo[count]->RegSet,sizeof(REG_INFO)); - SyncRegState(Section,&TargetSection[count]->RegStart); - //JmpLabel32(Label,0); - JmpLabel32(0); - SetJump32((uint32_t *)RecompPos - 1,TargetSection[count]->CompiledLocation); - } - } -} - - -uint32_t GenerateX86Code (BLOCK_SECTION * Section, uint32_t Test) { - int count; - - if (Section == NULL) { return 0; } - if (Section->CompiledLocation != NULL) { - if (Section->Test == Test) { return 0; } - Section->Test = Test; - if (GenerateX86Code(Section->ContinueSection,Test)) { return 1; } - if (GenerateX86Code(Section->JumpSection,Test)) { return 1; } - return 0; - } - if (Section->ParentSection) { - for (count = 0;Section->ParentSection[count] != NULL;count++) { - BLOCK_SECTION * Parent; - - Parent = Section->ParentSection[count]; - if (Parent->CompiledLocation != NULL) { continue; } - if (IsAllParentLoops(Section,Parent,1,GetNewTestValue())) { continue; } - return 0; - } - } - if (!InheritParentInfo(Section)) { return 0; } - Section->CompiledLocation = RecompPos; - Section->CompilePC = Section->StartPC; - NextInstruction = NORMAL; - -#ifdef USEX64 - MoveConstQwordToX86reg(TLB_Map, x86_R15); -#endif - - do { - //__try { - if (!r4300i_LW_VAddr(Section->CompilePC, &Opcode.Hex)) { - //DisplayError(GS(MSG_FAIL_LOAD_WORD)); - //ExitThread(0); - StopEmulation(); - } - - BlockCycleCount += 2; - - BlockRandomModifier += 1; - - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - - switch (Opcode.op) { - case R4300i_SPECIAL: - switch (Opcode.funct) { - case R4300i_SPECIAL_SLL: Compile_R4300i_SPECIAL_SLL(Section); break; - case R4300i_SPECIAL_SRL: Compile_R4300i_SPECIAL_SRL(Section); break; - case R4300i_SPECIAL_SRA: Compile_R4300i_SPECIAL_SRA(Section); break; - case R4300i_SPECIAL_SLLV: Compile_R4300i_SPECIAL_SLLV(Section); break; - case R4300i_SPECIAL_SRLV: Compile_R4300i_SPECIAL_SRLV(Section); break; - case R4300i_SPECIAL_SRAV: Compile_R4300i_SPECIAL_SRAV(Section); break; - case R4300i_SPECIAL_JR: Compile_R4300i_SPECIAL_JR(Section); break; - case R4300i_SPECIAL_JALR: Compile_R4300i_SPECIAL_JALR(Section); break; - case R4300i_SPECIAL_MFLO: Compile_R4300i_SPECIAL_MFLO(Section); break; - case R4300i_SPECIAL_SYSCALL: Compile_R4300i_SPECIAL_SYSCALL(Section); break; - case R4300i_SPECIAL_BREAK: Compile_R4300i_SPECIAL_BREAK(Section); break; - case R4300i_SPECIAL_MTLO: Compile_R4300i_SPECIAL_MTLO(Section); break; - case R4300i_SPECIAL_MFHI: Compile_R4300i_SPECIAL_MFHI(Section); break; - case R4300i_SPECIAL_MTHI: Compile_R4300i_SPECIAL_MTHI(Section); break; - case R4300i_SPECIAL_DSLLV: Compile_R4300i_SPECIAL_DSLLV(Section); break; - case R4300i_SPECIAL_DSRLV: Compile_R4300i_SPECIAL_DSRLV(Section); break; - case R4300i_SPECIAL_DSRAV: Compile_R4300i_SPECIAL_DSRAV(Section); break; - case R4300i_SPECIAL_MULT: Compile_R4300i_SPECIAL_MULT(Section); break; - case R4300i_SPECIAL_DIV: Compile_R4300i_SPECIAL_DIV(Section); break; - case R4300i_SPECIAL_DIVU: Compile_R4300i_SPECIAL_DIVU(Section); break; - case R4300i_SPECIAL_MULTU: Compile_R4300i_SPECIAL_MULTU(Section); break; - case R4300i_SPECIAL_DMULT: Compile_R4300i_SPECIAL_DMULT(Section); break; - case R4300i_SPECIAL_DMULTU: Compile_R4300i_SPECIAL_DMULTU(Section); break; - case R4300i_SPECIAL_DDIV: Compile_R4300i_SPECIAL_DDIV(Section); break; - case R4300i_SPECIAL_DDIVU: Compile_R4300i_SPECIAL_DDIVU(Section); break; - case R4300i_SPECIAL_ADD: Compile_R4300i_SPECIAL_ADD(Section); break; - case R4300i_SPECIAL_ADDU: Compile_R4300i_SPECIAL_ADDU(Section); break; - case R4300i_SPECIAL_SUB: Compile_R4300i_SPECIAL_SUB(Section); break; - case R4300i_SPECIAL_SUBU: Compile_R4300i_SPECIAL_SUBU(Section); break; - case R4300i_SPECIAL_AND: Compile_R4300i_SPECIAL_AND(Section); break; - case R4300i_SPECIAL_OR: Compile_R4300i_SPECIAL_OR(Section); break; - case R4300i_SPECIAL_XOR: Compile_R4300i_SPECIAL_XOR(Section); break; - case R4300i_SPECIAL_NOR: Compile_R4300i_SPECIAL_NOR(Section); break; - case R4300i_SPECIAL_SLT: Compile_R4300i_SPECIAL_SLT(Section); break; - case R4300i_SPECIAL_SLTU: Compile_R4300i_SPECIAL_SLTU(Section); break; - case R4300i_SPECIAL_DADD: Compile_R4300i_SPECIAL_DADD(Section); break; - case R4300i_SPECIAL_DADDU: Compile_R4300i_SPECIAL_DADDU(Section); break; - case R4300i_SPECIAL_DSUB: Compile_R4300i_SPECIAL_DSUB(Section); break; - case R4300i_SPECIAL_DSUBU: Compile_R4300i_SPECIAL_DSUBU(Section); break; - case R4300i_SPECIAL_DSLL: Compile_R4300i_SPECIAL_DSLL(Section); break; - case R4300i_SPECIAL_DSRL: Compile_R4300i_SPECIAL_DSRL(Section); break; - case R4300i_SPECIAL_DSRA: Compile_R4300i_SPECIAL_DSRA(Section); break; - case R4300i_SPECIAL_DSLL32: Compile_R4300i_SPECIAL_DSLL32(Section); break; - case R4300i_SPECIAL_DSRL32: Compile_R4300i_SPECIAL_DSRL32(Section); break; - case R4300i_SPECIAL_DSRA32: Compile_R4300i_SPECIAL_DSRA32(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_REGIMM: - switch (Opcode.rt) { - case R4300i_REGIMM_BLTZ:Compile_R4300i_Branch(Section,BLTZ_Compare,BranchTypeRs, 0); break; - case R4300i_REGIMM_BGEZ:Compile_R4300i_Branch(Section,BGEZ_Compare,BranchTypeRs, 0); break; - case R4300i_REGIMM_BLTZL:Compile_R4300i_BranchLikely(Section,BLTZ_Compare, 0); break; - case R4300i_REGIMM_BGEZL:Compile_R4300i_BranchLikely(Section,BGEZ_Compare, 0); break; - case R4300i_REGIMM_BLTZAL:Compile_R4300i_Branch(Section,BLTZ_Compare,BranchTypeRs, 1); break; - case R4300i_REGIMM_BGEZAL:Compile_R4300i_Branch(Section,BGEZ_Compare,BranchTypeRs, 1); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_BEQ: Compile_R4300i_Branch(Section,BEQ_Compare,BranchTypeRsRt,0); break; - case R4300i_BNE: Compile_R4300i_Branch(Section,BNE_Compare,BranchTypeRsRt,0); break; - case R4300i_BGTZ:Compile_R4300i_Branch(Section,BGTZ_Compare,BranchTypeRs,0); break; - case R4300i_BLEZ:Compile_R4300i_Branch(Section,BLEZ_Compare,BranchTypeRs,0); break; - case R4300i_J: Compile_R4300i_J(Section); break; - case R4300i_JAL: Compile_R4300i_JAL(Section); break; - case R4300i_ADDI: Compile_R4300i_ADDI(Section); break; - case R4300i_ADDIU: Compile_R4300i_ADDIU(Section); break; - case R4300i_SLTI: Compile_R4300i_SLTI(Section); break; - case R4300i_SLTIU: Compile_R4300i_SLTIU(Section); break; - case R4300i_ANDI: Compile_R4300i_ANDI(Section); break; - case R4300i_ORI: Compile_R4300i_ORI(Section); break; - case R4300i_XORI: Compile_R4300i_XORI(Section); break; - case R4300i_LUI: Compile_R4300i_LUI(Section); break; - case R4300i_CP0: - switch (Opcode.rs) { - case R4300i_COP0_MF: Compile_R4300i_COP0_MF(Section); break; - case R4300i_COP0_MT: Compile_R4300i_COP0_MT(Section); break; - default: - if ( (Opcode.rs & 0x10 ) != 0 ) { - switch( Opcode.funct ) { - case R4300i_COP0_CO_TLBR: Compile_R4300i_COP0_CO_TLBR(Section); break; - case R4300i_COP0_CO_TLBWI: Compile_R4300i_COP0_CO_TLBWI(Section); break; - case R4300i_COP0_CO_TLBWR: Compile_R4300i_COP0_CO_TLBWR(Section); break; - case R4300i_COP0_CO_TLBP: Compile_R4300i_COP0_CO_TLBP(Section); break; - case R4300i_COP0_CO_ERET: Compile_R4300i_COP0_CO_ERET(Section); break; - default: Compile_R4300i_UnknownOpcode(Section); break; - } - } else { - Compile_R4300i_UnknownOpcode(Section); - } - } - break; - case R4300i_CP1: - switch (Opcode.rs) { - case R4300i_COP1_MF: Compile_R4300i_COP1_MF(Section); break; - case R4300i_COP1_DMF: Compile_R4300i_COP1_DMF(Section); break; - case R4300i_COP1_CF: Compile_R4300i_COP1_CF(Section); break; - case R4300i_COP1_MT: Compile_R4300i_COP1_MT(Section); break; - case R4300i_COP1_DMT: Compile_R4300i_COP1_DMT(Section); break; - case R4300i_COP1_CT: Compile_R4300i_COP1_CT(Section); break; - case R4300i_COP1_BC: - switch (Opcode.ft) { - case R4300i_COP1_BC_BCF: Compile_R4300i_Branch(Section,COP1_BCF_Compare,BranchTypeCop1,0); break; - case R4300i_COP1_BC_BCT: Compile_R4300i_Branch(Section,COP1_BCT_Compare,BranchTypeCop1,0); break; - case R4300i_COP1_BC_BCFL: Compile_R4300i_BranchLikely(Section,COP1_BCF_Compare,0); break; - case R4300i_COP1_BC_BCTL: Compile_R4300i_BranchLikely(Section,COP1_BCT_Compare,0); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_S: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_S_ADD(Section); break; - case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_S_SUB(Section); break; - case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_S_MUL(Section); break; - case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_S_DIV(Section); break; - case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_S_ABS(Section); break; - case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_S_NEG(Section); break; - case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_S_SQRT(Section); break; - case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_S_MOV(Section); break; - case R4300i_COP1_FUNCT_TRUNC_L: Compile_R4300i_COP1_S_TRUNC_L(Section); break; - case R4300i_COP1_FUNCT_CEIL_L: Compile_R4300i_COP1_S_CEIL_L(Section); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_L: Compile_R4300i_COP1_S_FLOOR_L(Section); break; //added by Witten - case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_S_ROUND_W(Section); break; - case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_S_TRUNC_W(Section); break; - case R4300i_COP1_FUNCT_CEIL_W: Compile_R4300i_COP1_S_CEIL_W(Section); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_S_FLOOR_W(Section); break; - case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_S_CVT_D(Section); break; - case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_S_CVT_W(Section); break; - case R4300i_COP1_FUNCT_CVT_L: Compile_R4300i_COP1_S_CVT_L(Section); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - Compile_R4300i_COP1_S_CMP(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_D: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_D_ADD(Section); break; - case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_D_SUB(Section); break; - case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_D_MUL(Section); break; - case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_D_DIV(Section); break; - case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_D_ABS(Section); break; - case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_D_NEG(Section); break; - case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_D_SQRT(Section); break; - case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_D_MOV(Section); break; - case R4300i_COP1_FUNCT_TRUNC_L: Compile_R4300i_COP1_D_TRUNC_L(Section); break; //added by Witten - case R4300i_COP1_FUNCT_CEIL_L: Compile_R4300i_COP1_D_CEIL_L(Section); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_L: Compile_R4300i_COP1_D_FLOOR_L(Section); break; //added by Witten - case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_D_ROUND_W(Section); break; - case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_D_TRUNC_W(Section); break; - case R4300i_COP1_FUNCT_CEIL_W: Compile_R4300i_COP1_D_CEIL_W(Section); break; //added by Witten - case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_D_FLOOR_W(Section); break; //added by Witten - case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_D_CVT_S(Section); break; - case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_D_CVT_W(Section); break; - case R4300i_COP1_FUNCT_CVT_L: Compile_R4300i_COP1_D_CVT_L(Section); break; - case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: - case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: - case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: - case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: - case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: - case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: - case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: - case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: - Compile_R4300i_COP1_D_CMP(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_W: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_W_CVT_S(Section); break; - case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_W_CVT_D(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_COP1_L: - switch (Opcode.funct) { - case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_L_CVT_S(Section); break; - case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_L_CVT_D(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - break; - case R4300i_BEQL: Compile_R4300i_BranchLikely(Section,BEQ_Compare,0); break; - case R4300i_BNEL: Compile_R4300i_BranchLikely(Section,BNE_Compare,0); break; - case R4300i_BGTZL:Compile_R4300i_BranchLikely(Section,BGTZ_Compare,0); break; - case R4300i_BLEZL:Compile_R4300i_BranchLikely(Section,BLEZ_Compare,0); break; - case R4300i_DADDIU: Compile_R4300i_DADDIU(Section); break; - case R4300i_LDL: Compile_R4300i_LDL(Section); break; - case R4300i_LDR: Compile_R4300i_LDR(Section); break; - case R4300i_LB: Compile_R4300i_LB(Section); break; - case R4300i_LH: Compile_R4300i_LH(Section); break; - case R4300i_LWL: Compile_R4300i_LWL(Section); break; - case R4300i_LW: Compile_R4300i_LW(Section); break; - case R4300i_LBU: Compile_R4300i_LBU(Section); break; - case R4300i_LHU: Compile_R4300i_LHU(Section); break; - case R4300i_LWR: Compile_R4300i_LWR(Section); break; - case R4300i_LWU: Compile_R4300i_LWU(Section); break; //added by Witten - case R4300i_SB: Compile_R4300i_SB(Section); break; - case R4300i_SH: Compile_R4300i_SH(Section); break; - case R4300i_SWL: Compile_R4300i_SWL(Section); break; - case R4300i_SW: Compile_R4300i_SW(Section); break; - case R4300i_SWR: Compile_R4300i_SWR(Section); break; - case R4300i_SDL: Compile_R4300i_SDL(Section); break; - case R4300i_SDR: Compile_R4300i_SDR(Section); break; - case R4300i_CACHE: Compile_R4300i_CACHE(Section); break; - case R4300i_LL: Compile_R4300i_LL(Section); break; - case R4300i_LWC1: Compile_R4300i_LWC1(Section); break; - case R4300i_LDC1: Compile_R4300i_LDC1(Section); break; - case R4300i_SC: Compile_R4300i_SC(Section); break; - case R4300i_LD: Compile_R4300i_LD(Section); break; - case R4300i_SWC1: Compile_R4300i_SWC1(Section); break; - case R4300i_SDC1: Compile_R4300i_SDC1(Section); break; - case R4300i_SD: Compile_R4300i_SD(Section); break; - default: - Compile_R4300i_UnknownOpcode(Section); break; - } - - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - - UnMap_AllFPRs(Section); - - if ((Section->CompilePC &0xFFC) == 0xFFC) { - if (NextInstruction == DO_DELAY_SLOT) { - } - if (NextInstruction == NORMAL) { - CompileExit (Section->CompilePC + 4,&Section->RegWorking,Normal,1,NULL); - NextInstruction = END_BLOCK; - } - } - - switch (NextInstruction) { - case NORMAL: - Section->CompilePC += 4; - break; - case DO_DELAY_SLOT: - NextInstruction = DELAY_SLOT; - Section->CompilePC += 4; - break; - case DELAY_SLOT: - NextInstruction = DELAY_SLOT_DONE; - BlockCycleCount -= 2; - BlockRandomModifier -= 1; - Section->CompilePC -= 4; - break; - } - - } while (NextInstruction != END_BLOCK); - - return 1; -} - -uint32_t GetNewTestValue(void) { - static uint32_t LastTest = 0; - if (LastTest == 0xFFFFFFFF) { LastTest = 0; } - LastTest += 1; - return LastTest; -} - -void InitilizeRegSet(REG_INFO * RegSet) { - int count; - - RegSet->MIPS_RegState[0] = STATE_CONST_32; - RegSet->MIPS_RegVal[0].DW = 0; - for (count = 1; count < 32; count ++ ) { - RegSet->MIPS_RegState[count] = STATE_UNKNOWN; - RegSet->MIPS_RegVal[count].DW = 0; - - } - for (count = 0; count < 64; count ++ ) { - RegSet->x86reg_MappedTo[count] = NotMapped; - RegSet->x86reg_Protected[count] = 0; - RegSet->x86reg_MapOrder[count] = 0; - } - RegSet->CycleCount = 0; - RegSet->RandomModifier = 0; - - RegSet->Stack_TopPos = 0; - for (count = 0; count < 8; count ++ ) { - RegSet->x86fpu_MappedTo[count] = -1; - RegSet->x86fpu_State[count] = FPU_Unkown; - RegSet->x86fpu_RoundingModel[count] = RoundDefault; - } - RegSet->Fpu_Used = 0; - RegSet->RoundingModel = RoundUnknown; -} - -void InheritConstants(BLOCK_SECTION * Section) { - int NoOfParents, count; - BLOCK_SECTION * Parent; - REG_INFO * RegSet; - - - if (Section->ParentSection == NULL) { - InitilizeRegSet(&Section->RegStart); - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - return; - } - - Parent = Section->ParentSection[0]; - RegSet = Section == Parent->ContinueSection?&Parent->Cont.RegSet:&Parent->Jump.RegSet; - memcpy(&Section->RegStart,RegSet,sizeof(REG_INFO)); - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - - for (NoOfParents = 1;Section->ParentSection[NoOfParents] != NULL;NoOfParents++) { - Parent = Section->ParentSection[NoOfParents]; - RegSet = Section == Parent->ContinueSection?&Parent->Cont.RegSet:&Parent->Jump.RegSet; - - for (count = 0; count < 32; count++) { - if (IsConst(count)) { - if (MipsRegState(count) != RegSet->MIPS_RegState[count]) { - MipsRegState(count) = STATE_UNKNOWN; - } else if (Is32Bit(count) && MipsRegLo(count) != RegSet->MIPS_RegVal[count].UW[0]) { - MipsRegState(count) = STATE_UNKNOWN; - } else if (Is64Bit(count) && MipsReg(count) != RegSet->MIPS_RegVal[count].UDW) { - MipsRegState(count) = STATE_UNKNOWN; - } - } - } - } - memcpy(&Section->RegStart,&Section->RegWorking,sizeof(REG_INFO)); -} - -uint32_t InheritParentInfo (BLOCK_SECTION * Section) { - int count, start, NoOfParents, NoOfCompiledParents, FirstParent,CurrentParent; - BLOCK_PARENT * SectionParents; - BLOCK_SECTION * Parent; - JUMP_INFO * JumpInfo; - //char Label[100]; - uint32_t NeedSync; - - DisplaySectionInformation(Section,Section->SectionID,GetNewTestValue()); - - if (Section->ParentSection == NULL) { - InitilizeRegSet(&Section->RegStart); - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - return 1; - } - - NoOfParents = 0; - for (count = 0;Section->ParentSection[count] != NULL;count++) { - Parent = Section->ParentSection[count]; - NoOfParents += Parent->JumpSection != Parent->ContinueSection?1:2; - } - - if (NoOfParents == 0) { - return 0; - } else if (NoOfParents == 1) { - Parent = Section->ParentSection[0]; - if (Section == Parent->ContinueSection) { JumpInfo = &Parent->Cont; } - else if (Section == Parent->JumpSection) { JumpInfo = &Parent->Jump; } - else { - } - - memcpy(&Section->RegStart,&JumpInfo->RegSet,sizeof(REG_INFO)); - if (JumpInfo->LinkLocation != NULL) { - SetJump32(JumpInfo->LinkLocation,RecompPos); - if (JumpInfo->LinkLocation2 != NULL) { - SetJump32(JumpInfo->LinkLocation2,RecompPos); - } - } - memcpy(&Section->RegWorking,&Section->RegStart,sizeof(REG_INFO)); - return 1; - } - - //Multiple Parents - for (count = 0, NoOfCompiledParents = 0;Section->ParentSection[count] != NULL;count++) { - Parent = Section->ParentSection[count]; - if (Parent->CompiledLocation != NULL) { - NoOfCompiledParents += Parent->JumpSection != Parent->ContinueSection?1:2; - } - } - if (NoOfCompiledParents == 0){ return 0; } - SectionParents = (BLOCK_PARENT *)malloc(NoOfParents * sizeof(BLOCK_PARENT)); - - for (count = 0, NoOfCompiledParents = 0;Section->ParentSection[count] != NULL;count++) { - Parent = Section->ParentSection[count]; - if (Parent->CompiledLocation == NULL) { continue; } - if (Parent->JumpSection != Parent->ContinueSection) { - SectionParents[NoOfCompiledParents].Parent = Parent; - SectionParents[NoOfCompiledParents].JumpInfo = - Section == Parent->ContinueSection?&Parent->Cont:&Parent->Jump; - NoOfCompiledParents += 1; - } else { - SectionParents[NoOfCompiledParents].Parent = Parent; - SectionParents[NoOfCompiledParents].JumpInfo = &Parent->Cont; - NoOfCompiledParents += 1; - SectionParents[NoOfCompiledParents].Parent = Parent; - SectionParents[NoOfCompiledParents].JumpInfo = &Parent->Jump; - NoOfCompiledParents += 1; - } - } - - start = NoOfCompiledParents; - for (count = 0;Section->ParentSection[count] != NULL;count++) { - Parent = Section->ParentSection[count]; - if (Parent->CompiledLocation != NULL) { continue; } - if (Parent->JumpSection != Parent->ContinueSection) { - SectionParents[start].Parent = Parent; - SectionParents[start].JumpInfo = - Section == Parent->ContinueSection?&Parent->Cont:&Parent->Jump; - start += 1; - } else { - SectionParents[start].Parent = Parent; - SectionParents[start].JumpInfo = &Parent->Cont; - start += 1; - SectionParents[start].Parent = Parent; - SectionParents[start].JumpInfo = &Parent->Jump; - start += 1; - } - } - FirstParent = 0; - for (count = 1;count < NoOfCompiledParents;count++) { - if (SectionParents[count].JumpInfo->FallThrough) { - FirstParent = count; break; - } - } - - //Link First Parent to start - Parent = SectionParents[FirstParent].Parent; - JumpInfo = SectionParents[FirstParent].JumpInfo; - - memcpy(&Section->RegWorking,&JumpInfo->RegSet,sizeof(REG_INFO)); - if (JumpInfo->LinkLocation != NULL) { - SetJump32(JumpInfo->LinkLocation,RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) { - SetJump32(JumpInfo->LinkLocation2,RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - JumpInfo->FallThrough = 0; - - //Fix up initial state - UnMap_AllFPRs(Section); - for (count = 0;count < NoOfParents;count++) { - int count2, count3; - REG_INFO * RegSet; - - if (count == FirstParent) { continue; } - Parent = SectionParents[count].Parent; - RegSet = &SectionParents[count].JumpInfo->RegSet; - - if (CurrentRoundingModel != RegSet->RoundingModel) { CurrentRoundingModel = RoundUnknown; } - if (NoOfParents != NoOfCompiledParents) { CurrentRoundingModel = RoundUnknown; } - - for (count2 = 1; count2 < 32; count2++) { - if (Is32BitMapped(count2)) { - switch (RegSet->MIPS_RegState[count2]) { - case STATE_MAPPED_64: Map_GPR_64bit(Section,count2,count2); break; - case STATE_MAPPED_32_ZERO: break; - case STATE_MAPPED_32_SIGN: - if (IsUnsigned(count2)) { - MipsRegState(count2) = STATE_MAPPED_32_SIGN; - } - break; - case STATE_CONST_64: Map_GPR_64bit(Section,count2,count2); break; - case STATE_CONST_32: - if ((RegSet->MIPS_RegVal[count2].W[0] < 0) && IsUnsigned(count2)) { - MipsRegState(count2) = STATE_MAPPED_32_SIGN; - } - break; - case STATE_UNKNOWN: - //Map_GPR_32bit(Section,count2,1,count2); - Map_GPR_64bit(Section,count2,count2); //?? - //UnMap_GPR(Section,count2,1); ?? - break; - } - } - if (IsConst(count2)) { - if (MipsRegState(count2) != RegSet->MIPS_RegState[count2]) { - if (Is32Bit(count2)) { - Map_GPR_32bit(Section,count2,1,count2); - } else { - Map_GPR_32bit(Section,count2,1,count2); - } - } else if (Is32Bit(count2) && MipsRegLo(count2) != RegSet->MIPS_RegVal[count2].UW[0]) { - Map_GPR_32bit(Section,count2,1,count2); - } else if (Is64Bit(count2) && MipsReg(count2) != RegSet->MIPS_RegVal[count2].UDW) { - Map_GPR_32bit(Section,count2,1,count2); - } - } - for (count3 = 1; count3 < 64; count3 ++) { x86Protected(count3) = 0; } - } - } - memcpy(&Section->RegStart,&Section->RegWorking,sizeof(REG_INFO)); - - //Sync registers for different blocks -// sprintf(Label,"Section_%d",Section->SectionID); - CurrentParent = FirstParent; - NeedSync = 0; - for (count = 0;count < NoOfCompiledParents;count++) { - REG_INFO * RegSet; - int count2; - - if (count == FirstParent) { continue; } - Parent = SectionParents[count].Parent; - JumpInfo = SectionParents[count].JumpInfo; - RegSet = &SectionParents[count].JumpInfo->RegSet; - - if (JumpInfo->RegSet.CycleCount != 0) { NeedSync = 1; } - if (JumpInfo->RegSet.RandomModifier != 0) { NeedSync = 1; } - - for (count2 = 0; count2 < 8; count2++) { - if (FpuMappedTo(count2) == (uint32_t)-1) { - NeedSync = 1; - } - } - - for (count2 = 0; count2 < 32; count2++) { - if (NeedSync == 1) { break; } - if (MipsRegState(count2) != RegSet->MIPS_RegState[count2]) { - NeedSync = 1; - continue; - } - switch (MipsRegState(count2)) { - case STATE_UNKNOWN: break; - case STATE_MAPPED_64: - if (MipsReg(count2) != RegSet->MIPS_RegVal[count2].UDW) { - NeedSync = 1; - } - break; - case STATE_MAPPED_32_ZERO: - case STATE_MAPPED_32_SIGN: - if (MipsRegLo(count2) != RegSet->MIPS_RegVal[count2].UW[0]) { - //DisplayError("Parent: %d",Parent->SectionID); - NeedSync = 1; - } - break; - case STATE_CONST_32: - if (MipsRegLo(count2) != RegSet->MIPS_RegVal[count2].UW[0]) { - NeedSync = 1; - } - break; - } - } - if (NeedSync == 0) { continue; } - Parent = SectionParents[CurrentParent].Parent; - JumpInfo = SectionParents[CurrentParent].JumpInfo; - //JmpLabel32(Label,0); - JmpLabel32(0); - JumpInfo->LinkLocation = RecompPos - 4; - JumpInfo->LinkLocation2 = NULL; - - CurrentParent = count; - Parent = SectionParents[CurrentParent].Parent; - JumpInfo = SectionParents[CurrentParent].JumpInfo; - if (JumpInfo->LinkLocation != NULL) { - SetJump32(JumpInfo->LinkLocation,RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) { - SetJump32(JumpInfo->LinkLocation2,RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } - memcpy(&Section->RegWorking,&JumpInfo->RegSet,sizeof(REG_INFO)); - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - SyncRegState(Section,&Section->RegStart); //Sync - memcpy(&Section->RegStart,&Section->RegWorking,sizeof(REG_INFO)); - - } - - for (count = 0;count < NoOfCompiledParents;count++) { - Parent = SectionParents[count].Parent; - JumpInfo = SectionParents[count].JumpInfo; - - if (JumpInfo->LinkLocation != NULL) { - SetJump32(JumpInfo->LinkLocation,RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) { - SetJump32(JumpInfo->LinkLocation2,RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - } - } - - BlockCycleCount = 0; - BlockRandomModifier = 0; - free(SectionParents); - SectionParents = NULL; - return 1; -} - -uint32_t IsAllParentLoops(BLOCK_SECTION * Section, BLOCK_SECTION * Parent, uint32_t IgnoreIfCompiled, uint32_t Test) { - int count; - - if (IgnoreIfCompiled && Parent->CompiledLocation != NULL) { return 1; } - if (!Section->InLoop) { return 0; } - if (!Parent->InLoop) { return 0; } - if (Parent->ParentSection == NULL) { return 0; } - if (Section == Parent) { return 1; } - if (Parent->Test == Test) { return 1; } - Parent->Test = Test; - - for (count = 0;Parent->ParentSection[count] != NULL;count++) { - if (!IsAllParentLoops(Section,Parent->ParentSection[count],IgnoreIfCompiled,Test)) { return 0; } - } - return 1; -} - -void InitilzeSection (BLOCK_SECTION * Section, BLOCK_SECTION * Parent, uint32_t StartAddr, uint32_t ID) { - Section->ParentSection = NULL; - Section->JumpSection = NULL; - Section->ContinueSection = NULL; - Section->CompiledLocation = NULL; - - Section->SectionID = ID; - Section->Test = 0; - Section->Test2 = 0; - Section->InLoop = 0; - - Section->StartPC = StartAddr; - Section->CompilePC = Section->StartPC; - - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - Section->Jump.FallThrough = 0; - Section->Jump.PermLoop = 0; - Section->Jump.TargetPC = (uint32_t)-1; - Section->Cont.LinkLocation = NULL; - Section->Cont.LinkLocation2 = NULL; - Section->Cont.FallThrough = 0; - Section->Cont.PermLoop = 0; - Section->Cont.TargetPC = (uint32_t)-1; - - AddParent(Section,Parent); -} - -void MarkCodeBlock (uint32_t PAddr) { - if (PAddr < RdramSize) { - N64_Blocks.NoOfRDRamBlocks[PAddr >> 12] += 1; - } else if (PAddr >= 0x04000000 && PAddr <= 0x04000FFC) { - N64_Blocks.NoOfDMEMBlocks += 1; - } else if (PAddr >= 0x04001000 && PAddr <= 0x04001FFC) { - N64_Blocks.NoOfIMEMBlocks += 1; - } else if (PAddr >= 0x1FC00000 && PAddr <= 0x1FC00800) { - N64_Blocks.NoOfPifRomBlocks += 1; - } else { - } -} - -extern uint8_t * MemChunk; - -void CallBlock(void (*block)(void)) { - -#ifdef USEX64 - // Make sure the Memory block pointer is in register R15 - __asm__ __volatile__("mov %%rax, %%r15" : : "a"(MemChunk)); - __asm__ __volatile__("pushq %rbx"); - __asm__ __volatile__("pushq %rcx"); - __asm__ __volatile__("pushq %rdx"); - __asm__ __volatile__("pushq %r9"); - __asm__ __volatile__("pushq %r10"); - __asm__ __volatile__("pushq %r11"); - __asm__ __volatile__("pushq %r12"); - __asm__ __volatile__("pushq %r13"); - __asm__ __volatile__("pushq %r14"); - __asm__ __volatile__("pushq %r15"); - - block(); - - __asm__ __volatile__("popq %r15"); - __asm__ __volatile__("popq %r14"); - __asm__ __volatile__("popq %r13"); - __asm__ __volatile__("popq %r12"); - __asm__ __volatile__("popq %r11"); - __asm__ __volatile__("popq %r10"); - __asm__ __volatile__("popq %r9"); - __asm__ __volatile__("popq %rdx"); - __asm__ __volatile__("popq %rcx"); - __asm__ __volatile__("popq %rbx"); -#else - __asm__ __volatile__("pusha"); - block(); - __asm__ __volatile__("popa"); -#endif - -} -//#include -//int r4300i_CPU_MemoryFilter64( DWORD dwExptCode, LPEXCEPTION_POINTERS lpEP); - -uint32_t lastgood = 0; - - -void StartRecompilerCPU (void ) { - uintptr_t Addr; - void (*Block)(void) = 0; - - InitExceptionHandler(); - - ResetRecompCode(); - memset(&N64_Blocks,0,sizeof(N64_Blocks)); - NextInstruction = NORMAL; - - //__try { - - //for (;;) { - while(cpu_running == 1) { - - if(PROGRAM_COUNTER < 0x90000000) - lastgood = PROGRAM_COUNTER; - Addr = PROGRAM_COUNTER; - if (!TranslateVaddr(&Addr)) { - DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER); - NextInstruction = NORMAL; - Addr = PROGRAM_COUNTER; - if (!TranslateVaddr(&Addr)) { - StopEmulation(); - } - } - if (NextInstruction == DELAY_SLOT) { - Block = *(DelaySlotTable + (Addr >> 12)); - - if (Block == NULL) { - Block = CompileDelaySlot(); - - *(DelaySlotTable + (Addr >> 12)) = Block; - - NextInstruction = NORMAL; - } - - CallBlock(Block); - - continue; - } - - - if (Addr > 0x10000000) - { - if (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) { - while (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) { - ExecuteInterpreterOpCode(); - } - continue; - } else { - - StopEmulation(); - } - } - - Block = *(JumpTable + (Addr >> 2)); - - - if (Block == NULL) { - Block = Compiler4300iBlock(); - - *(JumpTable + (Addr >> 2)) = Block; - - NextInstruction = NORMAL; - } - - - CallBlock(Block); - } - - cpu_stopped = 1; -} - - -void SyncRegState (BLOCK_SECTION * Section, REG_INFO * SyncTo) { - int count, x86Reg,x86RegHi, changed; - - changed = 0; - UnMap_AllFPRs(Section); - if (CurrentRoundingModel != SyncTo->RoundingModel) { CurrentRoundingModel = RoundUnknown; } - - for (count = 1; count < 32; count ++) { - if (MipsRegState(count) == SyncTo->MIPS_RegState[count]) { - switch (MipsRegState(count)) { - case STATE_UNKNOWN: continue; - case STATE_MAPPED_64: - if (MipsReg(count) == SyncTo->MIPS_RegVal[count].UDW) { - continue; - } - break; - case STATE_MAPPED_32_ZERO: - case STATE_MAPPED_32_SIGN: - if (MipsRegLo(count) == SyncTo->MIPS_RegVal[count].UW[0]) { - continue; - } - break; - case STATE_CONST_64: - if (MipsReg(count) != SyncTo->MIPS_RegVal[count].UDW) { - } - continue; - case STATE_CONST_32: - if (MipsRegLo(count) != SyncTo->MIPS_RegVal[count].UW[0]) { - } - continue; - } - } - changed = 1; - - switch (SyncTo->MIPS_RegState[count]) { - case STATE_UNKNOWN: UnMap_GPR(Section,count,1); break; - case STATE_MAPPED_64: - x86Reg = SyncTo->MIPS_RegVal[count].UW[0]; - x86RegHi = SyncTo->MIPS_RegVal[count].UW[1]; - UnMap_X86reg(Section,x86Reg); - UnMap_X86reg(Section,x86RegHi); - switch (MipsRegState(count)) { - case STATE_UNKNOWN: - MoveVariableToX86reg(&GPR[count].UW[0],x86Reg); - MoveVariableToX86reg(&GPR[count].UW[1],x86RegHi); - break; - case STATE_MAPPED_64: - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - MoveX86RegToX86Reg(MipsRegHi(count),x86RegHi); - x86Mapped(MipsRegHi(count)) = NotMapped; - break; - case STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(MipsRegLo(count),x86RegHi); - ShiftRightSignImmed(x86RegHi,31); - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - break; - case STATE_MAPPED_32_ZERO: - XorX86RegToX86Reg(x86RegHi,x86RegHi); - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - break; - case STATE_CONST_64: - MoveConstToX86reg(MipsRegHi(count),x86RegHi); - MoveConstToX86reg(MipsRegLo(count),x86Reg); - break; - case STATE_CONST_32: - MoveConstToX86reg(MipsRegLo_S(count) >> 31,x86RegHi); - MoveConstToX86reg(MipsRegLo(count),x86Reg); - break; - default: - continue; - } - MipsRegLo(count) = x86Reg; - MipsRegHi(count) = x86RegHi; - MipsRegState(count) = STATE_MAPPED_64; - x86Mapped(x86Reg) = GPR_Mapped; - x86Mapped(x86RegHi) = GPR_Mapped; - x86MapOrder(x86Reg) = 1; - x86MapOrder(x86RegHi) = 1; - break; - case STATE_MAPPED_32_SIGN: - x86Reg = SyncTo->MIPS_RegVal[count].UW[0]; - UnMap_X86reg(Section,x86Reg); - switch (MipsRegState(count)) { - case STATE_UNKNOWN: MoveVariableToX86reg(&GPR[count].UW[0],x86Reg); break; - case STATE_CONST_32: MoveConstToX86reg(MipsRegLo(count),x86Reg); break; - case STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - break; - case STATE_MAPPED_32_ZERO: - if (MipsRegLo(count) != (uint32_t)x86Reg) { - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - } - break; - case STATE_MAPPED_64: - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - x86Mapped(MipsRegHi(count)) = NotMapped; - break; - } - MipsRegLo(count) = x86Reg; - MipsRegState(count) = STATE_MAPPED_32_SIGN; - x86Mapped(x86Reg) = GPR_Mapped; - x86MapOrder(x86Reg) = 1; - break; - case STATE_MAPPED_32_ZERO: - x86Reg = SyncTo->MIPS_RegVal[count].UW[0]; - UnMap_X86reg(Section,x86Reg); - switch (MipsRegState(count)) { - case STATE_MAPPED_64: - case STATE_UNKNOWN: - MoveVariableToX86reg(&GPR[count].UW[0],x86Reg); - break; - case STATE_MAPPED_32_ZERO: - MoveX86RegToX86Reg(MipsRegLo(count),x86Reg); - x86Mapped(MipsRegLo(count)) = NotMapped; - break; - case STATE_CONST_32: - if (MipsRegLo_S(count) < 0) { - } - MoveConstToX86reg(MipsRegLo(count),x86Reg); - break; - } - MipsRegLo(count) = x86Reg; - MipsRegState(count) = SyncTo->MIPS_RegState[count]; - x86Mapped(x86Reg) = GPR_Mapped; - x86MapOrder(x86Reg) = 1; - break; - default: - changed = 0; - } - } -} diff --git a/src/usf/recompiler_cpu.h b/src/usf/recompiler_cpu.h deleted file mode 100644 index fd1aa77..0000000 --- a/src/usf/recompiler_cpu.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#ifndef _RECOMPILER_CPU_H_ -#define _RECOMPILER_CPU_H_ - -#include "types.h" - -#pragma pack(push,1) - -#define MaxCodeBlocks 50000 -#define MaxOrigMem 65000 - -#define NotMapped 0 -#define GPR_Mapped 1 -#define Temp_Mapped 2 -#define Stack_Mapped 3 - -#define BranchTypeCop1 0 -#define BranchTypeRs 1 -#define BranchTypeRsRt 2 - -//Exit Block Methods -#define Normal 0 -#define Normal_NoSysCheck 1 -#define DoCPU_Action 2 -#define COP1_Unuseable 3 -#define DoSysCall 4 -#define TLBReadMiss 5 -#define ExitResetRecompCode 6 -#define DoBreak 7 - -#define STATE_KNOWN_VALUE 1 -//#define STATE_UNKNOW_VALUE - -#define STATE_X86_MAPPED 2 -//#define STATE_CONST - -#define STATE_SIGN 4 -//#define STATE_ZERO - -#define STATE_32BIT 8 -//#define STATE_64BIT - -#define STATE_UNKNOWN 0 - -//STATE_MAPPED_64 = 3; -//STATE_MAPPED_32_ZERO = 11 -//STATE_MAPPED_32_SIGN = 15 -#define STATE_MAPPED_64 (STATE_KNOWN_VALUE | STATE_X86_MAPPED) -#define STATE_MAPPED_32_ZERO (STATE_KNOWN_VALUE | STATE_X86_MAPPED | STATE_32BIT) -#define STATE_MAPPED_32_SIGN (STATE_KNOWN_VALUE | STATE_X86_MAPPED | STATE_32BIT | STATE_SIGN) - -//STATE_CONST_64 = 1 -//STATE_CONST_32 = 13 -#define STATE_CONST_64 (STATE_KNOWN_VALUE) -#define STATE_CONST_32 (STATE_KNOWN_VALUE | STATE_32BIT | STATE_SIGN) - -#define IsKnown(Reg) ((MipsRegState(Reg) & STATE_KNOWN_VALUE) != 0) -#define IsUnknown(Reg) (!IsKnown(Reg)) - -#define IsMapped(Reg) (IsKnown(Reg) && (MipsRegState(Reg) & STATE_X86_MAPPED) != 0) -#define IsConst(Reg) (IsKnown(Reg) && !IsMapped(Reg)) - -#define IsSigned(Reg) (IsKnown(Reg) && (MipsRegState(Reg) & STATE_SIGN) != 0) -#define IsUnsigned(Reg) (IsKnown(Reg) && !IsSigned(Reg)) - -#define Is32Bit(Reg) (IsKnown(Reg) && (MipsRegState(Reg) & STATE_32BIT) != 0) -#define Is64Bit(Reg) (IsKnown(Reg) && !Is32Bit(Reg)) - -#define Is32BitMapped(Reg) (Is32Bit(Reg) && (MipsRegState(Reg) & STATE_X86_MAPPED) != 0) -#define Is64BitMapped(Reg) (Is64Bit(Reg) && !Is32BitMapped(Reg)) - -#define MipsRegState(Reg) Section->RegWorking.MIPS_RegState[Reg] -#define MipsReg(Reg) Section->RegWorking.MIPS_RegVal[Reg].UDW -#define MipsReg_S(Reg) Section->RegWorking.MIPS_RegVal[Reg].DW -#define MipsRegLo(Reg) Section->RegWorking.MIPS_RegVal[Reg].UW[0] -#define MipsRegLo_S(Reg) Section->RegWorking.MIPS_RegVal[Reg].W[0] -#define MipsRegHi(Reg) Section->RegWorking.MIPS_RegVal[Reg].UW[1] -#define MipsRegHi_S(Reg) Section->RegWorking.MIPS_RegVal[Reg].W[1] - -#define x86MapOrder(Reg) Section->RegWorking.x86reg_MapOrder[Reg] -#define x86Protected(Reg) Section->RegWorking.x86reg_Protected[Reg] -#define x86Mapped(Reg) Section->RegWorking.x86reg_MappedTo[Reg] - -#define BlockCycleCount Section->RegWorking.CycleCount -#define BlockRandomModifier Section->RegWorking.RandomModifier - - -#define StackTopPos Section->RegWorking.Stack_TopPos -#define FpuMappedTo(Reg) Section->RegWorking.x86fpu_MappedTo[Reg] -#define FpuState(Reg) Section->RegWorking.x86fpu_State[Reg] -#define FpuRoundingModel(Reg) Section->RegWorking.x86fpu_RoundingModel[Reg] -#define FpuBeenUsed Section->RegWorking.Fpu_Used -#define CurrentRoundingModel Section->RegWorking.RoundingModel - -typedef struct { - //r4k - int32_t MIPS_RegState[32]; - MIPS_DWORD MIPS_RegVal[32]; - - uint32_t x86reg_MappedTo[64]; - uint32_t x86reg_MapOrder[64]; - uint32_t x86reg_Protected[64]; - - uint32_t CycleCount; - uint32_t RandomModifier; - - //FPU - uint32_t Stack_TopPos; - uint32_t x86fpu_MappedTo[16]; - uint32_t x86fpu_State[16]; - uint32_t x86fpu_RoundingModel[16]; - - uint32_t Fpu_Used; - uint32_t RoundingModel; -} REG_INFO; - -typedef struct { - uint32_t TargetPC; - //uint8_t * BranchLabel; - uint8_t * LinkLocation; - uint8_t * LinkLocation2; - uint32_t FallThrough; - uint32_t PermLoop; - uint32_t DoneDelaySlot; - REG_INFO RegSet; -} JUMP_INFO; - -typedef struct { - /* Block Connection info */ - void ** ParentSection; - void * ContinueSection; - void * JumpSection; - uint8_t * CompiledLocation; - - - uint32_t SectionID; - uint32_t Test; - uint32_t Test2; - uint32_t InLoop; - - uint32_t StartPC; - uint32_t CompilePC; - - /* Register Info */ - REG_INFO RegStart; - REG_INFO RegWorking; - - /* Jump Info */ - JUMP_INFO Jump; - JUMP_INFO Cont; -} BLOCK_SECTION; - -typedef struct { - BLOCK_SECTION * Parent; - JUMP_INFO * JumpInfo; -} BLOCK_PARENT; - -typedef struct { - uint32_t TargetPC; - REG_INFO ExitRegSet; - int32_t reason; - int32_t NextInstruction; - uint8_t * JumpLoc; //32bit jump -} EXIT_INFO; - -typedef struct { - uint32_t StartVAddr; - uint8_t * CompiledLocation; - int32_t NoOfSections; - BLOCK_SECTION BlockInfo; - EXIT_INFO ** ExitInfo; - int32_t ExitCount; -} BLOCK_INFO; - -typedef struct { - void * CodeBlock; - QWORD OriginalMemory; -} TARGET_INFO; - -typedef struct { - uint32_t PAddr; - uint32_t VAddr; - uint32_t OriginalValue; - void * CompiledLocation; -} ORIGINAL_MEMMARKER; - -typedef struct { - uint32_t NoOfRDRamBlocks[2048]; - uint32_t NoOfDMEMBlocks; - uint32_t NoOfIMEMBlocks; - uint32_t NoOfPifRomBlocks; -} N64_Blocks_t; - -extern N64_Blocks_t N64_Blocks; - -#pragma pack(pop) - -uint8_t *Compiler4300iBlock ( void ); -uint8_t *CompileDelaySlot ( void ); -void CompileExit ( uint32_t TargetPC, REG_INFO * ExitRegSet, int32_t reason, int32_t CompileNow, void (*x86Jmp)(uintptr_t Value)); -void CompileSystemCheck ( uint32_t TimerModifier, uint32_t TargetPC, REG_INFO RegSet ); -void FixRandomReg ( void ); -void FreeSection ( BLOCK_SECTION * Section, BLOCK_SECTION * Parent); -void StartRecompilerCPU ( void ); -void GenerateSectionLinkage ( BLOCK_SECTION * Section ); -void InitilizeInitialCompilerVariable ( void); -int UnMap_TempRegSet (REG_INFO * RegWorking); - -extern uint32_t * TLBLoadAddress, TargetIndex; -extern TARGET_INFO * TargetInfo; -extern uint16_t FPU_RoundingMode; - -#define SetJump32(Loc,JumpLoc) *(uint32_t *)(Loc)= (uint32_t)(((uint32_t)(JumpLoc)) - (((uint32_t)(Loc)) + 4)); -#define SetJump8(Loc,JumpLoc) *(uint8_t *)(Loc)= (uint8_t )(((uint8_t )(JumpLoc)) - (((uint8_t )(Loc)) + 1)); - -#endif diff --git a/src/usf/recompiler_fpu_ops.c b/src/usf/recompiler_fpu_ops.c deleted file mode 100644 index 8411dcc..0000000 --- a/src/usf/recompiler_fpu_ops.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" -#include "x86.h" -#include "types.h" - -uint16_t FPU_RoundingMode = 0x0000;//_RC_NEAR -char Name[50]; - -void ChangeDefaultRoundingModel (void) { - switch((FPCR[31] & 3)) { - case 0: FPU_RoundingMode = 0x0000; break; //_RC_NEAR - case 1: FPU_RoundingMode = 0x0C00; break; //_RC_CHOP - case 2: FPU_RoundingMode = 0x0800; break; //_RC_UP - case 3: FPU_RoundingMode = 0x0400; break; //_RC_UP - } -} - -void CompileCop1Test (BLOCK_SECTION * Section) { - if (FpuBeenUsed) { return; } - TestVariable(STATUS_CU1,&STATUS_REGISTER); - CompileExit(Section->CompilePC,&Section->RegWorking,COP1_Unuseable,0,JeLabel32); - FpuBeenUsed = 1; -} - -/********************** Load/store functions ************************/ -void Compile_R4300i_LWC1 (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, TempReg3; - CompileCop1Test(Section); - if ((Opcode.ft & 1) != 0) { - if (RegInStack(Section,Opcode.ft-1,FPU_Double) || RegInStack(Section,Opcode.ft-1,FPU_Qword)) { - UnMap_FPR(Section,Opcode.ft-1,1); - } - } - if (RegInStack(Section,Opcode.ft,FPU_Double) || RegInStack(Section,Opcode.ft,FPU_Qword)) { - UnMap_FPR(Section,Opcode.ft,1); - } else { - UnMap_FPR(Section,Opcode.ft,0); - } - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(TempReg1,Address); - - TempReg2 = Map_TempReg(Section,x86_Any,-1,0); - MovePointerToX86reg(&FPRFloatLocation[Opcode.ft],TempReg2); - MoveX86regToX86Pointer(TempReg1,TempReg2); - return; - } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - ProtectGPR(Section,Opcode.base); - TempReg1 = MipsRegLo(Opcode.base); - - } else { - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - } - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - - TempReg3 = Map_TempReg(Section,x86_Any,-1,0); - MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg3); - - MovePointerToX86reg(&FPRFloatLocation[Opcode.ft],TempReg2); - MoveX86regToX86Pointer(TempReg3,TempReg2); -} - -void Compile_R4300i_LDC1 (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, TempReg3; - - - - CompileCop1Test(Section); - - UnMap_FPR(Section,Opcode.ft,0); - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(TempReg1,Address); - - TempReg2 = Map_TempReg(Section,x86_Any,-1,0); - MovePointerToX86reg(&FPRDoubleLocation[Opcode.ft],TempReg2); - AddConstToX86Reg(TempReg2 | x64_Reg,4); - MoveX86regToX86Pointer(TempReg1,TempReg2); - - Compile_LW(TempReg1,Address + 4); - MovePointerToX86reg(&FPRDoubleLocation[Opcode.ft],TempReg2); - MoveX86regToX86Pointer(TempReg1,TempReg2); - return; - } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - ProtectGPR(Section,Opcode.base); - TempReg1 = MipsRegLo(Opcode.base); - - } else { - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - TempReg3 = Map_TempReg(Section,x86_Any,-1,0); - MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg3); - Push(TempReg2); - MoveVariableToX86reg(&FPRDoubleLocation[Opcode.ft],TempReg2 | x64_Reg); - AddConstToX86Reg(TempReg2 | x64_Reg,4); - MoveX86regToX86Pointer(TempReg3,TempReg2); - Pop(TempReg2); - MoveX86regPointerToX86regDisp8(TempReg1, TempReg2,TempReg3,4); - MoveVariableToX86reg(&FPRDoubleLocation[Opcode.ft],TempReg2 | x64_Reg); - MoveX86regToX86Pointer(TempReg3,TempReg2); - -} - -void Compile_R4300i_SWC1 (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2, TempReg3; - - - - CompileCop1Test(Section); - - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - UnMap_FPR(Section,Opcode.ft,1); - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg(&FPRFloatLocation[Opcode.ft],TempReg1); - MoveX86PointerToX86reg(TempReg1,TempReg1); - Compile_SW_Register(TempReg1, Address); - return; - } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - UnMap_FPR(Section,Opcode.ft,1); - TempReg3 = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg(&FPRFloatLocation[Opcode.ft],TempReg3); - MoveX86PointerToX86reg(TempReg3,TempReg3); - MoveX86regToX86regPointer(TempReg3,TempReg1, TempReg2); - -} - -void Compile_R4300i_SDC1 (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2, TempReg3; - - CompileCop1Test(Section); - - - - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.ft],TempReg1); - AddConstToX86Reg(TempReg1 | x64_Reg,4); - MoveX86PointerToX86reg(TempReg1,TempReg1); - Compile_SW_Register(TempReg1, Address); - - - MovePointerToX86reg(&FPRDoubleLocation[Opcode.ft],TempReg1); - MoveX86PointerToX86reg(TempReg1,TempReg1); - Compile_SW_Register(TempReg1, Address + 4); - return; - } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - TempReg3 = Map_TempReg(Section,x86_Any,-1,0); - - MoveVariableToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.ft],TempReg3 | x64_Reg); - - AddConstToX86Reg(TempReg3 | x64_Reg,4); - MoveX86PointerToX86reg(TempReg3,TempReg3); - MoveX86regToX86regPointer(TempReg3,TempReg1, TempReg2); - AddConstToX86Reg(TempReg1,4); - - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.ft],TempReg3); - MoveX86PointerToX86reg(TempReg3,TempReg3); - MoveX86regToX86regPointer(TempReg3,TempReg1, TempReg2); - - -} - -/************************** COP1 functions **************************/ -void Compile_R4300i_COP1_MF (BLOCK_SECTION * Section) { - uint32_t TempReg; - - - CompileCop1Test(Section); - - UnMap_FPR(Section,Opcode.fs,1); - Map_GPR_32bit(Section,Opcode.rt, 1, -1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Opcode.fs],TempReg); - MoveX86PointerToX86reg(MipsRegLo(Opcode.rt),TempReg); -} - -void Compile_R4300i_COP1_DMF (BLOCK_SECTION * Section) { - uint32_t TempReg; - - - CompileCop1Test(Section); - - UnMap_FPR(Section,Opcode.fs,1); - Map_GPR_64bit(Section,Opcode.rt, -1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.fs],TempReg); - AddConstToX86Reg(TempReg | x64_Reg,4); - MoveX86PointerToX86reg(MipsRegHi(Opcode.rt),TempReg); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.fs],TempReg); - MoveX86PointerToX86reg(MipsRegLo(Opcode.rt),TempReg); -} - -void Compile_R4300i_COP1_CF(BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - - if (Opcode.fs != 31 && Opcode.fs != 0) { Compile_R4300i_UnknownOpcode (Section); return; } - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveVariableToX86reg(&FPCR[Opcode.fs],MipsRegLo(Opcode.rt)); -} - -void Compile_R4300i_COP1_MT( BLOCK_SECTION * Section) { - uint32_t TempReg; - - - CompileCop1Test(Section); - - if ((Opcode.fs & 1) != 0) { - if (RegInStack(Section,Opcode.fs-1,FPU_Double) || RegInStack(Section,Opcode.fs-1,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs-1,1); - } - } - UnMap_FPR(Section,Opcode.fs,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Opcode.fs],TempReg); - - if (IsConst(Opcode.rt)) { - MoveConstToX86Pointer(MipsRegLo(Opcode.rt),TempReg); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToX86Pointer(MipsRegLo(Opcode.rt),TempReg); - } else { - MoveX86regToX86Pointer(Map_TempReg(Section,x86_Any, Opcode.rt, 0),TempReg); - } -} - -void Compile_R4300i_COP1_DMT( BLOCK_SECTION * Section) { - uint32_t TempReg; - - - CompileCop1Test(Section); - - if ((Opcode.fs & 1) == 0) { - if (RegInStack(Section,Opcode.fs+1,FPU_Float) || RegInStack(Section,Opcode.fs+1,FPU_Dword)) { - UnMap_FPR(Section,Opcode.fs+1,1); - } - } - UnMap_FPR(Section,Opcode.fs,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.fs],TempReg); - - if (IsConst(Opcode.rt)) { - MoveConstToX86Pointer(MipsRegLo(Opcode.rt),TempReg); - AddConstToX86Reg(TempReg,4); - if Is64Bit(Opcode.rt) { - MoveConstToX86Pointer(MipsRegHi(Opcode.rt),TempReg); - } else { - MoveConstToX86Pointer(MipsRegLo_S(Opcode.rt) >> 31,TempReg); - } - } else if (IsMapped(Opcode.rt)) { - MoveX86regToX86Pointer(MipsRegLo(Opcode.rt),TempReg); - AddConstToX86Reg64(TempReg,4); - if Is64Bit(Opcode.rt) { - MoveX86regToX86Pointer(MipsRegHi(Opcode.rt),TempReg); - } else { - MoveX86regToX86Pointer(Map_TempReg(Section,x86_Any, Opcode.rt, 1),TempReg); - } - } else { - int x86Reg = Map_TempReg(Section,x86_Any, Opcode.rt, 0); - MoveX86regToX86Pointer(x86Reg,TempReg); - AddConstToX86Reg64(TempReg,4); - MoveX86regToX86Pointer(Map_TempReg(Section,x86Reg, Opcode.rt, 1),TempReg); - } -} - - -void Compile_R4300i_COP1_CT(BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fs != 31) { Compile_R4300i_UnknownOpcode (Section); return; } - - if (IsConst(Opcode.rt)) { - MoveConstToVariable(MipsRegLo(Opcode.rt),&FPCR[Opcode.fs]); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToVariable(MipsRegLo(Opcode.rt),&FPCR[Opcode.fs]); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rt,0),&FPCR[Opcode.fs]); - } - Pushad(); - Call_Direct(ChangeDefaultRoundingModel); - Popad(); - CurrentRoundingModel = RoundUnknown; -} - -/************************** COP1: S functions ************************/ -void Compile_R4300i_COP1_S_ADD (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - - - - CompileCop1Test(Section); - - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Float); - if (RegInStack(Section,Reg2, FPU_Float)) { - fpuAddReg(StackPosition(Section,Reg2)); - } else { - uint32_t TempReg; - - UnMap_FPR(Section,Reg2,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Reg2],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Float); - fpuAddDwordRegPointer(TempReg); - } - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_SUB (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - if (Opcode.fd == Opcode.ft) { - UnMap_FPR(Section,Opcode.fd,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Opcode.ft],TempReg); - fpuSubDwordRegPointer(TempReg); - } else { - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Float); - if (RegInStack(Section,Reg2, FPU_Float)) { - fpuSubReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Reg2],TempReg); - fpuSubDwordRegPointer(TempReg); - } - } - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_MUL (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Float); - if (RegInStack(Section,Reg2, FPU_Float)) { - fpuMulReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Reg2],TempReg); - fpuMulDwordRegPointer(TempReg); - } - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_DIV (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - if (Opcode.fd == Opcode.ft) { - UnMap_FPR(Section,Opcode.fd,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Opcode.ft],TempReg); - fpuDivDwordRegPointer(TempReg); - } else { - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Float); - if (RegInStack(Section,Reg2, FPU_Float)) { - fpuDivReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Reg2],TempReg); - fpuDivDwordRegPointer(TempReg); - } - } - - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_ABS (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - fpuAbs(); - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_NEG (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - fpuNeg(); - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_SQRT (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - fpuSqrt(); - UnMap_FPR(Section,Opcode.fd,1); -} - -void Compile_R4300i_COP1_S_MOV (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); -} - -void Compile_R4300i_COP1_S_TRUNC_L (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Qword,RoundTruncate); -} - -void Compile_R4300i_COP1_S_CEIL_L (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Qword,RoundUp); -} - -void Compile_R4300i_COP1_S_FLOOR_L (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Qword,RoundDown); -} - -void Compile_R4300i_COP1_S_ROUND_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Dword,RoundNearest); -} - -void Compile_R4300i_COP1_S_TRUNC_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Dword,RoundTruncate); -} - -void Compile_R4300i_COP1_S_CEIL_W (BLOCK_SECTION * Section) { // added by Witten - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Dword,RoundUp); -} - -void Compile_R4300i_COP1_S_FLOOR_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Dword,RoundDown); -} - -void Compile_R4300i_COP1_S_CVT_D (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Double,RoundDefault); -} - -void Compile_R4300i_COP1_S_CVT_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Dword,RoundDefault); -} - -void Compile_R4300i_COP1_S_CVT_L (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Float)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Float); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Float,FPU_Qword,RoundDefault); -} - -void Compile_R4300i_COP1_S_CMP (BLOCK_SECTION * Section) { - uint32_t Reg1 = RegInStack(Section,Opcode.ft, FPU_Float)?Opcode.ft:Opcode.fs; - uint32_t Reg2 = RegInStack(Section,Opcode.ft, FPU_Float)?Opcode.fs:Opcode.ft; - int x86reg, cmp = 0; - - - - - CompileCop1Test(Section); - //if ((Opcode.funct & 1) != 0) { Compile_R4300i_UnknownOpcode(Section); } - if ((Opcode.funct & 2) != 0) { cmp |= 0x4000; } - if ((Opcode.funct & 4) != 0) { cmp |= 0x0100; } - - Load_FPR_ToTop(Section,Reg1,Reg1, FPU_Float); - Map_TempReg(Section,x86_EAX, 0, 0); - if (RegInStack(Section,Reg2, FPU_Float)) { - fpuComReg(StackPosition(Section,Reg2),0); - } else { - uint32_t TempReg; - - UnMap_FPR(Section,Reg2,1); - Load_FPR_ToTop(Section,Reg1,Reg1, FPU_Float); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRFloatLocation[Reg2],TempReg); - fpuComDwordRegPointer(TempReg,0); - } - AndConstToVariable(~FPCSR_C, &FSTATUS_REGISTER); - fpuStoreStatus(); - x86reg = Map_TempReg(Section,x86_Any8Bit, 0, 0); - TestConstToX86Reg(cmp,x86_EAX); - Setnz(x86reg); - - if (cmp != 0) { - TestConstToX86Reg(cmp,x86_EAX); - Setnz(x86reg); - - if ((Opcode.funct & 1) != 0) { - int x86reg2 = Map_TempReg(Section,x86_Any8Bit, 0, 0); - AndConstToX86Reg(x86_EAX, 0x4300); - CompConstToX86reg(x86_EAX, 0x4300); - Setz(x86reg2); - - OrX86RegToX86Reg(x86reg, x86reg2); - } - } else if ((Opcode.funct & 1) != 0) { - AndConstToX86Reg(x86_EAX, 0x4300); - CompConstToX86reg(x86_EAX, 0x4300); - Setz(x86reg); - } - ShiftLeftSignImmed(x86reg, 23); - OrX86RegToVariable(&FPCR[31], x86reg); -} - -/************************** COP1: D functions ************************/ -void Compile_R4300i_COP1_D_ADD (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - - - - CompileCop1Test(Section); - - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Double); - if (RegInStack(Section,Reg2, FPU_Double)) { - fpuAddReg(StackPosition(Section,Reg2)); - } else { - uint32_t TempReg; - - UnMap_FPR(Section,Reg2,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Reg2],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Double); - fpuAddQwordRegPointer(TempReg); - } -} - -void Compile_R4300i_COP1_D_SUB (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - if (Opcode.fd == Opcode.ft) { - UnMap_FPR(Section,Opcode.fd,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.ft],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - fpuSubQwordRegPointer(TempReg); - } else { - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Double); - if (RegInStack(Section,Reg2, FPU_Double)) { - fpuSubReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Reg2],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Double); - fpuSubQwordRegPointer(TempReg); - } - } -} - -void Compile_R4300i_COP1_D_MUL (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Double); - if (RegInStack(Section,Reg2, FPU_Double)) { - fpuMulReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Double); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Reg2],TempReg); - fpuMulQwordRegPointer(TempReg); - } -} - -void Compile_R4300i_COP1_D_DIV (BLOCK_SECTION * Section) { - uint32_t Reg1 = Opcode.ft == Opcode.fd?Opcode.ft:Opcode.fs; - uint32_t Reg2 = Opcode.ft == Opcode.fd?Opcode.fs:Opcode.ft; - uint32_t TempReg; - - - - CompileCop1Test(Section); - - if (Opcode.fd == Opcode.ft) { - UnMap_FPR(Section,Opcode.fd,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Opcode.ft],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - fpuDivQwordRegPointer(TempReg); - } else { - Load_FPR_ToTop(Section,Opcode.fd,Reg1, FPU_Double); - if (RegInStack(Section,Reg2, FPU_Double)) { - fpuDivReg(StackPosition(Section,Reg2)); - } else { - UnMap_FPR(Section,Reg2,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Reg2],TempReg); - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fd, FPU_Double); - fpuDivQwordRegPointer(TempReg); - } - } -} - -void Compile_R4300i_COP1_D_ABS (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - fpuAbs(); -} - -void Compile_R4300i_COP1_D_NEG (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - fpuNeg(); -} - -void Compile_R4300i_COP1_D_SQRT (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - fpuSqrt(); -} - -void Compile_R4300i_COP1_D_MOV (BLOCK_SECTION * Section) { - - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); -} - -void Compile_R4300i_COP1_D_TRUNC_L (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Qword,RoundTruncate); -} - -void Compile_R4300i_COP1_D_CEIL_L (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Qword,RoundUp); -} - -void Compile_R4300i_COP1_D_FLOOR_L (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Qword,RoundDown); -} - -void Compile_R4300i_COP1_D_ROUND_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Dword,RoundNearest); -} - -void Compile_R4300i_COP1_D_TRUNC_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Dword,RoundTruncate); -} - -void Compile_R4300i_COP1_D_CEIL_W (BLOCK_SECTION * Section) { // added by Witten - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Dword,RoundUp); -} - -void Compile_R4300i_COP1_D_FLOOR_W (BLOCK_SECTION * Section) { //added by Witten - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Dword,RoundDown); -} - -void Compile_R4300i_COP1_D_CVT_S (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Float,RoundDefault); -} - -void Compile_R4300i_COP1_D_CVT_W (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Dword,RoundDefault); -} - -void Compile_R4300i_COP1_D_CVT_L (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (RegInStack(Section,Opcode.fs,FPU_Double) || RegInStack(Section,Opcode.fs,FPU_Qword)) { - UnMap_FPR(Section,Opcode.fs,1); - } - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Double)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Double); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Double,FPU_Qword,RoundDefault); -} - -void Compile_R4300i_COP1_D_CMP (BLOCK_SECTION * Section) { - uint32_t Reg1 = RegInStack(Section,Opcode.ft, FPU_Float)?Opcode.ft:Opcode.fs; - uint32_t Reg2 = RegInStack(Section,Opcode.ft, FPU_Float)?Opcode.fs:Opcode.ft; - int x86reg, cmp = 0; - - - - - CompileCop1Test(Section); - //if ((Opcode.funct & 1) != 0) { Compile_R4300i_UnknownOpcode(Section); } - if ((Opcode.funct & 2) != 0) { cmp |= 0x4000; } - if ((Opcode.funct & 4) != 0) { cmp |= 0x0100; } - - Load_FPR_ToTop(Section,Reg1,Reg1, FPU_Double); - Map_TempReg(Section,x86_EAX, 0, 0); - if (RegInStack(Section,Reg2, FPU_Double)) { - fpuComReg(StackPosition(Section,Reg2),0); - } else { - uint32_t TempReg; - - UnMap_FPR(Section,Reg2,1); - TempReg = Map_TempReg(Section,x86_Any,-1,0); - - MovePointerToX86reg((uint8_t *)&FPRDoubleLocation[Reg2],TempReg); - Load_FPR_ToTop(Section,Reg1,Reg1, FPU_Double); - fpuComQwordRegPointer(TempReg,0); - } - AndConstToVariable(~FPCSR_C, &FSTATUS_REGISTER); - fpuStoreStatus(); - x86reg = Map_TempReg(Section,x86_Any8Bit, 0, 0); - TestConstToX86Reg(cmp,x86_EAX); - Setnz(x86reg); - if (cmp != 0) { - TestConstToX86Reg(cmp,x86_EAX); - Setnz(x86reg); - - if ((Opcode.funct & 1) != 0) { - int x86reg2 = Map_TempReg(Section,x86_Any8Bit, 0, 0); - AndConstToX86Reg(x86_EAX, 0x4300); - CompConstToX86reg(x86_EAX, 0x4300); - Setz(x86reg2); - - OrX86RegToX86Reg(x86reg, x86reg2); - } - } else if ((Opcode.funct & 1) != 0) { - AndConstToX86Reg(x86_EAX, 0x4300); - CompConstToX86reg(x86_EAX, 0x4300); - Setz(x86reg); - } - ShiftLeftSignImmed(x86reg, 23); - OrX86RegToVariable(&FPCR[31], x86reg); -} - -/************************** COP1: W functions ************************/ -void Compile_R4300i_COP1_W_CVT_S (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Dword)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Dword); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Dword,FPU_Float,RoundDefault); -} - -void Compile_R4300i_COP1_W_CVT_D (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Dword)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Dword); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Dword,FPU_Double,RoundDefault); -} - -/************************** COP1: L functions ************************/ -void Compile_R4300i_COP1_L_CVT_S (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Qword)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Qword); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Qword,FPU_Float,RoundDefault); -} - -void Compile_R4300i_COP1_L_CVT_D (BLOCK_SECTION * Section) { - - - CompileCop1Test(Section); - if (Opcode.fd != Opcode.fs || !RegInStack(Section,Opcode.fd,FPU_Qword)) { - Load_FPR_ToTop(Section,Opcode.fd,Opcode.fs,FPU_Qword); - } - ChangeFPURegFormat(Section,Opcode.fd,FPU_Qword,FPU_Double,RoundDefault); -} diff --git a/src/usf/recompiler_ops.c b/src/usf/recompiler_ops.c deleted file mode 100644 index 522e8fb..0000000 --- a/src/usf/recompiler_ops.c +++ /dev/null @@ -1,4657 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" -#include "x86.h" -#include "types.h" - -uint32_t BranchCompare = 0; - -void CompileReadTLBMiss (BLOCK_SECTION * Section, int32_t AddressReg, int32_t LookUpReg ) { -#ifdef USEX64 - MoveX86regToMemory(AddressReg, x86_R15, (uintptr_t)TLBLoadAddress-(uintptr_t)TLB_Map); -#else - MoveX86regToVariable(AddressReg,TLBLoadAddress); -#endif - TestX86RegToX86Reg(LookUpReg,LookUpReg); - CompileExit(Section->CompilePC,&Section->RegWorking,TLBReadMiss,0,JeLabel32); -} - -/************************** Branch functions ************************/ -void Compile_R4300i_Branch (BLOCK_SECTION * Section, void (*CompareFunc)(BLOCK_SECTION * Section), int32_t BranchType, uint32_t Link) { - static int32_t EffectDelaySlot; - static REG_INFO RegBeforeDelay; - int32_t count; - - if ( NextInstruction == NORMAL ) { - - if ((Section->CompilePC & 0xFFC) != 0xFFC) { - switch (BranchType) { - case BranchTypeRs: EffectDelaySlot = DelaySlotEffectsCompare(Section->CompilePC,Opcode.rs,0); break; - case BranchTypeRsRt: EffectDelaySlot = DelaySlotEffectsCompare(Section->CompilePC,Opcode.rs,Opcode.rt); break; - case BranchTypeCop1: - { - OPCODE Command; - - if (!r4300i_LW_VAddr(Section->CompilePC + 4, &Command.Hex)) { - //DisplayError(GS(MSG_FAIL_LOAD_WORD)); - StopEmulation(); - } - - EffectDelaySlot = 0; - if (Command.op == R4300i_CP1) { - if (Command.fmt == R4300i_COP1_S && (Command.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - if (Command.fmt == R4300i_COP1_D && (Command.funct & 0x30) == 0x30 ) { - EffectDelaySlot = 1; - } - } - } - break; - - } - } else { - EffectDelaySlot = 1; - } - Section->Jump.TargetPC = Section->CompilePC + ((short)Opcode.offset << 2) + 4; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - Section->Jump.DoneDelaySlot = 0; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Cont.LinkLocation = NULL; - Section->Cont.LinkLocation2 = NULL; - Section->Cont.DoneDelaySlot = 0; - if (Section->Jump.TargetPC < Section->Cont.TargetPC) { - Section->Cont.FallThrough = 0; - Section->Jump.FallThrough = 1; - } else { - Section->Cont.FallThrough = 1; - Section->Jump.FallThrough = 0; - } - if (Link) { - UnMap_GPR(Section, 31, 0); - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - } - if (EffectDelaySlot) { - CompareFunc(Section); - - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - return; - } - if (!Section->Jump.FallThrough && !Section->Cont.FallThrough) { - if (Section->Jump.LinkLocation != NULL) { - SetJump32((uint32_t *)Section->Jump.LinkLocation,(uint32_t *)RecompPos); - Section->Jump.LinkLocation = NULL; - if (Section->Jump.LinkLocation2 != NULL) { - SetJump32((uint32_t *)Section->Jump.LinkLocation2,(uint32_t *)RecompPos); - Section->Jump.LinkLocation2 = NULL; - } - Section->Jump.FallThrough = 1; - } else if (Section->Cont.LinkLocation != NULL){ - - SetJump32((uint32_t *)Section->Cont.LinkLocation,(uint32_t *)RecompPos); - Section->Cont.LinkLocation = NULL; - if (Section->Cont.LinkLocation2 != NULL) { - SetJump32((uint32_t *)Section->Cont.LinkLocation2,(uint32_t *)RecompPos); - Section->Cont.LinkLocation2 = NULL; - } - Section->Cont.FallThrough = 1; - } - } - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - memcpy(&RegBeforeDelay,&Section->RegWorking,sizeof(REG_INFO)); - } - NextInstruction = DO_DELAY_SLOT; - } else if (NextInstruction == DELAY_SLOT_DONE ) { - if (EffectDelaySlot) { - JUMP_INFO * FallInfo = Section->Jump.FallThrough?&Section->Jump:&Section->Cont; - JUMP_INFO * JumpInfo = Section->Jump.FallThrough?&Section->Cont:&Section->Jump; - - if (FallInfo->FallThrough && !FallInfo->DoneDelaySlot) { - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - memcpy(&FallInfo->RegSet,&Section->RegWorking,sizeof(REG_INFO)); - FallInfo->DoneDelaySlot = 1; - if (!JumpInfo->DoneDelaySlot) { - FallInfo->FallThrough = 0; - JmpLabel32(0); - FallInfo->LinkLocation = RecompPos - 4; - - if (JumpInfo->LinkLocation != NULL) { - SetJump32((uint32_t *)JumpInfo->LinkLocation,(uint32_t *)RecompPos); - JumpInfo->LinkLocation = NULL; - if (JumpInfo->LinkLocation2 != NULL) { - SetJump32((uint32_t *)JumpInfo->LinkLocation2,(uint32_t *)RecompPos); - JumpInfo->LinkLocation2 = NULL; - } - JumpInfo->FallThrough = 1; - NextInstruction = DO_DELAY_SLOT; - memcpy(&Section->RegWorking,&RegBeforeDelay,sizeof(REG_INFO)); - return; - } - } - } - } else { - int32_t count; - - CompareFunc(Section); - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - memcpy(&Section->Cont.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - } - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { - - } -} - -void Compile_R4300i_BranchLikely (BLOCK_SECTION * Section, void (*CompareFunc)(BLOCK_SECTION * Section), uint32_t Link) { - int32_t count; - - if ( NextInstruction == NORMAL ) { - Section->Jump.TargetPC = Section->CompilePC + ((short)Opcode.offset << 2) + 4; - Section->Jump.FallThrough = 1; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - Section->Cont.TargetPC = Section->CompilePC + 8; - Section->Cont.FallThrough = 0; - Section->Cont.LinkLocation = NULL; - Section->Cont.LinkLocation2 = NULL; - if (Link) { - UnMap_GPR(Section, 31, 0); - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - } - CompareFunc(Section); - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - memcpy(&Section->Cont.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - - if (Section->Cont.FallThrough) { - if (Section->Jump.LinkLocation != NULL) { - } - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - Section->Jump.FallThrough = 0; - if (Section->Jump.LinkLocation != NULL) { - SetJump32(Section->Jump.LinkLocation,RecompPos); - Section->Jump.LinkLocation = NULL; - if (Section->Jump.LinkLocation2 != NULL) { - SetJump32(Section->Jump.LinkLocation2,RecompPos); - Section->Jump.LinkLocation2 = NULL; - } - } - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - if (Section->Cont.LinkLocation != NULL) { - SetJump32(Section->Cont.LinkLocation,RecompPos); - Section->Cont.LinkLocation = NULL; - if (Section->Cont.LinkLocation2 != NULL) { - SetJump32(Section->Cont.LinkLocation2,RecompPos); - Section->Cont.LinkLocation2 = NULL; - } - } - CompileExit (Section->CompilePC + 8,&Section->RegWorking,Normal,1,NULL); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { - NextInstruction = DO_DELAY_SLOT; - } - } - } else if (NextInstruction == DELAY_SLOT_DONE ) { - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { - } -} - -void BNE_Compare (BLOCK_SECTION * Section) { - uint8_t *Jump; - - if (IsKnown(Opcode.rs) && IsKnown(Opcode.rt)) { - if (IsConst(Opcode.rs) && IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rs) || Is64Bit(Opcode.rt)) { - Compile_R4300i_UnknownOpcode(Section); - } else if (MipsRegLo(Opcode.rs) != MipsRegLo(Opcode.rt)) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsMapped(Opcode.rs) && IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rs) || Is64Bit(Opcode.rt)) { - ProtectGPR(Section,Opcode.rs); - ProtectGPR(Section,Opcode.rt); - - CompX86RegToX86Reg( - Is32Bit(Opcode.rs)?Map_TempReg(Section,x86_Any,Opcode.rs,1):MipsRegHi(Opcode.rs), - Is32Bit(Opcode.rt)?Map_TempReg(Section,x86_Any,Opcode.rt,1):MipsRegHi(Opcode.rt) - ); - - if (Section->Jump.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - CompX86RegToX86Reg(MipsRegLo(Opcode.rs),MipsRegLo(Opcode.rt)); - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation2 = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - SetJump8(Jump,RecompPos); - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation2 = RecompPos - 4; - } - } else { - CompX86RegToX86Reg(MipsRegLo(Opcode.rs),MipsRegLo(Opcode.rt)); - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } - } else { - uint32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(ConstReg) || Is64Bit(MappedReg)) { - if (Is32Bit(ConstReg) || Is32Bit(MappedReg)) { - ProtectGPR(Section,MappedReg); - if (Is32Bit(MappedReg)) { - CompConstToX86reg(Map_TempReg(Section,x86_Any,MappedReg,1),MipsRegHi(ConstReg)); - } else { - CompConstToX86reg(MipsRegHi(MappedReg),(int32_t)MipsRegLo(ConstReg) >> 31); - } - } else { - CompConstToX86reg(MipsRegHi(MappedReg),MipsRegHi(ConstReg)); - } - if (Section->Jump.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - if (MipsRegLo(ConstReg) == 0) { - OrX86RegToX86Reg(MipsRegLo(MappedReg),MipsRegLo(MappedReg)); - } else { - CompConstToX86reg(MipsRegLo(MappedReg),MipsRegLo(ConstReg)); - } - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation2 = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation2 = RecompPos - 4; - } - } else { - if (MipsRegLo(ConstReg) == 0) { - OrX86RegToX86Reg(MipsRegLo(MappedReg),MipsRegLo(MappedReg)); - } else { - CompConstToX86reg(MipsRegLo(MappedReg),MipsRegLo(ConstReg)); - } - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } - } - } else if (IsKnown(Opcode.rs) || IsKnown(Opcode.rt)) { - uint32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - if (Is64Bit(KnownReg)) { - CompConstToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else if (IsSigned(KnownReg)) { - CompConstToVariable(((int32_t)MipsRegLo(KnownReg) >> 31),&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(0,&GPR[UnknownReg].W[1]); - } - } else { - if (Is64Bit(KnownReg)) { - CompX86regToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else if (IsSigned(KnownReg)) { - ProtectGPR(Section,KnownReg); - CompX86regToVariable(Map_TempReg(Section,x86_Any,KnownReg,1),&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(0,&GPR[UnknownReg].W[1]); - } - } - if (Section->Jump.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - if (IsConst(KnownReg)) { - CompConstToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } else { - CompX86regToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation2 = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation2 = RecompPos - 4; - } - } else { - int32_t x86Reg; - - x86Reg = Map_TempReg(Section,x86_Any,Opcode.rt,1); - CompX86regToVariable(x86Reg,&GPR[Opcode.rs].W[1]); - if (Section->Jump.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - - x86Reg = Map_TempReg(Section,x86Reg,Opcode.rt,0); - CompX86regToVariable(x86Reg,&GPR[Opcode.rs].W[0]); - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation2 = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation2 = RecompPos - 4; - } - } -} - -void BEQ_Compare (BLOCK_SECTION * Section) { - uint8_t *Jump; - - if (IsKnown(Opcode.rs) && IsKnown(Opcode.rt)) { - if (IsConst(Opcode.rs) && IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rs) || Is64Bit(Opcode.rt)) { - Compile_R4300i_UnknownOpcode(Section); - } else if (MipsRegLo(Opcode.rs) == MipsRegLo(Opcode.rt)) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsMapped(Opcode.rs) && IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rs) || Is64Bit(Opcode.rt)) { - ProtectGPR(Section,Opcode.rs); - ProtectGPR(Section,Opcode.rt); - - CompX86RegToX86Reg( - Is32Bit(Opcode.rs)?Map_TempReg(Section,x86_Any,Opcode.rs,1):MipsRegHi(Opcode.rs), - Is32Bit(Opcode.rt)?Map_TempReg(Section,x86_Any,Opcode.rt,1):MipsRegHi(Opcode.rt) - ); - if (Section->Cont.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Cont.LinkLocation = RecompPos - 4; - } - CompX86RegToX86Reg(MipsRegLo(Opcode.rs),MipsRegLo(Opcode.rt)); - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - CompX86RegToX86Reg(MipsRegLo(Opcode.rs),MipsRegLo(Opcode.rt)); - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } - } else { - uint32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(ConstReg) || Is64Bit(MappedReg)) { - if (Is32Bit(ConstReg) || Is32Bit(MappedReg)) { - if (Is32Bit(MappedReg)) { - ProtectGPR(Section,MappedReg); - CompConstToX86reg(Map_TempReg(Section,x86_Any,MappedReg,1),MipsRegHi(ConstReg)); - } else { - CompConstToX86reg(MipsRegHi(MappedReg),(int32_t)MipsRegLo(ConstReg) >> 31); - } - } else { - CompConstToX86reg(MipsRegHi(MappedReg),MipsRegHi(ConstReg)); - } - if (Section->Cont.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Cont.LinkLocation = RecompPos - 4; - } - if (MipsRegLo(ConstReg) == 0) { - OrX86RegToX86Reg(MipsRegLo(MappedReg),MipsRegLo(MappedReg)); - } else { - CompConstToX86reg(MipsRegLo(MappedReg),MipsRegLo(ConstReg)); - } - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - if (MipsRegLo(ConstReg) == 0) { - OrX86RegToX86Reg(MipsRegLo(MappedReg),MipsRegLo(MappedReg)); - } else { - CompConstToX86reg(MipsRegLo(MappedReg),MipsRegLo(ConstReg)); - } - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } - } - } else if (IsKnown(Opcode.rs) || IsKnown(Opcode.rt)) { - uint32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - if (Is64Bit(KnownReg)) { - CompConstToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else if (IsSigned(KnownReg)) { - CompConstToVariable((int32_t)MipsRegLo(KnownReg) >> 31,&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(0,&GPR[UnknownReg].W[1]); - } - } else { - ProtectGPR(Section,KnownReg); - if (Is64Bit(KnownReg)) { - CompX86regToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else if (IsSigned(KnownReg)) { - CompX86regToVariable(Map_TempReg(Section,x86_Any,KnownReg,1),&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(0,&GPR[UnknownReg].W[1]); - } - } - if (Section->Cont.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Cont.LinkLocation = RecompPos - 4; - } - if (IsConst(KnownReg)) { - CompConstToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } else { - CompX86regToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - int32_t x86Reg = Map_TempReg(Section,x86_Any,Opcode.rs,1); - CompX86regToVariable(x86Reg,&GPR[Opcode.rt].W[1]); - if (Section->Cont.FallThrough) { - JneLabel8(0); - Jump = RecompPos - 1; - } else { - JneLabel32(0); - Section->Cont.LinkLocation = RecompPos - 4; - } - CompX86regToVariable(Map_TempReg(Section,x86Reg,Opcode.rs,0),&GPR[Opcode.rt].W[0]); - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - - - SetJump8(Jump,RecompPos); - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } -} - -void BGTZ_Compare (BLOCK_SECTION * Section) { - if (IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - if (MipsReg_S(Opcode.rs) > 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else { - if (MipsRegLo_S(Opcode.rs) > 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } - } else if (IsMapped(Opcode.rs) && Is32Bit(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - if (Section->Jump.FallThrough) { - JleLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else if (Section->Cont.FallThrough) { - JgLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JleLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - uint8_t *Jump; - - if (IsMapped(Opcode.rs)) { - CompConstToX86reg(MipsRegHi(Opcode.rs),0); - } else { - CompConstToVariable(0,&GPR[Opcode.rs].W[1]); - } - if (Section->Jump.FallThrough) { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JgLabel8(0); - Jump = RecompPos - 1; - } else if (Section->Cont.FallThrough) { - JlLabel8(0); - Jump = RecompPos - 1; - JgLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JgLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - - if (IsMapped(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - } else { - CompConstToVariable(0,&GPR[Opcode.rs].W[0]); - } - if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - } else if (Section->Cont.FallThrough) { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - } else { - JneLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - JmpLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - } - } -} - -void BLEZ_Compare (BLOCK_SECTION * Section) { - if (IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - if (MipsReg_S(Opcode.rs) <= 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsSigned(Opcode.rs)) { - if (MipsRegLo_S(Opcode.rs) <= 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else { - if (MipsRegLo(Opcode.rs) == 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } - } else { - if (IsMapped(Opcode.rs) && Is32Bit(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - if (Section->Jump.FallThrough) { - JgLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else if (Section->Cont.FallThrough) { - JleLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JgLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - uint8_t *Jump; - - if (IsMapped(Opcode.rs)) { - CompConstToX86reg(MipsRegHi(Opcode.rs),0); - } else { - CompConstToVariable(0,&GPR[Opcode.rs].W[1]); - } - if (Section->Jump.FallThrough) { - JgLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JlLabel8(0); - Jump = RecompPos - 1; - } else if (Section->Cont.FallThrough) { - JgLabel8(0); - Jump = RecompPos - 1; - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JgLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - - if (IsMapped(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - } else { - CompConstToVariable(0,&GPR[Opcode.rs].W[0]); - } - if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - } else if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation2 = RecompPos - 4; - - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation2 = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation2 = RecompPos - 4; - } - } - } -} - -void BLTZ_Compare (BLOCK_SECTION * Section) { - if (IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - if (MipsReg_S(Opcode.rs) < 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsSigned(Opcode.rs)) { - if (MipsRegLo_S(Opcode.rs) < 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - CompConstToX86reg(MipsRegHi(Opcode.rs),0); - if (Section->Jump.FallThrough) { - JgeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else if (Section->Cont.FallThrough) { - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JgeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else if (IsSigned(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - if (Section->Jump.FallThrough) { - JgeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else if (Section->Cont.FallThrough) { - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JgeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else if (IsUnknown(Opcode.rs)) { - CompConstToVariable(0,&GPR[Opcode.rs].W[1]); - if (Section->Jump.FallThrough) { - JgeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else if (Section->Cont.FallThrough) { - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } else { - JlLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - JmpLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } - } -} - -void BGEZ_Compare (BLOCK_SECTION * Section) { - if (IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { -#ifndef EXTERNAL_RELEASE - DisplayError("BGEZ 1"); -#endif - Compile_R4300i_UnknownOpcode(Section); - } else if IsSigned(Opcode.rs) { - if (MipsRegLo_S(Opcode.rs) >= 0) { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } else { - Section->Jump.FallThrough = 0; - Section->Cont.FallThrough = 1; - } - } else { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } - } else if (IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - CompConstToX86reg(MipsRegHi(Opcode.rs),0); - if (Section->Cont.FallThrough) { - JgeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else if (IsSigned(Opcode.rs)) { - CompConstToX86reg(MipsRegLo(Opcode.rs),0); - if (Section->Cont.FallThrough) { - JgeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } else { - Section->Jump.FallThrough = 1; - Section->Cont.FallThrough = 0; - } - } else { - CompConstToVariable(0,&GPR[Opcode.rs].W[1]); - if (Section->Cont.FallThrough) { - JgeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JlLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } - } -} - -void COP1_BCF_Compare (BLOCK_SECTION * Section) { - TestVariable(FPCSR_C,&FPCR[31]); - if (Section->Cont.FallThrough) { - JeLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JneLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } -} - -void COP1_BCT_Compare (BLOCK_SECTION * Section) { - TestVariable(FPCSR_C,&FPCR[31]); - if (Section->Cont.FallThrough) { - JneLabel32 ( 0 ); - Section->Jump.LinkLocation = RecompPos - 4; - } else if (Section->Jump.FallThrough) { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - } else { - JeLabel32 ( 0 ); - Section->Cont.LinkLocation = RecompPos - 4; - JmpLabel32(0); - Section->Jump.LinkLocation = RecompPos - 4; - } -} -/************************* OpCode functions *************************/ -void Compile_R4300i_J (BLOCK_SECTION * Section) { - if ( NextInstruction == NORMAL ) { - Section->Jump.TargetPC = (Section->CompilePC & 0xF0000000) + (Opcode.target << 2);; - Section->Jump.FallThrough = 1; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - NextInstruction = DO_DELAY_SLOT; - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } - } else if (NextInstruction == DELAY_SLOT_DONE ) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { -#ifndef EXTERNAL_RELEASE - DisplayError("WTF\n\nJal\nNextInstruction = %X", NextInstruction); -#endif - } -} - -void Compile_R4300i_JAL (BLOCK_SECTION * Section) { - - //UnMap_TempReg(Section); - if ( NextInstruction == NORMAL ) { - - UnMap_GPR(Section, 31, 0); - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - MoveConstToVariable((Section->CompilePC & 0xF0000000) + (Opcode.target << 2),&JumpToLocation); - MoveConstToVariable(Section->CompilePC + 4,&PROGRAM_COUNTER); - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - WriteBackRegisters(Section); - MoveConstToVariable(DELAY_SLOT,&NextInstruction); - Ret(); - NextInstruction = END_BLOCK; - return; - } - NextInstruction = DO_DELAY_SLOT; - } else if (NextInstruction == DELAY_SLOT_DONE ) { - MoveConstToVariable((Section->CompilePC & 0xF0000000) + (Opcode.target << 2),&PROGRAM_COUNTER); - CompileExit((uint32_t)-1,&Section->RegWorking,Normal,1,NULL); - NextInstruction = END_BLOCK; - } else { -#ifndef EXTERNAL_RELEASE - DisplayError("WTF\n\nBranch\nNextInstruction = %X", NextInstruction); -#endif - } - return; - - if ( NextInstruction == NORMAL ) { - - - UnMap_GPR(Section, 31, 0); - MipsRegLo(31) = Section->CompilePC + 8; - MipsRegState(31) = STATE_CONST_32; - NextInstruction = DO_DELAY_SLOT; - - Section->Jump.TargetPC = (Section->CompilePC & 0xF0000000) + (Opcode.target << 2); - Section->Jump.FallThrough = 1; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } - } else if (NextInstruction == DELAY_SLOT_DONE ) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - } else { -#ifndef EXTERNAL_RELEASE - DisplayError("WTF\n\nJal\nNextInstruction = %X", NextInstruction); -#endif - } -} - -void Compile_R4300i_ADDI (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return; } - if (IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rt)) { UnMap_GPR(Section,Opcode.rt, 0); } - MipsRegLo(Opcode.rt) = MipsRegLo(Opcode.rs) + (short)Opcode.immediate; - MipsRegState(Opcode.rt) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rs); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(MipsRegLo(Opcode.rt)); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(MipsRegLo(Opcode.rt)); - } else { - AddConstToX86Reg(MipsRegLo(Opcode.rt),(short)Opcode.immediate); - } - -} - -void Compile_R4300i_ADDIU (BLOCK_SECTION * Section) { - - - - if (Opcode.rt == 0) { return; } - - if (IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rt)) { UnMap_GPR(Section,Opcode.rt, 0); } - MipsRegLo(Opcode.rt) = MipsRegLo(Opcode.rs) + (short)Opcode.immediate; - MipsRegState(Opcode.rt) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rs); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(MipsRegLo(Opcode.rt)); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(MipsRegLo(Opcode.rt)); - } else { - AddConstToX86Reg(MipsRegLo(Opcode.rt),(short)Opcode.immediate); - } -} - -void Compile_R4300i_SLTIU (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Result; - - if (Is64Bit(Opcode.rs)) { - int64_t Immediate = (int64_t)((short)Opcode.immediate); - Result = MipsReg(Opcode.rs) < ((unsigned)(Immediate))?1:0; - } else if (Is32Bit(Opcode.rs)) { - Result = MipsRegLo(Opcode.rs) < ((unsigned)((short)Opcode.immediate))?1:0; - } - UnMap_GPR(Section,Opcode.rt, 0); - MipsRegState(Opcode.rt) = STATE_CONST_32; - MipsRegLo(Opcode.rt) = Result; - } else if (IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - uint8_t * Jump[2]; - - CompConstToX86reg(MipsRegHi(Opcode.rs),((short)Opcode.immediate >> 31)); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetbVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToX86reg(MipsRegLo(Opcode.rs),(short)Opcode.immediate); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - } else { - CompConstToX86reg(MipsRegLo(Opcode.rs),(short)Opcode.immediate); - SetbVariable(&BranchCompare); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - } - } else { - uint8_t * Jump; - - CompConstToVariable(((short)Opcode.immediate >> 31),&GPR[Opcode.rs].W[1]); - JneLabel8(0); - Jump = RecompPos - 1; - CompConstToVariable((short)Opcode.immediate,&GPR[Opcode.rs].W[0]); - - - *((uint8_t *)(Jump))=(uint8_t)(RecompPos - Jump - 1); - SetbVariable(&BranchCompare); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - - - /*SetbVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToVariable((short)Opcode.immediate,&GPR[Opcode.rs].W[0]); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt));*/ - } -} - -void Compile_R4300i_SLTI (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Result; - - if (Is64Bit(Opcode.rs)) { - int64_t Immediate = (int64_t)((short)Opcode.immediate); - Result = (int64_t)MipsReg(Opcode.rs) < Immediate?1:0; - } else if (Is32Bit(Opcode.rs)) { - Result = MipsRegLo_S(Opcode.rs) < (short)Opcode.immediate?1:0; - } - UnMap_GPR(Section,Opcode.rt, 0); - MipsRegState(Opcode.rt) = STATE_CONST_32; - MipsRegLo(Opcode.rt) = Result; - } else if (IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - uint8_t * Jump[2]; - - CompConstToX86reg(MipsRegHi(Opcode.rs),((short)Opcode.immediate >> 31)); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetlVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToX86reg(MipsRegLo(Opcode.rs),(short)Opcode.immediate); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - } else { - /* CompConstToX86reg(MipsRegLo(Opcode.rs),(short)Opcode.immediate); - SetlVariable(&BranchCompare); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - */ - ProtectGPR(Section, Opcode.rs); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - CompConstToX86reg(MipsRegLo(Opcode.rs),(short)Opcode.immediate); - - if (MipsRegLo(Opcode.rt) > x86_EDX) { - SetlVariable(&BranchCompare); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - } else { - Setl(MipsRegLo(Opcode.rt)); - AndConstToX86Reg(MipsRegLo(Opcode.rt), 1); - } - } - } else { - uint8_t * Jump[2]; - - CompConstToVariable(((short)Opcode.immediate >> 31),&GPR[Opcode.rs].W[1]); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetlVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToVariable((short)Opcode.immediate,&GPR[Opcode.rs].W[0]); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rt,0, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rt)); - } -} - -void Compile_R4300i_ANDI (BLOCK_SECTION * Section) { - - - if (Opcode.rt == 0) { return;} - - if (IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rt)) { UnMap_GPR(Section,Opcode.rt, 0); } - MipsRegState(Opcode.rt) = STATE_CONST_32; - MipsRegLo(Opcode.rt) = MipsRegLo(Opcode.rs) & Opcode.immediate; - } else if (Opcode.immediate != 0) { - Map_GPR_32bit(Section,Opcode.rt,0,Opcode.rs); - AndConstToX86Reg(MipsRegLo(Opcode.rt),Opcode.immediate); - } else { - Map_GPR_32bit(Section,Opcode.rt,0,0); - } -} - -void Compile_R4300i_ORI (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return;} - - if (IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rt)) { UnMap_GPR(Section,Opcode.rt, 0); } - MipsRegState(Opcode.rt) = MipsRegState(Opcode.rs); - MipsRegHi(Opcode.rt) = MipsRegHi(Opcode.rs); - MipsRegLo(Opcode.rt) = MipsRegLo(Opcode.rs) | Opcode.immediate; - } else if (IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - Map_GPR_64bit(Section,Opcode.rt,Opcode.rs); - } else { - Map_GPR_32bit(Section,Opcode.rt,IsSigned(Opcode.rs),Opcode.rs); - } - OrConstToX86Reg(Opcode.immediate,MipsRegLo(Opcode.rt)); - } else { - Map_GPR_64bit(Section,Opcode.rt,Opcode.rs); - OrConstToX86Reg(Opcode.immediate,MipsRegLo(Opcode.rt)); - } -} - -void Compile_R4300i_XORI (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return;} - - if (IsConst(Opcode.rs)) { - if (Opcode.rs != Opcode.rt) { UnMap_GPR(Section,Opcode.rt, 0); } - MipsRegState(Opcode.rt) = MipsRegState(Opcode.rs); - MipsRegHi(Opcode.rt) = MipsRegHi(Opcode.rs); - MipsRegLo(Opcode.rt) = MipsRegLo(Opcode.rs) ^ Opcode.immediate; - } else { - if (IsMapped(Opcode.rs) && Is32Bit(Opcode.rs)) { - Map_GPR_32bit(Section,Opcode.rt,IsSigned(Opcode.rs),Opcode.rs); - } else { - Map_GPR_64bit(Section,Opcode.rt,Opcode.rs); - } - if (Opcode.immediate != 0) { XorConstToX86Reg(MipsRegLo(Opcode.rt),Opcode.immediate); } - } -} - -void Compile_R4300i_LUI (BLOCK_SECTION * Section) { - - if (Opcode.rt == 0) { return;} - - UnMap_GPR(Section,Opcode.rt, 0); - MipsRegLo(Opcode.rt) = ((short)Opcode.offset << 16); - MipsRegState(Opcode.rt) = STATE_CONST_32; -} - -void Compile_R4300i_DADDIU (BLOCK_SECTION * Section) { - - - if (Opcode.rs != 0) { UnMap_GPR(Section,Opcode.rs,1); } - if (Opcode.rs != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_DADDIU); - Popad(); -} - -void Compile_R4300i_LDL (BLOCK_SECTION * Section) { - - if (Opcode.base != 0) { UnMap_GPR(Section,Opcode.base,1); } - if (Opcode.rt != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_LDL); - Popad(); - -} - -void Compile_R4300i_LDR (BLOCK_SECTION * Section) { - - if (Opcode.base != 0) { UnMap_GPR(Section,Opcode.base,1); } - if (Opcode.rt != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_LDR); - Popad(); -} - - -void Compile_R4300i_LB (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - if (Opcode.rt == 0) return; - -// UnMap_TempReg(Section); //hax - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; - Map_GPR_32bit(Section,Opcode.rt,1,0); - Compile_LB(MipsRegLo(Opcode.rt),Address,1); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - - LOAD_FROM_TLB(TempReg2, TempReg2); - - CompileReadTLBMiss(Section,TempReg1,TempReg2); - XorConstToX86Reg(TempReg1|x64_Reg,3); - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveSxByteX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); -} - - -void Compile_R4300i_LH (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; - Map_GPR_32bit(Section,Opcode.rt,1,0); - Compile_LH(MipsRegLo(Opcode.rt),Address,1); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - XorConstToX86Reg(TempReg1,2); - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveSxHalfX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - -} - -void Compile_R4300i_LWL (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, Offset, shift; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address, Value; - - Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Offset = Address & 3; - - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rt); - Value = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(Value,(Address & ~3)); - AndConstToX86Reg(MipsRegLo(Opcode.rt),LWL_MASK[Offset]); - ShiftLeftSignImmed(Value,(uint8_t)LWL_SHIFT[Offset]); - AddX86RegToX86Reg(MipsRegLo(Opcode.rt),Value); - return; - } - - shift = Map_TempReg(Section,x86_ECX,-1,0); - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - - CompileReadTLBMiss(Section,TempReg1,TempReg2); - - Offset = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, Offset); - AndConstToX86Reg(Offset,3); - AndConstToX86Reg(TempReg1,~3); - - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rt); - AndVariableDispToX86Reg(LWL_MASK,MipsRegLo(Opcode.rt),Offset,4); - MoveVariableDispToX86Reg(LWL_SHIFT,shift,Offset,4); - - MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1); - - ShiftLeftSign(TempReg1); - AddX86RegToX86Reg(MipsRegLo(Opcode.rt),TempReg1); -} - -void Compile_R4300i_LW (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - if (Opcode.rt == 0) return; - - { - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Map_GPR_32bit(Section,Opcode.rt,1,-1); - Compile_LW(MipsRegLo(Opcode.rt),Address); - return; - } - - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - ProtectGPR(Section,Opcode.base); - TempReg1 = MipsRegLo(Opcode.base); - } else { - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - } - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - MoveX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - } -} - -void Compile_R4300i_LBU (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; - Map_GPR_32bit(Section,Opcode.rt,0,0); - Compile_LB(MipsRegLo(Opcode.rt),Address,0); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - XorConstToX86Reg(TempReg1,3); - Map_GPR_32bit(Section,Opcode.rt,0,-1); - MoveZxByteX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - -} - -void Compile_R4300i_LHU (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; - Map_GPR_32bit(Section,Opcode.rt,0,0); - Compile_LH(MipsRegLo(Opcode.rt),Address,0); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - XorConstToX86Reg(TempReg1,2); - Map_GPR_32bit(Section,Opcode.rt,0,-1); - MoveZxHalfX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - -} - -void Compile_R4300i_LWR (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, Offset, shift; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address, Value; - - Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Offset = Address & 3; - - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rt); - Value = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(Value,(Address & ~3)); - AndConstToX86Reg(MipsRegLo(Opcode.rt),LWR_MASK[Offset]); - ShiftRightUnsignImmed(Value,(uint8_t)LWR_SHIFT[Offset]); - AddX86RegToX86Reg(MipsRegLo(Opcode.rt),Value); - return; - } - - shift = Map_TempReg(Section,x86_ECX,-1,0); - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - - CompileReadTLBMiss(Section,TempReg1,TempReg2); - - Offset = Map_TempReg(Section,x64_Any,-1,0); - //BreakPoint(); - MoveX86RegToX86Reg(TempReg1, Offset); - AndConstToX86Reg(Offset,3); - AndConstToX86Reg(TempReg1,~3); - - Map_GPR_32bit(Section,Opcode.rt,1,Opcode.rt); - AndVariableDispToX86Reg(LWR_MASK,MipsRegLo(Opcode.rt),Offset,4); - MoveVariableDispToX86Reg(LWR_SHIFT,shift,Offset,4); - - MoveX86regPointerToX86reg(TempReg1, TempReg2,TempReg1); - - ShiftRightUnsign(TempReg1); - AddX86RegToX86Reg(MipsRegLo(Opcode.rt),TempReg1); -} - -void Compile_R4300i_LWU (BLOCK_SECTION * Section) { //added by Witten - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset); - Map_GPR_32bit(Section,Opcode.rt,0,0); - Compile_LW(MipsRegLo(Opcode.rt),Address); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - Map_GPR_32bit(Section,Opcode.rt,0,-1); - MoveZxHalfX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - -} - -void Compile_R4300i_SB (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2; - - - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 3; - - if (IsConst(Opcode.rt)) { - Compile_SB_Const((uint8_t)MipsRegLo(Opcode.rt), Address); - } else if (IsMapped(Opcode.rt) && Is8BitReg(MipsRegLo(Opcode.rt))) { - Compile_SB_Register(MipsRegLo(Opcode.rt), Address); - } else { - Compile_SB_Register(Map_TempReg(Section,x86_Any8Bit,Opcode.rt,0), Address); - } - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - XorConstToX86Reg(TempReg1 | x64_Reg,3); - if (IsConst(Opcode.rt)) { - MoveConstByteToX86regPointer((uint8_t)MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt) && Is8BitReg(MipsRegLo(Opcode.rt))) { - MoveX86regByteToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else { - - UnProtectGPR(Section,Opcode.rt); - MoveX86regByteToX86regPointer(Map_TempReg(Section,x86_Any8Bit,Opcode.rt,0),TempReg1, TempReg2); - } - -} - -void Compile_R4300i_SH (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2; - - - - if (IsConst(Opcode.base)) { - uint32_t Address = (MipsRegLo(Opcode.base) + (short)Opcode.offset) ^ 2; - - if (IsConst(Opcode.rt)) { - Compile_SH_Const((uint16_t)MipsRegLo(Opcode.rt), Address); - } else if (IsMapped(Opcode.rt)) { - Compile_SH_Register(MipsRegLo(Opcode.rt), Address); - } else { - Compile_SH_Register(Map_TempReg(Section,x86_Any,Opcode.rt,0), Address); - } - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - XorConstToX86Reg(TempReg1,2); - if (IsConst(Opcode.rt)) { - MoveConstHalfToX86regPointer((uint16_t)MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { - MoveX86regHalfToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else { - MoveX86regHalfToX86regPointer(Map_TempReg(Section,x86_Any,Opcode.rt,0),TempReg1, TempReg2); - } - -} - -void Compile_R4300i_SWL (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, Value, Offset, shift; - - - - if (IsConst(Opcode.base)) { - uint32_t Address; - - Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Offset = Address & 3; - - Value = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(Value,(Address & ~3)); - AndConstToX86Reg(Value,SWL_MASK[Offset]); - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.rt,0); - ShiftRightUnsignImmed(TempReg1,(uint8_t)SWL_SHIFT[Offset]); - AddX86RegToX86Reg(Value,TempReg1); - Compile_SW_Register(Value, (Address & ~3)); - return; - } - shift = Map_TempReg(Section,x86_ECX,-1,0); - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - Offset = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, Offset); - AndConstToX86Reg(Offset,3); - AndConstToX86Reg(TempReg1,~3); - - Value = Map_TempReg(Section,x86_Any,-1,0); - - MoveX86regPointerToX86reg(TempReg1, TempReg2,Value); - - - AndVariableDispToX86Reg(SWL_MASK,Value,Offset,4); - if (!IsConst(Opcode.rt) || MipsRegLo(Opcode.rt) != 0) { - MoveVariableDispToX86Reg(SWL_SHIFT,shift,Offset,4); - if (IsConst(Opcode.rt)) { - MoveConstToX86reg(MipsRegLo(Opcode.rt),Offset); - } else if (IsMapped(Opcode.rt)) { - MoveX86RegToX86Reg(MipsRegLo(Opcode.rt),Offset); - } else { - MoveVariableToX86reg(&GPR[Opcode.rt].UW[0],Offset); - } - ShiftRightUnsign(Offset); - AddX86RegToX86Reg(Value,Offset); - } - - - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - - MoveX86regToX86regPointer(Value,TempReg1, TempReg2); - -} - -void Compile_R4300i_SW (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - { - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - - if (IsConst(Opcode.rt)) { - Compile_SW_Const(MipsRegLo(Opcode.rt), Address); - } else if (IsMapped(Opcode.rt)) { - Compile_SW_Register(MipsRegLo(Opcode.rt), Address); - } else { - Compile_SW_Register(Map_TempReg(Section,x86_Any,Opcode.rt,0), Address); - } - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - if (IsConst(Opcode.rt)) { - MoveConstToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else { - MoveX86regToX86regPointer(Map_TempReg(Section,x86_Any,Opcode.rt,0),TempReg1, TempReg2); - } - - } -} - -void Compile_R4300i_SWR (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2, Value, Offset, shift; - - - - if (IsConst(Opcode.base)) { - uint32_t Address; - - Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Offset = Address & 3; - - Value = Map_TempReg(Section,x86_Any,-1,0); - Compile_LW(Value,(Address & ~3)); - AndConstToX86Reg(Value,SWR_MASK[Offset]); - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.rt,0); - ShiftLeftSignImmed(TempReg1,(uint8_t)SWR_SHIFT[Offset]); - AddX86RegToX86Reg(Value,TempReg1); - Compile_SW_Register(Value, (Address & ~3)); - return; - } - shift = Map_TempReg(Section,x86_ECX,-1,0); - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - Offset = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, Offset); - AndConstToX86Reg(Offset,3); - AndConstToX86Reg(TempReg1,~3); - - Value = Map_TempReg(Section,x86_Any,-1,0); - - MoveX86regPointerToX86reg(TempReg1, TempReg2,Value); - - AndVariableDispToX86Reg(SWR_MASK,Value,Offset,4); - if (!IsConst(Opcode.rt) || MipsRegLo(Opcode.rt) != 0) { - MoveVariableDispToX86Reg(SWR_SHIFT,shift,Offset,4); - if (IsConst(Opcode.rt)) { - MoveConstToX86reg(MipsRegLo(Opcode.rt),Offset); - } else if (IsMapped(Opcode.rt)) { - MoveX86RegToX86Reg(MipsRegLo(Opcode.rt),Offset); - } else { - MoveVariableToX86reg(&GPR[Opcode.rt].UW[0],Offset); - } - ShiftLeftSign(Offset); - AddX86RegToX86Reg(Value,Offset); - } - - - - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - - MoveX86regToX86regPointer(Value,TempReg1, TempReg2); - -} - -void Compile_R4300i_SDL (BLOCK_SECTION * Section) { - - if (Opcode.base != 0) { UnMap_GPR(Section,Opcode.base,1); } - if (Opcode.rt != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_SDL); - Popad(); - -} - -void Compile_R4300i_SDR (BLOCK_SECTION * Section) { - - if (Opcode.base != 0) { UnMap_GPR(Section,Opcode.base,1); } - if (Opcode.rt != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_SDR); - Popad(); - -} - -void ClearRecomplierCache (uint32_t Address) { - if (!TranslateVaddr(&Address)) { DisplayError("Cache: Failed to translate: %X",Address); return; } - if (Address < RdramSize) { - uint32_t Block = Address >> 12; - if (N64_Blocks.NoOfRDRamBlocks[Block] > 0) { - N64_Blocks.NoOfRDRamBlocks[Block] = 0; - memset(JumpTable + (Block << 10),0,0x1000); - *(DelaySlotTable + Block) = NULL; - } - } else { -#ifndef EXTERNAL_RELEASE - DisplayError("ClearRecomplierCache: %X",Address); -#endif - } -} - -void Compile_R4300i_CACHE (BLOCK_SECTION * Section){ -/* - if (SelfModCheck != ModCode_Cache && SelfModCheck != ModCode_ChangeMemory && SelfModCheck != ModCode_CheckMemory2 && SelfModCheck != ModCode_CheckMemoryCache) { - return; - } - - switch(Opcode.rt) { - case 0: - case 16: - Pushad(); - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - MoveConstToX86reg(Address,x86_ECX); - } else if (IsMapped(Opcode.base)) { - if (MipsRegLo(Opcode.base) == x86_ECX) { - AddConstToX86Reg(x86_ECX,(short)Opcode.offset); - } else { - LeaSourceAndOffset(x86_ECX,MipsRegLo(Opcode.base),(short)Opcode.offset); - } - } else { - MoveVariableToX86reg(&GPR[Opcode.base].UW[0],x86_ECX); - AddConstToX86Reg(x86_ECX,(short)Opcode.offset); - } - Call_Direct(ClearRecomplierCache); - Popad(); - break; - case 1: - case 3: - case 13: - case 5: - case 8: - case 9: - case 17: - case 21: - case 25: - break; -#ifndef EXTERNAL_RELEASE - default: - DisplayError("cache: %d",Opcode.rt); -#endif - } - */ -} - -void Compile_R4300i_LL (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Map_GPR_32bit(Section,Opcode.rt,1,-1); - Compile_LW(MipsRegLo(Opcode.rt),Address); - MoveConstToVariable(1,&LLBit); - TranslateVaddr(&Address); - MoveConstToVariable(Address,&LLAddr); - return; - } - - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - ProtectGPR(Section,Opcode.base); - TempReg1 = MipsRegLo(Opcode.base); - } else { - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - } - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - CompileReadTLBMiss(Section,TempReg1,TempReg2); - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveX86regPointerToX86reg(TempReg1, TempReg2,MipsRegLo(Opcode.rt)); - MoveConstToVariable(1,&LLBit); - MoveX86regToVariable(TempReg1,&LLAddr); - AddX86regToVariable(TempReg2,&LLAddr); - SubConstFromVariable((uintptr_t)N64MEM,&LLAddr); - -} - -void Compile_R4300i_SC (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2; - uint8_t * Jump; - - - - CompConstToVariable(1,&LLBit); - JneLabel32(0); - Jump = RecompPos - 4; - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - if (IsConst(Opcode.rt)) { - Compile_SW_Const(MipsRegLo(Opcode.rt), Address); - } else if (IsMapped(Opcode.rt)) { - Compile_SW_Register(MipsRegLo(Opcode.rt), Address); - } else { - Compile_SW_Register(Map_TempReg(Section,x86_Any,Opcode.rt,0), Address); - } - - *((uint32_t *)(Jump))=(uint8_t)(RecompPos - Jump - 4); - Map_GPR_32bit(Section,Opcode.rt,0,-1); - MoveVariableToX86reg(&LLBit,MipsRegLo(Opcode.rt)); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - UnProtectGPR(Section,Opcode.base); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - if (IsConst(Opcode.rt)) { - MoveConstToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else { - MoveX86regToX86regPointer(Map_TempReg(Section,x86_Any,Opcode.rt,0),TempReg1, TempReg2); - } - - - *((uint32_t *)(Jump))=(uint8_t)(RecompPos - Jump - 4); - Map_GPR_32bit(Section,Opcode.rt,0,-1); - MoveVariableToX86reg(&LLBit,MipsRegLo(Opcode.rt)); - -} - -void Compile_R4300i_LD (BLOCK_SECTION * Section) { - uint32_t TempReg1, TempReg2; - - - - if (Opcode.rt == 0) return; - - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - Map_GPR_64bit(Section,Opcode.rt,-1); - Compile_LW(MipsRegHi(Opcode.rt),Address); - Compile_LW(MipsRegLo(Opcode.rt),Address + 4); - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base) && Opcode.offset == 0) { - - ProtectGPR(Section,Opcode.base); - TempReg1 = MipsRegLo(Opcode.base); - - } else { - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - Map_GPR_64bit(Section,Opcode.rt,-1); - MoveX86regPointerToX86reg(TempReg1, TempReg2,MipsRegHi(Opcode.rt)); - MoveX86regPointerToX86regDisp8(TempReg1, TempReg2,MipsRegLo(Opcode.rt),4); - - -} - -void Compile_R4300i_SD (BLOCK_SECTION * Section){ - uint32_t TempReg1, TempReg2; - - - - if (IsConst(Opcode.base)) { - uint32_t Address = MipsRegLo(Opcode.base) + (short)Opcode.offset; - - if (IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { - Compile_SW_Const(MipsRegHi(Opcode.rt), Address); - } else { - Compile_SW_Const((MipsRegLo_S(Opcode.rt) >> 31), Address); - } - Compile_SW_Const(MipsRegLo(Opcode.rt), Address + 4); - } else if (IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { - Compile_SW_Register(MipsRegHi(Opcode.rt), Address); - } else { - Compile_SW_Register(Map_TempReg(Section,x86_Any,Opcode.rt,1), Address); - } - Compile_SW_Register(MipsRegLo(Opcode.rt), Address + 4); - } else { - Compile_SW_Register(TempReg1 = Map_TempReg(Section,x86_Any,Opcode.rt,1), Address); - Compile_SW_Register(Map_TempReg(Section,TempReg1,Opcode.rt,0), Address + 4); - } - return; - } - if (IsMapped(Opcode.rt)) { ProtectGPR(Section,Opcode.rt); } - if (IsMapped(Opcode.base)) { - ProtectGPR(Section,Opcode.base); - if (Opcode.offset != 0) { - TempReg1 = Map_TempReg(Section,x86_Any,-1,0); - LeaSourceAndOffset(TempReg1,MipsRegLo(Opcode.base),(short)Opcode.offset); - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - } - } else { - TempReg1 = Map_TempReg(Section,x86_Any,Opcode.base,0); - if (Opcode.immediate == 0) { - } else if (Opcode.immediate == 1) { - IncX86reg(TempReg1); - } else if (Opcode.immediate == 0xFFFF) { - DecX86reg(TempReg1); - } else { - AddConstToX86Reg(TempReg1,(short)Opcode.immediate); - } - } - - TempReg2 = Map_TempReg(Section,x64_Any,-1,0); - MoveX86RegToX86Reg(TempReg1, TempReg2); - ShiftRightUnsignImmed(TempReg2,12); - //MoveVariableDispToX86Reg(TLB_Map,TempReg2,TempReg2,8); - LOAD_FROM_TLB(TempReg2, TempReg2); - //For tlb miss - //0041C522 85 C0 test eax,eax - //0041C524 75 01 jne 0041C527 - - if (IsConst(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { - MoveConstToX86regPointer(MipsRegHi(Opcode.rt),TempReg1, TempReg2); - } else { - MoveConstToX86regPointer((MipsRegLo_S(Opcode.rt) >> 31),TempReg1, TempReg2); - } - AddConstToX86Reg(TempReg1,4); - MoveConstToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else if (IsMapped(Opcode.rt)) { - if (Is64Bit(Opcode.rt)) { - MoveX86regToX86regPointer(MipsRegHi(Opcode.rt),TempReg1, TempReg2); - } else { - MoveX86regToX86regPointer(Map_TempReg(Section,x86_Any,Opcode.rt,1),TempReg1, TempReg2); - } - AddConstToX86Reg(TempReg1,4); - MoveX86regToX86regPointer(MipsRegLo(Opcode.rt),TempReg1, TempReg2); - } else { - int32_t X86Reg = Map_TempReg(Section,x86_Any,Opcode.rt,1); - MoveX86regToX86regPointer(X86Reg,TempReg1, TempReg2); - AddConstToX86Reg(TempReg1,4); - MoveX86regToX86regPointer(Map_TempReg(Section,X86Reg,Opcode.rt,0),TempReg1, TempReg2); - } - -} - -/********************** R4300i OpCodes: Special **********************/ -void Compile_R4300i_SPECIAL_SLL (BLOCK_SECTION * Section) { - - - if (Opcode.rd == 0) { return; } - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) << Opcode.sa; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - if (Opcode.rd != Opcode.rt && IsMapped(Opcode.rt)) { - switch (Opcode.sa) { - case 0: - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - break; - case 1: - ProtectGPR(Section,Opcode.rt); - Map_GPR_32bit(Section,Opcode.rd,1,-1); - LeaRegReg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt), 2); - break; - case 2: - ProtectGPR(Section,Opcode.rt); - Map_GPR_32bit(Section,Opcode.rd,1,-1); - LeaRegReg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt), 4); - break; - case 3: - ProtectGPR(Section,Opcode.rt); - Map_GPR_32bit(Section,Opcode.rd,1,-1); - LeaRegReg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt), 8); - break; - default: - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftLeftSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } - } else { - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftLeftSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } -} - -void Compile_R4300i_SPECIAL_SRL (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) >> Opcode.sa; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightUnsignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); -} - -void Compile_R4300i_SPECIAL_SRA (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo_S(Opcode.rt) >> Opcode.sa; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); -} - -void Compile_R4300i_SPECIAL_SLLV (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x1F); - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) << Shift; - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftLeftSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Shift); - } - return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x1F); - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftLeftSign(MipsRegLo(Opcode.rd)); -} - -void Compile_R4300i_SPECIAL_SRLV (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsKnown(Opcode.rs) && IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x1F); - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) >> Shift; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightUnsignImmed(MipsRegLo(Opcode.rd),(uint8_t)Shift); - return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x1F); - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightUnsign(MipsRegLo(Opcode.rd)); -} - -void Compile_R4300i_SPECIAL_SRAV (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsKnown(Opcode.rs) && IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x1F); - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = MipsRegLo_S(Opcode.rt) >> Shift; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Shift); - return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x1F); - Map_GPR_32bit(Section,Opcode.rd,1,Opcode.rt); - ShiftRightSign(MipsRegLo(Opcode.rd)); -} - -void Compile_R4300i_SPECIAL_JR (BLOCK_SECTION * Section) { - - if ( NextInstruction == NORMAL ) { - - if (IsConst(Opcode.rs)) { - Section->Jump.TargetPC = MipsRegLo(Opcode.rs); - Section->Jump.FallThrough = 1; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - Section->Cont.FallThrough = 0; - Section->Cont.LinkLocation = NULL; - Section->Cont.LinkLocation2 = NULL; - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - GenerateSectionLinkage(Section); - NextInstruction = END_BLOCK; - return; - } - } - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - if (IsMapped(Opcode.rs)) { - MoveX86regToVariable(MipsRegLo(Opcode.rs),&JumpToLocation); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,0),&JumpToLocation); - } - MoveConstToVariable(Section->CompilePC + 4,&PROGRAM_COUNTER); - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - WriteBackRegisters(Section); - MoveConstToVariable(DELAY_SLOT,&NextInstruction); - Ret(); - NextInstruction = END_BLOCK; - return; - } - if (DelaySlotEffectsCompare(Section->CompilePC,Opcode.rs,0)) { - if (IsConst(Opcode.rs)) { - MoveConstToVariable(MipsRegLo(Opcode.rs),&PROGRAM_COUNTER); - } else if (IsMapped(Opcode.rs)) { - MoveX86regToVariable(MipsRegLo(Opcode.rs),&PROGRAM_COUNTER); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,0),&PROGRAM_COUNTER); - } - } - NextInstruction = DO_DELAY_SLOT; - } else if (NextInstruction == DELAY_SLOT_DONE ) { - if (DelaySlotEffectsCompare(Section->CompilePC,Opcode.rs,0)) { - - CompileExit((uint32_t)-1,&Section->RegWorking,Normal,1,NULL); - } else { - if (IsConst(Opcode.rs)) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - GenerateSectionLinkage(Section); - } else { - if (IsMapped(Opcode.rs)) { - - MoveX86regToVariable(MipsRegLo(Opcode.rs),&PROGRAM_COUNTER); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,0),&PROGRAM_COUNTER); - } - CompileExit((uint32_t)-1,&Section->RegWorking,Normal,1,NULL); - } - } - NextInstruction = END_BLOCK; - } else { -#ifndef EXTERNAL_RELEASE - DisplayError("WTF\n\nBranch\nNextInstruction = %X", NextInstruction); -#endif - } -} - -void Compile_R4300i_SPECIAL_JALR (BLOCK_SECTION * Section) { - if ( NextInstruction == NORMAL ) { - - if (DelaySlotEffectsCompare(Section->CompilePC,Opcode.rs,0)) { - Compile_R4300i_UnknownOpcode(Section); - } - UnMap_GPR(Section, Opcode.rd, 0); - MipsRegLo(Opcode.rd) = Section->CompilePC + 8; - MipsRegState(Opcode.rd) = STATE_CONST_32; - if ((Section->CompilePC & 0xFFC) == 0xFFC) { - if (IsMapped(Opcode.rs)) { - MoveX86regToVariable(MipsRegLo(Opcode.rs),&JumpToLocation); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,0),&JumpToLocation); - } - MoveConstToVariable(Section->CompilePC + 4,&PROGRAM_COUNTER); - if (BlockCycleCount != 0) { - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - } - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - WriteBackRegisters(Section); - MoveConstToVariable(DELAY_SLOT,&NextInstruction); - Ret(); - NextInstruction = END_BLOCK; - return; - } - NextInstruction = DO_DELAY_SLOT; - } else if (NextInstruction == DELAY_SLOT_DONE ) { - if (IsConst(Opcode.rs)) { - memcpy(&Section->Jump.RegSet,&Section->RegWorking,sizeof(REG_INFO)); - Section->Jump.TargetPC = MipsRegLo(Opcode.rs); - Section->Jump.FallThrough = 1; - Section->Jump.LinkLocation = NULL; - Section->Jump.LinkLocation2 = NULL; - Section->Cont.FallThrough = 0; - Section->Cont.LinkLocation = NULL; - Section->Cont.LinkLocation2 = NULL; - - GenerateSectionLinkage(Section); - } else { - if (IsMapped(Opcode.rs)) { - MoveX86regToVariable(MipsRegLo(Opcode.rs),&PROGRAM_COUNTER); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,0),&PROGRAM_COUNTER); - } - CompileExit((uint32_t)-1,&Section->RegWorking,Normal,1,NULL); - } - NextInstruction = END_BLOCK; - } else { - } -} - -void Compile_R4300i_SPECIAL_SYSCALL (BLOCK_SECTION * Section) { - CompileExit(Section->CompilePC,&Section->RegWorking,DoSysCall,1,NULL); -} - -void Compile_R4300i_SPECIAL_BREAK (BLOCK_SECTION * Section) { - //CompileExit(Section->CompilePC,Section->RegWorking,DoBreak,1,NULL); - MoveConstToVariable(1,WaitMode); -} - - -void Compile_R4300i_SPECIAL_MFLO (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - Map_GPR_64bit(Section,Opcode.rd,-1); - MoveVariableToX86reg(&LO.UW[0],MipsRegLo(Opcode.rd)); - MoveVariableToX86reg(&LO.UW[1],MipsRegHi(Opcode.rd)); -} - -void Compile_R4300i_SPECIAL_MTLO (BLOCK_SECTION * Section) { - - - if (IsKnown(Opcode.rs) && IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - MoveConstToVariable(MipsRegHi(Opcode.rs),&LO.UW[1]); - } else if (IsSigned(Opcode.rs) && ((MipsRegLo(Opcode.rs) & 0x80000000) != 0)) { - MoveConstToVariable(0xFFFFFFFF,&LO.UW[1]); - } else { - MoveConstToVariable(0,&LO.UW[1]); - } - MoveConstToVariable(MipsRegLo(Opcode.rs), &LO.UW[0]); - } else if (IsKnown(Opcode.rs) && IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - MoveX86regToVariable(MipsRegHi(Opcode.rs),&LO.UW[1]); - } else if (IsSigned(Opcode.rs)) { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,1),&LO.UW[1]); - } else { - MoveConstToVariable(0,&LO.UW[1]); - } - MoveX86regToVariable(MipsRegLo(Opcode.rs), &LO.UW[0]); - } else { - int32_t x86reg = Map_TempReg(Section,x86_Any,Opcode.rs,1); - MoveX86regToVariable(x86reg,&LO.UW[1]); - MoveX86regToVariable(Map_TempReg(Section,x86reg,Opcode.rs,0), &LO.UW[0]); - } -} - -void Compile_R4300i_SPECIAL_MFHI (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - Map_GPR_64bit(Section,Opcode.rd,-1); - MoveVariableToX86reg(&HI.UW[0],MipsRegLo(Opcode.rd)); - MoveVariableToX86reg(&HI.UW[1],MipsRegHi(Opcode.rd)); -} - -void Compile_R4300i_SPECIAL_MTHI (BLOCK_SECTION * Section) { - - if (IsKnown(Opcode.rs) && IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - MoveConstToVariable(MipsRegHi(Opcode.rs),&HI.UW[1]); - } else if (IsSigned(Opcode.rs) && ((MipsRegLo(Opcode.rs) & 0x80000000) != 0)) { - MoveConstToVariable(0xFFFFFFFF,&HI.UW[1]); - } else { - MoveConstToVariable(0,&HI.UW[1]); - } - MoveConstToVariable(MipsRegLo(Opcode.rs), &HI.UW[0]); - } else if (IsKnown(Opcode.rs) && IsMapped(Opcode.rs)) { - if (Is64Bit(Opcode.rs)) { - MoveX86regToVariable(MipsRegHi(Opcode.rs),&HI.UW[1]); - } else if (IsSigned(Opcode.rs)) { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rs,1),&HI.UW[1]); - } else { - MoveConstToVariable(0,&HI.UW[1]); - } - MoveX86regToVariable(MipsRegLo(Opcode.rs), &HI.UW[0]); - } else { - int32_t x86reg = Map_TempReg(Section,x86_Any,Opcode.rs,1); - MoveX86regToVariable(x86reg,&HI.UW[1]); - MoveX86regToVariable(Map_TempReg(Section,x86reg,Opcode.rs,0), &HI.UW[0]); - } -} - -void Compile_R4300i_SPECIAL_DSLLV (BLOCK_SECTION * Section) { - uint8_t * Jump[2]; - - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x3F); - Compile_R4300i_UnknownOpcode(Section); - return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x3F); - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - CompConstToX86reg(x86_ECX,0x20); - JaeLabel8( 0); - Jump[0] = RecompPos - 1; - ShiftLeftDouble(MipsRegHi(Opcode.rd),MipsRegLo(Opcode.rd)); - ShiftLeftSign(MipsRegLo(Opcode.rd)); - JmpLabel8( 0); - Jump[1] = RecompPos - 1; - - //MORE32: - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - MoveX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegHi(Opcode.rd)); - XorX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rd)); - AndConstToX86Reg(x86_ECX,0x1F); - ShiftLeftSign(MipsRegHi(Opcode.rd)); - - //continue: - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); -} - -void Compile_R4300i_SPECIAL_DSRLV (BLOCK_SECTION * Section) { - uint8_t * Jump[2]; - - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x3F); - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsReg(Opcode.rd) = Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt); - MipsReg(Opcode.rd) = MipsReg(Opcode.rd) >> Shift; - if ((MipsRegHi(Opcode.rd) == 0) && (MipsRegLo(Opcode.rd) & 0x80000000) == 0) { - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if ((MipsRegHi(Opcode.rd) == 0xFFFFFFFF) && (MipsRegLo(Opcode.rd) & 0x80000000) != 0) { - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - return; - } - //if (Shift < 0x20) { - //} else { - //} - //Compile_R4300i_UnknownOpcode(Section); - //return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x3F); - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - CompConstToX86reg(x86_ECX,0x20); - JaeLabel8( 0); - Jump[0] = RecompPos - 1; - ShiftRightDouble(MipsRegLo(Opcode.rd),MipsRegHi(Opcode.rd)); - ShiftRightUnsign(MipsRegHi(Opcode.rd)); - JmpLabel8( 0); - Jump[1] = RecompPos - 1; - - //MORE32: - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - MoveX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegLo(Opcode.rd)); - XorX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(Opcode.rd)); - AndConstToX86Reg(x86_ECX,0x1F); - ShiftRightUnsign(MipsRegLo(Opcode.rd)); - - //continue: - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); -} - -void Compile_R4300i_SPECIAL_DSRAV (BLOCK_SECTION * Section) { - uint8_t * Jump[2]; - - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rs)) { - uint32_t Shift = (MipsRegLo(Opcode.rs) & 0x3F); - Compile_R4300i_UnknownOpcode(Section); - return; - } - Map_TempReg(Section,x86_ECX,Opcode.rs,0); - AndConstToX86Reg(x86_ECX,0x3F); - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - CompConstToX86reg(x86_ECX,0x20); - JaeLabel8( 0); - Jump[0] = RecompPos - 1; - ShiftRightDouble(MipsRegLo(Opcode.rd),MipsRegHi(Opcode.rd)); - ShiftRightSign(MipsRegHi(Opcode.rd)); - JmpLabel8( 0); - Jump[1] = RecompPos - 1; - - //MORE32: - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - MoveX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegLo(Opcode.rd)); - ShiftRightSignImmed(MipsRegHi(Opcode.rd),0x1F); - AndConstToX86Reg(x86_ECX,0x1F); - ShiftRightSign(MipsRegLo(Opcode.rd)); - - //continue: - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); -} - -void Compile_R4300i_SPECIAL_MULT ( BLOCK_SECTION * Section) { - - - x86Protected(x86_EDX) = 1; - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - x86Protected(x86_EDX) = 0; - Map_TempReg(Section,x86_EDX,Opcode.rt,0); - - imulX86reg(x86_EDX); - - MoveX86regToVariable(x86_EAX,&LO.UW[0]); - MoveX86regToVariable(x86_EDX,&HI.UW[0]); - ShiftRightSignImmed(x86_EAX,31); /* paired */ - ShiftRightSignImmed(x86_EDX,31); - MoveX86regToVariable(x86_EAX,&LO.UW[1]); - MoveX86regToVariable(x86_EDX,&HI.UW[1]); -} - -void Compile_R4300i_SPECIAL_MULTU (BLOCK_SECTION * Section) { - - - x86Protected(x86_EDX) = 1; - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - x86Protected(x86_EDX) = 0; - Map_TempReg(Section,x86_EDX,Opcode.rt,0); - - MulX86reg(x86_EDX); - - MoveX86regToVariable(x86_EAX,&LO.UW[0]); - MoveX86regToVariable(x86_EDX,&HI.UW[0]); - ShiftRightSignImmed(x86_EAX,31); /* paired */ - ShiftRightSignImmed(x86_EDX,31); - MoveX86regToVariable(x86_EAX,&LO.UW[1]); - MoveX86regToVariable(x86_EDX,&HI.UW[1]); -} - -void Compile_R4300i_SPECIAL_DIV (BLOCK_SECTION * Section) { - uint8_t *Jump[2]; - - - - if (IsConst(Opcode.rt)) { - if (MipsRegLo(Opcode.rt) == 0) { - MoveConstToVariable(0, &LO.UW[0]); - MoveConstToVariable(0, &LO.UW[1]); - MoveConstToVariable(0, &HI.UW[0]); - MoveConstToVariable(0, &HI.UW[1]); - return; - } - Jump[1] = NULL; - } else { - if (IsMapped(Opcode.rt)) { - CompConstToX86reg(MipsRegLo(Opcode.rt),0); - } else { - CompConstToVariable(0, &GPR[Opcode.rt].W[0]); - } - JneLabel8( 0); - Jump[0] = RecompPos - 1; - - MoveConstToVariable(0, &LO.UW[0]); - MoveConstToVariable(0, &LO.UW[1]); - MoveConstToVariable(0, &HI.UW[0]); - MoveConstToVariable(0, &HI.UW[1]); - - JmpLabel8( 0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - } - /* lo = (SD)rs / (SD)rt; - hi = (SD)rs % (SD)rt; */ - - x86Protected(x86_EDX) = 1; - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - - /* edx is the signed portion to eax */ - x86Protected(x86_EDX) = 0; - Map_TempReg(Section,x86_EDX, -1, 0); - - MoveX86RegToX86Reg(x86_EAX, x86_EDX); - ShiftRightSignImmed(x86_EDX,31); - - if (IsMapped(Opcode.rt)) { - idivX86reg(MipsRegLo(Opcode.rt)); - } else { - idivX86reg(Map_TempReg(Section,x86_Any,Opcode.rt,0)); - } - - - MoveX86regToVariable(x86_EAX,&LO.UW[0]); - MoveX86regToVariable(x86_EDX,&HI.UW[0]); - ShiftRightSignImmed(x86_EAX,31); /* paired */ - ShiftRightSignImmed(x86_EDX,31); - MoveX86regToVariable(x86_EAX,&LO.UW[1]); - MoveX86regToVariable(x86_EDX,&HI.UW[1]); - - if( Jump[1] != NULL ) { - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - } -} - -void Compile_R4300i_SPECIAL_DIVU ( BLOCK_SECTION * Section) { - uint8_t *Jump[2]; - int32_t x86reg; - - - - if (IsConst(Opcode.rt)) { - if (MipsRegLo(Opcode.rt) == 0) { - MoveConstToVariable(0, &LO.UW[0]); - MoveConstToVariable(0, &LO.UW[1]); - MoveConstToVariable(0, &HI.UW[0]); - MoveConstToVariable(0, &HI.UW[1]); - return; - } - Jump[1] = NULL; - } else { - if (IsMapped(Opcode.rt)) { - CompConstToX86reg(MipsRegLo(Opcode.rt),0); - } else { - CompConstToVariable(0, &GPR[Opcode.rt].W[0]); - } - JneLabel8( 0); - Jump[0] = RecompPos - 1; - - MoveConstToVariable(0, &LO.UW[0]); - MoveConstToVariable(0, &LO.UW[1]); - MoveConstToVariable(0, &HI.UW[0]); - MoveConstToVariable(0, &HI.UW[1]); - - JmpLabel8( 0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - } - - - /* lo = (UD)rs / (UD)rt; - hi = (UD)rs % (UD)rt; */ - - x86Protected(x86_EAX) = 1; - Map_TempReg(Section,x86_EDX, 0, 0); - x86Protected(x86_EAX) = 0; - - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - x86reg = Map_TempReg(Section,x86_Any,Opcode.rt,0); - - DivX86reg(x86reg); - - MoveX86regToVariable(x86_EAX,&LO.UW[0]); - MoveX86regToVariable(x86_EDX,&HI.UW[0]); - - /* wouldnt these be zero (???) */ - - ShiftRightSignImmed(x86_EAX,31); /* paired */ - ShiftRightSignImmed(x86_EDX,31); - MoveX86regToVariable(x86_EAX,&LO.UW[1]); - MoveX86regToVariable(x86_EDX,&HI.UW[1]); - - if( Jump[1] != NULL ) { - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - } -} - -void Compile_R4300i_SPECIAL_DMULT (BLOCK_SECTION * Section) { - - - if (Opcode.rs != 0) { UnMap_GPR(Section,Opcode.rs,1); } - if (Opcode.rs != 0) { UnMap_GPR(Section,Opcode.rt,1); } - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_SPECIAL_DMULT); - Popad(); -} - -void Compile_R4300i_SPECIAL_DMULTU (BLOCK_SECTION * Section) { - - - /* LO.UDW = (uint64)GPR[Opcode.rs].UW[0] * (uint64)GPR[Opcode.rt].UW[0]; */ - x86Protected(x86_EDX) = 1; - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - x86Protected(x86_EDX) = 0; - Map_TempReg(Section,x86_EDX,Opcode.rt,0); - - MulX86reg(x86_EDX); - MoveX86regToVariable(x86_EAX, &LO.UW[0]); - MoveX86regToVariable(x86_EDX, &LO.UW[1]); - - /* HI.UDW = (uint64)GPR[Opcode.rs].UW[1] * (uint64)GPR[Opcode.rt].UW[1]; */ - Map_TempReg(Section,x86_EAX,Opcode.rs,1); - Map_TempReg(Section,x86_EDX,Opcode.rt,1); - - MulX86reg(x86_EDX); - MoveX86regToVariable(x86_EAX, &HI.UW[0]); - MoveX86regToVariable(x86_EDX, &HI.UW[1]); - - /* Tmp[0].UDW = (uint64)GPR[Opcode.rs].UW[1] * (uint64)GPR[Opcode.rt].UW[0]; */ - Map_TempReg(Section,x86_EAX,Opcode.rs,1); - Map_TempReg(Section,x86_EDX,Opcode.rt,0); - - Map_TempReg(Section,x86_EBX,-1,0); - Map_TempReg(Section,x86_ECX,-1,0); - - MulX86reg(x86_EDX); - MoveX86RegToX86Reg(x86_EAX, x86_EBX); /* EDX:EAX -> ECX:EBX */ - MoveX86RegToX86Reg(x86_EDX, x86_ECX); - - /* Tmp[1].UDW = (uint64)GPR[Opcode.rs].UW[0] * (uint64)GPR[Opcode.rt].UW[1]; */ - Map_TempReg(Section,x86_EAX,Opcode.rs,0); - Map_TempReg(Section,x86_EDX,Opcode.rt,1); - - MulX86reg(x86_EDX); - Map_TempReg(Section,x86_ESI,-1,0); - Map_TempReg(Section,x86_EDI,-1,0); - MoveX86RegToX86Reg(x86_EAX, x86_ESI); /* EDX:EAX -> EDI:ESI */ - MoveX86RegToX86Reg(x86_EDX, x86_EDI); - - /* Tmp[2].UDW = (uint64)LO.UW[1] + (uint64)Tmp[0].UW[0] + (uint64)Tmp[1].UW[0]; */ - XorX86RegToX86Reg(x86_EDX, x86_EDX); - MoveVariableToX86reg(&LO.UW[1], x86_EAX); - AddX86RegToX86Reg(x86_EAX, x86_EBX); - AddConstToX86Reg(x86_EDX, 0); - AddX86RegToX86Reg(x86_EAX, x86_ESI); - AddConstToX86Reg(x86_EDX, 0); /* EDX:EAX */ - - /* LO.UDW += ((uint64)Tmp[0].UW[0] + (uint64)Tmp[1].UW[0]) << 32; */ - /* [low+4] += ebx + esi */ - - AddX86regToVariable(x86_EBX, &LO.UW[1]); - AddX86regToVariable(x86_ESI, &LO.UW[1]); - - /* HI.UDW += (uint64)Tmp[0].UW[1] + (uint64)Tmp[1].UW[1] + Tmp[2].UW[1]; */ - /* [hi] += ecx + edi + edx */ - - /*AddX86regToVariable(x86_ECX, &HI.UW[0]); - AdcConstToVariable(&HI.UW[1], 0); - - AddX86regToVariable(x86_EDI, &HI.UW[0]); - AdcConstToVariable(&HI.UW[1], 0); - - AddX86regToVariable(x86_EDX, &HI.UW[0]); - AdcConstToVariable(&HI.UW[1], 0);*/ -} - -void Compile_R4300i_SPECIAL_DDIV (BLOCK_SECTION * Section) { - - - UnMap_GPR(Section,Opcode.rs,1); - UnMap_GPR(Section,Opcode.rt,1); - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_SPECIAL_DDIV); - Popad(); -} - -void Compile_R4300i_SPECIAL_DDIVU (BLOCK_SECTION * Section) { - - - UnMap_GPR(Section,Opcode.rs,1); - UnMap_GPR(Section,Opcode.rt,1); - Pushad(); - MoveConstToVariable(Opcode.Hex, &Opcode.Hex ); - Call_Direct(r4300i_SPECIAL_DDIVU); - Popad(); -} - -void Compile_R4300i_SPECIAL_ADD (BLOCK_SECTION * Section) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - - if (Opcode.rd == 0) { return; } - - if (IsConst(source1) && IsConst(source2)) { - uint32_t temp = MipsRegLo(source1) + MipsRegLo(source2); - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = temp; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - - Map_GPR_32bit(Section,Opcode.rd,1, source1); - if (IsConst(source2)) { - if (MipsRegLo(source2) != 0) { - AddConstToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } - } else if (IsKnown(source2) && IsMapped(source2)) { - AddX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else { - AddVariableToX86reg(MipsRegLo(Opcode.rd),&GPR[source2].W[0]); - } -} - -void Compile_R4300i_SPECIAL_ADDU (BLOCK_SECTION * Section) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - - if (Opcode.rd == 0) { return; } - - if (IsConst(source1) && IsConst(source2)) { - uint32_t temp = MipsRegLo(source1) + MipsRegLo(source2); - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = temp; - MipsRegState(Opcode.rd) = STATE_CONST_32; - return; - } - - Map_GPR_32bit(Section,Opcode.rd,1, source1); - if (IsConst(source2)) { - if (MipsRegLo(source2) != 0) { - AddConstToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } - } else if (IsKnown(source2) && IsMapped(source2)) { - AddX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else { - AddVariableToX86reg(MipsRegLo(Opcode.rd),&GPR[source2].W[0]); - } -} - -void Compile_R4300i_SPECIAL_SUB (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - uint32_t temp = MipsRegLo(Opcode.rs) - MipsRegLo(Opcode.rt); - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = temp; - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - if (Opcode.rd == Opcode.rt) { - int32_t x86Reg = Map_TempReg(Section,x86_Any,Opcode.rt,0); - Map_GPR_32bit(Section,Opcode.rd,1, Opcode.rs); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),x86Reg); - return; - } - Map_GPR_32bit(Section,Opcode.rd,1, Opcode.rs); - if (IsConst(Opcode.rt)) { - SubConstFromX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - } else { - SubVariableFromX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - } - } -} - -void Compile_R4300i_SPECIAL_SUBU (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - uint32_t temp = MipsRegLo(Opcode.rs) - MipsRegLo(Opcode.rt); - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegLo(Opcode.rd) = temp; - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - if (Opcode.rd == Opcode.rt) { - int32_t x86Reg = Map_TempReg(Section,x86_Any,Opcode.rt,0); - Map_GPR_32bit(Section,Opcode.rd,1, Opcode.rs); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),x86Reg); - return; - } - Map_GPR_32bit(Section,Opcode.rd,1, Opcode.rs); - if (IsConst(Opcode.rt)) { - SubConstFromX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - } else { - SubVariableFromX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - } - } -} - -void Compile_R4300i_SPECIAL_AND (BLOCK_SECTION * Section) { - - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - MipsReg(Opcode.rd) = - (Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt)) & - (Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs)); - - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - MipsReg(Opcode.rd) = MipsRegLo(Opcode.rt) & MipsReg(Opcode.rs); - MipsRegState(Opcode.rd) = STATE_CONST_32; - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - ProtectGPR(Section,source1); - ProtectGPR(Section,source2); - if (Is32Bit(source1) && Is32Bit(source2)) { - int32_t Sign = (IsSigned(Opcode.rt) && IsSigned(Opcode.rs))?1:0; - Map_GPR_32bit(Section,Opcode.rd,Sign,source1); - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else if (Is32Bit(source1) || Is32Bit(source2)) { - if (IsUnsigned(Is32Bit(source1)?source1:source2)) { - Map_GPR_32bit(Section,Opcode.rd,0,source1); - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else { - Map_GPR_64bit(Section,Opcode.rd,source1); - if (Is32Bit(source2)) { - AndX86RegToX86Reg(MipsRegHi(Opcode.rd),Map_TempReg(Section,x86_Any,source2,1)); - } else { - AndX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(source2)); - } - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,source1); - AndX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(source2)); - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } - } else { - int32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - int32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(ConstReg)) { - if (Is32Bit(MappedReg) && IsUnsigned(MappedReg)) { - if (MipsRegLo(ConstReg) == 0) { - Map_GPR_32bit(Section,Opcode.rd,0, 0); - } else { - uint32_t Value = MipsRegLo(ConstReg); - Map_GPR_32bit(Section,Opcode.rd,0, MappedReg); - AndConstToX86Reg(MipsRegLo(Opcode.rd),Value); - } - } else { - int64_t Value = MipsReg(ConstReg); - Map_GPR_64bit(Section,Opcode.rd,MappedReg); - AndConstToX86Reg(MipsRegHi(Opcode.rd),(uint32_t)(Value >> 32)); - AndConstToX86Reg(MipsRegLo(Opcode.rd),(uint32_t)Value); - } - } else if (Is64Bit(MappedReg)) { - uint32_t Value = MipsRegLo(ConstReg); - if (Value != 0) { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(ConstReg)?1:0,MappedReg); - AndConstToX86Reg(MipsRegLo(Opcode.rd),(uint32_t)Value); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(ConstReg)?1:0, 0); - } - } else { - uint32_t Value = MipsRegLo(ConstReg); - int32_t Sign = 0; - if (IsSigned(ConstReg) && IsSigned(MappedReg)) { Sign = 1; } - if (Value != 0) { - Map_GPR_32bit(Section,Opcode.rd,Sign,MappedReg); - AndConstToX86Reg(MipsRegLo(Opcode.rd),Value); - } else { - Map_GPR_32bit(Section,Opcode.rd,0, 0); - } - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - uint32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - if (Is64Bit(KnownReg)) { - uint64_t Value = MipsReg(KnownReg); - Map_GPR_64bit(Section,Opcode.rd,UnknownReg); - AndConstToX86Reg(MipsRegHi(Opcode.rd),(uint32_t)(Value >> 32)); - AndConstToX86Reg(MipsRegLo(Opcode.rd),(uint32_t)Value); - } else { - uint32_t Value = MipsRegLo(KnownReg); - Map_GPR_32bit(Section,Opcode.rd,IsSigned(KnownReg),UnknownReg); - AndConstToX86Reg(MipsRegLo(Opcode.rd),(uint32_t)Value); - } - } else { - ProtectGPR(Section,KnownReg); - if (KnownReg == Opcode.rd) { - if (Is64Bit(KnownReg)) { - Map_GPR_64bit(Section,Opcode.rd,KnownReg); - AndVariableToX86Reg(&GPR[UnknownReg].W[1],MipsRegHi(Opcode.rd)); - AndVariableToX86Reg(&GPR[UnknownReg].W[0],MipsRegLo(Opcode.rd)); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(KnownReg),KnownReg); - AndVariableToX86Reg(&GPR[UnknownReg].W[0],MipsRegLo(Opcode.rd)); - } - } else { - if (Is64Bit(KnownReg)) { - Map_GPR_64bit(Section,Opcode.rd,UnknownReg); - AndX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(KnownReg)); - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(KnownReg)); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(KnownReg),UnknownReg); - AndX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(KnownReg)); - } - } - } - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - AndVariableToX86Reg(&GPR[Opcode.rs].W[1],MipsRegHi(Opcode.rd)); - AndVariableToX86Reg(&GPR[Opcode.rs].W[0],MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_OR (BLOCK_SECTION * Section) { - - - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - MipsReg(Opcode.rd) = - (Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt)) | - (Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs)); - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) | MipsRegLo(Opcode.rs); - MipsRegState(Opcode.rd) = STATE_CONST_32; - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - ProtectGPR(Section,Opcode.rt); - ProtectGPR(Section,Opcode.rs); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - Map_GPR_64bit(Section,Opcode.rd,source1); - if (Is64Bit(source2)) { - OrX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(source2)); - } else { - OrX86RegToX86Reg(MipsRegHi(Opcode.rd),Map_TempReg(Section,x86_Any,source2,1)); - } - } else { - ProtectGPR(Section,source2); - Map_GPR_32bit(Section,Opcode.rd,1,source1); - } - OrX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else { - uint32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint64_t Value; - - if (Is64Bit(ConstReg)) { - Value = MipsReg(ConstReg); - } else { - Value = IsSigned(ConstReg)?MipsRegLo_S(ConstReg):MipsRegLo(ConstReg); - } - Map_GPR_64bit(Section,Opcode.rd,MappedReg); - if ((Value >> 32) != 0) { - OrConstToX86Reg((uint32_t)(Value >> 32),MipsRegHi(Opcode.rd)); - } - if ((uint32_t)Value != 0) { - OrConstToX86Reg((uint32_t)Value,MipsRegLo(Opcode.rd)); - } - } else { - int32_t Value = MipsRegLo(ConstReg); - Map_GPR_32bit(Section,Opcode.rd,1, MappedReg); - if (Value != 0) { OrConstToX86Reg(Value,MipsRegLo(Opcode.rd)); } - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - int32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - int32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - uint64_t Value; - - Value = Is64Bit(KnownReg)?MipsReg(KnownReg):MipsRegLo_S(KnownReg); - Map_GPR_64bit(Section,Opcode.rd,UnknownReg); - if ((Value >> 32) != 0) { - OrConstToX86Reg((uint32_t)(Value >> 32),MipsRegHi(Opcode.rd)); - } - if ((uint32_t)Value != 0) { - OrConstToX86Reg((uint32_t)Value,MipsRegLo(Opcode.rd)); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,KnownReg); - OrVariableToX86Reg(&GPR[UnknownReg].W[1],MipsRegHi(Opcode.rd)); - OrVariableToX86Reg(&GPR[UnknownReg].W[0],MipsRegLo(Opcode.rd)); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - OrVariableToX86Reg(&GPR[Opcode.rs].W[1],MipsRegHi(Opcode.rd)); - OrVariableToX86Reg(&GPR[Opcode.rs].W[0],MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_XOR (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - //BreakPoint(); - - if (Opcode.rt == Opcode.rs) { - UnMap_GPR(Section, Opcode.rd, 0); - MipsRegState(Opcode.rd) = STATE_CONST_32; - MipsRegLo(Opcode.rd) = 0; - return; - } - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { -#ifndef EXTERNAL_RELEASE - DisplayError("XOR 1"); -#endif - Compile_R4300i_UnknownOpcode(Section); - } else { - MipsRegState(Opcode.rd) = STATE_CONST_32; - MipsRegLo(Opcode.rd) = MipsRegLo(Opcode.rt) ^ MipsRegLo(Opcode.rs); - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - ProtectGPR(Section,source1); - ProtectGPR(Section,source2); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - Map_GPR_64bit(Section,Opcode.rd,source1); - if (Is64Bit(source2)) { - XorX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(source2)); - } else if (IsSigned(source2)) { - XorX86RegToX86Reg(MipsRegHi(Opcode.rd),Map_TempReg(Section,x86_Any,source2,1)); - } - XorX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } else { - if (IsSigned(Opcode.rt) != IsSigned(Opcode.rs)) { - Map_GPR_32bit(Section,Opcode.rd,1,source1); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(Opcode.rt),source1); - } - XorX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - } - } else { - uint32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint32_t ConstHi, ConstLo; - - ConstHi = Is32Bit(ConstReg)?(uint32_t)(MipsRegLo_S(ConstReg) >> 31):MipsRegHi(ConstReg); - ConstLo = MipsRegLo(ConstReg); - Map_GPR_64bit(Section,Opcode.rd,MappedReg); - if (ConstHi != 0) { XorConstToX86Reg(MipsRegHi(Opcode.rd),ConstHi); } - if (ConstLo != 0) { XorConstToX86Reg(MipsRegLo(Opcode.rd),ConstLo); } - } else { - int32_t Value = MipsRegLo(ConstReg); - if (IsSigned(Opcode.rt) != IsSigned(Opcode.rs)) { - Map_GPR_32bit(Section,Opcode.rd,1, MappedReg); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(MappedReg)?1:0, MappedReg); - } - if (Value != 0) { XorConstToX86Reg(MipsRegLo(Opcode.rd),Value); } - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - int32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - int32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - uint64_t Value; - - if (Is64Bit(KnownReg)) { - Value = MipsReg(KnownReg); - } else { - if (IsSigned(KnownReg)) { - Value = (int32_t)MipsRegLo(KnownReg); - } else { - Value = MipsRegLo(KnownReg); - } - } - Map_GPR_64bit(Section,Opcode.rd,UnknownReg); - if ((Value >> 32) != 0) { - XorConstToX86Reg(MipsRegHi(Opcode.rd),(uint32_t)(Value >> 32)); - } - if ((uint32_t)Value != 0) { - XorConstToX86Reg(MipsRegLo(Opcode.rd),(uint32_t)Value); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,KnownReg); - XorVariableToX86reg(&GPR[UnknownReg].W[1],MipsRegHi(Opcode.rd)); - XorVariableToX86reg(&GPR[UnknownReg].W[0],MipsRegLo(Opcode.rd)); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - XorVariableToX86reg(&GPR[Opcode.rs].W[1],MipsRegHi(Opcode.rd)); - XorVariableToX86reg(&GPR[Opcode.rs].W[0],MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_NOR (BLOCK_SECTION * Section) { - - - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - Compile_R4300i_UnknownOpcode(Section); - } else { - MipsRegLo(Opcode.rd) = ~(MipsRegLo(Opcode.rt) | MipsRegLo(Opcode.rs)); - MipsRegState(Opcode.rd) = STATE_CONST_32; - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - int32_t source1 = Opcode.rd == Opcode.rt?Opcode.rt:Opcode.rs; - int32_t source2 = Opcode.rd == Opcode.rt?Opcode.rs:Opcode.rt; - - ProtectGPR(Section,source1); - ProtectGPR(Section,source2); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - Map_GPR_64bit(Section,Opcode.rd,source1); - if (Is64Bit(source2)) { - OrX86RegToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(source2)); - } else { - OrX86RegToX86Reg(MipsRegHi(Opcode.rd),Map_TempReg(Section,x86_Any,source2,1)); - } - OrX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - NotX86Reg(MipsRegHi(Opcode.rd)); - NotX86Reg(MipsRegLo(Opcode.rd)); - } else { - ProtectGPR(Section,source2); - if (IsSigned(Opcode.rt) != IsSigned(Opcode.rs)) { - Map_GPR_32bit(Section,Opcode.rd,1,source1); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(Opcode.rt),source1); - } - OrX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(source2)); - NotX86Reg(MipsRegLo(Opcode.rd)); - } - } else { - uint32_t ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint64_t Value; - - if (Is64Bit(ConstReg)) { - Value = MipsReg(ConstReg); - } else { - Value = IsSigned(ConstReg)?MipsRegLo_S(ConstReg):MipsRegLo(ConstReg); - } - Map_GPR_64bit(Section,Opcode.rd,MappedReg); - if ((Value >> 32) != 0) { - OrConstToX86Reg((uint32_t)(Value >> 32),MipsRegHi(Opcode.rd)); - } - if ((uint32_t)Value != 0) { - OrConstToX86Reg((uint32_t)Value,MipsRegLo(Opcode.rd)); - } - NotX86Reg(MipsRegHi(Opcode.rd)); - NotX86Reg(MipsRegLo(Opcode.rd)); - } else { - int32_t Value = MipsRegLo(ConstReg); - if (IsSigned(Opcode.rt) != IsSigned(Opcode.rs)) { - Map_GPR_32bit(Section,Opcode.rd,1, MappedReg); - } else { - Map_GPR_32bit(Section,Opcode.rd,IsSigned(MappedReg)?1:0, MappedReg); - } - if (Value != 0) { OrConstToX86Reg(Value,MipsRegLo(Opcode.rd)); } - NotX86Reg(MipsRegLo(Opcode.rd)); - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - int32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - int32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - - if (IsConst(KnownReg)) { - uint64_t Value; - - Value = Is64Bit(KnownReg)?MipsReg(KnownReg):MipsRegLo_S(KnownReg); - Map_GPR_64bit(Section,Opcode.rd,UnknownReg); - if ((Value >> 32) != 0) { - OrConstToX86Reg((uint32_t)(Value >> 32),MipsRegHi(Opcode.rd)); - } - if ((uint32_t)Value != 0) { - OrConstToX86Reg((uint32_t)Value,MipsRegLo(Opcode.rd)); - } - } else { - Map_GPR_64bit(Section,Opcode.rd,KnownReg); - OrVariableToX86Reg(&GPR[UnknownReg].W[1],MipsRegHi(Opcode.rd)); - OrVariableToX86Reg(&GPR[UnknownReg].W[0],MipsRegLo(Opcode.rd)); - } - NotX86Reg(MipsRegHi(Opcode.rd)); - NotX86Reg(MipsRegLo(Opcode.rd)); - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - OrVariableToX86Reg(&GPR[Opcode.rs].W[1],MipsRegHi(Opcode.rd)); - OrVariableToX86Reg(&GPR[Opcode.rs].W[0],MipsRegLo(Opcode.rd)); - NotX86Reg(MipsRegHi(Opcode.rd)); - NotX86Reg(MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_SLT (BLOCK_SECTION * Section) { - - - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - DisplayError("1"); - Compile_R4300i_UnknownOpcode(Section); - } else { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegState(Opcode.rd) = STATE_CONST_32; - if (MipsRegLo_S(Opcode.rs) < MipsRegLo_S(Opcode.rt)) { - MipsRegLo(Opcode.rd) = 1; - } else { - MipsRegLo(Opcode.rd) = 0; - } - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - ProtectGPR(Section,Opcode.rt); - ProtectGPR(Section,Opcode.rs); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint8_t *Jump[2]; - - CompX86RegToX86Reg( - Is64Bit(Opcode.rs)?MipsRegHi(Opcode.rs):Map_TempReg(Section,x86_Any,Opcode.rs,1), - Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1) - ); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetlVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompX86RegToX86Reg(MipsRegLo(Opcode.rs), MipsRegLo(Opcode.rt)); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - Map_GPR_32bit(Section,Opcode.rd,1, -1); - CompX86RegToX86Reg(MipsRegLo(Opcode.rs), MipsRegLo(Opcode.rt)); - - if (MipsRegLo(Opcode.rd) > x86_EDX) { - SetlVariable(&BranchCompare); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - Setl(MipsRegLo(Opcode.rd)); - AndConstToX86Reg(MipsRegLo(Opcode.rd), 1); - } - } - } else { - uint32_t ConstReg = IsConst(Opcode.rs)?Opcode.rs:Opcode.rt; - uint32_t MappedReg = IsConst(Opcode.rs)?Opcode.rt:Opcode.rs; - - ProtectGPR(Section,MappedReg); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint8_t *Jump[2]; - - CompConstToX86reg( - Is64Bit(MappedReg)?MipsRegHi(MappedReg):Map_TempReg(Section,x86_Any,MappedReg,1), - Is64Bit(ConstReg)?MipsRegHi(ConstReg):(MipsRegLo_S(ConstReg) >> 31) - ); - JeLabel8(0); - Jump[0] = RecompPos - 1; - if (MappedReg == Opcode.rs) { - SetlVariable(&BranchCompare); - } else { - SetgVariable(&BranchCompare); - } - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToX86reg(MipsRegLo(MappedReg), MipsRegLo(ConstReg)); - if (MappedReg == Opcode.rs) { - SetbVariable(&BranchCompare); - } else { - SetaVariable(&BranchCompare); - } - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - uint32_t Constant = MipsRegLo(ConstReg); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - CompConstToX86reg(MipsRegLo(MappedReg), Constant); - - if (MipsRegLo(Opcode.rd) > x86_EDX) { - if (MappedReg == Opcode.rs) { - SetlVariable(&BranchCompare); - } else { - SetgVariable(&BranchCompare); - } - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - if (MappedReg == Opcode.rs) { - Setl(MipsRegLo(Opcode.rd)); - } else { - Setg(MipsRegLo(Opcode.rd)); - } - AndConstToX86Reg(MipsRegLo(Opcode.rd), 1); - } - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - uint32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - uint8_t *Jump[2]; - - if (IsConst(KnownReg)) { - if (Is64Bit(KnownReg)) { - CompConstToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(((int32_t)MipsRegLo(KnownReg) >> 31),&GPR[UnknownReg].W[1]); - } - } else { - if (Is64Bit(KnownReg)) { - CompX86regToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else { - ProtectGPR(Section,KnownReg); - CompX86regToVariable(Map_TempReg(Section,x86_Any,KnownReg,1),&GPR[UnknownReg].W[1]); - } - } - JeLabel8(0); - Jump[0] = RecompPos - 1; - if (KnownReg == (IsConst(KnownReg)?Opcode.rs:Opcode.rt)) { - SetgVariable(&BranchCompare); - } else { - SetlVariable(&BranchCompare); - } - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - if (IsConst(KnownReg)) { - CompConstToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } else { - CompX86regToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } - if (KnownReg == (IsConst(KnownReg)?Opcode.rs:Opcode.rt)) { - SetaVariable(&BranchCompare); - } else { - SetbVariable(&BranchCompare); - } - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - uint8_t *Jump[2]; - int32_t x86Reg; - - x86Reg = Map_TempReg(Section,x86_Any,Opcode.rs,1); - CompX86regToVariable(x86Reg,&GPR[Opcode.rt].W[1]); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetlVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompX86regToVariable(Map_TempReg(Section,x86Reg,Opcode.rs,0),&GPR[Opcode.rt].W[0]); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_SLTU (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsKnown(Opcode.rt) && IsKnown(Opcode.rs)) { - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { -#ifndef EXTERNAL_RELEASE - DisplayError("1"); -#endif - Compile_R4300i_UnknownOpcode(Section); - } else { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegState(Opcode.rd) = STATE_CONST_32; - if (MipsRegLo(Opcode.rs) < MipsRegLo(Opcode.rt)) { - MipsRegLo(Opcode.rd) = 1; - } else { - MipsRegLo(Opcode.rd) = 0; - } - } - } else if (IsMapped(Opcode.rt) && IsMapped(Opcode.rs)) { - ProtectGPR(Section,Opcode.rt); - ProtectGPR(Section,Opcode.rs); - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint8_t *Jump[2]; - - CompX86RegToX86Reg( - Is64Bit(Opcode.rs)?MipsRegHi(Opcode.rs):Map_TempReg(Section,x86_Any,Opcode.rs,1), - Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1) - ); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetbVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompX86RegToX86Reg(MipsRegLo(Opcode.rs), MipsRegLo(Opcode.rt)); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - CompX86RegToX86Reg(MipsRegLo(Opcode.rs), MipsRegLo(Opcode.rt)); - SetbVariable(&BranchCompare); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } - } else { - if (Is64Bit(Opcode.rt) || Is64Bit(Opcode.rs)) { - uint32_t MappedRegHi, MappedRegLo, ConstHi, ConstLo, MappedReg, ConstReg; - uint8_t *Jump[2]; - - ConstReg = IsConst(Opcode.rt)?Opcode.rt:Opcode.rs; - MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - ConstLo = MipsRegLo(ConstReg); - ConstHi = (int32_t)ConstLo >> 31; - if (Is64Bit(ConstReg)) { ConstHi = MipsRegHi(ConstReg); } - - ProtectGPR(Section,MappedReg); - MappedRegLo = MipsRegLo(MappedReg); - MappedRegHi = MipsRegHi(MappedReg); - if (Is32Bit(MappedReg)) { - MappedRegHi = Map_TempReg(Section,x86_Any,MappedReg,1); - } - - - Map_GPR_32bit(Section,Opcode.rd,1, -1); - CompConstToX86reg(MappedRegHi, ConstHi); - JeLabel8(0); - Jump[0] = RecompPos - 1; - if (MappedReg == Opcode.rs) { - SetbVariable(&BranchCompare); - } else { - SetaVariable(&BranchCompare); - } - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompConstToX86reg(MappedRegLo, ConstLo); - if (MappedReg == Opcode.rs) { - SetbVariable(&BranchCompare); - } else { - SetaVariable(&BranchCompare); - } - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - uint32_t Const = IsConst(Opcode.rs)?MipsRegLo(Opcode.rs):MipsRegLo(Opcode.rt); - uint32_t MappedReg = IsConst(Opcode.rt)?Opcode.rs:Opcode.rt; - - CompConstToX86reg(MipsRegLo(MappedReg), Const); - if (MappedReg == Opcode.rs) { - SetbVariable(&BranchCompare); - } else { - SetaVariable(&BranchCompare); - } - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } - } - } else if (IsKnown(Opcode.rt) || IsKnown(Opcode.rs)) { - uint32_t KnownReg = IsKnown(Opcode.rt)?Opcode.rt:Opcode.rs; - uint32_t UnknownReg = IsKnown(Opcode.rt)?Opcode.rs:Opcode.rt; - uint8_t *Jump[2]; - - if (IsConst(KnownReg)) { - if (Is64Bit(KnownReg)) { - CompConstToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else { - CompConstToVariable(((int32_t)MipsRegLo(KnownReg) >> 31),&GPR[UnknownReg].W[1]); - } - } else { - if (Is64Bit(KnownReg)) { - CompX86regToVariable(MipsRegHi(KnownReg),&GPR[UnknownReg].W[1]); - } else { - ProtectGPR(Section,KnownReg); - CompX86regToVariable(Map_TempReg(Section,x86_Any,KnownReg,1),&GPR[UnknownReg].W[1]); - } - } - JeLabel8(0); - Jump[0] = RecompPos - 1; - if (KnownReg == (IsConst(KnownReg)?Opcode.rs:Opcode.rt)) { - SetaVariable(&BranchCompare); - } else { - SetbVariable(&BranchCompare); - } - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - if (IsConst(KnownReg)) { - CompConstToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } else { - CompX86regToVariable(MipsRegLo(KnownReg),&GPR[UnknownReg].W[0]); - } - if (KnownReg == (IsConst(KnownReg)?Opcode.rs:Opcode.rt)) { - SetaVariable(&BranchCompare); - } else { - SetbVariable(&BranchCompare); - } - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } else { - uint8_t *Jump[2]; - int32_t x86Reg; - - x86Reg = Map_TempReg(Section,x86_Any,Opcode.rs,1); - CompX86regToVariable(x86Reg,&GPR[Opcode.rt].W[1]); - JeLabel8(0); - Jump[0] = RecompPos - 1; - SetbVariable(&BranchCompare); - JmpLabel8(0); - Jump[1] = RecompPos - 1; - - - - *((uint8_t *)(Jump[0]))=(uint8_t)(RecompPos - Jump[0] - 1); - CompX86regToVariable(Map_TempReg(Section,x86Reg,Opcode.rs,0),&GPR[Opcode.rt].W[0]); - SetbVariable(&BranchCompare); - - - *((uint8_t *)(Jump[1]))=(uint8_t)(RecompPos - Jump[1] - 1); - Map_GPR_32bit(Section,Opcode.rd,1, -1); - MoveVariableToX86reg(&BranchCompare,MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_DADD (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsReg(Opcode.rd) = - Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs) + - Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt); - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - if (IsConst(Opcode.rt)) { - AddConstToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - AddConstToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - int32_t HiReg = Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1); - ProtectGPR(Section,Opcode.rt); - AddX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - AdcX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - } else { - AddVariableToX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - AdcVariableToX86reg(MipsRegHi(Opcode.rd),&GPR[Opcode.rt].W[1]); - } - } -} - -void Compile_R4300i_SPECIAL_DADDU (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - int64_t ValRs = Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs); - int64_t ValRt = Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt); - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsReg(Opcode.rd) = ValRs + ValRt; - if ((MipsRegHi(Opcode.rd) == 0) && (MipsRegLo(Opcode.rd) & 0x80000000) == 0) { - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if ((MipsRegHi(Opcode.rd) == 0xFFFFFFFF) && (MipsRegLo(Opcode.rd) & 0x80000000) != 0) { - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - if (IsConst(Opcode.rt)) { - AddConstToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - AddConstToX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - int32_t HiReg = Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1); - ProtectGPR(Section,Opcode.rt); - AddX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - AdcX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - } else { - AddVariableToX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - AdcVariableToX86reg(MipsRegHi(Opcode.rd),&GPR[Opcode.rt].W[1]); - } - } -} - -void Compile_R4300i_SPECIAL_DSUB (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsReg(Opcode.rd) = - Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs) - - Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt); - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - if (Opcode.rd == Opcode.rt) { - int32_t HiReg = Map_TempReg(Section,x86_Any,Opcode.rt,1); - int32_t LoReg = Map_TempReg(Section,x86_Any,Opcode.rt,0); - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),LoReg); - SbbX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - return; - } - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - if (IsConst(Opcode.rt)) { - SubConstFromX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - SbbConstFromX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - int32_t HiReg = Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1); - ProtectGPR(Section,Opcode.rt); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - SbbX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - } else { - SubVariableFromX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - SbbVariableFromX86reg(MipsRegHi(Opcode.rd),&GPR[Opcode.rt].W[1]); - } - } -} - -void Compile_R4300i_SPECIAL_DSUBU (BLOCK_SECTION * Section) { - - if (Opcode.rd == 0) { return; } - - if (IsConst(Opcode.rt) && IsConst(Opcode.rs)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsReg(Opcode.rd) = - Is64Bit(Opcode.rs)?MipsReg(Opcode.rs):(int64_t)MipsRegLo_S(Opcode.rs) - - Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt); - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - } else { - if (Opcode.rd == Opcode.rt) { - int32_t HiReg = Map_TempReg(Section,x86_Any,Opcode.rt,1); - int32_t LoReg = Map_TempReg(Section,x86_Any,Opcode.rt,0); - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),LoReg); - SbbX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - return; - } - Map_GPR_64bit(Section,Opcode.rd,Opcode.rs); - if (IsConst(Opcode.rt)) { - SubConstFromX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - SbbConstFromX86Reg(MipsRegHi(Opcode.rd),MipsRegHi(Opcode.rt)); - } else if (IsMapped(Opcode.rt)) { - int32_t HiReg = Is64Bit(Opcode.rt)?MipsRegHi(Opcode.rt):Map_TempReg(Section,x86_Any,Opcode.rt,1); - ProtectGPR(Section,Opcode.rt); - SubX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rt)); - SbbX86RegToX86Reg(MipsRegHi(Opcode.rd),HiReg); - } else { - SubVariableFromX86reg(MipsRegLo(Opcode.rd),&GPR[Opcode.rt].W[0]); - SbbVariableFromX86reg(MipsRegHi(Opcode.rd),&GPR[Opcode.rt].W[1]); - } - } -} - -void Compile_R4300i_SPECIAL_DSLL (BLOCK_SECTION * Section) { - - - if (Opcode.rd == 0) { return; } - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - - MipsReg(Opcode.rd) = Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt) << Opcode.sa; - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - return; - } - - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - ShiftLeftDoubleImmed(MipsRegHi(Opcode.rd),MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - ShiftLeftSignImmed( MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); -} - -void Compile_R4300i_SPECIAL_DSRL (BLOCK_SECTION * Section) { - - - if (Opcode.rd == 0) { return; } - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - - MipsReg(Opcode.rd) = Is64Bit(Opcode.rt)?MipsReg(Opcode.rt):(QWORD)MipsRegLo_S(Opcode.rt) >> Opcode.sa; - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - return; - } - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - ShiftRightDoubleImmed(MipsRegLo(Opcode.rd),MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); - ShiftRightUnsignImmed(MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); -} - -void Compile_R4300i_SPECIAL_DSRA (BLOCK_SECTION * Section) { - - - if (Opcode.rd == 0) { return; } - if (IsConst(Opcode.rt)) { - if (IsMapped(Opcode.rd)) { UnMap_GPR(Section,Opcode.rd, 0); } - - MipsReg_S(Opcode.rd) = Is64Bit(Opcode.rt)?MipsReg_S(Opcode.rt):(int64_t)MipsRegLo_S(Opcode.rt) >> Opcode.sa; - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - return; - } - Map_GPR_64bit(Section,Opcode.rd,Opcode.rt); - ShiftRightDoubleImmed(MipsRegLo(Opcode.rd),MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); - ShiftRightSignImmed(MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); -} - -void Compile_R4300i_SPECIAL_DSLL32 (BLOCK_SECTION * Section) { - - - if (Opcode.rd == 0) { return; } - if (IsConst(Opcode.rt)) { - if (Opcode.rt != Opcode.rd) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegHi(Opcode.rd) = MipsRegLo(Opcode.rt) << Opcode.sa; - MipsRegLo(Opcode.rd) = 0; - if (MipsRegLo_S(Opcode.rd) < 0 && MipsRegHi_S(Opcode.rd) == -1){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else if (MipsRegLo_S(Opcode.rd) >= 0 && MipsRegHi_S(Opcode.rd) == 0){ - MipsRegState(Opcode.rd) = STATE_CONST_32; - } else { - MipsRegState(Opcode.rd) = STATE_CONST_64; - } - - } else if (IsMapped(Opcode.rt)) { - ProtectGPR(Section,Opcode.rt); - Map_GPR_64bit(Section,Opcode.rd,-1); - if (Opcode.rt != Opcode.rd) { - MoveX86RegToX86Reg(MipsRegLo(Opcode.rt),MipsRegHi(Opcode.rd)); - } else { - int32_t HiReg = MipsRegHi(Opcode.rt); - MipsRegHi(Opcode.rt) = MipsRegLo(Opcode.rt); - MipsRegLo(Opcode.rt) = HiReg; - } - if ((uint8_t)Opcode.sa != 0) { - ShiftLeftSignImmed(MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); - } - XorX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rd)); - } else { - Map_GPR_64bit(Section,Opcode.rd,-1); - MoveVariableToX86reg(&GPR[Opcode.rt],MipsRegHi(Opcode.rd)); - if ((uint8_t)Opcode.sa != 0) { - ShiftLeftSignImmed(MipsRegHi(Opcode.rd),(uint8_t)Opcode.sa); - } - XorX86RegToX86Reg(MipsRegLo(Opcode.rd),MipsRegLo(Opcode.rd)); - } -} - -void Compile_R4300i_SPECIAL_DSRL32 (BLOCK_SECTION * Section) { - - if (IsConst(Opcode.rt)) { - if (Opcode.rt != Opcode.rd) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegState(Opcode.rd) = STATE_CONST_32; - MipsRegLo(Opcode.rd) = (uint32_t)(MipsReg(Opcode.rt) >> (Opcode.sa + 32)); - } else if (IsMapped(Opcode.rt)) { - ProtectGPR(Section,Opcode.rt); - if (Is64Bit(Opcode.rt)) { - if (Opcode.rt == Opcode.rd) { - int32_t HiReg = MipsRegHi(Opcode.rt); - MipsRegHi(Opcode.rt) = MipsRegLo(Opcode.rt); - MipsRegLo(Opcode.rt) = HiReg; - Map_GPR_32bit(Section,Opcode.rd,0,-1); - } else { - Map_GPR_32bit(Section,Opcode.rd,0,-1); - MoveX86RegToX86Reg(MipsRegHi(Opcode.rt),MipsRegLo(Opcode.rd)); - } - if ((uint8_t)Opcode.sa != 0) { - ShiftRightUnsignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } - } else { - Compile_R4300i_UnknownOpcode(Section); - } - } else { - Map_GPR_32bit(Section,Opcode.rd,0,-1); - MoveVariableToX86reg(&GPR[Opcode.rt].UW[1],MipsRegLo(Opcode.rd)); - if ((uint8_t)Opcode.sa != 0) { - ShiftRightUnsignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } - } -} - -void Compile_R4300i_SPECIAL_DSRA32 (BLOCK_SECTION * Section) { - - if (IsConst(Opcode.rt)) { - if (Opcode.rt != Opcode.rd) { UnMap_GPR(Section,Opcode.rd, 0); } - MipsRegState(Opcode.rd) = STATE_CONST_32; - MipsRegLo(Opcode.rd) = (uint32_t)(MipsReg_S(Opcode.rt) >> (Opcode.sa + 32)); - } else if (IsMapped(Opcode.rt)) { - ProtectGPR(Section,Opcode.rt); - if (Is64Bit(Opcode.rt)) { - if (Opcode.rt == Opcode.rd) { - int32_t HiReg = MipsRegHi(Opcode.rt); - MipsRegHi(Opcode.rt) = MipsRegLo(Opcode.rt); - MipsRegLo(Opcode.rt) = HiReg; - Map_GPR_32bit(Section,Opcode.rd,1,-1); - } else { - Map_GPR_32bit(Section,Opcode.rd,1,-1); - MoveX86RegToX86Reg(MipsRegHi(Opcode.rt),MipsRegLo(Opcode.rd)); - } - if ((uint8_t)Opcode.sa != 0) { - ShiftRightSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } - } else { - Compile_R4300i_UnknownOpcode(Section); - } - } else { - Map_GPR_32bit(Section,Opcode.rd,1,-1); - MoveVariableToX86reg(&GPR[Opcode.rt].UW[1],MipsRegLo(Opcode.rd)); - if ((uint8_t)Opcode.sa != 0) { - ShiftRightSignImmed(MipsRegLo(Opcode.rd),(uint8_t)Opcode.sa); - } - } -} - -/************************** COP0 functions **************************/ -void Compile_R4300i_COP0_MF(BLOCK_SECTION * Section) { - - - switch (Opcode.rd) { - case 9: //Count - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - BlockCycleCount = 0; - } - Map_GPR_32bit(Section,Opcode.rt,1,-1); - MoveVariableToX86reg(&CP0[Opcode.rd],MipsRegLo(Opcode.rt)); -} - -void Compile_R4300i_COP0_MT (BLOCK_SECTION * Section) { - int32_t OldStatusReg; - uint8_t *Jump; - - - - switch (Opcode.rd) { - case 0: //Index - case 2: //EntryLo0 - case 3: //EntryLo1 - case 4: //Context - case 5: //PageMask - case 9: //Count - case 10: //Entry Hi - case 11: //Compare - case 14: //EPC - case 16: //Config - case 18: //WatchLo - case 19: //WatchHi - case 28: //Tag lo - case 29: //Tag Hi - case 30: //ErrEPC - if (IsConst(Opcode.rt)) { - MoveConstToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rt,0), &CP0[Opcode.rd]); - } - switch (Opcode.rd) { - case 4: //Context - AndConstToVariable(0xFF800000,&CP0[Opcode.rd]); - break; - case 9: //Count - BlockCycleCount = 0; - Pushad(); - Call_Direct(ChangeCompareTimer); - Popad(); - break; - case 11: //Compare - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockCycleCount,&Timers->Timer); - BlockCycleCount = 0; - AndConstToVariable(~CAUSE_IP7,&FAKE_CAUSE_REGISTER); - Pushad(); - Call_Direct(ChangeCompareTimer); - Popad(); - } - break; - case 12: //Status - OldStatusReg = Map_TempReg(Section,x86_Any,-1,0); - MoveVariableToX86reg(&CP0[Opcode.rd],OldStatusReg); - if (IsConst(Opcode.rt)) { - MoveConstToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rt,0), &CP0[Opcode.rd]); - } - XorVariableToX86reg(&CP0[Opcode.rd],OldStatusReg); - TestConstToX86Reg(STATUS_FR,OldStatusReg); - JeLabel8(0); - Jump = RecompPos - 1; - Pushad(); - Call_Direct(SetFpuLocations); - Popad(); - *(uint8_t *)(Jump)= (uint8_t )(((uint8_t )(RecompPos)) - (((uint8_t )(Jump)) + 1)); - - //TestConstToX86Reg(STATUS_FR,OldStatusReg); - //CompileExit(Section->CompilePC+4,Section->RegWorking,ExitResetRecompCode,0,JneLabel32); - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - case 6: //Wired - Pushad(); - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - BlockRandomModifier = 0; - Call_Direct(FixRandomReg); - Popad(); - if (IsConst(Opcode.rt)) { - MoveConstToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else if (IsMapped(Opcode.rt)) { - MoveX86regToVariable(MipsRegLo(Opcode.rt), &CP0[Opcode.rd]); - } else { - MoveX86regToVariable(Map_TempReg(Section,x86_Any,Opcode.rt,0), &CP0[Opcode.rd]); - } - break; - case 13: //cause - if (IsConst(Opcode.rt)) { - AndConstToVariable(0xFFFFCFF,&CP0[Opcode.rd]); -#ifndef EXTERNAL_RELEASE - if ((MipsRegLo(Opcode.rt) & 0x300) != 0 ){ DisplayError("Set IP0 or IP1"); } -#endif - } else { - Compile_R4300i_UnknownOpcode(Section); - } - Pushad(); - Call_Direct(CheckInterrupts); - Popad(); - break; - default: - Compile_R4300i_UnknownOpcode(Section); - } -} - -/************************** COP0 CO functions ***********************/ -void Compile_R4300i_COP0_CO_TLBR( BLOCK_SECTION * Section) { - Pushad(); - Call_Direct(TLB_Read); - Popad(); -} - -void Compile_R4300i_COP0_CO_TLBWI( BLOCK_SECTION * Section) { - Pushad(); - MoveVariableToX86reg(&INDEX_REGISTER,x86_EDI); - AndConstToX86Reg(x86_EDI,0x1F); -#ifdef USEX64 - Call_Direct(WriteTLBEntry); -#else - Push(x86_ECX); - Call_Direct(WriteTLBEntry); - AddConstToX86Reg(x86_ESP, 0x4); -#endif - Popad(); -} - -void Compile_R4300i_COP0_CO_TLBWR( BLOCK_SECTION * Section) { - if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&CP0[1]); } - BlockRandomModifier = 0; - Pushad(); - //Call_Direct(FixRandomReg); - MoveVariableToX86reg(&RANDOM_REGISTER,x86_EDI); - AndConstToX86Reg(x86_EDI,0x1F); - //BreakPoint(); - //Push(x86_ECX); -#ifdef USEX64 - Call_Direct(WriteTLBEntry); -#else - Push(x86_ECX); - Call_Direct(WriteTLBEntry); - AddConstToX86Reg(x86_ESP, 0x4); -#endif - - //AddConstToX86Reg(x86_ESP,4); - Popad(); -} - - - -void Compile_R4300i_COP0_CO_TLBP( BLOCK_SECTION * Section) { - Pushad(); - Call_Direct(TLB_Probe); - Popad(); -} - -void compiler_COP0_CO_ERET (void) { - if ((STATUS_REGISTER & STATUS_ERL) != 0) { - PROGRAM_COUNTER = ERROREPC_REGISTER; - STATUS_REGISTER &= ~STATUS_ERL; - } else { - PROGRAM_COUNTER = EPC_REGISTER; - STATUS_REGISTER &= ~STATUS_EXL; - } - LLBit = 0; - CheckInterrupts(); -} - -void Compile_R4300i_COP0_CO_ERET( BLOCK_SECTION * Section) { - WriteBackRegisters(Section); - Pushad(); - Call_Direct(compiler_COP0_CO_ERET); - Popad(); - CompileExit((uint32_t)-1,&Section->RegWorking,Normal,1,NULL); - NextInstruction = END_BLOCK; -} - -/************************** Other functions **************************/ -void Compile_R4300i_UnknownOpcode (BLOCK_SECTION * Section) { - -// Int3(); - FreeSection(Section->ContinueSection,Section); - FreeSection(Section->JumpSection,Section); - BlockCycleCount -= 2; - BlockRandomModifier -= 1; - MoveConstToVariable(Section->CompilePC,&PROGRAM_COUNTER); - WriteBackRegisters(Section); - AddConstToVariable(BlockCycleCount,&CP0[9]); - SubConstFromVariable(BlockRandomModifier,&CP0[1]); - MoveConstToVariable(Opcode.Hex,&Opcode.Hex); - Pushad(); - Call_Direct(R4300i_UnknownOpcode); - Popad(); - Ret(); - if (NextInstruction == NORMAL) { NextInstruction = END_BLOCK; } -} - diff --git a/src/usf/recompiler_ops.h b/src/usf/recompiler_ops.h deleted file mode 100644 index b1e5809..0000000 --- a/src/usf/recompiler_ops.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -void CompileReadTLBMiss (BLOCK_SECTION * Section, int32_t AddressReg, int32_t LookUpReg ); - -/************************** Branch functions ************************/ -void Compile_R4300i_Branch ( BLOCK_SECTION * Section, void (*CompareFunc)(BLOCK_SECTION * Section), int32_t BranchType, uint32_t Link); -void Compile_R4300i_BranchLikely ( BLOCK_SECTION * Section, void (*CompareFunc)(BLOCK_SECTION * Section), uint32_t Link); -void BNE_Compare ( BLOCK_SECTION * Section ); -void BEQ_Compare ( BLOCK_SECTION * Section ); -void BGTZ_Compare ( BLOCK_SECTION * Section ); -void BLEZ_Compare ( BLOCK_SECTION * Section ); -void BLTZ_Compare ( BLOCK_SECTION * Section ); -void BGEZ_Compare ( BLOCK_SECTION * Section ); -void COP1_BCF_Compare ( BLOCK_SECTION * Section ); -void COP1_BCT_Compare ( BLOCK_SECTION * Section ); - -/************************* OpCode functions *************************/ -void Compile_R4300i_J ( BLOCK_SECTION * Section ); -void Compile_R4300i_JAL ( BLOCK_SECTION * Section ); -void Compile_R4300i_ADDI ( BLOCK_SECTION * Section ); -void Compile_R4300i_ADDIU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SLTI ( BLOCK_SECTION * Section ); -void Compile_R4300i_SLTIU ( BLOCK_SECTION * Section ); -void Compile_R4300i_ANDI ( BLOCK_SECTION * Section ); -void Compile_R4300i_ORI ( BLOCK_SECTION * Section ); -void Compile_R4300i_XORI ( BLOCK_SECTION * Section ); -void Compile_R4300i_LUI ( BLOCK_SECTION * Section ); -void Compile_R4300i_DADDIU ( BLOCK_SECTION * Section ); -void Compile_R4300i_LDL ( BLOCK_SECTION * Section ); -void Compile_R4300i_LDR ( BLOCK_SECTION * Section ); -void Compile_R4300i_LB ( BLOCK_SECTION * Section ); -void Compile_R4300i_LH ( BLOCK_SECTION * Section ); -void Compile_R4300i_LWL ( BLOCK_SECTION * Section ); -void Compile_R4300i_LW ( BLOCK_SECTION * Section ); -void Compile_R4300i_LBU ( BLOCK_SECTION * Section ); -void Compile_R4300i_LHU ( BLOCK_SECTION * Section ); -void Compile_R4300i_LWR ( BLOCK_SECTION * Section ); -void Compile_R4300i_LWU ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_SB ( BLOCK_SECTION * Section ); -void Compile_R4300i_SH ( BLOCK_SECTION * Section ); -void Compile_R4300i_SWL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SW ( BLOCK_SECTION * Section ); -void Compile_R4300i_SWR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SDL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SDR ( BLOCK_SECTION * Section ); -void Compile_R4300i_CACHE ( BLOCK_SECTION * Section ); -void Compile_R4300i_LL ( BLOCK_SECTION * Section ); -void Compile_R4300i_LWC1 ( BLOCK_SECTION * Section ); -void Compile_R4300i_LDC1 ( BLOCK_SECTION * Section ); -void Compile_R4300i_LD ( BLOCK_SECTION * Section ); -void Compile_R4300i_SC ( BLOCK_SECTION * Section ); -void Compile_R4300i_SWC1 ( BLOCK_SECTION * Section ); -void Compile_R4300i_SDC1 ( BLOCK_SECTION * Section ); -void Compile_R4300i_SD ( BLOCK_SECTION * Section ); - -/********************** R4300i OpCodes: Special **********************/ -void Compile_R4300i_SPECIAL_SLL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SRL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SRA ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SLLV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SRLV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SRAV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_JR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_JALR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SYSCALL( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MFLO ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MTLO ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MFHI ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MTHI ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSLLV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRLV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRAV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MULT ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_MULTU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DIV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DIVU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DMULT ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DMULTU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DDIV ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DDIVU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_ADD ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_ADDU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SUB ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SUBU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_AND ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_OR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_XOR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_NOR ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SLT ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_SLTU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DADD ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DADDU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSUB ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSUBU ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSLL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRL ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRA ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSLL32 ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRL32 ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_DSRA32 ( BLOCK_SECTION * Section ); -void Compile_R4300i_SPECIAL_BREAK ( BLOCK_SECTION * Section ); - -/************************** COP0 functions **************************/ -void Compile_R4300i_COP0_MF ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP0_MT ( BLOCK_SECTION * Section ); - -/************************** COP0 CO functions ***********************/ -void Compile_R4300i_COP0_CO_TLBR ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP0_CO_TLBWI ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP0_CO_TLBWR ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP0_CO_TLBP ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP0_CO_ERET ( BLOCK_SECTION * Section ); - -/************************** COP1 functions **************************/ -void Compile_R4300i_COP1_MF ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_DMF ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_CF ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_MT ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_DMT ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_CT ( BLOCK_SECTION * Section ); - -/************************** COP1: S functions ************************/ -void Compile_R4300i_COP1_S_ADD ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_SUB ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_MUL ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_DIV ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_ABS ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_NEG ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_SQRT ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_MOV ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_TRUNC_L ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CEIL_L ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_S_FLOOR_L ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_S_ROUND_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_TRUNC_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CEIL_W ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_S_FLOOR_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CVT_D ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CVT_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CVT_L ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_S_CMP ( BLOCK_SECTION * Section ); - -/************************** COP1: D functions ************************/ -void Compile_R4300i_COP1_D_ADD ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_SUB ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_MUL ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_DIV ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_ABS ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_NEG ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_SQRT ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_MOV ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_TRUNC_L ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_D_CEIL_L ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_D_FLOOR_L ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_D_ROUND_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_TRUNC_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_CEIL_W ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_D_FLOOR_W ( BLOCK_SECTION * Section ); //added by Witten -void Compile_R4300i_COP1_D_CVT_S ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_CVT_W ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_CVT_L ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_D_CMP ( BLOCK_SECTION * Section ); - -/************************** COP1: W functions ************************/ -void Compile_R4300i_COP1_W_CVT_S ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_W_CVT_D ( BLOCK_SECTION * Section ); - -/************************** COP1: L functions ************************/ -void Compile_R4300i_COP1_L_CVT_S ( BLOCK_SECTION * Section ); -void Compile_R4300i_COP1_L_CVT_D ( BLOCK_SECTION * Section ); - -/************************** Other functions **************************/ -void Compile_R4300i_UnknownOpcode ( BLOCK_SECTION * Section ); diff --git a/src/usf/registers.c b/src/usf/registers.c deleted file mode 100644 index 8971d1a..0000000 --- a/src/usf/registers.c +++ /dev/null @@ -1,1054 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ - -// #ifdef EXT_REGS - -#include "main.h" -#include "cpu.h" -#include "x86.h" -#include "types.h" - -uint32_t PROGRAM_COUNTER, * CP0,*FPCR,*RegRDRAM,*RegSP,*RegDPC,*RegMI,*RegVI,*RegAI,*RegPI, - *RegRI,*RegSI, HalfLine, RegModValue, ViFieldNumber, LLBit, LLAddr; -void * FPRDoubleLocation[32], * FPRFloatLocation[32]; -MIPS_DWORD *GPR, *FPR, HI, LO; -int32_t fpuControl; -N64_REGISTERS * Registers = 0; - -void SetupRegisters(N64_REGISTERS * n64_Registers) { - PROGRAM_COUNTER = n64_Registers->PROGRAM_COUNTER; - HI.DW = n64_Registers->HI.DW; - LO.DW = n64_Registers->LO.DW; - CP0 = n64_Registers->CP0; - GPR = n64_Registers->GPR; - FPR = n64_Registers->FPR; - FPCR = n64_Registers->FPCR; - RegRDRAM = n64_Registers->RDRAM; - RegSP = n64_Registers->SP; - RegDPC = n64_Registers->DPC; - RegMI = n64_Registers->MI; - RegVI = n64_Registers->VI; - RegAI = n64_Registers->AI; - RegPI = n64_Registers->PI; - RegRI = n64_Registers->RI; - RegSI = n64_Registers->SI; - PIF_Ram = n64_Registers->PIF_Ram; -} - -int fUnMap_8BitTempReg (BLOCK_SECTION * Section); -int UnMap_TempReg (BLOCK_SECTION * Section); -uint32_t UnMap_X86reg (BLOCK_SECTION * Section, uint32_t x86Reg); - -void ChangeFPURegFormat (BLOCK_SECTION * Section, int32_t Reg, int32_t OldFormat, int32_t NewFormat, int32_t RoundingModel) { - int32_t i; - - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)Reg) { - if (FpuState(i) != (uint32_t)OldFormat) { - UnMap_FPR(Section,Reg,1); - Load_FPR_ToTop(Section,Reg,Reg,OldFormat); - ChangeFPURegFormat(Section,Reg,OldFormat,NewFormat,RoundingModel); - return; - } - FpuRoundingModel(i) = RoundingModel; - FpuState(i) = NewFormat; - return; - } - } - -} - -void ChangeMiIntrMask (void) { - if ( ( RegModValue & MI_INTR_MASK_CLR_SP ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_SP; } - if ( ( RegModValue & MI_INTR_MASK_SET_SP ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_SP; } - if ( ( RegModValue & MI_INTR_MASK_CLR_SI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_SI; } - if ( ( RegModValue & MI_INTR_MASK_SET_SI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_SI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_AI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_AI; } - if ( ( RegModValue & MI_INTR_MASK_SET_AI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_AI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_VI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_VI; } - if ( ( RegModValue & MI_INTR_MASK_SET_VI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_VI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_PI ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_PI; } - if ( ( RegModValue & MI_INTR_MASK_SET_PI ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_PI; } - if ( ( RegModValue & MI_INTR_MASK_CLR_DP ) != 0 ) { MI_INTR_MASK_REG &= ~MI_INTR_MASK_DP; } - if ( ( RegModValue & MI_INTR_MASK_SET_DP ) != 0 ) { MI_INTR_MASK_REG |= MI_INTR_MASK_DP; } -} - -void ChangeMiModeReg (void) { - MI_MODE_REG &= ~0x7F; - MI_MODE_REG |= (RegModValue & 0x7F); - if ( ( RegModValue & MI_CLR_INIT ) != 0 ) { MI_MODE_REG &= ~MI_MODE_INIT; } - if ( ( RegModValue & MI_SET_INIT ) != 0 ) { MI_MODE_REG |= MI_MODE_INIT; } - if ( ( RegModValue & MI_CLR_EBUS ) != 0 ) { MI_MODE_REG &= ~MI_MODE_EBUS; } - if ( ( RegModValue & MI_SET_EBUS ) != 0 ) { MI_MODE_REG |= MI_MODE_EBUS; } - if ( ( RegModValue & MI_CLR_DP_INTR ) != 0 ) { MI_INTR_REG &= ~MI_INTR_DP; } - if ( ( RegModValue & MI_CLR_RDRAM ) != 0 ) { MI_MODE_REG &= ~MI_MODE_RDRAM; } - if ( ( RegModValue & MI_SET_RDRAM ) != 0 ) { MI_MODE_REG |= MI_MODE_RDRAM; } -} - -void ChangeSpStatus (void) { - if ( ( RegModValue & SP_CLR_HALT ) != 0) { SP_STATUS_REG &= ~SP_STATUS_HALT; } - if ( ( RegModValue & SP_SET_HALT ) != 0) { SP_STATUS_REG |= SP_STATUS_HALT; } - if ( ( RegModValue & SP_CLR_BROKE ) != 0) { SP_STATUS_REG &= ~SP_STATUS_BROKE; } - if ( ( RegModValue & SP_CLR_INTR ) != 0) { - MI_INTR_REG &= ~MI_INTR_SP; - CheckInterrupts(); - } - - if ( ( RegModValue & SP_CLR_SSTEP ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SSTEP; } - if ( ( RegModValue & SP_SET_SSTEP ) != 0) { SP_STATUS_REG |= SP_STATUS_SSTEP; } - if ( ( RegModValue & SP_CLR_INTR_BREAK ) != 0) { SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } - if ( ( RegModValue & SP_SET_INTR_BREAK ) != 0) { SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } - if ( ( RegModValue & SP_CLR_SIG0 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG0; } - if ( ( RegModValue & SP_SET_SIG0 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG0; } - if ( ( RegModValue & SP_CLR_SIG1 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG1; } - if ( ( RegModValue & SP_SET_SIG1 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG1; } - if ( ( RegModValue & SP_CLR_SIG2 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG2; } - if ( ( RegModValue & SP_SET_SIG2 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG2; } - if ( ( RegModValue & SP_CLR_SIG3 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG3; } - if ( ( RegModValue & SP_SET_SIG3 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG3; } - if ( ( RegModValue & SP_CLR_SIG4 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG4; } - if ( ( RegModValue & SP_SET_SIG4 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG4; } - if ( ( RegModValue & SP_CLR_SIG5 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG5; } - if ( ( RegModValue & SP_SET_SIG5 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG5; } - if ( ( RegModValue & SP_CLR_SIG6 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG6; } - if ( ( RegModValue & SP_SET_SIG6 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG6; } - if ( ( RegModValue & SP_CLR_SIG7 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG7; } - if ( ( RegModValue & SP_SET_SIG7 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG7; } - - RunRsp(); - -} - -int32_t Free8BitX86Reg (BLOCK_SECTION * Section) { - int32_t x86Reg, count, MapCount[64], MapReg[64]; - - //if (x86Mapped(x86_EBX) == NotMapped && !x86Protected(x86_EBX)) {return x86_EBX; } - //if (x86Mapped(x86_EAX) == NotMapped && !x86Protected(x86_EAX)) {return x86_EAX; } - //if (x86Mapped(x86_EDX) == NotMapped && !x86Protected(x86_EDX)) {return x86_EDX; } - //if (x86Mapped(x86_ECX) == NotMapped && !x86Protected(x86_ECX)) {return x86_ECX; } - if (x86Mapped(x86_EBX&0x2f) == NotMapped && !x86Protected(x86_EBX&0x2f)) {return x86_EBX; } - if (x86Mapped(x86_EDX&0x2f) == NotMapped && !x86Protected(x86_EDX&0x2f)) {return x86_EDX; } - if (x86Mapped(x86_ECX&0x2f) == NotMapped && !x86Protected(x86_ECX&0x2f)) {return x86_ECX; } - if (x86Mapped(x86_EAX&0x2f) == NotMapped && !x86Protected(x86_EAX&0x2f)) {return x86_EAX; } -#ifdef EXT_REGS - if (x86Mapped(x86_R9D&0x2f) == NotMapped && !x86Protected(x86_R9D&0x2f)) {return x86_R9D; } - if (x86Mapped(x86_R10D&0x2f) == NotMapped && !x86Protected(x86_R10D&0x2f)) {return x86_R10D; } - if (x86Mapped(x86_R11D&0x2f) == NotMapped && !x86Protected(x86_R11D&0x2f)) {return x86_R11D; } - if (x86Mapped(x86_R14D&0x2f) == NotMapped && !x86Protected(x86_R14D&0x2f)) {return x86_R14D; } -#endif - - x86Reg = UnMap_8BitTempReg(Section); - if (x86Reg >= 0) { return x86Reg; } - - for (count = 0; count < 64; count ++) { - MapCount[count] = x86MapOrder(count); - MapReg[count] = count; - } - for (count = 0; count < 64; count ++) { - int i; - - for (i = 0; i < 63; i ++) { - int temp; - - if (MapCount[i] < MapCount[i+1]) { - temp = MapCount[i]; - MapCount[i] = MapCount[i+1]; - MapCount[i+1] = temp; - temp = MapReg[i]; - MapReg[i] = MapReg[i+1]; - MapReg[i+1] = temp; - } - } - - } - for (count = 0; count < 64; count ++) { - if (MapCount[count] > 0) { - if (!Is8BitReg(count)) { continue; } - if (UnMap_X86reg(Section,count)) { - return count; - } - } - } - - return -1; -} - - -int32_t FreeX86Reg (BLOCK_SECTION * Section) { - int32_t x86Reg, count, MapCount[64], MapReg[64], StackReg; - - if (x86Mapped(x86_ESI&0x2f) == NotMapped && !x86Protected(x86_ESI&0x2f)) {return x86_ESI; } - if (x86Mapped(x86_EDI&0x2f) == NotMapped && !x86Protected(x86_EDI&0x2f)) {return x86_EDI; } - if (x86Mapped(x86_EBX&0x2f) == NotMapped && !x86Protected(x86_EBX&0x2f)) {return x86_EBX; } - if (x86Mapped(x86_EDX&0x2f) == NotMapped && !x86Protected(x86_EDX&0x2f)) {return x86_EDX; } - if (x86Mapped(x86_ECX&0x2f) == NotMapped && !x86Protected(x86_ECX&0x2f)) {return x86_ECX; } - if (x86Mapped(x86_EAX&0x2f) == NotMapped && !x86Protected(x86_EAX&0x2f)) {return x86_EAX; } -#ifdef EXT_REGS - if (x86Mapped(x86_R9D&0x2f) == NotMapped && !x86Protected(x86_R9D&0x2f)) {return x86_R9D; } - if (x86Mapped(x86_R10D&0x2f) == NotMapped && !x86Protected(x86_R10D&0x2f)) {return x86_R10D; } - if (x86Mapped(x86_R11D&0x2f) == NotMapped && !x86Protected(x86_R11D&0x2f)) {return x86_R11D; } - if (x86Mapped(x86_R12D&0x2f) == NotMapped && !x86Protected(x86_R12D&0x2f)) {return x86_R12D; } - if (x86Mapped(x86_R13D&0x2f) == NotMapped && !x86Protected(x86_R13D&0x2f)) {return x86_R13D; } - if (x86Mapped(x86_R14D&0x2f) == NotMapped && !x86Protected(x86_R14D&0x2f)) {return x86_R14D; } -#endif - - x86Reg = UnMap_TempReg(Section); - if (x86Reg > 0) { return x86Reg; } - - for (count = 0; count < 64; count ++) { - MapCount[count] = x86MapOrder(count); - MapReg[count] = count; - } - for (count = 0; count < 64; count ++) { - int i; - - for (i = 0; i < 63; i ++) { - int temp; - - if (MapCount[i] < MapCount[i+1]) { - temp = MapCount[i]; - MapCount[i] = MapCount[i+1]; - MapCount[i+1] = temp; - temp = MapReg[i]; - MapReg[i] = MapReg[i+1]; - MapReg[i+1] = temp; - } - } - - } - StackReg = -1; - for (count = 0; count < 64; count ++) { - if (MapCount[count] > 0 && x86Mapped(MapReg[count]) != Stack_Mapped) { - if (UnMap_X86reg(Section,MapReg[count])) { - return MapReg[count]; - } - } - if (x86Mapped(MapReg[count]) == Stack_Mapped) { StackReg = MapReg[count]; } - } - if (StackReg >= 0) { - UnMap_X86reg(Section,StackReg); - return StackReg; - } - return -1; -} - - -uint32_t Is8BitReg (int32_t x86Reg) { - if (x86Reg == x86_EAX) { return 1; } - if (x86Reg == x86_EBX) { return 1; } - if (x86Reg == x86_ECX) { return 1; } - if (x86Reg == x86_EDX) { return 1; } -#ifdef EXT_REGS - if (x86Reg == x86_R9D) { return 1; } - if (x86Reg == x86_R10D) { return 1; } - if (x86Reg == x86_R11D) { return 1; } - if (x86Reg == x86_R14D) { return 1; } -#endif - return 0; -} - -void Load_FPR_ToTop (BLOCK_SECTION * Section, int32_t Reg, int32_t RegToLoad, int32_t Format) { - int32_t i; - - if (RegToLoad < 0) { return; } - if (Reg < 0) { return; } - - if (Format == FPU_Double || Format == FPU_Qword) { - UnMap_FPR(Section,Reg + 1,1); - UnMap_FPR(Section,RegToLoad + 1,1); - } else { - if ((Reg & 1) != 0) { - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)(Reg - 1)) { - if (FpuState(i) == FPU_Double || FpuState(i) == FPU_Qword) { - UnMap_FPR(Section,Reg,1); - } - i = 8; - } - } - } - if ((RegToLoad & 1) != 0) { - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)(RegToLoad - 1)) { - if (FpuState(i) == FPU_Double || FpuState(i) == FPU_Qword) { - UnMap_FPR(Section,RegToLoad,1); - } - i = 8; - } - } - } - } - - if (Reg == RegToLoad) { - //if different format then unmap original reg from stack - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)Reg) { - if (FpuState(i) != (uint32_t)Format) { - UnMap_FPR(Section,Reg,1); - } - i = 8; - } - } - } else { - UnMap_FPR(Section,Reg,0); - } - - if (RegInStack(Section,RegToLoad,Format)) { - if (Reg != RegToLoad) { - if (FpuMappedTo((StackTopPos - 1) & 7) != (uint32_t)RegToLoad) { - UnMap_FPR(Section,FpuMappedTo((StackTopPos - 1) & 7),1); - fpuLoadReg(&StackTopPos,StackPosition(Section,RegToLoad)); - FpuRoundingModel(StackTopPos) = RoundDefault; - FpuMappedTo(StackTopPos) = Reg; - FpuState(StackTopPos) = Format; - } else { - UnMap_FPR(Section,FpuMappedTo((StackTopPos - 1) & 7),1); - Load_FPR_ToTop (Section,Reg, RegToLoad, Format); - } - } else { - uint32_t RegPos, StackPos, i; - - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)Reg) { - RegPos = i; - i = 8; - } - } - - if (RegPos == StackTopPos) { - return; - } - StackPos = StackPosition(Section,Reg); - - FpuRoundingModel(RegPos) = FpuRoundingModel(StackTopPos); - FpuMappedTo(RegPos) = FpuMappedTo(StackTopPos); - FpuState(RegPos) = FpuState(StackTopPos); - - fpuExchange(StackPos); - - FpuRoundingModel(StackTopPos) = RoundDefault; - FpuMappedTo(StackTopPos) = Reg; - FpuState(StackTopPos) = Format; - } - } else { - int TempReg; - - UnMap_FPR(Section,FpuMappedTo((StackTopPos - 1) & 7),1); - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)RegToLoad) { - UnMap_FPR(Section,RegToLoad,1); - i = 8; - } - } - TempReg = Map_TempReg(Section,x86_Any,-1,0); - switch (Format) { - case FPU_Dword: - MovePointerToX86reg(&FPRFloatLocation[RegToLoad],TempReg); - MovePointerToX86reg(&FPRFloatLocation[RegToLoad],TempReg); - - fpuLoadIntegerDwordFromX86Reg(&StackTopPos,TempReg); - break; - case FPU_Qword: - MovePointerToX86reg(&FPRDoubleLocation[RegToLoad],TempReg); - fpuLoadIntegerQwordFromX86Reg(&StackTopPos,TempReg); - break; - case FPU_Float: - MovePointerToX86reg(&FPRFloatLocation[RegToLoad],TempReg); - fpuLoadDwordFromX86Reg(&StackTopPos,TempReg); - break; - case FPU_Double: - MovePointerToX86reg(&FPRDoubleLocation[RegToLoad],TempReg); - fpuLoadQwordFromX86Reg(&StackTopPos,TempReg); - break; - } - x86Protected(TempReg) = 0; - FpuRoundingModel(StackTopPos) = RoundDefault; - FpuMappedTo(StackTopPos) = Reg; - FpuState(StackTopPos) = Format; - } - - //CurrentRoundingModel,FpuRoundingModel(StackTopPos)); -} - -void Map_GPR_32bit (BLOCK_SECTION * Section, int32_t Reg, uint32_t SignValue, int32_t MipsRegToLoad) { - int x86Reg,count; - - if (Reg == 0) { - return; - } - - if (IsUnknown(Reg) || IsConst(Reg)) { - x86Reg = FreeX86Reg(Section); - if (x86Reg < 0) { - printf("out of registers\n"); - return; - } - } else { - if (Is64Bit(Reg)) { - x86MapOrder(MipsRegHi(Reg)) = 0; - x86Mapped(MipsRegHi(Reg)) = NotMapped; - x86Protected(MipsRegHi(Reg)) = 0; - MipsRegHi(Reg) = 0; - } - x86Reg = MipsRegLo(Reg); - } - for (count = 0; count < 64; count ++) { - if (x86MapOrder(count) > 0) { - x86MapOrder(count) += 1; - } - } - x86MapOrder(x86Reg) = 1; - - if (MipsRegToLoad > 0) { - if (IsUnknown(MipsRegToLoad)) { - MoveVariableToX86reg(&GPR[MipsRegToLoad].UW[0],x86Reg); - } else if (IsMapped(MipsRegToLoad)) { - if (Reg != MipsRegToLoad) { - MoveX86RegToX86Reg(MipsRegLo(MipsRegToLoad),x86Reg); - } - } else { - if (MipsRegLo(MipsRegToLoad) != 0) { - MoveConstToX86reg(MipsRegLo(MipsRegToLoad),x86Reg); - } else { - XorX86RegToX86Reg(x86Reg,x86Reg); - } - } - } else if (MipsRegToLoad == 0) { - XorX86RegToX86Reg(x86Reg,x86Reg); - } - x86Mapped(x86Reg) = GPR_Mapped; - x86Protected(x86Reg) = 1; - MipsRegLo(Reg) = x86Reg; - MipsRegState(Reg) = SignValue ? STATE_MAPPED_32_SIGN : STATE_MAPPED_32_ZERO; -} - -void Map_GPR_64bit (BLOCK_SECTION * Section, int32_t Reg, int32_t MipsRegToLoad) { - int x86Hi, x86lo, count; - - if (Reg == 0) { - - return; - } - - ProtectGPR(Section,Reg); - if (IsUnknown(Reg) || IsConst(Reg)) { - x86Hi = FreeX86Reg(Section); - if (x86Hi < 0) { printf("out of registers\n"); return; } - x86Protected(x86Hi) = 1; - - x86lo = FreeX86Reg(Section); - if (x86lo < 0) { printf("out of registers\n"); return; } - x86Protected(x86lo) = 1; - - } else { - x86lo = MipsRegLo(Reg); - if (Is32Bit(Reg)) { - x86Protected(x86lo) = 1; - x86Hi = FreeX86Reg(Section); - if (x86Hi < 0) { printf("out of registers\n"); return; } - x86Protected(x86Hi) = 1; - } else { - x86Hi = MipsRegHi(Reg); - } - } - - for (count = 0; count < 64; count ++) { - if (x86MapOrder(count) > 0) { x86MapOrder(count) += 1; } - } - - x86MapOrder(x86Hi) = 1; - x86MapOrder(x86lo) = 1; - if (MipsRegToLoad > 0) { - if (IsUnknown(MipsRegToLoad)) { - MoveVariableToX86reg(&GPR[MipsRegToLoad].UW[1],x86Hi); - MoveVariableToX86reg(&GPR[MipsRegToLoad].UW[0],x86lo); - } else if (IsMapped(MipsRegToLoad)) { - if (Is32Bit(MipsRegToLoad)) { - if (IsSigned(MipsRegToLoad)) { - - MoveX86RegToX86Reg(MipsRegLo(MipsRegToLoad),x86Hi); - ShiftRightSignImmed(x86Hi,31); - } else { - XorX86RegToX86Reg(x86Hi,x86Hi); - } - if (Reg != MipsRegToLoad) { - MoveX86RegToX86Reg(MipsRegLo(MipsRegToLoad),x86lo); - } - } else { - if (Reg != MipsRegToLoad) { - MoveX86RegToX86Reg(MipsRegHi(MipsRegToLoad),x86Hi); - MoveX86RegToX86Reg(MipsRegLo(MipsRegToLoad),x86lo); - } - } - } else { - if (Is32Bit(MipsRegToLoad)) { - if (IsSigned(MipsRegToLoad)) { - if (MipsRegLo((int)MipsRegLo(MipsRegToLoad) >> 31) != 0) { - MoveConstToX86reg((int)MipsRegLo(MipsRegToLoad) >> 31,x86Hi); - } else { - XorX86RegToX86Reg(x86Hi,x86Hi); - } - } else { - XorX86RegToX86Reg(x86Hi,x86Hi); - } - } else { - if (MipsRegHi(MipsRegToLoad) != 0) { - MoveConstToX86reg(MipsRegHi(MipsRegToLoad),x86Hi); - } else { - XorX86RegToX86Reg(x86Hi,x86Hi); - } - } - if (MipsRegLo(MipsRegToLoad) != 0) { - MoveConstToX86reg(MipsRegLo(MipsRegToLoad),x86lo); - } else { - XorX86RegToX86Reg(x86lo,x86lo); - } - } - } else if (MipsRegToLoad == 0) { - XorX86RegToX86Reg(x86Hi,x86Hi); - XorX86RegToX86Reg(x86lo,x86lo); - } - x86Mapped(x86Hi) = GPR_Mapped; - x86Mapped(x86lo) = GPR_Mapped; - MipsRegHi(Reg) = x86Hi; - MipsRegLo(Reg) = x86lo; - MipsRegState(Reg) = STATE_MAPPED_64; -} - -int32_t Map_TempReg (BLOCK_SECTION * Section, int32_t x86Reg, int32_t MipsReg, uint32_t LoadHiWord) { - int32_t count, x64reg = 0; - - //if((x86Reg & x64_Reg) || (x86Reg & x64_Any)) - //Int3(); - x64reg = (x86Reg & x64_Reg) || (x86Reg & x64_Any); - x86Reg &= ~x64_Reg; - - if ((x86Reg == x86_Any) || (x86Reg == x64_Any)) { - for (count = 0; count < 64; count ++ ) { - if (x86Mapped(count) == Temp_Mapped) { - if (x86Protected(count) == 0) { x86Reg = count; } - } - } - - if ((x86Reg == x86_Any) || (x86Reg == x64_Any)) { - x86Reg = FreeX86Reg(Section); - if (x86Reg < 0) { - x86Reg = FreeX86Reg(Section); - return -1; - } - } - } else if (x86Reg == x86_Any8Bit) { - if (x86Mapped(x86_EBX&0x2f) == Temp_Mapped && !x86Protected(x86_EBX&0x2f)) { x86Reg = x86_EBX; } - if (x86Mapped(x86_EAX&0x2f) == Temp_Mapped && !x86Protected(x86_EAX&0x2f)) { x86Reg = x86_EAX; } - if (x86Mapped(x86_EDX&0x2f) == Temp_Mapped && !x86Protected(x86_EDX&0x2f)) { x86Reg = x86_EDX; } - if (x86Mapped(x86_ECX&0x2f) == Temp_Mapped && !x86Protected(x86_ECX&0x2f)) { x86Reg = x86_ECX; } - -#ifdef EXT_REGS - if (x86Mapped(x86_R9D&0x2f) == Temp_Mapped && !x86Protected(x86_R9D&0x2f)) { x86Reg = x86_R9D; } - if (x86Mapped(x86_R10D&0x2f) == Temp_Mapped && !x86Protected(x86_R10D&0x2f)) { x86Reg = x86_R10D; } - if (x86Mapped(x86_R11D&0x2f) == Temp_Mapped && !x86Protected(x86_R11D&0x2f)) { x86Reg = x86_R11D; } - if (x86Mapped(x86_R14D&0x2f) == Temp_Mapped && !x86Protected(x86_R14D&0x2f)) { x86Reg = x86_R14D; } -#endif - - if (x86Reg == x86_Any8Bit) { - x86Reg = Free8BitX86Reg(Section); - if (x86Reg < 0) { - return -1; - } - } - } else { - int NewReg; - - if (x86Mapped(x86Reg) == GPR_Mapped) { - if (x86Protected(x86Reg) == 1) { - return -1; - } - x86Protected(x86Reg) = 1; - NewReg = FreeX86Reg(Section); - for (count = 1; count < 32; count ++) { - if (IsMapped(count)) { - if (MipsRegLo(count) == (uint32_t)x86Reg) { - if (NewReg < 0) { - UnMap_GPR(Section,count,1); - count = 32; - continue; - } - - x86Mapped(NewReg) = GPR_Mapped; - x86MapOrder(NewReg) = x86MapOrder(x86Reg); - MipsRegLo(count) = NewReg; - MoveX86RegToX86Reg(x86Reg,NewReg); - if (MipsReg == count && LoadHiWord == 0) { MipsReg = -1; } - count = 32; - } - if (Is64Bit(count) && MipsRegHi(count) == (uint32_t)x86Reg) { - if (NewReg < 0) { - UnMap_GPR(Section,count,1); - count = 32; - continue; - } - x86Mapped(NewReg) = GPR_Mapped; - x86MapOrder(NewReg) = x86MapOrder(x86Reg); - MipsRegHi(count) = NewReg; - MoveX86RegToX86Reg(x86Reg,NewReg); - if (MipsReg == count && LoadHiWord == 1) { MipsReg = -1; } - count = 32; - } - } - } - } - if (x86Mapped(x86Reg) == Stack_Mapped) { - UnMap_X86reg(Section,x86Reg); - } - } - if (MipsReg >= 0) { - if (LoadHiWord) { - if (IsUnknown(MipsReg)) { - MoveVariableToX86reg(&GPR[MipsReg].UW[1],x86Reg); - } else if (IsMapped(MipsReg)) { - if (Is64Bit(MipsReg)) { - MoveX86RegToX86Reg(MipsRegHi(MipsReg),x86Reg); - } else if (IsSigned(MipsReg)){ - MoveX86RegToX86Reg(MipsRegLo(MipsReg),x86Reg); - - ShiftRightSignImmed(x86Reg,31); - } else { - MoveConstToX86reg(0,x86Reg); - } - } else { - if (Is64Bit(MipsReg)) { - if (MipsRegHi(MipsReg) != 0) { - MoveConstToX86reg(MipsRegHi(MipsReg),x86Reg); - } else { - XorX86RegToX86Reg(x86Reg,x86Reg); - } - } else { - if ((int)MipsRegLo(MipsReg) >> 31 != 0) { - MoveConstToX86reg((int)MipsRegLo(MipsReg) >> 31,x86Reg); - } else { - XorX86RegToX86Reg(x86Reg,x86Reg); - } - } - } - } else { - if (IsUnknown(MipsReg)) { - MoveVariableToX86reg(&GPR[MipsReg].UW[0],x86Reg); - } else if (IsMapped(MipsReg)) { - MoveX86RegToX86Reg(MipsRegLo(MipsReg),x86Reg); - } else { - if (MipsRegLo(MipsReg) != 0) { - MoveConstToX86reg(MipsRegLo(MipsReg),x86Reg); - } else { - XorX86RegToX86Reg(x86Reg,x86Reg); - } - } - } - } - x86Mapped(x86Reg) = Temp_Mapped; - x86Protected(x86Reg) = 1; - for (count = 0; count < 64; count ++) { - if (x86MapOrder(count) > 0) { - x86MapOrder(count) += 1; - } - } - x86MapOrder(x86Reg) = 1; - if(x64reg) x86Reg |= x64_Reg; - return x86Reg; -} - -void ProtectGPR(BLOCK_SECTION * Section, uint32_t Reg) { - if (IsUnknown(Reg)) { return; } - if (IsConst(Reg)) { return; } - if (Is64Bit(Reg)) { - x86Protected(MipsRegHi(Reg)) = 1; - } - x86Protected(MipsRegLo(Reg)) = 1; -} - -uint32_t RegInStack(BLOCK_SECTION * Section,int32_t Reg, int32_t Format) { - int i; - - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)Reg) { - if (FpuState(i) == (uint32_t)Format) { return 1; } - else if (Format == -1) { return 1; } - return 0; - } - } - return 0; -} - -void SetFpuLocations (void) { - int count; - - if ((STATUS_REGISTER & STATUS_FR) == 0) { - for (count = 0; count < 32; count ++) { - FPRFloatLocation[count] = (void *)(&FPR[count >> 1].W[count & 1]); - //FPRDoubleLocation[count] = FPRFloatLocation[count]; - FPRDoubleLocation[count] = (void *)(&FPR[count >> 1].DW); - } - } else { - for (count = 0; count < 32; count ++) { - FPRFloatLocation[count] = (void *)(&FPR[count].W[1]); - //FPRFloatLocation[count] = (void *)(&FPR[count].W[1]); - //FPRDoubleLocation[count] = FPRFloatLocation[count]; - FPRDoubleLocation[count] = (void *)(&FPR[count].DW); - } - } -} - -int32_t StackPosition (BLOCK_SECTION * Section, int32_t Reg) { - int32_t i; - - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) == (uint32_t)Reg) { - return ((i - StackTopPos) & 7); - } - } - return -1; -} - -int UnMap_8BitTempReg (BLOCK_SECTION * Section) { - int32_t count; - - for (count = 0; count < 64; count ++) { - if (!Is8BitReg(count)) { continue; } - if (MipsRegState(count) == Temp_Mapped) { - if (x86Protected(count) == 0) { - x86Mapped(count) = NotMapped; - return count; - } - } - } - return -1; -} - -void UnMap_AllFPRs ( BLOCK_SECTION * Section ) { - int32_t StackPos; - - for (;;) { - int i, StartPos; - StackPos = StackTopPos; - if (FpuMappedTo(StackTopPos) != -1 ) { - UnMap_FPR(Section,FpuMappedTo(StackTopPos),1); - continue; - } - //see if any more registers mapped - StartPos = StackTopPos; - for (i = 0; i < 8; i++) { - if (FpuMappedTo((StartPos + i) & 7) != -1 ) { fpuIncStack(&StackTopPos); } - } - if (StackPos != StackTopPos) { continue; } - return; - } -} - -void UnMap_FPR (BLOCK_SECTION * Section, int32_t Reg, int32_t WriteBackValue ) { - int32_t TempReg; - int32_t i; - - if (Reg < 0) { return; } - for (i = 0; i < 8; i++) { - if (FpuMappedTo(i) != (uint32_t)Reg) { continue; } - if (WriteBackValue) { - int RegPos; - - if (((i - StackTopPos + 8) & 7) != 0) { - uint32_t RoundingModel, MappedTo, RegState; - - RoundingModel = FpuRoundingModel(StackTopPos); - MappedTo = FpuMappedTo(StackTopPos); - RegState = FpuState(StackTopPos); - FpuRoundingModel(StackTopPos) = FpuRoundingModel(i); - FpuMappedTo(StackTopPos) = FpuMappedTo(i); - FpuState(StackTopPos) = FpuState(i); - FpuRoundingModel(i) = RoundingModel; - FpuMappedTo(i) = MappedTo; - FpuState(i) = RegState; - fpuExchange((i - StackTopPos) & 7); - } - - if (CurrentRoundingModel != FpuRoundingModel(i)) { - int x86reg; - - fpuControl = 0; - fpuStoreControl(&fpuControl); - x86reg = Map_TempReg(Section,x86_Any,-1,0); - MoveVariableToX86reg(&fpuControl, x86reg); - AndConstToX86Reg(x86reg, 0xF3FF); - - switch (FpuRoundingModel(i)) { - case RoundDefault: OrVariableToX86Reg(&FPU_RoundingMode,x86reg); break; - case RoundTruncate: OrConstToX86Reg(0x0C00, x86reg); break; - case RoundNearest: /*OrConstToX86Reg(0x0000, x86reg);*/ break; - case RoundDown: OrConstToX86Reg(0x0400, x86reg); break; - case RoundUp: OrConstToX86Reg(0x0800, x86reg); break; - } - MoveX86regToVariable(x86reg, &fpuControl); - fpuLoadControl(&fpuControl); - CurrentRoundingModel = FpuRoundingModel(i); - } - - RegPos = StackTopPos; - TempReg = Map_TempReg(Section,x86_Any,-1,0); - switch (FpuState(StackTopPos)) { - case FPU_Dword: - MovePointerToX86reg(&FPRFloatLocation[FpuMappedTo(StackTopPos)],TempReg); - fpuStoreIntegerDwordFromX86Reg(&StackTopPos,TempReg, 1); - break; - case FPU_Qword: - MovePointerToX86reg(&FPRDoubleLocation[FpuMappedTo(StackTopPos)],TempReg); - fpuStoreIntegerQwordFromX86Reg(&StackTopPos,TempReg, 1); - break; - case FPU_Float: - MovePointerToX86reg(&FPRFloatLocation[FpuMappedTo(StackTopPos)],TempReg); - fpuStoreDwordFromX86Reg(&StackTopPos,TempReg, 1); - break; - case FPU_Double: - MovePointerToX86reg(&FPRDoubleLocation[FpuMappedTo(StackTopPos)],TempReg); - fpuStoreQwordFromX86Reg(&StackTopPos,TempReg, 1); - break; - } - x86Protected(TempReg) = 0; - FpuRoundingModel(RegPos) = RoundDefault; - FpuMappedTo(RegPos) = -1; - FpuState(RegPos) = FPU_Unkown; - } else { - fpuFree((i - StackTopPos) & 7); - FpuRoundingModel(i) = RoundDefault; - FpuMappedTo(i) = -1; - FpuState(i) = FPU_Unkown; - } - return; - } -} - -void UnMap_GPR (BLOCK_SECTION * Section, uint32_t Reg, int32_t WriteBackValue) { - if (Reg == 0) { - return; - } - if (IsUnknown(Reg)) { return; } - if (IsConst(Reg)) { - if (!WriteBackValue) { - MipsRegState(Reg) = STATE_UNKNOWN; - return; - } - if (Is64Bit(Reg)) { - MoveConstToVariable(MipsRegHi(Reg),&GPR[Reg].UW[1]); - MoveConstToVariable(MipsRegLo(Reg),&GPR[Reg].UW[0]); - MipsRegState(Reg) = STATE_UNKNOWN; - return; - } - if ((MipsRegLo(Reg) & 0x80000000) != 0) { - MoveConstToVariable(0xFFFFFFFF,&GPR[Reg].UW[1]); - } else { - MoveConstToVariable(0,&GPR[Reg].UW[1]); - } - MoveConstToVariable(MipsRegLo(Reg),&GPR[Reg].UW[0]); - MipsRegState(Reg) = STATE_UNKNOWN; - return; - } - if (Is64Bit(Reg)) { - x86Mapped(MipsRegHi(Reg)) = NotMapped; - x86Protected(MipsRegHi(Reg)) = 0; - } - x86Mapped(MipsRegLo(Reg)) = NotMapped; - x86Protected(MipsRegLo(Reg)) = 0; - if (!WriteBackValue) { - MipsRegState(Reg) = STATE_UNKNOWN; - return; - } - MoveX86regToVariable(MipsRegLo(Reg),&GPR[Reg].UW[0]); - if (Is64Bit(Reg)) { - MoveX86regToVariable(MipsRegHi(Reg),&GPR[Reg].UW[1]); - } else { - if (IsSigned(Reg)) { - ShiftRightSignImmed(MipsRegLo(Reg),31); - MoveX86regToVariable(MipsRegLo(Reg),&GPR[Reg].UW[1]); - } else { - MoveConstToVariable(0,&GPR[Reg].UW[1]); - } - } - MipsRegState(Reg) = STATE_UNKNOWN; -} - -int UnMap_TempReg (BLOCK_SECTION * Section) { - int count; - - for (count = 0; count < 64; count ++) { - if (x86Mapped(count) == Temp_Mapped) { - if (x86Protected(count) == 0) { - x86Mapped(count) = NotMapped; - return count & 0xff; - } - } - } - return -1; -} - -int UnMap_TempRegSet (REG_INFO * RegWorking) { - int count; - - for (count = 0; count < 64; count ++) { - if (RegWorking->x86reg_MappedTo[count] == Temp_Mapped) { - if (RegWorking->x86reg_Protected[count] == 0) { - RegWorking->x86reg_MappedTo[count] = NotMapped; - return count; - } - } - } - return -1; -} - - -uint32_t UnMap_X86reg (BLOCK_SECTION * Section, uint32_t x86Reg) { - int count; - - if (x86Mapped(x86Reg) == NotMapped && x86Protected(x86Reg) == 0) { return 1; } - if (x86Mapped(x86Reg) == Temp_Mapped) { - if (x86Protected(x86Reg) == 0) { - x86Mapped(x86Reg) = NotMapped; - return 1; - } - return 0; - } - for (count = 1; count < 32; count ++) { - if (IsMapped(count)) { - if (Is64Bit(count)) { - if (MipsRegHi(count) == x86Reg) { - if (x86Protected(x86Reg) == 0) { - UnMap_GPR(Section,count,1); - return 1; - } - break; - } - } - if (MipsRegLo(count) == x86Reg) { - if (x86Protected(x86Reg) == 0) { - UnMap_GPR(Section,count,1); - return 1; - } - break; - } - } - } - return 0; -} - -void UnProtectGPR(BLOCK_SECTION * Section, uint32_t Reg) { - if (IsUnknown(Reg)) { return; } - if (IsConst(Reg)) { return; } - if (Is64Bit(Reg)) { - x86Protected(MipsRegHi(Reg)) = 0; - } - x86Protected(MipsRegLo(Reg)) = 0; -} - -void UpdateCurrentHalfLine (void) { - if (Timers->Timer < 0) { - HalfLine = 0; - return; - } - HalfLine = (Timers->Timer / 1500); - HalfLine &= ~1; - HalfLine += ViFieldNumber; - -} - -void WriteBackRegisters (BLOCK_SECTION * Section) { - int32_t count; - uint32_t bEdiZero = 0; - uint32_t bEsiSign = 0; - /*** coming soon ***/ - //uint32_t bEaxGprLo = 0; - //uint32_t bEbxGprHi = 0; - - for (count = 1; count < 64; count ++) { x86Protected(count) = 0; } - for (count = 1; count < 64; count ++) { UnMap_X86reg (Section, count); } - - /*************************************/ - - for (count = 1; count < 32; count ++) { - switch (MipsRegState(count)) { - case STATE_UNKNOWN: break; - case STATE_CONST_32: - if (!bEdiZero && (!MipsRegLo(count) || !(MipsRegLo(count) & 0x80000000))) { - XorX86RegToX86Reg(x86_EDI, x86_EDI); - bEdiZero = 1; - } - if (!bEsiSign && (MipsRegLo(count) & 0x80000000)) { - MoveConstToX86reg(0xFFFFFFFF, x86_ESI); - bEsiSign = 1; - } - - if ((MipsRegLo(count) & 0x80000000) != 0) { - MoveX86regToVariable(x86_ESI,&GPR[count].UW[1]); - } else { - MoveX86regToVariable(x86_EDI,&GPR[count].UW[1]); - } - - if (MipsRegLo(count) == 0) { - MoveX86regToVariable(x86_EDI,&GPR[count].UW[0]); - } else if (MipsRegLo(count) == 0xFFFFFFFF) { - MoveX86regToVariable(x86_ESI,&GPR[count].UW[0]); - } else - MoveConstToVariable(MipsRegLo(count),&GPR[count].UW[0]); - - MipsRegState(count) = STATE_UNKNOWN; - break; - case STATE_CONST_64: - if (MipsRegLo(count) == 0 || MipsRegHi(count) == 0) { - XorX86RegToX86Reg(x86_EDI, x86_EDI); - bEdiZero = 1; - } - if (MipsRegLo(count) == 0xFFFFFFFF || MipsRegHi(count) == 0xFFFFFFFF) { - MoveConstToX86reg(0xFFFFFFFF, x86_ESI); - bEsiSign = 1; - } - - if (MipsRegHi(count) == 0) { - MoveX86regToVariable(x86_EDI,&GPR[count].UW[1]); - } else if (MipsRegLo(count) == 0xFFFFFFFF) { - MoveX86regToVariable(x86_ESI,&GPR[count].UW[1]); - } else { - MoveConstToVariable(MipsRegHi(count),&GPR[count].UW[1]); - } - - if (MipsRegLo(count) == 0) { - MoveX86regToVariable(x86_EDI,&GPR[count].UW[0]); - } else if (MipsRegLo(count) == 0xFFFFFFFF) { - MoveX86regToVariable(x86_ESI,&GPR[count].UW[0]); - } else { - MoveConstToVariable(MipsRegLo(count),&GPR[count].UW[0]); - } - MipsRegState(count) = STATE_UNKNOWN; - break; - - } - } - UnMap_AllFPRs(Section); -} - diff --git a/src/usf/registers.h b/src/usf/registers.h deleted file mode 100644 index 4c9b1b3..0000000 --- a/src/usf/registers.h +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ - -#ifndef REGISTERS_H -#define REGISTERS_H - -#include "recompiler_cpu.h" -#include "types.h" - -#define INDEX_REGISTER CP0[0] -#define RANDOM_REGISTER CP0[1] -#define ENTRYLO0_REGISTER CP0[2] -#define ENTRYLO1_REGISTER CP0[3] -#define CONTEXT_REGISTER CP0[4] -#define PAGE_MASK_REGISTER CP0[5] -#define WIRED_REGISTER CP0[6] -#define BAD_VADDR_REGISTER CP0[8] -#define COUNT_REGISTER CP0[9] -#define ENTRYHI_REGISTER CP0[10] -#define COMPARE_REGISTER CP0[11] -#define STATUS_REGISTER CP0[12] -#define CAUSE_REGISTER CP0[13] -#define EPC_REGISTER CP0[14] -#define CONFIG_REGISTER CP0[16] -#define TAGLO_REGISTER CP0[28] -#define TAGHI_REGISTER CP0[29] -#define ERROREPC_REGISTER CP0[30] -#define FAKE_CAUSE_REGISTER CP0[32] - -#define COMPARE_REGISTER_NO 11 -#define STATUS_REGISTER_NO 12 -#define CAUSE_REGISTER_NO 13 - -#define REVISION_REGISTER FPCR[0] -#define FSTATUS_REGISTER FPCR[31] - -#define GPR_S0 GPR[16] -#define GPR_S1 GPR[17] -#define GPR_S2 GPR[18] -#define GPR_S3 GPR[19] -#define GPR_S4 GPR[20] -#define GPR_S5 GPR[21] -#define GPR_S6 GPR[22] -#define GPR_S7 GPR[23] -#define GPR_SP GPR[29] -#define GPR_RA GPR[31] - -#define RDRAM_CONFIG_REG RegRDRAM[0] -#define RDRAM_DEVICE_TYPE_REG RegRDRAM[0] -#define RDRAM_DEVICE_ID_REG RegRDRAM[1] -#define RDRAM_DELAY_REG RegRDRAM[2] -#define RDRAM_MODE_REG RegRDRAM[3] -#define RDRAM_REF_INTERVAL_REG RegRDRAM[4] -#define RDRAM_REF_ROW_REG RegRDRAM[5] -#define RDRAM_RAS_INTERVAL_REG RegRDRAM[6] -#define RDRAM_MIN_INTERVAL_REG RegRDRAM[7] -#define RDRAM_ADDR_SELECT_REG RegRDRAM[8] -#define RDRAM_DEVICE_MANUF_REG RegRDRAM[9] - -#define SP_MEM_ADDR_REG RegSP[0] -#define SP_DRAM_ADDR_REG RegSP[1] -#define SP_RD_LEN_REG RegSP[2] -#define SP_WR_LEN_REG RegSP[3] -#define SP_STATUS_REG RegSP[4] -#define SP_DMA_FULL_REG RegSP[5] -#define SP_DMA_BUSY_REG RegSP[6] -#define SP_SEMAPHORE_REG RegSP[7] -#define SP_PC_REG RegSP[8] -#define SP_IBIST_REG RegSP[9] - -#define DPC_START_REG RegDPC[0] -#define DPC_END_REG RegDPC[1] -#define DPC_CURRENT_REG RegDPC[2] -#define DPC_STATUS_REG RegDPC[3] -#define DPC_CLOCK_REG RegDPC[4] -#define DPC_BUFBUSY_REG RegDPC[5] -#define DPC_PIPEBUSY_REG RegDPC[6] -#define DPC_TMEM_REG RegDPC[7] - -#define MI_INIT_MODE_REG RegMI[0] -#define MI_MODE_REG RegMI[0] -#define MI_VERSION_REG RegMI[1] -#define MI_NOOP_REG RegMI[1] -#define MI_INTR_REG RegMI[2] -#define MI_INTR_MASK_REG RegMI[3] - -#define VI_STATUS_REG RegVI[0] -#define VI_CONTROL_REG RegVI[0] -#define VI_ORIGIN_REG RegVI[1] -#define VI_DRAM_ADDR_REG RegVI[1] -#define VI_WIDTH_REG RegVI[2] -#define VI_H_WIDTH_REG RegVI[2] -#define VI_INTR_REG RegVI[3] -#define VI_V_INTR_REG RegVI[3] -#define VI_CURRENT_REG RegVI[4] -#define VI_V_CURRENT_LINE_REG RegVI[4] -#define VI_BURST_REG RegVI[5] -#define VI_TIMING_REG RegVI[5] -#define VI_V_SYNC_REG RegVI[6] -#define VI_H_SYNC_REG RegVI[7] -#define VI_LEAP_REG RegVI[8] -#define VI_H_SYNC_LEAP_REG RegVI[8] -#define VI_H_START_REG RegVI[9] -#define VI_H_VIDEO_REG RegVI[9] -#define VI_V_START_REG RegVI[10] -#define VI_V_VIDEO_REG RegVI[10] -#define VI_V_BURST_REG RegVI[11] -#define VI_X_SCALE_REG RegVI[12] -#define VI_Y_SCALE_REG RegVI[13] - -#define AI_DRAM_ADDR_REG RegAI[0] -#define AI_LEN_REG RegAI[1] -#define AI_CONTROL_REG RegAI[2] -#define AI_STATUS_REG RegAI[3] -#define AI_DACRATE_REG RegAI[4] -#define AI_BITRATE_REG RegAI[5] - -#define PI_DRAM_ADDR_REG RegPI[0] -#define PI_CART_ADDR_REG RegPI[1] -#define PI_RD_LEN_REG RegPI[2] -#define PI_WR_LEN_REG RegPI[3] -#define PI_STATUS_REG RegPI[4] -#define PI_BSD_DOM1_LAT_REG RegPI[5] -#define PI_DOMAIN1_REG RegPI[5] -#define PI_BSD_DOM1_PWD_REG RegPI[6] -#define PI_BSD_DOM1_PGS_REG RegPI[7] -#define PI_BSD_DOM1_RLS_REG RegPI[8] -#define PI_BSD_DOM2_LAT_REG RegPI[9] -#define PI_DOMAIN2_REG RegPI[9] -#define PI_BSD_DOM2_PWD_REG RegPI[10] -#define PI_BSD_DOM2_PGS_REG RegPI[11] -#define PI_BSD_DOM2_RLS_REG RegPI[12] - -#define RI_MODE_REG RegRI[0] -#define RI_CONFIG_REG RegRI[1] -#define RI_CURRENT_LOAD_REG RegRI[2] -#define RI_SELECT_REG RegRI[3] -#define RI_COUNT_REG RegRI[4] -#define RI_REFRESH_REG RegRI[4] -#define RI_LATENCY_REG RegRI[5] -#define RI_RERROR_REG RegRI[6] -#define RI_WERROR_REG RegRI[7] - -#define SI_DRAM_ADDR_REG RegSI[0] -#define SI_PIF_ADDR_RD64B_REG RegSI[1] -#define SI_PIF_ADDR_WR64B_REG RegSI[2] -#define SI_STATUS_REG RegSI[3] - -#define STATUS_IE 0x00000001 -#define STATUS_EXL 0x00000002 -#define STATUS_ERL 0x00000004 -#define STATUS_IP0 0x00000100 -#define STATUS_IP1 0x00000200 -#define STATUS_IP2 0x00000400 -#define STATUS_IP3 0x00000800 -#define STATUS_IP4 0x00001000 -#define STATUS_IP5 0x00002000 -#define STATUS_IP6 0x00004000 -#define STATUS_IP7 0x00008000 -#define STATUS_BEV 0x00400000 -#define STATUS_FR 0x04000000 -#define STATUS_CU0 0x10000000 -#define STATUS_CU1 0x20000000 - -#define CAUSE_EXC_CODE 0xFF -#define CAUSE_IP0 0x100 -#define CAUSE_IP1 0x200 -#define CAUSE_IP2 0x400 -#define CAUSE_IP3 0x800 -#define CAUSE_IP4 0x1000 -#define CAUSE_IP5 0x2000 -#define CAUSE_IP6 0x4000 -#define CAUSE_IP7 0x8000 -#define CAUSE_BD 0x80000000 - -#define SP_CLR_HALT 0x00001 /* Bit 0: clear halt */ -#define SP_SET_HALT 0x00002 /* Bit 1: set halt */ -#define SP_CLR_BROKE 0x00004 /* Bit 2: clear broke */ -#define SP_CLR_INTR 0x00008 /* Bit 3: clear intr */ -#define SP_SET_INTR 0x00010 /* Bit 4: set intr */ -#define SP_CLR_SSTEP 0x00020 /* Bit 5: clear sstep */ -#define SP_SET_SSTEP 0x00040 /* Bit 6: set sstep */ -#define SP_CLR_INTR_BREAK 0x00080 /* Bit 7: clear intr on break */ -#define SP_SET_INTR_BREAK 0x00100 /* Bit 8: set intr on break */ -#define SP_CLR_SIG0 0x00200 /* Bit 9: clear signal 0 */ -#define SP_SET_SIG0 0x00400 /* Bit 10: set signal 0 */ -#define SP_CLR_SIG1 0x00800 /* Bit 11: clear signal 1 */ -#define SP_SET_SIG1 0x01000 /* Bit 12: set signal 1 */ -#define SP_CLR_SIG2 0x02000 /* Bit 13: clear signal 2 */ -#define SP_SET_SIG2 0x04000 /* Bit 14: set signal 2 */ -#define SP_CLR_SIG3 0x08000 /* Bit 15: clear signal 3 */ -#define SP_SET_SIG3 0x10000 /* Bit 16: set signal 3 */ -#define SP_CLR_SIG4 0x20000 /* Bit 17: clear signal 4 */ -#define SP_SET_SIG4 0x40000 /* Bit 18: set signal 4 */ -#define SP_CLR_SIG5 0x80000 /* Bit 19: clear signal 5 */ -#define SP_SET_SIG5 0x100000 /* Bit 20: set signal 5 */ -#define SP_CLR_SIG6 0x200000 /* Bit 21: clear signal 6 */ -#define SP_SET_SIG6 0x400000 /* Bit 22: set signal 6 */ -#define SP_CLR_SIG7 0x800000 /* Bit 23: clear signal 7 */ -#define SP_SET_SIG7 0x1000000 /* Bit 24: set signal 7 */ - -#define SP_STATUS_HALT 0x001 /* Bit 0: halt */ -#define SP_STATUS_BROKE 0x002 /* Bit 1: broke */ -#define SP_STATUS_DMA_BUSY 0x004 /* Bit 2: dma busy */ -#define SP_STATUS_DMA_FULL 0x008 /* Bit 3: dma full */ -#define SP_STATUS_IO_FULL 0x010 /* Bit 4: io full */ -#define SP_STATUS_SSTEP 0x020 /* Bit 5: single step */ -#define SP_STATUS_INTR_BREAK 0x040 /* Bit 6: interrupt on break */ -#define SP_STATUS_SIG0 0x080 /* Bit 7: signal 0 set */ -#define SP_STATUS_SIG1 0x100 /* Bit 8: signal 1 set */ -#define SP_STATUS_SIG2 0x200 /* Bit 9: signal 2 set */ -#define SP_STATUS_SIG3 0x400 /* Bit 10: signal 3 set */ -#define SP_STATUS_SIG4 0x800 /* Bit 11: signal 4 set */ -#define SP_STATUS_SIG5 0x1000 /* Bit 12: signal 5 set */ -#define SP_STATUS_SIG6 0x2000 /* Bit 13: signal 6 set */ -#define SP_STATUS_SIG7 0x4000 /* Bit 14: signal 7 set */ - -#define DPC_CLR_XBUS_DMEM_DMA 0x0001 /* Bit 0: clear xbus_dmem_dma */ -#define DPC_SET_XBUS_DMEM_DMA 0x0002 /* Bit 1: set xbus_dmem_dma */ -#define DPC_CLR_FREEZE 0x0004 /* Bit 2: clear freeze */ -#define DPC_SET_FREEZE 0x0008 /* Bit 3: set freeze */ -#define DPC_CLR_FLUSH 0x0010 /* Bit 4: clear flush */ -#define DPC_SET_FLUSH 0x0020 /* Bit 5: set flush */ -#define DPC_CLR_TMEM_CTR 0x0040 /* Bit 6: clear tmem ctr */ -#define DPC_CLR_PIPE_CTR 0x0080 /* Bit 7: clear pipe ctr */ -#define DPC_CLR_CMD_CTR 0x0100 /* Bit 8: clear cmd ctr */ -#define DPC_CLR_CLOCK_CTR 0x0200 /* Bit 9: clear clock ctr */ - -#define DPC_STATUS_XBUS_DMEM_DMA 0x001 /* Bit 0: xbus_dmem_dma */ -#define DPC_STATUS_FREEZE 0x002 /* Bit 1: freeze */ -#define DPC_STATUS_FLUSH 0x004 /* Bit 2: flush */ -#define DPC_STATUS_START_GCLK 0x008 /* Bit 3: start gclk */ -#define DPC_STATUS_TMEM_BUSY 0x010 /* Bit 4: tmem busy */ -#define DPC_STATUS_PIPE_BUSY 0x020 /* Bit 5: pipe busy */ -#define DPC_STATUS_CMD_BUSY 0x040 /* Bit 6: cmd busy */ -#define DPC_STATUS_CBUF_READY 0x080 /* Bit 7: cbuf ready */ -#define DPC_STATUS_DMA_BUSY 0x100 /* Bit 8: dma busy */ -#define DPC_STATUS_END_VALID 0x200 /* Bit 9: end valid */ -#define DPC_STATUS_START_VALID 0x400 /* Bit 10: start valid */ - -#define MI_CLR_INIT 0x0080 /* Bit 7: clear init mode */ -#define MI_SET_INIT 0x0100 /* Bit 8: set init mode */ -#define MI_CLR_EBUS 0x0200 /* Bit 9: clear ebus test */ -#define MI_SET_EBUS 0x0400 /* Bit 10: set ebus test mode */ -#define MI_CLR_DP_INTR 0x0800 /* Bit 11: clear dp interrupt */ -#define MI_CLR_RDRAM 0x1000 /* Bit 12: clear RDRAM reg */ -#define MI_SET_RDRAM 0x2000 /* Bit 13: set RDRAM reg mode */ - -#define MI_MODE_INIT 0x0080 /* Bit 7: init mode */ -#define MI_MODE_EBUS 0x0100 /* Bit 8: ebus test mode */ -#define MI_MODE_RDRAM 0x0200 /* Bit 9: RDRAM reg mode */ - -#define MI_INTR_MASK_CLR_SP 0x0001 /* Bit 0: clear SP mask */ -#define MI_INTR_MASK_SET_SP 0x0002 /* Bit 1: set SP mask */ -#define MI_INTR_MASK_CLR_SI 0x0004 /* Bit 2: clear SI mask */ -#define MI_INTR_MASK_SET_SI 0x0008 /* Bit 3: set SI mask */ -#define MI_INTR_MASK_CLR_AI 0x0010 /* Bit 4: clear AI mask */ -#define MI_INTR_MASK_SET_AI 0x0020 /* Bit 5: set AI mask */ -#define MI_INTR_MASK_CLR_VI 0x0040 /* Bit 6: clear VI mask */ -#define MI_INTR_MASK_SET_VI 0x0080 /* Bit 7: set VI mask */ -#define MI_INTR_MASK_CLR_PI 0x0100 /* Bit 8: clear PI mask */ -#define MI_INTR_MASK_SET_PI 0x0200 /* Bit 9: set PI mask */ -#define MI_INTR_MASK_CLR_DP 0x0400 /* Bit 10: clear DP mask */ -#define MI_INTR_MASK_SET_DP 0x0800 /* Bit 11: set DP mask */ - -#define MI_INTR_MASK_SP 0x01 /* Bit 0: SP intr mask */ -#define MI_INTR_MASK_SI 0x02 /* Bit 1: SI intr mask */ -#define MI_INTR_MASK_AI 0x04 /* Bit 2: AI intr mask */ -#define MI_INTR_MASK_VI 0x08 /* Bit 3: VI intr mask */ -#define MI_INTR_MASK_PI 0x10 /* Bit 4: PI intr mask */ -#define MI_INTR_MASK_DP 0x20 /* Bit 5: DP intr mask */ - -#define MI_INTR_SP 0x01 /* Bit 0: SP intr */ -#define MI_INTR_SI 0x02 /* Bit 1: SI intr */ -#define MI_INTR_AI 0x04 /* Bit 2: AI intr */ -#define MI_INTR_VI 0x08 /* Bit 3: VI intr */ -#define MI_INTR_PI 0x10 /* Bit 4: PI intr */ -#define MI_INTR_DP 0x20 /* Bit 5: DP intr */ - -#define PI_STATUS_DMA_BUSY 0x01 -#define PI_STATUS_IO_BUSY 0x02 -#define PI_STATUS_ERROR 0x04 - -#define PI_SET_RESET 0x01 -#define PI_CLR_INTR 0x02 - -#define SI_STATUS_DMA_BUSY 0x0001 -#define SI_STATUS_RD_BUSY 0x0002 -#define SI_STATUS_DMA_ERROR 0x0008 -#define SI_STATUS_INTERRUPT 0x1000 - -#define FPCSR_FS 0x01000000 /* flush denorm to zero */ -#define FPCSR_C 0x00800000 /* condition bit */ -#define FPCSR_CE 0x00020000 /* cause: unimplemented operation */ -#define FPCSR_CV 0x00010000 /* cause: invalid operation */ -#define FPCSR_CZ 0x00008000 /* cause: division by zero */ -#define FPCSR_CO 0x00004000 /* cause: overflow */ -#define FPCSR_CU 0x00002000 /* cause: underflow */ -#define FPCSR_CI 0x00001000 /* cause: inexact operation */ -#define FPCSR_EV 0x00000800 /* enable: invalid operation */ -#define FPCSR_EZ 0x00000400 /* enable: division by zero */ -#define FPCSR_EO 0x00000200 /* enable: overflow */ -#define FPCSR_EU 0x00000100 /* enable: underflow */ -#define FPCSR_EI 0x00000080 /* enable: inexact operation */ -#define FPCSR_FV 0x00000040 /* flag: invalid operation */ -#define FPCSR_FZ 0x00000020 /* flag: division by zero */ -#define FPCSR_FO 0x00000010 /* flag: overflow */ -#define FPCSR_FU 0x00000008 /* flag: underflow */ -#define FPCSR_FI 0x00000004 /* flag: inexact operation */ -#define FPCSR_RM_MASK 0x00000003 /* rounding mode mask */ -#define FPCSR_RM_RN 0x00000000 /* round to nearest */ -#define FPCSR_RM_RZ 0x00000001 /* round to zero */ -#define FPCSR_RM_RP 0x00000002 /* round to positive infinity */ -#define FPCSR_RM_RM 0x00000003 /* round to negative infinity */ - -#define FPR_Type(Reg) (Reg) == R4300i_COP1_S ? "S" : (Reg) == R4300i_COP1_D ? "D" :\ - (Reg) == R4300i_COP1_W ? "W" : "L" - -typedef struct { - uint32_t PROGRAM_COUNTER; - MIPS_DWORD GPR[32]; - MIPS_DWORD FPR[32]; - uint32_t CP0[33]; - uint32_t FPCR[32]; - MIPS_DWORD HI; - MIPS_DWORD LO; - uint32_t RDRAM[10]; - uint32_t SP[10]; - uint32_t DPC[10]; - uint32_t MI[4]; - uint32_t VI[14]; - uint32_t AI[6]; - uint32_t PI[13]; - uint32_t RI[8]; - uint32_t SI[4]; - int8_t PIF_Ram[0x40]; -} N64_REGISTERS; - - -extern uint32_t PROGRAM_COUNTER, * CP0,*FPCR,*RegRDRAM,*RegSP,*RegDPC,*RegMI,*RegVI,*RegAI,*RegPI, - *RegRI,*RegSI, HalfLine, RegModValue, ViFieldNumber, LLBit, LLAddr; -extern void * FPRDoubleLocation[32], * FPRFloatLocation[32]; -extern MIPS_DWORD *GPR, *FPR, HI, LO; -extern N64_REGISTERS * Registers; - -enum FPU_Format { - FPU_Unkown,FPU_Dword, FPU_Qword, FPU_Float, FPU_Double -}; - -enum FPU_RoundingModel { - RoundUnknown, RoundDefault, RoundTruncate, RoundNearest, RoundDown, RoundUp -}; - -void ChangeFPURegFormat ( BLOCK_SECTION * Section, int32_t Reg, int32_t OldFormat, int32_t NewFormat, int32_t RoundingModel ); -void ChangeMiIntrMask ( void ); -void ChangeMiModeReg ( void ); -void ChangeSpStatus ( void ); -void InitalizeR4300iRegisters ( void ); -uint32_t Is8BitReg ( int32_t x86Reg); -void Load_FPR_ToTop ( BLOCK_SECTION * Section, int32_t Reg, int32_t RegToLoad, int32_t Format); -void Map_GPR_32bit ( BLOCK_SECTION * Section, int32_t Reg, uint32_t SignValue, int32_t MipsRegToLoad ); -void Map_GPR_64bit ( BLOCK_SECTION * Section, int32_t Reg, int32_t MipsRegToLoad ); -int32_t Map_TempReg ( BLOCK_SECTION * Section, int32_t x86Reg, int32_t MipsReg, uint32_t LoadHiWord ); -uint32_t RegInStack ( BLOCK_SECTION * Section, int32_t Reg, int32_t Format ); -void ProtectGPR ( BLOCK_SECTION * Section, uint32_t Reg ); -void SetFpuLocations ( void ); -int32_t StackPosition ( BLOCK_SECTION * Section, int32_t Reg ); -int UnMap_8BitTempReg (BLOCK_SECTION * Section); -void UnMap_AllFPRs ( BLOCK_SECTION * Section ); -void UnMap_FPR ( BLOCK_SECTION * Section, int32_t Reg, int32_t WriteBackValue ); -void UnMap_GPR ( BLOCK_SECTION * Section, uint32_t Reg, int32_t WriteBackValue ); -uint32_t UnMap_X86reg ( BLOCK_SECTION * Section, uint32_t x86Reg ); -void UnProtectGPR ( BLOCK_SECTION * Section, uint32_t Reg ); -void UpdateCurrentHalfLine ( void ); -void WriteBackRegisters ( BLOCK_SECTION * Section ); - - -void SetupRegisters(N64_REGISTERS * n64_Registers); - -#endif diff --git a/src/usf/rsp.c b/src/usf/rsp.c deleted file mode 100644 index 2a5cea3..0000000 --- a/src/usf/rsp.c +++ /dev/null @@ -1,1065 +0,0 @@ -#include -#include -#include "usf.h" -#include "cpu.h" -#include "memory.h" -#include "audio.h" -#include "rsp.h" -#include "types.h" -#include "main.h" - -#include "rsp_recompiler_cpu.h" - - - -uint32_t NoOfMaps, MapsCRC[MaxMaps], Table,ConditionalMove=0; -uint8_t * RSPRecompCode = 0, * RSPRecompCodeSecondary, * RSPRecompPos, *RSPJumpTables; -void ** RSPJumpTable; - - -RSP_COMPILER Compiler; -//REGISTER32 RSP_GPR[32], RSP_Flags[4]; -REGISTER32 *RSP_GPR, RSP_Flags[4]; -REGISTER * RSP_ACCUM; -VECTOR * RSP_Vect; - -REGISTER EleSpec[32], Indx[32]; -RSPOPCODE RSPOpC; -uint32_t *PrgCount = 0, RSPNextInstruction = 0; -uint32_t RSP_NextInstruction = 0; -REGISTER32 Recp, RecpResult, SQroot, SQrootResult; - -uint32_t RSP_NextInstruction, RSP_JumpTo; -uint32_t RSP_Running = 0; -int32_t RSP_Cpu = 0; - - -void RSPReInitMemory() -{ - - if(RSPRecompCode == NULL) { - printf("enough memory for RSP RSPRecompCode!"); - return; - } - - RSPRecompCodeSecondary = RSPRecompCode + RSP_RECOMPMEM_SIZE; - - - if( RSPJumpTables == NULL ) { - DisplayError("Not enough memory for Jump Table!"); - return; - } - - memset((uint8_t*)RSPJumpTables, 0, 0x2000 * MaxMaps); - memset((uint8_t*)RSPRecompCode, 0, 0x00400000); - memset((uint8_t*)RSPRecompCodeSecondary, 0, 0x00200000); - - - RSPJumpTable = (void **)RSPJumpTables; - RSPRecompPos = RSPRecompCode; - NoOfMaps = 0; -} - -int32_t RSPAllocateMemory (void) { - - RSPRecompCode=(uint8_t *) malloc_exec(RSP_RECOMPMEM_SIZE + RSP_SECRECOMPMEM_SIZE); - if(RSPRecompCode == NULL) { - DisplayError("Not enough memory for RSP RSPRecompCode!"); - return 0; - } - - RSPRecompCodeSecondary = RSPRecompCode + RSP_RECOMPMEM_SIZE; - - RSPJumpTables = malloc(0x2000 * MaxMaps); - - if( RSPJumpTables == NULL ) { - DisplayError("Not enough memory for Jump Table!"); - return 0; - } - - memset((uint8_t*)RSPJumpTables, 0, 0x2000 * MaxMaps); - memset((uint8_t*)RSPRecompCode, 0, 0x00400000); - memset((uint8_t*)RSPRecompCodeSecondary, 0, 0x00200000); - - RSPJumpTable = (void **)RSPJumpTables; - RSPRecompPos = RSPRecompCode; - NoOfMaps = 0; - return 1; -} - -FILE *qfil = 0; - -void real_run_rsp(uint32_t cycles) -{ -//replace with interpreter -if(RSP_Cpu) { - RSP_Running = 1; - - while(RSP_Running) { - // int32_t last = -1, count = 0, el, del; - RSP_LW_IMEM(*PrgCount, &RSPOpC.Hex); - - /*if(*PrgCount == 0x100) { - int32_t i= 0; - FILE *fil4 = fopen("sc2000i.dmem","wb"); - for(i = 0; i < 0x2000;i+=4) { - uint32_t dat = 0; - dat = *(int32_t*)(DMEM + i); - DoBswap(&dat); - fwrite(&dat,1,4,fil4); - } - fclose(fil4); - printf("RSP: %x\n", RSP_GPR[26].UW); -// Int3(); -// RSPBreakPoint(); - }*/ -/* - if(!qfil) qfil = fopen("rsplogi.log","wb"); - fprintf(qfil,"PC = %08x ", *PrgCount); - fprintf(qfil,"r0=%08x at=%08x v0=%08x v1=%08x a0=%08x a1=%08x a2=%08x a3=%08x t0=%08x t1=%08x t2=%08x t3=%08x t4=%08x t5=%08x t6=%08x t7=%08x s0=%08x s1=%08x s2=%08x s3=%08x s4=%08x s5=%08x s6=%08x s7=%08x t8=%08x t9=%08x k0=%08x k1=%08x gp=%08x sp=%08x s8=%08x ra=%08x\n", - RSP_GPR[0].UW,RSP_GPR[1].UW,RSP_GPR[2].UW,RSP_GPR[3].UW, - RSP_GPR[4].UW,RSP_GPR[5].UW,RSP_GPR[6].UW,RSP_GPR[7].UW, - RSP_GPR[8].UW,RSP_GPR[9].UW,RSP_GPR[10].UW,RSP_GPR[11].UW,RSP_GPR[12].UW, - RSP_GPR[13].UW,RSP_GPR[14].UW,RSP_GPR[15].UW,RSP_GPR[16].UW, - RSP_GPR[17].UW,RSP_GPR[18].UW,RSP_GPR[19].UW,RSP_GPR[20].UW, - RSP_GPR[21].UW,RSP_GPR[22].UW,RSP_GPR[23].UW,RSP_GPR[24].UW, - RSP_GPR[25].UW,RSP_GPR[26].UW,RSP_GPR[27].UW,RSP_GPR[28].UW, - RSP_GPR[29].UW,RSP_GPR[30].UW,RSP_GPR[31].UW); -*/ - /*if((RSPOpC.op == 18) && (RSPOpC.rs & 0x10)) { - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - if((last >= 0) && (last != del)) - printf("not same!\t%d\n", RSPOpC.funct); - // 16,19,20,22 - // funct: 0,16,6,14,44,15,7 - last = del; - } - }*/ - - //if(RSPOpC.rs < 0x10) printf("%d\n", RSPOpC.rs); - - (RSP_Opcode[ RSPOpC.op ])(); - - switch (RSP_NextInstruction) { - case NORMAL: - *PrgCount = (*PrgCount + 4) & 0xFFC; - break; - case DELAY_SLOT: - RSP_NextInstruction = JUMP; - *PrgCount = (*PrgCount + 4) & 0xFFC; - break; - case JUMP: - RSP_NextInstruction = NORMAL; - - *PrgCount = RSP_JumpTo; - break; - } - - } - - *PrgCount -= 4; - - return; - - } else { - RunRecompilerCPU(cycles); - } - -} - -void RSP_SP_DMA_READ (void) { - uint32_t i, j, Length, Skip, Count; - uint8_t *Dest, *Source; - - SP_DRAM_ADDR_REG &= 0x00FFFFFF; - - if (SP_DRAM_ADDR_REG > 0x800000) { - printf("SP DMA READ\nSP_DRAM_ADDR_REG not in RDRam space"); - return; - } - - if ((SP_RD_LEN_REG & 0xFFF) + 1 + (SP_MEM_ADDR_REG & 0xFFF) > 0x1000) { - printf("SP DMA READ\ncould not fit copy in memory segement\nSP_RD_LEN_REG=%08x\nSP_MEM_ADDR_REG=%08x",SP_RD_LEN_REG,SP_MEM_ADDR_REG); - return; - } - - Length = ((SP_RD_LEN_REG & 0xFFF) | 7) + 1; - Skip = (SP_RD_LEN_REG >> 20) + Length; - Count = ((SP_RD_LEN_REG >> 12) & 0xFF) + 1; - - if ((SP_MEM_ADDR_REG & 0x1000) != 0) { - Dest = IMEM + ((SP_MEM_ADDR_REG & 0x0FFF) & ~7); - } else { - Dest = DMEM + ((SP_MEM_ADDR_REG & 0x0FFF) & ~7); - } - Source = RDRAM + (SP_DRAM_ADDR_REG & ~7); - -#if defined(RSP_SAFE_DMA) - for (j = 0 ; j < Count; j++) { - for (i = 0 ; i < Length; i++) { - *(uint8_t *)(((uint32_t)Dest + j * Length + i) ^ 3) = *(uint8_t *)(((uint32_t)Source + j * Skip + i) ^ 3); - } - } -#else - if ((Skip & 0x3) == 0) { - for (j = 0; j < Count; j++) { - memcpy(Dest, Source, Length); - Source += Skip; - Dest += Length; - } - } else { - for (j = 0 ; j < Count; j++) { - for (i = 0 ; i < Length; i++) { - *(uint8_t *)(((uint32_t)Dest + i) ^ 3) = *(uint8_t *)(((uint32_t)Source + i) ^ 3); - } - Source += Skip; - Dest += Length; - } - } -#endif - if ((!RSP_Cpu) && ((SP_MEM_ADDR_REG & 0x1000) != 0)) { - RSPSetJumpTable(); - } - - - - SP_DMA_BUSY_REG = 0; - SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; -} - -void RSP_SP_DMA_WRITE (void) { - uint32_t i, j, Length, Skip, Count; - uint8_t *Dest, *Source; - - SP_DRAM_ADDR_REG &= 0x00FFFFFF; - - if (SP_DRAM_ADDR_REG > 0x800000) { - printf("SP DMA WRITE\nSP_DRAM_ADDR_REG not in RDRam space"); - return; - } - - if ((SP_WR_LEN_REG & 0xFFF) + 1 + (SP_MEM_ADDR_REG & 0xFFF) > 0x1000) { - printf("SP DMA READ\ncould not fit copy in memory segement\nSP_WR_LEN_REG=%08x\nSP_MEM_ADDR_REG=%08x",SP_WR_LEN_REG,SP_MEM_ADDR_REG); - return; - } - - Length = ((SP_WR_LEN_REG & 0xFFF) | 7) + 1; - Skip = (SP_WR_LEN_REG >> 20) + Length; - Count = ((SP_WR_LEN_REG >> 12) & 0xFF) + 1; - Dest = RDRAM + (SP_DRAM_ADDR_REG & ~7); - Source = DMEM + ((SP_MEM_ADDR_REG & 0x1FFF) & ~7); - -#if defined(RSP_SAFE_DMA) - for (j = 0 ; j < Count; j++) { - for (i = 0 ; i < Length; i++) { - *(uint8_t *)(((uint32_t)Dest + j * Skip + i) ^ 3) = *(uint8_t *)(((uint32_t)Source + j * Length + i) ^ 3); - } - } -#else - if ((Skip & 0x3) == 0) { - for (j = 0; j < Count; j++) { - memcpy(Dest, Source, Length); - Source += Length; - Dest += Skip; - } - } else { - for (j = 0 ; j < Count; j++) { - for (i = 0 ; i < Length; i++) { - *(uint8_t *)(((uint32_t)Dest + i) ^ 3) = *(uint8_t *)(((uint32_t)Source + i) ^ 3); - } - Source += Length; - Dest += Skip; - } - } -#endif - SP_DMA_BUSY_REG = 0; - SP_STATUS_REG &= ~SP_STATUS_DMA_BUSY; -} - -void RSP_LB_DMEM ( uint32_t Addr, uint8_t * Value ) { - * Value = *(uint8_t *)(DMEM + ((Addr ^ 3) & 0xFFF)) ; -} - -void RSP_LBV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - RSP_Vect[vect].B[15 - element] = *(DMEM + ((Addr ^ 3) & 0xFFF)); -} - -void RSP_LDV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count; - - length = 8; - if (length > 16 - element) { - length = 16 - element; - } - for (Count = element; Count < (length + element); Count ++ ){ - RSP_Vect[vect].B[15 - Count] = *(DMEM + ((Addr ^ 3) & 0xFFF)); - Addr += 1; - } - -} - -void RSP_LFV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, count; - VECTOR Temp; - - length = 8; - if (length > 16 - element) { - length = 16 - element; - } - - Temp.HW[7] = *(DMEM + (((Addr + element) ^3) & 0xFFF)) << 7; - Temp.HW[6] = *(DMEM + (((Addr + ((0x4 - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[5] = *(DMEM + (((Addr + ((0x8 - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[4] = *(DMEM + (((Addr + ((0xC - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[3] = *(DMEM + (((Addr + ((0x8 - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[2] = *(DMEM + (((Addr + ((0xC - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[1] = *(DMEM + (((Addr + ((0x10 - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - Temp.HW[0] = *(DMEM + (((Addr + ((0x4 - element) ^ 3) & 0xf)) & 0xFFF)) << 7; - - for (count = element; count < (length + element); count ++ ){ - RSP_Vect[vect].B[15 - count] = Temp.B[15 - count]; - } -} - -void RSP_LH_DMEM ( uint32_t Addr, uint16_t * Value ) { - if ((Addr & 0x1) != 0) { - if (Addr > 0xFFE) { - printf("hmmmm.... Problem with:\nRSP_LH_DMEM"); - return; - } - Addr &= 0xFFF; - *Value = *(uint8_t *)(DMEM + (Addr^ 3)) << 8; - *Value += *(uint8_t *)(DMEM + ((Addr + 1)^ 3)); - return; - } - * Value = *(uint16_t *)(DMEM + ((Addr ^ 2 ) & 0xFFF)); - -} - -void RSP_LHV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - RSP_Vect[vect].HW[7] = *(DMEM + ((Addr + ((0x10 - element) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[6] = *(DMEM + ((Addr + ((0x10 - element + 2) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[5] = *(DMEM + ((Addr + ((0x10 - element + 4) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[4] = *(DMEM + ((Addr + ((0x10 - element + 6) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[3] = *(DMEM + ((Addr + ((0x10 - element + 8) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[2] = *(DMEM + ((Addr + ((0x10 - element + 10) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[1] = *(DMEM + ((Addr + ((0x10 - element + 12) & 0xF) ^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[0] = *(DMEM + ((Addr + ((0x10 - element + 14) & 0xF) ^3) & 0xFFF)) << 7; -} - -void RSP_LLV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count; - - length = 4; - if (length > 16 - element) { - length = 16 - element; - } - for (Count = element; Count < (length + element); Count ++ ){ - RSP_Vect[vect].B[15 - Count] = *(DMEM + ((Addr ^ 3) & 0xFFF)); - Addr += 1; - } - -} - -void RSP_LPV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - RSP_Vect[vect].HW[7] = *(DMEM + ((Addr + ((0x10 - element) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[6] = *(DMEM + ((Addr + ((0x10 - element + 1) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[5] = *(DMEM + ((Addr + ((0x10 - element + 2) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[4] = *(DMEM + ((Addr + ((0x10 - element + 3) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[3] = *(DMEM + ((Addr + ((0x10 - element + 4) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[2] = *(DMEM + ((Addr + ((0x10 - element + 5) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[1] = *(DMEM + ((Addr + ((0x10 - element + 6) & 0xF)^3) & 0xFFF)) << 8; - RSP_Vect[vect].HW[0] = *(DMEM + ((Addr + ((0x10 - element + 7) & 0xF)^3) & 0xFFF)) << 8; -} - -void RSP_LRV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count, offset; - - offset = (Addr & 0xF) - 1; - length = (Addr & 0xF) - element; - Addr &= 0xFF0; - for (Count = element; Count < (length + element); Count ++ ){ - RSP_Vect[vect].B[offset - Count] = *(DMEM + ((Addr ^ 3) & 0xFFF)); - Addr += 1; - } - -} - -void RSP_LQV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count; - - length = ((Addr + 0x10) & ~0xF) - Addr; - if (length > 16 - element) { - length = 16 - element; - } - for (Count = element; Count < (length + element); Count ++ ){ - RSP_Vect[vect].B[15 - Count] = *(DMEM + ((Addr ^ 3) & 0xFFF)); - Addr += 1; - } - -} - -void RSP_LSV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count; - - length = 2; - if (length > 16 - element) { - length = 16 - element; - } - for (Count = element; Count < (length + element); Count ++ ){ - RSP_Vect[vect].B[15 - Count] = *(DMEM + ((Addr ^ 3) & 0xFFF)); - Addr += 1; - } -} - -void RSP_LTV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t del, count, length; - - length = 8; - if (length > 32 - vect) { - length = 32 - vect; - } - - Addr = ((Addr + 8) & 0xFF0) + (element & 0x1); - for (count = 0; count < length; count ++) { - del = ((8 - (element >> 1) + count) << 1) & 0xF; - RSP_Vect[vect + count].B[15 - del] = *(DMEM + (Addr ^ 3)); - RSP_Vect[vect + count].B[14 - del] = *(DMEM + ((Addr + 1) ^ 3)); - Addr += 2; - } -} - -void RSP_LUV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - RSP_Vect[vect].HW[7] = *(DMEM + ((Addr + ((0x10 - element) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[6] = *(DMEM + ((Addr + ((0x10 - element + 1) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[5] = *(DMEM + ((Addr + ((0x10 - element + 2) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[4] = *(DMEM + ((Addr + ((0x10 - element + 3) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[3] = *(DMEM + ((Addr + ((0x10 - element + 4) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[2] = *(DMEM + ((Addr + ((0x10 - element + 5) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[1] = *(DMEM + ((Addr + ((0x10 - element + 6) & 0xF)^3) & 0xFFF)) << 7; - RSP_Vect[vect].HW[0] = *(DMEM + ((Addr + ((0x10 - element + 7) & 0xF)^3) & 0xFFF)) << 7; -} - -void RSP_LW_DMEM ( uint32_t Addr, uint32_t * Value ) { - if ((Addr & 0x3) != 0) { - Addr &= 0xFFF; - if (Addr > 0xFFC) { - printf("hmmmm.... Problem with:\nRSP_LW_DMEM"); - return; - } - *Value = *(uint8_t *)(DMEM + (Addr^ 3)) << 0x18; - *Value += *(uint8_t *)(DMEM + ((Addr + 1)^ 3)) << 0x10; - *Value += *(uint8_t *)(DMEM + ((Addr + 2)^ 3)) << 8; - *Value += *(uint8_t *)(DMEM + ((Addr + 3)^ 3)); - return; - } - * Value = *(uint32_t *)(DMEM + (Addr & 0xFFF)); -} - -void RSP_LW_IMEM ( uint32_t Addr, uint32_t * Value ) { - if ((Addr & 0x3) != 0) { - printf("Unaligned RSP_LW_IMEM"); - } - * Value = *(uint32_t *)(IMEM + (Addr & 0xFFF)); -} - -void RSP_SB_DMEM ( uint32_t Addr, uint8_t Value ) { - *(uint8_t *)(DMEM + ((Addr ^ 3) & 0xFFF)) = Value; -} - -void RSP_SBV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].B[15 - element]; -} - -void RSP_SDV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count; - - for (Count = element; Count < (8 + element); Count ++ ){ - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].B[15 - (Count & 0xF)]; - Addr += 1; - } -} - -void RSP_SFV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t offset = Addr & 0xF; - Addr &= 0xFF0; - - switch (element) { - case 0: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[7] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[6] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[5] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[4] >> 7; - break; - case 1: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[1] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[0] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[3] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[2] >> 7; - break; - case 2: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 3: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF)^3))) = 0; - break; - case 4: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[6] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[5] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[4] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[7] >> 7; - break; - case 5: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[0] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[3] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[2] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[1] >> 7; - break; - case 6: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 7: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 8: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[3] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[2] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[1] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[0] >> 7; - break; - case 9: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 10: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 11: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[4] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[7] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[6] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[5] >> 7; - break; - case 12: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[2] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[1] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[0] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[3] >> 7; - break; - case 13: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 14: - *(DMEM + ((Addr + offset)^3)) = 0; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = 0; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = 0; - break; - case 15: - *(DMEM + ((Addr + offset)^3)) = RSP_Vect[vect].UHW[7] >> 7; - *(DMEM + ((Addr + ((offset + 4) & 0xF))^3)) = RSP_Vect[vect].UHW[6] >> 7; - *(DMEM + ((Addr + ((offset + 8) & 0xF))^3)) = RSP_Vect[vect].UHW[5] >> 7; - *(DMEM + ((Addr + ((offset + 12) & 0xF))^3)) = RSP_Vect[vect].UHW[4] >> 7; - break; - } -} - -void RSP_SH_DMEM ( uint32_t Addr, uint16_t Value ) { - if ((Addr & 0x1) != 0) { - printf("Unaligned RSP_SH_DMEM"); - return; - } - *(uint16_t *)(DMEM + ((Addr ^ 2) & 0xFFF)) = Value; -} - -void RSP_SHV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - *(DMEM + ((Addr^3) & 0xFFF)) = (RSP_Vect[vect].UB[(15 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(14 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 2)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(13 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(12 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 4)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(11 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(10 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 6)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(9 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(8 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 8)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(7 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(6 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 10)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(5 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(4 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 12)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(3 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(2 - element) & 0xF] >> 7); - *(DMEM + (((Addr + 14)^3) & 0xFFF)) = (RSP_Vect[vect].UB[(1 - element) & 0xF] << 1) + - (RSP_Vect[vect].UB[(0 - element) & 0xF] >> 7); -} - -void RSP_SLV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count; - - for (Count = element; Count < (4 + element); Count ++ ){ - *(DMEM + ((Addr ^3) & 0xFFF)) = RSP_Vect[vect].B[15 - (Count & 0xF)]; - Addr += 1; - } -} - -void RSP_SPV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count; - - for (Count = element; Count < (8 + element); Count ++ ){ - if (((Count) & 0xF) < 8) { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].UB[15 - ((Count & 0xF) << 1)]; - } else { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = (RSP_Vect[vect].UB[15 - ((Count & 0x7) << 1)] << 1) + - (RSP_Vect[vect].UB[14 - ((Count & 0x7) << 1)] >> 7); - } - Addr += 1; - } -} - -void RSP_SQV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count; - - length = ((Addr + 0x10) & ~0xF) - Addr; - for (Count = element; Count < (length + element); Count ++ ){ - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].B[15 - (Count & 0xF)]; - Addr += 1; - } -} - -void RSP_SRV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t length, Count, offset; - - length = (Addr & 0xF); - offset = (0x10 - length) & 0xF; - Addr &= 0xFF0; - for (Count = element; Count < (length + element); Count ++ ){ - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].B[15 - ((Count + offset) & 0xF)]; - Addr += 1; - } -} - -void RSP_SSV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count; - - for (Count = element; Count < (2 + element); Count ++ ){ - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].B[15 - (Count & 0xF)]; - Addr += 1; - } -} - -void RSP_STV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t del, count, length; - - length = 8; - if (length > 32 - vect) { - length = 32 - vect; - } - length = length << 1; - del = element >> 1; - for (count = 0; count < length; count += 2) { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect + del].UB[15 - count]; - *(DMEM + (((Addr + 1) ^ 3) & 0xFFF)) = RSP_Vect[vect + del].UB[14 - count]; - del = (del + 1) & 7; - Addr += 2; - } -} - -void RSP_SUV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count; - - for (Count = element; Count < (8 + element); Count ++ ){ - if (((Count) & 0xF) < 8) { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = (RSP_Vect[vect].UB[15 - ((Count & 0x7) << 1)] << 1) + - (RSP_Vect[vect].UB[14 - ((Count & 0x7) << 1)] >> 7); - } else { - *(DMEM + ((Addr ^ 3) & 0xFFF)) = RSP_Vect[vect].UB[15 - ((Count & 0x7) << 1)]; - } - Addr += 1; - } -} - -void RSP_SW_DMEM ( uint32_t Addr, uint32_t Value ) { - Addr &= 0xFFF; - - if ((Addr & 0x3) != 0) { - if (Addr > 0xFFC) { - printf("hmmmm.... Problem with:\nRSP_SW_DMEM"); - return; - } - *(uint8_t *)(DMEM + (Addr ^ 3)) = (uint8_t)(Value >> 0x18); - *(uint8_t *)(DMEM + ((Addr + 1) ^ 3)) = (uint8_t)(Value >> 0x10); - *(uint8_t *)(DMEM + ((Addr + 2) ^ 3)) = (uint8_t)(Value >> 0x8); - *(uint8_t *)(DMEM + ((Addr + 3) ^ 3)) = (uint8_t)(Value); - return; - } - *(uint32_t *)(DMEM + Addr) = Value; -} - -void RSP_SWV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ) { - int32_t Count, offset; - - offset = Addr & 0xF; - Addr &= 0xFF0; - for (Count = element; Count < (16 + element); Count ++ ){ - *(DMEM + ((Addr + (offset & 0xF)) ^ 3)) = RSP_Vect[vect].B[15 - (Count & 0xF)]; - offset += 1; - } -} - -int runcount = 0; - -int32_t init_rsp(void) -{ - - - int32_t i = 0, CpuFeatures = 0; - runcount++; - - RSP_Running = 0; - - - NoOfMaps = 0; - Table = 0; - ConditionalMove = 0; - - - RSP_NextInstruction = 0; - RSP_JumpTo = 0; - - dwBuffer = MainBuffer; - - pLastSecondary == NULL; - pLastPrimary = NULL; - RSPBlockID = 1; - - memset(RSP_GPR,0,sizeof(RSP_GPR)); - memset(RSP_Vect,0,sizeof(RSP_Vect)); - memset(RSP_ACCUM,0,sizeof(RSP_ACCUM)); - memset(RSP_Flags,0,sizeof(RSP_Flags)); - - for(i = 0; i < 64; i++) { - RSP_Opcode[i]= rsp_UnknownOpcode; - RSP_RegImm[i>>1]= rsp_UnknownOpcode; - RSP_Special[i]= rsp_UnknownOpcode; - RSP_Cop0[i>>1]= rsp_UnknownOpcode; - RSP_Cop2[i>>1]= rsp_UnknownOpcode; - RSP_Vector[i] = rsp_UnknownOpcode; - RSP_Lc2[i>>1] = rsp_UnknownOpcode; - RSP_Sc2[i>>1] = rsp_UnknownOpcode; - } - - - RSP_Opcode[ 0] = RSP_Opcode_SPECIAL; - RSP_Opcode[ 1] = RSP_Opcode_REGIMM; - RSP_Opcode[ 2] = RSP_Opcode_J; - RSP_Opcode[ 3] = RSP_Opcode_JAL; - RSP_Opcode[ 4] = RSP_Opcode_BEQ; - RSP_Opcode[ 5] = RSP_Opcode_BNE; - RSP_Opcode[ 6] = RSP_Opcode_BLEZ; - RSP_Opcode[ 7] = RSP_Opcode_BGTZ; - RSP_Opcode[ 8] = RSP_Opcode_ADDI; - RSP_Opcode[ 9] = RSP_Opcode_ADDIU; - RSP_Opcode[10] = RSP_Opcode_SLTI; - RSP_Opcode[11] = RSP_Opcode_SLTIU; - RSP_Opcode[12] = RSP_Opcode_ANDI; - RSP_Opcode[13] = RSP_Opcode_ORI; - RSP_Opcode[14] = RSP_Opcode_XORI; - RSP_Opcode[15] = RSP_Opcode_LUI; - RSP_Opcode[16] = RSP_Opcode_COP0; - RSP_Opcode[18] = RSP_Opcode_COP2; - RSP_Opcode[32] = RSP_Opcode_LB; - RSP_Opcode[33] = RSP_Opcode_LH; - RSP_Opcode[35] = RSP_Opcode_LW; - RSP_Opcode[36] = RSP_Opcode_LBU; - RSP_Opcode[37] = RSP_Opcode_LHU; - RSP_Opcode[40] = RSP_Opcode_SB; - RSP_Opcode[41] = RSP_Opcode_SH; - RSP_Opcode[43] = RSP_Opcode_SW; - RSP_Opcode[50] = RSP_Opcode_LC2; - RSP_Opcode[58] = RSP_Opcode_SC2; - - RSP_Special[ 0] = RSP_Special_SLL; - RSP_Special[ 2] = RSP_Special_SRL; - RSP_Special[ 3] = RSP_Special_SRA; - RSP_Special[ 4] = RSP_Special_SLLV; - RSP_Special[ 6] = RSP_Special_SRLV; - RSP_Special[ 7] = RSP_Special_SRAV; - RSP_Special[ 8] = RSP_Special_JR; - RSP_Special[ 9] = RSP_Special_JALR; - RSP_Special[13] = RSP_Special_BREAK; - RSP_Special[32] = RSP_Special_ADD; - RSP_Special[33] = RSP_Special_ADDU; - RSP_Special[34] = RSP_Special_SUB; - RSP_Special[35] = RSP_Special_SUBU; - RSP_Special[36] = RSP_Special_AND; - RSP_Special[37] = RSP_Special_OR; - RSP_Special[38] = RSP_Special_XOR; - RSP_Special[39] = RSP_Special_NOR; - RSP_Special[42] = RSP_Special_SLT; - RSP_Special[43] = RSP_Special_SLTU; - - RSP_RegImm[ 0] = RSP_Opcode_BLTZ; - RSP_RegImm[ 1] = RSP_Opcode_BGEZ; - RSP_RegImm[16] = RSP_Opcode_BLTZAL; - - RSP_Cop0[ 0] = RSP_Cop0_MF; - RSP_Cop0[ 4] = RSP_Cop0_MT; - - RSP_Cop2[ 0] = RSP_Cop2_MF; - RSP_Cop2[ 2] = RSP_Cop2_CF; - RSP_Cop2[ 4] = RSP_Cop2_MT; - RSP_Cop2[ 6] = RSP_Cop2_CT; - RSP_Cop2[16] = RSP_COP2_VECTOR; - RSP_Cop2[17] = RSP_COP2_VECTOR; - RSP_Cop2[18] = RSP_COP2_VECTOR; - RSP_Cop2[19] = RSP_COP2_VECTOR; - RSP_Cop2[20] = RSP_COP2_VECTOR; - RSP_Cop2[21] = RSP_COP2_VECTOR; - RSP_Cop2[22] = RSP_COP2_VECTOR; - RSP_Cop2[23] = RSP_COP2_VECTOR; - RSP_Cop2[24] = RSP_COP2_VECTOR; - RSP_Cop2[25] = RSP_COP2_VECTOR; - RSP_Cop2[26] = RSP_COP2_VECTOR; - RSP_Cop2[27] = RSP_COP2_VECTOR; - RSP_Cop2[28] = RSP_COP2_VECTOR; - RSP_Cop2[29] = RSP_COP2_VECTOR; - RSP_Cop2[30] = RSP_COP2_VECTOR; - RSP_Cop2[31] = RSP_COP2_VECTOR; - - RSP_Vector[ 0] = RSP_Vector_VMULF; - RSP_Vector[ 1] = RSP_Vector_VMULU; - RSP_Vector[ 4] = RSP_Vector_VMUDL; - RSP_Vector[ 5] = RSP_Vector_VMUDM; - RSP_Vector[ 6] = RSP_Vector_VMUDN; - RSP_Vector[ 7] = RSP_Vector_VMUDH; - RSP_Vector[ 8] = RSP_Vector_VMACF; - RSP_Vector[ 9] = RSP_Vector_VMACU; - RSP_Vector[11] = RSP_Vector_VMACQ; - RSP_Vector[12] = RSP_Vector_VMADL; - RSP_Vector[13] = RSP_Vector_VMADM; - RSP_Vector[14] = RSP_Vector_VMADN; - RSP_Vector[15] = RSP_Vector_VMADH; - RSP_Vector[16] = RSP_Vector_VADD; - RSP_Vector[17] = RSP_Vector_VSUB; - RSP_Vector[19] = RSP_Vector_VABS; - RSP_Vector[20] = RSP_Vector_VADDC; - RSP_Vector[21] = RSP_Vector_VSUBC; - RSP_Vector[29] = RSP_Vector_VSAW; - RSP_Vector[32] = RSP_Vector_VLT; - RSP_Vector[33] = RSP_Vector_VEQ; - RSP_Vector[34] = RSP_Vector_VNE; - RSP_Vector[35] = RSP_Vector_VGE; - RSP_Vector[36] = RSP_Vector_VCL; - RSP_Vector[37] = RSP_Vector_VCH; - RSP_Vector[38] = RSP_Vector_VCR; - RSP_Vector[39] = RSP_Vector_VMRG; - RSP_Vector[40] = RSP_Vector_VAND; - RSP_Vector[41] = RSP_Vector_VNAND; - RSP_Vector[42] = RSP_Vector_VOR; - RSP_Vector[43] = RSP_Vector_VNOR; - RSP_Vector[44] = RSP_Vector_VXOR; - RSP_Vector[45] = RSP_Vector_VNXOR; - RSP_Vector[48] = RSP_Vector_VRCP; - RSP_Vector[49] = RSP_Vector_VRCPL; - RSP_Vector[50] = RSP_Vector_VRCPH; - RSP_Vector[51] = RSP_Vector_VMOV; - RSP_Vector[52] = RSP_Vector_VRSQ; - RSP_Vector[53] = RSP_Vector_VRSQL; - RSP_Vector[54] = RSP_Vector_VRSQH; - RSP_Vector[55] = RSP_Vector_VNOOP; - - RSP_Lc2[ 0] = RSP_Opcode_LBV; - RSP_Lc2[ 1] = RSP_Opcode_LSV; - RSP_Lc2[ 2] = RSP_Opcode_LLV; - RSP_Lc2[ 3] = RSP_Opcode_LDV; - RSP_Lc2[ 4] = RSP_Opcode_LQV; - RSP_Lc2[ 5] = RSP_Opcode_LRV; - RSP_Lc2[ 6] = RSP_Opcode_LPV; - RSP_Lc2[ 7] = RSP_Opcode_LUV; - RSP_Lc2[ 8] = RSP_Opcode_LHV; - RSP_Lc2[ 9] = RSP_Opcode_LFV; - RSP_Lc2[11] = RSP_Opcode_LTV; - - RSP_Sc2[ 0] = RSP_Opcode_SBV; - RSP_Sc2[ 1] = RSP_Opcode_SSV; - RSP_Sc2[ 2] = RSP_Opcode_SLV; - RSP_Sc2[ 3] = RSP_Opcode_SDV; - RSP_Sc2[ 4] = RSP_Opcode_SQV; - RSP_Sc2[ 5] = RSP_Opcode_SRV; - RSP_Sc2[ 6] = RSP_Opcode_SPV; - RSP_Sc2[ 7] = RSP_Opcode_SUV; - RSP_Sc2[ 8] = RSP_Opcode_SHV; - RSP_Sc2[ 9] = RSP_Opcode_SFV; - RSP_Sc2[10] = RSP_Opcode_SWV; - RSP_Sc2[11] = RSP_Opcode_STV; - - EleSpec[ 0].DW = 0; - EleSpec[ 1].DW = 0; - EleSpec[ 2].DW = 0; - EleSpec[ 3].DW = 0; - EleSpec[ 4].DW = 0; - EleSpec[ 5].DW = 0; - EleSpec[ 6].DW = 0; - EleSpec[ 7].DW = 0; - EleSpec[ 8].DW = 0; - EleSpec[ 9].DW = 0; - EleSpec[10].DW = 0; - EleSpec[11].DW = 0; - EleSpec[12].DW = 0; - EleSpec[13].DW = 0; - EleSpec[14].DW = 0; - EleSpec[15].DW = 0; - EleSpec[16].DW = 0x0001020304050607ULL; /* None */ - EleSpec[17].DW = 0x0001020304050607ULL; /* None */ - EleSpec[18].DW = 0x0000020204040606ULL; /* 0q */ - EleSpec[19].DW = 0x0101030305050707ULL; /* 1q */ - EleSpec[20].DW = 0x0000000004040404ULL; /* 0h */ - EleSpec[21].DW = 0x0101010105050505ULL; /* 1h */ - EleSpec[22].DW = 0x0202020206060606ULL; /* 2h */ - EleSpec[23].DW = 0x0303030307070707ULL; /* 3h */ - EleSpec[24].DW = 0x0000000000000000ULL; /* 0 */ - EleSpec[25].DW = 0x0101010101010101ULL; /* 1 */ - EleSpec[26].DW = 0x0202020202020202ULL; /* 2 */ - EleSpec[27].DW = 0x0303030303030303ULL; /* 3 */ - EleSpec[28].DW = 0x0404040404040404ULL; /* 4 */ - EleSpec[29].DW = 0x0505050505050505ULL; /* 5 */ - EleSpec[30].DW = 0x0606060606060606ULL; /* 6 */ - EleSpec[31].DW = 0x0707070707070707ULL; /* 7 */ - - Indx[ 0].DW = 0; - Indx[ 1].DW = 0; - Indx[ 2].DW = 0; - Indx[ 3].DW = 0; - Indx[ 4].DW = 0; - Indx[ 5].DW = 0; - Indx[ 6].DW = 0; - Indx[ 7].DW = 0; - Indx[ 8].DW = 0; - Indx[ 9].DW = 0; - Indx[10].DW = 0; - Indx[11].DW = 0; - Indx[12].DW = 0; - Indx[13].DW = 0; - Indx[14].DW = 0; - Indx[15].DW = 0; - - Indx[16].DW = 0x0001020304050607ULL; /* None */ - Indx[17].DW = 0x0001020304050607ULL; /* None */ - Indx[18].DW = 0x0103050700020406ULL; /* 0q */ - Indx[19].DW = 0x0002040601030507ULL; /* 1q */ - Indx[20].DW = 0x0102030506070004ULL; /* 0h */ - Indx[21].DW = 0x0002030406070105ULL; /* 1h */ - Indx[22].DW = 0x0001030405070206ULL; /* 2h */ - Indx[23].DW = 0x0001020405060307ULL; /* 3h */ - Indx[24].DW = 0x0102030405060700ULL; /* 0 */ - Indx[25].DW = 0x0002030405060701ULL; /* 1 */ - Indx[26].DW = 0x0001030405060702ULL; /* 2 */ - Indx[27].DW = 0x0001020405060703ULL; /* 3 */ - Indx[28].DW = 0x0001020305060704ULL; /* 4 */ - Indx[29].DW = 0x0001020304060705ULL; /* 5 */ - Indx[30].DW = 0x0001020304050706ULL; /* 6 */ - Indx[31].DW = 0x0001020304050607ULL; /* 7 */ - - for (i = 16; i < 32; i ++) { - int32_t count; - - for (count = 0; count < 8; count ++) { - Indx[i].B[count] = 7 - Indx[i].B[count]; - EleSpec[i].B[count] = 7 - EleSpec[i].B[count]; - } - for (count = 0; count < 4; count ++) { - uint8_t Temp; - - Temp = Indx[i].B[count]; - Indx[i].B[count] = Indx[i].B[7 - count]; - Indx[i].B[7 - count] = Temp; - } - } - - PrgCount = &SP_PC_REG; - - memset(&Compiler, 0, sizeof(Compiler)); - - Compiler.bAlignGPR = 1; - Compiler.bAlignVector = 1; - Compiler.bFlags = 1; - Compiler.bReOrdering = 1; - Compiler.bSections = 0; //do i really need to do this? - Compiler.bDest = 1; - Compiler.bAccum = 1; - Compiler.bGPRConstants = 1; - - if(!fake_seek_stopping) { - RSPAllocateMemory(); - } else { - RSPReInitMemory(); - } - - memset(RSP_GPR,0,sizeof(RSP_GPR)); - memset(RSP_Vect,0,sizeof(RSP_Vect)); - -#ifndef USEX64 - asm volatile("push %%ebx; mov $1, %%eax; cpuid; pop %%ebx" : : "a"(CpuFeatures) : "edx","ecx"); -#else - asm volatile("push %%rbx; mov $1, %%eax; cpuid; pop %%rbx" : : "a"(CpuFeatures) : "rdx","rcx"); -#endif - - - Compiler.mmx2 = CpuFeatures & 0x4000000; - Compiler.sse = CpuFeatures & 0x2000000; - Compiler.mmx = CpuFeatures & 0x800000; - - if(!RSP_Cpu) - BuildRecompilerCPU(); - - ClearAllx86Code(); - -} - -void RSPSetJumpTable (void) { - uint32_t CRC, count; - - CRC = 0; - for (count = 0; count < 0x800; count += 0x40) { - CRC += *(uint32_t *)(IMEM + count); - } - - for (count = 0; count < NoOfMaps; count++ ) { - if (CRC == MapsCRC[count]) { - RSPJumpTable = (void **)(RSPJumpTables + (count * (sizeof(void*) * 0x400))); - Table = count; - return; - } - } - - if (NoOfMaps == MaxMaps) { - DisplayError("Used up all the Jump tables in the rsp"); - StopEmulation(); - } - - MapsCRC[NoOfMaps] = CRC; - - RSPJumpTable = (void **)(RSPJumpTables + (NoOfMaps * (sizeof(void*) * 0x400) )); - Table = NoOfMaps; - NoOfMaps += 1; -} diff --git a/src/usf/rsp.h b/src/usf/rsp.h deleted file mode 100644 index 2921dea..0000000 --- a/src/usf/rsp.h +++ /dev/null @@ -1,423 +0,0 @@ -#ifndef _RSP_H_ -#define _RSP_H_ - -#include -#include -#include -#include "types.h" - -#define CPU_Message(...) -//#define DisplayError printf - -#pragma pack(push,1) - -typedef struct tagOPCODE { - union { - - uint32_t Hex; - uint8_t Ascii[4]; - - struct { - unsigned offset : 16; - unsigned rt : 5; - unsigned rs : 5; - unsigned op : 6; - }; - - struct { - unsigned immediate : 16; - unsigned : 5; - unsigned base : 5; - unsigned : 6; - }; - - struct { - unsigned target : 26; - unsigned : 6; - }; - - struct { - unsigned funct : 6; - unsigned sa : 5; - unsigned rd : 5; - unsigned : 5; - unsigned : 5; - unsigned : 6; - }; - - struct { - signed voffset : 7; - unsigned del : 4; - unsigned : 5; - unsigned dest : 5; - unsigned : 5; - unsigned : 6; - }; - - }; -} RSPOPCODE; - -#pragma pack(pop) - -#define REGISTER32 MIPS_WORD -#define REGISTER MIPS_DWORD - - -//RSP OpCodes -#define RSP_SPECIAL 0 -#define RSP_REGIMM 1 -#define RSP_J 2 -#define RSP_JAL 3 -#define RSP_BEQ 4 -#define RSP_BNE 5 -#define RSP_BLEZ 6 -#define RSP_BGTZ 7 -#define RSP_ADDI 8 -#define RSP_ADDIU 9 -#define RSP_SLTI 10 -#define RSP_SLTIU 11 -#define RSP_ANDI 12 -#define RSP_ORI 13 -#define RSP_XORI 14 -#define RSP_LUI 15 -#define RSP_CP0 16 -#define RSP_CP2 18 -#define RSP_LB 32 -#define RSP_LH 33 -#define RSP_LW 35 -#define RSP_LBU 36 -#define RSP_LHU 37 -#define RSP_SB 40 -#define RSP_SH 41 -#define RSP_SW 43 -#define RSP_LC2 50 -#define RSP_SC2 58 - -/* RSP Special opcodes */ -#define RSP_SPECIAL_SLL 0 -#define RSP_SPECIAL_SRL 2 -#define RSP_SPECIAL_SRA 3 -#define RSP_SPECIAL_SLLV 4 -#define RSP_SPECIAL_SRLV 6 -#define RSP_SPECIAL_SRAV 7 -#define RSP_SPECIAL_JR 8 -#define RSP_SPECIAL_JALR 9 -#define RSP_SPECIAL_BREAK 13 -#define RSP_SPECIAL_ADD 32 -#define RSP_SPECIAL_ADDU 33 -#define RSP_SPECIAL_SUB 34 -#define RSP_SPECIAL_SUBU 35 -#define RSP_SPECIAL_AND 36 -#define RSP_SPECIAL_OR 37 -#define RSP_SPECIAL_XOR 38 -#define RSP_SPECIAL_NOR 39 -#define RSP_SPECIAL_SLT 42 -#define RSP_SPECIAL_SLTU 43 - -/* RSP RegImm opcodes */ -#define RSP_REGIMM_BLTZ 0 -#define RSP_REGIMM_BGEZ 1 -#define RSP_REGIMM_BLTZAL 16 -#define RSP_REGIMM_BGEZAL 17 - -/* RSP COP0 opcodes */ -#define RSP_COP0_MF 0 -#define RSP_COP0_MT 4 - -/* RSP COP2 opcodes */ -#define RSP_COP2_MF 0 -#define RSP_COP2_CF 2 -#define RSP_COP2_MT 4 -#define RSP_COP2_CT 6 - -/* RSP Vector opcodes */ -#define RSP_VECTOR_VMULF 0 -#define RSP_VECTOR_VMULU 1 -#define RSP_VECTOR_VRNDP 2 -#define RSP_VECTOR_VMULQ 3 -#define RSP_VECTOR_VMUDL 4 -#define RSP_VECTOR_VMUDM 5 -#define RSP_VECTOR_VMUDN 6 -#define RSP_VECTOR_VMUDH 7 -#define RSP_VECTOR_VMACF 8 -#define RSP_VECTOR_VMACU 9 -#define RSP_VECTOR_VRNDN 10 -#define RSP_VECTOR_VMACQ 11 -#define RSP_VECTOR_VMADL 12 -#define RSP_VECTOR_VMADM 13 -#define RSP_VECTOR_VMADN 14 -#define RSP_VECTOR_VMADH 15 -#define RSP_VECTOR_VADD 16 -#define RSP_VECTOR_VSUB 17 -#define RSP_VECTOR_VABS 19 -#define RSP_VECTOR_VADDC 20 -#define RSP_VECTOR_VSUBC 21 -#define RSP_VECTOR_VSAW 29 -#define RSP_VECTOR_VLT 32 -#define RSP_VECTOR_VEQ 33 -#define RSP_VECTOR_VNE 34 -#define RSP_VECTOR_VGE 35 -#define RSP_VECTOR_VCL 36 -#define RSP_VECTOR_VCH 37 -#define RSP_VECTOR_VCR 38 -#define RSP_VECTOR_VMRG 39 -#define RSP_VECTOR_VAND 40 -#define RSP_VECTOR_VNAND 41 -#define RSP_VECTOR_VOR 42 -#define RSP_VECTOR_VNOR 43 -#define RSP_VECTOR_VXOR 44 -#define RSP_VECTOR_VNXOR 45 -#define RSP_VECTOR_VRCP 48 -#define RSP_VECTOR_VRCPL 49 -#define RSP_VECTOR_VRCPH 50 -#define RSP_VECTOR_VMOV 51 -#define RSP_VECTOR_VRSQ 52 -#define RSP_VECTOR_VRSQL 53 -#define RSP_VECTOR_VRSQH 54 -#define RSP_VECTOR_VNOOP 55 - -/* RSP LSC2 opcodes */ -#define RSP_LSC2_BV 0 -#define RSP_LSC2_SV 1 -#define RSP_LSC2_LV 2 -#define RSP_LSC2_DV 3 -#define RSP_LSC2_QV 4 -#define RSP_LSC2_RV 5 -#define RSP_LSC2_PV 6 -#define RSP_LSC2_UV 7 -#define RSP_LSC2_HV 8 -#define RSP_LSC2_FV 9 -#define RSP_LSC2_WV 10 -#define RSP_LSC2_TV 11 - - -/************************* OpCode functions *************************/ -void RSP_Opcode_SPECIAL ( void ); -void RSP_Opcode_REGIMM ( void ); -void RSP_Opcode_J ( void ); -void RSP_Opcode_JAL ( void ); -void RSP_Opcode_BEQ ( void ); -void RSP_Opcode_BNE ( void ); -void RSP_Opcode_BLEZ ( void ); -void RSP_Opcode_BGTZ ( void ); -void RSP_Opcode_ADDI ( void ); -void RSP_Opcode_ADDIU ( void ); -void RSP_Opcode_SLTI ( void ); -void RSP_Opcode_SLTIU ( void ); -void RSP_Opcode_ANDI ( void ); -void RSP_Opcode_ORI ( void ); -void RSP_Opcode_XORI ( void ); -void RSP_Opcode_LUI ( void ); -void RSP_Opcode_COP0 ( void ); -void RSP_Opcode_COP2 ( void ); -void RSP_Opcode_LB ( void ); -void RSP_Opcode_LH ( void ); -void RSP_Opcode_LW ( void ); -void RSP_Opcode_LBU ( void ); -void RSP_Opcode_LHU ( void ); -void RSP_Opcode_SB ( void ); -void RSP_Opcode_SH ( void ); -void RSP_Opcode_SW ( void ); -void RSP_Opcode_LC2 ( void ); -void RSP_Opcode_SC2 ( void ); -/********************** R4300i OpCodes: Special **********************/ -void RSP_Special_SLL ( void ); -void RSP_Special_SRL ( void ); -void RSP_Special_SRA ( void ); -void RSP_Special_SLLV ( void ); -void RSP_Special_SRLV ( void ); -void RSP_Special_SRAV ( void ); -void RSP_Special_JR ( void ); -void RSP_Special_JALR ( void ); -void RSP_Special_BREAK ( void ); -void RSP_Special_ADD ( void ); -void RSP_Special_ADDU ( void ); -void RSP_Special_SUB ( void ); -void RSP_Special_SUBU ( void ); -void RSP_Special_AND ( void ); -void RSP_Special_OR ( void ); -void RSP_Special_XOR ( void ); -void RSP_Special_NOR ( void ); -void RSP_Special_SLT ( void ); -void RSP_Special_SLTU ( void ); -/********************** R4300i OpCodes: RegImm **********************/ -void RSP_Opcode_BLTZ ( void ); -void RSP_Opcode_BGEZ ( void ); -void RSP_Opcode_BLTZAL ( void ); -void RSP_Opcode_BGEZAL ( void ); -/************************** Cop0 functions *************************/ -void RSP_Cop0_MF ( void ); -void RSP_Cop0_MT ( void ); -/************************** Cop2 functions *************************/ -void RSP_Cop2_MF ( void ); -void RSP_Cop2_CF ( void ); -void RSP_Cop2_MT ( void ); -void RSP_Cop2_CT ( void ); -void RSP_COP2_VECTOR ( void ); -/************************** Vect functions **************************/ -void RSP_Vector_VMULF ( void ); -void RSP_Vector_VMULU ( void ); -void RSP_Vector_VMUDL ( void ); -void RSP_Vector_VMUDM ( void ); -void RSP_Vector_VMUDN ( void ); -void RSP_Vector_VMUDH ( void ); -void RSP_Vector_VMACF ( void ); -void RSP_Vector_VMACU ( void ); -void RSP_Vector_VMACQ ( void ); -void RSP_Vector_VMADL ( void ); -void RSP_Vector_VMADM ( void ); -void RSP_Vector_VMADN ( void ); -void RSP_Vector_VMADH ( void ); -void RSP_Vector_VADD ( void ); -void RSP_Vector_VSUB ( void ); -void RSP_Vector_VABS ( void ); -void RSP_Vector_VADDC ( void ); -void RSP_Vector_VSUBC ( void ); -void RSP_Vector_VSAW ( void ); -void RSP_Vector_VLT ( void ); -void RSP_Vector_VEQ ( void ); -void RSP_Vector_VNE ( void ); -void RSP_Vector_VGE ( void ); -void RSP_Vector_VCL ( void ); -void RSP_Vector_VCH ( void ); -void RSP_Vector_VCR ( void ); -void RSP_Vector_VMRG ( void ); -void RSP_Vector_VAND ( void ); -void RSP_Vector_VNAND ( void ); -void RSP_Vector_VOR ( void ); -void RSP_Vector_VNOR ( void ); -void RSP_Vector_VXOR ( void ); -void RSP_Vector_VNXOR ( void ); -void RSP_Vector_VRCP ( void ); -void RSP_Vector_VRCPL ( void ); -void RSP_Vector_VRCPH ( void ); -void RSP_Vector_VMOV ( void ); -void RSP_Vector_VRSQ ( void ); -void RSP_Vector_VRSQL ( void ); -void RSP_Vector_VRSQH ( void ); -void RSP_Vector_VNOOP ( void ); -/************************** lc2 functions **************************/ -void RSP_Opcode_LBV ( void ); -void RSP_Opcode_LSV ( void ); -void RSP_Opcode_LLV ( void ); -void RSP_Opcode_LDV ( void ); -void RSP_Opcode_LQV ( void ); -void RSP_Opcode_LRV ( void ); -void RSP_Opcode_LPV ( void ); -void RSP_Opcode_LUV ( void ); -void RSP_Opcode_LHV ( void ); -void RSP_Opcode_LFV ( void ); -void RSP_Opcode_LTV ( void ); -/************************** lc2 functions **************************/ -void RSP_Opcode_SBV ( void ); -void RSP_Opcode_SSV ( void ); -void RSP_Opcode_SLV ( void ); -void RSP_Opcode_SDV ( void ); -void RSP_Opcode_SQV ( void ); -void RSP_Opcode_SRV ( void ); -void RSP_Opcode_SPV ( void ); -void RSP_Opcode_SUV ( void ); -void RSP_Opcode_SHV ( void ); -void RSP_Opcode_SFV ( void ); -void RSP_Opcode_STV ( void ); -void RSP_Opcode_SWV ( void ); -/************************** Other functions **************************/ -void rsp_UnknownOpcode ( void ); -void RSPSetJumpTable ( void ); - -extern void (*RSP_Opcode[64])(); -extern void (*RSP_RegImm[32])(); -extern void (*RSP_Special[64])(); -extern void (*RSP_Cop0[32])(); -extern void (*RSP_Cop2[32])(); -extern void (*RSP_Vector[64])(); -extern void (*RSP_Lc2[32])(); -extern void (*RSP_Sc2[32])(); - -void RSP_SP_DMA_READ (void); -void RSP_SP_DMA_WRITE(void); - -/******************* Function prototypes are hard ********************/ -void RSP_LB_DMEM ( uint32_t Addr, uint8_t * Value ); -void RSP_LH_DMEM ( uint32_t Addr, uint16_t * Value ); -void RSP_LW_DMEM ( uint32_t Addr, uint32_t * Value ); -void RSP_LW_IMEM ( uint32_t Addr, uint32_t * Value ); -void RSP_SB_DMEM ( uint32_t Addr, uint8_t Value ); -void RSP_SH_DMEM ( uint32_t Addr, uint16_t Value ); -void RSP_SW_DMEM ( uint32_t Addr, uint32_t Value ); -void RSP_LBV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LSV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LLV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SFV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_STV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SWV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LDV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LQV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LRV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LBV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LDV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LFV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LHV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LLV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LPV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LRV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LQV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LSV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LTV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_LUV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SBV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SDV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SFV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SHV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SLV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SPV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SQV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SRV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SSV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_STV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SUV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); -void RSP_SWV_DMEM ( uint32_t Addr, int32_t vect, int32_t element ); - -extern REGISTER32 *RSP_GPR, RSP_Flags[4]; -extern REGISTER *RSP_ACCUM; -extern VECTOR *RSP_Vect; - -extern REGISTER EleSpec[32], Indx[32]; -extern RSPOPCODE RSPOpC; -extern uint32_t *PrgCount, RSPNextInstruction; -extern uint32_t RSP_NextInstruction; -extern REGISTER32 Recp, RecpResult, SQroot, SQrootResult; - -extern uint32_t RSP_NextInstruction, RSP_JumpTo; - - -extern uint32_t RSP_Running; - - -//extern uint8_t * RSPRecompPos, * RSPRecompCode, * RSPRecompCodeSecondary; -//extern uint8_t * RSPJumpTable; -#define MaxMaps 32 - -extern uint32_t NoOfMaps, MapsCRC[MaxMaps], Table, ConditionalMove; -extern uint8_t * RSPRecompCode, * RSPRecompCodeSecondary, * RSPRecompPos, *RSPJumpTables; -extern void ** RSPJumpTable; - - -#define NORMAL 0 -#define DO_DELAY_SLOT 1 -#define DO_END_DELAY_SLOT 2 -#define DELAY_SLOT 3 -#define END_DELAY_SLOT 4 -#define LIKELY_DELAY_SLOT 5 -#define JUMP 6 -#define DELAY_SLOT_DONE 7 -#define LIKELY_DELAY_SLOT_DONE 8 -#define END_BLOCK 9 -#define FINISH_BLOCK 10 // from RSP Recompiler CPU -#define FINISH_SUB_BLOCK 11 // from RSP Recompiler CPU - -void real_run_rsp(uint32_t cycles); -int32_t init_rsp(void); - - -#endif diff --git a/src/usf/rsp_interpreter_cpu.c b/src/usf/rsp_interpreter_cpu.c deleted file mode 100644 index 2fba36a..0000000 --- a/src/usf/rsp_interpreter_cpu.c +++ /dev/null @@ -1,1706 +0,0 @@ -#include -#include -#include "usf.h" -#include "cpu.h" -#include "memory.h" -#include "audio.h" -#include "rsp.h" - - -void (*RSP_Opcode[64])(); -void (*RSP_RegImm[32])(); -void (*RSP_Special[64])(); -void (*RSP_Cop0[32])(); -void (*RSP_Cop2[32])(); -void (*RSP_Vector[64])(); -void (*RSP_Lc2[32])(); -void (*RSP_Sc2[32])(); - -void RSP_Opcode_SPECIAL ( void ) { - (RSP_Special[ RSPOpC.funct ])(); -} - -void RSP_Opcode_REGIMM ( void ) { - (RSP_RegImm[ RSPOpC.rt ])(); -} - -void RSP_Opcode_J ( void ) { - RSP_NextInstruction = DELAY_SLOT; - RSP_JumpTo = (RSPOpC.target << 2) & 0xFFC; -} - -void RSP_Opcode_JAL ( void ) { - RSP_NextInstruction = DELAY_SLOT; - RSP_GPR[31].UW = ( *PrgCount + 8 ) & 0xFFC; - RSP_JumpTo = (RSPOpC.target << 2) & 0xFFC; -} - -void RSP_Opcode_BEQ ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W == RSP_GPR[RSPOpC.rt].W) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BNE ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W != RSP_GPR[RSPOpC.rt].W) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BLEZ ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W <= 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BGTZ ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W > 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_ADDI ( void ) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rs].W + (int16_t)RSPOpC.immediate; - } -} - -void RSP_Opcode_ADDIU ( void ) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].UW = RSP_GPR[RSPOpC.rs].UW + (uint32_t)((int16_t)RSPOpC.immediate); - } -} - -void RSP_Opcode_SLTI (void) { - if (RSPOpC.rt == 0) { return; } - if (RSP_GPR[RSPOpC.rs].W < (int16_t)RSPOpC.immediate) { - RSP_GPR[RSPOpC.rt].W = 1; - } else { - RSP_GPR[RSPOpC.rt].W = 0; - } -} - -void RSP_Opcode_SLTIU (void) { - if (RSPOpC.rt == 0) { return; } - if (RSP_GPR[RSPOpC.rs].UW < (uint32_t)(int16_t)RSPOpC.immediate) { - RSP_GPR[RSPOpC.rt].W = 1; - } else { - RSP_GPR[RSPOpC.rt].W = 0; - } -} - -void RSP_Opcode_ANDI ( void ) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rs].W & RSPOpC.immediate; - } -} - -void RSP_Opcode_ORI ( void ) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rs].W | RSPOpC.immediate; - } -} - -void RSP_Opcode_XORI ( void ) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rs].W ^ RSPOpC.immediate; - } -} - -void RSP_Opcode_LUI (void) { - if (RSPOpC.rt != 0) { - RSP_GPR[RSPOpC.rt].W = (int16_t)RSPOpC.offset << 16; - } -} - -void RSP_Opcode_COP0 (void) { - (RSP_Cop0[ RSPOpC.rs ])(); -} - -void RSP_Opcode_COP2 (void) { - (RSP_Cop2[ RSPOpC.rs ])(); -} - -void RSP_Opcode_LB ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_LB_DMEM( Address, &RSP_GPR[RSPOpC.rt].UB[0] ); - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rt].B[0]; -} - -void RSP_Opcode_LH ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_LH_DMEM( Address, &RSP_GPR[RSPOpC.rt].UHW[0] ); - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rt].HW[0]; -} - -void RSP_Opcode_LW ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_LW_DMEM( Address, &RSP_GPR[RSPOpC.rt].UW ); -} - -void RSP_Opcode_LBU ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_LB_DMEM( Address, &RSP_GPR[RSPOpC.rt].UB[0] ); - RSP_GPR[RSPOpC.rt].UW = RSP_GPR[RSPOpC.rt].UB[0]; -} - -void RSP_Opcode_LHU ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_LH_DMEM( Address, &RSP_GPR[RSPOpC.rt].UHW[0] ); - RSP_GPR[RSPOpC.rt].UW = RSP_GPR[RSPOpC.rt].UHW[0]; -} - -void RSP_Opcode_SB ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_SB_DMEM( Address, RSP_GPR[RSPOpC.rt].UB[0] ); -} - -void RSP_Opcode_SH ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - //if(Address == 0x370) { - // printf("%08x\nOpcode: %08x\n%08x\nRA: %08x\n", RSPCompilePC, RSPOpC.Hex, (int16_t)RSPOpC.offset,RSP_GPR[31].UW); - //} - - RSP_SH_DMEM( Address, RSP_GPR[RSPOpC.rt].UHW[0] ); -} - -void RSP_Opcode_SW ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (int16_t)RSPOpC.offset) & 0xFFF); - RSP_SW_DMEM( Address, RSP_GPR[RSPOpC.rt].UW ); -} - -void RSP_Opcode_LC2 (void) { - (RSP_Lc2 [ RSPOpC.rd ])(); -} - -void RSP_Opcode_SC2 (void) { - (RSP_Sc2 [ RSPOpC.rd ])(); -} -/********************** R4300i OpCodes: Special **********************/ -void RSP_Special_SLL ( void ) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rt].W << RSPOpC.sa; - } -} - -void RSP_Special_SRL ( void ) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rt].UW >> RSPOpC.sa; - } -} - -void RSP_Special_SRA ( void ) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rt].W >> RSPOpC.sa; - } -} - -void RSP_Special_SLLV (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rt].W << (RSP_GPR[RSPOpC.rs].W & 0x1F); - } -} - -void RSP_Special_SRLV (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rt].UW >> (RSP_GPR[RSPOpC.rs].W & 0x1F); - } -} - -void RSP_Special_SRAV (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rt].W >> (RSP_GPR[RSPOpC.rs].W & 0x1F); - } -} - -void RSP_Special_JR (void) { - RSP_NextInstruction = DELAY_SLOT; - RSP_JumpTo = (RSP_GPR[RSPOpC.rs].W & 0xFFC); -} - -void RSP_Special_JALR (void) { - RSP_NextInstruction = DELAY_SLOT; - RSP_GPR[RSPOpC.rd].W = (*PrgCount + 8) & 0xFFC; - RSP_JumpTo = (RSP_GPR[RSPOpC.rs].W & 0xFFC); -} - -#define R4300i_SP_Intr 0x1 - -void RSP_Special_BREAK ( void ) { - RSP_Running = 0; - SP_STATUS_REG |= (SP_STATUS_HALT | SP_STATUS_BROKE ); - if ((SP_STATUS_REG & SP_STATUS_INTR_BREAK) != 0 ) { - MI_INTR_REG |= R4300i_SP_Intr; - CheckInterrupts(); - } -} - -void RSP_Special_ADD (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rs].W + RSP_GPR[RSPOpC.rt].W; - } -} - -void RSP_Special_ADDU (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rs].UW + RSP_GPR[RSPOpC.rt].UW; - } -} - -void RSP_Special_SUB (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].W = RSP_GPR[RSPOpC.rs].W - RSP_GPR[RSPOpC.rt].W; - } -} - -void RSP_Special_SUBU (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rs].UW - RSP_GPR[RSPOpC.rt].UW; - } -} - -void RSP_Special_AND (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rs].UW & RSP_GPR[RSPOpC.rt].UW; - } -} - -void RSP_Special_OR (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rs].UW | RSP_GPR[RSPOpC.rt].UW; - } -} - -void RSP_Special_XOR (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = RSP_GPR[RSPOpC.rs].UW ^ RSP_GPR[RSPOpC.rt].UW; - } -} - -void RSP_Special_NOR (void) { - if (RSPOpC.rd != 0) { - RSP_GPR[RSPOpC.rd].UW = ~(RSP_GPR[RSPOpC.rs].UW | RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSP_Special_SLT (void) { - if (RSPOpC.rd == 0) { return; } - if (RSP_GPR[RSPOpC.rs].W < RSP_GPR[RSPOpC.rt].W) { - RSP_GPR[RSPOpC.rd].UW = 1; - } else { - RSP_GPR[RSPOpC.rd].UW = 0; - } -} - -void RSP_Special_SLTU (void) { - if (RSPOpC.rd == 0) { return; } - if (RSP_GPR[RSPOpC.rs].UW < RSP_GPR[RSPOpC.rt].UW) { - RSP_GPR[RSPOpC.rd].UW = 1; - } else { - RSP_GPR[RSPOpC.rd].UW = 0; - } -} -/********************** R4300i OpCodes: RegImm **********************/ -void RSP_Opcode_BLTZ ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W < 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BGEZ ( void ) { - RSP_NextInstruction = DELAY_SLOT; - if (RSP_GPR[RSPOpC.rs].W >= 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BLTZAL ( void ) { - RSP_NextInstruction = DELAY_SLOT; - RSP_GPR[31].UW = ( *PrgCount + 8 ) & 0xFFC; - if (RSP_GPR[RSPOpC.rs].W < 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} - -void RSP_Opcode_BGEZAL ( void ) { - RSP_NextInstruction = DELAY_SLOT; - RSP_GPR[31].UW = ( *PrgCount + 8 ) & 0xFFC; - if (RSP_GPR[RSPOpC.rs].W >= 0) { - RSP_JumpTo = ( *PrgCount + ((int16_t)RSPOpC.offset << 2) + 4 ) & 0xFFC; - } else { - RSP_JumpTo = ( *PrgCount + 8 ) & 0xFFC; - } -} -/************************** Cop0 functions *************************/ -void RSP_Cop0_MF (void) { - switch (RSPOpC.rd) { - case 4: RSP_GPR[RSPOpC.rt].UW = SP_STATUS_REG; break; - case 5: RSP_GPR[RSPOpC.rt].UW = SP_DMA_FULL_REG; break; - case 6: RSP_GPR[RSPOpC.rt].UW = SP_DMA_BUSY_REG; break; - case 7: - RSP_GPR[RSPOpC.rt].W = 0; - //RSP_GPR[RSPOpC.rt].W = SP_SEMAPHORE_REG; - //SP_SEMAPHORE_REG = 1; - break; - case 8: RSP_GPR[RSPOpC.rt].UW = DPC_START_REG ; break; - case 9: RSP_GPR[RSPOpC.rt].UW = DPC_END_REG ; break; - case 10: RSP_GPR[RSPOpC.rt].UW = DPC_CURRENT_REG; break; - case 11: RSP_GPR[RSPOpC.rt].W = DPC_STATUS_REG; break; - case 12: RSP_GPR[RSPOpC.rt].W = DPC_CLOCK_REG; break; - default: - printf("have not implemented RSP MF cpu->CP0 reg (%d)",RSPOpC.rd); - } -} - -void RSP_Cop0_MT (void) { - switch (RSPOpC.rd) { - case 0: SP_MEM_ADDR_REG = RSP_GPR[RSPOpC.rt].UW; break; - case 1: SP_DRAM_ADDR_REG = RSP_GPR[RSPOpC.rt].UW; break; - case 2: - SP_RD_LEN_REG = RSP_GPR[RSPOpC.rt].UW; - RSP_SP_DMA_READ(); - break; - case 3: - SP_WR_LEN_REG = RSP_GPR[RSPOpC.rt].UW; - RSP_SP_DMA_WRITE(); - break; - case 4: - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_HALT ) != 0) { SP_STATUS_REG &= ~SP_STATUS_HALT; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_HALT ) != 0) { SP_STATUS_REG |= SP_STATUS_HALT; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_BROKE ) != 0) { SP_STATUS_REG &= ~SP_STATUS_BROKE; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_INTR ) != 0) { MI_INTR_REG &= ~R4300i_SP_Intr; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_INTR ) != 0) { printf("SP_SET_INTR"); } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SSTEP ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SSTEP; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SSTEP ) != 0) { SP_STATUS_REG |= SP_STATUS_SSTEP; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_INTR_BREAK ) != 0) { SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_INTR_BREAK ) != 0) { SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG0 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG0; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG0 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG0; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG1 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG1; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG1 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG1; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG2 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG2; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG2 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG2; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG3 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG3; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG3 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG3; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG4 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG4; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG4 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG4; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG5 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG5; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG5 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG5; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG6 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG6; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG6 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG6; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_CLR_SIG7 ) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG7; } - if ( ( RSP_GPR[RSPOpC.rt].W & SP_SET_SIG7 ) != 0) { SP_STATUS_REG |= SP_STATUS_SIG7; } - break; - case 7: SP_SEMAPHORE_REG = 0; break; - case 8: - DPC_START_REG = RSP_GPR[RSPOpC.rt].UW; - DPC_CURRENT_REG = RSP_GPR[RSPOpC.rt].UW; - break; - case 9: - DPC_END_REG = RSP_GPR[RSPOpC.rt].UW; - break; - case 10: DPC_CURRENT_REG = RSP_GPR[RSPOpC.rt].UW; break; - case 11: - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_XBUS_DMEM_DMA ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_SET_XBUS_DMEM_DMA ) != 0) { DPC_STATUS_REG |= DPC_STATUS_XBUS_DMEM_DMA; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_FREEZE ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_FREEZE; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_SET_FREEZE ) != 0) { DPC_STATUS_REG |= DPC_STATUS_FREEZE; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_FLUSH ) != 0) { DPC_STATUS_REG &= ~DPC_STATUS_FLUSH; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_SET_FLUSH ) != 0) { DPC_STATUS_REG |= DPC_STATUS_FLUSH; } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_TMEM_CTR ) != 0) { /* printf("RSP: DPC_STATUS_REG: DPC_CLR_TMEM_CTR"); */ } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_PIPE_CTR ) != 0) { printf("RSP: DPC_STATUS_REG: DPC_CLR_PIPE_CTR"); } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_CMD_CTR ) != 0) { printf("RSP: DPC_STATUS_REG: DPC_CLR_CMD_CTR"); } - if ( ( RSP_GPR[RSPOpC.rt].W & DPC_CLR_CLOCK_CTR ) != 0) { /* printf("RSP: DPC_STATUS_REG: DPC_CLR_CLOCK_CTR"); */ } - break; - default: - printf("have not implemented RSP MT cpu->CP0 reg (%d)",RSPOpC.rd); - } -} - -/************************** Cop2 functions *************************/ -void RSP_Cop2_MF (void) { - int32_t element = (RSPOpC.sa >> 1); - RSP_GPR[RSPOpC.rt].B[1] = RSP_Vect[RSPOpC.rd].B[15 - element]; - RSP_GPR[RSPOpC.rt].B[0] = RSP_Vect[RSPOpC.rd].B[15 - ((element + 1) % 16)]; - RSP_GPR[RSPOpC.rt].W = RSP_GPR[RSPOpC.rt].HW[0]; -} - -void RSP_Cop2_CF (void) { - switch ((RSPOpC.rd & 0x03)) { - case 0: RSP_GPR[RSPOpC.rt].W = RSP_Flags[0].HW[0]; break; - case 1: RSP_GPR[RSPOpC.rt].W = RSP_Flags[1].HW[0]; break; - case 2: RSP_GPR[RSPOpC.rt].W = RSP_Flags[2].HW[0]; break; - case 3: RSP_GPR[RSPOpC.rt].W = RSP_Flags[2].HW[0]; break; - } -} - -void RSP_Cop2_MT (void) { - int32_t element = 15 - (RSPOpC.sa >> 1); - RSP_Vect[RSPOpC.rd].B[element] = RSP_GPR[RSPOpC.rt].B[1]; - if (element != 0) { - RSP_Vect[RSPOpC.rd].B[element - 1] = RSP_GPR[RSPOpC.rt].B[0]; - } -} - -void RSP_Cop2_CT (void) { - switch ((RSPOpC.rd & 0x03)) { - case 0: RSP_Flags[0].HW[0] = RSP_GPR[RSPOpC.rt].HW[0]; break; - case 1: RSP_Flags[1].HW[0] = RSP_GPR[RSPOpC.rt].HW[0]; break; - case 2: RSP_Flags[2].B[0] = RSP_GPR[RSPOpC.rt].B[0]; break; - case 3: RSP_Flags[2].B[0] = RSP_GPR[RSPOpC.rt].B[0]; break; - } -} - -void RSP_COP2_VECTOR (void) { -//((void (*)()) RSP_Vector[ RSPOpC.funct ])(); - (RSP_Vector[ RSPOpC.funct ])(); -} -/************************** Vect functions **************************/ - /* - vmulf $v27, $v31[14] - - Format: VMULF $v, $v, $v[el] - sa rd rt rs - */ -void RSP_Vector_VMULF (void) { - int32_t count, el, del; - REGISTER32 temp; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSP_Vect[RSPOpC.rd].UHW[el] != 0x8000 || RSP_Vect[RSPOpC.rt].UHW[del] != 0x8000) { - temp.W = ((int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)RSP_Vect[RSPOpC.rt].HW[del]) << 1; - temp.UW += 0x8000; - RSP_ACCUM[el].HW[2] = temp.HW[1]; - RSP_ACCUM[el].HW[1] = temp.HW[0]; - if ( RSP_ACCUM[el].HW[2] < 0 ) { - RSP_ACCUM[el].HW[3] = -1; - } else { - RSP_ACCUM[el].HW[3] = 0; - } - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } else { - temp.W = 0x80000000; - RSP_ACCUM[el].UHW[3] = 0; - RSP_ACCUM[el].UHW[2] = 0x8000; - RSP_ACCUM[el].UHW[1] = 0x8000; - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } - } -} - -void RSP_Vector_VMULU (void) { - int32_t count, el, del; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_ACCUM[el].DW = (int64_t)(RSP_Vect[RSPOpC.rd].HW[el] * RSP_Vect[RSPOpC.rt].HW[del]) << 17; - RSP_ACCUM[el].DW += 0x80000000; - if (RSP_ACCUM[el].DW < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else if ((int16_t)(RSP_ACCUM[el].UHW[3] ^ RSP_ACCUM[el].UHW[2]) < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = -1; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } -} - -/* - vmudl $v23, $v30, $v24[10] - rs=10, rt=24, rd=30, sa=23 - - Format: VMUDM $v, $v, $v[el] - sa rd rt rs - vmudm $v23, $v20, $v24[10] - rs=10, rt=24, rd=20, sa=23 - -*/ - -void RSP_Vector_VMUDL (void) { - int32_t count, el, del; - REGISTER32 temp; - - /*if(((*PrgCount) & 0xFFC) == 0xC08) { - for(int32_t i = 0; i < 32; i++) { - cprintf("i = %d : ", i); - for (count = 0; count < 8; count ++ ) { - cprintf("%d,%d ", Indx[i].B[count], EleSpec[i].B[Indx[i].B[count]]); - } - cprintf("\n"); - } - - }*/ - - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (uint32_t)RSP_Vect[RSPOpC.rd].UHW[el] * (uint32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - - RSP_ACCUM[el].W[1] = 0; - RSP_ACCUM[el].HW[1] = temp.HW[1]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - - } - -} - -void RSP_Vector_VMUDM (void) { - int32_t count, el, del; - REGISTER32 temp; - -// cprintf("%08x%08x x %08x%08x = ", RSP_Vect[RSPOpC.rd].DW[0], RSP_Vect[RSPOpC.rd].DW[1],RSP_Vect[RSPOpC.rt].DW[0],RSP_Vect[RSPOpC.rt].DW[1]) - - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (uint32_t)((int32_t)RSP_Vect[RSPOpC.rd].HW[el]) * (uint32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - if (temp.W < 0) { - RSP_ACCUM[el].HW[3] = -1; - } else { - RSP_ACCUM[el].HW[3] = 0; - } - RSP_ACCUM[el].HW[2] = temp.HW[1]; - RSP_ACCUM[el].HW[1] = temp.HW[0]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - //cprintf("%08x%08x\n", RSP_Vect[RSPOpC.sa].DW[0],RSP_Vect[RSPOpC.sa].DW[1]); -} - - -void RSP_Vector_VMUDN (void) { - int32_t count, el, del; - REGISTER32 temp; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - temp.UW = (uint32_t)RSP_Vect[RSPOpC.rd].UHW[el] * (uint32_t)(int32_t)(RSP_Vect[RSPOpC.rt].HW[del]); - if (temp.W < 0) { - RSP_ACCUM[el].HW[3] = -1; - } else { - RSP_ACCUM[el].HW[3] = 0; - } - RSP_ACCUM[el].HW[2] = temp.HW[1]; - RSP_ACCUM[el].HW[1] = temp.HW[0]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - -} - -void RSP_Vector_VMUDH (void) { - int32_t count, el, del; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - RSP_ACCUM[el].W[1] = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].HW[1] = 0; - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } - } -} - -void RSP_Vector_VMACF (void) { - int32_t count, el, del; - //UWORD temp, temp2; - REGISTER32 temp; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /*temp.W = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)(uint32_t)RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].UHW[3] += (uint16_t)(temp.W >> 31); - temp.UW = temp.UW << 1; - temp2.UW = temp.UHW[0] + RSP_ACCUM[el].UHW[1]; - RSP_ACCUM[el].HW[1] = temp2.HW[0]; - temp2.UW = temp.UHW[1] + RSP_ACCUM[el].UHW[2] + temp2.UHW[1]; - RSP_ACCUM[el].HW[2] = temp2.HW[0]; - RSP_ACCUM[el].HW[3] += temp2.HW[1];*/ - temp.W = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)(uint32_t)RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].DW += ((int64_t)temp.W) << 17; - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } - } -} - -void RSP_Vector_VMACU (void) { - int32_t count, el, del; - REGISTER32 temp, temp2; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.W = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)(uint32_t)RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].UHW[3] += (uint16_t)(temp.W >> 31); - temp.UW = temp.UW << 1; - temp2.UW = temp.UHW[0] + RSP_ACCUM[el].UHW[1]; - RSP_ACCUM[el].HW[1] = temp2.HW[0]; - temp2.UW = temp.UHW[1] + RSP_ACCUM[el].UHW[2] + temp2.UHW[1]; - RSP_ACCUM[el].HW[2] = temp2.HW[0]; - RSP_ACCUM[el].HW[3] += temp2.HW[1]; - if (RSP_ACCUM[el].HW[3] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } - } -} - -void RSP_Vector_VMACQ (void) { - int32_t count, el, del; - REGISTER32 temp; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSP_ACCUM[el].W[1] > 0x20) { - if ((RSP_ACCUM[el].W[1] & 0x20) == 0) { - RSP_ACCUM[el].W[1] -= 0x20; - } - } else if (RSP_ACCUM[el].W[1] < -0x20) { - if ((RSP_ACCUM[el].W[1] & 0x20) == 0) { - RSP_ACCUM[el].W[1] += 0x20; - } - } - temp.W = RSP_ACCUM[el].W[1] >> 1; - if (temp.HW[1] < 0) { - if (temp.UHW[1] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - if (temp.HW[0] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)(temp.UW & 0xFFF0); - } - } - } else { - if (temp.UHW[1] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FF0; - } else { - if (temp.HW[0] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FF0; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)(temp.UW & 0xFFF0); - } - } - } - } -} - -void RSP_Vector_VMADL (void) { - int32_t count, el, del; - REGISTER32 temp, temp2; - - - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (uint32_t)RSP_Vect[RSPOpC.rd].UHW[el] * (uint32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - temp2.UW = temp.UHW[1] + RSP_ACCUM[el].UHW[1]; - RSP_ACCUM[el].HW[1] = temp2.HW[0]; - temp2.UW = RSP_ACCUM[el].UHW[2] + temp2.UHW[1]; - RSP_ACCUM[el].HW[2] = temp2.HW[0]; - RSP_ACCUM[el].HW[3] += temp2.HW[1]; - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - } - } - } - -} - -void RSP_Vector_VMADM (void) { - int32_t count, el, del; - REGISTER32 temp, temp2; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (uint32_t)((int32_t)RSP_Vect[RSPOpC.rd].HW[el]) * (uint32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - temp2.UW = temp.UHW[0] + RSP_ACCUM[el].UHW[1]; - RSP_ACCUM[el].HW[1] = temp2.HW[0]; - temp2.UW = temp.UHW[1] + RSP_ACCUM[el].UHW[2] + temp2.UHW[1]; - RSP_ACCUM[el].HW[2] = temp2.HW[0]; - RSP_ACCUM[el].HW[3] += temp2.HW[1]; - if (temp.W < 0) { - RSP_ACCUM[el].HW[3] -= 1; - } - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } - //RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } -} - -void RSP_Vector_VMADN (void) { - int32_t count, el, del; - REGISTER32 temp, temp2; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (uint32_t)RSP_Vect[RSPOpC.rd].UHW[el] * (uint32_t)((int32_t)RSP_Vect[RSPOpC.rt].HW[del]); - temp2.UW = temp.UHW[0] + RSP_ACCUM[el].UHW[1]; - RSP_ACCUM[el].HW[1] = temp2.HW[0]; - temp2.UW = temp.UHW[1] + RSP_ACCUM[el].UHW[2] + temp2.UHW[1]; - RSP_ACCUM[el].HW[2] = temp2.HW[0]; - RSP_ACCUM[el].HW[3] += temp2.HW[1]; - if (temp.W < 0) { - RSP_ACCUM[el].HW[3] -= 1; - } - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].UHW[el] = 0xFFFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - } - } - } -} - -void RSP_Vector_VMADH (void) { - int32_t count, el, del; - - for (count = 0; count < 8; count ++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - RSP_ACCUM[el].W[1] += (int32_t)RSP_Vect[RSPOpC.rd].HW[el] * (int32_t)RSP_Vect[RSPOpC.rt].HW[del]; - if (RSP_ACCUM[el].HW[3] < 0) { - if (RSP_ACCUM[el].UHW[3] != 0xFFFF) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - if (RSP_ACCUM[el].HW[2] >= 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } else { - if (RSP_ACCUM[el].UHW[3] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - if (RSP_ACCUM[el].HW[2] < 0) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[2]; - } - } - } - } -} - -void RSP_Vector_VADD (void) { - int32_t count, el, del; - REGISTER32 temp; - - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.W = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] + (int32_t)RSP_Vect[RSPOpC.rt].HW[del] + - ((RSP_Flags[0].UW >> (7 - el)) & 0x1); - RSP_ACCUM[el].HW[1] = temp.HW[0]; - if ((temp.HW[0] & 0x8000) == 0) { - if (temp.HW[1] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - } - } else { - if (temp.HW[1] != -1 ) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - } - } - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VSUB (void) { - int32_t count, el, del; - REGISTER32 temp; - - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.W = (int32_t)RSP_Vect[RSPOpC.rd].HW[el] - (int32_t)RSP_Vect[RSPOpC.rt].HW[del] - - ((RSP_Flags[0].UW >> (7 - el)) & 0x1); - RSP_ACCUM[el].HW[1] = temp.HW[0]; - if ((temp.HW[0] & 0x8000) == 0) { - if (temp.HW[1] != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = (uint16_t)0x8000; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - } - } else { - if (temp.HW[1] != -1 ) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - } - } - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VABS (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSP_Vect[RSPOpC.rd].HW[el] > 0) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].UHW[del]; - } else if (RSP_Vect[RSPOpC.rd].HW[el] < 0) { - if (RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[el]] == 0x8000) { - RSP_Vect[RSPOpC.sa].HW[el] = 0x7FFF; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].HW[del] * -1; - } - } else { - RSP_Vect[RSPOpC.sa].HW[el] = 0; - } - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VADDC (void) { - int32_t count, el, del; - REGISTER32 temp; - - RSP_Flags[0].UW = 0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (int32_t)RSP_Vect[RSPOpC.rd].UHW[el] + (int32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_ACCUM[el].HW[1] = temp.HW[0]; - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - if (temp.UW & 0xffff0000) { - RSP_Flags[0].UW |= ( 1 << (7 - el) ); - } - } -} - -void RSP_Vector_VSUBC (void) { - int32_t count, el, del; - REGISTER32 temp; - - RSP_Flags[0].UW = 0x0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - temp.UW = (int32_t)RSP_Vect[RSPOpC.rd].UHW[el] - (int32_t)RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_ACCUM[el].HW[1] = temp.HW[0]; - RSP_Vect[RSPOpC.sa].HW[el] = temp.HW[0]; - if (temp.HW[0] != 0) { - RSP_Flags[0].UW |= ( 0x1 << (15 - el) ); - } - if (temp.UW & 0xffff0000) { - RSP_Flags[0].UW |= ( 0x1 << (7 - el) ); - } - } -} - -void RSP_Vector_VSAW (void) { - switch ((RSPOpC.rs & 0xF)) { - case 8: - RSP_Vect[RSPOpC.sa].HW[0] = RSP_ACCUM[0].HW[3]; - RSP_Vect[RSPOpC.sa].HW[1] = RSP_ACCUM[1].HW[3]; - RSP_Vect[RSPOpC.sa].HW[2] = RSP_ACCUM[2].HW[3]; - RSP_Vect[RSPOpC.sa].HW[3] = RSP_ACCUM[3].HW[3]; - RSP_Vect[RSPOpC.sa].HW[4] = RSP_ACCUM[4].HW[3]; - RSP_Vect[RSPOpC.sa].HW[5] = RSP_ACCUM[5].HW[3]; - RSP_Vect[RSPOpC.sa].HW[6] = RSP_ACCUM[6].HW[3]; - RSP_Vect[RSPOpC.sa].HW[7] = RSP_ACCUM[7].HW[3]; - break; - case 9: - RSP_Vect[RSPOpC.sa].HW[0] = RSP_ACCUM[0].HW[2]; - RSP_Vect[RSPOpC.sa].HW[1] = RSP_ACCUM[1].HW[2]; - RSP_Vect[RSPOpC.sa].HW[2] = RSP_ACCUM[2].HW[2]; - RSP_Vect[RSPOpC.sa].HW[3] = RSP_ACCUM[3].HW[2]; - RSP_Vect[RSPOpC.sa].HW[4] = RSP_ACCUM[4].HW[2]; - RSP_Vect[RSPOpC.sa].HW[5] = RSP_ACCUM[5].HW[2]; - RSP_Vect[RSPOpC.sa].HW[6] = RSP_ACCUM[6].HW[2]; - RSP_Vect[RSPOpC.sa].HW[7] = RSP_ACCUM[7].HW[2]; - break; - case 10: - RSP_Vect[RSPOpC.sa].HW[0] = RSP_ACCUM[0].HW[1]; - RSP_Vect[RSPOpC.sa].HW[1] = RSP_ACCUM[1].HW[1]; - RSP_Vect[RSPOpC.sa].HW[2] = RSP_ACCUM[2].HW[1]; - RSP_Vect[RSPOpC.sa].HW[3] = RSP_ACCUM[3].HW[1]; - RSP_Vect[RSPOpC.sa].HW[4] = RSP_ACCUM[4].HW[1]; - RSP_Vect[RSPOpC.sa].HW[5] = RSP_ACCUM[5].HW[1]; - RSP_Vect[RSPOpC.sa].HW[6] = RSP_ACCUM[6].HW[1]; - RSP_Vect[RSPOpC.sa].HW[7] = RSP_ACCUM[7].HW[1]; - break; - default: - RSP_Vect[RSPOpC.sa].DW[1] = 0; - RSP_Vect[RSPOpC.sa].DW[0] = 0; - } -} - -void RSP_Vector_VLT (void) { - int32_t count, el, del; - - RSP_Flags[1].UW = 0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSP_Vect[RSPOpC.rd].HW[el] < RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].UHW[el]; - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } else if (RSP_Vect[RSPOpC.rd].HW[el] != RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW &= ~( 1 << (7 - el) ); - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].UHW[el]; - if ( (RSP_Flags[0].UW & (0x101 << (7 - el))) == (uint16_t)(0x101 << (7 - el))) { - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } else { - RSP_Flags[1].UW &= ~( 1 << (7 - el) ); - } - } - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VEQ (void) { - int32_t count, el, del; - - RSP_Flags[1].UW = 0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rt].UHW[del]; - if (RSP_Vect[RSPOpC.rd].UHW[el] == RSP_Vect[RSPOpC.rt].UHW[del]) { - if ( (RSP_Flags[0].UW & (1 << (15 - el))) == 0) { - RSP_Flags[1].UW |= ( 1 << (7 - el)); - } - } - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VNE (void) { - int32_t count, el, del; - - RSP_Flags[1].UW = 0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].UHW[el]; - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].UHW[el]; - if (RSP_Vect[RSPOpC.rd].UHW[el] != RSP_Vect[RSPOpC.rt].UHW[del]) { - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } else { - if ( (RSP_Flags[0].UW & (1 << (15 - el))) != 0) { - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } - } - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VGE (void) { - int32_t count, el, del; - - RSP_Flags[1].UW = 0; - for ( count = 0; count < 8; count++ ) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSP_Vect[RSPOpC.rd].HW[el] == RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].UHW[el]; - if ( (RSP_Flags[0].UW & (0x101 << (7 - el))) == (uint16_t)(0x101 << (7 - el))) { - RSP_Flags[1].UW &= ~( 1 << (7 - el) ); - } else { - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } - } else if (RSP_Vect[RSPOpC.rd].HW[el] > RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].UHW[el]; - RSP_Flags[1].UW |= ( 1 << (7 - el) ); - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW &= ~( 1 << (7 - el) ); - } - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } - RSP_Flags[0].UW = 0; -} - -void RSP_Vector_VCL (void) { - int32_t count, el, del; - - for (count = 0;count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if ((RSP_Flags[0].UW & ( 1 << (7 - el))) != 0 ) { - if ((RSP_Flags[0].UW & ( 1 << (15 - el))) != 0 ) { - if ((RSP_Flags[1].UW & ( 1 << (7 - el))) != 0 ) { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.rt].UHW[del]; - } else { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - } - } else { - if ((RSP_Flags[2].UW & ( 1 << (7 - el)))) { - if ( RSP_Vect[RSPOpC.rd].UHW[el] + RSP_Vect[RSPOpC.rt].UHW[del] > 0x10000) { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - RSP_Flags[1].UW &= ~(1 << (7 - el)); - } else { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW |= (1 << (7 - el)); - } - } else { - if (RSP_Vect[RSPOpC.rt].UHW[del] + RSP_Vect[RSPOpC.rd].UHW[el] != 0) { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - RSP_Flags[1].UW &= ~(1 << (7 - el)); - } else { - RSP_ACCUM[el].HW[1] = -RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW |= (1 << (7 - el)); - } - } - } - } else { - if ((RSP_Flags[0].UW & ( 1 << (15 - el))) != 0 ) { - if ((RSP_Flags[1].UW & ( 1 << (15 - el))) != 0 ) { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rt].HW[del]; - } else { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - } - } else { - if ( RSP_Vect[RSPOpC.rd].UHW[el] - RSP_Vect[RSPOpC.rt].UHW[del] >= 0) { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW |= (1 << (15 - el)); - } else { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - RSP_Flags[1].UW &= ~(1 << (15 - el)); - } - } - } - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } - RSP_Flags[0].UW = 0; - RSP_Flags[2].UW = 0; -} - -void RSP_Vector_VCH (void) { - int32_t count, el, del; - - RSP_Flags[0].UW = 0; - RSP_Flags[1].UW = 0; - RSP_Flags[2].UW = 0; - - for (count = 0;count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if ((RSP_Vect[RSPOpC.rd].HW[el] ^ RSP_Vect[RSPOpC.rt].HW[del]) < 0) { - RSP_Flags[0].UW |= ( 1 << (7 - el)); - if (RSP_Vect[RSPOpC.rt].HW[del] < 0) { - RSP_Flags[1].UW |= ( 1 << (15 - el)); - - } - if (RSP_Vect[RSPOpC.rd].HW[el] + RSP_Vect[RSPOpC.rt].HW[del] <= 0) { - if (RSP_Vect[RSPOpC.rd].HW[el] + RSP_Vect[RSPOpC.rt].HW[del] == -1) { - RSP_Flags[2].UW |= ( 1 << (7 - el)); - } - RSP_Flags[1].UW |= ( 1 << (7 - el)); - RSP_Vect[RSPOpC.sa].HW[el] = -RSP_Vect[RSPOpC.rt].UHW[del]; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el]; - } - if (RSP_Vect[RSPOpC.rd].HW[el] + RSP_Vect[RSPOpC.rt].HW[del] != 0) { - if (RSP_Vect[RSPOpC.rd].HW[el] != ~RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Flags[0].UW |= ( 1 << (15 - el)); - } - } - } else { - if (RSP_Vect[RSPOpC.rt].HW[del] < 0) { - RSP_Flags[1].UW |= ( 1 << (7 - el)); - } - if (RSP_Vect[RSPOpC.rd].HW[el] - RSP_Vect[RSPOpC.rt].HW[del] >= 0) { - RSP_Flags[1].UW |= ( 1 << (15 - el)); - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].UHW[del]; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el]; - } - if (RSP_Vect[RSPOpC.rd].HW[el] - RSP_Vect[RSPOpC.rt].HW[del] != 0) { - if (RSP_Vect[RSPOpC.rd].HW[el] != ~RSP_Vect[RSPOpC.rt].HW[del]) { - RSP_Flags[0].UW |= ( 1 << (15 - el)); - } - } - } - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VCR (void) { - int32_t count, el, del; - - RSP_Flags[0].UW = 0; - RSP_Flags[1].UW = 0; - RSP_Flags[2].UW = 0; - for (count = 0;count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if ((RSP_Vect[RSPOpC.rd].HW[el] ^ RSP_Vect[RSPOpC.rt].HW[del]) < 0) { - if (RSP_Vect[RSPOpC.rt].HW[del] < 0) { - RSP_Flags[1].UW |= ( 1 << (15 - el)); - } - if (RSP_Vect[RSPOpC.rd].HW[el] + RSP_Vect[RSPOpC.rt].HW[del] <= 0) { - RSP_ACCUM[el].HW[1] = ~RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW |= ( 1 << (7 - el)); - } else { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - } - } else { - if (RSP_Vect[RSPOpC.rt].HW[del] < 0) { - RSP_Flags[1].UW |= ( 1 << (7 - el)); - } - if (RSP_Vect[RSPOpC.rd].HW[el] - RSP_Vect[RSPOpC.rt].HW[del] >= 0) { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rt].UHW[del]; - RSP_Flags[1].UW |= ( 1 << (15 - el)); - } else { - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.rd].HW[el]; - } - } - RSP_Vect[RSPOpC.sa].HW[el] = RSP_ACCUM[el].HW[1]; - } -} - -void RSP_Vector_VMRG (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if ((RSP_Flags[1].UW & ( 1 << (7 - el))) != 0) { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el]; - } else { - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rt].HW[del]; - } - } -} - -void RSP_Vector_VAND (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el] & RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VNAND (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = 7 - count; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = ~(RSP_Vect[RSPOpC.rd].HW[el] & RSP_Vect[RSPOpC.rt].HW[del]); - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VOR (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el] | RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VNOR (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = ~(RSP_Vect[RSPOpC.rd].HW[el] | RSP_Vect[RSPOpC.rt].HW[del]); - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VXOR (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = RSP_Vect[RSPOpC.rd].HW[el] ^ RSP_Vect[RSPOpC.rt].HW[del]; - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VNXOR (void) { - int32_t count, el, del; - - for ( count = 0; count < 8; count ++ ){ - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - RSP_Vect[RSPOpC.sa].HW[el] = ~(RSP_Vect[RSPOpC.rd].HW[el] ^ RSP_Vect[RSPOpC.rt].HW[del]); - RSP_ACCUM[el].HW[1] = RSP_Vect[RSPOpC.sa].HW[el]; - } -} - -void RSP_Vector_VRCP (void) { - int32_t count, neg; - - RecpResult.W = RSP_Vect[RSPOpC.rt].HW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]]; - if (RecpResult.UW == 0) { - RecpResult.UW = 0x7FFFFFFF; - } else { - if (RecpResult.W < 0) { - neg = 1; - RecpResult.W = ~RecpResult.W + 1; - } else { - neg = 0; - } - for (count = 15; count > 0; count--) { - if ((RecpResult.W & (1 << count))) { - RecpResult.W &= (0xFFC0 >> (15 - count) ); - count = 0; - } - } - RecpResult.W = (int32_t)((0x7FFFFFFF / (double)RecpResult.W)); - for (count = 31; count > 0; count--) { - if ((RecpResult.W & (1 << count))) { - RecpResult.W &= (0xFFFF8000 >> (31 - count) ); - count = 0; - } - } - if (neg == 1) { - RecpResult.W = ~RecpResult.W; - } - } - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].HW[7 - (RSPOpC.rd & 0x7)] = RecpResult.UHW[0]; -} - -void RSP_Vector_VRCPL (void) { - int32_t count, neg; - - RecpResult.UW = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]] | Recp.W; - if (RecpResult.UW == 0) { - RecpResult.UW = 0x7FFFFFFF; - } else { - if (RecpResult.W < 0) { - neg = 1; - if (RecpResult.UHW[1] == 0xFFFF && RecpResult.HW[0] < 0) { - RecpResult.W = ~RecpResult.W + 1; - } else { - RecpResult.W = ~RecpResult.W; - } - } else { - neg = 0; - } - for (count = 31; count > 0; count--) { - if ((RecpResult.W & (1 << count))) { - RecpResult.W &= (0xFFC00000 >> (31 - count) ); - count = 0; - } - } - RecpResult.W = 0x7FFFFFFF / RecpResult.W; - for (count = 31; count > 0; count--) { - if ((RecpResult.W & (1 << count))) { - RecpResult.W &= (0xFFFF8000 >> (31 - count) ); - count = 0; - } - } - if (neg == 1) { - RecpResult.W = ~RecpResult.W; - } - } - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].HW[7 - (RSPOpC.rd & 0x7)] = RecpResult.UHW[0]; -} - -void RSP_Vector_VRCPH (void) { - int32_t count; - - Recp.UHW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]]; - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].UHW[7 - (RSPOpC.rd & 0x7)] = RecpResult.UHW[1]; -} - -void RSP_Vector_VMOV (void) { - RSP_Vect[RSPOpC.sa].UHW[7 - (RSPOpC.rd & 0x7)] = - RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]]; -} - -void RSP_Vector_VRSQ (void) { - int32_t count, neg; - - SQrootResult.W = RSP_Vect[RSPOpC.rt].HW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]]; - if (SQrootResult.UW == 0) { - SQrootResult.UW = 0x7FFFFFFF; - } else if (SQrootResult.UW == 0xFFFF8000) { - SQrootResult.UW = 0xFFFF0000; - } else { - if (SQrootResult.W < 0) { - neg = 1; - SQrootResult.W = ~SQrootResult.W + 1; - } else { - neg = 0; - } - for (count = 15; count > 0; count--) { - if ((SQrootResult.W & (1 << count))) { - SQrootResult.W &= (0xFF80 >> (15 - count) ); - count = 0; - } - } - //SQrootResult.W = sqrt(SQrootResult.W); - SQrootResult.W = (int32_t)(0x7FFFFFFF / (int32_t) sqrt((double) SQrootResult.W)); - for (count = 31; count > 0; count--) { - if ((SQrootResult.W & (1 << count))) { - SQrootResult.W &= (0xFFFF8000 >> (31 - count) ); - count = 0; - } - } - if (neg == 1) { - SQrootResult.W = ~SQrootResult.W; - } - } - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].HW[7 - (RSPOpC.rd & 0x7)] = SQrootResult.UHW[0]; -} - -void RSP_Vector_VRSQL (void) { - int32_t count, neg; - - SQrootResult.UW = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]] | SQroot.W; - if (SQrootResult.UW == 0) { - SQrootResult.UW = 0x7FFFFFFF; - } else if (SQrootResult.UW == 0xFFFF8000) { - SQrootResult.UW = 0xFFFF0000; - } else { - if (SQrootResult.W < 0) { - neg = 1; - if (SQrootResult.UHW[1] == 0xFFFF && SQrootResult.HW[0] < 0) { - SQrootResult.W = ~SQrootResult.W + 1; - } else { - SQrootResult.W = ~SQrootResult.W; - } - } else { - neg = 0; - } - for (count = 31; count > 0; count--) { - if ((SQrootResult.W & (1 << count))) { - SQrootResult.W &= (0xFF800000 >> (31 - count) ); - count = 0; - } - } - SQrootResult.W = (int32_t)(0x7FFFFFFF / (int32_t) sqrt((double) SQrootResult.W)); - - for (count = 31; count > 0; count--) { - if ((SQrootResult.W & (1 << count))) { - SQrootResult.W &= (0xFFFF8000 >> (31 - count) ); - count = 0; - } - } - if (neg == 1) { - SQrootResult.W = ~SQrootResult.W; - } - } - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].HW[7 - (RSPOpC.rd & 0x7)] = SQrootResult.UHW[0]; -} - -void RSP_Vector_VRSQH (void) { - int32_t count; - - SQroot.UHW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]]; - for ( count = 0; count < 8; count++ ) { - RSP_ACCUM[count].HW[1] = RSP_Vect[RSPOpC.rt].UHW[EleSpec[RSPOpC.rs].B[count]]; - } - RSP_Vect[RSPOpC.sa].UHW[7 - (RSPOpC.rd & 0x7)] = SQrootResult.UHW[1]; -} - -void RSP_Vector_VNOOP (void) {} -/************************** lc2 functions **************************/ -void RSP_Opcode_LBV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset)) &0xFFF); - RSP_LBV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LSV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 1)) &0xFFF); - RSP_LSV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LLV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 2)) &0xFFF); - RSP_LLV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LDV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_LDV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LQV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_LQV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LRV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_LRV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LPV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_LPV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LUV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_LUV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LHV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_LHV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LFV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_LFV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_LTV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_LTV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -/************************** sc2 functions **************************/ -void RSP_Opcode_SBV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset)) &0xFFF); - RSP_SBV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SSV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 1)) &0xFFF); - RSP_SSV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SLV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 2)) &0xFFF); - RSP_SLV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SDV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_SDV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SQV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_SQV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SRV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_SRV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SPV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_SPV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SUV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 3)) &0xFFF); - RSP_SUV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SHV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_SHV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SFV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_SFV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_STV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) &0xFFF); - RSP_STV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -void RSP_Opcode_SWV ( void ) { - uint32_t Address = ((RSP_GPR[RSPOpC.base].UW + (uint32_t)(RSPOpC.voffset << 4)) & 0xFFF); - RSP_SWV_DMEM( Address, RSPOpC.rt, RSPOpC.del); -} - -/************************** Other functions **************************/ - -void rsp_UnknownOpcode (void) { - - printf("Unhandled RSP opcode (%08x)\n", RSPOpC.Hex); - //ExitThread(0); - exit(0); -} - diff --git a/src/usf/rsp_mmx.c b/src/usf/rsp_mmx.c deleted file mode 100644 index 24d4022..0000000 --- a/src/usf/rsp_mmx.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 "rsp.h" -#include "rsp_x86.h" -#include "recompiler_cpu.h" -#include "memory.h" - -#define PUTDST8(dest,value) (*((uint8_t *)(dest))=(uint8_t)(value)); dest += 1; -#define PUTDST16(dest,value) (*((uint16_t *)(dest))=(uint16_t)(value)); dest += 2; -#define PUTDST32(dest,value) (*((uint32_t *)(dest))=(uint32_t)(value)); dest += 4; -#define PUTDST64(dest,value) {(*((uint64_t *)(dest))=(uint64_t)(value)); dest += 8;} - -void RSPMmxEmptyMultimediaState(void) { - PUTDST16(RSPRecompPos,0x770f); -} - -void RSPMmxMoveRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x7f0f,Source,Dest); -} - -void RSPMmxMoveQwordVariableToReg(int32_t Dest, void *Variable) { - OPCODE_REG_VARIABLE(,16,0x6f0f,Dest,Variable); -} - -void RSPMmxMoveQwordRegToVariable(int32_t Dest, void *Variable) { - OPCODE_REG_VARIABLE(,16,0x7f0f,Dest,Variable); -} - -void RSPMmxPorRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x7f0f,Source,Dest); -} - -void RSPMmxPorVariableToReg(void * Variable, int32_t Dest) { - OPCODE_REG_VARIABLE(,16,0xeb0f,Dest,Variable); -} - -void RSPMmxPandRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xdb0f,Dest,Source); -} - -void RSPMmxPandVariableToReg(void * Variable, int32_t Dest) { - OPCODE_REG_VARIABLE(,16,0xdb0f,Dest,Variable); -} - -void RSPMmxPandnRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xdf0f,Dest,Source); -} - -void RSPMmxXorRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xef0f,Dest,Source); -} - -void RSPMmxShuffleMemoryToReg(int32_t Dest, void * Variable, uint8_t Immed) { - OPCODE_REG_VARIABLE(,16,0x700f,Dest,(uint8_t*)Variable); - PUTDST8(RSPRecompPos, Immed); -} - -void RSPMmxPmullwRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xd50f,Dest,Source); -} - -void RSPMmxPmullwVariableToReg(int32_t Dest, void * Variable) { - OPCODE_REG_VARIABLE(,16,0xd50f,Dest,Variable); -} - -void RSPMmxPmulhuwRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xe40f,Dest,Source); -} - -void RSPMmxPmulhwRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xe50f,Dest,Source); -} - -void RSPMmxPmulhwRegToVariable(int32_t Dest, void * Variable) { - OPCODE_REG_VARIABLE(,16,0xe50f,Dest,Variable); -} - -void RSPMmxPsrlwImmed(int32_t Dest, uint8_t Immed) { - OPCODE_REG_REG(16,0xe50f,OP_D2,Dest); - PUTDST8(RSPRecompPos, Immed); -} - -void RSPMmxPsrawImmed(int32_t Dest, uint8_t Immed) { - OPCODE_REG_REG(16,0x710f,OP_D4,Dest); - PUTDST8(RSPRecompPos, Immed); -} - -void RSPMmxPsllwImmed(int32_t Dest, uint8_t Immed) { - OPCODE_REG_REG(16,0x710f,OP_D6,Dest); - PUTDST8(RSPRecompPos, Immed); -} - -void RSPMmxPaddswRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xed0f,Dest,Source); -} - -void RSPMmxPaddswVariableToReg(int32_t Dest, void * Variable) { - OPCODE_REG_VARIABLE(,16,0xed0f,Dest,Variable); -} - -void RSPMmxPaddwRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0xfd0f,Dest,Source); -} - -void RSPMmxPackSignedDwords(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x6b0f,Dest,Source); -} - -void RSPMmxUnpackLowWord(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x610f,Dest,Source); -} - -void RSPMmxUnpackHighWord(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x690f,Dest,Source); -} - -void RSPMmxCompareGreaterWordRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x650f,Dest,Source); -} diff --git a/src/usf/rsp_recompiler_analysis.c b/src/usf/rsp_recompiler_analysis.c deleted file mode 100644 index 4c2877a..0000000 --- a/src/usf/rsp_recompiler_analysis.c +++ /dev/null @@ -1,1780 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 "rsp.h" -#include "rsp_recompiler_cpu.h" - -#define RSP_SAFE_ANALYSIS /* makes optimization less risky (dlist useful) */ - -/************************************************************ -** IsOpcodeNop -** -** Output: BOOLean whether opcode at PC is a NOP -** Input: PC -*************************************************************/ - -int32_t IsOpcodeNop(uint32_t PC) { - RSPOPCODE RspOp; - RSP_LW_IMEM(PC, &RspOp.Hex); - - if (RspOp.op == RSP_SPECIAL && RspOp.funct == RSP_SPECIAL_SLL) { - return (RspOp.rd == 0) ? 1 : 0; - } - - return 0; -} - -/************************************************************ -** IsNextInstructionMmx -** -** Output: determines EMMS status -** Input: PC -*************************************************************/ - -int32_t IsNextInstructionMmx(uint32_t PC) { - RSPOPCODE RspOp; - - if (IsMmxEnabled == 0) - return 0; - - PC += 4; - if (PC >= 0x1000) return 0; - RSP_LW_IMEM(PC, &RspOp.Hex); - - if (RspOp.op != RSP_CP2) - return 0; - - if ((RspOp.rs & 0x10) != 0) { - switch (RspOp.funct) { - case RSP_VECTOR_VMULF: - case RSP_VECTOR_VMUDL: /* Warning: Not all handled? */ - case RSP_VECTOR_VMUDM: - case RSP_VECTOR_VMUDN: - case RSP_VECTOR_VMUDH: - if (1 == WriteToAccum(7, PC)) { - return 0; - } else if ((RspOp.rs & 0x0f) >= 2 && (RspOp.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) { - return 0; - } else - return 1; - - case RSP_VECTOR_VAND: - case RSP_VECTOR_VOR: - case RSP_VECTOR_VXOR: - if (1 == WriteToAccum(Low16BitAccum, PC)) { - return 0; - } else if ((RspOp.rs & 0x0f) >= 2 && (RspOp.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) { - return 0; - } else - return 1; - - case RSP_VECTOR_VADD: - /* Requires no accumulator write! & No flags! */ - if (WriteToAccum(Low16BitAccum, RSPCompilePC) == 1) { - return 0; - } else if (UseRspFlags(RSPCompilePC) == 1) { - return 0; - } else if ((RspOp.rs & 0x0f) >= 2 && (RspOp.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) { - return 0; - } else - return 1; - - default: - return 0; - } - } else - return 0; -} - -/************************************************************ -** WriteToAccum2 -** -** Output: -** 1: Accumulation series -** 0: Accumulator is reset after this op -** -** Input: PC, Location in accumulator -*************************************************************/ - -#define HIT_BRANCH 0x2 - -uint32_t WriteToAccum2 (int32_t Location, int32_t PC, int32_t RecursiveCall) { - RSPOPCODE RspOp; - uint32_t BranchTarget = 0; - int32_t BranchImmed = 0; - uint32_t JumpTarget = 0; - int32_t JumpUncond = 0; - - int32_t Instruction_State = RSPNextInstruction; - - if (Compiler.bAccum == 0) return 1; - - if (Instruction_State == DELAY_SLOT) { - return 1; - } - - do { - PC += 4; - if (PC >= 0x1000) { return 1; } - RSP_LW_IMEM(PC, &RspOp.Hex); - - switch (RspOp.op) { - case RSP_REGIMM: - switch (RspOp.rt) { - case RSP_REGIMM_BLTZ: - case RSP_REGIMM_BGEZ: - case RSP_REGIMM_BLTZAL: - case RSP_REGIMM_BGEZAL: - Instruction_State = DO_DELAY_SLOT; - break; - default: - CompilerWarning("Unkown opcode in WriteToAccum\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SPECIAL: - switch (RspOp.funct) { - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - case RSP_SPECIAL_BREAK: - break; - - case RSP_SPECIAL_JR: - Instruction_State = DO_DELAY_SLOT; - break; - - default: - CompilerWarning("Unkown opcode in WriteToAccum\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_J: - case RSP_JAL: - if (!JumpTarget) { - JumpUncond = 1; - JumpTarget = (RspOp.target << 2) & 0xFFC; - } - Instruction_State = DO_DELAY_SLOT; - break; - - case RSP_BEQ: - case RSP_BNE: - case RSP_BLEZ: - case RSP_BGTZ: - Instruction_State = DO_DELAY_SLOT; - BranchTarget = (PC + ((int16_t)RspOp.offset << 2) + 4) & 0xFFC; - BranchImmed = (int16_t)RspOp.offset; - break; - case RSP_ADDI: - case RSP_ADDIU: - case RSP_SLTI: - case RSP_SLTIU: - case RSP_ANDI: - case RSP_ORI: - case RSP_XORI: - case RSP_LUI: - case RSP_CP0: - break; - - case RSP_CP2: - if ((RspOp.rs & 0x10) != 0) { - switch (RspOp.funct) { - case RSP_VECTOR_VMULF: - case RSP_VECTOR_VMUDL: - case RSP_VECTOR_VMUDM: - case RSP_VECTOR_VMUDN: - case RSP_VECTOR_VMUDH: - return 0; - case RSP_VECTOR_VMACF: - case RSP_VECTOR_VMADL: - case RSP_VECTOR_VMADM: - case RSP_VECTOR_VMADN: - case RSP_VECTOR_VMADH: - return 1; - case RSP_VECTOR_VABS: // hope this is ok - case RSP_VECTOR_VADD: - case RSP_VECTOR_VADDC: - case RSP_VECTOR_VSUB: - case RSP_VECTOR_VSUBC: - case RSP_VECTOR_VAND: - case RSP_VECTOR_VOR: - case RSP_VECTOR_VXOR: - case RSP_VECTOR_VNXOR: - case RSP_VECTOR_VCR: - case RSP_VECTOR_VCH: - case RSP_VECTOR_VCL: - case RSP_VECTOR_VRCP: - case RSP_VECTOR_VRCPL: // hope this is ok - case RSP_VECTOR_VRCPH: - case RSP_VECTOR_VRSQL: - case RSP_VECTOR_VRSQH: // hope this is ok - case RSP_VECTOR_VLT: - case RSP_VECTOR_VEQ: - case RSP_VECTOR_VGE: - if (Location == Low16BitAccum) { return 0; } - break; - - case RSP_VECTOR_VMOV: - case RSP_VECTOR_VMRG: - break; - case RSP_VECTOR_VSAW: - return 1; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } else { - switch (RspOp.rs) { - case RSP_COP2_CF: - case RSP_COP2_CT: - case RSP_COP2_MT: - case RSP_COP2_MF: - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } - break; - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - case RSP_SB: - case RSP_SH: - case RSP_SW: - break; - case RSP_LC2: - switch (RspOp.rd) { - case RSP_LSC2_SV: - case RSP_LSC2_DV: - case RSP_LSC2_RV: - case RSP_LSC2_QV: - case RSP_LSC2_LV: - case RSP_LSC2_UV: - case RSP_LSC2_PV: - case RSP_LSC2_TV: - break; - default: - CompilerWarning("Unkown opcode in WriteToAccum\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SC2: - switch (RspOp.rd) { - case RSP_LSC2_BV: - case RSP_LSC2_SV: - case RSP_LSC2_LV: - case RSP_LSC2_DV: - case RSP_LSC2_QV: - case RSP_LSC2_RV: - case RSP_LSC2_PV: - case RSP_LSC2_UV: - case RSP_LSC2_HV: - case RSP_LSC2_FV: - case RSP_LSC2_WV: - case RSP_LSC2_TV: - break; - default: - CompilerWarning("Unkown opcode in WriteToAccum\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - default: - CompilerWarning("Unkown opcode in WriteToAccum\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - switch (Instruction_State) { - case NORMAL: break; - case DO_DELAY_SLOT: - Instruction_State = DELAY_SLOT; - break; - case DELAY_SLOT: - if (JumpUncond) { - PC = JumpTarget - 0x04; - Instruction_State = NORMAL; - } else { - Instruction_State = FINISH_BLOCK; - } - JumpUncond = 0; - break; - } - } while (Instruction_State != FINISH_BLOCK); - - /*** - ** This is a tricky situation because most of the - ** microcode does loops, so looping back and checking - ** can prove effective, but it's still a branch.. - ***/ - - if (BranchTarget != 0 && RecursiveCall == 0) { - uint32_t BranchTaken, BranchFall; - - /* analysis of branch taken */ - BranchTaken = WriteToAccum2(Location, BranchTarget - 4, 1); - /* analysis of branch as nop */ - BranchFall = WriteToAccum2(Location, PC, 1); - - if (BranchImmed < 0) { - if (BranchTaken != 0) { - /* - ** took this back branch and couldnt find a place - ** that resets the accum or hit a branch etc - **/ - return 1; - } else if (BranchFall == HIT_BRANCH) { - /* risky? the loop ended, hit another branch after loop-back */ - -#if !defined(RSP_SAFE_ANALYSIS) - CPU_Message("WriteToDest: Backward branch hit, BranchFall = Hit branch (returning 0)"); - return 0; -#endif - return 1; - } else { - /* otherwise this is completely valid */ - return BranchFall; - } - } else { - if (BranchFall != 0) { - /* - ** took this forward branch and couldnt find a place - ** that resets the accum or hit a branch etc - **/ - return 1; - } else if (BranchTaken == HIT_BRANCH) { - /* risky? jumped forward, hit another branch */ - -#if !defined(RSP_SAFE_ANALYSIS) - CPU_Message("WriteToDest: Forward branch hit, BranchTaken = Hit branch (returning 0)"); - return 0; -#endif - - return 1; - } else { - /* otherwise this is completely valid */ - return BranchTaken; - } - } - } else { - return HIT_BRANCH; - } -} - -int32_t WriteToAccum (int32_t Location, int32_t PC) { - uint32_t value = WriteToAccum2(Location, PC, 0); - - if (value == HIT_BRANCH) { - return 1; /* ??? */ - } else - return value; -} - -/************************************************************ -** WriteToVectorDest -** -** Output: -** 1: Destination is over-written later -** 0: Destination is used as a source later -** -** Input: PC, Register -*************************************************************/ - -int32_t WriteToVectorDest2 (uint32_t DestReg, int32_t PC, int32_t RecursiveCall) { - RSPOPCODE RspOp; - uint32_t BranchTarget = 0; - int32_t BranchImmed = 0; - uint32_t JumpTarget = 0; - int32_t JumpUncond = 0; - - int32_t Instruction_State = RSPNextInstruction; - - if (Compiler.bDest == 0) return 1; - - if (Instruction_State == DELAY_SLOT) { - return 1; - } - - do { - PC += 4; - if (PC >= 0x1000) { return 1; } - RSP_LW_IMEM(PC, &RspOp.Hex); - - switch (RspOp.op) { - - case RSP_REGIMM: - switch (RspOp.rt) { - case RSP_REGIMM_BLTZ: - case RSP_REGIMM_BGEZ: - case RSP_REGIMM_BLTZAL: - case RSP_REGIMM_BGEZAL: - Instruction_State = DO_DELAY_SLOT; - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SPECIAL: - switch (RspOp.funct) { - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - case RSP_SPECIAL_BREAK: - break; - - case RSP_SPECIAL_JR: - Instruction_State = DO_DELAY_SLOT; - break; - - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_J: - case RSP_JAL: - if (!JumpTarget) { - JumpUncond = 1; - JumpTarget = (RspOp.target << 2) & 0xFFC; - } - Instruction_State = DO_DELAY_SLOT; - break; - case RSP_BEQ: - case RSP_BNE: - case RSP_BLEZ: - case RSP_BGTZ: - Instruction_State = DO_DELAY_SLOT; - BranchTarget = (PC + ((int16_t)RspOp.offset << 2) + 4) & 0xFFC; - BranchImmed = (int16_t)RspOp.offset; - break; - case RSP_ADDI: - case RSP_ADDIU: - case RSP_SLTI: - case RSP_SLTIU: - case RSP_ANDI: - case RSP_ORI: - case RSP_XORI: - case RSP_LUI: - case RSP_CP0: - break; - - case RSP_CP2: - if ((RspOp.rs & 0x10) != 0) { - switch (RspOp.funct) { - case RSP_VECTOR_VMULF: - case RSP_VECTOR_VMUDL: - case RSP_VECTOR_VMUDM: - case RSP_VECTOR_VMUDN: - case RSP_VECTOR_VMUDH: - case RSP_VECTOR_VMACF: - case RSP_VECTOR_VMADL: - case RSP_VECTOR_VMADM: - case RSP_VECTOR_VMADN: - case RSP_VECTOR_VMADH: - case RSP_VECTOR_VADD: - case RSP_VECTOR_VADDC: - case RSP_VECTOR_VSUB: - case RSP_VECTOR_VSUBC: - case RSP_VECTOR_VAND: - case RSP_VECTOR_VOR: - case RSP_VECTOR_VXOR: - case RSP_VECTOR_VNXOR: - case RSP_VECTOR_VABS: - if (DestReg == RspOp.rd) { return 1; } - if (DestReg == RspOp.rt) { return 1; } - if (DestReg == RspOp.sa) { return 0; } - break; - - case RSP_VECTOR_VMOV: - if (DestReg == RspOp.rt) { return 1; } - break; - - case RSP_VECTOR_VCR: - case RSP_VECTOR_VRCP: - case RSP_VECTOR_VRCPH: - case RSP_VECTOR_VRSQH: - case RSP_VECTOR_VCH: - case RSP_VECTOR_VCL: - return 1; - - case RSP_VECTOR_VMRG: - case RSP_VECTOR_VLT: - case RSP_VECTOR_VEQ: - case RSP_VECTOR_VGE: - if (DestReg == RspOp.rd) { return 1; } - if (DestReg == RspOp.rt) { return 1; } - if (DestReg == RspOp.sa) { return 0; } - break; - case RSP_VECTOR_VSAW: - if (DestReg == RspOp.sa) { return 0; } - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } else { - switch (RspOp.rs) { - case RSP_COP2_CF: - case RSP_COP2_CT: - break; - case RSP_COP2_MT: - /* if (DestReg == RspOp.rd) { return 0; } */ - break; - case RSP_COP2_MF: - if (DestReg == RspOp.rd) { return 1; } - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } - break; - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - case RSP_SB: - case RSP_SH: - case RSP_SW: - break; - case RSP_LC2: - switch (RspOp.rd) { - case RSP_LSC2_SV: - case RSP_LSC2_DV: - case RSP_LSC2_RV: - break; - - case RSP_LSC2_QV: - case RSP_LSC2_LV: - case RSP_LSC2_UV: - case RSP_LSC2_PV: - case RSP_LSC2_TV: - break; - - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SC2: - switch (RspOp.rd) { - case RSP_LSC2_BV: - case RSP_LSC2_SV: - case RSP_LSC2_LV: - case RSP_LSC2_DV: - case RSP_LSC2_QV: - case RSP_LSC2_RV: - case RSP_LSC2_PV: - case RSP_LSC2_UV: - case RSP_LSC2_HV: - case RSP_LSC2_FV: - case RSP_LSC2_WV: - case RSP_LSC2_TV: - if (DestReg == RspOp.rt) { return 1; } - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - switch (Instruction_State) { - case NORMAL: break; - case DO_DELAY_SLOT: - Instruction_State = DELAY_SLOT; - break; - case DELAY_SLOT: - if (JumpUncond) { - PC = JumpTarget - 0x04; - Instruction_State = NORMAL; - } else { - Instruction_State = FINISH_BLOCK; - } - JumpUncond = 0; - break; - } - } while (Instruction_State != FINISH_BLOCK); - - /*** - ** This is a tricky situation because most of the - ** microcode does loops, so looping back and checking - ** can prove effective, but it's still a branch.. - ***/ - - if (BranchTarget != 0 && RecursiveCall == 0) { - uint32_t BranchTaken, BranchFall; - - /* analysis of branch taken */ - BranchTaken = WriteToVectorDest2(DestReg, BranchTarget - 4, 1); - /* analysis of branch as nop */ - BranchFall = WriteToVectorDest2(DestReg, PC, 1); - - if (BranchImmed < 0) { - if (BranchTaken != 0) { - /* - ** took this back branch and found a place - ** that needs this vector as a source - **/ - return 1; - } else if (BranchFall == HIT_BRANCH) { - /* (dlist) risky? the loop ended, hit another branch after loop-back */ - -#if !defined(RSP_SAFE_ANALYSIS) - CPU_Message("WriteToDest: Backward branch hit, BranchFall = Hit branch (returning 0)"); - return 0; -#endif - - return 1; - } else { - /* otherwise this is completely valid */ - return BranchFall; - } - } else { - if (BranchFall != 0) { - /* - ** took this forward branch and found a place - ** that needs this vector as a source - **/ - return 1; - } else if (BranchTaken == HIT_BRANCH) { - /* (dlist) risky? jumped forward, hit another branch */ - -#if !defined(RSP_SAFE_ANALYSIS) - CPU_Message("WriteToDest: Forward branch hit, BranchTaken = Hit branch (returning 0)"); - return 0; -#endif - - return 1; - } else { - /* otherwise this is completely valid */ - return BranchTaken; - } - } - } else { - return HIT_BRANCH; - } -} - -int32_t WriteToVectorDest (uint32_t DestReg, int32_t PC) { - uint32_t value = WriteToVectorDest2(DestReg, PC, 0); - - if (value == HIT_BRANCH) { - return 1; /* ??? */ - } else - return value; -} - -/************************************************************ -** UseRspFlags -** -** Output: -** 1: Flags are determined not in use -** 0: Either unable to determine or are in use -** -** Input: PC -*************************************************************/ - -/* TODO: consider delay slots and such in a branch? */ -int32_t UseRspFlags (int32_t PC) { - RSPOPCODE RspOp; - int32_t Instruction_State = RSPNextInstruction; - - if (Compiler.bFlags == 0) return 1; - - if (Instruction_State == DELAY_SLOT) { - return 1; - } - - do { - PC -= 4; - if (PC < 0) { return 1; } - RSP_LW_IMEM(PC, &RspOp.Hex); - - switch (RspOp.op) { - - case RSP_REGIMM: - switch (RspOp.rt) { - case RSP_REGIMM_BLTZ: - case RSP_REGIMM_BGEZ: - Instruction_State = DO_DELAY_SLOT; - break; - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SPECIAL: - switch (RspOp.funct) { - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - case RSP_SPECIAL_BREAK: - break; - - case RSP_SPECIAL_JR: - Instruction_State = DO_DELAY_SLOT; - break; - - default: - CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_J: - case RSP_JAL: - case RSP_BEQ: - case RSP_BNE: - case RSP_BLEZ: - case RSP_BGTZ: - Instruction_State = DO_DELAY_SLOT; - break; - case RSP_ADDI: - case RSP_ADDIU: - case RSP_SLTI: - case RSP_SLTIU: - case RSP_ANDI: - case RSP_ORI: - case RSP_XORI: - case RSP_LUI: - case RSP_CP0: - break; - - case RSP_CP2: - if ((RspOp.rs & 0x10) != 0) { - switch (RspOp.funct) { - case RSP_VECTOR_VMULF: - case RSP_VECTOR_VMUDL: - case RSP_VECTOR_VMUDM: - case RSP_VECTOR_VMUDN: - case RSP_VECTOR_VMUDH: - break; - case RSP_VECTOR_VMACF: - case RSP_VECTOR_VMADL: - case RSP_VECTOR_VMADM: - case RSP_VECTOR_VMADN: - case RSP_VECTOR_VMADH: - break; - - case RSP_VECTOR_VSUB: - case RSP_VECTOR_VADD: - return 0; - case RSP_VECTOR_VSUBC: - case RSP_VECTOR_VADDC: - return 1; - - case RSP_VECTOR_VABS: - case RSP_VECTOR_VAND: - case RSP_VECTOR_VOR: - case RSP_VECTOR_VXOR: - case RSP_VECTOR_VRCPH: - case RSP_VECTOR_VRSQL: - case RSP_VECTOR_VRSQH: - case RSP_VECTOR_VRCPL: - case RSP_VECTOR_VRCP: - break; - - case RSP_VECTOR_VCR: - case RSP_VECTOR_VCH: - case RSP_VECTOR_VCL: - case RSP_VECTOR_VLT: - case RSP_VECTOR_VEQ: - case RSP_VECTOR_VGE: - case RSP_VECTOR_VMRG: - return 1; - - case RSP_VECTOR_VSAW: - case RSP_VECTOR_VMOV: - break; - - default: - CompilerWarning("Unkown opcode in UseRspFlags\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } else { - switch (RspOp.rs) { - case RSP_COP2_CT: - return 1; - - case RSP_COP2_CF: - case RSP_COP2_MT: - case RSP_COP2_MF: - break; - default: - CompilerWarning("Unkown opcode in UseRspFlags\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - } - break; - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - case RSP_SB: - case RSP_SH: - case RSP_SW: - break; - case RSP_LC2: - switch (RspOp.rd) { - case RSP_LSC2_SV: - case RSP_LSC2_DV: - case RSP_LSC2_RV: - case RSP_LSC2_QV: - case RSP_LSC2_LV: - case RSP_LSC2_UV: - case RSP_LSC2_PV: - case RSP_LSC2_TV: - break; - default: - CompilerWarning("Unkown opcode in UseRspFlags\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - case RSP_SC2: - switch (RspOp.rd) { - case RSP_LSC2_BV: - case RSP_LSC2_SV: - case RSP_LSC2_LV: - case RSP_LSC2_DV: - case RSP_LSC2_QV: - case RSP_LSC2_RV: - case RSP_LSC2_PV: - case RSP_LSC2_UV: - case RSP_LSC2_HV: - case RSP_LSC2_FV: - case RSP_LSC2_WV: - case RSP_LSC2_TV: - break; - default: - CompilerWarning("Unkown opcode in UseRspFlags\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - break; - default: - CompilerWarning("Unkown opcode in UseRspFlags\n%s",RSPOpcodeName(RspOp.Hex,PC)); - return 1; - } - switch (Instruction_State) { - case NORMAL: break; - case DO_DELAY_SLOT: - Instruction_State = DELAY_SLOT; - break; - case DELAY_SLOT: - Instruction_State = FINISH_BLOCK; - break; - } - } while ( Instruction_State != FINISH_BLOCK); - return 1; -} - -/************************************************************ -** IsRegisterConstant -** -** Output: -** 1: Register is constant throughout -** 0: Register is not constant at all -** -** Input: PC, Pointer to constant to fill -*************************************************************/ - -int32_t IsRegisterConstant (uint32_t Reg, uint32_t * Constant) { - uint32_t PC = 0; - uint32_t References = 0; - uint32_t Const = 0; - RSPOPCODE RspOp; - - if (Compiler.bGPRConstants == 0) - return 0; - - while (PC < 0x1000) { - - RSP_LW_IMEM(PC, &RspOp.Hex); - PC += 4; - - switch (RspOp.op) { - case RSP_REGIMM: - break; - - case RSP_SPECIAL: - switch (RspOp.funct) { - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - if (RspOp.rd == Reg) { return 0; } - break; - - case RSP_SPECIAL_BREAK: - case RSP_SPECIAL_JR: - break; - - default: - // CompilerWarning("Unkown opcode in IsRegisterConstant\n%s",RSPOpcodeName(RspOp.Hex,PC)); - // return 0; - break; - } - break; - - case RSP_J: - case RSP_JAL: - case RSP_BEQ: - case RSP_BNE: - case RSP_BLEZ: - case RSP_BGTZ: - break; - - case RSP_ADDI: - case RSP_ADDIU: - if (RspOp.rt == Reg) { - if (!RspOp.rs) { - if (References > 0) { return 0; } - Const = (int16_t)RspOp.immediate; - References++; - } else - return 0; - } - break; - case RSP_ORI: - if (RspOp.rt == Reg) { - if (!RspOp.rs) { - if (References > 0) { return 0; } - Const = (uint16_t)RspOp.immediate; - References++; - } else - return 0; - } - break; - - case RSP_LUI: - if (RspOp.rt == Reg) { - if (References > 0) { return 0; } - Const = (int16_t)RspOp.offset << 16; - References++; - } - break; - - case RSP_ANDI: - case RSP_XORI: - case RSP_SLTI: - case RSP_SLTIU: - if (RspOp.rt == Reg) { return 0; } - break; - - case RSP_CP0: - switch (RspOp.rs) { - case RSP_COP0_MF: - if (RspOp.rt == Reg) { return 0; } - case RSP_COP0_MT: - break; - } - break; - - case RSP_CP2: - if ((RspOp.rs & 0x10) == 0) { - switch (RspOp.rs) { - case RSP_COP2_CT: - case RSP_COP2_MT: - break; - - case RSP_COP2_CF: - case RSP_COP2_MF: - if (RspOp.rt == Reg) { return 0; } - break; - - default: - // CompilerWarning("Unkown opcode in IsRegisterConstant\n%s",RSPOpcodeName(RspOp.Hex,PC)); - // return 0; - break; - } - } - break; - - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - if (RspOp.rt == Reg) { return 0; } - break; - - case RSP_SB: - case RSP_SH: - case RSP_SW: - break; - case RSP_LC2: - break; - case RSP_SC2: - break; - default: - // CompilerWarning("Unkown opcode in IsRegisterConstant\n%s",RSPOpcodeName(RspOp.Hex,PC)); - // return 0; - break; - } - } - - if (References > 0) { - *Constant = Const; - return 1; - } else { - *Constant = 0; - return 0; - } -} - -/************************************************************ -** IsOpcodeBranch -** -** Output: -** 1: opcode is a branch -** 0: opcode is not a branch -** -** Input: PC -*************************************************************/ - -int32_t IsOpcodeBranch(uint32_t PC, RSPOPCODE RspOp) { - switch (RspOp.op) { - case RSP_REGIMM: - switch (RspOp.rt) { - case RSP_REGIMM_BLTZ: - case RSP_REGIMM_BGEZ: - case RSP_REGIMM_BLTZAL: - case RSP_REGIMM_BGEZAL: - return 1; - default: - //CompilerWarning("Unknown opcode in IsOpcodeBranch\n%s",RSPOpcodeName(RspOp.Hex,PC)); - break; - } - break; - case RSP_SPECIAL: - switch (RspOp.funct) { - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - case RSP_SPECIAL_BREAK: - break; - - case RSP_SPECIAL_JALR: - case RSP_SPECIAL_JR: - return 1; - - default: - //CompilerWarning("Unknown opcode in IsOpcodeBranch\n%s",RSPOpcodeName(RspOp.Hex,PC)); - break; - } - break; - case RSP_J: - case RSP_JAL: - case RSP_BEQ: - case RSP_BNE: - case RSP_BLEZ: - case RSP_BGTZ: - return 1; - - case RSP_ADDI: - case RSP_ADDIU: - case RSP_SLTI: - case RSP_SLTIU: - case RSP_ANDI: - case RSP_ORI: - case RSP_XORI: - case RSP_LUI: - - case RSP_CP0: - case RSP_CP2: - break; - - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - case RSP_SB: - case RSP_SH: - case RSP_SW: - break; - - case RSP_LC2: - case RSP_SC2: - break; - - default: - //CompilerWarning("Unknown opcode in IsOpcodeBranch\n%s",RSPOpcodeName(RspOp.Hex,PC)); - break; - } - - return 0; -} - -/************************************************************ -** GetInstructionInfo -** -** Output: None in regard to return value -** -** Input: -** pointer to info structure, fills this -** with valid opcode data -*************************************************************/ - -/* 3 possible values, GPR, VEC, VEC & GPR, NOOP is zero */ -#define GPR_Instruction 0x0001 /* GPR Instruction flag */ -#define VEC_Instruction 0x0002 /* Vec Instruction flag */ -#define Instruction_Mask (GPR_Instruction | VEC_Instruction) - -/* 3 possible values, one flag must be set only */ -#define Load_Operation 0x0004 /* Load Instruction flag */ -#define Store_Operation 0x0008 /* Store Instruction flag */ -#define Accum_Operation 0x0010 /* Vector op uses accum - loads & stores dont */ -#define MemOperation_Mask (Load_Operation | Store_Operation) -#define Operation_Mask (MemOperation_Mask | Accum_Operation) - -/* Per situation basis flags */ -#define VEC_ResetAccum 0x0000 /* Vector op resets acc */ -#define VEC_Accumulate 0x0020 /* Vector op accumulates */ - -#define InvalidOpcode 0x0040 - -typedef struct { - union { - uint32_t DestReg; - uint32_t StoredReg; - }; - union { - uint32_t SourceReg0; - uint32_t IndexReg; - }; - uint32_t SourceReg1; - uint32_t flags; -} OPCODE_INFO; - -void GetInstructionInfo(uint32_t PC, RSPOPCODE * RspOp, OPCODE_INFO * info) { - switch (RspOp->op) { - case RSP_REGIMM: - switch (RspOp->rt) { - case RSP_REGIMM_BLTZ: - case RSP_REGIMM_BLTZAL: - case RSP_REGIMM_BGEZ: - case RSP_REGIMM_BGEZAL: - info->flags = InvalidOpcode; - info->SourceReg0 = RspOp->rs; - info->SourceReg1 = -1; - break; - - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - break; - case RSP_SPECIAL: - switch (RspOp->funct) { - case RSP_SPECIAL_BREAK: - info->DestReg = -1; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction; - break; - - case RSP_SPECIAL_SLL: - case RSP_SPECIAL_SRL: - case RSP_SPECIAL_SRA: - info->DestReg = RspOp->rd; - info->SourceReg0 = RspOp->rt; - info->SourceReg1 = -1; - info->flags = GPR_Instruction; - break; - case RSP_SPECIAL_SLLV: - case RSP_SPECIAL_SRLV: - case RSP_SPECIAL_SRAV: - case RSP_SPECIAL_ADD: - case RSP_SPECIAL_ADDU: - case RSP_SPECIAL_SUB: - case RSP_SPECIAL_SUBU: - case RSP_SPECIAL_AND: - case RSP_SPECIAL_OR: - case RSP_SPECIAL_XOR: - case RSP_SPECIAL_NOR: - case RSP_SPECIAL_SLT: - case RSP_SPECIAL_SLTU: - info->DestReg = RspOp->rd; - info->SourceReg0 = RspOp->rs; - info->SourceReg1 = RspOp->rt; - info->flags = GPR_Instruction; - break; - - case RSP_SPECIAL_JR: - info->flags = InvalidOpcode; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - break; - - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - break; - case RSP_J: - case RSP_JAL: - info->flags = InvalidOpcode; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - break; - case RSP_BEQ: - case RSP_BNE: - info->flags = InvalidOpcode; - info->SourceReg0 = RspOp->rt; - info->SourceReg1 = RspOp->rs; - break; - case RSP_BLEZ: - case RSP_BGTZ: - info->flags = InvalidOpcode; - info->SourceReg0 = RspOp->rs; - info->SourceReg1 = -1; - break; - - case RSP_ADDI: - case RSP_ADDIU: - case RSP_SLTI: - case RSP_SLTIU: - case RSP_ANDI: - case RSP_ORI: - case RSP_XORI: - info->DestReg = RspOp->rt; - info->SourceReg0 = RspOp->rs; - info->SourceReg1 = -1; - info->flags = GPR_Instruction; - break; - - case RSP_LUI: - info->DestReg = RspOp->rt; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction; - break; - - case RSP_CP0: - switch (RspOp->rs) { - case RSP_COP0_MF: - info->DestReg = RspOp->rt; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction | Load_Operation; - break; - - case RSP_COP0_MT: - info->StoredReg = RspOp->rt; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction | Store_Operation; - break; - } - break; - - case RSP_CP2: - if ((RspOp->rs & 0x10) != 0) { - switch (RspOp->funct) { - case RSP_VECTOR_VNOOP: - info->DestReg = -1; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = VEC_Instruction; - break; - - case RSP_VECTOR_VMULF: - case RSP_VECTOR_VMUDL: - case RSP_VECTOR_VMUDM: - case RSP_VECTOR_VMUDN: - case RSP_VECTOR_VMUDH: - info->DestReg = RspOp->sa; - info->SourceReg0 = RspOp->rd; - info->SourceReg1 = RspOp->rt; - info->flags = VEC_Instruction | VEC_ResetAccum | Accum_Operation; - break; - case RSP_VECTOR_VMACF: - case RSP_VECTOR_VMADL: - case RSP_VECTOR_VMADM: - case RSP_VECTOR_VMADN: - case RSP_VECTOR_VMADH: - info->DestReg = RspOp->sa; - info->SourceReg0 = RspOp->rd; - info->SourceReg1 = RspOp->rt; - info->flags = VEC_Instruction | VEC_Accumulate | Accum_Operation; - break; - case RSP_VECTOR_VABS: - case RSP_VECTOR_VADD: - case RSP_VECTOR_VADDC: - case RSP_VECTOR_VSUB: - case RSP_VECTOR_VSUBC: - case RSP_VECTOR_VAND: - case RSP_VECTOR_VOR: - case RSP_VECTOR_VXOR: - case RSP_VECTOR_VNXOR: - case RSP_VECTOR_VCR: - case RSP_VECTOR_VCH: - case RSP_VECTOR_VCL: - case RSP_VECTOR_VRCP: - case RSP_VECTOR_VRCPL: - case RSP_VECTOR_VRCPH: - case RSP_VECTOR_VRSQL: - case RSP_VECTOR_VRSQH: - case RSP_VECTOR_VLT: - case RSP_VECTOR_VEQ: - case RSP_VECTOR_VGE: - info->DestReg = RspOp->sa; - info->SourceReg0 = RspOp->rd; - info->SourceReg1 = RspOp->rt; - info->flags = VEC_Instruction | VEC_ResetAccum | Accum_Operation; - break; - - case RSP_VECTOR_VMOV: - info->flags = InvalidOpcode; - /* info->DestReg = RspOp->sa; - info->SourceReg0 = RspOp->rt; - info->SourceReg1 = -1; - info->flags = VEC_Instruction; /* Assume reset? */ - break; - - case RSP_VECTOR_VMRG: - info->flags = InvalidOpcode; - /* info->DestReg = RspOp->sa; - info->SourceReg0 = RspOp->rt; - info->SourceReg1 = RspOp->rd; - info->flags = VEC_Instruction; /* Assum reset? */ - break; - - case RSP_VECTOR_VSAW: - // info->flags = InvalidOpcode; - info->DestReg = RspOp->sa; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = VEC_Instruction | Accum_Operation | VEC_Accumulate; - break; - - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - } else { - switch (RspOp->rs) { - case RSP_COP2_CT: - info->StoredReg = RspOp->rt; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction | Store_Operation; - break; - case RSP_COP2_CF: - info->DestReg = RspOp->rt; - info->SourceReg0 = -1; - info->SourceReg1 = -1; - info->flags = GPR_Instruction | Load_Operation; - break; - - /* RD is always the vector register, RT is always GPR */ - case RSP_COP2_MT: - info->DestReg = RspOp->rd; - info->SourceReg0 = RspOp->rt; - info->SourceReg1 = -1; - info->flags = VEC_Instruction | GPR_Instruction | Load_Operation; - break; - case RSP_COP2_MF: - info->DestReg = RspOp->rt; - info->SourceReg0 = RspOp->rd; - info->SourceReg1 = -1; - info->flags = VEC_Instruction | GPR_Instruction | Store_Operation; - break; - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - } - break; - case RSP_LB: - case RSP_LH: - case RSP_LW: - case RSP_LBU: - case RSP_LHU: - info->DestReg = RspOp->rt; - info->IndexReg = RspOp->base; - info->SourceReg1 = -1; - info->flags = Load_Operation | GPR_Instruction; - break; - case RSP_SB: - case RSP_SH: - case RSP_SW: - info->StoredReg = RspOp->rt; - info->IndexReg = RspOp->base; - info->SourceReg1 = -1; - info->flags = Store_Operation | GPR_Instruction; - break; - case RSP_LC2: - switch (RspOp->rd) { - case RSP_LSC2_SV: - case RSP_LSC2_DV: - case RSP_LSC2_RV: - case RSP_LSC2_QV: - case RSP_LSC2_LV: - case RSP_LSC2_UV: - case RSP_LSC2_PV: - info->DestReg = RspOp->rt; - info->IndexReg = RspOp->base; - info->SourceReg1 = -1; - info->flags = Load_Operation | VEC_Instruction; - break; - - case RSP_LSC2_TV: - info->flags = InvalidOpcode; - break; - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - break; - case RSP_SC2: - switch (RspOp->rd) { - case RSP_LSC2_BV: - case RSP_LSC2_SV: - case RSP_LSC2_LV: - case RSP_LSC2_DV: - case RSP_LSC2_QV: - case RSP_LSC2_RV: - case RSP_LSC2_PV: - case RSP_LSC2_UV: - case RSP_LSC2_HV: - case RSP_LSC2_FV: - case RSP_LSC2_WV: - info->DestReg = RspOp->rt; - info->IndexReg = RspOp->base; - info->SourceReg1 = -1; - info->flags = Store_Operation | VEC_Instruction; - break; - case RSP_LSC2_TV: - info->flags = InvalidOpcode; - break; - default: - CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - info->flags = InvalidOpcode; - break; - } - break; - default: - /* CompilerWarning("Unkown opcode in GetInstructionInfo\n%s",RSPOpcodeName(RspOp->Hex,PC)); - */ info->flags = InvalidOpcode; - break; - } -} - -/************************************************************ -** DelaySlotAffectBranch -** -** Output: -** 1: Delay slot does affect the branch -** 0: Registers do not affect each other -** -** Input: PC -*************************************************************/ - -int32_t DelaySlotAffectBranch(uint32_t PC) { - RSPOPCODE Branch, Delay; - OPCODE_INFO infoBranch, infoDelay; - - if (IsOpcodeNop(PC + 4) == 1) { - return 0; - } - - RSP_LW_IMEM(PC, &Branch.Hex); - RSP_LW_IMEM(PC+4, &Delay.Hex); - - memset(&infoDelay,0,sizeof(infoDelay)); - memset(&infoBranch,0,sizeof(infoBranch)); - - GetInstructionInfo(PC, &Branch, &infoBranch); - GetInstructionInfo(PC+4, &Delay, &infoDelay); - - if ((infoDelay.flags & Instruction_Mask) == VEC_Instruction) { - return 0; - } - - if (infoBranch.SourceReg0 == infoDelay.DestReg) { return 1; } - if (infoBranch.SourceReg1 == infoDelay.DestReg) { return 1; } - - return 0; -} - -/************************************************************ -** CompareInstructions -** -** Output: -** 1: The opcodes are fine, no dependency -** 0: Watch it, these ops cant be touched -** -** Input: -** Top, not the current operation, the one above -** Bottom: the current opcode for re-ordering bubble style -*************************************************************/ - -int32_t CompareInstructions(uint32_t PC, RSPOPCODE * Top, RSPOPCODE * Bottom) { - - OPCODE_INFO info0, info1; - uint32_t InstructionType; - - GetInstructionInfo(PC - 4, Top, &info0); - GetInstructionInfo(PC, Bottom, &info1); - - /* usually branches and such */ - if ((info0.flags & InvalidOpcode) != 0) return 0; - if ((info1.flags & InvalidOpcode) != 0) return 0; - - InstructionType = (info0.flags & Instruction_Mask) << 2; - InstructionType |= info1.flags & Instruction_Mask; - InstructionType &= 0x0F; /* Paranoia */ - - /* 4 bit range, 16 possible combinations */ - switch (InstructionType) { - /* - ** Detect noop instruction, 7 cases, (see flags) */ - case 0x01: case 0x02: case 0x03: /* First is a noop */ - return 1; - case 0x00: /* Both ??? */ - case 0x10: case 0x20: case 0x30: /* Second is a noop */ - return 0; - - case 0x06: /* GPR than Vector - 01,10 */ - if ((info0.flags & MemOperation_Mask) != 0 && (info1.flags & MemOperation_Mask) != 0) { - /* TODO: We have a vector & GPR memory operation */ - return 0; - } else if ((info1.flags & MemOperation_Mask) != 0) { - /* We have a vector memory operation */ - return (info1.IndexReg == info0.DestReg) ? 0 : 1; - } else { - /* We could have memory or normal gpr instruction here - ** paired with some kind of vector operation - */ - return 1; - } - return 0; - - case 0x0A: /* Vector than Vector - 10,10 */ - - /* - ** Check for Vector Store than Vector multiply (VMULF) - ** - ** This basically gives preferences to putting stores - ** as close to the finish of an operation as possible - */ - if ((info0.flags & Store_Operation) != 0 && (info1.flags & Accum_Operation) != 0 - && !(info1.flags & VEC_Accumulate)) { return 0; } - - /* - ** Look for loads and than some kind of vector operation - ** that does no accumulating, there is no reason to reorder - */ - if ((info0.flags & Load_Operation) != 0 && (info1.flags & Accum_Operation) != 0 - && !(info1.flags & VEC_Accumulate)) { return 0; } - - if ((info0.flags & MemOperation_Mask) != 0 && (info1.flags & MemOperation_Mask) != 0) { - /* - ** TODO: This is a bitch, its best to leave it alone - **/ - return 0; - } else if ((info1.flags & MemOperation_Mask) != 0) { - /* Remember stored reg & loaded reg are the same */ - if (info0.DestReg == info1.DestReg) { return 0; } - - if (info1.flags & Load_Operation) { - if (info0.SourceReg0 == info1.DestReg) { return 0; } - if (info0.SourceReg1 == info1.DestReg) { return 0; } - } else if (info1.flags & Store_Operation) { - /* It can store source regs */ - return 1; - } - - return 1; - } else if ((info0.flags & MemOperation_Mask) != 0) { - /* Remember stored reg & loaded reg are the same */ - if (info0.DestReg == info1.DestReg) { return 0; } - - if (info0.flags & Load_Operation) { - if (info1.SourceReg0 == info0.DestReg) { return 0; } - if (info1.SourceReg1 == info0.DestReg) { return 0; } - } else if (info0.flags & Store_Operation) { - /* It can store source regs */ - return 1; - } - - return 1; - } else if ((info0.flags & VEC_Accumulate) != 0) { - /* - ** Example: - ** VMACF - ** VMUDH or VMADH or VADD - */ - - return 0; - } else if ((info1.flags & VEC_Accumulate) != 0) { - /* - ** Example: - ** VMULF - ** VMADH - */ - - return 0; - } else { - /* - ** Example: - ** VMULF or VADDC - ** VADD or VMUDH - */ - - return 0; - } - break; - - case 0x09: /* Vector than GPR - 10,01 */ - /********** - ** this is where the bias comes into play, otherwise - ** we can sit here all day swapping these 2 types - ***********/ - return 0; - - case 0x05: /* GPR than GPR - 01,01 */ - case 0x07: /* GPR than Cop2 - 01, 11 */ - case 0x0D: /* Cop2 than GPR - 11, 01 */ - case 0x0F: /* Cop2 than Cop2 - 11, 11 */ - return 0; - - case 0x0B: /* Vector than Cop2 - 10, 11 */ - if (info1.flags & Load_Operation) { - /* Move To Cop2 (dest) from GPR (source) */ - if (info1.DestReg == info0.DestReg) { return 0; } - if (info1.DestReg == info0.SourceReg0) { return 0; } - if (info1.DestReg == info0.SourceReg1) { return 0; } - } else if (info1.flags & Store_Operation) { - /* Move From Cop2 (source) to GPR (dest) */ - if (info1.SourceReg0 == info0.DestReg) { return 0; } - if (info1.SourceReg0 == info0.SourceReg0) { return 0; } - if (info1.SourceReg0 == info0.SourceReg1) { return 0; } - } else { - //CompilerWarning("ReOrder: Unhandled Vector than Cop2"); - } - // we want vectors on top - return 0; - - case 0x0E: /* Cop2 than Vector - 11, 10 */ - if (info0.flags & Load_Operation) { - /* Move To Cop2 (dest) from GPR (source) */ - if (info0.DestReg == info1.DestReg) { return 0; } - if (info0.DestReg == info1.SourceReg0) { return 0; } - if (info0.DestReg == info1.SourceReg1) { return 0; } - } else if (info0.flags & Store_Operation) { - /* Move From Cop2 (source) to GPR (dest) */ - if (info0.SourceReg0 == info1.DestReg) { return 0; } - if (info0.SourceReg0 == info1.SourceReg0) { return 0; } - if (info0.SourceReg0 == info1.SourceReg1) { return 0; } - } else { - //CompilerWarning("ReOrder: Unhandled Cop2 than Vector"); - } - // we want this at the top - return 1; - - default: - CompilerWarning("ReOrder: Unhandled instruction type: %i", InstructionType); - } - - return 0; -} diff --git a/src/usf/rsp_recompiler_cpu.c b/src/usf/rsp_recompiler_cpu.c deleted file mode 100644 index f26f075..0000000 --- a/src/usf/rsp_recompiler_cpu.c +++ /dev/null @@ -1,954 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 -#include -#include -#include "rsp.h" -#include "rsp_recompiler_cpu.h" -#include "rsp_recompiler_ops.h" -#include "rsp_x86.h" -#include "recompiler_cpu.h" -#include "memory.h" -#include "main.h" -#include "usf.h" -#include "types.h" - -/* #define REORDER_BLOCK_VERBOSE */ -#define LINK_BRANCHES_VERBOSE /* no choice really */ -#define X86_RECOMP_VERBOSE -#define BUILD_BRANCHLABELS_VERBOSE - -uint32_t RSPCompilePC, RSPBlockID = 0; -uint32_t dwBuffer = MainBuffer; - -RSP_BLOCK RSPCurrentBlock; -RSP_CODE RspCode; - -uint8_t * pLastSecondary = NULL, * pLastPrimary = NULL; - -void BuildRecompilerCPU ( void ) { - RSP_Opcode[ 0] = RSPCompile_SPECIAL; - RSP_Opcode[ 1] = RSPCompile_REGIMM; - RSP_Opcode[ 2] = RSPCompile_J; - RSP_Opcode[ 3] = RSPCompile_JAL; - RSP_Opcode[ 4] = RSPCompile_BEQ; - RSP_Opcode[ 5] = RSPCompile_BNE; - RSP_Opcode[ 6] = RSPCompile_BLEZ; - RSP_Opcode[ 7] = RSPCompile_BGTZ; - RSP_Opcode[ 8] = RSPCompile_ADDI; - RSP_Opcode[ 9] = RSPCompile_ADDIU; - RSP_Opcode[10] = RSPCompile_SLTI; - RSP_Opcode[11] = RSPCompile_SLTIU; - RSP_Opcode[12] = RSPCompile_ANDI; - RSP_Opcode[13] = RSPCompile_ORI; - RSP_Opcode[14] = RSPCompile_XORI; - RSP_Opcode[15] = RSPCompile_LUI; - RSP_Opcode[16] = RSPCompile_COP0; - RSP_Opcode[17] = RSPCompile_UnknownOpcode; - RSP_Opcode[18] = RSPCompile_COP2; - RSP_Opcode[19] = RSPCompile_UnknownOpcode; - RSP_Opcode[20] = RSPCompile_UnknownOpcode; - RSP_Opcode[21] = RSPCompile_UnknownOpcode; - RSP_Opcode[22] = RSPCompile_UnknownOpcode; - RSP_Opcode[23] = RSPCompile_UnknownOpcode; - RSP_Opcode[24] = RSPCompile_UnknownOpcode; - RSP_Opcode[25] = RSPCompile_UnknownOpcode; - RSP_Opcode[26] = RSPCompile_UnknownOpcode; - RSP_Opcode[27] = RSPCompile_UnknownOpcode; - RSP_Opcode[28] = RSPCompile_UnknownOpcode; - RSP_Opcode[29] = RSPCompile_UnknownOpcode; - RSP_Opcode[30] = RSPCompile_UnknownOpcode; - RSP_Opcode[31] = RSPCompile_UnknownOpcode; - RSP_Opcode[32] = RSPCompile_LB; - RSP_Opcode[33] = RSPCompile_LH; - RSP_Opcode[34] = RSPCompile_UnknownOpcode; - RSP_Opcode[35] = RSPCompile_LW; - RSP_Opcode[36] = RSPCompile_LBU; - RSP_Opcode[37] = RSPCompile_LHU; - RSP_Opcode[38] = RSPCompile_UnknownOpcode; - RSP_Opcode[39] = RSPCompile_UnknownOpcode; - RSP_Opcode[40] = RSPCompile_SB; - RSP_Opcode[41] = RSPCompile_SH; - RSP_Opcode[42] = RSPCompile_UnknownOpcode; - RSP_Opcode[43] = RSPCompile_SW; - RSP_Opcode[44] = RSPCompile_UnknownOpcode; - RSP_Opcode[45] = RSPCompile_UnknownOpcode; - RSP_Opcode[46] = RSPCompile_UnknownOpcode; - RSP_Opcode[47] = RSPCompile_UnknownOpcode; - RSP_Opcode[48] = RSPCompile_UnknownOpcode; - RSP_Opcode[49] = RSPCompile_UnknownOpcode; - RSP_Opcode[50] = RSPCompile_LC2; - RSP_Opcode[51] = RSPCompile_UnknownOpcode; - RSP_Opcode[52] = RSPCompile_UnknownOpcode; - RSP_Opcode[53] = RSPCompile_UnknownOpcode; - RSP_Opcode[54] = RSPCompile_UnknownOpcode; - RSP_Opcode[55] = RSPCompile_UnknownOpcode; - RSP_Opcode[56] = RSPCompile_UnknownOpcode; - RSP_Opcode[57] = RSPCompile_UnknownOpcode; - RSP_Opcode[58] = RSPCompile_SC2; - RSP_Opcode[59] = RSPCompile_UnknownOpcode; - RSP_Opcode[60] = RSPCompile_UnknownOpcode; - RSP_Opcode[61] = RSPCompile_UnknownOpcode; - RSP_Opcode[62] = RSPCompile_UnknownOpcode; - RSP_Opcode[63] = RSPCompile_UnknownOpcode; - - RSP_Special[ 0] = RSPCompile_Special_SLL; - RSP_Special[ 1] = RSPCompile_UnknownOpcode; - RSP_Special[ 2] = RSPCompile_Special_SRL; - RSP_Special[ 3] = RSPCompile_Special_SRA; - RSP_Special[ 4] = RSPCompile_Special_SLLV; - RSP_Special[ 5] = RSPCompile_UnknownOpcode; - RSP_Special[ 6] = RSPCompile_Special_SRLV; - RSP_Special[ 7] = RSPCompile_Special_SRAV; - RSP_Special[ 8] = RSPCompile_Special_JR; - RSP_Special[ 9] = RSPCompile_Special_JALR; - RSP_Special[10] = RSPCompile_UnknownOpcode; - RSP_Special[11] = RSPCompile_UnknownOpcode; - RSP_Special[12] = RSPCompile_UnknownOpcode; - RSP_Special[13] = RSPCompile_Special_BREAK; - RSP_Special[14] = RSPCompile_UnknownOpcode; - RSP_Special[15] = RSPCompile_UnknownOpcode; - RSP_Special[16] = RSPCompile_UnknownOpcode; - RSP_Special[17] = RSPCompile_UnknownOpcode; - RSP_Special[18] = RSPCompile_UnknownOpcode; - RSP_Special[19] = RSPCompile_UnknownOpcode; - RSP_Special[20] = RSPCompile_UnknownOpcode; - RSP_Special[21] = RSPCompile_UnknownOpcode; - RSP_Special[22] = RSPCompile_UnknownOpcode; - RSP_Special[23] = RSPCompile_UnknownOpcode; - RSP_Special[24] = RSPCompile_UnknownOpcode; - RSP_Special[25] = RSPCompile_UnknownOpcode; - RSP_Special[26] = RSPCompile_UnknownOpcode; - RSP_Special[27] = RSPCompile_UnknownOpcode; - RSP_Special[28] = RSPCompile_UnknownOpcode; - RSP_Special[29] = RSPCompile_UnknownOpcode; - RSP_Special[30] = RSPCompile_UnknownOpcode; - RSP_Special[31] = RSPCompile_UnknownOpcode; - RSP_Special[32] = RSPCompile_Special_ADD; - RSP_Special[33] = RSPCompile_Special_ADDU; - RSP_Special[34] = RSPCompile_Special_SUB; - RSP_Special[35] = RSPCompile_Special_SUBU; - RSP_Special[36] = RSPCompile_Special_AND; - RSP_Special[37] = RSPCompile_Special_OR; - RSP_Special[38] = RSPCompile_Special_XOR; - RSP_Special[39] = RSPCompile_Special_NOR; - RSP_Special[40] = RSPCompile_UnknownOpcode; - RSP_Special[41] = RSPCompile_UnknownOpcode; - RSP_Special[42] = RSPCompile_Special_SLT; - RSP_Special[43] = RSPCompile_Special_SLTU; - RSP_Special[44] = RSPCompile_UnknownOpcode; - RSP_Special[45] = RSPCompile_UnknownOpcode; - RSP_Special[46] = RSPCompile_UnknownOpcode; - RSP_Special[47] = RSPCompile_UnknownOpcode; - RSP_Special[48] = RSPCompile_UnknownOpcode; - RSP_Special[49] = RSPCompile_UnknownOpcode; - RSP_Special[50] = RSPCompile_UnknownOpcode; - RSP_Special[51] = RSPCompile_UnknownOpcode; - RSP_Special[52] = RSPCompile_UnknownOpcode; - RSP_Special[53] = RSPCompile_UnknownOpcode; - RSP_Special[54] = RSPCompile_UnknownOpcode; - RSP_Special[55] = RSPCompile_UnknownOpcode; - RSP_Special[56] = RSPCompile_UnknownOpcode; - RSP_Special[57] = RSPCompile_UnknownOpcode; - RSP_Special[58] = RSPCompile_UnknownOpcode; - RSP_Special[59] = RSPCompile_UnknownOpcode; - RSP_Special[60] = RSPCompile_UnknownOpcode; - RSP_Special[61] = RSPCompile_UnknownOpcode; - RSP_Special[62] = RSPCompile_UnknownOpcode; - RSP_Special[63] = RSPCompile_UnknownOpcode; - - RSP_RegImm[ 0] = RSPCompile_RegImm_BLTZ; - RSP_RegImm[ 1] = RSPCompile_RegImm_BGEZ; - RSP_RegImm[ 2] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 3] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 4] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 5] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 6] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 7] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 8] = RSPCompile_UnknownOpcode; - RSP_RegImm[ 9] = RSPCompile_UnknownOpcode; - RSP_RegImm[10] = RSPCompile_UnknownOpcode; - RSP_RegImm[11] = RSPCompile_UnknownOpcode; - RSP_RegImm[12] = RSPCompile_UnknownOpcode; - RSP_RegImm[13] = RSPCompile_UnknownOpcode; - RSP_RegImm[14] = RSPCompile_UnknownOpcode; - RSP_RegImm[15] = RSPCompile_UnknownOpcode; - RSP_RegImm[16] = RSPCompile_RegImm_BLTZAL; - RSP_RegImm[17] = RSPCompile_RegImm_BGEZAL; - RSP_RegImm[18] = RSPCompile_UnknownOpcode; - RSP_RegImm[19] = RSPCompile_UnknownOpcode; - RSP_RegImm[20] = RSPCompile_UnknownOpcode; - RSP_RegImm[21] = RSPCompile_UnknownOpcode; - RSP_RegImm[22] = RSPCompile_UnknownOpcode; - RSP_RegImm[23] = RSPCompile_UnknownOpcode; - RSP_RegImm[24] = RSPCompile_UnknownOpcode; - RSP_RegImm[25] = RSPCompile_UnknownOpcode; - RSP_RegImm[26] = RSPCompile_UnknownOpcode; - RSP_RegImm[27] = RSPCompile_UnknownOpcode; - RSP_RegImm[28] = RSPCompile_UnknownOpcode; - RSP_RegImm[29] = RSPCompile_UnknownOpcode; - RSP_RegImm[30] = RSPCompile_UnknownOpcode; - RSP_RegImm[31] = RSPCompile_UnknownOpcode; - - RSP_Cop0[ 0] = RSPCompile_Cop0_MF; - RSP_Cop0[ 1] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 2] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 3] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 4] = RSPCompile_Cop0_MT; - RSP_Cop0[ 5] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 6] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 7] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 8] = RSPCompile_UnknownOpcode; - RSP_Cop0[ 9] = RSPCompile_UnknownOpcode; - RSP_Cop0[10] = RSPCompile_UnknownOpcode; - RSP_Cop0[11] = RSPCompile_UnknownOpcode; - RSP_Cop0[12] = RSPCompile_UnknownOpcode; - RSP_Cop0[13] = RSPCompile_UnknownOpcode; - RSP_Cop0[14] = RSPCompile_UnknownOpcode; - RSP_Cop0[15] = RSPCompile_UnknownOpcode; - RSP_Cop0[16] = RSPCompile_UnknownOpcode; - RSP_Cop0[17] = RSPCompile_UnknownOpcode; - RSP_Cop0[18] = RSPCompile_UnknownOpcode; - RSP_Cop0[19] = RSPCompile_UnknownOpcode; - RSP_Cop0[20] = RSPCompile_UnknownOpcode; - RSP_Cop0[21] = RSPCompile_UnknownOpcode; - RSP_Cop0[22] = RSPCompile_UnknownOpcode; - RSP_Cop0[23] = RSPCompile_UnknownOpcode; - RSP_Cop0[24] = RSPCompile_UnknownOpcode; - RSP_Cop0[25] = RSPCompile_UnknownOpcode; - RSP_Cop0[26] = RSPCompile_UnknownOpcode; - RSP_Cop0[27] = RSPCompile_UnknownOpcode; - RSP_Cop0[28] = RSPCompile_UnknownOpcode; - RSP_Cop0[29] = RSPCompile_UnknownOpcode; - RSP_Cop0[30] = RSPCompile_UnknownOpcode; - RSP_Cop0[31] = RSPCompile_UnknownOpcode; - - RSP_Cop2[ 0] = RSPCompile_Cop2_MF; - RSP_Cop2[ 1] = RSPCompile_UnknownOpcode; - RSP_Cop2[ 2] = RSPCompile_Cop2_CF; - RSP_Cop2[ 3] = RSPCompile_UnknownOpcode; - RSP_Cop2[ 4] = RSPCompile_Cop2_MT; - RSP_Cop2[ 5] = RSPCompile_UnknownOpcode; - RSP_Cop2[ 6] = RSPCompile_Cop2_CT; - RSP_Cop2[ 7] = RSPCompile_UnknownOpcode; - RSP_Cop2[ 8] = RSPCompile_UnknownOpcode; - RSP_Cop2[ 9] = RSPCompile_UnknownOpcode; - RSP_Cop2[10] = RSPCompile_UnknownOpcode; - RSP_Cop2[11] = RSPCompile_UnknownOpcode; - RSP_Cop2[12] = RSPCompile_UnknownOpcode; - RSP_Cop2[13] = RSPCompile_UnknownOpcode; - RSP_Cop2[14] = RSPCompile_UnknownOpcode; - RSP_Cop2[15] = RSPCompile_UnknownOpcode; - RSP_Cop2[16] = RSPCompile_COP2_VECTOR; - RSP_Cop2[17] = RSPCompile_COP2_VECTOR; - RSP_Cop2[18] = RSPCompile_COP2_VECTOR; - RSP_Cop2[19] = RSPCompile_COP2_VECTOR; - RSP_Cop2[20] = RSPCompile_COP2_VECTOR; - RSP_Cop2[21] = RSPCompile_COP2_VECTOR; - RSP_Cop2[22] = RSPCompile_COP2_VECTOR; - RSP_Cop2[23] = RSPCompile_COP2_VECTOR; - RSP_Cop2[24] = RSPCompile_COP2_VECTOR; - RSP_Cop2[25] = RSPCompile_COP2_VECTOR; - RSP_Cop2[26] = RSPCompile_COP2_VECTOR; - RSP_Cop2[27] = RSPCompile_COP2_VECTOR; - RSP_Cop2[28] = RSPCompile_COP2_VECTOR; - RSP_Cop2[29] = RSPCompile_COP2_VECTOR; - RSP_Cop2[30] = RSPCompile_COP2_VECTOR; - RSP_Cop2[31] = RSPCompile_COP2_VECTOR; - - RSP_Vector[ 0] = RSPCompile_Vector_VMULF; - RSP_Vector[ 1] = RSPCompile_Vector_VMULU; - RSP_Vector[ 2] = RSPCompile_UnknownOpcode; - RSP_Vector[ 3] = RSPCompile_UnknownOpcode; - RSP_Vector[ 4] = RSPCompile_Vector_VMUDL; - RSP_Vector[ 5] = RSPCompile_Vector_VMUDM; - RSP_Vector[ 6] = RSPCompile_Vector_VMUDN; - RSP_Vector[ 7] = RSPCompile_Vector_VMUDH; - RSP_Vector[ 8] = RSPCompile_Vector_VMACF; - RSP_Vector[ 9] = RSPCompile_Vector_VMACU; - RSP_Vector[10] = RSPCompile_UnknownOpcode; - RSP_Vector[11] = RSPCompile_Vector_VMACQ; - RSP_Vector[12] = RSPCompile_Vector_VMADL; - RSP_Vector[13] = RSPCompile_Vector_VMADM; - RSP_Vector[14] = RSPCompile_Vector_VMADN; - RSP_Vector[15] = RSPCompile_Vector_VMADH; - RSP_Vector[16] = RSPCompile_Vector_VADD; - RSP_Vector[17] = RSPCompile_Vector_VSUB; - RSP_Vector[18] = RSPCompile_UnknownOpcode; - RSP_Vector[19] = RSPCompile_Vector_VABS; - RSP_Vector[20] = RSPCompile_Vector_VADDC; - RSP_Vector[21] = RSPCompile_Vector_VSUBC; - RSP_Vector[22] = RSPCompile_UnknownOpcode; - RSP_Vector[23] = RSPCompile_UnknownOpcode; - RSP_Vector[24] = RSPCompile_UnknownOpcode; - RSP_Vector[25] = RSPCompile_UnknownOpcode; - RSP_Vector[26] = RSPCompile_UnknownOpcode; - RSP_Vector[27] = RSPCompile_UnknownOpcode; - RSP_Vector[28] = RSPCompile_UnknownOpcode; - RSP_Vector[29] = RSPCompile_Vector_VSAW; - RSP_Vector[30] = RSPCompile_UnknownOpcode; - RSP_Vector[31] = RSPCompile_UnknownOpcode; - RSP_Vector[32] = RSPCompile_Vector_VLT; - RSP_Vector[33] = RSPCompile_Vector_VEQ; - RSP_Vector[34] = RSPCompile_Vector_VNE; - RSP_Vector[35] = RSPCompile_Vector_VGE; - RSP_Vector[36] = RSPCompile_Vector_VCL; - RSP_Vector[37] = RSPCompile_Vector_VCH; - RSP_Vector[38] = RSPCompile_Vector_VCR; - RSP_Vector[39] = RSPCompile_Vector_VMRG; - RSP_Vector[40] = RSPCompile_Vector_VAND; - RSP_Vector[41] = RSPCompile_Vector_VNAND; - RSP_Vector[42] = RSPCompile_Vector_VOR; - RSP_Vector[43] = RSPCompile_Vector_VNOR; - RSP_Vector[44] = RSPCompile_Vector_VXOR; - RSP_Vector[45] = RSPCompile_Vector_VNXOR; - RSP_Vector[46] = RSPCompile_UnknownOpcode; - RSP_Vector[47] = RSPCompile_UnknownOpcode; - RSP_Vector[48] = RSPCompile_Vector_VRCP; - RSP_Vector[49] = RSPCompile_Vector_VRCPL; - RSP_Vector[50] = RSPCompile_Vector_VRCPH; - RSP_Vector[51] = RSPCompile_Vector_VMOV; - RSP_Vector[52] = RSPCompile_Vector_VRSQ; - RSP_Vector[53] = RSPCompile_Vector_VRSQL; - RSP_Vector[54] = RSPCompile_Vector_VRSQH; - RSP_Vector[55] = RSPCompile_Vector_VNOOP; - RSP_Vector[56] = RSPCompile_UnknownOpcode; - RSP_Vector[57] = RSPCompile_UnknownOpcode; - RSP_Vector[58] = RSPCompile_UnknownOpcode; - RSP_Vector[59] = RSPCompile_UnknownOpcode; - RSP_Vector[60] = RSPCompile_UnknownOpcode; - RSP_Vector[61] = RSPCompile_UnknownOpcode; - RSP_Vector[62] = RSPCompile_UnknownOpcode; - RSP_Vector[63] = RSPCompile_UnknownOpcode; - - RSP_Lc2[ 0] = RSPCompile_Opcode_LBV; - RSP_Lc2[ 1] = RSPCompile_Opcode_LSV; - RSP_Lc2[ 2] = RSPCompile_Opcode_LLV; - RSP_Lc2[ 3] = RSPCompile_Opcode_LDV; - RSP_Lc2[ 4] = RSPCompile_Opcode_LQV; - RSP_Lc2[ 5] = RSPCompile_Opcode_LRV; - RSP_Lc2[ 6] = RSPCompile_Opcode_LPV; - RSP_Lc2[ 7] = RSPCompile_Opcode_LUV; - RSP_Lc2[ 8] = RSPCompile_UnknownOpcode; - RSP_Lc2[ 9] = RSPCompile_UnknownOpcode; - RSP_Lc2[10] = RSPCompile_UnknownOpcode; - RSP_Lc2[11] = RSPCompile_Opcode_LTV; - RSP_Lc2[12] = RSPCompile_UnknownOpcode; - RSP_Lc2[13] = RSPCompile_UnknownOpcode; - RSP_Lc2[14] = RSPCompile_UnknownOpcode; - RSP_Lc2[15] = RSPCompile_UnknownOpcode; - RSP_Lc2[16] = RSPCompile_UnknownOpcode; - RSP_Lc2[17] = RSPCompile_UnknownOpcode; - RSP_Lc2[18] = RSPCompile_UnknownOpcode; - RSP_Lc2[19] = RSPCompile_UnknownOpcode; - RSP_Lc2[20] = RSPCompile_UnknownOpcode; - RSP_Lc2[21] = RSPCompile_UnknownOpcode; - RSP_Lc2[22] = RSPCompile_UnknownOpcode; - RSP_Lc2[23] = RSPCompile_UnknownOpcode; - RSP_Lc2[24] = RSPCompile_UnknownOpcode; - RSP_Lc2[25] = RSPCompile_UnknownOpcode; - RSP_Lc2[26] = RSPCompile_UnknownOpcode; - RSP_Lc2[27] = RSPCompile_UnknownOpcode; - RSP_Lc2[28] = RSPCompile_UnknownOpcode; - RSP_Lc2[29] = RSPCompile_UnknownOpcode; - RSP_Lc2[30] = RSPCompile_UnknownOpcode; - RSP_Lc2[31] = RSPCompile_UnknownOpcode; - - RSP_Sc2[ 0] = RSPCompile_Opcode_SBV; - RSP_Sc2[ 1] = RSPCompile_Opcode_SSV; - RSP_Sc2[ 2] = RSPCompile_Opcode_SLV; - RSP_Sc2[ 3] = RSPCompile_Opcode_SDV; - RSP_Sc2[ 4] = RSPCompile_Opcode_SQV; - RSP_Sc2[ 5] = RSPCompile_Opcode_SRV; - RSP_Sc2[ 6] = RSPCompile_Opcode_SPV; - RSP_Sc2[ 7] = RSPCompile_Opcode_SUV; - RSP_Sc2[ 8] = RSPCompile_UnknownOpcode; - RSP_Sc2[ 9] = RSPCompile_UnknownOpcode; - RSP_Sc2[10] = RSPCompile_UnknownOpcode; - RSP_Sc2[11] = RSPCompile_Opcode_STV; - RSP_Sc2[12] = RSPCompile_UnknownOpcode; - RSP_Sc2[13] = RSPCompile_UnknownOpcode; - RSP_Sc2[14] = RSPCompile_UnknownOpcode; - RSP_Sc2[15] = RSPCompile_UnknownOpcode; - RSP_Sc2[16] = RSPCompile_UnknownOpcode; - RSP_Sc2[17] = RSPCompile_UnknownOpcode; - RSP_Sc2[18] = RSPCompile_UnknownOpcode; - RSP_Sc2[19] = RSPCompile_UnknownOpcode; - RSP_Sc2[20] = RSPCompile_UnknownOpcode; - RSP_Sc2[21] = RSPCompile_UnknownOpcode; - RSP_Sc2[22] = RSPCompile_UnknownOpcode; - RSP_Sc2[23] = RSPCompile_UnknownOpcode; - RSP_Sc2[24] = RSPCompile_UnknownOpcode; - RSP_Sc2[25] = RSPCompile_UnknownOpcode; - RSP_Sc2[26] = RSPCompile_UnknownOpcode; - RSP_Sc2[27] = RSPCompile_UnknownOpcode; - RSP_Sc2[28] = RSPCompile_UnknownOpcode; - RSP_Sc2[29] = RSPCompile_UnknownOpcode; - RSP_Sc2[30] = RSPCompile_UnknownOpcode; - RSP_Sc2[31] = RSPCompile_UnknownOpcode; - - RSPBlockID = 0; -} - -/****************************************************** -** ReOrderSubBlock -** -** Desc: -** this can be done, but will be interesting to put -** between branches labels, and actual branches, whichever -** occurs first in code -** -********************************************************/ - -void ReOrderInstructions(uint32_t StartPC, uint32_t EndPC) { - uint32_t InstructionCount = EndPC - StartPC; - uint32_t Count, ReorderedOps, CurrentPC; - RSPOPCODE PreviousOp, CurrentOp, RspOp; - - PreviousOp.Hex = *(uint32_t*)(IMEM + StartPC); - - if (1 == IsOpcodeBranch(StartPC, PreviousOp)) { - /* the sub block ends here anyway */ - return; - } - - if (IsOpcodeNop(StartPC) && IsOpcodeNop(StartPC + 4) && IsOpcodeNop(StartPC + 8)) { - /* Dont even bother */ - return; - } - - CPU_Message("***** Doing reorder (%X to %X) *****", StartPC, EndPC); - - if (InstructionCount < 0x0010) { return; } - if (InstructionCount > 0x0A00) { return; } - - CPU_Message(" Before:"); - for (Count = StartPC; Count < EndPC; Count += 4) { - RSP_LW_IMEM(Count, &RspOp.Hex); - //CPU_Message(" %X %s",Count,RSPOpcodeName(RspOp.Hex,Count)); - } - - for (Count = 0; Count < InstructionCount; Count += 4) { - CurrentPC = StartPC; - PreviousOp.Hex = *(uint32_t*)(IMEM + CurrentPC); - ReorderedOps = 0; - - for (;;) { - CurrentPC += 4; - if (CurrentPC >= EndPC) { break; } - CurrentOp.Hex = *(uint32_t*)(IMEM + CurrentPC); - - if (1 == CompareInstructions(CurrentPC, &PreviousOp, &CurrentOp)) { - /* Move current opcode up */ - *(uint32_t*)(IMEM + CurrentPC - 4) = CurrentOp.Hex; - *(uint32_t*)(IMEM + CurrentPC) = PreviousOp.Hex; - - ReorderedOps++; - #ifdef REORDER_BLOCK_VERBOSE - CPU_Message("Swapped %X and %X", CurrentPC - 4, CurrentPC); - #endif - } - PreviousOp.Hex = *(uint32_t*)(IMEM + CurrentPC); - - if (IsOpcodeNop(CurrentPC) && IsOpcodeNop(CurrentPC + 4) && IsOpcodeNop(CurrentPC + 8)) { - CurrentPC = EndPC; - } - } - - if (ReorderedOps == 0) { - Count = InstructionCount; - } - } - - CPU_Message(" After:"); - for (Count = StartPC; Count < EndPC; Count += 4) { - RSP_LW_IMEM(Count, &RspOp.Hex); - //CPU_Message(" %X %s",Count,RSPOpcodeName(RspOp.Hex,Count)); - } - CPU_Message(""); -} - -void ReOrderSubBlock(RSP_BLOCK * Block) { - uint32_t end = 0x0ffc; - uint32_t count; - - //return; //fixthis - if (!Compiler.bReOrdering) { - return; - } - if (Block->CurrPC > 0xFF0) { - return; - } - - /* find the label or jump closest to us */ - if (RspCode.LabelCount) { - for (count = 0; count < RspCode.LabelCount; count++) { - if (RspCode.BranchLabels[count] < end && - RspCode.BranchLabels[count] > Block->CurrPC) { - end = RspCode.BranchLabels[count]; - } - } - } - if (RspCode.BranchCount) { - for (count = 0; count < RspCode.BranchCount; count++) { - if (RspCode.BranchLocations[count] < end && - RspCode.BranchLocations[count] > Block->CurrPC) { - end = RspCode.BranchLocations[count]; - } - } - } - - /* it wont actually re-order the op at the end */ - ReOrderInstructions(Block->CurrPC, end); -} - -/****************************************************** -** DetectGPRConstants -** -** Desc: -** this needs to be called on a sub-block basis, like -** after every time we hit a branch and delay slot -** -********************************************************/ - -void DetectGPRConstants(RSP_CODE * code) { - uint32_t Count, Constant = 0; - - memset(&code->bIsRegConst, 0, sizeof(int32_t) * 0x20); - memset(&code->MipsRegConst, 0, sizeof(uint32_t) * 0x20); - - if (!Compiler.bGPRConstants) { - return; - } - CPU_Message("***** Detecting constants *****"); - - /*** Setup R0 ***/ - code->bIsRegConst[0] = 1; - code->MipsRegConst[0] = 0; - - /* Do your global search for them */ - for (Count = 1; Count < 32; Count++) { - if (IsRegisterConstant(Count, &Constant) == 1) { - //CPU_Message("Global: %s is a constant of: %08X", GPR_Name(Count), Constant); - code->bIsRegConst[Count] = 1; - code->MipsRegConst[Count] = Constant; - } - } - CPU_Message(""); -} - -/****************************************************** -** CompilerToggleBuffer and ClearX86Code -** -** Desc: -** 1> toggles the compiler buffer, useful for poorly -** taken branches like alignment -** -** 2> clears all the x86 code, jump tables etc -** -********************************************************/ - -void CompilerToggleBuffer(void) { - if (dwBuffer == MainBuffer) { - dwBuffer = SecondaryBuffer; - pLastPrimary = RSPRecompPos; - - if (pLastSecondary == NULL) { - pLastSecondary = RSPRecompCodeSecondary; - } - - RSPRecompPos = pLastSecondary; - CPU_Message(" (Secondary Buffer Active 0x%08X)", pLastSecondary); - } else { - dwBuffer = MainBuffer; - pLastSecondary = RSPRecompPos; - - if (pLastPrimary == NULL) { - pLastPrimary = RSPRecompCode; - } - - RSPRecompPos = pLastPrimary; - CPU_Message(" (Primary Buffer Active 0x%08X)", pLastPrimary); - } -} - -void ClearAllx86Code (void) { - extern uint32_t NoOfMaps, MapsCRC[32]; - extern uint8_t *RSPJumpTables; - - memset(&MapsCRC, 0, sizeof(uint32_t) * 0x20); - NoOfMaps = 0; - memset(RSPJumpTables,0,0x2000*32); - - RSPRecompPos = RSPRecompCode; - - pLastPrimary = NULL; - pLastSecondary = NULL; -} - -/****************************************************** -** Link Branches -** -** Desc: -** resolves all the collected branches, x86 style -** -********************************************************/ - -void LinkBranches(RSP_BLOCK * Block) { - uint32_t Count, Target; - uint32_t * JumpWord; - uint8_t * X86Code; - RSP_BLOCK Save; - - if (!RSPCurrentBlock.ResolveCount) { - return; - } - CPU_Message("***** Linking branches (%i) *****", RSPCurrentBlock.ResolveCount); - - for (Count = 0; Count < RSPCurrentBlock.ResolveCount; Count++) { - Target = RSPCurrentBlock.BranchesToResolve[Count].TargetPC; - X86Code = *(RSPJumpTable + (Target >> 2)); - - if (!X86Code) { - *PrgCount = Target; - CPU_Message(""); - CPU_Message("===== (Generate Code: %04X) =====", Target); - Save = *Block; - - /* compile this block and link */ - CompilerRSPBlock(); - LinkBranches(Block); - - *Block = Save; - CPU_Message("===== (End Generate Code: %04X) =====", Target); - CPU_Message(""); - X86Code = *(RSPJumpTable + (Target >> 2)); - } - - JumpWord = RSPCurrentBlock.BranchesToResolve[Count].X86JumpLoc; - RSPx86_SetBranch32b(JumpWord, (uint32_t*)X86Code); - - CPU_Message("Linked RSP branch from x86: %08X, to RSP: %X / x86: %08X", - JumpWord, Target, X86Code); - } - CPU_Message("***** Done Linking Branches *****"); - CPU_Message(""); -} - -/****************************************************** -** BuildBranchLabels -** -** Desc: -** Branch labels are used to start and stop re-ordering -** sections as well as set the jump table to points -** within a block that are safe -** -********************************************************/ - -void BuildBranchLabels(void) { - RSPOPCODE RspOp; - uint32_t i, Dest; - - #ifdef BUILD_BRANCHLABELS_VERBOSE - CPU_Message("***** Building branch labels *****"); - #endif - - for (i = 0; i < 0x1000; i += 4) { - RspOp.Hex = *(uint32_t*)(IMEM + i); - - if (1 == IsOpcodeBranch(i, RspOp)) { - if (RspCode.LabelCount >= 175) { - CompilerWarning("Out of space for Branch Labels",1); - return; - } - - RspCode.BranchLocations[RspCode.BranchCount++] = i; - if (RspOp.op == RSP_SPECIAL) { - /* register jump not predictable */ - } else if (RspOp.op == RSP_J || RspOp.op == RSP_JAL) { - /* for JAL its a sub-block for returns */ - Dest = (RspOp.target << 2) & 0xFFC; - RspCode.BranchLabels[RspCode.LabelCount] = Dest; - RspCode.LabelCount += 1; - #ifdef BUILD_BRANCHLABELS_VERBOSE - CPU_Message("[%02i] Added branch at %X to %X", RspCode.LabelCount, i, Dest); - #endif - } else { - Dest = (i + ((int16_t)RspOp.offset << 2) + 4) & 0xFFC; - RspCode.BranchLabels[RspCode.LabelCount] = Dest; - RspCode.LabelCount += 1; - #ifdef BUILD_BRANCHLABELS_VERBOSE - CPU_Message("[%02i] Added branch at %X to %X", RspCode.LabelCount, i, Dest); - #endif - } - } - } - - #ifdef BUILD_BRANCHLABELS_VERBOSE - CPU_Message("***** End branch labels *****"); - CPU_Message(""); - #endif -} - -int32_t IsJumpLabel(uint32_t PC) { - uint32_t Count; - - if (!RspCode.LabelCount) { - return 0; - } - - for (Count = 0; Count < RspCode.LabelCount; Count++) { - if (PC == RspCode.BranchLabels[Count]) { - return 1; - } - } - return 0; -} - - - -void CompilerLinkBlocks(void) { - uint8_t * KnownCode = *(RSPJumpTable + (RSPCompilePC >> 2)); - - CPU_Message("***** Linking block to X86: %08X *****", KnownCode); - RSPNextInstruction = FINISH_BLOCK; - - /* block linking scenario */ - RSPJmpLabel32(0); - RSPx86_SetBranch32b(RSPRecompPos - 4, KnownCode); -} - - -void CompilerRSPBlock ( void ) { - uint32_t Count, Padding, X86BaseAddress = (uint32_t)RSPRecompPos; - - RSPNextInstruction = NORMAL; - RSPCompilePC = *PrgCount; - - memset(&RSPCurrentBlock, 0, sizeof(RSPCurrentBlock)); - RSPCurrentBlock.StartPC = RSPCompilePC; - RSPCurrentBlock.CurrPC = RSPCompilePC; - - - /* Align the block to a boundary */ - if (X86BaseAddress & 7) { - Padding = (8 - (X86BaseAddress & 7)) & 7; - for (Count = 0; Count < Padding; Count++) { - *(RSPRecompPos++) = 0x90; - } - } - - if (Compiler.bReOrdering == 1) { - memcpy(&RSPCurrentBlock.IMEM[0], IMEM, 0x1000); - ReOrderSubBlock(&RSPCurrentBlock); - } - - /* this is for the block about to be compiled */ - *(RSPJumpTable + (RSPCompilePC >> 2)) = RSPRecompPos; - - -#ifdef USEX64 - RSPMoveConstQwordToX86reg(TLB_Map, x86_R15); -#endif - - do { - /* - ** Re-Ordering is setup to allow us to have loop labels - ** so here we see if this is one and put it in the jump table - **/ - - if (RSPNextInstruction == NORMAL && IsJumpLabel(RSPCompilePC)) { - /* jumps come around twice */ - if (NULL == *(RSPJumpTable + (RSPCompilePC >> 2))) { - CPU_Message("***** Adding Jump Table Entry for PC: %04X at X86: %08X *****", RSPCompilePC, RSPRecompPos); - CPU_Message(""); - *(RSPJumpTable + (RSPCompilePC >> 2)) = RSPRecompPos; - - /* reorder from here to next label or branch */ - RSPCurrentBlock.CurrPC = RSPCompilePC; - ReOrderSubBlock(&RSPCurrentBlock); - } else if (RSPNextInstruction != DELAY_SLOT_DONE) { - /* - * we could link the blocks here, but performance - * wise it might be better to just let it run - */ - } - } - - if (Compiler.bSections == 1) { - // if (1 == RSP_DoSections()) { - // continue; - // } - } - - #ifdef X86_RECOMP_VERBOSE - if (0 == IsOpcodeNop(RSPCompilePC)) { - CPU_Message("X86 Address: %08X", RSPRecompPos); - } - #endif - - RSP_LW_IMEM(RSPCompilePC, &RSPOpC.Hex); - - if (RSPOpC.Hex == 0xFFFFFFFF) { - /* i think this pops up an unknown op dialog */ - /* NextInstruction = FINISH_BLOCK; */ - } else { - ((void (*)()) RSP_Opcode[ RSPOpC.op ])(); - } - - //printf("%08x\n", RSPNextInstruction); - - switch (RSPNextInstruction) { - case NORMAL: - RSPCompilePC += 4; - break; - case DO_DELAY_SLOT: - RSPNextInstruction = DELAY_SLOT; - RSPCompilePC += 4; - break; - case DELAY_SLOT: - RSPNextInstruction = DELAY_SLOT_DONE; - RSPCompilePC -= 4; - break; - case FINISH_SUB_BLOCK: - RSPNextInstruction = NORMAL; - RSPCompilePC += 8; - if (RSPCompilePC >= 0x1000) { - RSPNextInstruction = FINISH_BLOCK; - } else if (NULL == *(RSPJumpTable + (RSPCompilePC >> 2))) { - /* this is for the new block being compiled now */ - CPU_Message("**** Continuing static SubBlock (jump table entry added for PC: %04X at X86: %08X) *****", RSPCompilePC, RSPRecompPos); - *(RSPJumpTable + (RSPCompilePC >> 2)) = RSPRecompPos; - - RSPCurrentBlock.CurrPC = RSPCompilePC; - /* reorder from after delay to next label or branch */ - ReOrderSubBlock(&RSPCurrentBlock); - } else { - CompilerLinkBlocks(); - } - break; - - case FINISH_BLOCK: break; - default: - DisplayError("Rsp Main loop\n\nWTF NextInstruction = %d",RSPNextInstruction); - RSPCompilePC += 4; - break; - } - } while ( RSPNextInstruction != FINISH_BLOCK && RSPCompilePC < 0x1000); - CPU_Message("==== end of recompiled code ===="); - - if (Compiler.bReOrdering == 1) { - memcpy(IMEM, &RSPCurrentBlock.IMEM[0], 0x1000); - } -} - -#include "types.h" - - -void RunRecompilerCPU ( uint32_t Cycles ) { - uint8_t * Block = 0; - - RSP_Running = 1; - RSPSetJumpTable(); - - - - while (RSP_Running) { - - Block = *(RSPJumpTable + (*PrgCount >> 2)); - - if (Block == NULL) { - //__try { - memset(&RspCode, 0, sizeof(RspCode)); - BuildBranchLabels(); - DetectGPRConstants(&RspCode); - CompilerRSPBlock(); - /*} __except(EXCEPTION_EXECUTE_HANDLER) { - DisplayError("Error RSPCompilePC = %08X", RSPCompilePC); - ClearAllx86Code(); - continue; - }*/ - - Block = *(RSPJumpTable + (*PrgCount >> 2)); - - /* - ** we are done compiling, but we may have references - ** to fill in still either from this block, or jumps - ** that go out of it, let's rock - **/ - - LinkBranches(&RSPCurrentBlock); - } - { - - void (*block)(); - block=Block; -#ifdef USEX64 - __asm__ __volatile__("pushq %rax"); - __asm__ __volatile__("pushq %rbx"); - __asm__ __volatile__("pushq %rcx"); - __asm__ __volatile__("pushq %rdx"); - __asm__ __volatile__("pushq %rbp"); - __asm__ __volatile__("pushq %r8"); - __asm__ __volatile__("pushq %r9"); - __asm__ __volatile__("pushq %r10"); - __asm__ __volatile__("pushq %r11"); - __asm__ __volatile__("pushq %r12"); - __asm__ __volatile__("pushq %r13"); - __asm__ __volatile__("pushq %r14"); - __asm__ __volatile__("pushq %r15"); - - block(); - - __asm__ __volatile__("popq %r15"); - __asm__ __volatile__("popq %r14"); - __asm__ __volatile__("popq %r13"); - __asm__ __volatile__("popq %r12"); - __asm__ __volatile__("popq %r11"); - __asm__ __volatile__("popq %r10"); - __asm__ __volatile__("popq %r9"); - __asm__ __volatile__("popq %r8"); - __asm__ __volatile__("popq %rbp"); - __asm__ __volatile__("popq %rdx"); - __asm__ __volatile__("popq %rcx"); - __asm__ __volatile__("popq %rbx"); - __asm__ __volatile__("popq %rax"); - -#else - __asm__ __volatile__("pusha"); - block(); - __asm__ __volatile__("popa"); -#endif - } - - } - -// if (IsMmxEnabled == 1) { -// _Emms(); -// } - return; -} diff --git a/src/usf/rsp_recompiler_cpu.h b/src/usf/rsp_recompiler_cpu.h deleted file mode 100644 index e54f900..0000000 --- a/src/usf/rsp_recompiler_cpu.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 "rsp.h" - -extern uint32_t RSPCompilePC, RSPNextInstruction; - -//#define CompilerWarning if (ShowErrors) DisplayError -//#define CompilerWarning(blah,blah2) -#define CompilerWarning(...) - -#define High16BitAccum 1 -#define Middle16BitAccum 2 -#define Low16BitAccum 4 -#define EntireAccum (Low16BitAccum|Middle16BitAccum|High16BitAccum) - -int32_t WriteToAccum (int32_t Location, int32_t PC); -int32_t WriteToVectorDest (uint32_t DestReg, int32_t PC); -int32_t UseRspFlags (int32_t PC); - -int32_t DelaySlotAffectBranch(uint32_t PC); -int32_t CompareInstructions(uint32_t PC, RSPOPCODE * Top, RSPOPCODE * Bottom); -int32_t IsOpcodeBranch(uint32_t PC, RSPOPCODE RspOp); -int32_t IsOpcodeNop(uint32_t PC); - -int32_t IsNextInstructionMmx(uint32_t PC); -int32_t IsRegisterConstant (uint32_t Reg, uint32_t * Constant); - -void RSP_Element2Mmx(int32_t MmxReg); -void RSP_MultiElement2Mmx(int32_t MmxReg1, int32_t MmxReg2); - -#define MainBuffer 0 -#define SecondaryBuffer 1 - -void RunRecompilerCPU ( uint32_t Cycles ); -void BuildRecompilerCPU ( void ); - -void CompilerRSPBlock ( void ); -void CompilerToggleBuffer (void); -int32_t RSP_DoSections(void); - -void ClearAllx86Code (void); - -typedef struct { - uint32_t StartPC, CurrPC; /* block start */ - - struct { - uint32_t TargetPC; /* Target for this unknown branch */ - uint32_t * X86JumpLoc; /* Our x86 dword to fill */ - } BranchesToResolve[200]; /* Branches inside or outside block */ - - uint32_t ResolveCount; /* Branches with NULL jump table */ - uint8_t IMEM[0x1000]; /* Saved off for re-order */ -} RSP_BLOCK; - -extern RSP_BLOCK RSPCurrentBlock; - -typedef struct { - int32_t bIsRegConst[32]; /* BOOLean toggle for constant */ - uint32_t MipsRegConst[32]; /* Value of register 32-bit */ - uint32_t BranchLabels[200]; - uint32_t LabelCount; - uint32_t BranchLocations[200]; - uint32_t BranchCount; -} RSP_CODE; - -extern RSP_CODE RspCode; - -#define IsRegConst(i) (RspCode.bIsRegConst[i]) -#define MipsRegConst(i) (RspCode.MipsRegConst[i]) - -typedef struct { - int32_t mmx, mmx2, sse; /* CPU specs and compiling */ - int32_t bFlags; /* RSP Flag Analysis */ - int32_t bReOrdering; /* Instruction reordering */ - int32_t bSections; /* Microcode sections */ - int32_t bDest; /* Vector destionation toggle */ - int32_t bAccum; /* Accumulator toggle */ - int32_t bGPRConstants; /* Analyze GPR constants */ - int32_t bAlignVector; /* Align known vector loads */ - int32_t bAlignGPR; /* Align known gpr loads */ -} RSP_COMPILER; - -extern RSP_COMPILER Compiler; - - -extern uint8_t * pLastSecondary, * pLastPrimary; -extern uint32_t RSPBlockID; -extern uint32_t dwBuffer; - -#define IsMmxEnabled (Compiler.mmx) -#define IsMmx2Enabled (Compiler.mmx2) -#define IsSseEnabled (Compiler.sse) diff --git a/src/usf/rsp_recompiler_ops.c b/src/usf/rsp_recompiler_ops.c deleted file mode 100644 index dfdf628..0000000 --- a/src/usf/rsp_recompiler_ops.c +++ /dev/null @@ -1,4619 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 -#include -#include "types.h" -#include "rsp.h" -#include "rsp_recompiler_cpu.h" -#include "rsp_x86.h" -#include "recompiler_cpu.h" -#include "memory.h" -#include "registers.h" -#include "usf.h" -#include "types.h" -#include "main.h" - -MIPSUWORD Recp, RecpResult, SQroot, SQrootResult; -uint32_t ESP_RegSave = 0, EBP_RegSave = 0; -uint32_t RSPBranchCompare = 0; -extern int runcount; -/* align option affects: sw, lh, sh */ -/* align option affects: lrv, ssv, lsv */ - -#if 1 -#define RSPCompile_Immediates /* ADDI, ADDIU, ANDI, ORI, XORI, LUI */ - -#define RSPCompile_GPRLoads /* LB, LH, LW, LBU, LHU */ -#define RSPCompile_GPRStores /* SB, SH, SW */ -#define RSPCompile_Special /* SLL, SRL, SRA, SRLV */ - /* XOR, OR, AND, SUB, SUBU, ADDU, ADD, SLT */ - -#define RSPCompile_Cop0 -#define RSPCompile_Cop2 - -#define RSP_VectorMuls -#define RSP_VectorLoads -#define RSP_VectorMisc - -#ifdef RSP_VectorMuls -# define RSPCompileVmulf /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmacf /* Rewritten & Verified 12/15/2000 - Jabo */ -# define RSPCompileVmudm /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmudh /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmudn /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmudl /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmadl -# define RSPCompileVmadm /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVmadh /* Verified 12/15/2000 - Jabo */ -# define RSPCompileVmadn /* Verified 12/17/2000 - Jabo */ -#endif -#ifdef RSP_VectorMisc -# define RSPCompileVrsqh -# define RSPCompileVrcph -# define RSPCompileVsaw /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVabs /* Verified 12/15/2000 - Jabo */ -# define RSPCompileVmov /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVxor /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVor /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVand /* Verified 12/17/2000 - Jabo */ -# define RSPCompileVsub /* Verified 12/17/2000 - Jabo (watch flags) */ -# define RSPCompileVadd /* Verified 12/17/2000 - Jabo (watch flags) */ -# define RSPCompileVaddc -# define RSPCompileVsubc -# define RSPCompileVmrg -#endif -#ifdef RSP_VectorLoads -# define RSPCompileSqv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileSdv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileSsv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileLrv /* Rewritten & Verified 12/17/2000 - Jabo */ -# define RSPCompileLqv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileLdv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileLsv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileLlv /* Verified 12/17/2000 - Jabo */ -# define RSPCompileSlv -#endif -#endif - -void RSPBranch_AddRef(uint32_t Target, uint32_t * X86Loc) { - if (RSPCurrentBlock.ResolveCount >= 150) { - //CompilerWarning(1); - } else { - uint8_t * KnownCode = *(RSPJumpTable + (Target >> 2)); - - if (KnownCode == NULL) { - uint32_t i = RSPCurrentBlock.ResolveCount; - RSPCurrentBlock.BranchesToResolve[i].TargetPC = Target; - RSPCurrentBlock.BranchesToResolve[i].X86JumpLoc = X86Loc; - RSPCurrentBlock.ResolveCount += 1; - } else { - CPU_Message( KnownCode); - RSPx86_SetBranch32b((uint32_t*)X86Loc, (uint32_t*)KnownCode); - } - } -} - -int32_t test33 = 0; -void RSPCheat_r4300iOpcode ( void * FunctAddress) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(RSPCompilePC, &test33); - RSPPushad(); - RSPMoveConstToVariable(RSPOpC.Hex, &RSPOpC.Hex ); - RSPCall_Direct(FunctAddress); - RSPPopad(); -} - -void RSPCheat_r4300iOpcodeNoMessage( void * FunctAddress) { - RSPMoveConstToVariable(RSPCompilePC, &test33); - RSPPushad(); - RSPMoveConstToVariable(RSPOpC.Hex, &RSPOpC.Hex ); - RSPCall_Direct(FunctAddress); - RSPPopad(); -} - -void RSPx86_SetBranch8b(void * JumpByte, void * Destination) { - /* calculate 32-bit relative offset */ - int32_t n = (uint8_t*)Destination - ((uint8_t*)JumpByte + 1); - - /* check limits, no pun intended */ - if (n > 0x80 || n < -0x7F) { - //CompilerWarning( n, RSPCompilePC); - } else - *(uint8_t*)(JumpByte) = (uint8_t)n; -} - -void RSPx86_SetBranch32b(void * JumpByte, void * Destination) { - //intptr_t disp = (uintptr_t)Destination - (uintptr_t)JumpByte; - - //if(disp < 0) disp = 0 - disp; - //if(disp >= 0x7f000000) { - // Int3(); - //} - *(uint32_t*)(JumpByte) = (uint32_t)((uint8_t*)Destination - (uint8_t*)((uint32_t*)JumpByte + 1)); -} - -/************************* OpCode functions *************************/ -void RSPCompile_SPECIAL ( void ) { - ((void (*)()) RSP_Special[ RSPOpC.funct ])(); -} - -void RSPCompile_REGIMM ( void ) { - ((void (*)()) RSP_RegImm[ RSPOpC.rt ])(); -} - -void RSPCompile_J ( void ) { - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - RSPJmpLabel32 ( 0 ); - RSPBranch_AddRef((RSPOpC.target << 2) & 0xFFC, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_JAL ( void ) { - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(RSPCompilePC + 8, &RSP_GPR[31].UW); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - RSPJmpLabel32 (0 ); - RSPBranch_AddRef((RSPOpC.target << 2) & 0xFFC, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_BEQ ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0 && RSPOpC.rt == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - if (RSPOpC.rt == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - } else if (RSPOpC.rs == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rt].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W,x86_EAX); - RSPCompX86regToVariable(x86_EAX,&RSP_GPR[RSPOpC.rs].W); - } - RSPSetzVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0 && RSPOpC.rt == 0) { - RSPJmpLabel32 (0 ); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - if (RSPOpC.rt == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - } else if (RSPOpC.rs == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rt].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W,x86_EAX); - RSPCompX86regToVariable(x86_EAX,&RSP_GPR[RSPOpC.rs].W); - } - RSPJeLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_BNE ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0 && RSPOpC.rt == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - if (RSPOpC.rt == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - } else if (RSPOpC.rs == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rt].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W,x86_EAX); - RSPCompX86regToVariable(x86_EAX,&RSP_GPR[RSPOpC.rs].W); - } - RSPSetnzVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0 && RSPOpC.rt == 0) { - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - - if (0 == bDelayAffect) { - if (RSPOpC.rt == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - } else if (RSPOpC.rs == 0) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rt].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W,x86_EAX); - RSPCompX86regToVariable(x86_EAX,&RSP_GPR[RSPOpC.rs].W); - } - RSPJneLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - //if(RSPCompilePC==0x24) - // Int3(); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_BLEZ ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetleVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPJmpLabel32 ( 0 ); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPJleLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_BGTZ ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetgVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPJgLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_ADDI ( void ) { - int32_t Immediate = (int16_t)RSPOpC.immediate; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_ADDI); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - - if (RSPOpC.rt == RSPOpC.rs) { - RSPAddConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else if (RSPOpC.rs == 0) { - RSPMoveConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - if (Immediate != 0) { - RSPAddConstToX86Reg(x86_EAX, Immediate); - } - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSPCompile_ADDIU ( void ) { - int32_t Immediate = (int16_t)RSPOpC.immediate; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_ADDIU); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - - if (RSPOpC.rt == RSPOpC.rs) { - RSPAddConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else if (RSPOpC.rs == 0) { - RSPMoveConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - RSPAddConstToX86Reg(x86_EAX, Immediate); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSPCompile_SLTI ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SLTI); -} - -void RSPCompile_SLTIU ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SLTIU); -} - -void RSPCompile_ANDI ( void ) { - int32_t Immediate = (uint16_t)RSPOpC.immediate; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_ANDI); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - - if (RSPOpC.rt == RSPOpC.rs) { - RSPAndConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else if (RSPOpC.rs == 0) { - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rt].UW); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - RSPAndConstToX86Reg(x86_EAX, Immediate); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSPCompile_ORI ( void ) { - int32_t Immediate = (uint16_t)RSPOpC.immediate; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_ORI); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - - if (RSPOpC.rt == RSPOpC.rs) { - RSPOrConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else if (RSPOpC.rs == 0) { - RSPMoveConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - if (Immediate != 0) { - RSPOrConstToX86Reg(Immediate, x86_EAX); - } - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSPCompile_XORI ( void ) { - int32_t Immediate = (uint16_t)RSPOpC.immediate; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_XORI); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - - if (RSPOpC.rt == RSPOpC.rs) { - RSPXorConstToVariable(&RSP_GPR[RSPOpC.rt].UW, Immediate); - } else if (RSPOpC.rs == 0) { - RSPMoveConstToVariable(Immediate, &RSP_GPR[RSPOpC.rt].UW); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - if (Immediate != 0) { - RSPXorConstToX86Reg(x86_EAX, Immediate); - } - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - } -} - -void RSPCompile_LUI ( void ) { - int32_t n = (int16_t)RSPOpC.offset << 16; - - #ifndef RSPCompile_Immediates - RSPCheat_r4300iOpcode(RSP_Opcode_LUI); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rt == 0) return; - RSPMoveConstToVariable(n, &RSP_GPR[RSPOpC.rt].W); -} - -void RSPCompile_COP0 (void) { - ((void (*)()) RSP_Cop0[ RSPOpC.rs ])(); -} - -void RSPCompile_COP2 (void) { - ((void (*)()) RSP_Cop2[ RSPOpC.rs ])(); -} - -void RSPCompile_LB ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - - #ifndef RSPCompile_GPRLoads - RSPCheat_r4300iOpcode(RSP_Opcode_LB); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - - RSPMoveSxN64MemToX86regByte(x86_EAX, x86_EBX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); -} - -void RSPCompile_LH ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - uint8_t * Jump[2]; - - #ifndef RSPCompile_GPRLoads - RSPCheat_r4300iOpcode(RSP_Opcode_LH); return; - #endif - - if(RSPCompilePC == 0x108) { - // RSPBreakPoint(); -// _asm int32_t 3 - - } - - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + Offset) ^ 2; - Addr &= 0xfff; - - if ((Addr & 1) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LH); - return; - } else { - - - RSPMoveSxVariableToX86regHalf(DMEM + Addr, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - return; - } - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - - if (Compiler.bAlignGPR == 0) { - RSPTestConstToX86Reg(1, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LH); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - } - - RSPXorConstToX86Reg(x86_EBX, 2); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - - - RSPMoveSxN64MemToX86regHalf(x86_EAX, x86_EBX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - - if (Compiler.bAlignGPR == 0) { - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); - } -} - -void RSPCompile_LW ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - uint8_t * Jump[2]; - - #ifndef RSPCompile_GPRLoads - RSPCheat_r4300iOpcode(RSP_Opcode_LW); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + Offset) & 0xfff; - - if ((Addr & 3) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LW); - return; - } else { - - - RSPMoveVariableToX86reg(DMEM + Addr, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - return; - } - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - //if(runcount == 2) - //asm("int $3"); - - CompilerToggleBuffer(); - - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - CPU_Message(" Unaligned:"); - - RSPLeaSourceAndOffset(x86_ECX , x86_EBX, 2); - RSPLeaSourceAndOffset(x86_EDX , x86_EBX, 3); - RSPMoveX86RegToX86Reg(x86_EBX, x86_EAX); - RSPAddConstToX86Reg(x86_EBX, 1); - - RSPXorConstToX86Reg(x86_EAX, 3); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPXorConstToX86Reg(x86_ECX, 3); - RSPXorConstToX86Reg(x86_EDX, 3); - RSPMoveN64MemToX86regByte(x86_EAX, x86_EAX); - RSPMoveN64MemToX86regByte(x86_EBX, x86_EBX); - RSPMoveN64MemToX86regByte(x86_ECX, x86_ECX); - RSPMoveN64MemToX86regByte(x86_EDX, x86_EDX); - RSPMoveX86regByteToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UB[3]); - RSPMoveX86regByteToVariable(x86_EBX, &RSP_GPR[RSPOpC.rt].UB[2]); - RSPMoveX86regByteToVariable(x86_ECX, &RSP_GPR[RSPOpC.rt].UB[1]); - RSPMoveX86regByteToVariable(x86_EDX, &RSP_GPR[RSPOpC.rt].UB[0]); - - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPMoveN64MemToX86reg(x86_EAX, x86_EBX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); -} - -void RSPCompile_LBU ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - - #ifndef RSPCompile_GPRLoads - RSPCheat_r4300iOpcode(RSP_Opcode_LBU); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - RSPXorX86RegToX86Reg(x86_EAX, x86_EAX); - - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - - RSPMoveN64MemToX86regByte(x86_EAX, x86_EBX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); -} - -void RSPCompile_LHU ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - uint8_t * Jump[2]; - - #ifndef RSPCompile_GPRLoads - RSPCheat_r4300iOpcode(RSP_Opcode_LHU); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + Offset) ^ 2; - Addr &= 0xfff; - - - if ((Addr & 1) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LHU); - return; - } else { - - - RSPMoveZxVariableToX86regHalf(DMEM + Addr, x86_ECX); - RSPMoveX86regToVariable(x86_ECX, &RSP_GPR[RSPOpC.rt].UW); - return; - } - } - - - - /* - * should really just do it by bytes but whatever for now - */ - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) { - RSPAddConstToX86Reg(x86_EBX, Offset); - } - RSPTestConstToX86Reg(1, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LHU); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - RSPXorConstToX86Reg(x86_EBX, 2); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPMoveZxN64MemToX86regHalf(x86_EAX, x86_EBX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); -} - -void RSPCompile_SB ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - - #ifndef RSPCompile_GPRStores - RSPCheat_r4300iOpcode(RSP_Opcode_SB); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - RSPMoveVariableToX86regByte(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - - RSPMoveX86regByteToN64Mem(x86_EAX, x86_EBX); -} - -void RSPCompile_SH ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - uint8_t * Jump[2]; - - #ifndef RSPCompile_GPRStores - RSPCheat_r4300iOpcode(RSP_Opcode_SH); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + Offset) ^ 2; - Addr &= 0xfff; - - if ((Offset & 1) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SH); - return; - } else { - - - RSPMoveVariableToX86regHalf(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regHalfToVariable(x86_EAX, DMEM + Addr); - return; - } - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - - if (Compiler.bAlignGPR == 0) { - RSPTestConstToX86Reg(1, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SH); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - } - - RSPXorConstToX86Reg(x86_EBX, 2); - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - - RSPMoveVariableToX86regHalf(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regHalfToN64Mem(x86_EAX, x86_EBX); - - if (Compiler.bAlignGPR == 0) { - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); - } -} - -void RSPCompile_SW ( void ) { - int32_t Offset = (int16_t)RSPOpC.offset; - uint8_t * Jump[2]; - - #ifndef RSPCompile_GPRStores - RSPCheat_r4300iOpcode(RSP_Opcode_SW); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + Offset) & 0xfff; - - if ((Addr & 3) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SW); - return; - } else { - - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, DMEM + Addr); - return; - } - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (Offset != 0) RSPAddConstToX86Reg(x86_EBX, Offset); - - if (Compiler.bAlignGPR == 0) { - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SW); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - } - - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToN64Mem(x86_EAX, x86_EBX); - - if (Compiler.bAlignGPR == 0) { - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); - } -} - -void RSPCompile_LC2 (void) { - ((void (*)()) RSP_Lc2 [ RSPOpC.rd ])(); -} - -void RSPCompile_SC2 (void) { - ((void (*)()) RSP_Sc2 [ RSPOpC.rd ])(); -} -/********************** R4300i OpCodes: Special **********************/ - -void RSPCompile_Special_SLL ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SLL); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rt) { - RSPShiftLeftSignVariableImmed(&RSP_GPR[RSPOpC.rd].W, (uint8_t)RSPOpC.sa); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPShiftLeftSignImmed(x86_EAX, (uint8_t)RSPOpC.sa); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_SRL ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SRL); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rt) { - RSPShiftRightUnsignVariableImmed(&RSP_GPR[RSPOpC.rd].W, (uint8_t)RSPOpC.sa); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPShiftRightUnsignImmed(x86_EAX, (uint8_t)RSPOpC.sa); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_SRA ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SRA); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rt) { - RSPShiftRightSignVariableImmed(&RSP_GPR[RSPOpC.rd].W, (uint8_t)RSPOpC.sa); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPShiftRightSignImmed(x86_EAX, (uint8_t)RSPOpC.sa); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_SLLV ( void ) { - RSPCheat_r4300iOpcode(RSP_Special_SLLV); -} - -void RSPCompile_Special_SRLV ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SRLV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rd == 0) return; - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_ECX); - RSPAndConstToX86Reg(x86_ECX, 0x1F); - RSPShiftRightUnsign(x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); -} - -void RSPCompile_Special_SRAV ( void ) { - RSPCheat_r4300iOpcode(RSP_Special_SRAV); -} - -void RSPCompile_Special_JR (void) { - uint8_t * Jump; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - /* transfer destination to location pointed to by PrgCount */ - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W,x86_EAX); - RSPAndConstToX86Reg(x86_EAX,0xFFC); - RSPMoveX86regToVariable(x86_EAX,PrgCount); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - //RSPBreakPoint(); - RSPMoveVariableToX86reg(PrgCount, x86_EAX); -#ifdef USEX64 - RSPShiftLeftDoubleImmed(x86_EAX,x86_EAX,1); -#endif - RSPAddVariableToX86reg(x86_RAX, &RSPJumpTable); - RSPMoveX86regPointerToX86reg(x86_RAX, x86_RAX); - - RSPTestX86RegToX86Reg(x86_RAX, x86_RAX); - RSPJeLabel8( 0); - Jump = RSPRecompPos - 1; - RSPPush(x86_RAX); - RSPPop(x86_RAX); - RSPJumpX86Reg(x86_RAX); - - RSPx86_SetBranch8b(Jump, RSPRecompPos); - CPU_Message(" Null:"); - RSPRet(); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -int32_t llastjump = 0; -void RSPCompile_Special_JALR ( void ) { - uint8_t * Jump; - uint32_t Const = (RSPCompilePC + 8) & 0xFFC; - - if (RSPNextInstruction == NORMAL) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(Const, &RSP_GPR[RSPOpC.rd].W); - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W,x86_EAX); - RSPAndConstToX86Reg(x86_EAX,0xFFC); - RSPMoveX86regToVariable(x86_EAX,PrgCount); - RSPNextInstruction = DO_DELAY_SLOT; - } else if (RSPNextInstruction == DELAY_SLOT_DONE) { - - RSPMoveVariableToX86reg(PrgCount, x86_EAX); -#ifdef USEX64 - RSPShiftLeftDoubleImmed(x86_RAX,x86_EAX,1); -#endif - RSPAddVariableToX86reg(x86_RAX, &RSPJumpTable); - RSPMoveX86regPointerToX86reg(x86_RAX, x86_RAX); - - RSPTestX86RegToX86Reg(x86_RAX, x86_RAX); - RSPJeLabel8( 0); - Jump = RSPRecompPos - 1; - - RSPJumpX86Reg(x86_RAX); - - RSPx86_SetBranch8b(Jump, RSPRecompPos); - CPU_Message(" Null:"); - RSPRet(); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_Special_BREAK ( void ) { - RSPCheat_r4300iOpcode(RSP_Special_BREAK); - if (RSPNextInstruction != NORMAL) { - DisplayError("Compile_Special_BREAK: problem"); - } - RSPMoveConstToVariable(RSPCompilePC + 4,PrgCount); - RSPRet(); - RSPNextInstruction = FINISH_BLOCK; -} - -void RSPCompile_Special_ADD ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_ADD); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPAddX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rd == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddX86RegToX86Reg(x86_EAX, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rt == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddVariableToX86reg(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_ADDU ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_ADDU); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPAddX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rd == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddX86RegToX86Reg(x86_EAX, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rt == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAddVariableToX86reg(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_SUB ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SUB); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPSubX86regFromVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPSubVariableFromX86reg(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_SUBU ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SUBU); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPSubX86regFromVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPSubVariableFromX86reg(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_AND ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_AND); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPAndX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rd == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAndX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPAndVariableToX86Reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_OR ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_OR); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPOrX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rd == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPOrX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rs == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else if (RSPOpC.rt == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPOrVariableToX86Reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_XOR ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_XOR); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.rd == 0) return; - - if (RSPOpC.rd == RSPOpC.rs) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPXorX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rd == RSPOpC.rt) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPXorX86RegToVariable(&RSP_GPR[RSPOpC.rd].W, x86_EAX); - } else if (RSPOpC.rs == RSPOpC.rt) { - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rd].W); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].W, x86_EAX); - RSPXorVariableToX86reg(&RSP_GPR[RSPOpC.rt].W, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rd].W); - } -} - -void RSPCompile_Special_NOR ( void ) { - RSPCheat_r4300iOpcode(RSP_Special_NOR); -} - -void RSPCompile_Special_SLT ( void ) { - #ifndef RSPCompile_Special - RSPCheat_r4300iOpcode(RSP_Special_SLT); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rt == 0) { return; } - - if (RSPOpC.rt == RSPOpC.rs) { - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rd].UW); - } else { - RSPXorX86RegToX86Reg(x86_EBX, x86_EBX); - if (RSPOpC.rs == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPCompConstToX86reg(x86_EAX, 0); - RSPSetg(x86_EBX); - } else if (RSPOpC.rt == 0) { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - RSPCompConstToX86reg(x86_EAX, 0); - RSPSetl(x86_EBX); - } else { - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rs].UW, x86_EAX); - RSPCompX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - RSPSetl(x86_EBX); - } - RSPMoveX86regToVariable(x86_EBX, &RSP_GPR[RSPOpC.rd].UW); - } -} - -void RSPCompile_Special_SLTU ( void ) { - RSPCheat_r4300iOpcode(RSP_Special_SLTU); -} - -/********************** R4300i OpCodes: RegImm **********************/ -void RSPCompile_RegImm_BLTZ ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetlVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPJlLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - //CompilerWarning( NextInstruction, RSPCompilePC); - } -} - -void RSPCompile_RegImm_BGEZ ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetgeVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPJmpLabel32 ( 0 ); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPJgeLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_RegImm_BLTZAL ( void ) { - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(RSPCompilePC + 8, &RSP_GPR[31].UW); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetlVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -void RSPCompile_RegImm_BGEZAL ( void ) { - static int32_t bDelayAffect; - - if ( RSPNextInstruction == NORMAL ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(RSPCompilePC + 8, &RSP_GPR[31].UW); - if (RSPOpC.rs == 0) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - bDelayAffect = DelaySlotAffectBranch(RSPCompilePC); - if (0 == bDelayAffect) { - RSPNextInstruction = DO_DELAY_SLOT; - return; - } - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPSetgeVariable(&RSPBranchCompare); - RSPNextInstruction = DO_DELAY_SLOT; - } else if ( RSPNextInstruction == DELAY_SLOT_DONE ) { - uint32_t Target = (RSPCompilePC + ((int16_t)RSPOpC.offset << 2) + 4) & 0xFFC; - - if (RSPOpC.rs == 0) { - RSPJmpLabel32 ( 0 ); - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - return; - } - if (0 == bDelayAffect) { - RSPCompConstToVariable(0,&RSP_GPR[RSPOpC.rs].W); - RSPJgeLabel32( 0); - } else { - /* take a look at the branch compare variable */ - RSPCompConstToVariable(1, &RSPBranchCompare); - RSPJeLabel32( 0); - } - RSPBranch_AddRef(Target, (uint32_t*)(RSPRecompPos - 4)); - RSPNextInstruction = FINISH_SUB_BLOCK; - } else { - CompilerWarning( NextInstruction); - } -} - -/************************** Cop0 functions *************************/ - -void RSPCompile_Cop0_MF ( void ) { - #ifndef RSPCompile_Cop0 - RSPCheat_r4300iOpcode(RSP_Cop0_MF); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - switch (RSPOpC.rd) { - case 4: - RSPMoveVariableToX86reg(&SP_STATUS_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 5: - RSPMoveVariableToX86reg(&SP_DMA_FULL_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 6: - RSPMoveVariableToX86reg(&SP_DMA_BUSY_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 7: - RSPMoveConstToVariable(0, &RSP_GPR[RSPOpC.rt].UW); - //RSPCheat_r4300iOpcode(RSP_Cop0_MF); - break; - case 8: - RSPMoveVariableToX86reg(&DPC_START_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 9: - RSPMoveVariableToX86reg(&DPC_END_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 10: - RSPMoveVariableToX86reg(&DPC_CURRENT_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 11: - RSPMoveVariableToX86reg(&DPC_STATUS_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - case 12: - RSPMoveVariableToX86reg(&DPC_CLOCK_REG, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].UW); - break; - - //default: - //CompilerWarning(COP0_Name(RSPOpC.rd),RSPOpC.rd); - } -} - -void RSPCompile_Cop0_MT ( void ) { -#ifndef RSPCompile_Cop0 - RSPCheat_r4300iOpcode(RSP_Cop0_MT); -#else - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - switch (RSPOpC.rd) { - case 0: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &SP_MEM_ADDR_REG); - break; - case 1: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &SP_DRAM_ADDR_REG); - break; - case 2: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &SP_RD_LEN_REG); - RSPPushad(); - RSPCall_Direct(RSP_SP_DMA_READ); - RSPPopad(); - break; - case 3: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &SP_WR_LEN_REG); - RSPPushad(); - RSPCall_Direct(RSP_SP_DMA_WRITE); - RSPPopad(); - break; - case 7: - RSPMoveConstToVariable(0, &SP_SEMAPHORE_REG); - break; - case 8: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &DPC_START_REG); - RSPMoveX86regToVariable(x86_EAX, &DPC_CURRENT_REG); - break; - case 9: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &DPC_END_REG); - - break; - case 10: - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.rt].UW, x86_EAX); - RSPMoveX86regToVariable(x86_EAX, &DPC_CURRENT_REG); - break; - - default: - RSPCheat_r4300iOpcode(RSP_Cop0_MT); - break; - } -#endif - if (RSPOpC.rd == 2) { - uint8_t * Jump; - - RSPTestConstToVariable(0x1000, &SP_MEM_ADDR_REG); - RSPJeLabel8( 0); - Jump = RSPRecompPos - 1; - - RSPMoveConstToVariable(RSPCompilePC + 4,PrgCount); - RSPRet(); - - CPU_Message("DontExit:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } -} -/************************** Cop2 functions *************************/ - -void RSPCompile_Cop2_MF ( void ) { - - int32_t element = (RSPOpC.sa >> 1); - - int32_t element1 = 15 - element; - int32_t element2 = 15 - ((element + 1) % 16); - - #ifndef RSPCompile_Cop2 - RSPCheat_r4300iOpcode(RSP_Cop2_MF); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (element2 != (element1 - 1)) { - RSPXorX86RegToX86Reg(x86_EAX, x86_EAX); - RSPXorX86RegToX86Reg(x86_EBX, x86_EBX); - - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rd].B[element1], x86_EAX); - - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rd].B[element2], x86_EBX); - - RSPShiftLeftSignImmed(x86_EAX, 8); - RSPOrX86RegToX86Reg(x86_EAX, x86_EBX); - RSPCwde(); - - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - } else { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].B[element2], x86_EAX); - - RSPMoveX86regToVariable(x86_EAX, &RSP_GPR[RSPOpC.rt].W); - } -} - -void RSPCompile_Cop2_CF ( void ) { - RSPCheat_r4300iOpcode(RSP_Cop2_CF); -} - -void RSPCompile_Cop2_MT ( void ) { - - int32_t element = 15 - (RSPOpC.sa >> 1); - - #ifndef RSPCompile_Cop2 - RSPCheat_r4300iOpcode(RSP_Cop2_MT); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - if (element == 0) { - - RSPMoveVariableToX86regByte(&RSP_GPR[RSPOpC.rt].B[1], x86_EAX); - - - RSPMoveX86regByteToVariable(x86_EAX, &RSP_Vect[RSPOpC.rd].B[element]); - } else { - - RSPMoveVariableToX86regHalf(&RSP_GPR[RSPOpC.rt].B[0], x86_EAX); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.rd].B[element - 1]); - } -} - -void RSPCompile_Cop2_CT ( void ) { - RSPCheat_r4300iOpcode(RSP_Cop2_CT); -} - -void RSPCompile_COP2_VECTOR (void) { - ((void (*)()) RSP_Vector[ RSPOpC.funct ])(); -} - -/************************** Vect functions **************************/ - -MIPS_DWORD MMX_Scratch; - -void RSP_Element2Mmx(int32_t MmxReg) { - - - uint32_t Rs = RSPOpC.rs & 0x0f; - uint32_t el; - - switch (Rs) { - case 0: case 1: - case 2: case 3: - case 4: case 5: - case 6: case 7: - //CompilerWarning("Unimplemented RSP_Element2Mmx"); - break; - - default: - /* - * Noticed the exclusive-or of seven to take into account - * the pseudo-swapping we have in the vector registers - */ - - el = (RSPOpC.rs & 0x07) ^ 7; - - if (IsMmx2Enabled == 0) { - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[el], x86_ECX); - RSPMoveX86regHalfToVariable(x86_ECX, &MMX_Scratch.HW[0]); - RSPMoveX86regHalfToVariable(x86_ECX, &MMX_Scratch.HW[1]); - RSPMoveX86regHalfToVariable(x86_ECX, &MMX_Scratch.HW[2]); - RSPMoveX86regHalfToVariable(x86_ECX, &MMX_Scratch.HW[3]); - RSPMmxMoveQwordVariableToReg(MmxReg, &MMX_Scratch.HW[0]); - } else { - uint32_t Qword; - - Qword = (el >> 2) & 0x1; - el &= 0x3; - - - RSPMmxShuffleMemoryToReg(MmxReg, - &RSP_Vect[RSPOpC.rt].DW[Qword], _MMX_SHUFFLE(el, el, el, el)); - } - break; - } -} - -void RSP_MultiElement2Mmx(int32_t MmxReg1, int32_t MmxReg2) { - - uint32_t Rs = RSPOpC.rs & 0x0f; - - /* - * Ok, this is tricky, hopefully this clears it up: - * - * $vd[0] = $vd[0] + $vt[2] - * because of swapped registers becomes: - * $vd[7] = $vd[7] + $vt[5] - * - * we must perform this swap correctly, this involves the 3-bit - * xclusive or, 2-bits of which are done within a dword boundary, - * the last bit, is ignored because we are loading the source linearly, - * so the xclusive or has transparently happened on that side - * - */ - - switch (Rs) { - case 0: - case 1: - - RSPMmxMoveQwordVariableToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].UHW[0]); - - RSPMmxMoveQwordVariableToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].UHW[4]); - break; - case 2: - /* [0q] | 0 | 0 | 2 | 2 | 4 | 4 | 6 | 6 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0xF5); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0xF5); - break; - case 3: - /* [1q] | 1 | 1 | 3 | 3 | 5 | 5 | 7 | 7 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0xA0); - //RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0x0A); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0xA0); - //RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0x0A); - break; - case 4: - /* [0h] | 0 | 0 | 0 | 0 | 4 | 4 | 4 | 4 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0xFF); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0xFF); - break; - case 5: - /* [1h] | 1 | 1 | 1 | 1 | 5 | 5 | 5 | 5 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0xAA); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0xAA); - break; - case 6: - /* [2h] | 2 | 2 | 2 | 2 | 6 | 6 | 6 | 6 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0x55); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0x55); - break; - case 7: - /* [3h] | 3 | 3 | 3 | 3 | 7 | 7 | 7 | 7 | */ - - RSPMmxShuffleMemoryToReg(MmxReg1, &RSP_Vect[RSPOpC.rt].DW[0], 0x00); - - RSPMmxShuffleMemoryToReg(MmxReg2, &RSP_Vect[RSPOpC.rt].DW[1], 0x00); - break; - - default: - //CompilerWarning("Unimplemented RSP_MultiElement2Mmx [?]"); - break; - } -} - -int32_t RSPCompile_Vector_VMULF_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - /* NOTE: Problem here is the lack of +/- 0x8000 rounding */ - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxPmulhwRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.rt].UHW[0]); - - RSPMmxPmulhwRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.rt].UHW[4]); - } else if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM1, x86_MM2); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPmulhwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM1, x86_MM3); - } - RSPMmxPsllwImmed(x86_MM0, 1); - RSPMmxPsllwImmed(x86_MM1, 1); - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VMULF ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - - #ifndef RSPCompileVmulf - RSPCheat_r4300iOpcode(RSP_Vector_VMULF); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VMULF_MMX()) - return; - } - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - if (bWriteToDest == 1) { - RSPMoveConstToX86reg(0x7fff0000, x86_ESI); - } - if (bWriteToAccum == 1) { - RSPXorX86RegToX86Reg(x86_EDI, x86_EDI); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (RSPOpC.rt == RSPOpC.rd && !bOptimize) { - RSPimulX86reg(x86_EAX); - } else { - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - RSPimulX86reg(x86_EBX); - } - - RSPShiftLeftSignImmed(x86_EAX, 1); - RSPAddConstToX86Reg(x86_EAX, 0x8000); - - if (bWriteToAccum == 1) { - RSPMoveX86regToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - /* calculate sign extension into edx */ - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 31); - } - - RSPCompConstToX86reg(x86_EAX, 0x80008000); - - if (bWriteToAccum == 1) { - RSPCondMoveEqual(x86_EDX, x86_EDI); - RSPMoveX86regHalfToVariable(x86_EDX, &RSP_ACCUM[el].HW[3]); - } - if (bWriteToDest == 1) { - RSPCondMoveEqual(x86_EAX, x86_ESI); - RSPShiftRightUnsignImmed(x86_EAX, 16); - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } -} - -void RSPCompile_Vector_VMULU ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VMULU); -} - -int32_t RSPCompile_Vector_VMUDL_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if (IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxMoveQwordVariableToReg(x86_MM2, &RSP_Vect[RSPOpC.rt].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM3, &RSP_Vect[RSPOpC.rt].UHW[4]); - - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM3); - } else if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM2); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VMUDL ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmudl - RSPCheat_r4300iOpcode(RSP_Vector_VMUDL); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VMUDL_MMX()) - return; - } - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - if (bWriteToAccum == 1) - RSPXorX86RegToX86Reg(x86_EDI, x86_EDI); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].UHW[el], x86_EAX); - - if (bOptimize == 0) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPimulX86reg(x86_EBX); - - if (bWriteToAccum == 1) { - - RSPMoveX86regToVariable(x86_EAX, &RSP_ACCUM[el].UW[0]); - - RSPMoveX86regToVariable(x86_EDI, &RSP_ACCUM[el].UW[1]); - } - - if (bWriteToDest == 1) { - RSPShiftRightUnsignImmed(x86_EAX, 16); - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } -} - -int32_t RSPCompile_Vector_VMUDM_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if (IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxMoveQwordVariableToReg(x86_MM4, &RSP_Vect[RSPOpC.rt].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM5, &RSP_Vect[RSPOpC.rt].UHW[4]); - - /* Copy the signed portion */ - RSPMmxMoveRegToReg(x86_MM2, x86_MM0); - RSPMmxMoveRegToReg(x86_MM3, x86_MM1); - - /* high((u16)a * b) */ - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM4); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM5); - - /* low((a >> 15) * b) */ - RSPMmxPsrawImmed(x86_MM2, 15); - RSPMmxPsrawImmed(x86_MM3, 15); - RSPMmxPmullwRegToReg(x86_MM2, x86_MM4); - RSPMmxPmullwRegToReg(x86_MM3, x86_MM5); - } else if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM4); - - /* Copy the signed portion */ - RSPMmxMoveRegToReg(x86_MM2, x86_MM0); - RSPMmxMoveRegToReg(x86_MM3, x86_MM1); - - /* high((u16)a * b) */ - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM4); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM4); - - /* low((a >> 15) * b) */ - RSPMmxPsrawImmed(x86_MM2, 15); - RSPMmxPsrawImmed(x86_MM3, 15); - RSPMmxPmullwRegToReg(x86_MM2, x86_MM4); - RSPMmxPmullwRegToReg(x86_MM3, x86_MM4); - } else { - RSP_MultiElement2Mmx(x86_MM4, x86_MM5); - - /* Copy the signed portion */ - RSPMmxMoveRegToReg(x86_MM2, x86_MM0); - RSPMmxMoveRegToReg(x86_MM3, x86_MM1); - - /* high((u16)a * b) */ - RSPMmxPmulhuwRegToReg(x86_MM0, x86_MM4); - RSPMmxPmulhuwRegToReg(x86_MM1, x86_MM5); - - /* low((a >> 15) * b) */ - RSPMmxPsrawImmed(x86_MM2, 15); - RSPMmxPsrawImmed(x86_MM3, 15); - RSPMmxPmullwRegToReg(x86_MM2, x86_MM4); - RSPMmxPmullwRegToReg(x86_MM3, x86_MM5); - } - - /* Add them up */ - RSPMmxPaddwRegToReg(x86_MM0, x86_MM2); - RSPMmxPaddwRegToReg(x86_MM1, x86_MM3); - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VMUDM ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmudm - RSPCheat_r4300iOpcode(RSP_Vector_VMUDM); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VMUDM_MMX()) - return; - } - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - if (bWriteToDest) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.sa].HW[0], x86_RCX); - } else if (!bOptimize) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rt].HW[0], x86_RCX); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX);*/ - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bOptimize == 0) { - if (bWriteToDest == 1) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } else { - RSPMoveZxX86RegPtrDispToX86RegHalf(x86_RCX, del * 2, x86_EBX); - } - } - - RSPimulX86reg(x86_EBX); - - if (bWriteToAccum == 0 && bWriteToDest == 1) { - RSPShiftRightUnsignImmed(x86_EAX, 16); - /* - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]);*/ - RSPMoveX86regHalfToX86regPointerDisp(x86_EAX, x86_ECX, el * 2); - } else { - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 16); - RSPShiftLeftSignImmed(x86_EAX, 16); - - if (bWriteToAccum == 1) { - - RSPMoveX86regToVariable(x86_EAX, &RSP_ACCUM[el].UW[0]); - - RSPMoveX86regToVariable(x86_EDX ,&RSP_ACCUM[el].UW[1]); - } - if (bWriteToDest == 1) { - /* - RSPMoveX86regHalfToVariable(x86_EDX, &RSP_Vect[RSPOpC.sa].HW[el]);*/ - RSPMoveX86regHalfToX86regPointerDisp(x86_EDX, x86_ECX, el * 2); - } - } - } - - RSPPop(x86_RBP); -} - -int32_t RSPCompile_Vector_VMUDN_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxPmullwVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rt].UHW[0]); - - RSPMmxPmullwVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rt].UHW[4]); - } else if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPmullwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmullwRegToReg(x86_MM1, x86_MM2); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPmullwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmullwRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VMUDN ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmudn - RSPCheat_r4300iOpcode(RSP_Vector_VMUDN); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VMUDN_MMX()) - return; - } - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].UHW[el], x86_EAX);*/ - RSPMoveZxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPimulX86reg(x86_EBX); - - if (bWriteToDest == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - - if (bWriteToAccum == 1) { - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 16); - RSPShiftLeftSignImmed(x86_EAX, 16); - - RSPMoveX86regToVariable(x86_EAX, &RSP_ACCUM[el].UW[0]); - - RSPMoveX86regToVariable(x86_EDX, &RSP_ACCUM[el].UW[1]); - } - } - RSPPop(x86_RBP); -} - -int32_t RSPCompile_Vector_VMUDH_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].HW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].HW[4]); - - /* Registers 4 & 5 are high */ - RSPMmxMoveRegToReg(x86_MM4, x86_MM0); - RSPMmxMoveRegToReg(x86_MM5, x86_MM1); - - if ((RSPOpC.rs & 0x0f) < 2) { - - RSPMmxMoveQwordVariableToReg(x86_MM2, &RSP_Vect[RSPOpC.rt].HW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM3, &RSP_Vect[RSPOpC.rt].HW[4]); - - RSPMmxPmullwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM4, x86_MM2); - RSPMmxPmullwRegToReg(x86_MM1, x86_MM3); - RSPMmxPmulhwRegToReg(x86_MM5, x86_MM3); - } else if ((RSPOpC.rs & 0x0f) >= 8) { - RSP_Element2Mmx(x86_MM2); - - RSPMmxPmullwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM4, x86_MM2); - RSPMmxPmullwRegToReg(x86_MM1, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM5, x86_MM2); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - - RSPMmxPmullwRegToReg(x86_MM0, x86_MM2); - RSPMmxPmulhwRegToReg(x86_MM4, x86_MM2); - RSPMmxPmullwRegToReg(x86_MM1, x86_MM3); - RSPMmxPmulhwRegToReg(x86_MM5, x86_MM3); - } - - /* 0 & 1 are low, 4 & 5 are high */ - RSPMmxMoveRegToReg(x86_MM6, x86_MM0); - RSPMmxMoveRegToReg(x86_MM7, x86_MM1); - - RSPMmxUnpackLowWord(x86_MM0, x86_MM4); - RSPMmxUnpackHighWord(x86_MM6, x86_MM4); - RSPMmxUnpackLowWord(x86_MM1, x86_MM5); - RSPMmxUnpackHighWord(x86_MM7, x86_MM5); - - /* Integrate copies */ - RSPMmxPackSignedDwords(x86_MM0, x86_MM6); - RSPMmxPackSignedDwords(x86_MM1, x86_MM7); - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].HW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].HW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VMUDH ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - -// RSPBreakPoint(); - #ifndef RSPCompileVmudh - RSPCheat_r4300iOpcode(RSP_Vector_VMUDH); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VMUDH_MMX()) - return; - } - - if (bWriteToDest == 0 && bOptimize == 1) { - RSPPush(x86_RBP); - - - /* Load source */ - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - - /* - * Pipe lined segment 0 - */ - - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 0, x86_EAX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 2, x86_ECX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 4, x86_EDI); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 6, x86_ESI); - - RSPImulX86RegToX86Reg(x86_EAX, x86_EBX); - RSPImulX86RegToX86Reg(x86_ECX, x86_EBX); - RSPImulX86RegToX86Reg(x86_EDI, x86_EBX); - RSPImulX86RegToX86Reg(x86_ESI, x86_EBX); - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_ACCUM[0].W[0], x86_RBP); - - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 0); - RSPMoveX86RegToX86regPointerDisp(x86_EAX, x86_RBP, 4); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 8); - RSPMoveX86RegToX86regPointerDisp(x86_ECX, x86_RBP, 12); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 16); - RSPMoveX86RegToX86regPointerDisp(x86_EDI, x86_RBP, 20); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 24); - RSPMoveX86RegToX86regPointerDisp(x86_ESI, x86_RBP, 28); - - /* - * Pipe lined segment 1 - */ - - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 8, x86_EAX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 10, x86_ECX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 12, x86_EDI); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 14, x86_ESI); - - RSPImulX86RegToX86Reg(x86_EAX, x86_EBX); - RSPImulX86RegToX86Reg(x86_ECX, x86_EBX); - RSPImulX86RegToX86Reg(x86_EDI, x86_EBX); - RSPImulX86RegToX86Reg(x86_ESI, x86_EBX); - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_ACCUM[0].W[0], x86_RBP); - - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 32); - RSPMoveX86RegToX86regPointerDisp(x86_EAX, x86_RBP, 36); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 40); - RSPMoveX86RegToX86regPointerDisp(x86_ECX, x86_RBP, 44); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 48); - RSPMoveX86RegToX86regPointerDisp(x86_EDI, x86_RBP, 52); - RSPMoveX86RegToX86regPointerDisp(x86_EDX, x86_RBP, 56); - RSPMoveX86RegToX86regPointerDisp(x86_ESI, x86_RBP, 60); - - RSPPop(x86_RBP); - } else { - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xFFFF8000, x86_EDI); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - RSPimulX86reg(x86_EBX); - - if (bWriteToAccum == 1) { - RSPMoveX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[1]); - RSPMoveConstToVariable(0, &RSP_ACCUM[el].W[0]); - } - - if (bWriteToDest == 1) { - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - } -} - -void RSPCompile_Vector_VMACF ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmacf - RSPCheat_r4300iOpcode(RSP_Vector_VMACF); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xFFFF8000, x86_EDI); - } - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - for (count = 0; count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - CPU_Message( count); - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPimulX86reg(x86_EBX); - - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 15); - RSPShiftLeftSignImmed(x86_EAX, 17); - - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[0]); - RSPAdcX86regToVariable(x86_EDX, &RSP_ACCUM[el].W[1]); - - if (bWriteToDest == 1) { - RSPMoveVariableToX86reg(&RSP_ACCUM[el].W[1], x86_EAX); - - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } -} - -void RSPCompile_Vector_VMACU ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VMACU); -} - -void RSPCompile_Vector_VMACQ ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VMACQ); -} - -void RSPCompile_Vector_VMADL ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - - #ifndef RSPCompileVmadl - RSPCheat_r4300iOpcode(RSP_Vector_VMADL); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007FFF, x86_ESI); - RSPMoveConstToX86reg(0xFFFF8000, x86_EDI); - - RSPPush(x86_RBP); - RSPMoveConstToX86reg(0x0000FFFF, x86_EBP); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bOptimize == 0) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPimulX86reg(x86_EBX); - - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[0]); - - RSPAdcConstToVariable(&RSP_ACCUM[el].W[1], 0); - - if (bWriteToDest != 0) { - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - RSPMoveVariableToX86reg(&RSP_ACCUM[el].W[1], x86_EAX); - RSPMoveZxVariableToX86regHalf(&RSP_ACCUM[el].HW[1], x86_ECX); - - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_ECX, x86_EBP); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_ECX, x86_EDX); - - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - - if (bWriteToDest == 1) { - RSPPop(x86_EBP); - } -} - -void RSPCompile_Vector_VMADM ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmadm - RSPCheat_r4300iOpcode(RSP_Vector_VMADM); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xFFFF8000, x86_EDI); - } - - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - if (bWriteToDest) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.sa].HW[0], x86_RCX); - } else if (!bOptimize) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rt].HW[0], x86_RCX); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX);*/ - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bOptimize == 0) { - if (bWriteToDest == 1) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } else { - RSPMoveZxX86RegPtrDispToX86RegHalf(x86_ECX, del * 2, x86_EBX); - } - } - - RSPimulX86reg(x86_EBX); - - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 16); - RSPShiftLeftSignImmed(x86_EAX, 16); - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[0]); - RSPAdcX86regToVariable(x86_EDX, &RSP_ACCUM[el].W[1]); - - if (bWriteToDest == 1) { - /* For compare */ - - RSPMoveVariableToX86reg(&RSP_ACCUM[el].W[1], x86_EAX); - - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - /* - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]);*/ - RSPMoveX86regHalfToX86regPointerDisp(x86_EAX, x86_ECX, el * 2); - } - } - - RSPPop(x86_RBP); -} - -void RSPCompile_Vector_VMADN ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(EntireAccum, RSPCompilePC); - - #ifndef RSPCompileVmadn - RSPCheat_r4300iOpcode(RSP_Vector_VMADN); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x0000ffff, x86_ESI); - RSPMoveConstToX86reg(0x00000000, x86_EDI); - } - - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].UHW[el], x86_EAX);*/ - RSPMoveZxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPimulX86reg(x86_EBX); - - RSPMoveX86RegToX86Reg(x86_EAX, x86_EDX); - RSPShiftRightSignImmed(x86_EDX, 16); - RSPShiftLeftSignImmed(x86_EAX, 16); - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[0]); - RSPAdcX86regToVariable(x86_EDX, &RSP_ACCUM[el].W[1]); - - if (bWriteToDest == 1) { - /* For compare */ - - RSPMoveVariableToX86reg(&RSP_ACCUM[el].W[1], x86_EAX); - - /* For vector */ - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[el].HW[1], x86_ECX); - - /* Weird eh */ - RSPCompConstToX86reg(x86_EAX, 0x7fff); - RSPCondMoveGreater(x86_ECX, x86_ESI); - RSPCompConstToX86reg(x86_EAX, -0x8000); - RSPCondMoveLess(x86_ECX, x86_EDI); - - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - RSPPop(x86_RBP); -} - -void RSPCompile_Vector_VMADH ( void ) { - - int32_t count, el, del; - - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - - #ifndef RSPCompileVmadh - RSPCheat_r4300iOpcode(RSP_Vector_VMADH); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xFFFF8000, x86_EDI); - } - - if (bWriteToDest == 0 && bOptimize == 1) { - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - /* - * Pipe lined segment 0 - */ - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 0, x86_EAX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 2, x86_ECX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 4, x86_EDI); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 6, x86_ESI); - - RSPImulX86RegToX86Reg(x86_EAX, x86_EBX); - RSPImulX86RegToX86Reg(x86_ECX, x86_EBX); - RSPImulX86RegToX86Reg(x86_EDI, x86_EBX); - RSPImulX86RegToX86Reg(x86_ESI, x86_EBX); - - - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[0].W[1]); - - RSPAddX86regToVariable(x86_ECX, &RSP_ACCUM[1].W[1]); - - RSPAddX86regToVariable(x86_EDI, &RSP_ACCUM[2].W[1]); - - RSPAddX86regToVariable(x86_ESI, &RSP_ACCUM[3].W[1]); - - /* - * Pipe lined segment 1 - */ - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 8, x86_EAX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 10, x86_ECX); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 12, x86_EDI); - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, 14, x86_ESI); - - RSPImulX86RegToX86Reg(x86_EAX, x86_EBX); - RSPImulX86RegToX86Reg(x86_ECX, x86_EBX); - RSPImulX86RegToX86Reg(x86_EDI, x86_EBX); - RSPImulX86RegToX86Reg(x86_ESI, x86_EBX); - - - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[4].W[1]); - - RSPAddX86regToVariable(x86_ECX, &RSP_ACCUM[5].W[1]); - - RSPAddX86regToVariable(x86_EDI, &RSP_ACCUM[6].W[1]); - - RSPAddX86regToVariable(x86_ESI, &RSP_ACCUM[7].W[1]); - - RSPPop(x86_EBP); - } else { - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - if (bWriteToDest) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.sa].HW[0], x86_RCX); - } else if (!bOptimize) { - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rt].HW[0], x86_RCX); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX);*/ - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bOptimize == 0) { - if (bWriteToDest == 1) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } else { - RSPMoveSxX86RegPtrDispToX86RegHalf(x86_RCX, del * 2, x86_EBX); - } - } - - RSPimulX86reg(x86_EBX); - - RSPAddX86regToVariable(x86_EAX, &RSP_ACCUM[el].W[1]); - - if (bWriteToDest == 1) { - RSPMoveVariableToX86reg(&RSP_ACCUM[el].W[1], x86_EAX); - - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - /* - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]);*/ - RSPMoveX86regHalfToX86regPointerDisp(x86_EAX, x86_ECX, el * 2); - } - } - RSPPop(x86_RBP); - } -} - -int32_t RSPCompile_Vector_VADD_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 15) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPaddswRegToReg(x86_MM0, x86_MM2); - RSPMmxPaddswRegToReg(x86_MM1, x86_MM2); - } else if ((RSPOpC.rs & 15) < 2) { - - RSPMmxPaddswVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rt].HW[0]); - - RSPMmxPaddswVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rt].HW[4]); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPaddswRegToReg(x86_MM0, x86_MM2); - RSPMmxPaddswRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VADD ( void ) { - - int32_t count, el, del; - - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bElement = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - int32_t bFlagUseage = UseRspFlags(RSPCompilePC); - - #ifndef RSPCompileVadd - RSPCheat_r4300iOpcode(RSP_Vector_VADD); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0 && bFlagUseage == 0) { - if (1 == RSPCompile_Vector_VADD_MMX()) - return; - } - - if (bElement == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xffff8000, x86_EDI); - } - - /* Used for involking x86 carry flag */ - RSPXorX86RegToX86Reg(x86_ECX, x86_ECX); - RSPPush(x86_RBP); - RSPMoveVariableToX86reg(&RSP_Flags[0].UW, x86_EBP); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bElement == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPMoveX86RegToX86Reg(x86_EBP, x86_EDX); - RSPAndConstToX86Reg(x86_EDX, 1 << (7 - el)); - RSPCompX86RegToX86Reg(x86_ECX, x86_EDX); - - RSPAdcX86RegToX86Reg(x86_EAX, x86_EBX); - - if (bWriteToAccum == 1) { - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - if (bWriteToDest == 1) { - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - RSPMoveConstToVariable(0, &RSP_Flags[0].UW); - RSPPop(x86_EBP); -} - -void RSPCompile_Vector_VSUB ( void ) { - - int32_t count, el, del; - - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bOptimize = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - #ifndef RSPCompileVsub - RSPCheat_r4300iOpcode(RSP_Vector_VSUB); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPPush(x86_RBP); - - /* Used for involking the x86 carry flag */ - RSPXorX86RegToX86Reg(x86_ECX, x86_ECX); - RSPMoveVariableToX86reg(&RSP_Flags[0].UW, x86_EBP); - - if (bOptimize == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - if (bWriteToDest == 1) { - /* - * Prepare for conditional moves - */ - RSPMoveConstToX86reg(0x00007fff, x86_ESI); - RSPMoveConstToX86reg(0xffff8000, x86_EDI); - } - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - if (bOptimize == 0) { - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPMoveX86RegToX86Reg(x86_EBP, x86_EDX); - RSPAndConstToX86Reg(x86_EDX, 1 << (7 - el)); - RSPCompX86RegToX86Reg(x86_ECX, x86_EDX); - - RSPSbbX86RegToX86Reg(x86_EAX, x86_EBX); - - if (bWriteToAccum == 1) { - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - if (bWriteToDest == 1) { - RSPCompX86RegToX86Reg(x86_EAX, x86_ESI); - RSPCondMoveGreater(x86_EAX, x86_ESI); - RSPCompX86RegToX86Reg(x86_EAX, x86_EDI); - RSPCondMoveLess(x86_EAX, x86_EDI); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - - RSPMoveConstToVariable(0, &RSP_Flags[0].UW); - RSPPop(x86_EBP); -} - -void RSPCompile_Vector_VABS ( void ) { - int32_t count, el, del; - - - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - #ifndef RSPCompileVabs - RSPCheat_r4300iOpcode(RSP_Vector_VABS); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - if (RSPOpC.rd == RSPOpC.rt && (RSPOpC.rs & 0xF) < 2) { - /** - ** Optimize: EDI/ESI unused, and ECX is const etc - ***/ - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - /*** Obtain the negative of the source ****/ - RSPMoveX86RegToX86Reg(x86_EAX, x86_EBX); - RSPNegateX86reg(x86_EBX); - - /** - ** determine negative value, - ** note: negate(FFFF8000h) == 00008000h - ***/ - - RSPMoveConstToX86reg(0x7fff, x86_ECX); - RSPCompConstToX86reg(x86_EBX, 0x00008000); - RSPCondMoveEqual(x86_EBX, x86_ECX); - - /* sign clamp, dest = (eax >= 0) ? eax : ebx */ - RSPCompConstToX86reg(x86_EAX, 0); - RSPCondMoveLess(x86_EAX, x86_EBX); - - if (bWriteToDest == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - if (bWriteToAccum == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - } else { - /** - ** Optimize: ESI unused, and EDX is const etc - ***/ - - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - RSPMoveSxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - - /*** Obtain the negative of the source ****/ - RSPMoveX86RegToX86Reg(x86_EBX, x86_ECX); - RSPNegateX86reg(x86_EBX); - - /** - ** determine negative value, - ** note: negate(FFFF8000h) == 00008000h - ***/ - - RSPMoveConstToX86reg(0x7fff, x86_EDX); - RSPCompConstToX86reg(x86_EBX, 0x00008000); - RSPCondMoveEqual(x86_EBX, x86_EDX); - - /* sign clamp, dest = (eax >= 0) ? ecx : ebx */ - RSPCompConstToX86reg(x86_EAX, 0); - RSPCondMoveGreaterEqual(x86_EDI, x86_ECX); - RSPCondMoveLess(x86_EDI, x86_EBX); - - if (bWriteToDest == 1) { - - RSPMoveX86regHalfToVariable(x86_EDI, &RSP_Vect[RSPOpC.sa].HW[el]); - } - if (bWriteToAccum == 1) { - - RSPMoveX86regHalfToVariable(x86_EDI, &RSP_ACCUM[el].HW[1]); - } - } - } -} - -void RSPCompile_Vector_VADDC ( void ) { - - int32_t count, el, del; - - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - int32_t bElement = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - - #ifndef RSPCompileVaddc - RSPCheat_r4300iOpcode(RSP_Vector_VADDC); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bElement == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - /* Initialize flag register */ - RSPXorX86RegToX86Reg(x86_ECX, x86_ECX); - - RSPPush(x86_RBP); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rd].HW[0], x86_RBP); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - /* - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX);*/ - RSPMoveZxX86RegPtrDispToX86RegHalf(x86_RBP, el * 2, x86_EAX); - - if (bElement == 0) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPAddX86RegToX86Reg(x86_EAX, x86_EBX); - - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - RSPTestConstToX86Reg(0xFFFF0000, x86_EAX); - RSPSetnz(x86_EDX); - if ((7 - el) != 0) { - RSPShiftLeftSignImmed(x86_EDX, 7 - el); - } - RSPOrX86RegToX86Reg(x86_ECX, x86_EDX); - - if (bWriteToAccum == 1) { - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - if (bWriteToDest == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - RSPMoveX86regToVariable(x86_ECX, &RSP_Flags[0].UW); - RSPPop(x86_RBP); -} - -void RSPCompile_Vector_VSUBC ( void ) { - - int32_t count, el, del; - - int32_t bWriteToDest = WriteToVectorDest(RSPOpC.sa, RSPCompilePC); - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - int32_t bElement = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - - #ifndef RSPCompileVsubc - RSPCheat_r4300iOpcode(RSP_Vector_VSUBC); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bElement == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - /* Initialize flag register */ - RSPXorX86RegToX86Reg(x86_ECX, x86_ECX); - - for (count = 0; count < 8; count++) { - CPU_Message( count); - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bElement == 0) { - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - RSPSubX86RegToX86Reg(x86_EAX, x86_EBX); - - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - RSPTestConstToX86Reg(0x0000FFFF, x86_EAX); - RSPSetnz(x86_EDX); - RSPShiftLeftSignImmed(x86_EDX, 15 - el); - RSPOrX86RegToX86Reg(x86_ECX, x86_EDX); - - RSPXorX86RegToX86Reg(x86_EDX, x86_EDX); - RSPTestConstToX86Reg(0xFFFF0000, x86_EAX); - RSPSetnz(x86_EDX); - RSPShiftLeftSignImmed(x86_EDX, 7 - el); - RSPOrX86RegToX86Reg(x86_ECX, x86_EDX); - - if (bWriteToAccum == 1) { - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - if (bWriteToDest == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } - } - RSPMoveX86regToVariable(x86_ECX, &RSP_Flags[0].UW); -} - -void RSPCompile_Vector_VSAW ( void ) { - - uint32_t Word; - - #ifndef RSPCompileVsaw - RSPCheat_r4300iOpcode(RSP_Vector_VSAW); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - switch ((RSPOpC.rs & 0xF)) { - case 8: Word = 3; break; - case 9: Word = 2; break; - case 10: Word = 1; break; - default: - RSPMoveConstToVariable(0, &RSP_Vect[RSPOpC.sa].DW[1]); - RSPMoveConstToVariable(0, &RSP_Vect[RSPOpC.sa].DW[0]); - return; - } - - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[1].HW[Word], x86_EAX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[3].HW[Word], x86_EBX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[5].HW[Word], x86_ECX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[7].HW[Word], x86_EDX); - - RSPShiftLeftSignImmed(x86_EAX, 16); - RSPShiftLeftSignImmed(x86_EBX, 16); - RSPShiftLeftSignImmed(x86_ECX, 16); - RSPShiftLeftSignImmed(x86_EDX, 16); - - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[0].HW[Word], x86_EAX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[2].HW[Word], x86_EBX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[4].HW[Word], x86_ECX); - - RSPMoveVariableToX86regHalf(&RSP_ACCUM[6].HW[Word], x86_EDX); - - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[0]); - - RSPMoveX86regToVariable(x86_EBX, &RSP_Vect[RSPOpC.sa].HW[2]); - - RSPMoveX86regToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].HW[4]); - - RSPMoveX86regToVariable(x86_EDX, &RSP_Vect[RSPOpC.sa].HW[6]); -} - -void RSPCompile_Vector_VLT ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VLT); -} - -void RSPCompile_Vector_VEQ ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VEQ); -} - -void RSPCompile_Vector_VNE ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VNE); -} - -int32_t RSPCompile_Vector_VGE_MMX(void) { - - - if ((RSPOpC.rs & 0xF) >= 2 && (RSPOpC.rs & 0xF) <= 7 && IsMmx2Enabled == 0) - return 0; - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveConstToVariable(0, &RSP_Flags[1].UW); - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].HW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].HW[4]); - RSPMmxMoveRegToReg(x86_MM2, x86_MM0); - RSPMmxMoveRegToReg(x86_MM3, x86_MM1); - - if ((RSPOpC.rs & 0x0f) < 2) { - - RSPMmxMoveQwordVariableToReg(x86_MM4, &RSP_Vect[RSPOpC.rt].HW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM5, &RSP_Vect[RSPOpC.rt].HW[4]); - } else if ((RSPOpC.rs & 0x0f) >= 8) { - RSP_Element2Mmx(x86_MM4); - } else { - RSP_MultiElement2Mmx(x86_MM4, x86_MM5); - } - - RSPMmxCompareGreaterWordRegToReg(x86_MM2, x86_MM4); - RSPMmxCompareGreaterWordRegToReg(x86_MM3, ((RSPOpC.rs & 0x0f) >= 8) ? x86_MM4 : x86_MM5); - - RSPMmxPandRegToReg(x86_MM0, x86_MM2); - RSPMmxPandRegToReg(x86_MM1, x86_MM3); - RSPMmxPandnRegToReg(x86_MM2, x86_MM4); - RSPMmxPandnRegToReg(x86_MM3, ((RSPOpC.rs & 0x0f) >= 8) ? x86_MM4 : x86_MM5); - - RSPMmxPorRegToReg(x86_MM0, x86_MM2); - RSPMmxPorRegToReg(x86_MM1, x86_MM3); - RSPMoveConstToVariable(0, &RSP_Flags[0].UW); - return 1; -} - -void RSPCompile_Vector_VGE ( void ) { -/* int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - /* FIXME: works ok, but needs careful flag analysis */ -/* #if defined (DLIST) - if (bWriteToAccum == 0 && 1 == RSPCompile_Vector_VGE_MMX()) { - return; - } - #endif -*/ - RSPCheat_r4300iOpcode(RSP_Vector_VGE); -} - -void RSPCompile_Vector_VCL ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VCL); -} - -void RSPCompile_Vector_VCH ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VCH); -} - -void RSPCompile_Vector_VCR ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VCR); -} - -void RSPCompile_Vector_VMRG ( void ) { - - int32_t count, el, del; - - #ifndef RSPCompileVmrg - RSPCheat_r4300iOpcode(RSP_Vector_VMRG); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPMoveVariableToX86reg(&RSP_Flags[1].UW, x86_EDX); - - for (count = 0;count < 8; count++) { - el = Indx[RSPOpC.rs].UB[count]; - del = EleSpec[RSPOpC.rs].UB[el]; - CPU_Message( count); - - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - RSPMoveZxVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - - RSPTestConstToX86Reg(1 << (7 - el), x86_EDX); - RSPCondMoveNotEqual(x86_ECX, x86_EAX); - RSPCondMoveEqual(x86_ECX, x86_EBX); - - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].HW[el]); - } -} - -int32_t RSPCompile_Vector_VAND_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPandRegToReg(x86_MM0, x86_MM2); - RSPMmxPandRegToReg(x86_MM1, x86_MM2); - } else if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxPandVariableToReg(&RSP_Vect[RSPOpC.rt].HW[0], x86_MM0); - - RSPMmxPandVariableToReg(&RSP_Vect[RSPOpC.rt].HW[4], x86_MM1); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPandRegToReg(x86_MM0, x86_MM2); - RSPMmxPandRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VAND ( void ) { - - int32_t el, del, count; - int32_t bElement = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - #ifndef RSPCompileVand - RSPCheat_r4300iOpcode(RSP_Vector_VAND); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VAND_MMX()) - return; - } - - if (bElement == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - for (count = 0; count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - CPU_Message( count); - - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bElement == 0) { - - RSPAndVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EAX); - } else { - RSPAndX86RegHalfToX86RegHalf(x86_EAX, x86_EBX); - } - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - - if (bWriteToAccum != 0) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - } -} - -void RSPCompile_Vector_VNAND ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VNAND); -} - -int32_t RSPCompile_Vector_VOR_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 0) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxPorRegToReg(x86_MM0, x86_MM2); - RSPMmxPorRegToReg(x86_MM1, x86_MM2); - } else if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxPorVariableToReg(&RSP_Vect[RSPOpC.rt].HW[0], x86_MM0); - - RSPMmxPorVariableToReg(&RSP_Vect[RSPOpC.rt].HW[4], x86_MM1); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxPorRegToReg(x86_MM0, x86_MM2); - RSPMmxPorRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VOR ( void ) { - - int32_t el, del, count; - int32_t bElement = ((RSPOpC.rs & 0x0f) >= 8) ? 1 : 0; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - #ifndef RSPCompileVor - RSPCheat_r4300iOpcode(RSP_Vector_VOR); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (bWriteToAccum == 0) { - if (1 == RSPCompile_Vector_VOR_MMX()) - return; - } - - if (bElement == 1) { - del = (RSPOpC.rs & 0x07) ^ 7; - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EBX); - } - - for (count = 0; count < 8; count++) { - el = Indx[RSPOpC.rs].B[count]; - del = EleSpec[RSPOpC.rs].B[el]; - - CPU_Message( count); - - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rd].HW[el], x86_EAX); - - if (bElement == 0) { - - RSPOrVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].HW[del], x86_EAX); - } else { - RSPOrX86RegToX86Reg(x86_EAX, x86_EBX); - } - - if (bWriteToAccum == 1) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[el].HW[1]); - } - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_Vect[RSPOpC.sa].HW[el]); - } -} - -void RSPCompile_Vector_VNOR ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VNOR); -} - -int32_t RSPCompile_Vector_VXOR_MMX ( void ) { - - - /* Do our MMX checks here */ - if (IsMmxEnabled == 1) - return 0; - if ((RSPOpC.rs & 0x0f) >= 2 && (RSPOpC.rs & 0x0f) <= 7 && IsMmx2Enabled == 0) - return 0; - - if ((RSPOpC.rs & 0xF) < 2 && (RSPOpC.rd == RSPOpC.rt)) { - static uint32_t VXOR_DynaRegCount = 0; - RSPMmxXorRegToReg(VXOR_DynaRegCount+1, VXOR_DynaRegCount+1); - - - RSPMmxMoveQwordRegToVariable(VXOR_DynaRegCount+1, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(VXOR_DynaRegCount+1, &RSP_Vect[RSPOpC.sa].UHW[4]); - VXOR_DynaRegCount = (VXOR_DynaRegCount + 1) & 7; - } else { - - RSPMmxMoveQwordVariableToReg(x86_MM0, &RSP_Vect[RSPOpC.rd].UHW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM1, &RSP_Vect[RSPOpC.rd].UHW[4]); - - if ((RSPOpC.rs & 0xF) >= 8) { - RSP_Element2Mmx(x86_MM2); - RSPMmxXorRegToReg(x86_MM0, x86_MM2); - RSPMmxXorRegToReg(x86_MM1, x86_MM2); - } else if ((RSPOpC.rs & 0xF) < 2) { - - RSPMmxMoveQwordVariableToReg(x86_MM2, &RSP_Vect[RSPOpC.rt].HW[0]); - - RSPMmxMoveQwordVariableToReg(x86_MM3, &RSP_Vect[RSPOpC.rt].HW[4]); - - RSPMmxXorRegToReg(x86_MM0, x86_MM2); - RSPMmxXorRegToReg(x86_MM1, x86_MM3); - } else { - RSP_MultiElement2Mmx(x86_MM2, x86_MM3); - RSPMmxXorRegToReg(x86_MM0, x86_MM2); - RSPMmxXorRegToReg(x86_MM1, x86_MM3); - } - - - RSPMmxMoveQwordRegToVariable(x86_MM0, &RSP_Vect[RSPOpC.sa].UHW[0]); - - RSPMmxMoveQwordRegToVariable(x86_MM1, &RSP_Vect[RSPOpC.sa].UHW[4]); - } - - if (IsNextInstructionMmx(RSPCompilePC) == 0) - RSPMmxEmptyMultimediaState(); - - return 1; -} - -void RSPCompile_Vector_VXOR ( void ) { - #ifdef RSPCompileVxor - - uint32_t count; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (!bWriteToAccum || ((RSPOpC.rs & 0xF) < 2 && RSPOpC.rd == RSPOpC.rt)) { - if (1 == RSPCompile_Vector_VXOR_MMX()) { - if (bWriteToAccum == 1) { - RSPXorX86RegToX86Reg(x86_EAX, x86_EAX); - for (count = 0; count < 8; count++) { - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[count].HW[1]); - } - } - return; - } - } - #endif - - RSPCheat_r4300iOpcodeNoMessage(RSP_Vector_VXOR); -} - -void RSPCompile_Vector_VNXOR ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VNXOR); -} - -void RSPCompile_Vector_VRCP ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VRCP); -} - -void RSPCompile_Vector_VRCPL ( void ) { - RSPCheat_r4300iOpcode(RSP_Vector_VRCPL); -} - -void RSPCompile_Vector_VRCPH ( void ) { - - int32_t count, el, last = -1; - int32_t bWriteToAccum = WriteToAccum(Low16BitAccum, RSPCompilePC); - - #ifndef RSPCompileVrcph - RSPCheat_r4300iOpcode(RSP_Vector_VRCPH); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - el = EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]; - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].UHW[el], x86_EDX); - RSPMoveX86regHalfToVariable(x86_EDX, &Recp.UHW[1]); - - RSPMoveConstHalfToVariable(0, &Recp.UHW[0]); - - RSPMoveVariableToX86regHalf(&RecpResult.UHW[1], x86_ECX); - el = 7 - (RSPOpC.rd & 0x7); - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].UHW[el]); - - if (bWriteToAccum == 0) return; - - for (count = 0; count < 8; count++) { - el = EleSpec[RSPOpC.rs].B[count]; - - if (el != last) { - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].UHW[el], x86_EAX); - last = el; - } - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[count].HW[1]); - } -} - -void RSPCompile_Vector_VMOV ( void ) { - - int32_t el; - - #ifndef RSPCompileVmov - RSPCheat_r4300iOpcode(RSP_Vector_VMOV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - el = EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]; - - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].UHW[el], x86_ECX); - - el = 7 - (RSPOpC.rd & 0x7); - - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].UHW[el]); -} - -void RSPCompile_Vector_VRSQ ( void ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPCheat_r4300iOpcodeNoMessage(RSP_Vector_VRSQ); -} - -void RSPCompile_Vector_VRSQL ( void ) { - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - RSPCheat_r4300iOpcodeNoMessage(RSP_Vector_VRSQL); -} - -void RSPCompile_Vector_VRSQH ( void ) { - - int32_t count, el; - - #ifndef RSPCompileVrsqh - RSPCheat_r4300iOpcode(RSP_Vector_VRSQH); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - el = EleSpec[RSPOpC.rs].B[(RSPOpC.rd & 0x7)]; - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].UHW[el], x86_EDX); - RSPMoveX86regHalfToVariable(x86_EDX, &SQroot.UHW[1]); - - RSPMoveVariableToX86regHalf(&SQrootResult.UHW[1], x86_ECX); - el = 7 - (RSPOpC.rd & 0x7); - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.sa].UHW[el]); - - for (count = 0; count < 8; count++) { - el = EleSpec[RSPOpC.rs].B[count]; - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].UHW[el], x86_EAX); - - - RSPMoveX86regHalfToVariable(x86_EAX, &RSP_ACCUM[count].HW[1]); - } -} - -void RSPCompile_Vector_VNOOP ( void ) { - -} - -/************************** lc2 functions **************************/ - -void RSPCompile_Opcode_LBV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LBV); -} - -void RSPCompile_Opcode_LSV ( void ) { - - int32_t offset = (RSPOpC.voffset << 1); - - if (RSPOpC.del > 14) { - rsp_UnknownOpcode(); - return; - } - - #ifndef RSPCompileLsv - RSPCheat_r4300iOpcode(RSP_Opcode_LSV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 1) != 0) { - - RSPMoveVariableToX86regByte(DMEM + ((Addr + 0) ^ 3), x86_ECX); - - RSPMoveVariableToX86regByte(DMEM + ((Addr + 1) ^ 3), x86_EDX); - - - RSPMoveX86regByteToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 0)]); - - RSPMoveX86regByteToVariable(x86_EDX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)]); - } else { - - RSPMoveVariableToX86regHalf(DMEM + (Addr ^ 2), x86_EDX); - - RSPMoveX86regHalfToVariable(x86_EDX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)]); - } - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) RSPAddConstToX86Reg(x86_EBX, offset); - RSPAndConstToX86Reg(x86_EBX, 0x0FFF); - - if (Compiler.bAlignVector == 1) { - RSPXorConstToX86Reg(x86_EBX, 2); - RSPMoveN64MemToX86regHalf(x86_ECX, x86_EBX); - - RSPMoveX86regHalfToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)]); - } else { - RSPLeaSourceAndOffset(x86_EAX, x86_EBX, 1); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPXorConstToX86Reg(x86_EAX, 3); - - RSPMoveN64MemToX86regByte(x86_ECX, x86_EBX); - RSPMoveN64MemToX86regByte(x86_EDX, x86_EAX); - - - RSPMoveX86regByteToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 0)]); - - - RSPMoveX86regByteToVariable(x86_EDX, &RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)]); - } -} - -void RSPCompile_Opcode_LLV ( void ) { - - int32_t offset = (RSPOpC.voffset << 2); - uint8_t * Jump[2]; - - #ifndef RSPCompileLlv - RSPCheat_r4300iOpcode(RSP_Opcode_LLV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if ((RSPOpC.del & 0x3) != 0) { - rsp_UnknownOpcode(); - return; - } - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 3) != 0) { - //CompilerWarning("Unaligned LLV at constant address"); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LLV); - return; - } - - - RSPMoveVariableToX86reg(DMEM + Addr, x86_EAX); - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4]); - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) RSPAddConstToX86Reg(x86_EBX, offset); - - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - /* - * Unaligned - */ - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - *((uint32_t *)(Jump[0]))=(uint32_t)(RSPRecompPos - Jump[0] - 4); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LLV); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - - /* - * Aligned - */ - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPMoveN64MemToX86reg(x86_EAX, x86_EBX); - /* Because of byte swapping this swizzle works nicely */ - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4]); - - CPU_Message(" Done:"); - *((uint32_t *)(Jump[1]))=(uint32_t)(RSPRecompPos - Jump[1] - 4); -} - -void RSPCompile_Opcode_LDV ( void ) { - - int32_t offset = (RSPOpC.voffset << 3); - uint8_t * Jump[2], * LoopEntry; - //RSPBreakPoint(); - - #ifndef RSPCompileLdv - RSPCheat_r4300iOpcode(RSP_Opcode_LDV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - /* FIXME: Conker's hits this */ - //if ((RSPOpC.del & 0x7) != 0) { - // rsp_UnknownOpcode(); - // return; - //} - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 3) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LDV); - return; - } - - - RSPMoveVariableToX86reg(DMEM + Addr + 0, x86_EAX); - - RSPMoveVariableToX86reg(DMEM + Addr + 4, x86_ECX); - - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4]); - - RSPMoveX86regToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 8]); - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) { - RSPAddConstToX86Reg(x86_EBX, offset); - } - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rt].UB[15 - RSPOpC.del], x86_RDI); - RSPMoveConstToX86reg(8, x86_ECX); - -/* mov eax, ebx - dec edi - xor eax, 3h - inc ebx - mov dl, byte ptr [eax+Dmem] - dec ecx - mov byte ptr [edi+1], dl - jne $Loop */ - - LoopEntry = RSPRecompPos; - CPU_Message(" Loop:"); - RSPMoveX86RegToX86Reg(x86_EBX, x86_EAX); - RSPXorConstToX86Reg(x86_EAX, 3); - RSPMoveN64MemToX86regByte(x86_EDX, x86_EAX); - RSPMoveX86regByteToX86regPointer(x86_EDX, x86_EDI); - RSPIncX86reg(x86_EBX); /* address constant */ - RSPDecX86reg(x86_RDI); /* vector pointer */ - RSPDecX86reg(x86_ECX); /* counter */ - RSPJneLabel8( 0); - RSPx86_SetBranch8b(RSPRecompPos - 1, LoopEntry); - - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - RSPMoveN64MemToX86reg(x86_EAX, x86_EBX); - RSPMoveN64MemDispToX86reg(x86_ECX, x86_EBX, 4); - - /* Because of byte swapping this swizzle works nicely */ - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4]); - - RSPMoveX86regToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 8]); - - CPU_Message(" Done:"); - RSPx86_SetBranch32b(Jump[1], RSPRecompPos); -} - -void RSPCompile_Opcode_LQV ( void ) { - - int32_t offset = (RSPOpC.voffset << 4); - uint8_t * Jump[2], * Jump3; - - #ifndef RSPCompileLqv - RSPCheat_r4300iOpcode(RSP_Opcode_LQV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.del != 0) { - rsp_UnknownOpcode(); - return; - } - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if (Addr & 15) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LQV); - return; - } - - /* - * Aligned store - */ - - if (IsSseEnabled == 0) { - - RSPMoveVariableToX86reg(DMEM + Addr + 0, x86_EAX); - - RSPMoveVariableToX86reg(DMEM + Addr + 4, x86_EBX); - - RSPMoveVariableToX86reg(DMEM + Addr + 8, x86_ECX); - - RSPMoveVariableToX86reg(DMEM + Addr + 12, x86_EDX); - - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[12]); - - RSPMoveX86regToVariable(x86_EBX, &RSP_Vect[RSPOpC.rt].B[8]); - - RSPMoveX86regToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[4]); - - RSPMoveX86regToVariable(x86_EDX, &RSP_Vect[RSPOpC.rt].B[0]); - } else { - - RSPSseMoveUnalignedVariableToReg(DMEM + Addr, x86_XMM0); - RSPSseShuffleReg(x86_XMM0, x86_MM0, 0x1b); - - RSPSseMoveAlignedRegToVariable(x86_XMM0, &RSP_Vect[RSPOpC.rt].B[0]); - } - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) { - RSPAddConstToX86Reg(x86_EBX, offset); - } -/* - //RSPBreakPoint(); - RSPTestConstToX86Reg(15, x86_EBX); - RSPJeLabel32( 0); - Jump3 = RSPRecompPos - 4; - - RSPBreakPoint(); - RSPx86_SetBranch32b((uint32_t*)Jump3, (uint32_t*)RSPRecompPos); - - RSPTestConstToX86Reg(15, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; -*/ - -#define RSetJump32(Loc,JumpLoc) *(uint32_t *)(Loc)= (uint32_t)(((uint64_t)(JumpLoc)) - (((uint64_t)(Loc)) + 4)); - - RSPTestConstToX86Reg(15, x86_EBX); - RSPJeLabel32( 0); - Jump3 = RSPRecompPos - 4; -// RSPBreakPoint(); - //Int3(); - RSPJmpLabel32( 0); - Jump[0] = RSPRecompPos - 4; - RSPx86_SetBranch32b((uint32_t*)Jump3, (uint32_t*)RSPRecompPos); - - // 000000440000150E E9 15 EE FF FF jmp 0000004400000328 - CompilerToggleBuffer(); - CPU_Message(" Unaligned:"); - //if(RSPRecompPos == 0x0000004400000328) - //Int3(); -// RSPx86_SetBranch32b(Jump[0], RSPRecompPos); -//void RSPx86_SetBranch32b(void * JumpByte, void * Destination) { -// *(uint32_t*)(JumpByte) = (uint32_t)((uint8_t*)Destination - (uint8_t*)((uint32_t*)JumpByte + 1)); -//} - //*(uint32_t*)(Jump[0]) = (uint32_t)((uint8_t*)RSPRecompPos - (uint8_t*)((Jump[0]) + 1)); - RSetJump32(Jump[0], RSPRecompPos); - - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LQV); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - if (IsSseEnabled == 0) { - RSPMoveN64MemDispToX86reg(x86_EAX, x86_EBX, 0); - RSPMoveN64MemDispToX86reg(x86_ECX, x86_EBX, 4); - RSPMoveN64MemDispToX86reg(x86_EDX, x86_EBX, 8); - RSPMoveN64MemDispToX86reg(x86_EDI, x86_EBX, 12); - - - RSPMoveX86regToVariable(x86_EAX, &RSP_Vect[RSPOpC.rt].B[12]); - - RSPMoveX86regToVariable(x86_ECX, &RSP_Vect[RSPOpC.rt].B[8]); - - RSPMoveX86regToVariable(x86_EDX, &RSP_Vect[RSPOpC.rt].B[4]); - - RSPMoveX86regToVariable(x86_EDI, &RSP_Vect[RSPOpC.rt].B[0]); - } else { - RSPSseMoveUnalignedN64MemToReg(x86_XMM0, x86_EBX); - RSPSseShuffleReg(x86_XMM0, x86_MM0, 0x1b); - - RSPSseMoveAlignedRegToVariable(x86_XMM0, &RSP_Vect[RSPOpC.rt].B[0]); - } - CPU_Message(" Done:"); - RSPx86_SetBranch32b((uint32_t*)Jump[1], (uint32_t*)RSPRecompPos); -} - -void RSPCompile_Opcode_LRV ( void ) { - int32_t offset = (RSPOpC.voffset << 4); - uint8_t * Loop, * Jump[2]; - - #ifndef RSPCompileLrv - RSPCheat_r4300iOpcode(RSP_Opcode_LRV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.del != 0) { - rsp_UnknownOpcode(); - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) RSPAddConstToX86Reg(x86_EBX, offset); - - if (Compiler.bAlignVector == 0) { - RSPTestConstToX86Reg(1, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - /* Unaligned */ - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b(Jump[0], RSPRecompPos); - - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_LRV); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - } - -// RSPBreakPoint(); - - /* Aligned */ - RSPMoveX86RegToX86Reg(x86_EBX, x86_EAX); - RSPAndConstToX86Reg(x86_EAX, 0x0F); - RSPAndConstToX86Reg(x86_EBX, 0x0ff0); - - RSPMoveX86RegToX86Reg(x86_EAX, x86_ECX); - RSPShiftRightUnsignImmed(x86_ECX, 1); - - RSPJeLabel8( 0); - Jump[0] = RSPRecompPos - 1; -/* - RSPDecX86reg(x86_EAX); - RSPLeaSourceAndOffset(x86_EAX, x86_EAX, (uint32_t) &RSP_Vect[RSPOpC.rt].B[0]); - RSPDecX86reg(x86_EAX); -*/ - -// RSPBreakPoint(); -//Int3(); - RSPAddQwordToX86Reg(x86_RAX, ((uintptr_t)&RSP_Vect[RSPOpC.rt].UB[0]) - 2); - - CPU_Message(" Loop:"); - Loop = RSPRecompPos; - - RSPMoveX86RegToX86Reg(x86_EBX, x86_ESI); - RSPXorConstToX86Reg(x86_ESI, 2); - RSPMoveN64MemToX86regHalf(x86_EDX, x86_ESI); - RSPMoveX86regHalfToX86regPointer(x86_EDX, x86_RAX); - - RSPAddConstToX86Reg(x86_EBX, 2); /* Dmem pointer */ - RSPSubConstFromX86Reg(x86_RAX, 2); /* Vector pointer */ - RSPDecX86reg(x86_ECX); /* Loop counter */ - RSPJneLabel8( 0); - RSPx86_SetBranch8b(RSPRecompPos - 1, Loop); - - if (Compiler.bAlignVector == 0) { - CPU_Message(" Done:"); - RSPx86_SetBranch32b((uint32_t*)Jump[1], (uint32_t*)RSPRecompPos); - } - - RSPx86_SetBranch8b(Jump[0], RSPRecompPos); -} - -void RSPCompile_Opcode_LPV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LPV); -} - -void RSPCompile_Opcode_LUV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LUV); -} - - -void RSPCompile_Opcode_LHV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LHV); -} - - -void RSPCompile_Opcode_LFV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LFV); -} - -void RSPCompile_Opcode_LTV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_LTV); -} - -/************************** sc2 functions **************************/ - -void RSPCompile_Opcode_SBV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SBV); -} - -void RSPCompile_Opcode_SSV ( void ) { - - int32_t offset = (RSPOpC.voffset << 1); - - if (RSPOpC.del > 14) { - rsp_UnknownOpcode(); - return; - } - - #ifndef RSPCompileSsv - RSPCheat_r4300iOpcode(RSP_Opcode_SSV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 1) != 0) { - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 0)], x86_ECX); - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)], x86_EDX); - - - RSPMoveX86regByteToVariable(x86_ECX, DMEM + ((Addr + 0) ^ 3)); - - RSPMoveX86regByteToVariable(x86_EDX, DMEM + ((Addr + 1) ^ 3)); - } else { - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)], x86_ECX); - - RSPMoveX86regHalfToVariable(x86_ECX, DMEM + (Addr ^ 2)); - } - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) RSPAddConstToX86Reg(x86_EBX, offset); - RSPAndConstToX86Reg(x86_EBX, 0x0FFF); - - if (Compiler.bAlignVector == 1) { - - RSPMoveVariableToX86regHalf(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)], x86_ECX); - RSPXorConstToX86Reg(x86_EBX, 2); - RSPMoveX86regHalfToN64Mem(x86_ECX, x86_EBX); - } else { - RSPLeaSourceAndOffset(x86_EAX, x86_EBX, 1); - RSPXorConstToX86Reg(x86_EBX, 3); - RSPXorConstToX86Reg(x86_EAX, 3); - - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 0)], x86_ECX); - - RSPMoveVariableToX86regByte(&RSP_Vect[RSPOpC.rt].B[15 - (RSPOpC.del + 1)], x86_EDX); - - RSPMoveX86regByteToN64Mem(x86_ECX, x86_EBX); - RSPMoveX86regByteToN64Mem(x86_EDX, x86_EAX); - } -} - -void RSPCompile_Opcode_SLV ( void ) { - - int32_t offset = (RSPOpC.voffset << 2); - uint8_t * Jump[2]; - - #ifndef RSPCompileSlv - RSPCheat_r4300iOpcode(RSP_Opcode_SLV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - -// if ((RSPOpC.del & 0x3) != 0) { -// rsp_UnknownOpcode(); -// return; -// } - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 3) != 0) { - //CompilerWarning("Unaligned SLV at constant address"); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SLV); - return; - } - - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4], x86_EAX); - - RSPMoveX86regToVariable(x86_EAX, DMEM + Addr); - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) RSPAddConstToX86Reg(x86_EBX, offset); - - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - /* - * Unaligned - */ - CompilerToggleBuffer(); - - CPU_Message(" Unaligned:"); - *((uint32_t *)(Jump[0]))=(uint32_t)(RSPRecompPos - Jump[0] - 4); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SLV); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - - /* - * Aligned - */ - - /* Because of byte swapping this swizzle works nicely */ - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4], x86_EAX); - - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPMoveX86regToN64Mem(x86_EAX, x86_EBX); - - CPU_Message(" Done:"); - *((uint32_t *)(Jump[1]))=(uint32_t)(RSPRecompPos - Jump[1] - 4); -} - -void RSPCompile_Opcode_SDV ( void ) { - - int32_t offset = (RSPOpC.voffset << 3); - uint8_t * Jump[2], * LoopEntry; - - //if ((RSPOpC.del & 0x7) != 0) { - // rsp_UnknownOpcode(); - // return; - //} - - #ifndef RSPCompileSdv - RSPCheat_r4300iOpcode(RSP_Opcode_SDV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if ((Addr & 3) != 0) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SDV); - return; - } - - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4], x86_EAX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 8], x86_EBX); - - - RSPMoveX86regToVariable(x86_EAX, DMEM + Addr); - - RSPMoveX86regToVariable(x86_EBX, DMEM + Addr + 4); - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) { - RSPAddConstToX86Reg(x86_EBX, offset); - } - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - RSPTestConstToX86Reg(3, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b((uint32_t*)Jump[0], (uint32_t*)RSPRecompPos); - - - RSPMoveConstQwordToX86reg((uintptr_t)&RSP_Vect[RSPOpC.rt].UB[15 - RSPOpC.del], x86_RDI); - RSPMoveConstToX86reg(8, x86_ECX); - - CPU_Message(" Loop:"); - LoopEntry = RSPRecompPos; - RSPMoveX86RegToX86Reg(x86_EBX, x86_EAX); - RSPXorConstToX86Reg(x86_EAX, 3); - RSPMoveX86regPointerToX86regByte(x86_EDX, x86_EDI); - RSPMoveX86regByteToN64Mem(x86_EDX, x86_EAX); - RSPIncX86reg(x86_EBX); /* address constant */ - RSPDecX86reg(x86_RDI); /* vector pointer */ - RSPDecX86reg(x86_ECX); /* counter */ - RSPJneLabel8( 0); - RSPx86_SetBranch8b(RSPRecompPos - 1, LoopEntry); - - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 4], x86_EAX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[16 - RSPOpC.del - 8], x86_ECX); - RSPMoveX86regToN64Mem(x86_EAX, x86_EBX); - RSPMoveX86regToN64MemDisp(x86_ECX, x86_EBX, 4); - - CPU_Message(" Done:"); - RSPx86_SetBranch32b((uint32_t*)Jump[1], (uint32_t*)RSPRecompPos); -} - -void RSPCompile_Opcode_SQV ( void ) { - - int32_t offset = (RSPOpC.voffset << 4); - uint8_t * Jump[2]; - - #ifndef RSPCompileSqv - RSPCheat_r4300iOpcode(RSP_Opcode_SQV); return; - #endif - - CPU_Message(RSPCompilePC,RSPOpcodeName(RSPOpC.Hex,RSPCompilePC)); - - if (RSPOpC.del != 0) { - rsp_UnknownOpcode(); - return; - } - - if (IsRegConst(RSPOpC.base) == 1) { - uint32_t Addr = (MipsRegConst(RSPOpC.base) + offset) & 0xfff; - - if (Addr & 15) { - CompilerWarning( RSPCompilePC); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SQV); - return; - } - - /* - * Aligned store - */ - - if (IsSseEnabled == 0) { - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[12], x86_EAX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[8], x86_EBX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[4], x86_ECX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[0], x86_EDX); - - - RSPMoveX86regToVariable(x86_EAX, DMEM + Addr + 0); - - RSPMoveX86regToVariable(x86_EBX, DMEM + Addr + 4); - - RSPMoveX86regToVariable(x86_ECX, DMEM + Addr + 8); - - RSPMoveX86regToVariable(x86_EDX, DMEM + Addr + 12); - } else { - - RSPSseMoveAlignedVariableToReg(&RSP_Vect[RSPOpC.rt].B[0], x86_XMM0); - RSPSseShuffleReg(x86_XMM0, x86_MM0, 0x1b); - - RSPSseMoveUnalignedRegToVariable(x86_XMM0, DMEM + Addr); - } - return; - } - - RSPMoveVariableToX86reg(&RSP_GPR[RSPOpC.base].UW, x86_EBX); - if (offset != 0) { - RSPAddConstToX86Reg(x86_EBX, offset); - } - RSPTestConstToX86Reg(15, x86_EBX); - RSPJneLabel32( 0); - Jump[0] = RSPRecompPos - 4; - - CompilerToggleBuffer(); - CPU_Message(" Unaligned:"); - RSPx86_SetBranch32b((uint32_t*)Jump[0], (uint32_t*)RSPRecompPos); - RSPCheat_r4300iOpcodeNoMessage(RSP_Opcode_SQV); - RSPJmpLabel32( 0); - Jump[1] = RSPRecompPos - 4; - CompilerToggleBuffer(); - - RSPAndConstToX86Reg(x86_EBX, 0x0fff); - if (IsSseEnabled == 0) { - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[12], x86_EAX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[8], x86_ECX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[4], x86_EDX); - - RSPMoveVariableToX86reg(&RSP_Vect[RSPOpC.rt].B[0], x86_EDI); - - RSPMoveX86regToN64MemDisp(x86_EAX, x86_EBX, 0); - RSPMoveX86regToN64MemDisp(x86_ECX, x86_EBX, 4); - RSPMoveX86regToN64MemDisp(x86_EDX, x86_EBX, 8); - RSPMoveX86regToN64MemDisp(x86_EDI, x86_EBX, 12); - } else { - - RSPSseMoveAlignedVariableToReg(&RSP_Vect[RSPOpC.rt].B[0], x86_XMM0); - RSPSseShuffleReg(x86_XMM0, x86_MM0, 0x1b); - RSPSseMoveUnalignedRegToN64Mem(x86_XMM0, x86_EBX); - } - CPU_Message(" Done:"); - RSPx86_SetBranch32b((uint32_t*)Jump[1], (uint32_t*)RSPRecompPos); -} - -void RSPCompile_Opcode_SRV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SRV); -} - -void RSPCompile_Opcode_SPV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SPV); -} - -void RSPCompile_Opcode_SUV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SUV); -} - -void RSPCompile_Opcode_SHV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SHV); -} - -void RSPCompile_Opcode_SFV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SFV); -} - -void RSPCompile_Opcode_STV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_STV); -} - -void RSPCompile_Opcode_SWV ( void ) { - RSPCheat_r4300iOpcode(RSP_Opcode_SWV); -} - -/************************** Other functions **************************/ - -void RSPCompile_UnknownOpcode (void) { - CPU_Message(RSPCompilePC, RSPOpcodeName(RSPOpC.Hex,RSPCompilePC) ); - RSPNextInstruction = FINISH_BLOCK; - RSPMoveConstToVariable(RSPCompilePC,PrgCount); - RSPMoveConstToVariable(RSPOpC.Hex,&RSPOpC.Hex); - RSPCall_Direct(rsp_UnknownOpcode ); - RSPRet(); -} diff --git a/src/usf/rsp_recompiler_ops.h b/src/usf/rsp_recompiler_ops.h deleted file mode 100644 index c13311a..0000000 --- a/src/usf/rsp_recompiler_ops.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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. - * - */ - -/************************* OpCode functions *************************/ -void RSPCompile_SPECIAL ( void ); -void RSPCompile_REGIMM ( void ); -void RSPCompile_J ( void ); -void RSPCompile_JAL ( void ); -void RSPCompile_BEQ ( void ); -void RSPCompile_BNE ( void ); -void RSPCompile_BLEZ ( void ); -void RSPCompile_BGTZ ( void ); -void RSPCompile_ADDI ( void ); -void RSPCompile_ADDIU ( void ); -void RSPCompile_SLTI ( void ); -void RSPCompile_SLTIU ( void ); -void RSPCompile_ANDI ( void ); -void RSPCompile_ORI ( void ); -void RSPCompile_XORI ( void ); -void RSPCompile_LUI ( void ); -void RSPCompile_COP0 ( void ); -void RSPCompile_COP2 ( void ); -void RSPCompile_LB ( void ); -void RSPCompile_LH ( void ); -void RSPCompile_LW ( void ); -void RSPCompile_LBU ( void ); -void RSPCompile_LHU ( void ); -void RSPCompile_SB ( void ); -void RSPCompile_SH ( void ); -void RSPCompile_SW ( void ); -void RSPCompile_LC2 ( void ); -void RSPCompile_SC2 ( void ); -/********************** R4300i OpCodes: Special **********************/ -void RSPCompile_Special_SLL ( void ); -void RSPCompile_Special_SRL ( void ); -void RSPCompile_Special_SRA ( void ); -void RSPCompile_Special_SLLV ( void ); -void RSPCompile_Special_SRLV ( void ); -void RSPCompile_Special_SRAV ( void ); -void RSPCompile_Special_JR ( void ); -void RSPCompile_Special_JALR ( void ); -void RSPCompile_Special_BREAK ( void ); -void RSPCompile_Special_ADD ( void ); -void RSPCompile_Special_ADDU ( void ); -void RSPCompile_Special_SUB ( void ); -void RSPCompile_Special_SUBU ( void ); -void RSPCompile_Special_AND ( void ); -void RSPCompile_Special_OR ( void ); -void RSPCompile_Special_XOR ( void ); -void RSPCompile_Special_NOR ( void ); -void RSPCompile_Special_SLT ( void ); -void RSPCompile_Special_SLTU ( void ); -/********************** R4300i OpCodes: RegImm **********************/ -void RSPCompile_RegImm_BLTZ ( void ); -void RSPCompile_RegImm_BGEZ ( void ); -void RSPCompile_RegImm_BLTZAL ( void ); -void RSPCompile_RegImm_BGEZAL ( void ); -/************************** Cop0 functions *************************/ -void RSPCompile_Cop0_MF ( void ); -void RSPCompile_Cop0_MT ( void ); -/************************** Cop2 functions *************************/ -void RSPCompile_Cop2_MF ( void ); -void RSPCompile_Cop2_CF ( void ); -void RSPCompile_Cop2_MT ( void ); -void RSPCompile_Cop2_CT ( void ); -void RSPCompile_COP2_VECTOR ( void ); -/************************** Vect functions **************************/ -void RSPCompile_Vector_VMULF ( void ); -void RSPCompile_Vector_VMULU ( void ); -void RSPCompile_Vector_VMUDL ( void ); -void RSPCompile_Vector_VMUDM ( void ); -void RSPCompile_Vector_VMUDN ( void ); -void RSPCompile_Vector_VMUDH ( void ); -void RSPCompile_Vector_VMACF ( void ); -void RSPCompile_Vector_VMACU ( void ); -void RSPCompile_Vector_VMACQ ( void ); -void RSPCompile_Vector_VMADL ( void ); -void RSPCompile_Vector_VMADM ( void ); -void RSPCompile_Vector_VMADN ( void ); -void RSPCompile_Vector_VMADH ( void ); -void RSPCompile_Vector_VADD ( void ); -void RSPCompile_Vector_VSUB ( void ); -void RSPCompile_Vector_VABS ( void ); -void RSPCompile_Vector_VADDC ( void ); -void RSPCompile_Vector_VSUBC ( void ); -void RSPCompile_Vector_VSAW ( void ); -void RSPCompile_Vector_VLT ( void ); -void RSPCompile_Vector_VEQ ( void ); -void RSPCompile_Vector_VNE ( void ); -void RSPCompile_Vector_VGE ( void ); -void RSPCompile_Vector_VCL ( void ); -void RSPCompile_Vector_VCH ( void ); -void RSPCompile_Vector_VCR ( void ); -void RSPCompile_Vector_VMRG ( void ); -void RSPCompile_Vector_VAND ( void ); -void RSPCompile_Vector_VNAND ( void ); -void RSPCompile_Vector_VOR ( void ); -void RSPCompile_Vector_VNOR ( void ); -void RSPCompile_Vector_VXOR ( void ); -void RSPCompile_Vector_VNXOR ( void ); -void RSPCompile_Vector_VRCP ( void ); -void RSPCompile_Vector_VRCPL ( void ); -void RSPCompile_Vector_VRCPH ( void ); -void RSPCompile_Vector_VMOV ( void ); -void RSPCompile_Vector_VRSQ ( void ); -void RSPCompile_Vector_VRSQL ( void ); -void RSPCompile_Vector_VRSQH ( void ); -void RSPCompile_Vector_VNOOP ( void ); -/************************** lc2 functions **************************/ -void RSPCompile_Opcode_LBV ( void ); -void RSPCompile_Opcode_LSV ( void ); -void RSPCompile_Opcode_LLV ( void ); -void RSPCompile_Opcode_LDV ( void ); -void RSPCompile_Opcode_LQV ( void ); -void RSPCompile_Opcode_LRV ( void ); -void RSPCompile_Opcode_LPV ( void ); -void RSPCompile_Opcode_LUV ( void ); -void RSPCompile_Opcode_LHV ( void ); -void RSPCompile_Opcode_LFV ( void ); -void RSPCompile_Opcode_LTV ( void ); -/************************** sc2 functions **************************/ -void RSPCompile_Opcode_SBV ( void ); -void RSPCompile_Opcode_SSV ( void ); -void RSPCompile_Opcode_SLV ( void ); -void RSPCompile_Opcode_SDV ( void ); -void RSPCompile_Opcode_SQV ( void ); -void RSPCompile_Opcode_SRV ( void ); -void RSPCompile_Opcode_SPV ( void ); -void RSPCompile_Opcode_SUV ( void ); -void RSPCompile_Opcode_SHV ( void ); -void RSPCompile_Opcode_SFV ( void ); -void RSPCompile_Opcode_SWV ( void ); -void RSPCompile_Opcode_STV ( void ); -/************************** Other functions **************************/ -void RSPCompile_UnknownOpcode (void); diff --git a/src/usf/rsp_registers.h b/src/usf/rsp_registers.h deleted file mode 100644 index 22fb196..0000000 --- a/src/usf/rsp_registers.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 "types.h" - -#define SP_STATUS_HALT 0x001 /* Bit 0: halt */ -#define SP_STATUS_BROKE 0x002 /* Bit 1: broke */ -#define SP_STATUS_DMA_BUSY 0x004 /* Bit 2: dma busy */ -#define SP_STATUS_DMA_FULL 0x008 /* Bit 3: dma full */ -#define SP_STATUS_IO_FULL 0x010 /* Bit 4: io full */ -#define SP_STATUS_SSTEP 0x020 /* Bit 5: single step */ -#define SP_STATUS_INTR_BREAK 0x040 /* Bit 6: interrupt on break */ -#define SP_STATUS_SIG0 0x080 /* Bit 7: signal 0 set */ -#define SP_STATUS_SIG1 0x100 /* Bit 8: signal 1 set */ -#define SP_STATUS_SIG2 0x200 /* Bit 9: signal 2 set */ -#define SP_STATUS_SIG3 0x400 /* Bit 10: signal 3 set */ -#define SP_STATUS_SIG4 0x800 /* Bit 11: signal 4 set */ -#define SP_STATUS_SIG5 0x1000 /* Bit 12: signal 5 set */ -#define SP_STATUS_SIG6 0x2000 /* Bit 13: signal 6 set */ -#define SP_STATUS_SIG7 0x4000 /* Bit 14: signal 7 set */ - -#define SP_CLR_HALT 0x00001 /* Bit 0: clear halt */ -#define SP_SET_HALT 0x00002 /* Bit 1: set halt */ -#define SP_CLR_BROKE 0x00004 /* Bit 2: clear broke */ -#define SP_CLR_INTR 0x00008 /* Bit 3: clear intr */ -#define SP_SET_INTR 0x00010 /* Bit 4: set intr */ -#define SP_CLR_SSTEP 0x00020 /* Bit 5: clear sstep */ -#define SP_SET_SSTEP 0x00040 /* Bit 6: set sstep */ -#define SP_CLR_INTR_BREAK 0x00080 /* Bit 7: clear intr on break */ -#define SP_SET_INTR_BREAK 0x00100 /* Bit 8: set intr on break */ -#define SP_CLR_SIG0 0x00200 /* Bit 9: clear signal 0 */ -#define SP_SET_SIG0 0x00400 /* Bit 10: set signal 0 */ -#define SP_CLR_SIG1 0x00800 /* Bit 11: clear signal 1 */ -#define SP_SET_SIG1 0x01000 /* Bit 12: set signal 1 */ -#define SP_CLR_SIG2 0x02000 /* Bit 13: clear signal 2 */ -#define SP_SET_SIG2 0x04000 /* Bit 14: set signal 2 */ -#define SP_CLR_SIG3 0x08000 /* Bit 15: clear signal 3 */ -#define SP_SET_SIG3 0x10000 /* Bit 16: set signal 3 */ -#define SP_CLR_SIG4 0x20000 /* Bit 17: clear signal 4 */ -#define SP_SET_SIG4 0x40000 /* Bit 18: set signal 4 */ -#define SP_CLR_SIG5 0x80000 /* Bit 19: clear signal 5 */ -#define SP_SET_SIG5 0x100000 /* Bit 20: set signal 5 */ -#define SP_CLR_SIG6 0x200000 /* Bit 21: clear signal 6 */ -#define SP_SET_SIG6 0x400000 /* Bit 22: set signal 6 */ -#define SP_CLR_SIG7 0x800000 /* Bit 23: clear signal 7 */ -#define SP_SET_SIG7 0x1000000 /* Bit 24: set signal 7 */ - -#define DPC_CLR_XBUS_DMEM_DMA 0x0001 /* Bit 0: clear xbus_dmem_dma */ -#define DPC_SET_XBUS_DMEM_DMA 0x0002 /* Bit 1: set xbus_dmem_dma */ -#define DPC_CLR_FREEZE 0x0004 /* Bit 2: clear freeze */ -#define DPC_SET_FREEZE 0x0008 /* Bit 3: set freeze */ -#define DPC_CLR_FLUSH 0x0010 /* Bit 4: clear flush */ -#define DPC_SET_FLUSH 0x0020 /* Bit 5: set flush */ -#define DPC_CLR_TMEM_CTR 0x0040 /* Bit 6: clear tmem ctr */ -#define DPC_CLR_PIPE_CTR 0x0080 /* Bit 7: clear pipe ctr */ -#define DPC_CLR_CMD_CTR 0x0100 /* Bit 8: clear cmd ctr */ -#define DPC_CLR_CLOCK_CTR 0x0200 /* Bit 9: clear clock ctr */ - -#define DPC_STATUS_XBUS_DMEM_DMA 0x001 /* Bit 0: xbus_dmem_dma */ -#define DPC_STATUS_FREEZE 0x002 /* Bit 1: freeze */ -#define DPC_STATUS_FLUSH 0x004 /* Bit 2: flush */ -#define DPC_STATUS_START_GCLK 0x008 /* Bit 3: start gclk */ -#define DPC_STATUS_TMEM_BUSY 0x010 /* Bit 4: tmem busy */ -#define DPC_STATUS_PIPE_BUSY 0x020 /* Bit 5: pipe busy */ -#define DPC_STATUS_CMD_BUSY 0x040 /* Bit 6: cmd busy */ -#define DPC_STATUS_CBUF_READY 0x080 /* Bit 7: cbuf ready */ -#define DPC_STATUS_DMA_BUSY 0x100 /* Bit 8: dma busy */ -#define DPC_STATUS_END_VALID 0x200 /* Bit 9: end valid */ -#define DPC_STATUS_START_VALID 0x400 /* Bit 10: start valid */ - -#define R4300i_SP_Intr 0x1 - -extern char * x86_Strings[8]; -extern char * GPR_Strings[32]; - -#define x86_Name(Reg) (x86_Strings[(Reg)]) -#define GPR_Name(Reg) (GPR_Strings[(Reg)]) - -/* -#define GPR_Name(Reg)\ - (Reg) == 0 ? "R0" : (Reg) == 1 ? "AT" : (Reg) == 2 ? "V0" : (Reg) == 3 ? "V1" :\ - (Reg) == 4 ? "A0" : (Reg) == 5 ? "A1" : (Reg) == 6 ? "A2" : (Reg) == 7 ? "A3" :\ - (Reg) == 8 ? "T0" : (Reg) == 9 ? "T1" : (Reg) == 10 ? "T2" : (Reg) == 11 ? "T3" :\ - (Reg) == 12 ? "T4" : (Reg) == 13 ? "T5" : (Reg) == 14 ? "T6" : (Reg) == 15 ? "T7" :\ - (Reg) == 16 ? "S0" : (Reg) == 17 ? "S1" : (Reg) == 18 ? "S2" : (Reg) == 19 ? "S3" :\ - (Reg) == 20 ? "S4" : (Reg) == 21 ? "S5" : (Reg) == 22 ? "S6" : (Reg) == 23 ? "S7" :\ - (Reg) == 24 ? "T8" : (Reg) == 25 ? "T9" : (Reg) == 26 ? "K0" : (Reg) == 27 ? "K1" :\ - (Reg) == 28 ? "GP" : (Reg) == 29 ? "SP" : (Reg) == 30 ? "S8" :\ - (Reg) == 31 ? "RA" : "Unknown Register" -*/ - -#define COP0_Name(Reg)\ - (Reg) == 0 ? "SP memory address" :\ - (Reg) == 1 ? "SP DRAM DMA address" :\ - (Reg) == 2 ? "SP read DMA length" :\ - (Reg) == 3 ? "SP write DMA length" :\ - (Reg) == 4 ? "SP status" :\ - (Reg) == 5 ? "SP DMA full" :\ - (Reg) == 6 ? "SP DMA busy" :\ - (Reg) == 7 ? "SP semaphore" :\ - (Reg) == 8 ? "DP CMD DMA start" :\ - (Reg) == 9 ? "DP CMD DMA end" :\ - (Reg) == 10 ? "DP CMD DMA current" :\ - (Reg) == 11 ? "DP CMD status" :\ - (Reg) == 12 ? "DP clock counter" :\ - (Reg) == 13 ? "DP buffer busy counter" :\ - (Reg) == 14 ? "DP pipe busy counter" :\ - (Reg) == 15 ? "DP TMEM load counter" :\ - "Unknown Register" - -#define ElementSpecifier(Elem)\ - (Elem) == 0 ? "" : (Elem) == 1 ? "" : (Elem) == 2 ? " [0q]" :\ - (Elem) == 3 ? " [1q]" : (Elem) == 4 ? " [0h]" : (Elem) == 5 ? " [1h]" :\ - (Elem) == 6 ? " [2h]" : (Elem) == 7 ? " [3h]" : (Elem) == 8 ? " [0]" :\ - (Elem) == 9 ? " [1]" : (Elem) == 10 ? " [2]" : (Elem) == 11 ? " [3]" :\ - (Elem) == 12 ? " [4]" : (Elem) == 13 ? " [5]" : (Elem) == 14 ? " [6]" :\ - (Elem) == 15 ? " [7]" : "Unknown Element" - -void InitilizeRSPRegisters (void); - -/*** RSP Registers ***/ -extern MIPSUWORD RSP_GPR[32], RSP_Flags[4]; -extern MIPSUDWORD RSP_ACCUM[8]; -extern VECTOR RSP_Vect[32]; - - diff --git a/src/usf/rsp_sse.c b/src/usf/rsp_sse.c deleted file mode 100644 index 2dc7d1c..0000000 --- a/src/usf/rsp_sse.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 "types.h" -#include "rsp.h" -#include "rsp_x86.h" -#include "recompiler_cpu.h" -#include "memory.h" -#include "types.h" - -extern uint8_t * DMEM; - -#define PUTDST8(dest,value) (*((uint8_t *)(dest))=(uint8_t)(value)); dest += 1; -#define PUTDST16(dest,value) (*((uint16_t *)(dest))=(uint16_t)(value)); dest += 2; -#define PUTDST32(dest,value) (*((uint32_t *)(dest))=(uint32_t)(value)); dest += 4; -#define PUTDST64(dest,value) {(*((uint64_t *)(dest))=(uint64_t)(value)); dest += 8;} - -void RSPSseMoveAlignedVariableToReg(void * Variable, int32_t sseReg) { - OPCODE_REG_VARIABLE(,16,0x100F,sseReg,Variable); -} - -void RSPSseMoveAlignedN64MemToReg(int32_t sseReg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0x100F,sseReg,AddrReg); -} - -void RSPSseMoveAlignedRegToVariable(int32_t sseReg, void *Variable) { - OPCODE_REG_VARIABLE(,16,0x110f,sseReg,Variable); //290F -} - -void RSPSseMoveAlignedRegToN64Mem(int32_t sseReg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0x110f,sseReg,AddrReg); //290F -} - -void RSPSseMoveUnalignedVariableToReg(void *Variable, int32_t sseReg) { - OPCODE_REG_VARIABLE(,16,0x100F,sseReg,Variable); -} - -void RSPSseMoveUnalignedN64MemToReg(int32_t sseReg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0x100f,sseReg,AddrReg); -} - -void RSPSseMoveUnalignedRegToVariable(int32_t sseReg, void *Variable) { - OPCODE_REG_VARIABLE(,16,0x110F,sseReg,Variable); -} - -void RSPSseMoveUnalignedRegToN64Mem(int32_t sseReg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0x110f,sseReg,AddrReg); -} - -void RSPSseMoveRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x280F,Dest,Source) -} - -void RSPSseXorRegToReg(int32_t Dest, int32_t Source) { - OPCODE_REG_REG(16,0x570F,Dest,Source) -} - -void RSPSseShuffleReg(int32_t Dest, int32_t Source, uint8_t Immed) { - OPCODE_REG_REG(16,0xC60F,Dest,Source) - PUTDST8(RSPRecompPos, Immed); -} diff --git a/src/usf/rsp_x86.c b/src/usf/rsp_x86.c deleted file mode 100644 index a7052b2..0000000 --- a/src/usf/rsp_x86.c +++ /dev/null @@ -1,1366 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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 -#include -#include "rsp.h" -#include "rsp_x86.h" -#include "recompiler_cpu.h" -#include "memory.h" -#include "types.h" -#include "main.h" - -#define PUTDST8(dest,value) {(*((uint8_t *)(dest))=(uint8_t)(value)); dest += 1;} -#define PUTDST16(dest,value) {(*((uint16_t *)(dest))=(uint16_t)(value)); dest += 2;} -#define PUTDST32(dest,value) {(*((uint32_t *)(dest))=(uint32_t)(value)); dest += 4;} -#define PUTDST64(dest,value) {(*((uint64_t *)(dest))=(uint64_t)(value)); dest += 8;} - - -#define x64_Reg 0x10 -#define X64_Reg 0x10 -#define X64_Ext 0x20 - -extern uint8_t Index[9]; - - -char * x86_Strings[8] = { - "eax", "ebx", "ecx", "edx", - "esi", "edi", "ebp", "esp" -}; - -char * x86_ByteStrings[8] = { - "al", "bl", "cl", "dl", - "?4", "?5", "?6", "?7" -}; - -char * x86_HalfStrings[8] = { - "ax", "bx", "cx", "dx", - "si", "di", "bp", "sp" -}; - -extern uint32_t ConditionalMove; - -#define x86Byte_Name(Reg) (x86_ByteStrings[(Reg)]) -#define x86Half_Name(Reg) (x86_HalfStrings[(Reg)]) - - - -void RSPAdcX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x11,x86reg,Variable) -} - -void RSPAdcConstToVariable(void *Variable, uint8_t Constant) { - RSPBreakPoint(); - - /*if(((uintptr_t)Variable - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - RSPBreakPoint(); - OPCODE_REG_MREG_IMM32(8,0x81,OP_D2,x86_R15,(uintptr_t)Variable - (uintptr_t)TLB_Map); - } else { - LOAD_VARIABLE(x86_TEMP, Variable); - OPCODE_REG_MREG(8,0x81,OP_D2,x86_TEMP); - } - - PUTDST8(RSPRecompPos,Constant); - */ -} - -void RSPAdcX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x13,Destination,Source); -} - -void RSPAddConstToVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D0,Variable) - PUTDST32(RSPRecompPos,Const); -} - -void RSPAddConstToX86Reg64 (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D0,x86reg | x64_Reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D0,x86reg | x64_Reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPAddConstToX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D0,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D0,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - - -void RSPAddQwordToX86Reg (int32_t x86reg, uint64_t Const) { -#ifdef USEX64 - LOAD_VARIABLE(x86_TEMP, Const); - OPCODE_REG_REG(8,0x1,x86_TEMP,x86reg); -#else - RSPAddConstToX86Reg(x86reg, Const); -#endif -} - - -void RSPAddVariableToX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x3,x86reg,Variable) -} - -void RSPAddX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x1,x86reg,Variable) -} - -void RSPAddX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x3,Destination,Source); -} - -void RSPAndConstToVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D4,Variable) - PUTDST32(RSPRecompPos,Const); -} - -void RSPAndConstToX86Reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D4,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D4,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPAndVariableDispToX86Reg(void *Variable, int32_t x86reg, int32_t AddrReg, int32_t Multiplier) { -#ifdef USEX64 - if(((uintptr_t)Variable - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_SCALE_IMM32(8,0x23,x86reg,x86_R15,AddrReg,Index[Multiplier], (uintptr_t)Variable - (uintptr_t)TLB_Map); - } else { - LOAD_VARIABLE(x86_TEMP, Variable); - OPCODE_REG_BASE_INDEX_SCALE(8,0x23,x86reg,x86_TEMP,AddrReg,Index[Multiplier]); - } -#else - OPCODE_REG_INDEX_SCALE_IMM32(8,0x23,x86reg,AddrReg,Index[Multiplier],Variable); -#endif -} - -void RSPAndVariableToX86Reg(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x23,x86reg,Variable) -} - -void RSPAndX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x21,Source,Destination); -} - -void RSPBreakPoint (void) { - PUTDST8(RSPRecompPos,0xCC); -} - -void RSPCall_Direct(void * FunctAddress) { - uintptr_t disp = 0; -#ifdef USEX64 - disp = (uintptr_t)FunctAddress-(uintptr_t)RSPRecompPos - 5; - RSPSubConstFromX86Reg(x86_RSP, 0x28); -// if(disp <= 0x7fffffff) { -// PUTDST8(RSPRecompPos,0xE8); -// PUTDST32(RSPRecompPos,disp); -// } else { - LOAD_VARIABLE(x86_TEMP, FunctAddress); - OPCODE_REG_REG(8,0xff,OP_D2,x86_TEMP); - -// } - RSPAddConstToX86Reg(x86_RSP, 0x28); -#else - disp = (uintptr_t)FunctAddress-(uintptr_t)RSPRecompPos - 5; - PUTDST8(RSPRecompPos,0xE8); - PUTDST32(RSPRecompPos,disp); -#endif -} - -void RSPCompConstToVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D7,Variable) - PUTDST32(RSPRecompPos,Const); -} - -void RSPCompConstToX86reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D7,x86reg); - PUTDST32(RSPRecompPos,Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D7,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPCompX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x3B,x86reg,Variable) -} - -void RSPCompX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x3B,Destination,Source); -} - -void RSPDecX86reg(x86reg) { - OPCODE_REG_REG(8,0xFF,OP_D1,x86reg); -} - -void RSPDivX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D6,x86reg); -} - -void RSPidivX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D7,x86reg); -} - -void RSPimulX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D5,x86reg); -} - -void RSPIncX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xFF,OP_D0,x86reg); -} - -void RSPJaeLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x73); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJaeLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x830F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJaLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x77); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJaLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x870F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJbLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x72); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJbLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x820F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJecxzLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0xE3); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJeLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x74); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJeLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x840F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJgeLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x8D0F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJgLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x7F); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJgLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x8F0F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJleLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x7E); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJleLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x8E0F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJlLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x7C); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJlLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x8C0F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJzLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x74); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJnzLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x75); - PUTDST8(RSPRecompPos,Value); -} - - -void RSPJmpDirectReg( int32_t x86reg ) { - OPCODE_REG_REG(8,0xff,OP_D4,x86reg); -} - -void RSPJmpLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0xEB); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJmpLabel32( uint32_t Value) { - PUTDST8(RSPRecompPos,0xE9); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJneLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x75); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJneLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x850F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJnsLabel8( uint8_t Value) { - PUTDST8(RSPRecompPos,0x79); - PUTDST8(RSPRecompPos,Value); -} - -void RSPJnsLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x890F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPJsLabel32(uint32_t Value) { - PUTDST16(RSPRecompPos,0x880F); - PUTDST32(RSPRecompPos,Value); -} - -void RSPLeaRegReg(int32_t x86RegDest, int32_t x86RegSrc, int32_t multiplier) { - OPCODE_REG_BASE_INDEX_SCALE(8,0x8D,x86RegDest,x86_EBP,x86RegSrc,Index[multiplier]); - PUTDST32(RSPRecompPos,0x00000000); -} - -void RSPLeaSourceAndOffset(int32_t x86DestReg, int32_t x86SourceReg, int32_t offset) { - OPCODE_REG_MREG_IMM32(8,0x8D,x86DestReg,x86SourceReg,offset); -} - -void RSPMoveConstByteToVariable (uint8_t Const,void *Variable) { - OPCODE_REG_VARIABLE(,8,0xC6,OP_D0,Variable) - PUTDST8(RSPRecompPos,Const); -} - -void RSPMoveConstHalfToVariable (uint16_t Const,void *Variable) { - OPCODE_REG_VARIABLE(PUTDST8(RSPRecompPos,0x66),8,0xC7,OP_D0,Variable) - PUTDST16(RSPRecompPos,Const); -} - -void RSPMoveConstHalfToX86regPointer(uint16_t Const, int32_t AddrReg1, int32_t AddrReg2) { - PUTDST8(RSPRecompPos,0x66); - OPCODE_REG_BASE_INDEX(8,0xC7,OP_D0,AddrReg1,AddrReg2); - PUTDST16(RSPRecompPos,Const); -} - -void RSPMoveX86regByteToN64Mem(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,8,0x88,x86reg,AddrReg); -} - -void RSPMoveX86regHalfToN64Mem(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(PUTDST8(RSPRecompPos,0x66),8,0x89,x86reg,AddrReg); -} - -void RSPMoveX86regToN64Mem(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,8,0x89,x86reg,AddrReg); -} - - -void RSPMoveConstToVariable (uint32_t Const,void *Variable) { - OPCODE_REG_VARIABLE(,8,0xC7,OP_D0,Variable) - PUTDST32(RSPRecompPos,Const); -} - -void RSPMoveConstToX86Pointer(uint32_t Const, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0xC7,OP_D0,X86Pointer); - PUTDST32(RSPRecompPos,Const); -} - - -void RSPMoveOffsetToX86reg(uint32_t Const, int32_t x86reg) { - OPCODE_REG_REG(8,0xC7,OP_D0,x86reg); - PUTDST32(RSPRecompPos,Const); -} - - -void RSPMoveConstToX86reg(uint32_t Const, int32_t x86reg) { - OPCODE_REG_REG(8,0xC7,OP_D0,x86reg); - PUTDST32(RSPRecompPos,Const); -} - -void RSPMoveConstQwordToX86reg(uintptr_t Const, int32_t x86reg) { -#ifndef USEX64 - OPCODE_REG_REG(8,0xC7,OP_D0,x86reg); - PUTDST32(RSPRecompPos,Const); -#else - PUTDST8(RSPRecompPos, 0x48 | ((x86reg&0x20)>>5)); - PUTDST8(RSPRecompPos, 0xB8 | ((x86reg-1)&0x7)); - PUTDST64(RSPRecompPos,Const); -#endif -} - -void RSPMoveConstByteToX86regPointer(uint8_t Const, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0xC6,OP_D0,AddrReg1,AddrReg2) - PUTDST8(RSPRecompPos,Const); -} - -void RSPMoveConstToX86regPointer(uint32_t Const, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0xC7,OP_D0,AddrReg1,AddrReg2); - PUTDST32(RSPRecompPos,Const); -} - -void RSPMoveN64MemToX86reg(int32_t x86reg, int32_t AddrReg) { -#ifdef USEX64 - if(((uintptr_t)DMEM - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_IMM32(8,0x8B,x86reg,x86_R15,AddrReg,(uintptr_t)DMEM - (uintptr_t)TLB_Map); - } else { - LOAD_VARIABLE(x86_TEMP, DMEM); - OPCODE_REG_BASE_INDEX(8,0x8B,x86reg,x86_TEMP,AddrReg); - } -#else - OPCODE_REG_MREG_IMM32(8,0x8B,x86reg,AddrReg,DMEM); -#endif -} - -void RSPMoveSxByteX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xBE0F,x86reg,AddrReg1,AddrReg2); -} - -void RSPMoveSxHalfX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xBF0F,x86reg,AddrReg1,AddrReg2); -} - - -void RSPMoveN64MemToX86regByte(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,8,0x8A,x86reg,AddrReg); -} - - -void RSPMoveSxN64MemToX86regByte(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0xBE0F,x86reg,AddrReg); -} - -void RSPMoveSxVariableToX86regHalf(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xBF0F,x86reg,Variable); -} - - -void RSPMoveSxN64MemToX86regHalf(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0xBF0F,x86reg,AddrReg); -} - -void RSPMoveZxN64MemToX86regHalf(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_ADDR_DMEM(,16,0xB70F,x86reg,AddrReg); -} - -void RSPMoveVariableToX86reg(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x8B,x86reg,Variable); -} - -void RSPMoveX86RegDispToX86Reg(int32_t x86reg, int32_t AddrReg, int32_t IndexReg, int32_t Multiplier) { - OPCODE_REG_BASE_INDEX_SCALE(8,0x8B,x86reg,AddrReg,IndexReg,Index[Multiplier]); -} - -void RSPMoveN64MemDispToX86reg(int32_t x86reg, int32_t AddrReg, uint8_t Disp) { -#ifdef USEX64 - if(((uintptr_t)DMEM - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_SCALE_IMM32(8,0x8B,x86reg,x86_R15,AddrReg,Index[0],(((uintptr_t)DMEM - (uintptr_t)TLB_Map))+Disp); - } else { - LOAD_VARIABLE(x86_TEMP, DMEM); - OPCODE_REG_BASE_INDEX_SCALE_IMM8(8,0x8B,x86reg,x86_TEMP,AddrReg,Index[0],Disp); - } -#else - OPCODE_REG_MREG_IMM32(8,0x8B,x86reg,AddrReg,DMEM+Disp); -#endif -} - -void RSPMoveVariableDispToX86Reg(void *Variable, int32_t x86reg, int32_t AddrReg, int32_t Multiplier) { -#ifdef USEX64 - if(((uintptr_t)Variable - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_SCALE_IMM32(8,0x8B,x86reg,x86_R15,AddrReg,Index[Multiplier],((uintptr_t)Variable - (uintptr_t)TLB_Map)); - } else { - LOAD_VARIABLE(x86_TEMP, Variable); - OPCODE_REG_BASE_INDEX_SCALE(8,0x8B,x86reg,x86_TEMP,AddrReg,Index[Multiplier]); - } -#else - OPCODE_REG_INDEX_SCALE_IMM32(8,0x8B,x86reg,AddrReg,Index[Multiplier],Variable); -#endif -} - -void RSPMoveN64MemToX86regHalf(int32_t x86reg, int32_t AddrReg) -{ - RSPMoveVariableDispToX86Reg(DMEM,x86reg,AddrReg,1); -} - - -void RSPMoveVariableToX86regByte(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x8A,x86reg,Variable); -} - -void RSPMoveVariableToX86regHalf(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(PUTDST8(RSPRecompPos,0x66),8,0x8B,x86reg,Variable); -} - -void RSPMoveX86regByteToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x88,x86reg,Variable); -} - -void RSPMoveX86regByteToX86regPointer(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_MREG(8,0x88,x86reg,AddrReg); -} - -void RSPMoveX86regHalfToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(PUTDST8(RSPRecompPos,0x66),8,0x89,x86reg,Variable); -} - -void RSPMoveX86regHalfToX86regPointer(int32_t x86reg, int32_t AddrReg) { - PUTDST8(RSPRecompPos,0x66); - OPCODE_REG_MREG(8,0x89,x86reg,AddrReg); -} - -void RSPMoveX86PointerToX86reg(int32_t x86reg, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0x8B,x86reg,X86Pointer); -} - -void RSPMoveX86regPointerToX86reg(int32_t Destination, int32_t AddrReg) { - OPCODE_REG_MREG(8,0x8B,Destination,AddrReg); -} - -void RSPMoveX86regPointerToX86regDisp8(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg, uint8_t offset) { - OPCODE_REG_BASE_INDEX_IMM8(8,0x8B,x86reg,AddrReg1,AddrReg2,offset); -} - -void RSPMoveX86regToMemory(int32_t x86reg, int32_t AddrReg, uint32_t Disp) { - OPCODE_REG_MREG_IMM32(8,0x89,x86reg,AddrReg,Disp); -} - -void RSPMoveX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x89,x86reg,Variable); -} - -void RSPMoveX86RegToX86Reg(int32_t Source, int32_t Destination) { - OPCODE_REG_REG(8,0x89,Source|X64_Reg, Destination|X64_Reg); -} - -void RSPMoveX86regToX86Pointer(int32_t x86reg, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0x89,x86reg, X86Pointer); -} - -void RSPMoveX86regToX86regPointer(int32_t x86reg, int32_t AddrReg) { - OPCODE_REG_MREG(8,0x89,x86reg,AddrReg); -} - -void RSPMoveZxByteX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xB60F,x86reg,AddrReg1,AddrReg2); -} - -void RSPMoveZxHalfX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xB70F,x86reg,AddrReg1,AddrReg2); -} - -void RSPMoveZxVariableToX86regByte(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xB60F,x86reg,Variable); -} - -void RSPMoveZxVariableToX86regHalf(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xB70F,x86reg,Variable); -} - -void RSPMulX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D4,x86reg); -} - -void RSPNotX86Reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D2,x86reg); -} - -void RSPOrConstToVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D1,Variable); - PUTDST32(RSPRecompPos,Const); -} - -void RSPOrConstToX86Reg(uint32_t Const, int32_t x86reg) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D1,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D1,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPOrVariableToX86Reg(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0xb,x86reg,Variable); -} - -void RSPOrX86RegToVariable(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x9,x86reg,Variable); -} - -void RSPOrX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x0B,Destination,Source); -} - -void RSPPushfd() { - PUTDST8(RSPRecompPos,0x9c); -} - -void RSPPopfd() { - PUTDST8(RSPRecompPos,0x9d); -} - -void RSPPopad(void) { -#ifdef USEX64 - PUTDST16(RSPRecompPos,0x5f41); - PUTDST16(RSPRecompPos,0x5e41); - PUTDST16(RSPRecompPos,0x5d41); - PUTDST16(RSPRecompPos,0x5c41); - PUTDST16(RSPRecompPos,0x5b41); - PUTDST16(RSPRecompPos,0x5a41); - PUTDST16(RSPRecompPos,0x5941); - PUTDST16(RSPRecompPos,0x5841); - PUTDST8(RSPRecompPos,0x5f); - PUTDST8(RSPRecompPos,0x5e); - PUTDST8(RSPRecompPos,0x5b); - PUTDST8(RSPRecompPos,0x5a); - PUTDST8(RSPRecompPos,0x59); - PUTDST8(RSPRecompPos,0x58); -#else - PUTDST8(RSPRecompPos,0x61); -#endif -} - -void RSPPushad(void) { -#ifdef USEX64 - PUTDST8(RSPRecompPos,0x50); - PUTDST8(RSPRecompPos,0x51); - PUTDST8(RSPRecompPos,0x52); - PUTDST8(RSPRecompPos,0x53); - PUTDST8(RSPRecompPos,0x56); - PUTDST8(RSPRecompPos,0x57); - PUTDST16(RSPRecompPos,0x5041); - PUTDST16(RSPRecompPos,0x5141); - PUTDST16(RSPRecompPos,0x5241); - PUTDST16(RSPRecompPos,0x5341); - PUTDST16(RSPRecompPos,0x5441); - PUTDST16(RSPRecompPos,0x5541); - PUTDST16(RSPRecompPos,0x5641); - PUTDST16(RSPRecompPos,0x5741); -#else -PUTDST8(RSPRecompPos,0x60); -#endif -} - -void RSPPush(int32_t x86reg) { - -#ifdef USEX64 - PUTDST8(RSPRecompPos, 0x40 | ((x86reg & 0x20) >> 5)); -#endif - switch(x86reg&0xf) { - case x86_EAX: PUTDST8(RSPRecompPos, 0x50); break; - case x86_EBX: PUTDST8(RSPRecompPos, 0x53); break; - case x86_ECX: PUTDST8(RSPRecompPos, 0x51); break; - case x86_EDX: PUTDST8(RSPRecompPos, 0x52); break; - case x86_ESI: PUTDST8(RSPRecompPos, 0x56); break; - case x86_EDI: PUTDST8(RSPRecompPos, 0x57); break; - case x86_ESP: PUTDST8(RSPRecompPos, 0x54); break; - case x86_EBP: PUTDST8(RSPRecompPos, 0x55); break; - } -} - -void RSPPop(int32_t x86reg) { -#ifdef USEX64 - PUTDST8(RSPRecompPos, 0x40 | ((x86reg & 0x20) >> 5)); -#endif - switch(x86reg&0xf) { - - case x86_EAX: PUTDST8(RSPRecompPos, 0x58); break; - case x86_EBX: PUTDST8(RSPRecompPos, 0x5B); break; - case x86_ECX: PUTDST8(RSPRecompPos, 0x59); break; - case x86_EDX: PUTDST8(RSPRecompPos, 0x5A); break; - case x86_ESI: PUTDST8(RSPRecompPos, 0x5E); break; - case x86_EDI: PUTDST8(RSPRecompPos, 0x5F); break; - case x86_ESP: PUTDST8(RSPRecompPos, 0x5C); break; - case x86_EBP: PUTDST8(RSPRecompPos, 0x5D); break; - } -} - -void RSPPushImm32(uint32_t Value) { - PUTDST8(RSPRecompPos,0x68); - PUTDST32(RSPRecompPos,Value); -} - -void RSPRet(void) { - PUTDST8(RSPRecompPos,0xC3); -} - -void RSPSeta(int32_t x86reg) { - OPCODE_REG_REG(16,0x970F,OP_D0,x86reg); -} - -void RSPSetaVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x970F,OP_D0,Variable); -} - -void RSPSetae(int32_t x86reg) { - OPCODE_REG_REG(16,0x930F,OP_D0,x86reg); -} - -void RSPSetb(int32_t x86reg) { - OPCODE_REG_REG(16,0x920F,OP_D0,x86reg); -} - -void RSPSetbVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x920F,OP_D0,Variable); -} - -void RSPSetg(int32_t x86reg) { - OPCODE_REG_REG(16,0x9F0F,OP_D0,x86reg); -} - -void RSPSetgVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x9F0F,OP_D0,Variable); -} - -void RSPSetl(int32_t x86reg) { - OPCODE_REG_REG(16,0x9C0F,OP_D0,x86reg); -} - -void RSPSetlVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x9C0F,OP_D0,Variable); -} - -void RSPShiftLeftSignVariableImmed(void *Variable, uint8_t Immediate) { - OPCODE_REG_VARIABLE(,8,0xC1,OP_D4,Variable); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftRightSignVariableImmed(void *Variable, uint8_t Immediate) { - OPCODE_REG_VARIABLE(,8,0xC1,OP_D7,Variable); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftRightUnsignVariableImmed(void *Variable, uint8_t Immediate) { - OPCODE_REG_VARIABLE(,8,0xC1,OP_D5,Variable); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPSetzVariable(void *Variable) { - OPCODE_REG_VARIABLE(,16,0x940F,OP_D0,Variable); -} - -void RSPSetnzVariable(void *Variable) { - OPCODE_REG_VARIABLE(,16,0x950F,OP_D0,Variable); -} - -void RSPSetleVariable(void *Variable) { - RSPBreakPoint(); - OPCODE_REG_VARIABLE(,16,0x9E0F,OP_D0,Variable); -} - -void RSPSetgeVariable(void *Variable) { - RSPBreakPoint(); - OPCODE_REG_VARIABLE(,16,0x9D0F,OP_D0,Variable); -} - -void RSPSetz(int32_t x86reg) { - OPCODE_REG_REG(16,0x940F,OP_D0,x86reg); -} - -void RSPSetnz(int32_t x86reg) { - OPCODE_REG_REG(16,0x950F,OP_D0,x86reg); -} - -void RSPShiftLeftDouble(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(16,0xA50F,Source,Destination); -} - -void RSPShiftLeftDoubleImmed(int32_t Destination, int32_t Source, uint8_t Immediate) { - OPCODE_REG_REG(16,0xA40F,Source,Destination); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftLeftSign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D4,x86reg); -} - -void RSPShiftLeftSignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D4,x86reg); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftRightSign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D7,x86reg); -} - -void RSPShiftRightSignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D7,x86reg); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftRightUnsign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D5,x86reg); -} - -void RSPShiftRightDouble(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(16,0xAD0F,Source,Destination); -} - -void RSPShiftRightDoubleImmed(int32_t Destination, int32_t Source, uint8_t Immediate) { - OPCODE_REG_REG(16,0xAC0F,Source,Destination); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPShiftRightUnsignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D5,x86reg); - PUTDST8(RSPRecompPos,Immediate); -} - -void RSPSbbConstFromX86Reg (int32_t x86reg, uint32_t Const) { -RSPBreakPoint(); - - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D3,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D3,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPSbbVariableFromX86reg(int32_t x86reg, void * Variable) { - RSPBreakPoint(); - OPCODE_REG_VARIABLE(,8,0x1B,x86reg,Variable); -} - -void RSPSbbX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x1B,Destination,Source); -} - -void RSPSubConstFromVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D5,Variable); - PUTDST32(RSPRecompPos,Const); -} - -void RSPSubConstFromX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D5,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D5,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - -void RSPSubVariableFromX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x2B,x86reg,Variable); -} - -void RSPSubX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x2B,Destination,Source); -} - -void RSPTestConstToX86Reg(uint32_t Const, int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D0,x86reg); - PUTDST32(RSPRecompPos,Const); -} - -void RSPTestVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0xf7,OP_D0,Variable); - PUTDST32(RSPRecompPos,Const); -} - -void RSPTestX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x85,Destination,Source); -} - -void RSPTestVariableToX86Reg(uint32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x85,x86reg,Variable); -} - -void RSPXorConstToX86Reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D6,x86reg); - PUTDST32(RSPRecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D6,x86reg); - PUTDST8(RSPRecompPos, Const); - } -} - - -void RSPXorX86RegToX86Reg(int32_t Source, int32_t Destination) { - OPCODE_REG_REG(8,0x31,Destination,Source); -} - -void RSPXorVariableToX86reg(void *Variable, int32_t x86reg) { - RSPBreakPoint(); - OPCODE_REG_VARIABLE(,8,0x33,x86reg,Variable); -} - - -void RSPXorConstToVariable(void *Variable, uint32_t Const) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D6,Variable); - PUTDST32(RSPRecompPos,Const); -} - -// ******************************************************************************************** - -void RSPAndX86RegToVariable(void * Variable, int32_t x86Reg) { - OPCODE_REG_VARIABLE(,8,0x21,x86Reg,Variable); -} - -void RSPXorX86RegToVariable(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x31,x86reg,Variable); -} - -void RSPTestConstToVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0xf7,OP_D0,Variable); - PUTDST32(RSPRecompPos,Const); -} - -void RSPCondMoveGreaterEqual(int32_t Destination, int32_t Source) { - if (ConditionalMove == 0) { - uint8_t * Jump; - // CPU_Message(" [*]cmovge %s, %s",x86_Name(Destination),x86_Name(Source)); - - RSPJlLabel8(0); - Jump = RSPRecompPos - 1; - RSPMoveX86RegToX86Reg(Source, Destination); - // CPU_Message(" label:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } else { - uint8_t x86Command; - // CPU_Message(" cmovge %s, %s",x86_Name(Destination),x86_Name(Source)); - - PUTDST16(RSPRecompPos,0x4D0F); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST8(RSPRecompPos, x86Command); - } -} - -void RSPMoveX86regPointerToX86regByte(int32_t Destination, int32_t AddrReg) { - uint8_t x86Command = 0; - - // CPU_Message(" mov %s, byte ptr [%s]",x86Byte_Name(Destination), x86_Name(AddrReg)); - - switch (AddrReg&0xf) { - 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; - default: DisplayError("MoveX86regPointerToX86regByte\nUnknown x86 Register"); - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0x00; break; - case x86_EBX: x86Command += 0x18; break; - case x86_ECX: x86Command += 0x08; break; - case x86_EDX: x86Command += 0x10; break; - default: DisplayError("MoveX86regPointerToX86regByte\nUnknown x86 Register"); - } - - PUTDST8(RSPRecompPos, 0x8A); - PUTDST8(RSPRecompPos, x86Command); -} - -void RSPMoveX86regToN64MemDisp(int32_t x86reg, int32_t AddrReg, uint8_t Disp) { -#ifdef USEX64 - if(((uintptr_t)DMEM - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_IMM32(8,0x89,x86reg,x86_R15,AddrReg,((uintptr_t)DMEM - (uintptr_t)TLB_Map) + Disp); - } else { - LOAD_VARIABLE(x86_TEMP, DMEM); - OPCODE_REG_MREG_IMM8(8,0xf7,x86reg,x86_TEMP,Disp); - } -#else - OPCODE_REG_MREG_IMM32(8,0x89,x86reg,AddrReg,DMEM + Disp); -#endif -} - -void RSPOrVariableToX86regHalf(void * Variable, int32_t x86Reg) { - OPCODE_REG_VARIABLE(PUTDST8(RSPRecompPos,0x66),8,0xb,x86Reg,Variable); -} - -void RSPAndVariableToX86regHalf(void * Variable, int32_t x86Reg) { - OPCODE_REG_VARIABLE(PUTDST8(RSPRecompPos,0x66),8,0x23,x86Reg,Variable); -} - -void RSPAndX86RegHalfToX86RegHalf(int32_t Destination, int32_t Source) { - PUTDST8(RSPRecompPos, 0x66); - OPCODE_REG_REG(8,0x21,Source,Destination); -} - -void RSPCondMoveNotEqual(int32_t Destination, int32_t Source) { - if (ConditionalMove == 0) { - uint8_t * Jump; - // CPU_Message(" [*]cmovne %s, %s",x86_Name(Destination),x86_Name(Source)); - - RSPJeLabel8(0); - Jump = RSPRecompPos - 1; - RSPMoveX86RegToX86Reg(Source, Destination); - // CPU_Message(" label:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } else { - uint8_t x86Command; - // CPU_Message(" cmovne %s, %s",x86_Name(Destination),x86_Name(Source)); - - PUTDST16(RSPRecompPos,0x450F); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST8(RSPRecompPos, x86Command); - } -} - - -void RSPNegateX86reg(int32_t x86reg) { - // CPU_Message(" neg %s", x86_Name(x86reg)); - switch (x86reg&0xf) { - case x86_EAX: PUTDST16(RSPRecompPos,0xd8f7); break; - case x86_EBX: PUTDST16(RSPRecompPos,0xdbf7); break; - case x86_ECX: PUTDST16(RSPRecompPos,0xd9f7); break; - case x86_EDX: PUTDST16(RSPRecompPos,0xdaf7); break; - case x86_ESI: PUTDST16(RSPRecompPos,0xdef7); break; - case x86_EDI: PUTDST16(RSPRecompPos,0xdff7); break; - case x86_ESP: PUTDST16(RSPRecompPos,0xdcf7); break; - case x86_EBP: PUTDST16(RSPRecompPos,0xddf7); break; - default: - DisplayError("NegateX86reg\nUnknown x86 Register"); - } -} - - -void RSPImulX86RegToX86Reg(int32_t Destination, int32_t Source) { - uint8_t x86Command; - - // CPU_Message(" imul %s, %s",x86_Name(Destination), x86_Name(Source)); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST16(RSPRecompPos, 0xAF0F); - PUTDST8(RSPRecompPos, x86Command); -} - - -void RSPMoveX86RegToX86regPointerDisp ( int32_t Source, int32_t AddrReg, uint8_t Disp ) { - OPCODE_REG_MREG_IMM8(8,0x89,Source,AddrReg,Disp); -} - -void RSPCondMoveGreater(int32_t Destination, int32_t Source) { - if (ConditionalMove == 0) { - uint8_t * Jump; - // CPU_Message(" [*]cmovg %s, %s",x86_Name(Destination),x86_Name(Source)); - - RSPJleLabel8(0); - Jump = RSPRecompPos - 1; - RSPMoveX86RegToX86Reg(Source, Destination); - // CPU_Message(" label:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } else { - uint8_t x86Command; - // CPU_Message(" cmovg %s, %s",x86_Name(Destination),x86_Name(Source)); - - PUTDST16(RSPRecompPos,0x4F0F); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST8(RSPRecompPos, x86Command); - } -} - -void RSPCondMoveLess(int32_t Destination, int32_t Source) { - if (ConditionalMove == 0) { - uint8_t * Jump; - // CPU_Message(" [*]cmovl %s, %s",x86_Name(Destination),x86_Name(Source)); - - RSPJgeLabel8(0); - Jump = RSPRecompPos - 1; - RSPMoveX86RegToX86Reg(Source, Destination); - // CPU_Message(" label:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } else { - uint8_t x86Command; - // CPU_Message(" cmovl %s, %s",x86_Name(Destination),x86_Name(Source)); - - PUTDST16(RSPRecompPos,0x4C0F); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST8(RSPRecompPos, x86Command); - } -} - -void RSPMoveSxX86RegPtrDispToX86RegHalf(int32_t AddrReg, uint8_t Disp, int32_t Destination) { - OPCODE_REG_MREG_IMM8(16,0xBF0F,Destination,AddrReg,Disp); - -} - - -void RSPMoveZxX86RegPtrDispToX86RegHalf(int32_t AddrReg, uint8_t Disp, int32_t Destination) { - OPCODE_REG_MREG_IMM8(16,0xB70F,Destination,AddrReg,Disp); -} - - -void RSPMoveX86regHalfToX86regPointerDisp(int32_t Source, int32_t AddrReg, uint8_t Disp) { - uint8_t x86Amb; - - // CPU_Message(" mov word ptr [%s+%X], %s",x86_Name(AddrReg), Disp, x86Half_Name(Source)); - - switch (AddrReg&0xf) { - case x86_EAX: x86Amb = 0x00; break; - case x86_EBX: x86Amb = 0x03; break; - case x86_ECX: x86Amb = 0x01; break; - case x86_EDX: x86Amb = 0x02; break; - case x86_ESI: x86Amb = 0x06; break; - case x86_EDI: x86Amb = 0x07; break; - case x86_ESP: x86Amb = 0x04; break; - case x86_EBP: x86Amb = 0x05; break; - default: DisplayError("MoveX86regBytePointer\nUnknown x86 Register"); - } - - switch (Source&0xf) { - case x86_EAX: x86Amb += 0x00; break; - case x86_ECX: x86Amb += 0x08; break; - case x86_EDX: x86Amb += 0x10; break; - case x86_EBX: x86Amb += 0x18; break; - case x86_ESI: x86Amb += 0x30; break; - case x86_EDI: x86Amb += 0x38; break; - case x86_ESP: x86Amb += 0x20; break; - case x86_EBP: x86Amb += 0x28; break; - default: DisplayError("MoveX86regBytePointer\nUnknown x86 Register"); - } - - PUTDST16(RSPRecompPos, 0x8966); - PUTDST8(RSPRecompPos, x86Amb | 0x40); - PUTDST8(RSPRecompPos, Disp); -} - -void RSPCondMoveEqual(int32_t Destination, int32_t Source) { - if (ConditionalMove == 0) { - uint8_t * Jump; - // CPU_Message(" [*]cmove %s, %s",x86_Name(Destination),x86_Name(Source)); - - RSPJneLabel8(0); - Jump = RSPRecompPos - 1; - RSPMoveX86RegToX86Reg(Source, Destination); - // CPU_Message(" label:"); - RSPx86_SetBranch8b(Jump, RSPRecompPos); - } else { - uint8_t x86Command; - // CPU_Message(" cmove %s, %s",x86_Name(Destination),x86_Name(Source)); - - PUTDST16(RSPRecompPos,0x440F); - - switch (Source&0xf) { - 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; - } - - switch (Destination&0xf) { - case x86_EAX: x86Command += 0xC0; break; - case x86_EBX: x86Command += 0xD8; break; - case x86_ECX: x86Command += 0xC8; break; - case x86_EDX: x86Command += 0xD0; break; - case x86_ESI: x86Command += 0xF0; break; - case x86_EDI: x86Command += 0xF8; break; - case x86_ESP: x86Command += 0xE0; break; - case x86_EBP: x86Command += 0xE8; break; - } - - PUTDST8(RSPRecompPos, x86Command); - } -} - - -void RSPCwd(void) { - // CPU_Message(" cwd"); - PUTDST16(RSPRecompPos, 0x9966); -} - -void RSPCwde(void) { - // CPU_Message(" cwde"); - PUTDST8(RSPRecompPos, 0x98); -} - -void RSPSubX86regFromVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x29,x86reg,Variable); -} - -void RSPJumpX86Reg( int32_t x86reg ) { - // CPU_Message(" jmp %s",x86_Name(x86reg)); -/* - switch (x86reg) { - case x86_EAX: PUTDST16(RSPRecompPos,0xe0ff); break; - case x86_EBX: PUTDST16(RSPRecompPos,0xe3ff); break; - case x86_ECX: PUTDST16(RSPRecompPos,0xe1ff); break; - case x86_EDX: PUTDST16(RSPRecompPos,0xe2ff); break; - case x86_ESI: PUTDST16(RSPRecompPos,0xe6ff); break; - case x86_EDI: PUTDST16(RSPRecompPos,0xe7ff); break; - default: DisplayError("JumpX86Reg: Unknown reg (%08x)", x86reg); Int3(); - }*/ - OPCODE_REG_REG(8,0xFF,OP_D4,x86reg); -} - - - - -void RSPJgeLabel8(uint8_t Value) { - PUTDST8(RSPRecompPos,0x7D); - PUTDST8(RSPRecompPos,Value); -} - diff --git a/src/usf/rsp_x86.h b/src/usf/rsp_x86.h deleted file mode 100644 index 0b7df86..0000000 --- a/src/usf/rsp_x86.h +++ /dev/null @@ -1,552 +0,0 @@ -/* - * RSP Compiler plug in for Project 64 (A Nintendo 64 emulator). - * - * (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. - * - */ - -/*enum x86RegValues { - x86_EAX = 0, x86_EBX = 1, x86_ECX = 2, x86_EDX = 3, - x86_ESI = 4, x86_EDI = 5, x86_EBP = 6, x86_ESP = 7 -};*/ - -#include "types.h" - -enum mmxRegValues { - x86_MM0 = 1, x86_MM1 = 2, x86_MM2 = 3, x86_MM3 = 4, - x86_MM4 = 5, x86_MM5 = 6, x86_MM6 = 7, x86_MM7 = 8 -}; - -enum sseRegValues { - x86_XMM0 = 1, x86_XMM1 = 2, x86_XMM2 = 3, x86_XMM3 = 4, - x86_XMM4 = 5, x86_XMM5 = 6, x86_XMM6 = 7, x86_XMM7 = 8 -}; - -#ifdef USEX64 -enum x86RegValues { - - x86_Any = 0, - x86_EAX,x86_ECX,x86_EDX,x86_EBX,x86_ESP,x86_EBP,x86_ESI,x86_EDI,x86_Any8Bit=0x40,x64_Any = 0x40, - - x86_RAX = 0x11,x86_RCX,x86_RDX,x86_RBX,x86_RSP,x86_RBP,x86_RSI,x86_RDI, - - x86_R8D = 0x21,x86_R9D,x86_R10D,x86_R11D,x86_R12D,x86_R13D,x86_R14D,x86_R15D, - - x86_R8 = 0x31,x86_R9,x86_R10,x86_R11,x86_R12,x86_R13,x86_R14,x86_R15, - -}; - -enum x86FpuValues { - x86_ST0,x86_ST1,x86_ST2,x86_ST3,x86_ST4,x86_ST5,x86_ST6,x86_ST7 -}; - -#define x86_TEMP x86_R8 -#define x86_TEMPD x86_R8D - -#define OP_D0 1 -#define OP_D1 2 -#define OP_D2 3 -#define OP_D3 4 -#define OP_D4 5 -#define OP_D5 6 -#define OP_D6 7 -#define OP_D7 8 - -#define LOAD_VARIABLE(reg,variable) \ - PUTDST8(RSPRecompPos, 0x48 | (((reg)&0x20)>>5)); \ - PUTDST8(RSPRecompPos,0xB8 | ((reg)-1)&0xf); \ - PUTDST64(RSPRecompPos,variable); - -// // 43 0F B6 0C 0D 40 83 C7 04 movzx ecx,byte ptr [r9+4C78340h] - -#define OPCODE_REG_REG(oplen,opcode,reg,rm) \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)&0x20)>>5) | ((((rm|reg))&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0xC0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); - -#define OPCODE_REG_MREG(oplen,opcode,reg,rm) \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((rm)&0xf)==0x6) { \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0); \ - } else if(((rm)&0xf)==0x5) { \ - PUTDST8(RSPRecompPos, 0x0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x24); \ - } else { \ - PUTDST8(RSPRecompPos, 0x00 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } - -#define OPCODE_REG_MREG_IMM32(oplen,opcode,reg,rm,imm32) \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((rm)&0xf)==0x5) { \ - PUTDST8(RSPRecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x24); \ - } else { \ - PUTDST8(RSPRecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } \ - PUTDST32(RSPRecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX(oplen,opcode,reg,base,index) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((base)&0xf)!=0x6) { \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - } else {\ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RSPRecompPos, 0); \ - } - -#define OPCODE_REG_MREG_IMM8(oplen,opcode,reg,rm,imm8) \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos,imm8); - -/*scale is: 0=1,0x40=2,0x80=4,0xc0=8 ??*/ - -#define OPCODE_REG_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((scale)-1)*0x40) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM32(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM8(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos,imm32); - - - -#define OPCODE_REG_BASE_INDEX_IMM8(oplen,opcode,reg,base,index,imm8) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RSPRecompPos, imm8); - -#define OPCODE_REG_BASE_INDEX_IMM32(oplen,opcode,reg,base,index,imm32) \ - PUTDST8(RSPRecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos, imm32); - -#else - -enum x86RegValues { - - x86_Any = 0, - x86_EAX,x86_ECX,x86_EDX,x86_EBX,x86_ESP,x86_EBP,x86_ESI,x86_EDI,x86_Any8Bit=0x40,x64_Any = 0x0, - x86_RAX = 0x1,x86_RCX,x86_RDX,x86_RBX,x86_RSP,x86_RBP,x86_RSI,x86_RDI, - -}; - -enum x86FpuValues { - x86_ST0,x86_ST1,x86_ST2,x86_ST3,x86_ST4,x86_ST5,x86_ST6,x86_ST7 -}; - - -#define OP_D0 1 -#define OP_D1 2 -#define OP_D2 3 -#define OP_D3 4 -#define OP_D4 5 -#define OP_D5 6 -#define OP_D6 7 -#define OP_D7 8 - -// // 43 0F B6 0C 0D 40 83 C7 04 movzx ecx,byte ptr [r9+4C78340h] - - -#define OPCODE_REG_DISP(oplen,opcode,reg,disp32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x5 | ((((reg)-1)&0x7) << 3)); \ - PUTDST32(RSPRecompPos,disp32); - - -#define OPCODE_REG_REG(oplen,opcode,reg,rm) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0xC0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); - -#define OPCODE_REG_MREG(oplen,opcode,reg,rm) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((rm)&0xf)==0x6) { \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0); \ - } else if(((rm)&0xf)==0x5) { \ - PUTDST8(RSPRecompPos, 0x0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x24); \ - } else { \ - PUTDST8(RSPRecompPos, 0x00 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } - -#define OPCODE_REG_MREG_IMM32(oplen,opcode,reg,rm,imm32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((rm)&0xf)==0x5) { \ - PUTDST8(RSPRecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x24); \ - } else { \ - PUTDST8(RSPRecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } \ - PUTDST32(RSPRecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX(oplen,opcode,reg,base,index) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - if(((base)&0xf)!=0x6) { \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - } else {\ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RSPRecompPos, 0); \ - } - -#define OPCODE_REG_MREG_IMM8(oplen,opcode,reg,rm,imm8) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos,imm8); - -#define OPCODE_REG_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((scale)-1)*0x40) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM32(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM8(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos,imm32); - - -#define OPCODE_REG_BASE_INDEX_IMM8(oplen,opcode,reg,base,index,imm8) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RSPRecompPos, imm8); - -#define OPCODE_REG_BASE_INDEX_IMM32(oplen,opcode,reg,base,index,imm32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos, imm32); - -#define OPCODE_REG_INDEX_SCALE_IMM32(oplen,opcode,reg,index,scale,imm32) \ - PUTDST##oplen (RSPRecompPos, opcode); \ - PUTDST8(RSPRecompPos, 0x4 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RSPRecompPos, 0x5 | (scale) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RSPRecompPos,imm32); - -#endif - - -#ifndef USEX64 - -#define OPCODE_REG_VARIABLE(PREFIX,oplen,opcode,reg,variable) \ - PREFIX \ - OPCODE_REG_DISP(oplen,opcode,reg,variable); - -#define OPCODE_REG_ADDR_DMEM(PREFIX,oplen,opcode,reg,addr) \ - PREFIX \ - OPCODE_REG_MREG_IMM32(oplen,opcode,reg,addr,DMEM); - -#else - -#define OPCODE_REG_VARIABLE(PREFIX,oplen,opcode,reg,Variable) \ - if(((uintptr_t)(Variable) - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { \ - PREFIX \ - OPCODE_REG_MREG_IMM32(oplen,opcode,reg,x86_R15,(uintptr_t)(Variable) - (uintptr_t)TLB_Map); \ - } else { \ - LOAD_VARIABLE(x86_TEMP, (Variable)); \ - PREFIX \ - OPCODE_REG_MREG(oplen,opcode,reg,x86_TEMP); \ - } - -#define OPCODE_REG_ADDR_DMEM(PREFIX,oplen,opcode,reg,addr) \ - if(((uintptr_t)(DMEM) - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { \ - PREFIX \ - OPCODE_REG_BASE_INDEX_IMM32(oplen,opcode,reg,x86_R15,addr,(uintptr_t)(DMEM) - (uintptr_t)TLB_Map); \ - } else { \ - LOAD_VARIABLE(x86_TEMP, (DMEM)); \ - PREFIX \ - OPCODE_REG_BASE_INDEX(oplen,opcode,reg,x86_TEMP,addr); \ - } - -#endif - -#ifdef USEX64 - #define LOAD_FROM_DMEM(dstreg,srcreg) MoveX86RegDispToX86Reg(dstreg, x86_R15, srcreg, 8); -#else - #define LOAD_FROM_DMEM(dstreg,srcreg) MoveVariableDispToX86Reg(DMEM,dstreg,srcreg,4); -#endif - - -void RSPAdcX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPAdcX86regToVariable ( int32_t x86reg, void * Variable ); -void RSPAdcX86regHalfToVariable ( int32_t x86reg, void * Variable ); -void RSPAdcConstToX86reg ( uint8_t Constant, int32_t x86reg ); -void RSPAdcConstToVariable ( void *Variable, uint8_t Constant ); -void RSPAdcConstHalfToVariable ( void *Variable, uint8_t Constant ); -void RSPAddConstToVariable ( uint32_t Const, void *Variable ); -void RSPAddConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void RSPAddQwordToX86Reg (int32_t x86reg, uint64_t Const); -void RSPAddVariableToX86reg ( int32_t x86reg, void * Variable ); -void RSPAddX86regToVariable ( int32_t x86reg, void * Variable ); -void RSPAddX86regHalfToVariable ( int32_t x86reg, void * Variable ); -void RSPAddX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPAndConstToVariable ( uint32_t Const, void *Variable ); -void RSPAndConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void RSPAndVariableToX86Reg ( void * Variable, int32_t x86Reg ); -void RSPAndVariableToX86regHalf ( void * Variable, int32_t x86Reg ); -void RSPAndX86RegToVariable ( void * Variable, int32_t x86Reg ); -void RSPAndX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPAndX86RegHalfToX86RegHalf ( int32_t Destination, int32_t Source ); -void RSPBreakPoint (void); -void RSPCall_Direct ( void * FunctAddress ); -void RSPCall_Indirect ( void * FunctAddress ); -void RSPCondMoveEqual ( int32_t Destination, int32_t Source ); -void RSPCondMoveNotEqual ( int32_t Destination, int32_t Source ); -void RSPCondMoveGreater ( int32_t Destination, int32_t Source ); -void RSPCondMoveGreaterEqual ( int32_t Destination, int32_t Source ); -void RSPCondMoveLess ( int32_t Destination, int32_t Source ); -void RSPCondMoveLessEqual ( int32_t Destination, int32_t Source ); -void RSPCompConstToVariable ( uint32_t Const, void * Variable ); -void RSPCompConstHalfToVariable ( uint16_t Const, void * Variable ); -void RSPCompConstToX86reg ( int32_t x86Reg, uint32_t Const ); -void RSPCompX86regToVariable ( int32_t x86Reg, void * Variable ); -void RSPCompVariableToX86reg ( int32_t x86Reg, void * Variable ); -void RSPCompX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPMoveConstQwordToX86reg ( uintptr_t, int32_t); -void RSPCwd ( void ); -void RSPCwde ( void ); -void RSPDecX86reg ( int32_t x86Reg ); -void RSPDivX86reg ( int32_t x86reg ); -void RSPidivX86reg ( int32_t x86reg ); -void RSPimulX86reg ( int32_t x86reg ); -void RSPImulX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPIncX86reg ( int32_t x86Reg ); -void RSPJaeLabel32 ( uint32_t Value ); -void RSPJaLabel8 ( uint8_t Value ); -void RSPJaLabel32 ( uint32_t Value ); -void RSPJbLabel8 ( uint8_t Value ); -void RSPJbLabel32 ( uint32_t Value ); -void RSPJeLabel8 ( uint8_t Value ); -void RSPJeLabel32 ( uint32_t Value ); -void RSPJgeLabel8 ( uint8_t Value ); -void RSPJgeLabel32 ( uint32_t Value ); -void RSPJgLabel8 ( uint8_t Value ); -void RSPJgLabel32 ( uint32_t Value ); -void RSPJleLabel8 ( uint8_t Value ); -void RSPJleLabel32 ( uint32_t Value ); -void RSPJlLabel8 ( uint8_t Value ); -void RSPJlLabel32 ( uint32_t Value ); -void RSPJumpX86Reg ( int32_t x86reg ); -void RSPJmpLabel8 ( uint8_t Value ); -void RSPJmpLabel32 ( uint32_t Value); -void RSPJneLabel8 ( uint8_t Value ); -void RSPJneLabel32 ( uint32_t Value ); -void RSPJnsLabel8 ( uint8_t Value ); -void RSPJnsLabel32 ( uint32_t Value ); -void RSPJsLabel32 ( uint32_t Value ); -void RSPLeaSourceAndOffset ( int32_t x86DestReg, int32_t x86SourceReg, int32_t offset ); -void RSPMoveConstByteToN64Mem ( uint8_t Const, int32_t AddrReg ); -void RSPMoveConstHalfToN64Mem ( uint16_t Const, int32_t AddrReg ); -void RSPMoveConstByteToVariable ( uint8_t Const,void *Variable ); -void RSPMoveConstHalfToVariable ( uint16_t Const, void *Variable ); -void RSPMoveConstToN64Mem ( uint32_t Const, int32_t AddrReg ); -void RSPMoveConstToN64MemDisp ( uint32_t Const, int32_t AddrReg, uint8_t Disp ); -void RSPMoveConstToVariable ( uint32_t Const, void *Variable ); -void RSPMoveConstToX86reg ( uint32_t Const, int32_t x86reg ); -void RSPMoveOffsetToX86reg ( uint32_t Const, int32_t x86reg ); -void RSPMoveX86regByteToX86regPointer ( int32_t Source, int32_t AddrReg ); -void RSPMoveX86regHalfToX86regPointer ( int32_t Source, int32_t AddrReg ); -void RSPMoveX86regHalfToX86regPointerDisp ( int32_t Source, int32_t AddrReg, uint8_t Disp); -void RSPMoveX86regToX86regPointer ( int32_t Source, int32_t AddrReg ); -void RSPMoveX86RegToX86regPointerDisp ( int32_t Source, int32_t AddrReg, uint8_t Disp ); -void RSPMoveX86regPointerToX86regByte ( int32_t Destination, int32_t AddrReg ); -void RSPMoveX86regPointerToX86regHalf ( int32_t Destination, int32_t AddrReg ); -void RSPMoveX86regPointerToX86reg ( int32_t Destination, int32_t AddrReg ); -void RSPMoveN64MemDispToX86reg ( int32_t x86reg, int32_t AddrReg, uint8_t Disp ); -void RSPMoveN64MemToX86reg ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveX86regByteToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveX86regByteToVariable ( int32_t x86reg, void * Variable ); -void RSPMoveX86regHalfToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveX86regHalfToVariable ( int32_t x86reg, void * Variable ); -void RSPMoveX86regToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveX86regToN64MemDisp ( int32_t x86reg, int32_t AddrReg, uint8_t Disp ); -void RSPMoveX86regToVariable ( int32_t x86reg, void * Variable ); -void RSPMoveX86RegToX86Reg ( int32_t Source, int32_t Destination ); -void RSPMoveVariableToX86reg ( void *Variable, int32_t x86reg ); -void RSPMoveVariableToX86regByte ( void *Variable, int32_t x86reg ); -void RSPMoveVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void RSPMoveSxX86RegHalfToX86Reg ( int32_t Source, int32_t Destination ); -void RSPMoveSxX86RegPtrDispToX86RegHalf( int32_t AddrReg, uint8_t Disp, int32_t Destination ); -void RSPMoveSxN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveSxN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveSxVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void RSPMoveZxX86RegHalfToX86Reg ( int32_t Source, int32_t Destination ); -void RSPMoveZxX86RegPtrDispToX86RegHalf( int32_t AddrReg, uint8_t Disp, int32_t Destination ); -void RSPMoveZxN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveZxN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void RSPMoveZxVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void RSPMulX86reg ( int32_t x86reg ); -void RSPNegateX86reg ( int32_t x86reg ); -void RSPOrConstToVariable ( uint32_t Const, void * Variable ); -void RSPOrConstToX86Reg ( uint32_t Const, int32_t x86Reg ); -void RSPOrVariableToX86Reg ( void * Variable, int32_t x86Reg ); -void RSPOrVariableToX86regHalf ( void * Variable, int32_t x86Reg ); -void RSPOrX86RegToVariable ( void * Variable, int32_t x86Reg ); -void RSPOrX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPPopad ( void ); -void RSPPushad ( void ); -void RSPPush ( int32_t x86reg ); -void RSPPop ( int32_t x86reg ); -void RSPPushImm32 ( uint32_t Value ); -void RSPRet ( void ); -void RSPSeta ( int32_t x86reg ); -void RSPSetae ( int32_t x86reg ); -void RSPSetl ( int32_t x86reg ); -void RSPSetb ( int32_t x86reg ); -void RSPSetg ( int32_t x86reg ); -void RSPSetz ( int32_t x86reg ); -void RSPSetnz ( int32_t x86reg ); -void RSPSetlVariable ( void * Variable ); -void RSPSetleVariable ( void * Variable ); -void RSPSetgVariable ( void * Variable ); -void RSPSetgeVariable ( void * Variable ); -void RSPSetbVariable ( void * Variable ); -void RSPSetaVariable ( void * Variable ); -void RSPSetzVariable ( void * Variable ); -void RSPSetnzVariable ( void * Variable ); -void RSPShiftLeftSign ( int32_t x86reg ); -void RSPShiftLeftSignImmed ( int32_t x86reg, uint8_t Immediate ); -void RSPShiftLeftSignVariableImmed ( void *Variable, uint8_t Immediate ); -void RSPShiftRightSignImmed ( int32_t x86reg, uint8_t Immediate ); -void RSPShiftRightSignVariableImmed ( void *Variable, uint8_t Immediate ); -void RSPShiftRightUnsign ( int32_t x86reg ); -void RSPShiftRightUnsignImmed ( int32_t x86reg, uint8_t Immediate ); -void RSPShiftRightUnsignVariableImmed ( void *Variable, uint8_t Immediate ); -void RSPShiftLeftDoubleImmed ( int32_t Destination, int32_t Source, uint8_t Immediate ); -void RSPShiftRightDoubleImmed ( int32_t Destination, int32_t Source, uint8_t Immediate ); -void RSPSubConstFromVariable ( uint32_t Const, void *Variable ); -void RSPSubConstFromX86Reg ( int32_t x86Reg, uint32_t Const ); -void RSPSubVariableFromX86reg ( int32_t x86reg, void * Variable ); -void RSPSubX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPSubX86regFromVariable ( int32_t x86reg, void * Variable ); -void RSPSbbX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPTestConstToVariable ( uint32_t Const, void * Variable ); -void RSPTestConstToX86Reg ( uint32_t Const, int32_t x86reg ); -void RSPTestX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void RSPXorConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void RSPXorX86RegToX86Reg ( int32_t Source, int32_t Destination ); -void RSPXorVariableToX86reg ( void *Variable, int32_t x86reg ); -void RSPXorX86RegToVariable ( void *Variable, int32_t x86reg ); -void RSPXorConstToVariable ( void *Variable, uint32_t Const ); - -#define _MMX_SHUFFLE(a, b, c, d) \ - ((uint8_t)(((a) << 6) | ((b) << 4) | ((c) << 2) | (d))) - -void RSPMmxMoveRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxMoveQwordRegToVariable ( int32_t Dest, void *Variable ); -void RSPMmxMoveQwordVariableToReg ( int32_t Dest, void *Variable ); -void RSPMmxPandRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPandnRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPandVariableToReg ( void * Variable, int32_t Dest ); -void RSPMmxPorRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPorVariableToReg ( void * Variable, int32_t Dest ); -void RSPMmxXorRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxShuffleMemoryToReg ( int32_t Dest, void * Variable, uint8_t Immed ); -void RSPMmxPmullwRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPmullwVariableToReg ( int32_t Dest, void * Variable ); -void RSPMmxPmulhuwRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPmulhwRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPmulhwRegToVariable ( int32_t Dest, void * Variable ); -void RSPMmxPsrlwImmed ( int32_t Dest, uint8_t Immed ); -void RSPMmxPsrawImmed ( int32_t Dest, uint8_t Immed ); -void RSPMmxPsllwImmed ( int32_t Dest, uint8_t Immed ); -void RSPMmxPaddswRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPaddswVariableToReg ( int32_t Dest, void * Variable ); -void RSPMmxPaddwRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxPackSignedDwords ( int32_t Dest, int32_t Source ); -void RSPMmxUnpackLowWord ( int32_t Dest, int32_t Source ); -void RSPMmxUnpackHighWord ( int32_t Dest, int32_t Source ); -void RSPMmxCompareGreaterWordRegToReg ( int32_t Dest, int32_t Source ); -void RSPMmxEmptyMultimediaState ( void ); - -void RSPSseMoveAlignedVariableToReg ( void *Variable, int32_t sseReg ); -void RSPSseMoveAlignedRegToVariable ( int32_t sseReg, void *Variable ); -void RSPSseMoveAlignedN64MemToReg ( int32_t sseReg, int32_t AddrReg ); -void RSPSseMoveAlignedRegToN64Mem ( int32_t sseReg, int32_t AddrReg ); -void RSPSseMoveUnalignedVariableToReg ( void *Variable, int32_t sseReg ); -void RSPSseMoveUnalignedRegToVariable ( int32_t sseReg, void *Variable ); -void RSPSseMoveUnalignedN64MemToReg ( int32_t sseReg, int32_t AddrReg ); -void RSPSseMoveUnalignedRegToN64Mem ( int32_t sseReg, int32_t AddrReg ); -void RSPSseMoveRegToReg ( int32_t Dest, int32_t Source ); -void RSPSseXorRegToReg ( int32_t Dest, int32_t Source ); - -typedef struct { - union { - struct { - unsigned Reg0 : 2; - unsigned Reg1 : 2; - unsigned Reg2 : 2; - unsigned Reg3 : 2; - }; - unsigned UB:8; - }; -} SHUFFLE; - -void RSPSseShuffleReg ( int32_t Dest, int32_t Source, uint8_t Immed ); - -void RSPx86_SetBranch32b(void * JumpByte, void * Destination); -void RSPx86_SetBranch8b(void * JumpByte, void * Destination); \ No newline at end of file diff --git a/src/usf/tlb.c b/src/usf/tlb.c deleted file mode 100644 index ab94197..0000000 --- a/src/usf/tlb.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" - -void SetupTLB_Entry (int32_t Entry); - -FASTTLB FastTlb[64]; -TLB tlb[32]; - -uint32_t AddressDefined ( uintptr_t VAddr) { - uint32_t i; - - if (VAddr >= 0x80000000 && VAddr <= 0xBFFFFFFF) { - return 1; - } - - for (i = 0; i < 64; i++) { - if (FastTlb[i].ValidEntry == 0) { continue; } - if (VAddr >= FastTlb[i].VSTART && VAddr <= FastTlb[i].VEND) { - return 1; - } - } - return 0; -} - -void InitilizeTLB (void) { - uint32_t count; - - for (count = 0; count < 32; count++) { tlb[count].EntryDefined = 0; } - for (count = 0; count < 64; count++) { FastTlb[count].ValidEntry = 0; } - SetupTLB(); -} - -void SetupTLB (void) { - uint32_t count; - - memset(TLB_Map,0,(0xFFFFF * sizeof(uintptr_t))); - for (count = 0x80000000; count < 0xC0000000; count += 0x1000) { - TLB_Map[count >> 12] = ((uintptr_t)N64MEM + (count & 0x1FFFFFFF)) - count; - } - for (count = 0; count < 32; count ++) { SetupTLB_Entry(count); } -} -/* -test=(BYTE *) VirtualAlloc( 0x10, 0x70000, MEM_RESERVE, PAGE_EXECUTE_READWRITE); - if(test == 0) { - printf("FAIL!\n"); - exit(0); - } -*/ - -void SetupTLB_Entry (int Entry) { - uint32_t FastIndx; - - - if (!tlb[Entry].EntryDefined) { return; } - FastIndx = Entry << 1; - FastTlb[FastIndx].VSTART=tlb[Entry].EntryHi.VPN2 << 13; - FastTlb[FastIndx].VEND = FastTlb[FastIndx].VSTART + (tlb[Entry].PageMask.Mask << 12) + 0xFFF; - FastTlb[FastIndx].PHYSSTART = tlb[Entry].EntryLo0.PFN << 12; - FastTlb[FastIndx].VALID = tlb[Entry].EntryLo0.V; - FastTlb[FastIndx].DIRTY = tlb[Entry].EntryLo0.D; - FastTlb[FastIndx].GLOBAL = tlb[Entry].EntryLo0.GLOBAL & tlb[Entry].EntryLo1.GLOBAL; - FastTlb[FastIndx].ValidEntry = 0; - - FastIndx = (Entry << 1) + 1; - FastTlb[FastIndx].VSTART=(tlb[Entry].EntryHi.VPN2 << 13) + ((tlb[Entry].PageMask.Mask << 12) + 0xFFF + 1); - FastTlb[FastIndx].VEND = FastTlb[FastIndx].VSTART + (tlb[Entry].PageMask.Mask << 12) + 0xFFF; - FastTlb[FastIndx].PHYSSTART = tlb[Entry].EntryLo1.PFN << 12; - FastTlb[FastIndx].VALID = tlb[Entry].EntryLo1.V; - FastTlb[FastIndx].DIRTY = tlb[Entry].EntryLo1.D; - FastTlb[FastIndx].GLOBAL = tlb[Entry].EntryLo0.GLOBAL & tlb[Entry].EntryLo1.GLOBAL; - FastTlb[FastIndx].ValidEntry = 0; - - for ( FastIndx = Entry << 1; FastIndx <= (Entry << 1) + 1; FastIndx++) { - uint32_t count; - - if (!FastTlb[FastIndx].VALID) { - FastTlb[FastIndx].ValidEntry = 1; - continue; - } - if (FastTlb[FastIndx].VEND <= FastTlb[FastIndx].VSTART) { - continue; - } - if (FastTlb[FastIndx].VSTART >= 0x80000000 && FastTlb[FastIndx].VEND <= 0xBFFFFFFF) { - continue; - } - if (FastTlb[FastIndx].PHYSSTART > 0x1FFFFFFF) { - continue; - } - - - //exit(0); - //"c:\music\xsf\usf\pdusf\03 - Carrington Institute.miniusf" - //"c:\music\xsf\usf\pdusf\03 - Carrington Institute.miniusf" - - - //test if overlap - FastTlb[FastIndx].ValidEntry = 1; - for (count = FastTlb[FastIndx].VSTART; count < FastTlb[FastIndx].VEND; count += 0x1000) { - TLB_Map[count >> 12] = ((uintptr_t)N64MEM + (count - FastTlb[FastIndx].VSTART + FastTlb[FastIndx].PHYSSTART)) - count; - } - } -} - -void TLB_Probe (void) { - uint32_t Counter; - - - INDEX_REGISTER |= 0x80000000; - for (Counter = 0; Counter < 32; Counter ++) { - uint32_t TlbValue = tlb[Counter].EntryHi.Value & (~tlb[Counter].PageMask.Mask << 13); - uint32_t EntryHi = ENTRYHI_REGISTER & (~tlb[Counter].PageMask.Mask << 13); - - if (TlbValue == EntryHi) { - uint32_t Global = (tlb[Counter].EntryHi.Value & 0x100) != 0; - uint32_t SameAsid = ((tlb[Counter].EntryHi.Value & 0xFF) == (ENTRYHI_REGISTER & 0xFF)); - - if (Global || SameAsid) { - INDEX_REGISTER = Counter; - return; - } - } - } -} - -void TLB_Read (void) { - uint32_t index = INDEX_REGISTER & 0x1F; - - PAGE_MASK_REGISTER = tlb[index].PageMask.Value ; - ENTRYHI_REGISTER = (tlb[index].EntryHi.Value & ~tlb[index].PageMask.Value) ; - ENTRYLO0_REGISTER = tlb[index].EntryLo0.Value; - ENTRYLO1_REGISTER = tlb[index].EntryLo1.Value; -} - -uint32_t TranslateVaddr ( uintptr_t * Addr) { - if (TLB_Map[((*Addr) & 0xffffffff) >> 12] == 0) { return 0; } - *Addr = (uintptr_t)((uint8_t *)(TLB_Map[((*Addr) & 0xffffffff) >> 12] + ((*Addr) & 0xffffffff)) - (uintptr_t)N64MEM); - return 1; -} - -void WriteTLBEntry (int32_t index) { - uint32_t FastIndx; - - FastIndx = index << 1; - if ((PROGRAM_COUNTER >= FastTlb[FastIndx].VSTART && - PROGRAM_COUNTER < FastTlb[FastIndx].VEND && - FastTlb[FastIndx].ValidEntry && FastTlb[FastIndx].VALID) - || - (PROGRAM_COUNTER >= FastTlb[FastIndx + 1].VSTART && - PROGRAM_COUNTER < FastTlb[FastIndx + 1].VEND && - FastTlb[FastIndx + 1].ValidEntry && FastTlb[FastIndx + 1].VALID)) - { - return; - } - - if (tlb[index].EntryDefined) { - uint32_t count; - - for ( FastIndx = index << 1; FastIndx <= (index << 1) + 1; FastIndx++) { - if (!FastTlb[FastIndx].ValidEntry) { continue; } - if (!FastTlb[FastIndx].VALID) { continue; } - for (count = FastTlb[FastIndx].VSTART; count < FastTlb[FastIndx].VEND; count += 0x1000) { - TLB_Map[count >> 12] = 0; - } - } - } - tlb[index].PageMask.Value = PAGE_MASK_REGISTER; - tlb[index].EntryHi.Value = ENTRYHI_REGISTER; - tlb[index].EntryLo0.Value = ENTRYLO0_REGISTER; - tlb[index].EntryLo1.Value = ENTRYLO1_REGISTER; - tlb[index].EntryDefined = 1; - - - SetupTLB_Entry(index); -} diff --git a/src/usf/tlb.h b/src/usf/tlb.h deleted file mode 100644 index 32a2075..0000000 --- a/src/usf/tlb.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#ifndef _TLB_H_ -#define _TLB_H_ - -typedef struct { - uint32_t EntryDefined; - union { - uint32_t Value; - uint8_t A[4]; - - struct { - unsigned zero : 13; - unsigned Mask : 12; - unsigned zero2 : 7; - } ; - - } PageMask; - - union { - uint32_t Value; - uint8_t A[4]; - - struct { - unsigned ASID : 8; - unsigned Zero : 4; - unsigned G : 1; - unsigned VPN2 : 19; - }; - - } EntryHi; - - union { - uint32_t Value; - uint8_t A[4]; - - struct { - unsigned GLOBAL: 1; - unsigned V : 1; - unsigned D : 1; - unsigned C : 3; - unsigned PFN : 20; - unsigned ZERO: 6; - }; - - } EntryLo0; - - union { - uint32_t Value; - uint8_t A[4]; - - struct { - unsigned GLOBAL: 1; - unsigned V : 1; - unsigned D : 1; - unsigned C : 3; - unsigned PFN : 20; - unsigned ZERO: 6; - } ; - - } EntryLo1; -} TLB; - -typedef struct { - uint32_t VSTART; - uint32_t VEND; - uint32_t PHYSSTART; - uint32_t VALID; - uint32_t DIRTY; - uint32_t GLOBAL; - uint32_t ValidEntry; -} FASTTLB; - -extern FASTTLB FastTlb[64]; -extern TLB tlb[32]; - -uint32_t AddressDefined ( uintptr_t VAddr); -void InitilizeTLB ( void ); -void SetupTLB ( void ); -void TLB_Probe ( void ); -void TLB_Read ( void ); -uint32_t TranslateVaddr ( uintptr_t * Addr); -void WriteTLBEntry ( int32_t index ); - -#endif diff --git a/src/usf/types.h b/src/usf/types.h deleted file mode 100644 index c56d3ff..0000000 --- a/src/usf/types.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ -#ifndef __Types_h -#define __Types_h - -#ifdef __LP64__ -#define USEX64 -#define EXTREGS -#endif - -#include -typedef uint64_t QWORD; - -typedef union tagVect { - double FD[2]; - int64_t DW[2]; - uint64_t UDW[2]; - int32_t W[4]; - float FS[4]; - uint32_t UW[4]; - int16_t HW[8]; - uint16_t UHW[8]; - int8_t B[16]; - uint8_t UB[16]; -} VECTOR; - -typedef union tagUWORD { - int32_t W; - uint32_t UW; - int16_t HW[2]; - uint16_t UHW[2]; - int8_t B[4]; - uint8_t UB[4]; - float F; -} MIPS_WORD; - -typedef union tagUDWORD { - double D; - int64_t DW; - uint64_t UDW; - int32_t W[2]; - uint32_t UW[2]; - int16_t HW[4]; - uint16_t UHW[4]; - int8_t B[8]; - uint8_t UB[8]; - float F[2]; -} MIPS_DWORD; - -typedef MIPS_WORD MIPSUWORD; -typedef MIPS_DWORD MIPSUDWORD; - - -#endif diff --git a/src/usf/usf.c b/src/usf/usf.c deleted file mode 100644 index 05b19d5..0000000 --- a/src/usf/usf.c +++ /dev/null @@ -1,522 +0,0 @@ - -#include -#include "usf.h" -#include "cpu.h" -#include "memory.h" -#include "audio.h" -#include "psftag.h" - -#include -#include - -#include - -#include -#include -#include -#include - -#include "types.h" - -extern int SampleRate; - -extern InputPlugin usf_ip; -InputPlayback * pcontext = 0; - -void usf_mseek(InputPlayback * context, gulong millisecond); -int8_t filename[512]; -uint32_t cpu_running = 0, use_interpreter = 0, use_audiohle = 0, is_paused = 0, cpu_stopped = 1, fake_seek_stopping = 0; -uint32_t is_fading = 0, fade_type = 1, fade_time = 5000, is_seeking = 0, seek_backwards = 0, track_time = 180000; -double seek_time = 0.0, play_time = 0.0, rel_volume = 1.0; - -uint32_t enablecompare = 0, enableFIFOfull = 0; - -uint32_t usf_length = 0, usf_fade_length = 0; - -int8_t title[100]; -uint8_t title_format[] = "%game% - %title%"; - -extern int32_t RSP_Cpu; - -uint32_t get_length_from_string(uint8_t * str_length) { - uint32_t ttime = 0, temp = 0, mult = 1, level = 1; - char Source[1024]; - uint8_t * src = Source + strlen(str_length); - strcpy(&Source[1], str_length); - Source[0] = 0; - - while(*src) { - if((*src >= '0') && (*src <= '9')) { - temp += ((*src - '0') * mult); - mult *= 10; - } else { - mult = 1; - if(*src == '.') { - ttime = temp; - temp = 0; - } else if(*src == ':') { - ttime += (temp * (1000 * level)); - temp = 0; - level *= 60; - } - } - src--; - } - - ttime += (temp * (1000 * level)); - return ttime; -} - -int LoadUSF(const gchar * fn) -{ - VFSFile * fil = NULL; - uint32_t reservedsize = 0, codesize = 0, crc = 0, tagstart = 0, reservestart = 0; - uint32_t filesize = 0, tagsize = 0, temp = 0; - uint8_t buffer[16], * buffer2 = NULL, * tagbuffer = NULL; - - is_fading = 0; - fade_type = 1; - fade_time = 5000; - track_time = 180000; - play_time = 0; - is_seeking = 0; - seek_backwards = 0; - seek_time = 0; - - fil = vfs_fopen(fn, "rb"); - - if(!fil) { - printf("Could not open USF!\n"); - return 0; - } - - vfs_fread(buffer,4 ,1 ,fil); - if(buffer[0] != 'P' && buffer[1] != 'S' && buffer[2] != 'F' && buffer[3] != 0x21) { - printf("Invalid header in file!\n"); - vfs_fclose(fil); - return 0; - } - - vfs_fread(&reservedsize, 4, 1, fil); - vfs_fread(&codesize, 4, 1, fil); - vfs_fread(&crc, 4, 1, fil); - - vfs_fseek(fil, 0, SEEK_END); - filesize = vfs_ftell(fil); - - reservestart = 0x10; - tagstart = reservestart + reservedsize; - tagsize = filesize - tagstart; - - if(tagsize) { - vfs_fseek(fil, tagstart, SEEK_SET); - vfs_fread(buffer, 5, 1, fil); - - if(buffer[0] != '[' && buffer[1] != 'T' && buffer[2] != 'A' && buffer[3] != 'G' && buffer[4] != ']') { - printf("Erroneous data in tag area! %" PRIu32 "\n", tagsize); - vfs_fclose(fil); - return 0; - } - - buffer2 = malloc(50001); - tagbuffer = malloc(tagsize); - - vfs_fread(tagbuffer, tagsize, 1, fil); - - psftag_raw_getvar(tagbuffer,"_lib",buffer2,50000); - - if(strlen(buffer2)) { - char path[512]; - int pathlength = 0; - - if(strrchr(fn, '/')) //linux - pathlength = strrchr(fn, '/') - fn + 1; - else if(strrchr(fn, '\\')) //windows - pathlength = strrchr(fn, '\\') - fn + 1; - else //no path - pathlength = strlen(fn); - - strncpy(path, fn, pathlength); - path[pathlength] = 0; - strcat(path, buffer2); - - LoadUSF(path); - } - - psftag_raw_getvar(tagbuffer,"_enablecompare",buffer2,50000); - if(strlen(buffer2)) - enablecompare = 1; - else - enablecompare = 0; - - psftag_raw_getvar(tagbuffer,"_enableFIFOfull",buffer2,50000); - if(strlen(buffer2)) - enableFIFOfull = 1; - else - enableFIFOfull = 0; - - psftag_raw_getvar(tagbuffer, "length", buffer2, 50000); - if(strlen(buffer2)) { - track_time = get_length_from_string(buffer2); - } - - psftag_raw_getvar(tagbuffer, "fade", buffer2, 50000); - if(strlen(buffer2)) { - fade_time = get_length_from_string(buffer2); - } - - psftag_raw_getvar(tagbuffer, "title", buffer2, 50000); - if(strlen(buffer2)) - strcpy(title, buffer2); - else - { - int pathlength = 0; - - if(strrchr(fn, '/')) //linux - pathlength = strrchr(fn, '/') - fn + 1; - else if(strrchr(fn, '\\')) //windows - pathlength = strrchr(fn, '\\') - fn + 1; - else //no path - pathlength = 7; - - strcpy(title, &fn[pathlength]); - - } - - free(buffer2); - buffer2 = NULL; - - free(tagbuffer); - tagbuffer = NULL; - - } - - vfs_fseek(fil, reservestart, SEEK_SET); - vfs_fread(&temp, 4, 1, fil); - - if(temp == 0x34365253) { //there is a rom section - int len = 0, start = 0; - vfs_fread(&len, 4, 1, fil); - - while(len) { - vfs_fread(&start, 4, 1, fil); - - while(len) { - int page = start >> 16; - int readLen = ( ((start + len) >> 16) > page) ? (((page + 1) << 16) - start) : len; - - if(ROMPages[page] == 0) { - ROMPages[page] = malloc(0x10000); - memset(ROMPages[page], 0, 0x10000); - } - - vfs_fread(ROMPages[page] + (start & 0xffff), readLen, 1, fil); - - start += readLen; - len -= readLen; - } - - vfs_fread(&len, 4, 1, fil); - } - - } - - - - vfs_fread(&temp, 4, 1, fil); - if(temp == 0x34365253) { - int len = 0, start = 0; - vfs_fread(&len, 4, 1, fil); - - while(len) { - vfs_fread(&start, 4, 1, fil); - - vfs_fread(savestatespace + start, len, 1, fil); - - vfs_fread(&len, 4, 1, fil); - } - } - - // Detect the Ramsize before the memory allocation - - if(*(uint32_t*)(savestatespace + 4) == 0x400000) { - RdramSize = 0x400000; - savestatespace = realloc(savestatespace, 0x40275c); - } else if(*(uint32_t*)(savestatespace + 4) == 0x800000) - RdramSize = 0x800000; - - vfs_fclose(fil); - - return 1; -} - - -void usf_init() -{ - use_audiohle = 0; - use_interpreter = 0; - RSP_Cpu = 0; // 0 is recompiler, 1 is interpreter -} - -void usf_destroy() -{ - -} - -void usf_seek(InputPlayback * context, gint time) -{ - usf_mseek(context, time * 1000); -} - - -void usf_mseek(InputPlayback * context, gulong millisecond) -{ - if(millisecond < play_time) { - is_paused = 0; - - fake_seek_stopping = 1; - CloseCpu(); - - while(!cpu_stopped) - usleep(1); - - is_seeking = 1; - seek_time = (double)millisecond; - - fake_seek_stopping = 2; - } else { - is_seeking = 1; - seek_time = (double)millisecond; - } - - context->output->flush(millisecond/1000); -} - -void usf_play(InputPlayback * context) -{ - if(!context->filename) - return; - - // Defaults (which would be overriden by Tags / playing - savestatespace = NULL; - cpu_running = is_paused = fake_seek_stopping = 0; - cpu_stopped = 1; - is_fading = 0; - fade_type = 1; - fade_time = 5000; - is_seeking = 0; - seek_backwards = 0; - track_time = 180000; - seek_time = 0.0; - play_time = 0.0; - rel_volume = 1.0; - - - pcontext = context; - - // Allocate main memory after usf loads (to determine ram size) - - PreAllocate_Memory(); - - if(!LoadUSF(context->filename)) { - Release_Memory(); - return; - } - - context->set_pb_ready(context); - - Allocate_Memory(); - - context->playing = TRUE; - while(context->playing) { - is_fading = 0; - play_time = 0; - - StartEmulationFromSave(savestatespace); - if(!fake_seek_stopping) break; - while(fake_seek_stopping != 2) - usleep(1); - fake_seek_stopping = 4; - } - - Release_Memory(); - context->playing = FALSE; - context->eof = TRUE; - - context->output->close_audio(); -} - -void usf_stop(InputPlayback *context) -{ - while (cpu_running == 1) - { - cpu_running = 0; - CloseCpu(); - } - - context->playing = FALSE; - is_paused = 0; - context->eof = FALSE; -} - -void usf_pause(InputPlayback *context, gshort paused) -{ - is_paused = paused;//is_paused?0:1; -} - -static const gchar *usf_exts [] = -{ - "usf", - "miniusf", - NULL -}; - - -Tuple * usf_get_song_tuple(const gchar * fn) -{ - Tuple * tuple = NULL; - - VFSFile * fil = NULL; - uint32_t reservedsize = 0, codesize = 0, crc = 0, tagstart = 0, reservestart = 0, filesize = 0, tagsize = 0; - uint8_t buffer[16], * buffer2 = NULL, * tagbuffer = NULL; - - fil = vfs_fopen(fn, "rb"); - - if(!fil) { - printf("Could not open USF!\n"); - return NULL; - } - - vfs_fread(buffer,4 ,1 ,fil); - - if(buffer[0] != 'P' && buffer[1] != 'S' && buffer[2] != 'F' && buffer[3] != 0x21) { - printf("Invalid header in file!\n"); - vfs_fclose(fil); - return NULL; - } - - vfs_fread(&reservedsize, 4, 1, fil); - vfs_fread(&codesize, 4, 1, fil); - vfs_fread(&crc, 4, 1, fil); - - vfs_fseek(fil, 0, SEEK_END); - filesize = vfs_ftell(fil); - - reservestart = 0x10; - tagstart = reservestart + reservedsize; - tagsize = filesize - tagstart; - - tuple = tuple_new_from_filename(fn); - - if(tagsize) { - int temp_fade = 0; - vfs_fseek(fil, tagstart, SEEK_SET); - vfs_fread(buffer, 5, 1, fil); - - if(buffer[0] != '[' && buffer[1] != 'T' && buffer[2] != 'A' && buffer[3] != 'G' && buffer[4] != ']') { - printf("Erroneous data in tag area! %" PRIu32 "\n", tagsize); - vfs_fclose(fil); - return NULL; - } - - buffer2 = malloc(50001); - tagbuffer = malloc(tagsize); - - vfs_fread(tagbuffer, tagsize, 1, fil); - - psftag_raw_getvar(tagbuffer, "fade", buffer2, 50000); - if(strlen(buffer2)) - temp_fade = get_length_from_string(buffer2); - - psftag_raw_getvar(tagbuffer, "length", buffer2, 50000); - if(strlen(buffer2)) - tuple_associate_int(tuple, FIELD_LENGTH, NULL, get_length_from_string(buffer2) + temp_fade); - else - tuple_associate_int(tuple, FIELD_LENGTH, NULL, (180*1000)); - - psftag_raw_getvar(tagbuffer, "title", buffer2, 50000); - if(strlen(buffer2)) - tuple_associate_string(tuple, FIELD_TITLE, NULL, buffer2); - else - { - char title[512]; - int pathlength = 0; - - if(strrchr(fn, '/')) //linux - pathlength = strrchr(fn, '/') - fn + 1; - else if(strrchr(fn, '\\')) //windows - pathlength = strrchr(fn, '\\') - fn + 1; - else //no path - pathlength = 7; - - strcpy(title, &fn[pathlength]); - - tuple_associate_string(tuple, FIELD_TITLE, NULL, title); - - } - - psftag_raw_getvar(tagbuffer, "artist", buffer2, 50000); - if(strlen(buffer2)) - tuple_associate_string(tuple, FIELD_ARTIST, NULL, buffer2); - - psftag_raw_getvar(tagbuffer, "game", buffer2, 50000); - if(strlen(buffer2)) { - tuple_associate_string(tuple, FIELD_ALBUM, NULL, buffer2); - tuple_associate_string(tuple, -1, "game", buffer2); - } - - psftag_raw_getvar(tagbuffer, "copyright", buffer2, 50000); - if(strlen(buffer2)) - tuple_associate_string(tuple, FIELD_COPYRIGHT, NULL, buffer2); - - // This for unknown reasons turns the "Kbps" in the UI to "channels" - //tuple_associate_string(tuple, FIELD_QUALITY, NULL, "sequenced"); - - tuple_associate_string(tuple, FIELD_CODEC, NULL, "Nintendo 64 Audio"); - tuple_associate_string(tuple, -1, "console", "Nintendo 64"); - - free(tagbuffer); - free(buffer2); - } - else - { - char title[512]; - int pathlength = 0; - - if(strrchr(fn, '/')) //linux - pathlength = strrchr(fn, '/') - fn + 1; - else if(strrchr(fn, '\\')) //windows - pathlength = strrchr(fn, '\\') - fn + 1; - else //no path - pathlength = 7; - - strcpy(title, &fn[pathlength]); - - - tuple_associate_int(tuple, FIELD_LENGTH, NULL, (180 * 1000)); - tuple_associate_string(tuple, FIELD_TITLE, NULL, title); - } - - vfs_fclose(fil); - - return tuple; -} - -InputPlugin usf_ip = { - .description = "USF Plugin", - .init = usf_init, - .play_file = usf_play, - .stop = usf_stop, - .pause = usf_pause, - .seek = usf_seek, - .mseek = usf_mseek, - .vfs_extensions = (gchar **)usf_exts, - .get_song_tuple = usf_get_song_tuple, -}; - - - -static InputPlugin *usf_iplist[] = { &usf_ip, NULL }; - -DECLARE_PLUGIN(usf_iplist, NULL, NULL, usf_iplist, NULL, NULL, NULL, NULL, NULL); - diff --git a/src/usf/usf.h b/src/usf/usf.h deleted file mode 100644 index f3853b7..0000000 --- a/src/usf/usf.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _USF_H_ -#define _USF_H_ -#define _CRT_SECURE_NO_WARNINGS - - -#include -#include -#include -#include -#include - - - -#include "usf.h" -#include "cpu.h" -#include "memory.h" - -extern int8_t filename[512], title[100]; -extern uint32_t cpu_running, use_interpreter, use_audiohle, is_paused, cpu_stopped, fake_seek_stopping; -extern uint32_t is_fading, fade_type, fade_time, is_seeking, seek_backwards, track_time; -extern double seek_time, play_time, rel_volume; - -extern uint32_t enablecompare, enableFIFOfull; - - -#endif - diff --git a/src/usf/x86.c b/src/usf/x86.c deleted file mode 100644 index 038ab35..0000000 --- a/src/usf/x86.c +++ /dev/null @@ -1,810 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" -#include "x86.h" -#include "types.h" - -uint8_t Index[9] = {0,0,0x40,0,0x80,0,0,0,0xC0}; - - -void AdcX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x11,x86reg,Variable); -} - -void AdcConstToVariable(void *Variable, uint8_t Constant) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D2,Variable); - PUTDST8(RecompPos,Constant); -} - -void AdcConstToX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D2,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D2,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void AdcVariableToX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x13 ,x86reg,Variable); -} - -void AdcX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x13,Destination,Source); -} - -void AddConstToVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D0,Variable); - PUTDST32(RecompPos,Const); -} - -void AddConstToX86Reg64 (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D0,x86reg | x64_Reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D0,x86reg | x64_Reg); - PUTDST8(RecompPos, Const); - } -} - -void AddConstToX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D0,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D0,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void AddVariableToX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x3,x86reg,Variable); -} - -void AddX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x1,x86reg,Variable); -} - -void AddX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x3,Destination,Source); -} - -void AndConstToVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D4,Variable); - PUTDST32(RecompPos,Const); -} - -void AndConstToX86Reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D4,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D4,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void AndVariableDispToX86Reg(void *Variable, int32_t x86reg, int32_t AddrReg, int32_t Multiplier) { -#ifdef USEX64 - if(((uintptr_t)Variable - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_SCALE_IMM32(8,0x23,x86reg,x86_R15,AddrReg,Index[Multiplier], (uintptr_t)Variable - (uintptr_t)TLB_Map); - } else { - LOAD_VARIABLE(x86_TEMP, Variable); - OPCODE_REG_BASE_INDEX_SCALE(8,0x23,x86reg,x86_TEMP,AddrReg,Index[Multiplier]); - } -#else - OPCODE_REG_INDEX_SCALE_IMM32(8,0x23,x86reg,AddrReg,Index[Multiplier],Variable); -#endif -} - -void AndVariableToX86Reg(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x23,x86reg,Variable); -} - -void AndX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x21,Source,Destination); -} - -void BreakPoint (void) { - PUTDST8(RecompPos,0xCC); -} - -void Call_Direct(void * FunctAddress) { - uintptr_t disp; -#ifdef USEX64 - disp = (uintptr_t)FunctAddress-(uintptr_t)RecompPos - 5; - SubConstFromX86Reg(x86_RSP, 0x28); - if(disp <= 0x7fffffff) { - PUTDST8(RecompPos,0xE8); - PUTDST32(RecompPos,disp); - } else { - LOAD_VARIABLE(x86_TEMP, FunctAddress); - OPCODE_REG_REG(8,0xff,OP_D2,x86_TEMP); - - } - AddConstToX86Reg(x86_RSP, 0x28); -#else - //BreakPoint(); - disp = (uintptr_t)FunctAddress-(uintptr_t)RecompPos - 5; - PUTDST8(RecompPos,0xE8); - PUTDST32(RecompPos,disp); -#endif -} - -void CompConstToVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D7,Variable); - PUTDST32(RecompPos,Const); -} - -void CompConstToX86reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D7,x86reg); - PUTDST32(RecompPos,Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D7,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void CompX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x3B,x86reg,Variable); -} - -void CompX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x3B,Destination,Source); -} - -void DecX86reg(x86reg) { - OPCODE_REG_REG(8,0xFF,OP_D1,x86reg); -} - -void DivX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D6,x86reg); -} - -void idivX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D7,x86reg); -} - -void imulX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D5,x86reg); -} - -void IncX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xFF,OP_D0,x86reg); -} - -void JaeLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x73); - PUTDST8(RecompPos,Value); -} - -void JaeLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x830F); - PUTDST32(RecompPos,Value); -} - -void JaLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x77); - PUTDST8(RecompPos,Value); -} - -void JaLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x870F); - PUTDST32(RecompPos,Value); -} - -void JbLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x72); - PUTDST8(RecompPos,Value); -} - -void JbLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x820F); - PUTDST32(RecompPos,Value); -} - -void JecxzLabel8( uint8_t Value) { - PUTDST8(RecompPos,0xE3); - PUTDST8(RecompPos,Value); -} - -void JeLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x74); - PUTDST8(RecompPos,Value); -} - -void JeLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x840F); - PUTDST32(RecompPos,Value); -} - -void JgeLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x8D0F); - PUTDST32(RecompPos,Value); -} - -void JgLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x7F); - PUTDST8(RecompPos,Value); -} - -void JgLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x8F0F); - PUTDST32(RecompPos,Value); -} - -void JleLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x7E); - PUTDST8(RecompPos,Value); -} - -void JleLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x8E0F); - PUTDST32(RecompPos,Value); -} - -void JlLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x7C); - PUTDST8(RecompPos,Value); -} - -void JlLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x8C0F); - PUTDST32(RecompPos,Value); -} - -void JzLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x74); - PUTDST8(RecompPos,Value); -} - -void JnzLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x75); - PUTDST8(RecompPos,Value); -} - - -void JmpDirectReg( int32_t x86reg ) { - OPCODE_REG_REG(8,0xff,OP_D4,x86reg); -} - -void JmpLabel8( uint8_t Value) { - PUTDST8(RecompPos,0xEB); - PUTDST8(RecompPos,Value); -} - -void JmpLabel32( uint32_t Value) { - PUTDST8(RecompPos,0xE9); - PUTDST32(RecompPos,Value); -} - -void JneLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x75); - PUTDST8(RecompPos,Value); -} - -void JneLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x850F); - PUTDST32(RecompPos,Value); -} - -void JnsLabel8( uint8_t Value) { - PUTDST8(RecompPos,0x79); - PUTDST8(RecompPos,Value); -} - -void JnsLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x890F); - PUTDST32(RecompPos,Value); -} - -void JsLabel32(uint32_t Value) { - PUTDST16(RecompPos,0x880F); - PUTDST32(RecompPos,Value); -} - -void LeaRegReg(int32_t x86RegDest, int32_t x86RegSrc, int32_t multiplier) { - OPCODE_REG_BASE_INDEX_SCALE(8,0x8D,x86RegDest,x86_EBP,x86RegSrc,Index[multiplier]); - PUTDST32(RecompPos,0x00000000); -} - -void LeaSourceAndOffset(int32_t x86DestReg, int32_t x86SourceReg, int32_t offset) { - OPCODE_REG_MREG_IMM32(8,0x8D,x86DestReg,x86SourceReg,offset); -} - -void MoveConstByteToVariable (uint8_t Const,void *Variable) { - OPCODE_REG_VARIABLE(,8,0xC6,OP_D0,Variable); - PUTDST8(RecompPos,Const); -} - -void MoveConstHalfToVariable (uint16_t Const,void *Variable) { - OPCODE_REG_VARIABLE(PUTDST8(RecompPos,0x66),8,0xC7,OP_D0,Variable); - PUTDST16(RecompPos,Const); -} - -void MoveConstHalfToX86regPointer(uint16_t Const, int32_t AddrReg1, int32_t AddrReg2) { - PUTDST8(RecompPos,0x66); - OPCODE_REG_BASE_INDEX(8,0xC7,OP_D0,AddrReg1,AddrReg2); - PUTDST16(RecompPos,Const); -} - -void MoveConstToVariable (uint32_t Const,void *Variable) { - OPCODE_REG_VARIABLE(,8,0xC7,OP_D0,Variable); - PUTDST32(RecompPos,Const); -} - -void MoveConstToX86Pointer(uint32_t Const, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0xC7,OP_D0,X86Pointer); - PUTDST32(RecompPos,Const); -} - - -void MoveConstToX86reg(uint32_t Const, int32_t x86reg) { - OPCODE_REG_REG(8,0xC7,OP_D0,x86reg); - PUTDST32(RecompPos,Const); -} - -void MoveConstQwordToX86reg(uint64_t Const, int32_t x86reg) { - PUTDST8(RecompPos, 0x48 | ((x86reg&0x20)>>5)); - PUTDST8(RecompPos, 0xB8 | ((x86reg-1)&0x7)); - PUTDST64(RecompPos,Const); -} - -void MoveConstByteToX86regPointer(uint8_t Const, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0xC6,OP_D0,AddrReg1,AddrReg2) - PUTDST8(RecompPos,Const); -} - -void MoveConstToX86regPointer(uint32_t Const, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0xC7,OP_D0,AddrReg1,AddrReg2); - PUTDST32(RecompPos,Const); -} - -void MoveSxByteX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xBE0F,x86reg,AddrReg1,AddrReg2); -} - -void MoveSxHalfX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xBF0F,x86reg,AddrReg1,AddrReg2); -} - -void MoveSxVariableToX86regByte(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xBE0F,x86reg,Variable); -} - -void MoveSxVariableToX86regHalf(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xBF0F,x86reg,Variable); -} - -void MoveVariableToX86reg(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x8B,x86reg,Variable); -} - -void MovePointerToX86reg(void *Variable, int32_t x86reg) { -#ifdef USEX64 - OPCODE_REG_VARIABLE(,8,0x8B,x86reg|x64_Reg,Variable); -#else - OPCODE_REG_VARIABLE(,8,0x8B,x86reg,Variable); -#endif -} - -void MoveX86RegDispToX86Reg(int32_t x86reg, int32_t AddrReg, int32_t IndexReg, int32_t Multiplier) { - OPCODE_REG_BASE_INDEX_SCALE(8,0x8B,x86reg,AddrReg,IndexReg,Index[Multiplier]); -} - -void MoveVariableDispToX86Reg(void *Variable, int32_t x86reg, int32_t AddrReg, int32_t Multiplier) { -#ifdef USEX64 - if(((uintptr_t)Variable - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { - OPCODE_REG_BASE_INDEX_SCALE_IMM32(8,0x8B,x86reg,x86_R15,AddrReg,Index[Multiplier],((uintptr_t)Variable - (uintptr_t)TLB_Map)); - } else { - LOAD_VARIABLE(x86_TEMP, Variable); - OPCODE_REG_BASE_INDEX_SCALE(8,0x8B,x86reg,x86_TEMP,AddrReg,Index[Multiplier]); - } -#else - OPCODE_REG_INDEX_SCALE_IMM32(8,0x8B,x86reg,AddrReg,Index[Multiplier],Variable); -#endif -} - -void MoveVariableToX86regByte(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x8A,x86reg,Variable); -} - -void MoveVariableToX86regHalf(void *Variable, int32_t x86reg) { - BreakPoint(); - OPCODE_REG_VARIABLE(PUTDST8(RecompPos,0x66),8,0x8B,x86reg,Variable); -} - -void MoveX86regByteToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x88,x86reg,Variable); -} - -void MoveX86regByteToX86regPointer(int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0x88,x86reg,AddrReg1,AddrReg2); -} - -void MoveX86regHalfToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(PUTDST8(RecompPos,0x66), 8,0x89,x86reg,Variable); -} - -void MoveX86regHalfToX86regPointer(int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2) { - PUTDST8(RecompPos,0x66); - OPCODE_REG_BASE_INDEX(8,0x89,x86reg,AddrReg1,AddrReg2); -} - -void MoveX86PointerToX86reg(int32_t x86reg, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0x8B,x86reg,X86Pointer); -} - -void MoveX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(8,0x8B,x86reg,AddrReg1,AddrReg2); -} - -void MoveX86regPointerToX86regDisp8(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg, uint8_t offset) { - OPCODE_REG_BASE_INDEX_IMM8(8,0x8B,x86reg,AddrReg1,AddrReg2,offset); -} - -void MoveX86regToMemory(int32_t x86reg, int32_t AddrReg, uint32_t Disp) { - OPCODE_REG_MREG_IMM32(8,0x89,x86reg,AddrReg,Disp); -} - -void MoveX86regToVariable(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x89,x86reg,Variable); -} - -void MoveX86RegToX86Reg(int32_t Source, int32_t Destination) { - OPCODE_REG_REG(8,0x89,Source|X64_Reg, Destination|X64_Reg); -} - -void MoveX86regToX86Pointer(int32_t x86reg, int32_t X86Pointer) { - OPCODE_REG_MREG(8,0x89,x86reg, X86Pointer); -} - -void MoveX86regToX86regPointer(int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2) { - OPCODE_REG_BASE_INDEX(8,0x89,x86reg,AddrReg1,AddrReg2); -} - -void MoveZxByteX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xB60F,x86reg,AddrReg1,AddrReg2); -} - -void MoveZxHalfX86regPointerToX86reg(int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg) { - OPCODE_REG_BASE_INDEX(16,0xB70F,x86reg,AddrReg1,AddrReg2); -} - -void MoveZxVariableToX86regByte(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xB60F,x86reg,Variable); -} - -void MoveZxVariableToX86regHalf(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,16,0xB70F,x86reg,Variable); -} - -void MulX86reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D4,x86reg); -} - -void NotX86Reg(int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D2,x86reg); -} - -void OrConstToVariable(uint32_t Const, void * Variable) { - if(Const < 0x80) { - OPCODE_REG_VARIABLE(,8,0x83,OP_D1,Variable); - PUTDST8(RecompPos,Const); - } else { - OPCODE_REG_VARIABLE(,8,0x81,OP_D1,Variable); - PUTDST32(RecompPos,Const); - } -} - -void OrConstToX86Reg(uint32_t Const, int32_t x86reg) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D1,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D1,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void OrVariableToX86Reg(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0xb,x86reg,Variable); -} - -void OrX86RegToVariable(void * Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x9,x86reg,Variable); -} - -void OrX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x0B,Destination,Source); -} - -void Pushfd() { - PUTDST8(RecompPos,0x9c); -} - -void Popfd() { - PUTDST8(RecompPos,0x9d); -} - -void Popad(void) { -#ifdef USEX64 - PUTDST16(RecompPos,0x5f41); - PUTDST16(RecompPos,0x5e41); - PUTDST16(RecompPos,0x5d41); - PUTDST16(RecompPos,0x5c41); - PUTDST16(RecompPos,0x5b41); - PUTDST16(RecompPos,0x5a41); - PUTDST16(RecompPos,0x5941); - PUTDST16(RecompPos,0x5841); - PUTDST8(RecompPos,0x5f); - PUTDST8(RecompPos,0x5e); - PUTDST8(RecompPos,0x5b); - PUTDST8(RecompPos,0x5a); - PUTDST8(RecompPos,0x59); - PUTDST8(RecompPos,0x58); -#else - PUTDST8(RecompPos,0x61); -#endif - -} - -void Pushad(void) { -#ifdef USEX64 - PUTDST8(RecompPos,0x50); - PUTDST8(RecompPos,0x51); - PUTDST8(RecompPos,0x52); - PUTDST8(RecompPos,0x53); - PUTDST8(RecompPos,0x56); - PUTDST8(RecompPos,0x57); - PUTDST16(RecompPos,0x5041); - PUTDST16(RecompPos,0x5141); - PUTDST16(RecompPos,0x5241); - PUTDST16(RecompPos,0x5341); - PUTDST16(RecompPos,0x5441); - PUTDST16(RecompPos,0x5541); - PUTDST16(RecompPos,0x5641); - PUTDST16(RecompPos,0x5741); -#else - PUTDST8(RecompPos,0x60); -#endif -} - -void Push(int32_t x86reg) { -#ifdef USEX64 - PUTDST8(RecompPos, 0x40 | ((x86reg & 0x20) >> 5)); -#endif - switch(x86reg&0xf) { - case x86_EAX: PUTDST8(RecompPos, 0x50); break; - case x86_EBX: PUTDST8(RecompPos, 0x53); break; - case x86_ECX: PUTDST8(RecompPos, 0x51); break; - case x86_EDX: PUTDST8(RecompPos, 0x52); break; - case x86_ESI: PUTDST8(RecompPos, 0x56); break; - case x86_EDI: PUTDST8(RecompPos, 0x57); break; - case x86_ESP: PUTDST8(RecompPos, 0x54); break; - case x86_EBP: PUTDST8(RecompPos, 0x55); break; - } -} - -void Pop(int32_t x86reg) { -#ifdef USEX64 - PUTDST8(RecompPos, 0x40 | ((x86reg & 0x20) >> 5)); -#endif - switch(x86reg&0xf) { - - case x86_EAX: PUTDST8(RecompPos, 0x58); break; - case x86_EBX: PUTDST8(RecompPos, 0x5B); break; - case x86_ECX: PUTDST8(RecompPos, 0x59); break; - case x86_EDX: PUTDST8(RecompPos, 0x5A); break; - case x86_ESI: PUTDST8(RecompPos, 0x5E); break; - case x86_EDI: PUTDST8(RecompPos, 0x5F); break; - case x86_ESP: PUTDST8(RecompPos, 0x5C); break; - case x86_EBP: PUTDST8(RecompPos, 0x5D); break; - } -} - -void PushImm32(uint32_t Value) { - PUTDST8(RecompPos,0x68); - PUTDST32(RecompPos,Value); -} - -void Ret(void) { - PUTDST8(RecompPos,0xC3); -} - -void Seta(int32_t x86reg) { - OPCODE_REG_REG(16,0x970F,OP_D0,x86reg); -} - -void SetaVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x970F,OP_D0,Variable); -} - -void Setae(int32_t x86reg) { - OPCODE_REG_REG(16,0x930F,OP_D0,x86reg); -} - -void Setb(int32_t x86reg) { - OPCODE_REG_REG(16,0x920F,OP_D0,x86reg); -} - -void SetbVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x920F,OP_D0,Variable); -} - -void Setg(int32_t x86reg) { - OPCODE_REG_REG(16,0x9F0F,OP_D0,x86reg); -} - -void SetgVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x9F0F,OP_D0,Variable); -} - -void Setl(int32_t x86reg) { - OPCODE_REG_REG(16,0x9C0F,OP_D0,x86reg); -} - -void SetlVariable(void * Variable) { - OPCODE_REG_VARIABLE(,16,0x9C0F,OP_D0,Variable); -} - - -void Setz(int32_t x86reg) { - OPCODE_REG_REG(16,0x940F,OP_D0,x86reg); -} - -void Setnz(int32_t x86reg) { - OPCODE_REG_REG(16,0x950F,OP_D0,x86reg); -} - -void ShiftLeftDouble(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(16,0xA50F,Source,Destination); -} - -void ShiftLeftDoubleImmed(int32_t Destination, int32_t Source, uint8_t Immediate) { - OPCODE_REG_REG(16,0xA40F,Source,Destination); - PUTDST8(RecompPos,Immediate); -} - -void ShiftLeftSign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D4,x86reg); -} - -void ShiftLeftSignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D4,x86reg); - PUTDST8(RecompPos,Immediate); -} - -void ShiftRightSign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D7,x86reg); -} - -void ShiftRightSignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D7,x86reg); - PUTDST8(RecompPos,Immediate); -} - -void ShiftRightUnsign(int32_t x86reg) { - OPCODE_REG_REG(8,0xD3,OP_D5,x86reg); -} - -void ShiftRightDouble(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(16,0xAD0F,Source,Destination); -} - -void ShiftRightDoubleImmed(int32_t Destination, int32_t Source, uint8_t Immediate) { - OPCODE_REG_REG(16,0xAC0F,Source,Destination); - PUTDST8(RecompPos,Immediate); -} - -void ShiftRightUnsignImmed(int32_t x86reg, uint8_t Immediate) { - OPCODE_REG_REG(8,0xC1,OP_D5,x86reg); - PUTDST8(RecompPos,Immediate); -} - -void SbbConstFromX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D3,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D3,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void SbbVariableFromX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x1b,x86reg,Variable); -} - -void SbbX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x1B,Destination,Source); -} - -void SubConstFromVariable (uint32_t Const, void *Variable) { - OPCODE_REG_VARIABLE(,8,0x81,OP_D5,Variable); - PUTDST32(RecompPos,Const); -} - -void SubConstFromX86Reg (int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D5,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D5,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void SubVariableFromX86reg(int32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x2B,x86reg,Variable); -} - -void SubX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x2B,Destination,Source); -} - -void TestConstToX86Reg(uint32_t Const, int32_t x86reg) { - OPCODE_REG_REG(8,0xF7,OP_D0,x86reg); - PUTDST32(RecompPos,Const); -} - -void TestVariable(uint32_t Const, void * Variable) { - OPCODE_REG_VARIABLE(,8,0xf7,OP_D0,Variable); - PUTDST32(RecompPos,Const); -} - -void TestX86RegToX86Reg(int32_t Destination, int32_t Source) { - OPCODE_REG_REG(8,0x85,Destination,Source); -} - -void TestVariableToX86Reg(uint32_t x86reg, void * Variable) { - OPCODE_REG_VARIABLE(,8,0x85,x86reg,Variable); -} - -void XorConstToX86Reg(int32_t x86reg, uint32_t Const) { - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - OPCODE_REG_REG(8,0x81,OP_D6,x86reg); - PUTDST32(RecompPos, Const); - } else { - OPCODE_REG_REG(8,0x83,OP_D6,x86reg); - PUTDST8(RecompPos, Const); - } -} - -void XorX86RegToX86Reg(int32_t Source, int32_t Destination) { - OPCODE_REG_REG(8,0x31,Destination,Source); -} - -void XorVariableToX86reg(void *Variable, int32_t x86reg) { - OPCODE_REG_VARIABLE(,8,0x33,x86reg,Variable); -} - - diff --git a/src/usf/x86.h b/src/usf/x86.h deleted file mode 100644 index 751f63d..0000000 --- a/src/usf/x86.h +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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. - * - */ - - -#define PUTDST8(dest,value) {(*((uint8_t *)(dest))=(uint8_t)(value)); dest += 1;} -#define PUTDST16(dest,value) {(*((uint16_t *)(dest))=(uint16_t)(value)); dest += 2;} -#define PUTDST32(dest,value) {(*((uint32_t *)(dest))=(uint32_t)(value)); dest += 4;} -#define PUTDST64(dest,value) {(*((uint64_t *)(dest))=(uint64_t)(value)); dest += 8;} - -#include "types.h" - -#ifdef USEX64 - -#define x64_Reg 0x10 -#define X64_Reg 0x10 -#define X64_Ext 0x20 - -extern uint8_t Index[9]; - -enum x86RegValues { - - x86_Any = 0, - x86_EAX,x86_ECX,x86_EDX,x86_EBX,x86_ESP,x86_EBP,x86_ESI,x86_EDI,x86_Any8Bit=0x40,x64_Any = 0x40, - - x86_RAX = 0x11,x86_RCX,x86_RDX,x86_RBX,x86_RSP,x86_RBP,x86_RSI,x86_RDI, - - x86_R8D = 0x21,x86_R9D,x86_R10D,x86_R11D,x86_R12D,x86_R13D,x86_R14D,x86_R15D, - - x86_R8 = 0x31,x86_R9,x86_R10,x86_R11,x86_R12,x86_R13,x86_R14,x86_R15, - -}; - -enum x86FpuValues { - x86_ST0,x86_ST1,x86_ST2,x86_ST3,x86_ST4,x86_ST5,x86_ST6,x86_ST7 -}; - -#define x86_TEMP x86_R8 -#define x86_TEMPD x86_R8D - -#define OP_D0 1 -#define OP_D1 2 -#define OP_D2 3 -#define OP_D3 4 -#define OP_D4 5 -#define OP_D5 6 -#define OP_D6 7 -#define OP_D7 8 - -#define LOAD_VARIABLE(reg,variable) \ - PUTDST8(RecompPos, 0x48 | (((reg)&0x20)>>5)); \ - PUTDST8(RecompPos,0xB8 | ((reg)-1)&0xf); \ - PUTDST64(RecompPos,variable); - -// // 43 0F B6 0C 0D 40 83 C7 04 movzx ecx,byte ptr [r9+4C78340h] - -#define OPCODE_REG_REG(oplen,opcode,reg,rm) \ - PUTDST8(RecompPos, 0x40 | (((rm)&0x20)>>5) | ((((rm|reg))&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0xC0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); - -#define OPCODE_REG_MREG(oplen,opcode,reg,rm) \ - PUTDST8(RecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RecompPos, opcode); \ - if(((rm)&0xf)==0x6) { \ - PUTDST8(RecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0); \ - } else if(((rm)&0xf)==0x5) { \ - PUTDST8(RecompPos, 0x0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x24); \ - } else { \ - PUTDST8(RecompPos, 0x00 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } - -#define OPCODE_REG_MREG_IMM32(oplen,opcode,reg,rm,imm32) \ - PUTDST8(RecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RecompPos, opcode); \ - if(((rm)&0xf)==0x5) { \ - PUTDST8(RecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x24); \ - } else { \ - PUTDST8(RecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } \ - PUTDST32(RecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX(oplen,opcode,reg,base,index) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - if(((base)&0xf)!=0x6) { \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - } else {\ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, 0); \ - } - -#define OPCODE_REG_MREG_IMM8(oplen,opcode,reg,rm,imm8) \ - PUTDST8(RecompPos, 0x40 | (((rm)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST32(RecompPos,imm8); - -/*scale is: 0=1,0x40=2,0x80=4,0xc0=8 ??*/ - -#define OPCODE_REG_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((scale)-1)*0x40) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM32(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM8(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RecompPos,imm32); - - -#define OPCODE_REG_BASE_INDEX_IMM8(oplen,opcode,reg,base,index,imm8) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, imm8); - -#define OPCODE_REG_BASE_INDEX_IMM32(oplen,opcode,reg,base,index,imm32) \ - PUTDST8(RecompPos, 0x40 | (((base)&0x20)>>5) | (((reg)&0x10)>>1) | (((reg)&0x20)>>3)| (((index)&0x20)>>4)); \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, imm32); - -#else /* !USEX64 */ - -#define x64_Reg 0 -#define X64_Reg 0 -#define X64_Ext 0 - - -extern uint8_t Index[9]; - -enum x86RegValues { - - x64_Any = 0, x86_Any = 0, - x86_EAX,x86_ECX,x86_EDX,x86_EBX,x86_ESP,x86_EBP,x86_ESI,x86_EDI,x86_Any8Bit=0x40, - -}; - -enum x86FpuValues { - x86_ST0,x86_ST1,x86_ST2,x86_ST3,x86_ST4,x86_ST5,x86_ST6,x86_ST7 -}; - -#define OP_D0 1 -#define OP_D1 2 -#define OP_D2 3 -#define OP_D3 4 -#define OP_D4 5 -#define OP_D5 6 -#define OP_D6 7 -#define OP_D7 8 - -// // 43 0F B6 0C 0D 40 83 C7 04 movzx ecx,byte ptr [r9+4C78340h] - -#define OPCODE_REG_DISP(oplen,opcode,reg,disp32) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x5 | ((((reg)-1)&0x7) << 3)); \ - PUTDST32(RecompPos,disp32); - -#define OPCODE_REG_REG(oplen,opcode,reg,rm) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0xC0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); - -#define OPCODE_REG_MREG(oplen,opcode,reg,rm) \ - PUTDST##oplen (RecompPos, opcode); \ - if(((rm)&0xf)==0x6) { \ - PUTDST8(RecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0); \ - } else if(((rm)&0xf)==0x5) { \ - PUTDST8(RecompPos, 0x0 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x24); \ - } else { \ - PUTDST8(RecompPos, 0x00 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } - -#define OPCODE_REG_MREG_IMM32(oplen,opcode,reg,rm,imm32) \ - PUTDST##oplen (RecompPos, opcode); \ - if(((rm)&0xf)==0x5) { \ - PUTDST8(RecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x24); \ - } else { \ - PUTDST8(RecompPos, 0x80 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - } \ - PUTDST32(RecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX(oplen,opcode,reg,base,index) \ - PUTDST##oplen (RecompPos, opcode); \ - if(((base)&0xf)!=0x6) { \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - } else {\ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x00 | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, 0); \ - } - -#define OPCODE_REG_MREG_IMM8(oplen,opcode,reg,rm,imm8) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x40 | (((rm)-1)&0x7) | ((((reg)-1)&0x7) << 3)); \ - PUTDST32(RecompPos,imm8); - -/*scale is: 0=1,0x40=2,0x80=4,0xc0=8 ??*/ - -#define OPCODE_REG_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((scale)-1)*0x40) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE(oplen,opcode,reg,base,index,scale) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x04 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM32(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x84 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RecompPos,imm32); - -#define OPCODE_REG_BASE_INDEX_SCALE_IMM8(oplen,opcode,reg,base,index,scale,imm32) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (scale) | (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RecompPos,imm32); - - -#define OPCODE_REG_BASE_INDEX_IMM8(oplen,opcode,reg,base,index,imm8) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, imm8); - -#define OPCODE_REG_BASE_INDEX_IMM32(oplen,opcode,reg,base,index,imm32) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x44 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, (((base)-1)&0x7) | ((((index)-1)&0x7) << 3) ); \ - PUTDST8(RecompPos, imm32); - -#define OPCODE_REG_INDEX_SCALE_IMM32(oplen,opcode,reg,index,scale,imm32) \ - PUTDST##oplen (RecompPos, opcode); \ - PUTDST8(RecompPos, 0x4 | ((((reg)-1)&0x7) << 3)); \ - PUTDST8(RecompPos, 0x5 | (scale) | ((((index)-1)&0x7) << 3) ); \ - PUTDST32(RecompPos,imm32); - -#endif - -#ifndef USEX64 - -#define OPCODE_REG_VARIABLE(PREFIX,oplen,opcode,reg,variable) \ - PREFIX \ - OPCODE_REG_DISP(oplen,opcode,reg,variable); -#else - -#define OPCODE_REG_VARIABLE(PREFIX,oplen,opcode,reg,Variable) \ - if(((uintptr_t)(Variable) - (uintptr_t)TLB_Map) < 0x7FFFFFFF) { \ - PREFIX \ - OPCODE_REG_MREG_IMM32(oplen,opcode,reg,x86_R15,(uintptr_t)(Variable) - (uintptr_t)TLB_Map); \ - } else { \ - LOAD_VARIABLE(x86_TEMP, (Variable)); \ - PREFIX \ - OPCODE_REG_MREG(oplen,opcode,reg,x86_TEMP); \ - } -#endif - -#ifdef USEX64 - #define LOAD_FROM_TLB(dstreg,srcreg) MoveX86RegDispToX86Reg(dstreg, x86_R15, srcreg, 8); -#else - #define LOAD_FROM_TLB(dstreg,srcreg) MoveVariableDispToX86Reg(TLB_Map,dstreg,srcreg,4); -#endif - - -void MoveX86RegDispToX86Reg(int32_t x86Reg, int32_t AddrReg, int32_t IndexReg, int32_t Multiplier); -void MoveVariableToX86reg64(void *Variable, int32_t x86reg); -void MovePointerToX86reg(void *Variable, int32_t x86reg); -void AddConstToX86Reg64 (int32_t x86Reg, uint32_t Const); -void MoveConstQwordToX86reg(uint64_t Const, int32_t x86reg); - -void AdcX86regToVariable ( int32_t x86reg, void * Variable ); -void AdcConstToVariable ( void *Variable, uint8_t Constant ); -void AdcConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void AdcVariableToX86reg ( int32_t x86reg, void * Variable ); -void AdcX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void AddConstToVariable ( uint32_t Const, void *Variable ); -void AddConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void AddVariableToX86reg ( int32_t x86reg, void * Variable ); -void AddX86regToVariable ( int32_t x86reg, void * Variable ); -void AddX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void AndConstToVariable ( uint32_t Const, void *Variable ); -void AndConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void AndVariableToX86Reg ( void * Variable, int32_t x86Reg ); -void AndVariableDispToX86Reg ( void * Variable, int32_t x86Reg, int32_t AddrReg, int32_t Multiplier); -void AndX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void BreakPoint ( void ); -void Call_Direct ( void * FunctAddress); -void Call_Indirect ( void * FunctAddress); -void CompConstToVariable ( uint32_t Const, void * Variable ); -void CompConstToX86reg ( int32_t x86Reg, uint32_t Const ); -void CompX86regToVariable ( int32_t x86Reg, void * Variable ); -void CompVariableToX86reg ( int32_t x86Reg, void * Variable ); -void CompX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void DecX86reg ( int32_t x86Reg ); -void DivX86reg ( int32_t x86reg ); -void idivX86reg ( int32_t x86reg ); -void imulX86reg ( int32_t x86reg ); -void IncX86reg ( int32_t x86Reg ); -void JaeLabel8 ( uint8_t Value ); -void JaeLabel32 ( uint32_t Value ); -void JaLabel8 ( uint8_t Value ); -void JaLabel32 ( uint32_t Value ); -void JbLabel8 ( uint8_t Value ); -void JbLabel32 ( uint32_t Value ); -void JecxzLabel8 ( uint8_t Value ); -void JeLabel8 ( uint8_t Value ); -void JeLabel32 ( uint32_t Value ); -void JgeLabel32 ( uint32_t Value ); -void JgLabel8 ( uint8_t Value ); -void JgLabel32 ( uint32_t Value ); -void JleLabel8 ( uint8_t Value ); -void JleLabel32 ( uint32_t Value ); -void JlLabel8 ( uint8_t Value ); -void JlLabel32 ( uint32_t Value ); -void JzLabel8 ( uint8_t Value ); -void JnzLabel8 ( uint8_t Value ); -void JmpDirectReg ( int32_t x86reg ); -void JmpIndirectLabel32 ( uint32_t location ); -void JmpIndirectReg ( int32_t x86reg ); -void JmpLabel8 ( uint8_t Value ); -void JmpLabel32 ( uint32_t Value ); -void JneLabel8 ( uint8_t Value ); -void JneLabel32 ( uint32_t Value ); -void JnsLabel8 ( uint8_t Value ); -void JnsLabel32 ( uint32_t Value ); -void JsLabel32 ( uint32_t Value ); -void LeaRegReg ( int32_t x86RegDest, int32_t x86RegSrc, int32_t multiplier ); -void LeaSourceAndOffset ( int32_t x86DestReg, int32_t x86SourceReg, int32_t offset ); -void MoveConstByteToN64Mem ( uint8_t Const, int32_t AddrReg ); -void MoveConstHalfToN64Mem ( uint16_t Const, int32_t AddrReg ); -void MoveConstByteToVariable ( uint8_t Const,void *Variable ); -void MoveConstByteToX86regPointer ( uint8_t Const, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveConstHalfToVariable ( uint16_t Const, void *Variable ); -void MoveConstHalfToX86regPointer ( uint16_t Const, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveConstToMemoryDisp ( uint32_t Const, int32_t AddrReg, uint32_t Disp ); -void MoveConstToN64Mem ( uint32_t Const, int32_t AddrReg ); -void MoveConstToN64MemDisp ( uint32_t Const, int32_t AddrReg, uint8_t Disp ); -void MoveConstToVariable ( uint32_t Const, void *Variable ); -void MoveConstToX86Pointer ( uint32_t Const, int32_t X86Pointer ); -void MoveConstToX86reg ( uint32_t Const, int32_t x86reg ); -void MoveConstToX86regPointer ( uint32_t Const, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveN64MemDispToX86reg ( int32_t x86reg, int32_t AddrReg, uint8_t Disp ); -void MoveN64MemToX86reg ( int32_t x86reg, int32_t AddrReg ); -void MoveN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void MoveN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void MoveSxByteX86regPointerToX86reg ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg ); -void MoveSxHalfX86regPointerToX86reg ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg ); -void MoveSxN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void MoveSxN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void MoveSxVariableToX86regByte ( void *Variable, int32_t x86reg ); -void MoveSxVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void MoveVariableDispToX86Reg ( void *Variable, int32_t x86Reg, int32_t AddrReg, int32_t Multiplier ); -void MoveVariableToX86reg ( void *Variable, int32_t x86reg ); -void MoveVariableToX86regByte ( void *Variable, int32_t x86reg ); -void MoveVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void MoveX86PointerToX86reg ( int32_t x86reg, int32_t X86Pointer ); -void MoveX86regByteToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void MoveX86regByteToVariable ( int32_t x86reg, void * Variable ); -void MoveX86regByteToX86regPointer ( int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveX86regHalfToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void MoveX86regHalfToVariable ( int32_t x86reg, void * Variable ); -void MoveX86regHalfToX86regPointer ( int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveX86regPointerToX86reg ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg ); -void MoveX86regPointerToX86regDisp8 ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg, uint8_t offset ); -void MoveX86regToMemory ( int32_t x86reg, int32_t AddrReg, uint32_t Disp ); -void MoveX86regToN64Mem ( int32_t x86reg, int32_t AddrReg ); -void MoveX86regToN64MemDisp ( int32_t x86reg, int32_t AddrReg, uint8_t Disp ); -void MoveX86regToVariable ( int32_t x86reg, void * Variable ); -void MoveX86RegToX86Reg ( int32_t Source, int32_t Destination ); -void MoveX86regToX86Pointer ( int32_t x86reg, int32_t X86Pointer ); -void MoveX86regToX86regPointer ( int32_t x86reg, int32_t AddrReg1, int32_t AddrReg2 ); -void MoveZxByteX86regPointerToX86reg ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg ); -void MoveZxHalfX86regPointerToX86reg ( int32_t AddrReg1, int32_t AddrReg2, int32_t x86reg ); -void MoveZxN64MemToX86regByte ( int32_t x86reg, int32_t AddrReg ); -void MoveZxN64MemToX86regHalf ( int32_t x86reg, int32_t AddrReg ); -void MoveZxVariableToX86regByte ( void *Variable, int32_t x86reg ); -void MoveZxVariableToX86regHalf ( void *Variable, int32_t x86reg ); -void MulX86reg ( int32_t x86reg ); -void NotX86Reg ( int32_t x86Reg ); -void OrConstToVariable ( uint32_t Const, void * Variable ); -void OrConstToX86Reg ( uint32_t Const, int32_t x86Reg ); -void OrVariableToX86Reg ( void * Variable, int32_t x86Reg ); -void OrX86RegToVariable ( void * Variable, int32_t x86Reg ); -void OrX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void Popad ( void ); -void Pushad ( void ); -void Push ( int32_t x86reg ); -void Pop ( int32_t x86reg ); -void PushImm32 ( uint32_t Value ); -void Ret ( void ); -void Seta ( int32_t x86reg ); -void Setae ( int32_t x86reg ); -void SetaVariable ( void * Variable ); -void Setb ( int32_t x86reg ); -void SetbVariable ( void * Variable ); -void Setg ( int32_t x86reg ); -void SetgVariable ( void * Variable ); -void Setl ( int32_t x86reg ); -void SetlVariable ( void * Variable ); -void Setz ( int32_t x86reg ); -void Setnz ( int32_t x86reg ); -void ShiftLeftDouble ( int32_t Destination, int32_t Source ); -void ShiftLeftDoubleImmed ( int32_t Destination, int32_t Source, uint8_t Immediate ); -void ShiftLeftSign ( int32_t x86reg ); -void ShiftLeftSignImmed ( int32_t x86reg, uint8_t Immediate ); -void ShiftRightDouble ( int32_t Destination, int32_t Source ); -void ShiftRightDoubleImmed ( int32_t Destination, int32_t Source, uint8_t Immediate ); -void ShiftRightSign ( int32_t x86reg ); -void ShiftRightSignImmed ( int32_t x86reg, uint8_t Immediate ); -void ShiftRightUnsign ( int32_t x86reg ); -void ShiftRightUnsignImmed ( int32_t x86reg, uint8_t Immediate ); -void SbbConstFromX86Reg ( int32_t x86Reg, uint32_t Const ); -void SbbVariableFromX86reg ( int32_t x86reg, void * Variable ); -void SbbX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void SubConstFromVariable ( uint32_t Const, void *Variable ); -void SubConstFromX86Reg ( int32_t x86Reg, uint32_t Const ); -void SubVariableFromX86reg ( int32_t x86reg, void * Variable ); -void SubX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void TestConstToX86Reg ( uint32_t Const, int32_t x86reg ); -void TestVariable ( uint32_t Const, void * Variable ); -void TestX86RegToX86Reg ( int32_t Destination, int32_t Source ); -void TestVariableToX86Reg ( uint32_t x86reg, void * Variable); -void XorConstToX86Reg ( int32_t x86Reg, uint32_t Const ); -void XorX86RegToX86Reg ( int32_t Source, int32_t Destination ); -void XorVariableToX86reg ( void *Variable, int32_t x86reg ); - - -void fpuAbs ( void ); -void fpuAddDword ( void *Variable ); -void fpuAddDwordRegPointer ( int32_t x86Pointer ); -void fpuAddQword ( void *Variable ); -void fpuAddQwordRegPointer ( int32_t x86Pointer ); -void fpuAddReg ( int32_t x86reg ); -void fpuAddRegPop ( int32_t * StackPos, int32_t x86reg ); -void fpuComDword ( void *Variable, uint32_t Pop ); -void fpuComDwordRegPointer ( int32_t x86Pointer, uint32_t Pop ); -void fpuComQword ( void *Variable, uint32_t Pop ); -void fpuComQwordRegPointer ( int32_t x86Pointer, uint32_t Pop ); -void fpuComReg ( int32_t x86reg, uint32_t Pop ); -void fpuDivDword ( void *Variable ); -void fpuDivDwordRegPointer ( int32_t x86Pointer ); -void fpuDivQword ( void *Variable ); -void fpuDivQwordRegPointer ( int32_t x86Pointer ); -void fpuDivReg ( int32_t Reg ); -void fpuDivRegPop ( int32_t x86reg ); -void fpuExchange ( int32_t Reg ); -void fpuFree ( int32_t Reg ); -void fpuDecStack ( int32_t * StackPos ); -void fpuIncStack ( int32_t * StackPos ); -void fpuLoadControl ( void *Variable ); -void fpuLoadDword ( int32_t * StackPos, void *Variable ); -void fpuLoadDwordFromX86Reg ( int32_t * StackPos, int32_t x86reg ); -void fpuLoadDwordFromN64Mem ( int32_t * StackPos, int32_t x86reg ); -void fpuLoadInt32bFromN64Mem ( int32_t * StackPos, int32_t x86reg ); -void fpuLoadIntegerDword ( int32_t * StackPos, void *Variable ); -void fpuLoadIntegerDwordFromX86Reg ( int32_t * StackPos,int32_t x86Reg ); -void fpuLoadIntegerQword ( int32_t * StackPos, void *Variable ); -void fpuLoadIntegerQwordFromX86Reg ( int32_t * StackPos,int32_t x86Reg ); -void fpuLoadQword ( int32_t * StackPos, void *Variable ); -void fpuLoadQwordFromX86Reg ( int32_t * StackPos, int32_t x86Reg ); -void fpuLoadQwordFromN64Mem ( int32_t * StackPos, int32_t x86reg ); -void fpuLoadReg ( int32_t * StackPos, int32_t Reg ); -void fpuMulDword ( void *Variable); -void fpuMulDwordRegPointer ( int32_t x86Pointer ); -void fpuMulQword ( void *Variable); -void fpuMulQwordRegPointer ( int32_t x86Pointer ); -void fpuMulReg ( int32_t x86reg ); -void fpuMulRegPop ( int32_t x86reg ); -void fpuNeg ( void ); -void fpuRound ( void ); -void fpuSqrt ( void ); -void fpuStoreControl ( void *Variable ); -void fpuStoreDword ( int32_t * StackPos, void *Variable, uint32_t pop ); -void fpuStoreDwordFromX86Reg ( int32_t * StackPos,int32_t x86Reg, uint32_t pop ); -void fpuStoreDwordToN64Mem ( int32_t * StackPos, int32_t x86reg, uint32_t Pop ); -void fpuStoreIntegerDword ( int32_t * StackPos, void *Variable, uint32_t pop ); -void fpuStoreIntegerDwordFromX86Reg ( int32_t * StackPos,int32_t x86Reg, uint32_t pop ); -void fpuStoreIntegerQword ( int32_t * StackPos, void *Variable, uint32_t pop ); -void fpuStoreIntegerQwordFromX86Reg ( int32_t * StackPos, int32_t x86Reg, uint32_t pop ); -void fpuStoreQword ( int32_t * StackPos, void *Variable, uint32_t pop ); -void fpuStoreQwordFromX86Reg ( int32_t * StackPos, int32_t x86Reg, uint32_t pop ); -void fpuStoreStatus ( void ); -void fpuSubDword ( void *Variable ); -void fpuSubDwordRegPointer ( int32_t x86Pointer ); -void fpuSubDwordReverse ( void *Variable ); -void fpuSubQword ( void *Variable ); -void fpuSubQwordRegPointer ( int32_t x86Pointer ); -void fpuSubQwordReverse ( void *Variable ); -void fpuSubReg ( int32_t x86reg ); -void fpuSubRegPop ( int32_t x86reg ); - -void MoveVariable64ToX86reg(void *Variable, int32_t x86reg); diff --git a/src/usf/x86_fpu.c b/src/usf/x86_fpu.c deleted file mode 100644 index 02fb9d2..0000000 --- a/src/usf/x86_fpu.c +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Project 64 - A Nintendo 64 emulator. - * - * (c) Copyright 2001 zilmar (zilmar@emulation64.com) and - * Jabo (jabo@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 "main.h" -#include "cpu.h" -#include "x86.h" -#include "types.h" - -void fpuAbs(void) { - PUTDST16(RecompPos,0xE1D9); -} - -void fpuAddDword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x05D8); - PUTDST32(RecompPos,Variable); -} - -void fpuAddDwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xD8,OP_D0,x86Pointer); -} - -void fpuAddQword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x05DC); - PUTDST32(RecompPos,Variable); -} - -void fpuAddQwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xDC,OP_D0,x86Pointer); -} - -void fpuAddReg(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xC0D8); break; - case x86_ST1: PUTDST16(RecompPos,0xC1D8); break; - case x86_ST2: PUTDST16(RecompPos,0xC2D8); break; - case x86_ST3: PUTDST16(RecompPos,0xC3D8); break; - case x86_ST4: PUTDST16(RecompPos,0xC4D8); break; - case x86_ST5: PUTDST16(RecompPos,0xC5D8); break; - case x86_ST6: PUTDST16(RecompPos,0xC6D8); break; - case x86_ST7: PUTDST16(RecompPos,0xC7D8); break; - } -} - -void fpuAddRegPop(int * StackPos, int x86reg) { - *StackPos = (*StackPos + 1) & 7; - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xC0DE); break; - case x86_ST1: PUTDST16(RecompPos,0xC1DE); break; - case x86_ST2: PUTDST16(RecompPos,0xC2DE); break; - case x86_ST3: PUTDST16(RecompPos,0xC3DE); break; - case x86_ST4: PUTDST16(RecompPos,0xC4DE); break; - case x86_ST5: PUTDST16(RecompPos,0xC5DE); break; - case x86_ST6: PUTDST16(RecompPos,0xC6DE); break; - case x86_ST7: PUTDST16(RecompPos,0xC7DE); break; - } -} - -void fpuComDword(void *Variable, uint32_t Pop) { - BreakPoint(); - PUTDST16(RecompPos, (Pop == 1) ? 0x1DD8 : 0x15D8); - PUTDST32(RecompPos,Variable); -} - -void fpuComDwordRegPointer(int x86Pointer, uint32_t Pop) { - if(Pop) { - OPCODE_REG_MREG(8,0xD8,OP_D3,x86Pointer); - } else { - OPCODE_REG_MREG(8,0xD8,OP_D2,x86Pointer); - } -} - -void fpuComQword(void *Variable, uint32_t Pop) { - BreakPoint(); - PUTDST16(RecompPos, (Pop == 1) ? 0x1DDC : 0x15DC); - PUTDST32(RecompPos,Variable); -} - -void fpuComQwordRegPointer(int x86Pointer, uint32_t Pop) { - if(Pop) { - OPCODE_REG_MREG(8,0xDC,OP_D3,x86Pointer); - } else { - OPCODE_REG_MREG(8,0xDC,OP_D2,x86Pointer); - } -} - -void fpuComReg(int x86reg, uint32_t Pop) { - int s = (Pop == 1) ? 0x0800 : 0x0000; - - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xD0D8|s); break; - case x86_ST1: PUTDST16(RecompPos,0xD1D8|s); break; - case x86_ST2: PUTDST16(RecompPos,0xD2D8|s); break; - case x86_ST3: PUTDST16(RecompPos,0xD3D8|s); break; - case x86_ST4: PUTDST16(RecompPos,0xD4D8|s); break; - case x86_ST5: PUTDST16(RecompPos,0xD5D8|s); break; - case x86_ST6: PUTDST16(RecompPos,0xD6D8|s); break; - case x86_ST7: PUTDST16(RecompPos,0xD7D8|s); break; - } -} - -void fpuDivDword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x35D8); - PUTDST32(RecompPos,Variable); -} - -void fpuDivDwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xD8,OP_D6,x86Pointer); -} - -void fpuDivQword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x35DC); - PUTDST32(RecompPos,Variable); -} - -void fpuDivQwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xDC,OP_D6,x86Pointer); -} - -void fpuDivReg(int Reg) { - switch (Reg) { - case x86_ST0: PUTDST16(RecompPos,0xF0D8); break; - case x86_ST1: PUTDST16(RecompPos,0xF1D8); break; - case x86_ST2: PUTDST16(RecompPos,0xF2D8); break; - case x86_ST3: PUTDST16(RecompPos,0xF3D8); break; - case x86_ST4: PUTDST16(RecompPos,0xF4D8); break; - case x86_ST5: PUTDST16(RecompPos,0xF5D8); break; - case x86_ST6: PUTDST16(RecompPos,0xF6D8); break; - case x86_ST7: PUTDST16(RecompPos,0xF7D8); break; - } -} - -void fpuDivRegPop(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xF8DE); break; - case x86_ST1: PUTDST16(RecompPos,0xF9DE); break; - case x86_ST2: PUTDST16(RecompPos,0xFADE); break; - case x86_ST3: PUTDST16(RecompPos,0xFBDE); break; - case x86_ST4: PUTDST16(RecompPos,0xFCDE); break; - case x86_ST5: PUTDST16(RecompPos,0xFDDE); break; - case x86_ST6: PUTDST16(RecompPos,0xFEDE); break; - case x86_ST7: PUTDST16(RecompPos,0xFFDE); break; - } -} - -void fpuExchange(int Reg) { - switch (Reg) { - case x86_ST0: PUTDST16(RecompPos,0xC8D9); break; - case x86_ST1: PUTDST16(RecompPos,0xC9D9); break; - case x86_ST2: PUTDST16(RecompPos,0xCAD9); break; - case x86_ST3: PUTDST16(RecompPos,0xCBD9); break; - case x86_ST4: PUTDST16(RecompPos,0xCCD9); break; - case x86_ST5: PUTDST16(RecompPos,0xCDD9); break; - case x86_ST6: PUTDST16(RecompPos,0xCED9); break; - case x86_ST7: PUTDST16(RecompPos,0xCFD9); break; - } -} - -void fpuFree(int Reg) { - switch (Reg) { - case x86_ST0: PUTDST16(RecompPos,0xC0DD); break; - case x86_ST1: PUTDST16(RecompPos,0xC1DD); break; - case x86_ST2: PUTDST16(RecompPos,0xC2DD); break; - case x86_ST3: PUTDST16(RecompPos,0xC3DD); break; - case x86_ST4: PUTDST16(RecompPos,0xC4DD); break; - case x86_ST5: PUTDST16(RecompPos,0xC5DD); break; - case x86_ST6: PUTDST16(RecompPos,0xC6DD); break; - case x86_ST7: PUTDST16(RecompPos,0xC7DD); break; - } -} - -void fpuDecStack(int * StackPos) { - *StackPos = (*StackPos - 1) & 7; - PUTDST16(RecompPos,0xF6D9); -} - -void fpuIncStack(int * StackPos) { - *StackPos = (*StackPos + 1) & 7; - PUTDST16(RecompPos,0xF7D9); -} - -void fpuLoadControl(void *Variable) { -#ifdef USEX64 - PUTDST16(RecompPos,0xB849); - PUTDST64(RecompPos,Variable); - PUTDST8(RecompPos,0x41); - PUTDST16(RecompPos,0x28D9); -#else - PUTDST16(RecompPos,0x2DD9); - PUTDST32(RecompPos,Variable); -#endif -} - -void fpuLoadDword(int * StackPos,void *Variable) { - *StackPos = (*StackPos - 1) & 7; - BreakPoint(); - PUTDST16(RecompPos,0x05D9); - PUTDST32(RecompPos,Variable); -} - -void fpuLoadDwordFromX86Reg(int * StackPos, int x86reg) { - *StackPos = (*StackPos - 1) & 7; - OPCODE_REG_MREG(8,0xD9,OP_D0,x86reg); -} - -void fpuLoadIntegerDword(int * StackPos,void *Variable) { - *StackPos = (*StackPos - 1) & 7; - BreakPoint(); - PUTDST16(RecompPos,0x05DB); - PUTDST32(RecompPos,Variable); -} - -void fpuLoadIntegerDwordFromX86Reg(int * StackPos,int x86reg) { - *StackPos = (*StackPos - 1) & 7; - OPCODE_REG_MREG(8,0xDB,OP_D0,x86reg); -} - -void fpuLoadIntegerQword(int * StackPos,void *Variable) { - *StackPos = (*StackPos - 1) & 7; - BreakPoint(); - PUTDST16(RecompPos,0x2DDF); - PUTDST32(RecompPos,Variable); -} - -void fpuLoadIntegerQwordFromX86Reg(int * StackPos,int x86reg) { - *StackPos = (*StackPos - 1) & 7; - OPCODE_REG_MREG(8,0xDF,OP_D5,x86reg); -} - -void fpuLoadQword(int * StackPos,void *Variable) { - *StackPos = (*StackPos - 1) & 7; - BreakPoint(); - PUTDST16(RecompPos,0x05DD); - PUTDST32(RecompPos,Variable); -} - -void fpuLoadQwordFromX86Reg(int * StackPos, int x86reg) { - *StackPos = (*StackPos - 1) & 7; - OPCODE_REG_MREG(8,0xDD,OP_D0,x86reg); -} -void fpuLoadReg(int * StackPos,int Reg) { - *StackPos = (*StackPos - 1) & 7; - switch (Reg) { - case x86_ST0: PUTDST16(RecompPos,0xC0D9); break; - case x86_ST1: PUTDST16(RecompPos,0xC1D9); break; - case x86_ST2: PUTDST16(RecompPos,0xC2D9); break; - case x86_ST3: PUTDST16(RecompPos,0xC3D9); break; - case x86_ST4: PUTDST16(RecompPos,0xC4D9); break; - case x86_ST5: PUTDST16(RecompPos,0xC5D9); break; - case x86_ST6: PUTDST16(RecompPos,0xC6D9); break; - case x86_ST7: PUTDST16(RecompPos,0xC7D9); break; - break; - } -} - -void fpuMulDword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x0DD8); - PUTDST32(RecompPos,Variable); -} - -void fpuMulDwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xD8,OP_D1,x86Pointer); -} - -void fpuMulQword(void *Variable) { -BreakPoint(); - PUTDST16(RecompPos,0x0DDC); - PUTDST32(RecompPos,Variable); -} - -void fpuMulQwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xDC,OP_D1,x86Pointer); -} - -void fpuMulReg(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xC8D8); break; - case x86_ST1: PUTDST16(RecompPos,0xC9D8); break; - case x86_ST2: PUTDST16(RecompPos,0xCAD8); break; - case x86_ST3: PUTDST16(RecompPos,0xCBD8); break; - case x86_ST4: PUTDST16(RecompPos,0xCCD8); break; - case x86_ST5: PUTDST16(RecompPos,0xCDD8); break; - case x86_ST6: PUTDST16(RecompPos,0xCED8); break; - case x86_ST7: PUTDST16(RecompPos,0xCFD8); break; - } -} - -void fpuMulRegPop(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xC8DE); break; - case x86_ST1: PUTDST16(RecompPos,0xC9DE); break; - case x86_ST2: PUTDST16(RecompPos,0xCADE); break; - case x86_ST3: PUTDST16(RecompPos,0xCBDE); break; - case x86_ST4: PUTDST16(RecompPos,0xCCDE); break; - case x86_ST5: PUTDST16(RecompPos,0xCDDE); break; - case x86_ST6: PUTDST16(RecompPos,0xCEDE); break; - case x86_ST7: PUTDST16(RecompPos,0xCFDE); break; - } -} - -void fpuNeg(void) { - PUTDST16(RecompPos,0xE0D9); -} - -void fpuRound(void) { - PUTDST16(RecompPos,0xFCD9); -} - -void fpuSqrt(void) { - PUTDST16(RecompPos,0xFAD9); -} - -void fpuStoreControl(void *Variable) { - -#ifdef USEX64 - PUTDST16(RecompPos,0xB849); - PUTDST64(RecompPos,Variable); - PUTDST8(RecompPos,0x41); - PUTDST16(RecompPos,0x38D9); -#else - PUTDST16(RecompPos,0x3DD9); - PUTDST32(RecompPos,Variable); -#endif -} - -void fpuStoreDword(int * StackPos,void *Variable, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - BreakPoint(); - PUTDST16(RecompPos,(pop == 0) ? 0x15D9 : 0x1DD9); - PUTDST32(RecompPos,Variable); -} - -void fpuStoreDwordFromX86Reg(int * StackPos,int x86reg, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - - if(pop) { - OPCODE_REG_MREG(8,0xD9,OP_D3,x86reg); - } else { - OPCODE_REG_MREG(8,0xD9,OP_D2,x86reg); - } -} - - -void fpuStoreIntegerDword(int * StackPos,void *Variable, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - BreakPoint(); - PUTDST16(RecompPos, (pop == 0) ? 0x15DB : 0x1DDB); - PUTDST32(RecompPos,Variable); -} - -void fpuStoreIntegerDwordFromX86Reg(int * StackPos,int x86reg, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - - if(pop) { - OPCODE_REG_MREG(8,0xDB,OP_D3,x86reg); - } else { - OPCODE_REG_MREG(8,0xDB,OP_D2,x86reg); - } -} - -void fpuStoreIntegerQword(int * StackPos,void *Variable, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - BreakPoint(); - PUTDST16(RecompPos, (pop == 0) ? 0x35DF : 0x3DDF); - PUTDST32(RecompPos,Variable); - if (!pop) { BreakPoint(); } -} - -void fpuStoreIntegerQwordFromX86Reg(int * StackPos, int x86reg, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - - BreakPoint(); - if(pop) { - OPCODE_REG_MREG(8,0xDF,OP_D5,x86reg); - } else { - OPCODE_REG_MREG(8,0xDF,OP_D4,x86reg); - } - -} - -void fpuStoreQwordFromX86Reg(int * StackPos, int x86reg, uint32_t pop) { - if (pop) { *StackPos = (*StackPos + 1) & 7; } - - if(pop) { - OPCODE_REG_MREG(8,0xDD,OP_D3,x86reg); - } else { - OPCODE_REG_MREG(8,0xDD,OP_D2,x86reg); - } - -} - -void fpuStoreStatus(void) { - PUTDST16(RecompPos,0xE0DF); -} - -void fpuSubDword(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x25D8); - PUTDST32(RecompPos,Variable); -} - -void fpuSubDwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xD8,OP_D4,x86Pointer); -} - -void fpuSubDwordReverse(void *Variable) { -BreakPoint(); - PUTDST16(RecompPos,0x2DD8); - PUTDST32(RecompPos,Variable); -} - -void fpuSubQword(void *Variable) { -BreakPoint(); - PUTDST16(RecompPos,0x25DC); - PUTDST32(RecompPos,Variable); -} - -void fpuSubQwordRegPointer(int x86Pointer) { - OPCODE_REG_MREG(8,0xDC,OP_D4,x86Pointer); -} - -void fpuSubQwordReverse(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x2DDC); - PUTDST32(RecompPos,Variable); -} - -void fpuSubReg(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xE0D8); break; - case x86_ST1: PUTDST16(RecompPos,0xE1D8); break; - case x86_ST2: PUTDST16(RecompPos,0xE2D8); break; - case x86_ST3: PUTDST16(RecompPos,0xE3D8); break; - case x86_ST4: PUTDST16(RecompPos,0xE4D8); break; - case x86_ST5: PUTDST16(RecompPos,0xE5D8); break; - case x86_ST6: PUTDST16(RecompPos,0xE6D8); break; - case x86_ST7: PUTDST16(RecompPos,0xE7D8); break; - break; - } -} - -void fpuSubRegPop(int x86reg) { - switch (x86reg&0xf) { - case x86_ST0: PUTDST16(RecompPos,0xE8DE); break; - case x86_ST1: PUTDST16(RecompPos,0xE9DE); break; - case x86_ST2: PUTDST16(RecompPos,0xEADE); break; - case x86_ST3: PUTDST16(RecompPos,0xEBDE); break; - case x86_ST4: PUTDST16(RecompPos,0xECDE); break; - case x86_ST5: PUTDST16(RecompPos,0xEDDE); break; - case x86_ST6: PUTDST16(RecompPos,0xEEDE); break; - case x86_ST7: PUTDST16(RecompPos,0xEFDE); break; - } -} -void fpuDivDwordReverse(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x3DD8); - PUTDST32(RecompPos,Variable); -} - - -void fpuDivQwordReverse(void *Variable) { - BreakPoint(); - PUTDST16(RecompPos,0x3DDC); - PUTDST32(RecompPos,Variable); -} - -unsigned int fpucontrol; - -/* returns and pushes current fpu state, bool for set normal */ -int fpuSaveControl(uint32_t bSetNormal) { -/* _asm { - fnstcw word ptr [fpucontrol] - } - - if (bSetNormal == 1) { - unsigned short fpunormal = fpucontrol & 0xF3FF; - _asm { - fldcw word ptr [fpunormal] - } - } -*/ - return fpucontrol; -} - -/* returns and pops fpu state previously pushed */ -int fpuRestoreControl() { -/* _asm { - fldcw word ptr [fpucontrol] - }*/ - return fpucontrol; -} - -void fpuSetupDouble(void) { -/* - int temp = 0; - _asm { - fnstcw word ptr [temp] - or [temp], 0x300 - and [temp], 0xFFFFF3FF - fldcw word ptr [temp] - } */ -} - -- cgit v1.2.3