Code clean up

This commit is contained in:
zilmar 2022-10-10 10:52:17 +10:30
parent 0d7f25138c
commit 761a1ee52a
207 changed files with 7244 additions and 3928 deletions

View File

@ -131,12 +131,13 @@ void MD5::finalize()
{ {
unsigned char bits[8]; unsigned char bits[8];
unsigned int index, padLen; unsigned int index, padLen;
static uint1 PADDING[64] = // clang-format off
{ static uint1 PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };
// clang-format on
if (finalized) if (finalized)
{ {

View File

@ -1,22 +1,22 @@
typedef const char * LPCSTR; typedef const char * LPCSTR;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
#include "7zip.h" #include "7zip.h"
#include <Common/StdString.h> #include <Common/StdString.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
C7zip::C7zip(const char * FileName) : C7zip::C7zip(const char * FileName) :
m_FileSize(0), m_FileSize(0),
m_CurrentFile(-1), m_CurrentFile(-1),
m_blockIndex(0xFFFFFFFF), m_blockIndex(0xFFFFFFFF),
m_outBuffer(0), m_outBuffer(0),
m_outBufferSize(0), m_outBufferSize(0),
m_NotfyCallback(NotfyCallbackDefault), m_NotfyCallback(NotfyCallbackDefault),
m_NotfyCallbackInfo(nullptr), m_NotfyCallbackInfo(nullptr),
m_db(nullptr), m_db(nullptr),
m_Opened(false) m_Opened(false)
{ {
memset(&m_FileName, 0, sizeof(m_FileName)); memset(&m_FileName, 0, sizeof(m_FileName));
memset(&m_archiveLookStream, 0, sizeof(m_archiveLookStream)); memset(&m_archiveLookStream, 0, sizeof(m_archiveLookStream));
@ -78,7 +78,6 @@ void C7zip::SetNotificationCallback(LP7ZNOTIFICATION NotfyFnc, void * CBInfo)
m_NotfyCallbackInfo = CBInfo; m_NotfyCallbackInfo = CBInfo;
} }
bool C7zip::GetFile(int index, Byte * Data, size_t DataLen) bool C7zip::GetFile(int index, Byte * Data, size_t DataLen)
{ {
m_CurrentFile = -1; m_CurrentFile = -1;
@ -101,9 +100,9 @@ bool C7zip::GetFile(int index, Byte * Data, size_t DataLen)
m_NotfyCallback(Msg, m_NotfyCallbackInfo); m_NotfyCallback(Msg, m_NotfyCallbackInfo);
SRes res = SzArEx_Extract(m_db, &m_archiveLookStream.s, index, SRes res = SzArEx_Extract(m_db, &m_archiveLookStream.s, index,
&m_blockIndex, &m_outBuffer, &m_outBufferSize, &m_blockIndex, &m_outBuffer, &m_outBufferSize,
&offset, &outSizeProcessed, &offset, &outSizeProcessed,
&m_allocImp, &m_allocTempImp); &m_allocImp, &m_allocTempImp);
if (res != SZ_OK) if (res != SZ_OK)
{ {
m_CurrentFile = -1; m_CurrentFile = -1;
@ -126,7 +125,7 @@ void * C7zip::AllocAllocImp(void * /*p*/, size_t size)
//return new BYTE[size]; //return new BYTE[size];
} }
void C7zip::AllocFreeImp(void * /*p*/, void *address) void C7zip::AllocFreeImp(void * /*p*/, void * address)
{ {
if (address != nullptr) if (address != nullptr)
{ {
@ -134,9 +133,9 @@ void C7zip::AllocFreeImp(void * /*p*/, void *address)
} }
} }
SRes C7zip::SzFileReadImp(void *object, void *buffer, size_t *processedSize) SRes C7zip::SzFileReadImp(void * object, void * buffer, size_t * processedSize)
{ {
CFileInStream *p = (CFileInStream *)object; CFileInStream * p = (CFileInStream *)object;
DWORD dwRead; DWORD dwRead;
if (!ReadFile(p->file.handle, buffer, (DWORD)*processedSize, &dwRead, nullptr)) if (!ReadFile(p->file.handle, buffer, (DWORD)*processedSize, &dwRead, nullptr))
{ {
@ -147,9 +146,9 @@ SRes C7zip::SzFileReadImp(void *object, void *buffer, size_t *processedSize)
return SZ_OK; return SZ_OK;
} }
SRes C7zip::SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin) SRes C7zip::SzFileSeekImp(void * p, Int64 * pos, ESzSeek origin)
{ {
CFileInStream *s = (CFileInStream *)p; CFileInStream * s = (CFileInStream *)p;
DWORD dwMoveMethod; DWORD dwMoveMethod;
switch (origin) switch (origin)

View File

@ -2,11 +2,12 @@
#include <string> #include <string>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
#include "7zip/7zCrc.h"
#include "7zip/7z.h" #include "7zip/7z.h"
#include "7zip/7zCrc.h"
#include "7zip/7zFile.h" #include "7zip/7zFile.h"
#include "7zip/Types.h" #include "7zip/Types.h"
@ -17,18 +18,29 @@ extern "C" {
class C7zip class C7zip
{ {
public: public:
C7zip(const char * FileName); C7zip(const char * FileName);
~C7zip(); ~C7zip();
typedef void (*LP7ZNOTIFICATION)(const char * Status, void * CBInfo); typedef void (*LP7ZNOTIFICATION)(const char * Status, void * CBInfo);
inline int NumFiles(void) const { return m_db ? m_db->db.NumFiles : 0; } inline int NumFiles(void) const
inline CSzFileItem * FileItem(int index) const { return m_db ? &m_db->db.Files[index] : nullptr; } {
inline int FileSize(void) const { return m_FileSize; } return m_db ? m_db->db.NumFiles : 0;
inline bool OpenSuccess(void) const { return m_Opened; } }
inline CSzFileItem * FileItem(int index) const
{
return m_db ? &m_db->db.Files[index] : nullptr;
}
inline int FileSize(void) const
{
return m_FileSize;
}
inline bool OpenSuccess(void) const
{
return m_Opened;
}
bool GetFile(int index, Byte * Data, size_t DataLen); bool GetFile(int index, Byte * Data, size_t DataLen);
const char * FileName(char * FileName, size_t SizeOfFileName) const; const char * FileName(char * FileName, size_t SizeOfFileName) const;
std::wstring FileNameIndex(int index); std::wstring FileNameIndex(int index);
@ -36,8 +48,8 @@ public:
private: private:
C7zip(void); C7zip(void);
C7zip(const C7zip&); C7zip(const C7zip &);
C7zip& operator=(const C7zip&); C7zip & operator=(const C7zip &);
CSzArEx * m_db; CSzArEx * m_db;
CFileInStream m_archiveStream; CFileInStream m_archiveStream;
@ -50,19 +62,21 @@ private:
bool m_Opened; bool m_Opened;
// Used for extraction // Used for extraction
UInt32 m_blockIndex; // It can have any value before first call (if outBuffer = 0) UInt32 m_blockIndex; // It can have any value before first call (if outBuffer = 0)
Byte * m_outBuffer; // It must be 0 before first call for each new archive Byte * m_outBuffer; // It must be 0 before first call for each new archive
size_t m_outBufferSize; // It can have any value before first call (if outBuffer = 0) size_t m_outBufferSize; // It can have any value before first call (if outBuffer = 0)
static void * AllocAllocImp(void *p, size_t size); static void * AllocAllocImp(void * p, size_t size);
static void AllocFreeImp(void *p, void *address); // Address can be 0 static void AllocFreeImp(void * p, void * address); // Address can be 0
static SRes SzFileReadImp(void *object, void *buffer, size_t *processedSize); static SRes SzFileReadImp(void * object, void * buffer, size_t * processedSize);
static SRes SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin); static SRes SzFileSeekImp(void * p, Int64 * pos, ESzSeek origin);
//static void __stdcall StatusUpdate(_7Z_STATUS status, int Value1, int Value2, C7zip * _this); //static void __stdcall StatusUpdate(_7Z_STATUS status, int Value1, int Value2, C7zip * _this);
static void NotfyCallbackDefault(const char * /*Status*/, void * /*CBInfo*/) { } static void NotfyCallbackDefault(const char * /*Status*/, void * /*CBInfo*/)
{
}
LP7ZNOTIFICATION m_NotfyCallback; LP7ZNOTIFICATION m_NotfyCallback;
void * m_NotfyCallbackInfo; void * m_NotfyCallbackInfo;

View File

@ -2,5 +2,5 @@
#include <Project64-core/Notification.h> #include <Project64-core/Notification.h>
bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char **argv); bool AppInit(CNotification * Notify, const char * BaseDirectory, int argc, char ** argv);
void AppCleanup(void); void AppCleanup(void);

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Project64-core/Settings/LoggingSettings.h>
#include <Common/File.h> #include <Common/File.h>
#include <Project64-core/Settings/LoggingSettings.h>
class CLogging : class CLogging :
public CLogSettings public CLogSettings

View File

@ -168,37 +168,37 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
switch (*(TypePos + 1)) switch (*(TypePos + 1))
{ {
case 0xB6: case 0xB6:
{ {
uint8_t Value = 0; uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value); g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value; *(uint32_t *)Reg = Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
case 0xB7: case 0xB7:
{ {
uint16_t Value = 0; uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value); g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value; *(uint32_t *)Reg = Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
case 0xBE: case 0xBE:
{ {
uint8_t Value = 0; uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value); g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(int32_t *)Reg = (int8_t)Value; *(int32_t *)Reg = (int8_t)Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
case 0xBF: case 0xBF:
{ {
uint16_t Value = 0; uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value); g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(int32_t *)Reg = (int16_t)Value; *(int32_t *)Reg = (int16_t)Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
default: default:
if (HaveDebugger()) if (HaveDebugger())
{ {
@ -211,13 +211,13 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
switch (*(TypePos + 1)) switch (*(TypePos + 1))
{ {
case 0x8B: case 0x8B:
{ {
uint16_t Value = 0; uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value); g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value; *(uint32_t *)Reg = Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
case 0x89: case 0x89:
g_MMU->SH_NonMemory((MemAddress | 0x80000000) ^ 2, *(uint16_t *)Reg); g_MMU->SH_NonMemory((MemAddress | 0x80000000) ^ 2, *(uint16_t *)Reg);
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
@ -247,13 +247,13 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
case 0x8A: case 0x8A:
{ {
uint8_t Value = 0; uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value); g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value; *(uint32_t *)Reg = Value;
}
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
return true; return true;
}
case 0x8B: case 0x8B:
g_MMU->LW_NonMemory(MemAddress | 0x80000000, *((uint32_t *)Reg)); g_MMU->LW_NonMemory(MemAddress | 0x80000000, *((uint32_t *)Reg));
*context.Eip = (uint32_t)ReadPos; *context.Eip = (uint32_t)ReadPos;
@ -379,12 +379,23 @@ bool CMipsMemoryVM::FilterArmException(uint32_t MemAddress, mcontext_t & context
return false; return false;
} }
uint32_t * ArmRegisters[16] = uint32_t * ArmRegisters[16] = {
{ (uint32_t *)&context.arm_r0,
(uint32_t*)&context.arm_r0, (uint32_t*)&context.arm_r1, (uint32_t*)&context.arm_r2, (uint32_t*)&context.arm_r3, (uint32_t *)&context.arm_r1,
(uint32_t*)&context.arm_r4, (uint32_t*)&context.arm_r5, (uint32_t*)&context.arm_r6, (uint32_t*)&context.arm_r7, (uint32_t *)&context.arm_r2,
(uint32_t*)&context.arm_r8, (uint32_t*)&context.arm_r9, (uint32_t*)&context.arm_r10,(uint32_t*)&context.arm_fp, (uint32_t *)&context.arm_r3,
(uint32_t*)&context.arm_ip, (uint32_t*)&context.arm_sp, (uint32_t*)&context.arm_lr, (uint32_t*)&context.arm_pc, (uint32_t *)&context.arm_r4,
(uint32_t *)&context.arm_r5,
(uint32_t *)&context.arm_r6,
(uint32_t *)&context.arm_r7,
(uint32_t *)&context.arm_r8,
(uint32_t *)&context.arm_r9,
(uint32_t *)&context.arm_r10,
(uint32_t *)&context.arm_fp,
(uint32_t *)&context.arm_ip,
(uint32_t *)&context.arm_sp,
(uint32_t *)&context.arm_lr,
(uint32_t *)&context.arm_pc,
}; };
ArmThumbOpcode * OpCode = (ArmThumbOpcode *)context.arm_pc; ArmThumbOpcode * OpCode = (ArmThumbOpcode *)context.arm_pc;
@ -569,9 +580,9 @@ bool CMipsMemoryVM::SetupSegvHandler(void)
return sigaction(SIGSEGV, &sig_act, nullptr) == 0; return sigaction(SIGSEGV, &sig_act, nullptr) == 0;
} }
void CMipsMemoryVM::segv_handler(int signal, siginfo_t *siginfo, void *sigcontext) void CMipsMemoryVM::segv_handler(int signal, siginfo_t * siginfo, void * sigcontext)
{ {
ucontext_t *ucontext = (ucontext_t*)sigcontext; ucontext_t * ucontext = (ucontext_t *)sigcontext;
WriteTrace(TraceExceptionHandler, TraceNotice, "Segmentation fault!"); WriteTrace(TraceExceptionHandler, TraceNotice, "Segmentation fault!");
WriteTrace(TraceExceptionHandler, TraceNotice, "info.si_signo = %d", signal); WriteTrace(TraceExceptionHandler, TraceNotice, "info.si_signo = %d", signal);
@ -597,15 +608,15 @@ void CMipsMemoryVM::segv_handler(int signal, siginfo_t *siginfo, void *sigcontex
} }
X86_CONTEXT context; X86_CONTEXT context;
context.Edi = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EDI]; context.Edi = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EDI];
context.Esi = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ESI]; context.Esi = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ESI];
context.Ebx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EBX]; context.Ebx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EBX];
context.Edx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EDX]; context.Edx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EDX];
context.Ecx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ECX]; context.Ecx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ECX];
context.Eax = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EAX]; context.Eax = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EAX];
context.Eip = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EIP]; context.Eip = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EIP];
context.Esp = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ESP]; context.Esp = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ESP];
context.Ebp = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EBP]; context.Ebp = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EBP];
if (FilterX86Exception(MemAddress, context)) if (FilterX86Exception(MemAddress, context))
{ {
@ -641,15 +652,15 @@ int32_t CMipsMemoryVM::MemoryFilter(uint32_t dwExptCode, void * lpExceptionPoint
uint32_t MemAddress = (char *)lpEP->ExceptionRecord->ExceptionInformation[1] - (char *)g_MMU->Rdram(); uint32_t MemAddress = (char *)lpEP->ExceptionRecord->ExceptionInformation[1] - (char *)g_MMU->Rdram();
X86_CONTEXT context; X86_CONTEXT context;
context.Edi = (uint32_t*)&lpEP->ContextRecord->Edi; context.Edi = (uint32_t *)&lpEP->ContextRecord->Edi;
context.Esi = (uint32_t*)&lpEP->ContextRecord->Esi; context.Esi = (uint32_t *)&lpEP->ContextRecord->Esi;
context.Ebx = (uint32_t*)&lpEP->ContextRecord->Ebx; context.Ebx = (uint32_t *)&lpEP->ContextRecord->Ebx;
context.Edx = (uint32_t*)&lpEP->ContextRecord->Edx; context.Edx = (uint32_t *)&lpEP->ContextRecord->Edx;
context.Ecx = (uint32_t*)&lpEP->ContextRecord->Ecx; context.Ecx = (uint32_t *)&lpEP->ContextRecord->Ecx;
context.Eax = (uint32_t*)&lpEP->ContextRecord->Eax; context.Eax = (uint32_t *)&lpEP->ContextRecord->Eax;
context.Eip = (uint32_t*)&lpEP->ContextRecord->Eip; context.Eip = (uint32_t *)&lpEP->ContextRecord->Eip;
context.Esp = (uint32_t*)&lpEP->ContextRecord->Esp; context.Esp = (uint32_t *)&lpEP->ContextRecord->Esp;
context.Ebp = (uint32_t*)&lpEP->ContextRecord->Ebp; context.Ebp = (uint32_t *)&lpEP->ContextRecord->Ebp;
if (FilterX86Exception(MemAddress, context)) if (FilterX86Exception(MemAddress, context))
{ {
@ -658,7 +669,7 @@ int32_t CMipsMemoryVM::MemoryFilter(uint32_t dwExptCode, void * lpExceptionPoint
} }
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
#else #else
dwExptCode = dwExptCode; //unreferenced formal parameter dwExptCode = dwExptCode; //unreferenced formal parameter
lpExceptionPointer = lpExceptionPointer; // unreferenced formal parameter lpExceptionPointer = lpExceptionPointer; // unreferenced formal parameter
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
#endif #endif

View File

@ -117,7 +117,7 @@ enum LanguageStringID
POPUP_CHEATS = 213, POPUP_CHEATS = 213,
POPUP_GFX_PLUGIN = 214, POPUP_GFX_PLUGIN = 214,
POPUP_PLAYDISK = 215, POPUP_PLAYDISK = 215,
POPUP_ENHANCEMENTS = 216, POPUP_ENHANCEMENTS = 216,
// Selecting save slot // Selecting save slot
SAVE_SLOT_DEFAULT = 220, SAVE_SLOT_DEFAULT = 220,
@ -391,7 +391,7 @@ enum LanguageStringID
STR_FR_DLS = 701, STR_FR_DLS = 701,
STR_FR_PERCENT = 702, STR_FR_PERCENT = 702,
STR_FR_DLS_VIS = 703, STR_FR_DLS_VIS = 703,
STR_FR_NONE = 704, STR_FR_NONE = 704,
// Increase speed // Increase speed
STR_INSREASE_SPEED = 710, STR_INSREASE_SPEED = 710,
@ -593,10 +593,10 @@ enum LanguageStringID
ANDROID_ABOUT_LICENCE = 3017, ANDROID_ABOUT_LICENCE = 3017,
ANDROID_ABOUT_REVISION = 3018, ANDROID_ABOUT_REVISION = 3018,
ANDROID_ABOUT_TEXT = 3019, ANDROID_ABOUT_TEXT = 3019,
ANDROID_ABOUT_PJ64_AUTHORS = 3020, ANDROID_ABOUT_PJ64_AUTHORS = 3020,
ANDROID_DISCORD = 3021, ANDROID_DISCORD = 3021,
ANDROID_SUPPORT_PJ64 = 3022, ANDROID_SUPPORT_PJ64 = 3022,
ANDROID_REVIEW_PJ64 = 3023, ANDROID_REVIEW_PJ64 = 3023,
// In-game menu // In-game menu
ANDROID_MENU_SETTINGS = 3100, ANDROID_MENU_SETTINGS = 3100,

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#pragma warning(disable:4786) #pragma warning(disable : 4786)
#include <string>
#include <map>
#include <list> #include <list>
#include <map>
#include <stdint.h> #include <stdint.h>
#include <string>
typedef std::map<int32_t, std::string, std::less<int32_t> > LANG_STRINGS; typedef std::map<int32_t, std::string, std::less<int32_t>> LANG_STRINGS;
typedef LANG_STRINGS::value_type LANG_STR; typedef LANG_STRINGS::value_type LANG_STR;
struct LanguageFile struct LanguageFile
@ -28,11 +28,14 @@ public:
void SetLanguage(const char * LanguageName); void SetLanguage(const char * LanguageName);
bool LoadCurrentStrings(void); bool LoadCurrentStrings(void);
bool IsCurrentLang(LanguageFile & File); bool IsCurrentLang(LanguageFile & File);
bool IsLanguageLoaded(void) const { return m_LanguageLoaded; } bool IsLanguageLoaded(void) const
{
return m_LanguageLoaded;
}
private: private:
CLanguage(const CLanguage&); CLanguage(const CLanguage &);
CLanguage& operator=(const CLanguage&); CLanguage & operator=(const CLanguage &);
static void StaticResetStrings(CLanguage * _this) static void StaticResetStrings(CLanguage * _this)
{ {

View File

@ -1,9 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include <Common/Util.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/Notification.h> #include <Project64-core/Notification.h>
#include <Common/Util.h>
void CN64System::StartEmulationThead() void CN64System::StartEmulationThead()
{ {
WriteTrace(TraceN64System, TraceDebug, "Start"); WriteTrace(TraceN64System, TraceDebug, "Start");

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Enhancement/Enhancement.h> #include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
@ -196,7 +197,7 @@ CEnhancement::CEnhancement(const char * Ident, const char * Entry) :
// Gameshark code // Gameshark code
while (CurrentLine < Lines.size()) while (CurrentLine < Lines.size())
{ {
char TempFormat[128] = { 0 }; char TempFormat[128] = {0};
const char * Line = Lines[CurrentLine].c_str(); const char * Line = Lines[CurrentLine].c_str();
size_t LineLen = strlen(Line); size_t LineLen = strlen(Line);
if (LineLen >= (sizeof(TempFormat) / sizeof(TempFormat[0]))) if (LineLen >= (sizeof(TempFormat) / sizeof(TempFormat[0])))

View File

@ -36,21 +36,66 @@ public:
void SetOnByDefault(bool OnByDefault); void SetOnByDefault(bool OnByDefault);
void SetOverClock(bool OverClock, uint32_t OverClockModifier); void SetOverClock(bool OverClock, uint32_t OverClockModifier);
inline const std::string & GetName(void) const { return m_Name; } inline const std::string & GetName(void) const
inline const std::string & GetNameAndExtension(void) const { return m_NameAndExtension; } {
inline const std::string & GetAuthor(void) const { return m_Author; } return m_Name;
inline const std::string & GetNote(void) const { return m_Note; } }
inline const CodeEntries & GetEntries(void) const { return m_Entries; } inline const std::string & GetNameAndExtension(void) const
inline const CodeOptions & GetOptions(void) const { return m_Options; } {
inline const PluginList & GetPluginList(void) const { return m_PluginList; } return m_NameAndExtension;
inline uint32_t CodeOptionSize(void) const { return m_CodeOptionSize; } }
inline bool Valid(void) const { return m_Valid; } inline const std::string & GetAuthor(void) const
inline bool Active(void) const { return m_Active; } {
inline bool GetOnByDefault(void) const { return m_OnByDefault; } return m_Author;
inline bool OverClock(void) const { return m_OverClock; } }
inline uint32_t OverClockModifier(void) const { return m_OverClockModifier; } inline const std::string & GetNote(void) const
bool OptionSelected() const { return (m_SelectedOption & 0xFFFF0000) == 0; } {
uint16_t SelectedOption() const { return (uint16_t)(m_SelectedOption & 0xFFFF); } return m_Note;
}
inline const CodeEntries & GetEntries(void) const
{
return m_Entries;
}
inline const CodeOptions & GetOptions(void) const
{
return m_Options;
}
inline const PluginList & GetPluginList(void) const
{
return m_PluginList;
}
inline uint32_t CodeOptionSize(void) const
{
return m_CodeOptionSize;
}
inline bool Valid(void) const
{
return m_Valid;
}
inline bool Active(void) const
{
return m_Active;
}
inline bool GetOnByDefault(void) const
{
return m_OnByDefault;
}
inline bool OverClock(void) const
{
return m_OverClock;
}
inline uint32_t OverClockModifier(void) const
{
return m_OverClockModifier;
}
bool OptionSelected() const
{
return (m_SelectedOption & 0xFFFF0000) == 0;
}
uint16_t SelectedOption() const
{
return (uint16_t)(m_SelectedOption & 0xFFFF);
}
private: private:
CEnhancement(); CEnhancement();

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Enhancement/EnhancementFile.h> #include <Project64-core/N64System/Enhancement/EnhancementFile.h>
#pragma warning(disable:4996) #pragma warning(disable : 4996)
CEnhancmentFile::CEnhancmentFile(const char * FileName, const char * Ident) : CEnhancmentFile::CEnhancmentFile(const char * FileName, const char * Ident) :
m_Ident(Ident), m_Ident(Ident),
@ -106,7 +106,7 @@ bool CEnhancmentFile::RemoveEnhancements(const char * Section)
return true; return true;
} }
bool CEnhancmentFile::GetName(const char * Section, std::string &Name) bool CEnhancmentFile::GetName(const char * Section, std::string & Name)
{ {
CGuard Guard(m_CS); CGuard Guard(m_CS);
if (!m_File.IsOpen()) if (!m_File.IsOpen())
@ -192,8 +192,14 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
do do
{ {
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; } if (result <= 1)
if (strlen(CleanLine(Input)) <= 1) { continue; } {
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
// We only care about sections // We only care about sections
char * CurrentSection = Input; char * CurrentSection = Input;
@ -203,9 +209,15 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
CurrentSection += 3; CurrentSection += 3;
} }
if (CurrentSection[0] != '[') { continue; } if (CurrentSection[0] != '[')
{
continue;
}
int lineEndPos = (int)strlen(CurrentSection) - 1; int lineEndPos = (int)strlen(CurrentSection) - 1;
if (CurrentSection[lineEndPos] != ']') { continue; } if (CurrentSection[lineEndPos] != ']')
{
continue;
}
// Take off the ']' from the end of the string // Take off the ']' from the end of the string
CurrentSection[lineEndPos] = 0; CurrentSection[lineEndPos] = 0;
CurrentSection += 1; CurrentSection += 1;
@ -236,9 +248,18 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
do do
{ {
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; } if (result <= 1)
if (strlen(CleanLine(Input)) <= 1) { continue; } {
if (Input[0] == '[') { break; } continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
if (Input[0] == '[')
{
break;
}
char * Pos = strchr(Input, '='); char * Pos = strchr(Input, '=');
if (Input[0] == '$') if (Input[0] == '$')
{ {
@ -323,7 +344,7 @@ void CEnhancmentFile::SaveCurrentSection(void)
} }
PluginList += List[i].c_str(); PluginList += List[i].c_str();
} }
Section += stdstr_f("Plugin List=%s%s", PluginList.c_str() , m_LineFeed); Section += stdstr_f("Plugin List=%s%s", PluginList.c_str(), m_LineFeed);
} }
if (Enhancement.GetOnByDefault()) if (Enhancement.GetOnByDefault())
{ {
@ -397,7 +418,10 @@ void CEnhancmentFile::SaveCurrentSection(void)
do do
{ {
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos); result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; } if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[') if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
{ {
EndPos = ((m_File.GetPosition() - DataSize) + ReadPos); EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);
@ -423,9 +447,12 @@ void CEnhancmentFile::SaveCurrentSection(void)
m_File.Write(Section.data(), (uint32_t)Section.length()); m_File.Write(Section.data(), (uint32_t)Section.length());
} }
int CEnhancmentFile::GetStringFromFile(char * & String, std::unique_ptr<char> & Data, int & MaxDataSize, int & DataSize, int & ReadPos) int CEnhancmentFile::GetStringFromFile(char *& String, std::unique_ptr<char> & Data, int & MaxDataSize, int & DataSize, int & ReadPos)
{ {
enum { BufferIncrease = 0x2000 }; enum
{
BufferIncrease = 0x2000
};
if (MaxDataSize == 0) if (MaxDataSize == 0)
{ {
ReadPos = 0; ReadPos = 0;
@ -542,7 +569,10 @@ const char * CEnhancmentFile::CleanLine(char * Line)
void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces) void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
{ {
enum { fIS_MvSize = 0x2000 }; enum
{
fIS_MvSize = 0x2000
};
unsigned char Data[fIS_MvSize + 1]; unsigned char Data[fIS_MvSize + 1];
int SizeToRead, result; int SizeToRead, result;
@ -558,7 +588,10 @@ void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
do do
{ {
SizeToRead = end - Pos; SizeToRead = end - Pos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; } if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
if (SizeToRead > 0) if (SizeToRead > 0)
{ {
m_File.Seek(SizeToRead * -1, CFileBase::current); m_File.Seek(SizeToRead * -1, CFileBase::current);
@ -582,7 +615,10 @@ void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
do do
{ {
SizeToRead = end - ReadPos; SizeToRead = end - ReadPos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; } if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
m_File.Seek(ReadPos, CFileBase::begin); m_File.Seek(ReadPos, CFileBase::begin);
m_File.Read(Data, SizeToRead); m_File.Read(Data, SizeToRead);
m_File.Seek(WritePos, CFileBase::begin); m_File.Seek(WritePos, CFileBase::begin);

View File

@ -1,19 +1,19 @@
#pragma once #pragma once
#include <Common/CriticalSection.h>
#include <Common/File.h>
#include <Project64-core/N64System/Enhancement/Enhancement.h> #include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <Project64-core/N64System/Enhancement/EnhancementList.h> #include <Project64-core/N64System/Enhancement/EnhancementList.h>
#include <Common/File.h> #include <map>
#include <Common/CriticalSection.h> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <map>
#include <vector> #include <vector>
#include <memory>
class CEnhancmentFile class CEnhancmentFile
{ {
struct insensitive_compare struct insensitive_compare
{ {
bool operator() (const std::string & a, const std::string & b) const bool operator()(const std::string & a, const std::string & b) const
{ {
return _stricmp(a.c_str(), b.c_str()) < 0; return _stricmp(a.c_str(), b.c_str()) < 0;
} }
@ -38,17 +38,20 @@ public:
void GetSections(SectionList & sections); void GetSections(SectionList & sections);
const char * FileName(void) const { return m_FileName.c_str(); } const char * FileName(void) const
{
return m_FileName.c_str();
}
private: private:
CEnhancmentFile(); CEnhancmentFile();
CEnhancmentFile(const CEnhancmentFile&); CEnhancmentFile(const CEnhancmentFile &);
CEnhancmentFile& operator=(const CEnhancmentFile&); CEnhancmentFile & operator=(const CEnhancmentFile &);
bool AddEnhancement(const CEnhancement & Details); bool AddEnhancement(const CEnhancement & Details);
void OpenFile(void); void OpenFile(void);
bool MoveToSection(const char * Section, bool ChangeCurrentSection); bool MoveToSection(const char * Section, bool ChangeCurrentSection);
int GetStringFromFile(char * & String, std::unique_ptr<char> & Data, int & MaxDataSize, int & DataSize, int & ReadPos); int GetStringFromFile(char *& String, std::unique_ptr<char> & Data, int & MaxDataSize, int & DataSize, int & ReadPos);
const char * CleanLine(char * Line); const char * CleanLine(char * Line);
void fInsertSpaces(int32_t Pos, int32_t NoOfSpaces); void fInsertSpaces(int32_t Pos, int32_t NoOfSpaces);
void ClearSectionPosList(long FilePos); void ClearSectionPosList(long FilePos);

View File

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <vector>
#include <string>
#include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <Common/Platform.h> #include <Common/Platform.h>
#include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <string>
#include <vector>
struct EnhancementItemList_compare struct EnhancementItemList_compare
{ {
bool operator() (const std::string & a, const std::string & b) const bool operator()(const std::string & a, const std::string & b) const
{ {
return _stricmp(a.c_str(), b.c_str()) < 0; return _stricmp(a.c_str(), b.c_str()) < 0;
} }

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Common/CriticalSection.h>
#include <Common/Thread.h>
#include <Project64-core/N64System/Enhancement/EnhancementFile.h> #include <Project64-core/N64System/Enhancement/EnhancementFile.h>
#include <Project64-core/N64System/Enhancement/EnhancementList.h> #include <Project64-core/N64System/Enhancement/EnhancementList.h>
#include <Common/Thread.h>
#include <Common/CriticalSection.h>
#include <map> #include <map>
#include <string> #include <string>
@ -36,17 +36,29 @@ private:
class GAMESHARK_CODE class GAMESHARK_CODE
{ {
public: public:
GAMESHARK_CODE(const GAMESHARK_CODE&); GAMESHARK_CODE(const GAMESHARK_CODE &);
GAMESHARK_CODE(uint32_t Command, uint16_t Value, bool HasDisableValue, uint16_t DisableValue); GAMESHARK_CODE(uint32_t Command, uint16_t Value, bool HasDisableValue, uint16_t DisableValue);
uint32_t Command(void) const { return m_Command; } uint32_t Command(void) const
uint16_t Value(void) const { return m_Value; } {
bool HasDisableValue(void) const { return m_HasDisableValue; } return m_Command;
uint16_t DisableValue(void) const { return m_DisableValue; } }
uint16_t Value(void) const
{
return m_Value;
}
bool HasDisableValue(void) const
{
return m_HasDisableValue;
}
uint16_t DisableValue(void) const
{
return m_DisableValue;
}
private: private:
GAMESHARK_CODE(); GAMESHARK_CODE();
GAMESHARK_CODE& operator=(const GAMESHARK_CODE&); GAMESHARK_CODE & operator=(const GAMESHARK_CODE &);
uint32_t m_Command; uint32_t m_Command;
uint16_t m_Value; uint16_t m_Value;
@ -86,7 +98,11 @@ private:
static uint32_t ConvertXP64Address(uint32_t Address); static uint32_t ConvertXP64Address(uint32_t Address);
static uint16_t ConvertXP64Value(uint16_t Value); static uint16_t ConvertXP64Value(uint16_t Value);
static uint32_t stScanFileThread(void * lpThreadParameter) { ((CEnhancements *)lpThreadParameter)->ScanFileThread(); return 0; } static uint32_t stScanFileThread(void * lpThreadParameter)
{
((CEnhancements *)lpThreadParameter)->ScanFileThread();
return 0;
}
CriticalSection m_CS; CriticalSection m_CS;
SectionFiles m_CheatFiles, m_EnhancementFiles; SectionFiles m_CheatFiles, m_EnhancementFiles;

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "FramePerSecond.h" #include "FramePerSecond.h"
#include <Project64-core/N64System/N64Types.h> #include <Project64-core/N64System/N64Types.h>
@ -86,7 +87,10 @@ void CFramePerSecond::UpdateDisplay(void)
} }
if (m_iFrameRateType == FR_DLs || m_iFrameRateType == FR_VIs_DLs) if (m_iFrameRateType == FR_DLs || m_iFrameRateType == FR_VIs_DLs)
{ {
if (DisplayString.length() > 0) { DisplayString += " "; } if (DisplayString.length() > 0)
{
DisplayString += " ";
}
DisplayString += stdstr_f(m_DlistFrameRate >= 0 ? "DL/s: %.1f" : "DL/s: -.--", m_DlistFrameRate); DisplayString += stdstr_f(m_DlistFrameRate >= 0 ? "DL/s: %.1f" : "DL/s: -.--", m_DlistFrameRate);
} }
g_Notify->DisplayMessage2(DisplayString.c_str()); g_Notify->DisplayMessage2(DisplayString.c_str());

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Common/HighResTimeStamp.h>
#include "../Settings/N64SystemSettings.h" #include "../Settings/N64SystemSettings.h"
#include <Common/HighResTimeStamp.h>
class CFramePerSecond : public CN64SystemSettings class CFramePerSecond : public CN64SystemSettings
{ {
@ -15,16 +15,19 @@ public:
void DisplayViCounter(int32_t FrameRateWhole, uint32_t FrameRateFraction); void DisplayViCounter(int32_t FrameRateWhole, uint32_t FrameRateFraction);
private: private:
CFramePerSecond(const CFramePerSecond&); CFramePerSecond(const CFramePerSecond &);
CFramePerSecond& operator=(const CFramePerSecond&); CFramePerSecond & operator=(const CFramePerSecond &);
static void FrameRateTypeChanged(CFramePerSecond * _this); static void FrameRateTypeChanged(CFramePerSecond * _this);
static void ScreenHertzChanged(CFramePerSecond * _this); static void ScreenHertzChanged(CFramePerSecond * _this);
void UpdateDisplay(void); void UpdateDisplay(void);
int32_t m_iFrameRateType, m_ScreenHertz; int32_t m_iFrameRateType, m_ScreenHertz;
enum { NoOfFrames = 7 }; enum
{
NoOfFrames = 7
};
HighResTimeStamp m_LastViFrame; HighResTimeStamp m_LastViFrame;
uint64_t m_ViFrames[NoOfFrames]; uint64_t m_ViFrames[NoOfFrames];

View File

@ -13,8 +13,8 @@ public:
private: private:
CInterpreterCPU(); CInterpreterCPU();
CInterpreterCPU(const CInterpreterCPU&); CInterpreterCPU(const CInterpreterCPU &);
CInterpreterCPU& operator=(const CInterpreterCPU&); CInterpreterCPU & operator=(const CInterpreterCPU &);
static R4300iOp::Func * m_R4300i_Opcode; static R4300iOp::Func * m_R4300i_Opcode;
}; };

View File

@ -2133,7 +2133,7 @@ void R4300iOp::COP1_BCTL()
__inline void Float_RoundToInteger32(int32_t * Dest, const float * Source, int RoundType) __inline void Float_RoundToInteger32(int32_t * Dest, const float * Source, int RoundType)
{ {
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4244) // warning C4244: disable conversion from 'float' to 'int32_t', possible loss of data #pragma warning(disable : 4244) // warning C4244: disable conversion from 'float' to 'int32_t', possible loss of data
if (RoundType == FE_TONEAREST) if (RoundType == FE_TONEAREST)
{ {
@ -2155,9 +2155,18 @@ __inline void Float_RoundToInteger32(int32_t * Dest, const float * Source, int R
*Dest = roundf(*Source); *Dest = roundf(*Source);
} }
} }
else if (RoundType == FE_TOWARDZERO) { *Dest = truncf(*Source); } else if (RoundType == FE_TOWARDZERO)
else if (RoundType == FE_UPWARD) { *Dest = ceilf(*Source); } {
else if (RoundType == FE_DOWNWARD) { *Dest = floorf(*Source); } *Dest = truncf(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceilf(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floorf(*Source);
}
#pragma warning(pop) #pragma warning(pop)
} }
@ -2165,7 +2174,7 @@ __inline void Float_RoundToInteger32(int32_t * Dest, const float * Source, int R
__inline void Float_RoundToInteger64(int64_t * Dest, const float * Source, int RoundType) __inline void Float_RoundToInteger64(int64_t * Dest, const float * Source, int RoundType)
{ {
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4244) // warning C4244: disable conversion from 'float' to 'int64_t', possible loss of data #pragma warning(disable : 4244) // warning C4244: disable conversion from 'float' to 'int64_t', possible loss of data
if (RoundType == FE_TONEAREST) if (RoundType == FE_TONEAREST)
{ {
@ -2187,9 +2196,18 @@ __inline void Float_RoundToInteger64(int64_t * Dest, const float * Source, int R
*Dest = roundf(*Source); *Dest = roundf(*Source);
} }
} }
else if (RoundType == FE_TOWARDZERO) { *Dest = truncf(*Source); } else if (RoundType == FE_TOWARDZERO)
else if (RoundType == FE_UPWARD) { *Dest = ceilf(*Source); } {
else if (RoundType == FE_DOWNWARD) { *Dest = floorf(*Source); } *Dest = truncf(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceilf(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floorf(*Source);
}
#pragma warning(pop) #pragma warning(pop)
} }
@ -2353,7 +2371,7 @@ void R4300iOp::COP1_S_CMP()
} }
condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) | condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) |
((m_Opcode.funct & 1) && unorded); ((m_Opcode.funct & 1) && unorded);
if (condition) if (condition)
{ {
@ -2370,7 +2388,7 @@ void R4300iOp::COP1_S_CMP()
__inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int RoundType) __inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int RoundType)
{ {
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4244) // warning C4244: disable conversion from 'double' to 'uint32_t', possible loss of data #pragma warning(disable : 4244) // warning C4244: disable conversion from 'double' to 'uint32_t', possible loss of data
if (RoundType == FE_TONEAREST) if (RoundType == FE_TONEAREST)
{ {
@ -2392,9 +2410,18 @@ __inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int
*Dest = round(*Source); *Dest = round(*Source);
} }
} }
else if (RoundType == FE_TOWARDZERO) { *Dest = trunc(*Source); } else if (RoundType == FE_TOWARDZERO)
else if (RoundType == FE_UPWARD) { *Dest = ceil(*Source); } {
else if (RoundType == FE_DOWNWARD) { *Dest = floor(*Source); } *Dest = trunc(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceil(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floor(*Source);
}
else else
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -2406,7 +2433,7 @@ __inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int
__inline void Double_RoundToInteger64(int64_t * Dest, const double * Source, int RoundType) __inline void Double_RoundToInteger64(int64_t * Dest, const double * Source, int RoundType)
{ {
#pragma warning(push) #pragma warning(push)
#pragma warning(disable:4244) // warning C4244: disable conversion from 'double' to 'uint64_t', possible loss of data #pragma warning(disable : 4244) // warning C4244: disable conversion from 'double' to 'uint64_t', possible loss of data
if (RoundType == FE_TONEAREST) if (RoundType == FE_TONEAREST)
{ {
@ -2428,9 +2455,18 @@ __inline void Double_RoundToInteger64(int64_t * Dest, const double * Source, int
*Dest = round(*Source); *Dest = round(*Source);
} }
} }
else if (RoundType == FE_TOWARDZERO) { *Dest = trunc(*Source); } else if (RoundType == FE_TOWARDZERO)
else if (RoundType == FE_UPWARD) { *Dest = ceil(*Source); } {
else if (RoundType == FE_DOWNWARD) { *Dest = floor(*Source); } *Dest = trunc(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceil(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floor(*Source);
}
else else
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -2598,7 +2634,7 @@ void R4300iOp::COP1_D_CMP()
} }
condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) | condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) |
((m_Opcode.funct & 1) && unorded); ((m_Opcode.funct & 1) && unorded);
if (condition) if (condition)
{ {

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h> #include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/Settings/DebugSettings.h>
class R4300iOp : class R4300iOp :
public CLogging, public CLogging,
@ -10,7 +10,7 @@ class R4300iOp :
protected CSystemRegisters protected CSystemRegisters
{ {
public: public:
typedef void(*Func)(); typedef void (*Func)();
// Opcode functions // Opcode functions
static void J(); static void J();
@ -101,12 +101,12 @@ public:
static void SPECIAL_DADDU(); static void SPECIAL_DADDU();
static void SPECIAL_DSUB(); static void SPECIAL_DSUB();
static void SPECIAL_DSUBU(); static void SPECIAL_DSUBU();
static void SPECIAL_TGE(); static void SPECIAL_TGE();
static void SPECIAL_TGEU(); static void SPECIAL_TGEU();
static void SPECIAL_TLT(); static void SPECIAL_TLT();
static void SPECIAL_TLTU(); static void SPECIAL_TLTU();
static void SPECIAL_TEQ(); static void SPECIAL_TEQ();
static void SPECIAL_TNE(); static void SPECIAL_TNE();
static void SPECIAL_DSLL(); static void SPECIAL_DSLL();
static void SPECIAL_DSRL(); static void SPECIAL_DSRL();
static void SPECIAL_DSRA(); static void SPECIAL_DSRA();
@ -212,12 +212,12 @@ public:
static void ReservedInstruction(); static void ReservedInstruction();
static void UnknownOpcode(); static void UnknownOpcode();
static Func* BuildInterpreter(); static Func * BuildInterpreter();
static bool m_TestTimer; static bool m_TestTimer;
static R4300iOpcode m_Opcode; static R4300iOpcode m_Opcode;
static bool MemoryBreakpoint(); static bool MemoryBreakpoint();
protected: protected:
static void SPECIAL(); static void SPECIAL();

View File

@ -1,20 +1,22 @@
#include "stdafx.h" #include "stdafx.h"
#include "InterpreterOps32.h"
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
#include <Project64-core/Logging.h>
#include <Project64-core/Debugger.h>
#define TEST_COP1_USABLE_EXCEPTION \ #include "InterpreterOps32.h"
if ((g_Reg->STATUS_REGISTER & STATUS_CU1) == 0) {\ #include <Project64-core/Debugger.h>
g_Reg->DoCopUnusableException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP,1);\ #include <Project64-core/Logging.h>
g_System->m_PipelineStage = PIPELINE_STAGE_JUMP;\ #include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
g_System->m_JumpToLocation = (*_PROGRAM_COUNTER);\ #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
return;\ #include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
#define TEST_COP1_USABLE_EXCEPTION \
if ((g_Reg->STATUS_REGISTER & STATUS_CU1) == 0) \
{ \
g_Reg->DoCopUnusableException(g_System->m_PipelineStage == PIPELINE_STAGE_JUMP, 1); \
g_System->m_PipelineStage = PIPELINE_STAGE_JUMP; \
g_System->m_JumpToLocation = (*_PROGRAM_COUNTER); \
return; \
} }
R4300iOp32::Func * R4300iOp32::BuildInterpreter() R4300iOp32::Func * R4300iOp32::BuildInterpreter()
@ -1261,7 +1263,10 @@ void R4300iOp32::COP1_CF()
TEST_COP1_USABLE_EXCEPTION TEST_COP1_USABLE_EXCEPTION
if (m_Opcode.fs != 31 && m_Opcode.fs != 0) if (m_Opcode.fs != 31 && m_Opcode.fs != 0)
{ {
if (CDebugSettings::HaveDebugger()) { g_Notify->DisplayError("CFC1: what register are you writing to?"); } if (CDebugSettings::HaveDebugger())
{
g_Notify->DisplayError("CFC1: what register are you writing to?");
}
return; return;
} }
_GPR[m_Opcode.rt].W[0] = (int32_t)_FPCR[m_Opcode.fs]; _GPR[m_Opcode.rt].W[0] = (int32_t)_FPCR[m_Opcode.fs];

View File

@ -7,67 +7,67 @@ class R4300iOp32 :
{ {
public: public:
// Opcode functions // Opcode functions
static void JAL(); static void JAL();
static void BEQ(); static void BEQ();
static void BNE(); static void BNE();
static void BLEZ(); static void BLEZ();
static void BGTZ(); static void BGTZ();
static void ADDI(); static void ADDI();
static void ADDIU(); static void ADDIU();
static void SLTI(); static void SLTI();
static void SLTIU(); static void SLTIU();
static void ANDI(); static void ANDI();
static void ORI(); static void ORI();
static void XORI(); static void XORI();
static void LUI(); static void LUI();
static void BEQL(); static void BEQL();
static void BNEL(); static void BNEL();
static void BLEZL(); static void BLEZL();
static void BGTZL(); static void BGTZL();
static void LB(); static void LB();
static void LH(); static void LH();
static void LWL(); static void LWL();
static void LW(); static void LW();
static void LBU(); static void LBU();
static void LHU(); static void LHU();
static void LWR(); static void LWR();
static void LWU(); static void LWU();
static void LL(); static void LL();
// R4300i opcodes: Special // R4300i opcodes: Special
static void SPECIAL_SLL(); static void SPECIAL_SLL();
static void SPECIAL_SRL(); static void SPECIAL_SRL();
static void SPECIAL_SRA(); static void SPECIAL_SRA();
static void SPECIAL_SLLV(); static void SPECIAL_SLLV();
static void SPECIAL_SRLV(); static void SPECIAL_SRLV();
static void SPECIAL_SRAV(); static void SPECIAL_SRAV();
static void SPECIAL_JALR(); static void SPECIAL_JALR();
static void SPECIAL_ADD(); static void SPECIAL_ADD();
static void SPECIAL_ADDU(); static void SPECIAL_ADDU();
static void SPECIAL_SUB(); static void SPECIAL_SUB();
static void SPECIAL_SUBU(); static void SPECIAL_SUBU();
static void SPECIAL_AND(); static void SPECIAL_AND();
static void SPECIAL_OR(); static void SPECIAL_OR();
static void SPECIAL_NOR(); static void SPECIAL_NOR();
static void SPECIAL_SLT(); static void SPECIAL_SLT();
static void SPECIAL_SLTU(); static void SPECIAL_SLTU();
static void SPECIAL_TEQ(); static void SPECIAL_TEQ();
// R4300i opcodes: RegImm // R4300i opcodes: RegImm
static void REGIMM_BLTZ(); static void REGIMM_BLTZ();
static void REGIMM_BGEZ(); static void REGIMM_BGEZ();
static void REGIMM_BLTZL(); static void REGIMM_BLTZL();
static void REGIMM_BGEZL(); static void REGIMM_BGEZL();
static void REGIMM_BLTZAL(); static void REGIMM_BLTZAL();
static void REGIMM_BGEZAL(); static void REGIMM_BGEZAL();
// COP0 functions // COP0 functions
static void COP0_MF(); static void COP0_MF();
// COP1 functions // COP1 functions
static void COP1_MF(); static void COP1_MF();
static void COP1_CF(); static void COP1_CF();
static void COP1_DMT(); static void COP1_DMT();
static Func* BuildInterpreter(); static Func * BuildInterpreter();
}; };

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "AudioInterfaceHandler.h" #include "AudioInterfaceHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
AudioInterfaceReg::AudioInterfaceReg(uint32_t * _AudioInterface) : AudioInterfaceReg::AudioInterfaceReg(uint32_t * _AudioInterface) :
@ -199,9 +200,9 @@ void AudioInterfaceHandler::SetFrequency(uint32_t Dacrate, uint32_t System)
switch (System) switch (System)
{ {
case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break; case SYSTEM_PAL: Frequency = 49656530 / (Dacrate + 1); break;
case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break; case SYSTEM_MPAL: Frequency = 48628316 / (Dacrate + 1); break;
default: Frequency = 48681812 / (Dacrate + 1); break; default: Frequency = 48681812 / (Dacrate + 1); break;
} }
//nBlockAlign = 16 / 8 * 2; //nBlockAlign = 16 / 8 * 2;
@ -239,7 +240,7 @@ uint32_t AudioInterfaceHandler::GetLength(void)
uint32_t TimeLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt), Res = 0; uint32_t TimeLeft = g_SystemTimer->GetTimer(CSystemTimer::AiTimerInterrupt), Res = 0;
if (TimeLeft > 0) if (TimeLeft > 0)
{ {
Res = (TimeLeft / m_CountsPerByte)&~7; Res = (TimeLeft / m_CountsPerByte) & ~7;
} }
WriteTrace(TraceAudio, TraceDebug, "Done (res = %d, TimeLeft = %d)", Res, TimeLeft); WriteTrace(TraceAudio, TraceDebug, "Done (res = %d, TimeLeft = %d)", Res, TimeLeft);
return Res; return Res;
@ -301,4 +302,3 @@ void AudioInterfaceHandler::LenChanged()
} }
WriteTrace(TraceAudio, TraceDebug, "Done"); WriteTrace(TraceAudio, TraceDebug, "Done");
} }

View File

@ -1,14 +1,14 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h> #include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Settings\GameSettings.h> #include <Project64-core\Settings\GameSettings.h>
#include <Project64-core\Logging.h>
#include <stdint.h> #include <stdint.h>
enum enum
{ {
AI_STATUS_FIFO_FULL = 0x80000000, // Bit 31: Full AI_STATUS_FIFO_FULL = 0x80000000, // Bit 31: Full
AI_STATUS_DMA_BUSY = 0x40000000, // Bit 30: Busy AI_STATUS_DMA_BUSY = 0x40000000, // Bit 30: Busy
}; };
class AudioInterfaceReg class AudioInterfaceReg
@ -26,8 +26,8 @@ public:
private: private:
AudioInterfaceReg(); AudioInterfaceReg();
AudioInterfaceReg(const AudioInterfaceReg&); AudioInterfaceReg(const AudioInterfaceReg &);
AudioInterfaceReg& operator=(const AudioInterfaceReg&); AudioInterfaceReg & operator=(const AudioInterfaceReg &);
}; };
class CRegisters; class CRegisters;
@ -60,8 +60,14 @@ private:
AudioInterfaceHandler(const AudioInterfaceHandler &); AudioInterfaceHandler(const AudioInterfaceHandler &);
AudioInterfaceHandler & operator=(const AudioInterfaceHandler &); AudioInterfaceHandler & operator=(const AudioInterfaceHandler &);
static void stSystemReset(AudioInterfaceHandler * _this) { _this->SystemReset(); } static void stSystemReset(AudioInterfaceHandler * _this)
static void stLoadedGameState(AudioInterfaceHandler * _this) { _this->LoadedGameState(); } {
_this->SystemReset();
}
static void stLoadedGameState(AudioInterfaceHandler * _this)
{
_this->LoadedGameState();
}
void LoadedGameState(void); void LoadedGameState(void);
void SystemReset(void); void SystemReset(void);

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "CartridgeDomain1Address1Handler.h" #include "CartridgeDomain1Address1Handler.h"
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64Rom.h> #include <Project64-core\N64System\N64Rom.h>

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "CartridgeDomain1Address3Handler.h" #include "CartridgeDomain1Address3Handler.h"
CartridgeDomain1Address3Handler::CartridgeDomain1Address3Handler() CartridgeDomain1Address3Handler::CartridgeDomain1Address3Handler()

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "CartridgeDomain2Address1Handler.h" #include "CartridgeDomain2Address1Handler.h"
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\Mips\Disk.h> #include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\N64System\Mips\Register.h>
DiskInterfaceReg::DiskInterfaceReg(uint32_t * DiskInterface) : DiskInterfaceReg::DiskInterfaceReg(uint32_t * DiskInterface) :
ASIC_DATA(DiskInterface[0]), ASIC_DATA(DiskInterface[0]),

View File

@ -63,8 +63,8 @@ public:
private: private:
DiskInterfaceReg(); DiskInterfaceReg();
DiskInterfaceReg(const DiskInterfaceReg&); DiskInterfaceReg(const DiskInterfaceReg &);
DiskInterfaceReg& operator=(const DiskInterfaceReg&); DiskInterfaceReg & operator=(const DiskInterfaceReg &);
}; };
class CRegisters; class CRegisters;

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "CartridgeDomain2Address2Handler.h" #include "CartridgeDomain2Address2Handler.h"
#include <Project64-core\N64System\N64System.h> #include <Project64-core\N64System\N64System.h>
@ -91,7 +92,7 @@ bool CartridgeDomain2Address2Handler::DMARead()
} }
if (m_System.m_SaveUsing == SaveChip_Sram) if (m_System.m_SaveUsing == SaveChip_Sram)
{ {
m_Sram.DmaToSram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG,m_Reg.PI_CART_ADDR_REG - 0x08000000, PI_RD_LEN_REG); m_Sram.DmaToSram(m_MMU.Rdram() + m_Reg.PI_DRAM_ADDR_REG, m_Reg.PI_CART_ADDR_REG - 0x08000000, PI_RD_LEN_REG);
m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY; m_Reg.PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
m_Reg.PI_STATUS_REG |= PI_STATUS_INTERRUPT; m_Reg.PI_STATUS_REG |= PI_STATUS_INTERRUPT;
m_Reg.MI_INTR_REG |= MI_INTR_PI; m_Reg.MI_INTR_REG |= MI_INTR_PI;

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Project64-core\N64System\SaveType\Sram.h>
#include <Project64-core\N64System\SaveType\FlashRam.h>
#include <Project64-core\Settings\DebugSettings.h>
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\N64System\SaveType\FlashRam.h>
#include <Project64-core\N64System\SaveType\Sram.h>
#include <Project64-core\Settings\DebugSettings.h>
class CN64System; class CN64System;
class CMipsMemoryVM; class CMipsMemoryVM;
@ -21,8 +21,14 @@ public:
bool DMARead(); bool DMARead();
void DMAWrite(); void DMAWrite();
CSram & Sram(void) { return m_Sram; } CSram & Sram(void)
CFlashRam & FlashRam (void) { return m_FlashRam; } {
return m_Sram;
}
CFlashRam & FlashRam(void)
{
return m_FlashRam;
}
private: private:
CartridgeDomain2Address2Handler(void); CartridgeDomain2Address2Handler(void);

View File

@ -1,11 +1,12 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\Plugins\Plugin.h>
#include <Project64-core\Plugins\GFXPlugin.h>
#include <Project64-core\ExceptionHandler.h>
#include "SPRegistersHandler.h" #include "SPRegistersHandler.h"
#include <Project64-core\ExceptionHandler.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\Plugins\GFXPlugin.h>
#include <Project64-core\Plugins\Plugin.h>
DisplayControlRegHandler::DisplayControlRegHandler(CN64System & N64System, CPlugins * Plugins, CRegisters & Reg) : DisplayControlRegHandler::DisplayControlRegHandler(CN64System & N64System, CPlugins * Plugins, CRegisters & Reg) :
DisplayControlReg(Reg.m_Display_ControlReg), DisplayControlReg(Reg.m_Display_ControlReg),
@ -143,4 +144,3 @@ bool DisplayControlRegHandler::Write32(uint32_t Address, uint32_t Value, uint32_
} }
return true; return true;
} }

View File

@ -1,34 +1,34 @@
#pragma once #pragma once
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h>
#include "SPRegistersHandler.h"
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include "SPRegistersHandler.h"
#include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
enum enum
{ {
DPC_CLR_XBUS_DMEM_DMA = 0x0001, // Bit 0: Clear xbus_dmem_dma DPC_CLR_XBUS_DMEM_DMA = 0x0001, // Bit 0: Clear xbus_dmem_dma
DPC_SET_XBUS_DMEM_DMA = 0x0002, // Bit 1: Set xbus_dmem_dma DPC_SET_XBUS_DMEM_DMA = 0x0002, // Bit 1: Set xbus_dmem_dma
DPC_CLR_FREEZE = 0x0004, // Bit 2: Clear freeze DPC_CLR_FREEZE = 0x0004, // Bit 2: Clear freeze
DPC_SET_FREEZE = 0x0008, // Bit 3: Set freeze DPC_SET_FREEZE = 0x0008, // Bit 3: Set freeze
DPC_CLR_FLUSH = 0x0010, // Bit 4: Clear flush DPC_CLR_FLUSH = 0x0010, // Bit 4: Clear flush
DPC_SET_FLUSH = 0x0020, // Bit 5: Set flush DPC_SET_FLUSH = 0x0020, // Bit 5: Set flush
DPC_CLR_TMEM_CTR = 0x0040, // Bit 6: Clear TMEM CTR DPC_CLR_TMEM_CTR = 0x0040, // Bit 6: Clear TMEM CTR
DPC_CLR_PIPE_CTR = 0x0080, // Bit 7: Clear pipe CTR DPC_CLR_PIPE_CTR = 0x0080, // Bit 7: Clear pipe CTR
DPC_CLR_CMD_CTR = 0x0100, // Bit 8: Clear CMD CTR DPC_CLR_CMD_CTR = 0x0100, // Bit 8: Clear CMD CTR
DPC_CLR_CLOCK_CTR = 0x0200, // Bit 9: Clear clock CTR DPC_CLR_CLOCK_CTR = 0x0200, // Bit 9: Clear clock CTR
DPC_STATUS_XBUS_DMEM_DMA = 0x001, // Bit 0: xbus_dmem_dma DPC_STATUS_XBUS_DMEM_DMA = 0x001, // Bit 0: xbus_dmem_dma
DPC_STATUS_FREEZE = 0x002, // Bit 1: Freeze DPC_STATUS_FREEZE = 0x002, // Bit 1: Freeze
DPC_STATUS_FLUSH = 0x004, // Bit 2: Flush DPC_STATUS_FLUSH = 0x004, // Bit 2: Flush
DPC_STATUS_START_GCLK = 0x008, // Bit 3: Start GCLK DPC_STATUS_START_GCLK = 0x008, // Bit 3: Start GCLK
DPC_STATUS_TMEM_BUSY = 0x010, // Bit 4: TMEM busy DPC_STATUS_TMEM_BUSY = 0x010, // Bit 4: TMEM busy
DPC_STATUS_PIPE_BUSY = 0x020, // Bit 5: Pipe busy DPC_STATUS_PIPE_BUSY = 0x020, // Bit 5: Pipe busy
DPC_STATUS_CMD_BUSY = 0x040, // Bit 6: CMD busy DPC_STATUS_CMD_BUSY = 0x040, // Bit 6: CMD busy
DPC_STATUS_CBUF_READY = 0x080, // Bit 7: CBUF ready DPC_STATUS_CBUF_READY = 0x080, // Bit 7: CBUF ready
DPC_STATUS_DMA_BUSY = 0x100, // Bit 8: DMA busy DPC_STATUS_DMA_BUSY = 0x100, // Bit 8: DMA busy
DPC_STATUS_END_VALID = 0x200, // Bit 9: End valid DPC_STATUS_END_VALID = 0x200, // Bit 9: End valid
DPC_STATUS_START_VALID = 0x400, // Bit 10: Start valid DPC_STATUS_START_VALID = 0x400, // Bit 10: Start valid
}; };
class DisplayControlReg class DisplayControlReg
@ -48,8 +48,8 @@ public:
private: private:
DisplayControlReg(); DisplayControlReg();
DisplayControlReg(const DisplayControlReg&); DisplayControlReg(const DisplayControlReg &);
DisplayControlReg& operator=(const DisplayControlReg&); DisplayControlReg & operator=(const DisplayControlReg &);
}; };
class CN64System; class CN64System;

View File

@ -1,8 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include "ISViewerHandler.h" #include "ISViewerHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Common/path.h>
#include <Common/File.h> #include <Common/File.h>
#include <Common/path.h>
#include <Project64-core\N64System\N64System.h>
ISViewerHandler::ISViewerHandler(CN64System & System) : ISViewerHandler::ISViewerHandler(CN64System & System) :
m_hLogFile(nullptr), m_hLogFile(nullptr),
@ -70,10 +71,7 @@ uint32_t ISViewerHandler::Swap32by8(uint32_t Value)
#elif defined(__GNUC__) #elif defined(__GNUC__)
__builtin_bswap32(Value) __builtin_bswap32(Value)
#else #else
(Value & 0x000000FFul) << 24 (Value & 0x000000FFul) << 24 | (Value & 0x0000FF00ul) << 8 | (Value & 0x00FF0000ul) >> 8 | (Value & 0xFF000000ul) >> 24
| (Value & 0x0000FF00ul) << 8
| (Value & 0x00FF0000ul) >> 8
| (Value & 0xFF000000ul) >> 24
#endif #endif
; ;
return (Swapped & 0xFFFFFFFFul); return (Swapped & 0xFFFFFFFFul);

View File

@ -2,8 +2,8 @@
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Common/File.h> #include <Common/File.h>
#include <memory> #include <memory>
#include <vector>
#include <stdint.h> #include <stdint.h>
#include <vector>
class CN64System; class CN64System;
@ -21,7 +21,10 @@ private:
ISViewerHandler(const ISViewerHandler &); ISViewerHandler(const ISViewerHandler &);
ISViewerHandler & operator=(const ISViewerHandler &); ISViewerHandler & operator=(const ISViewerHandler &);
static void stSystemReset(ISViewerHandler * _this) { _this->SystemReset(); } static void stSystemReset(ISViewerHandler * _this)
{
_this->SystemReset();
}
static uint32_t Swap32by8(uint32_t Value); static uint32_t Swap32by8(uint32_t Value);
void SystemReset(void); void SystemReset(void);

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "MIPSInterfaceHandler.h" #include "MIPSInterfaceHandler.h"
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\SystemGlobals.h>
MIPSInterfaceReg::MIPSInterfaceReg(uint32_t * MipsInterface) : MIPSInterfaceReg::MIPSInterfaceReg(uint32_t * MipsInterface) :
MI_INIT_MODE_REG(MipsInterface[0]), MI_INIT_MODE_REG(MipsInterface[0]),

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
class MIPSInterfaceReg class MIPSInterfaceReg
@ -19,8 +19,8 @@ public:
private: private:
MIPSInterfaceReg(); MIPSInterfaceReg();
MIPSInterfaceReg(const MIPSInterfaceReg&); MIPSInterfaceReg(const MIPSInterfaceReg &);
MIPSInterfaceReg& operator=(const MIPSInterfaceReg&); MIPSInterfaceReg & operator=(const MIPSInterfaceReg &);
}; };
class CRegisters; class CRegisters;

View File

@ -1,14 +1,15 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64Disk.h>
#include <Project64-core\Debugger.h>
#include "PeripheralInterfaceHandler.h" #include "PeripheralInterfaceHandler.h"
#include <Common\MemoryManagement.h> #include <Common\MemoryManagement.h>
#include <Project64-core\Debugger.h>
#include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64Disk.h>
#include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h>
PeripheralInterfaceReg::PeripheralInterfaceReg(uint32_t * PeripheralInterface) : PeripheralInterfaceReg::PeripheralInterfaceReg(uint32_t * PeripheralInterface) :
PI_DRAM_ADDR_REG(PeripheralInterface[0]), PI_DRAM_ADDR_REG(PeripheralInterface[0]),
@ -216,7 +217,7 @@ void PeripheralInterfaceHandler::PI_DMA_READ()
} }
// PI_STATUS_REG |= PI_STATUS_DMA_BUSY; // PI_STATUS_REG |= PI_STATUS_DMA_BUSY;
uint32_t PI_RD_LEN = ((PI_RD_LEN_REG) & 0x00FFFFFFul) + 1; uint32_t PI_RD_LEN = ((PI_RD_LEN_REG)&0x00FFFFFFul) + 1;
if ((PI_RD_LEN & 1) != 0) if ((PI_RD_LEN & 1) != 0)
{ {
PI_RD_LEN += 1; PI_RD_LEN += 1;

View File

@ -1,8 +1,9 @@
#pragma once #pragma once
#include <Project64-core\Settings\GameSettings.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h>
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core/Logging.h>
#include <Project64-core/N64System/MemoryHandler/MIPSInterfaceHandler.h>
#include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/Settings/GameSettings.h>
#include <stdint.h> #include <stdint.h>
class PeripheralInterfaceReg class PeripheralInterfaceReg
@ -29,10 +30,11 @@ public:
private: private:
PeripheralInterfaceReg(); PeripheralInterfaceReg();
PeripheralInterfaceReg(const PeripheralInterfaceReg&); PeripheralInterfaceReg(const PeripheralInterfaceReg &);
PeripheralInterfaceReg& operator=(const PeripheralInterfaceReg&); PeripheralInterfaceReg & operator=(const PeripheralInterfaceReg &);
}; };
class CN64System;
class CRegisters; class CRegisters;
class CMipsMemoryVM; class CMipsMemoryVM;
class CartridgeDomain2Address2Handler; class CartridgeDomain2Address2Handler;
@ -68,8 +70,14 @@ private:
PeripheralInterfaceHandler(const PeripheralInterfaceHandler &); PeripheralInterfaceHandler(const PeripheralInterfaceHandler &);
PeripheralInterfaceHandler & operator=(const PeripheralInterfaceHandler &); PeripheralInterfaceHandler & operator=(const PeripheralInterfaceHandler &);
static void stSystemReset(PeripheralInterfaceHandler * _this) { _this->SystemReset(); } static void stSystemReset(PeripheralInterfaceHandler * _this)
static void stLoadedGameState(PeripheralInterfaceHandler * _this) { _this->LoadedGameState(); } {
_this->SystemReset();
}
static void stLoadedGameState(PeripheralInterfaceHandler * _this)
{
_this->LoadedGameState();
}
void PI_DMA_READ(); void PI_DMA_READ();
void PI_DMA_WRITE(); void PI_DMA_WRITE();

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "PifRamHandler.h" #include "PifRamHandler.h"
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h> #include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
@ -79,10 +80,7 @@ uint32_t PifRamHandler::swap32by8(uint32_t word)
#elif defined(__GNUC__) #elif defined(__GNUC__)
__builtin_bswap32(word) __builtin_bswap32(word)
#else #else
(word & 0x000000FFul) << 24 (word & 0x000000FFul) << 24 | (word & 0x0000FF00ul) << 8 | (word & 0x00FF0000ul) >> 8 | (word & 0xFF000000ul) >> 24
| (word & 0x0000FF00ul) << 8
| (word & 0x00FF0000ul) >> 8
| (word & 0xFF000000ul) >> 24
#endif #endif
; ;
return (swapped & 0xFFFFFFFFul); return (swapped & 0xFFFFFFFFul);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
class CMipsMemoryVM; class CMipsMemoryVM;

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\N64System\Mips\Register.h>
#include "RDRAMInterfaceHandler.h" #include "RDRAMInterfaceHandler.h"
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\SystemGlobals.h>
RDRAMInterfaceReg::RDRAMInterfaceReg(uint32_t * RdramInterface) : RDRAMInterfaceReg::RDRAMInterfaceReg(uint32_t * RdramInterface) :
RI_MODE_REG(RdramInterface[0]), RI_MODE_REG(RdramInterface[0]),

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
class RDRAMInterfaceReg class RDRAMInterfaceReg

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "RDRAMRegistersHandler.h" #include "RDRAMRegistersHandler.h"
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
class RDRAMRegistersReg class RDRAMRegistersReg
@ -24,8 +24,8 @@ public:
private: private:
RDRAMRegistersReg(); RDRAMRegistersReg();
RDRAMRegistersReg(const RDRAMRegistersReg&); RDRAMRegistersReg(const RDRAMRegistersReg &);
RDRAMRegistersReg& operator=(const RDRAMRegistersReg&); RDRAMRegistersReg & operator=(const RDRAMRegistersReg &);
}; };
class CRegisters; class CRegisters;

View File

@ -1,8 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include "RomMemoryHandler.h" #include "RomMemoryHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64Rom.h> #include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
RomMemoryHandler::RomMemoryHandler(CN64System & System, CRegisters & Reg, CN64Rom & Rom) : RomMemoryHandler::RomMemoryHandler(CN64System & System, CRegisters & Reg, CN64Rom & Rom) :
@ -41,7 +42,7 @@ bool RomMemoryHandler::Read32(uint32_t Address, uint32_t & Value)
case 0x1000000C: LogMessage("%08X: read from ROM release offset (%08X)", m_PC, Value); break; case 0x1000000C: LogMessage("%08X: read from ROM release offset (%08X)", m_PC, Value); break;
case 0x10000010: LogMessage("%08X: read from ROM CRC1 (%08X)", m_PC, Value); break; case 0x10000010: LogMessage("%08X: read from ROM CRC1 (%08X)", m_PC, Value); break;
case 0x10000014: LogMessage("%08X: read from ROM CRC2 (%08X)", m_PC, Value); break; case 0x10000014: LogMessage("%08X: read from ROM CRC2 (%08X)", m_PC, Value); break;
default: LogMessage("%08X: read from ROM header 0x%X (%08X)", m_PC, ReadAddr & 0xFF, Value); break; default: LogMessage("%08X: read from ROM header 0x%X (%08X)", m_PC, ReadAddr & 0xFF, Value); break;
} }
} }
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
class CRegisters; class CRegisters;
@ -23,14 +23,20 @@ public:
private: private:
RomMemoryHandler(); RomMemoryHandler();
RomMemoryHandler(const RomMemoryHandler&); RomMemoryHandler(const RomMemoryHandler &);
RomMemoryHandler& operator=(const RomMemoryHandler&); RomMemoryHandler & operator=(const RomMemoryHandler &);
void SystemReset(void); void SystemReset(void);
void LoadedGameState(void); void LoadedGameState(void);
static void stSystemReset(RomMemoryHandler * _this) { _this->SystemReset(); } static void stSystemReset(RomMemoryHandler * _this)
static void stLoadedGameState(RomMemoryHandler * _this) { _this->LoadedGameState(); } {
_this->SystemReset();
}
static void stLoadedGameState(RomMemoryHandler * _this)
{
_this->LoadedGameState();
}
uint32_t & m_PC; uint32_t & m_PC;
CRegisters & m_Reg; CRegisters & m_Reg;

View File

@ -1,8 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include "SPRegistersHandler.h" #include "SPRegistersHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h> #include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
SPRegistersReg::SPRegistersReg(uint32_t * SignalProcessorInterface) : SPRegistersReg::SPRegistersReg(uint32_t * SignalProcessorInterface) :
@ -109,7 +110,7 @@ bool SPRegistersHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask
switch (Address & 0x1FFFFFFF) switch (Address & 0x1FFFFFFF)
{ {
case 0x04040000: SP_MEM_ADDR_REG = (SP_MEM_ADDR_REG & ~Mask) | (MaskedValue); break; case 0x04040000: SP_MEM_ADDR_REG = (SP_MEM_ADDR_REG & ~Mask) | (MaskedValue); break;
case 0x04040004: SP_DRAM_ADDR_REG = (SP_DRAM_ADDR_REG & ~Mask) | (MaskedValue); break; case 0x04040004: SP_DRAM_ADDR_REG = (SP_DRAM_ADDR_REG & ~Mask) | (MaskedValue); break;
case 0x04040008: case 0x04040008:
SP_RD_LEN_REG = MaskedValue; SP_RD_LEN_REG = MaskedValue;
SP_DMA_READ(); SP_DMA_READ();
@ -119,36 +120,111 @@ bool SPRegistersHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask
SP_DMA_WRITE(); SP_DMA_WRITE();
break; break;
case 0x04040010: case 0x04040010:
if ((MaskedValue & SP_CLR_HALT) != 0) { SP_STATUS_REG &= ~SP_STATUS_HALT; } if ((MaskedValue & SP_CLR_HALT) != 0)
if ((MaskedValue & SP_SET_HALT) != 0) { SP_STATUS_REG |= SP_STATUS_HALT; } {
if ((MaskedValue & SP_CLR_BROKE) != 0) { SP_STATUS_REG &= ~SP_STATUS_BROKE; } SP_STATUS_REG &= ~SP_STATUS_HALT;
}
if ((MaskedValue & SP_SET_HALT) != 0)
{
SP_STATUS_REG |= SP_STATUS_HALT;
}
if ((MaskedValue & SP_CLR_BROKE) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_BROKE;
}
if ((MaskedValue & SP_CLR_INTR) != 0) if ((MaskedValue & SP_CLR_INTR) != 0)
{ {
MI_INTR_REG &= ~MI_INTR_SP; MI_INTR_REG &= ~MI_INTR_SP;
m_RspIntrReg &= ~MI_INTR_SP; m_RspIntrReg &= ~MI_INTR_SP;
m_Reg.CheckInterrupts(); m_Reg.CheckInterrupts();
} }
if ((MaskedValue & SP_SET_INTR) != 0) { if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); } } if ((MaskedValue & SP_SET_INTR) != 0)
if ((MaskedValue & SP_CLR_SSTEP) != 0) { SP_STATUS_REG &= ~SP_STATUS_SSTEP; } {
if ((MaskedValue & SP_SET_SSTEP) != 0) { SP_STATUS_REG |= SP_STATUS_SSTEP; } if (BreakOnUnhandledMemory())
if ((MaskedValue & SP_CLR_INTR_BREAK) != 0) { SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK; } {
if ((MaskedValue & SP_SET_INTR_BREAK) != 0) { SP_STATUS_REG |= SP_STATUS_INTR_BREAK; } g_Notify->BreakPoint(__FILE__, __LINE__);
if ((MaskedValue & SP_CLR_SIG0) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG0; } }
if ((MaskedValue & SP_SET_SIG0) != 0) { SP_STATUS_REG |= SP_STATUS_SIG0; } }
if ((MaskedValue & SP_CLR_SIG1) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG1; } if ((MaskedValue & SP_CLR_SSTEP) != 0)
if ((MaskedValue & SP_SET_SIG1) != 0) { SP_STATUS_REG |= SP_STATUS_SIG1; } {
if ((MaskedValue & SP_CLR_SIG2) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG2; } SP_STATUS_REG &= ~SP_STATUS_SSTEP;
if ((MaskedValue & SP_SET_SIG2) != 0) { SP_STATUS_REG |= SP_STATUS_SIG2; } }
if ((MaskedValue & SP_CLR_SIG3) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG3; } if ((MaskedValue & SP_SET_SSTEP) != 0)
if ((MaskedValue & SP_SET_SIG3) != 0) { SP_STATUS_REG |= SP_STATUS_SIG3; } {
if ((MaskedValue & SP_CLR_SIG4) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG4; } SP_STATUS_REG |= SP_STATUS_SSTEP;
if ((MaskedValue & SP_SET_SIG4) != 0) { SP_STATUS_REG |= SP_STATUS_SIG4; } }
if ((MaskedValue & SP_CLR_SIG5) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG5; } if ((MaskedValue & SP_CLR_INTR_BREAK) != 0)
if ((MaskedValue & SP_SET_SIG5) != 0) { SP_STATUS_REG |= SP_STATUS_SIG5; } {
if ((MaskedValue & SP_CLR_SIG6) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG6; } SP_STATUS_REG &= ~SP_STATUS_INTR_BREAK;
if ((MaskedValue & SP_SET_SIG6) != 0) { SP_STATUS_REG |= SP_STATUS_SIG6; } }
if ((MaskedValue & SP_CLR_SIG7) != 0) { SP_STATUS_REG &= ~SP_STATUS_SIG7; } if ((MaskedValue & SP_SET_INTR_BREAK) != 0)
if ((MaskedValue & SP_SET_SIG7) != 0) { SP_STATUS_REG |= SP_STATUS_SIG7; } {
SP_STATUS_REG |= SP_STATUS_INTR_BREAK;
}
if ((MaskedValue & SP_CLR_SIG0) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG0;
}
if ((MaskedValue & SP_SET_SIG0) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG0;
}
if ((MaskedValue & SP_CLR_SIG1) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG1;
}
if ((MaskedValue & SP_SET_SIG1) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG1;
}
if ((MaskedValue & SP_CLR_SIG2) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG2;
}
if ((MaskedValue & SP_SET_SIG2) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG2;
}
if ((MaskedValue & SP_CLR_SIG3) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG3;
}
if ((MaskedValue & SP_SET_SIG3) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG3;
}
if ((MaskedValue & SP_CLR_SIG4) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG4;
}
if ((MaskedValue & SP_SET_SIG4) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG4;
}
if ((MaskedValue & SP_CLR_SIG5) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG5;
}
if ((MaskedValue & SP_SET_SIG5) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG5;
}
if ((MaskedValue & SP_CLR_SIG6) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG6;
}
if ((MaskedValue & SP_SET_SIG6) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG6;
}
if ((MaskedValue & SP_CLR_SIG7) != 0)
{
SP_STATUS_REG &= ~SP_STATUS_SIG7;
}
if ((MaskedValue & SP_SET_SIG7) != 0)
{
SP_STATUS_REG |= SP_STATUS_SIG7;
}
if ((MaskedValue & SP_SET_SIG0) != 0 && RspAudioSignal()) if ((MaskedValue & SP_SET_SIG0) != 0 && RspAudioSignal())
{ {
MI_INTR_REG |= MI_INTR_SP; MI_INTR_REG |= MI_INTR_SP;
@ -218,7 +294,10 @@ void SPRegistersHandler::SP_DMA_READ()
if ((CopyLength + ReadPos) > m_MMU.RdramSize()) if ((CopyLength + ReadPos) > m_MMU.RdramSize())
{ {
int32_t CopyAmount = m_MMU.RdramSize() - ReadPos; int32_t CopyAmount = m_MMU.RdramSize() - ReadPos;
if (CopyAmount < 0) { CopyAmount = 0; } if (CopyAmount < 0)
{
CopyAmount = 0;
}
NullLen = CopyLength - CopyAmount; NullLen = CopyLength - CopyAmount;
if (CopyAmount > 0) if (CopyAmount > 0)

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "MemoryHandler.h"
#include "MIPSInterfaceHandler.h" #include "MIPSInterfaceHandler.h"
#include <Project64-core\Settings\GameSettings.h> #include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Settings\GameSettings.h>
#include <stdint.h> #include <stdint.h>
class SPRegistersReg class SPRegistersReg
@ -25,8 +25,8 @@ public:
private: private:
SPRegistersReg(); SPRegistersReg();
SPRegistersReg(const SPRegistersReg&); SPRegistersReg(const SPRegistersReg &);
SPRegistersReg& operator=(const SPRegistersReg&); SPRegistersReg & operator=(const SPRegistersReg &);
}; };
class CRegisters; class CRegisters;
@ -51,8 +51,14 @@ private:
SPRegistersHandler(const SPRegistersHandler &); SPRegistersHandler(const SPRegistersHandler &);
SPRegistersHandler & operator=(const SPRegistersHandler &); SPRegistersHandler & operator=(const SPRegistersHandler &);
static void stSystemReset(SPRegistersHandler * _this) { _this->SystemReset(); } static void stSystemReset(SPRegistersHandler * _this)
static void stLoadedGameState(SPRegistersHandler * _this) { _this->LoadedGameState(); } {
_this->SystemReset();
}
static void stLoadedGameState(SPRegistersHandler * _this)
{
_this->LoadedGameState();
}
void SP_DMA_READ(); void SP_DMA_READ();
void SP_DMA_WRITE(); void SP_DMA_WRITE();

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "SerialInterfaceHandler.h" #include "SerialInterfaceHandler.h"
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h> #include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "MemoryHandler.h"
#include "MIPSInterfaceHandler.h" #include "MIPSInterfaceHandler.h"
#include <Project64-core\Settings\DebugSettings.h> #include "MemoryHandler.h"
#include <Project64-core\Logging.h> #include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h> #include <stdint.h>
enum enum
@ -26,8 +26,8 @@ public:
private: private:
SerialInterfaceReg(); SerialInterfaceReg();
SerialInterfaceReg(const SerialInterfaceReg&); SerialInterfaceReg(const SerialInterfaceReg &);
SerialInterfaceReg& operator=(const SerialInterfaceReg&); SerialInterfaceReg & operator=(const SerialInterfaceReg &);
}; };
class CMipsMemoryVM; class CMipsMemoryVM;

View File

@ -1,11 +1,12 @@
#include "stdafx.h" #include "stdafx.h"
#include "VideoInterfaceHandler.h" #include "VideoInterfaceHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h> #include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\SystemTiming.h>
#include <Project64-core\N64System\Mips\Register.h> #include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\Plugin.h> #include <Project64-core\N64System\Mips\SystemTiming.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\Plugin.h>
VideoInterfaceReg::VideoInterfaceReg(uint32_t * VideoInterface) : VideoInterfaceReg::VideoInterfaceReg(uint32_t * VideoInterface) :
VI_STATUS_REG(VideoInterface[0]), VI_STATUS_REG(VideoInterface[0]),

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "MemoryHandler.h" #include "MemoryHandler.h"
#include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h> #include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Settings\GameSettings.h> #include <Project64-core\Settings\GameSettings.h>
#include <Project64-core\Logging.h>
#include <stdint.h> #include <stdint.h>
class VideoInterfaceReg class VideoInterfaceReg
@ -37,8 +37,8 @@ public:
private: private:
VideoInterfaceReg(); VideoInterfaceReg();
VideoInterfaceReg(const VideoInterfaceReg&); VideoInterfaceReg(const VideoInterfaceReg &);
VideoInterfaceReg& operator=(const VideoInterfaceReg&); VideoInterfaceReg & operator=(const VideoInterfaceReg &);
}; };
class CMipsMemoryVM; class CMipsMemoryVM;
@ -67,8 +67,14 @@ private:
VideoInterfaceHandler(const VideoInterfaceHandler &); VideoInterfaceHandler(const VideoInterfaceHandler &);
VideoInterfaceHandler & operator=(const VideoInterfaceHandler &); VideoInterfaceHandler & operator=(const VideoInterfaceHandler &);
static void stSystemReset(VideoInterfaceHandler * _this) { _this->SystemReset(); } static void stSystemReset(VideoInterfaceHandler * _this)
static void stLoadedGameState(VideoInterfaceHandler * _this) { _this->LoadedGameState(); } {
_this->SystemReset();
}
static void stLoadedGameState(VideoInterfaceHandler * _this)
{
_this->LoadedGameState();
}
void UpdateHalfLine(); void UpdateHalfLine();
void LoadedGameState(void); void LoadedGameState(void);

View File

@ -1,11 +1,12 @@
// Based on MAME's N64DD driver code by Happy_ // Based on MAME's N64DD driver code by Happy_
#include "stdafx.h" #include "stdafx.h"
#include "Disk.h" #include "Disk.h"
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/SystemTiming.h> #include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
@ -41,7 +42,7 @@ void DiskCommand()
time_t ltime; time_t ltime;
ltime = time(&ltime); ltime = time(&ltime);
struct tm result = { 0 }; struct tm result = {0};
localtime_r(&ltime, &result); localtime_r(&ltime, &result);
// BCD format needed for 64DD RTC // BCD format needed for 64DD RTC
@ -72,7 +73,8 @@ void DiskCommand()
break; break;
case 0x00080000: case 0x00080000:
// Unset disk changed bit // Unset disk changed bit
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG; break; g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG;
break;
case 0x00090000: case 0x00090000:
// Unset reset and disk changed bit bit // Unset reset and disk changed bit bit
g_Reg->ASIC_STATUS &= ~DD_STATUS_RST_STATE; g_Reg->ASIC_STATUS &= ~DD_STATUS_RST_STATE;
@ -84,16 +86,20 @@ void DiskCommand()
break; break;
case 0x00120000: case 0x00120000:
// RTC get year and month // RTC get year and month
g_Reg->ASIC_DATA = (year << 24) | (month << 16); break; g_Reg->ASIC_DATA = (year << 24) | (month << 16);
break;
case 0x00130000: case 0x00130000:
// RTC get day and hour // RTC get day and hour
g_Reg->ASIC_DATA = (day << 24) | (hour << 16); break; g_Reg->ASIC_DATA = (day << 24) | (hour << 16);
break;
case 0x00140000: case 0x00140000:
// RTC get minute and second // RTC get minute and second
g_Reg->ASIC_DATA = (minute << 24) | (second << 16); break; g_Reg->ASIC_DATA = (minute << 24) | (second << 16);
break;
case 0x001B0000: case 0x001B0000:
// Disk inquiry // Disk inquiry
g_Reg->ASIC_DATA = 0x00000000; break; g_Reg->ASIC_DATA = 0x00000000;
break;
} }
if (isSeek) if (isSeek)

View File

@ -15,13 +15,13 @@ extern bool dd_reset_hold;
extern uint32_t dd_track_offset, dd_zone; extern uint32_t dd_track_offset, dd_zone;
extern uint32_t dd_start_block, dd_current; extern uint32_t dd_start_block, dd_current;
const uint32_t ddZoneSecSize[16] = { 232, 216, 208, 192, 176, 160, 144, 128, const uint32_t ddZoneSecSize[16] = {232, 216, 208, 192, 176, 160, 144, 128,
216, 208, 192, 176, 160, 144, 128, 112 }; 216, 208, 192, 176, 160, 144, 128, 112};
const uint32_t ddZoneTrackSize[16] = { 158, 158, 149, 149, 149, 149, 149, 114, const uint32_t ddZoneTrackSize[16] = {158, 158, 149, 149, 149, 149, 149, 114,
158, 158, 149, 149, 149, 149, 149, 114 }; 158, 158, 149, 149, 149, 149, 149, 114};
const uint32_t ddStartOffset[16] = const uint32_t ddStartOffset[16] =
{ 0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0, {0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0,
0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200 }; 0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200};
#define SECTORS_PER_BLOCK 85 #define SECTORS_PER_BLOCK 85
#define BLOCKS_PER_TRACK 2 #define BLOCKS_PER_TRACK 2

View File

@ -5,12 +5,12 @@
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html // GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include "stdafx.h" #include "stdafx.h"
#include "GBCart.h" #include "GBCart.h"
#include <time.h>
#include <memory> #include <memory>
#include <time.h>
static void read_gb_cart_normal(struct gb_cart* gb_cart, uint16_t address, uint8_t* data) static void read_gb_cart_normal(struct gb_cart * gb_cart, uint16_t address, uint8_t * data)
{ {
uint16_t offset; uint16_t offset;
@ -45,7 +45,7 @@ static void read_gb_cart_normal(struct gb_cart* gb_cart, uint16_t address, uint8
} }
} }
static void write_gb_cart_normal(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_normal(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
uint16_t offset; uint16_t offset;
if ((address >= 0xA000) && (address <= 0xBFFF)) if ((address >= 0xA000) && (address <= 0xBFFF))
@ -68,7 +68,7 @@ static void write_gb_cart_normal(struct gb_cart* gb_cart, uint16_t address, cons
} }
} }
static void read_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, uint8_t* data) static void read_gb_cart_mbc1(struct gb_cart * gb_cart, uint16_t address, uint8_t * data)
{ {
size_t offset; size_t offset;
@ -97,7 +97,7 @@ static void read_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, uint8_t
} }
} }
static void write_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_mbc1(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
size_t offset; size_t offset;
@ -108,7 +108,7 @@ static void write_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, const
} }
else if ((address >= 0x2000) && (address <= 0x3FFF)) // ROM bank select else if ((address >= 0x2000) && (address <= 0x3FFF)) // ROM bank select
{ {
gb_cart->rom_bank &= 0x60; // Keep MSB gb_cart->rom_bank &= 0x60; // Keep MSB
gb_cart->rom_bank |= data[0] & 0x1F; gb_cart->rom_bank |= data[0] & 0x1F;
// Emulate quirk: 0x00 -> 0x01, 0x20 -> 0x21, 0x40->0x41, 0x60 -> 0x61 // Emulate quirk: 0x00 -> 0x01, 0x20 -> 0x21, 0x40->0x41, 0x60 -> 0x61
@ -139,14 +139,14 @@ static void write_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, const
gb_cart->ram_bank_mode = data[0] & 0x01; gb_cart->ram_bank_mode = data[0] & 0x01;
if (gb_cart->ram_bank_mode) if (gb_cart->ram_bank_mode)
{ {
gb_cart->ram_bank = gb_cart->rom_bank >> 5; // Set the RAM bank to the "magic bits" gb_cart->ram_bank = gb_cart->rom_bank >> 5; // Set the RAM bank to the "magic bits"
gb_cart->rom_bank &= 0x1F; // Zero out bits 5 and 6 to keep consistency gb_cart->rom_bank &= 0x1F; // Zero out bits 5 and 6 to keep consistency
} }
else else
{ {
gb_cart->rom_bank &= 0x1F; gb_cart->rom_bank &= 0x1F;
gb_cart->rom_bank |= (gb_cart->ram_bank << 5); gb_cart->rom_bank |= (gb_cart->ram_bank << 5);
gb_cart->ram_bank = 0x00; // We can only reach RAM page 0 gb_cart->ram_bank = 0x00; // We can only reach RAM page 0
} }
} }
} }
@ -163,7 +163,7 @@ static void write_gb_cart_mbc1(struct gb_cart* gb_cart, uint16_t address, const
} }
} }
static void read_gb_cart_mbc2(struct gb_cart* gb_cart, uint16_t address, uint8_t* data) static void read_gb_cart_mbc2(struct gb_cart * gb_cart, uint16_t address, uint8_t * data)
{ {
size_t offset; size_t offset;
@ -192,7 +192,7 @@ static void read_gb_cart_mbc2(struct gb_cart* gb_cart, uint16_t address, uint8_t
} }
} }
static void write_gb_cart_mbc2(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_mbc2(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
size_t offset; size_t offset;
@ -228,36 +228,42 @@ static void write_gb_cart_mbc2(struct gb_cart* gb_cart, uint16_t address, const
} }
} }
void memoryUpdateMBC3Clock(struct gb_cart* gb_cart) void memoryUpdateMBC3Clock(struct gb_cart * gb_cart)
{ {
time_t now = time(nullptr); time_t now = time(nullptr);
time_t diff = now - gb_cart->rtc_last_time; time_t diff = now - gb_cart->rtc_last_time;
if (diff > 0) { if (diff > 0)
{
// Update the clock according to the last update time // Update the clock according to the last update time
gb_cart->rtc_data[0] += (int)(diff % 60); gb_cart->rtc_data[0] += (int)(diff % 60);
if (gb_cart->rtc_data[0] > 59) { if (gb_cart->rtc_data[0] > 59)
{
gb_cart->rtc_data[0] -= 60; gb_cart->rtc_data[0] -= 60;
gb_cart->rtc_data[1]++; gb_cart->rtc_data[1]++;
} }
diff /= 60; diff /= 60;
gb_cart->rtc_data[1] += (int)(diff % 60); gb_cart->rtc_data[1] += (int)(diff % 60);
if (gb_cart->rtc_data[1] > 59) { if (gb_cart->rtc_data[1] > 59)
{
gb_cart->rtc_data[1] -= 60; gb_cart->rtc_data[1] -= 60;
gb_cart->rtc_data[2]++; gb_cart->rtc_data[2]++;
} }
diff /= 60; diff /= 60;
gb_cart->rtc_data[2] += (int)(diff % 24); gb_cart->rtc_data[2] += (int)(diff % 24);
if (gb_cart->rtc_data[2] > 23) { if (gb_cart->rtc_data[2] > 23)
{
gb_cart->rtc_data[2] -= 24; gb_cart->rtc_data[2] -= 24;
gb_cart->rtc_data[3]++; gb_cart->rtc_data[3]++;
} }
diff /= 24; diff /= 24;
gb_cart->rtc_data[3] += (int)(diff & 0xFFFFFFFF); gb_cart->rtc_data[3] += (int)(diff & 0xFFFFFFFF);
if (gb_cart->rtc_data[3] > 255) { if (gb_cart->rtc_data[3] > 255)
if (gb_cart->rtc_data[3] > 511) { {
if (gb_cart->rtc_data[3] > 511)
{
gb_cart->rtc_data[3] %= 512; gb_cart->rtc_data[3] %= 512;
gb_cart->rtc_data[3] |= 0x80; gb_cart->rtc_data[3] |= 0x80;
} }
@ -267,7 +273,7 @@ void memoryUpdateMBC3Clock(struct gb_cart* gb_cart)
gb_cart->rtc_last_time = now; gb_cart->rtc_last_time = now;
} }
static void read_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, uint8_t* data) static void read_gb_cart_mbc3(struct gb_cart * gb_cart, uint16_t address, uint8_t * data)
{ {
size_t offset; size_t offset;
@ -317,7 +323,7 @@ static void read_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, uint8_t
} }
} }
static void write_gb_cart_mbc3(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_mbc3(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
uint8_t bank; uint8_t bank;
size_t offset; size_t offset;
@ -422,11 +428,11 @@ static void read_gb_cart_mbc5(struct gb_cart * gb_cart, uint16_t address, uint8_
} }
} }
static void write_gb_cart_mbc5(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_mbc5(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
size_t offset; size_t offset;
if ((address >= 0x0000) && (address <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on if ((address >= 0x0000) && (address <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on
{ {
// Enable / Disable RAM -- NOT WORKING -- // Enable / Disable RAM -- NOT WORKING --
gb_cart->ram_enabled = (data[0] & 0x0F) == 0x0A; gb_cart->ram_enabled = (data[0] & 0x0F) == 0x0A;
@ -511,11 +517,11 @@ static void read_gb_cart_pocket_cam(struct gb_cart * gb_cart, uint16_t address,
} }
} }
static void write_gb_cart_pocket_cam(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) static void write_gb_cart_pocket_cam(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
size_t offset; size_t offset;
if ((address >= 0x0000) && (address <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on if ((address >= 0x0000) && (address <= 0x1FFF)) // We shouldn't be able to read/write to RAM unless this is toggled on
{ {
// Enable / Disable RAM // Enable / Disable RAM
gb_cart->ram_enabled = (data[0] & 0x0F) == 0x0A; gb_cart->ram_enabled = (data[0] & 0x0F) == 0x0A;
@ -603,46 +609,45 @@ enum gbcart_extra_devices
struct parsed_cart_type struct parsed_cart_type
{ {
void(*read_gb_cart)(struct gb_cart*, uint16_t, uint8_t*); void (*read_gb_cart)(struct gb_cart *, uint16_t, uint8_t *);
void(*write_gb_cart)(struct gb_cart*, uint16_t, const uint8_t*); void (*write_gb_cart)(struct gb_cart *, uint16_t, const uint8_t *);
unsigned int extra_devices; unsigned int extra_devices;
}; };
static const struct parsed_cart_type* parse_cart_type(uint8_t cart_type) static const struct parsed_cart_type * parse_cart_type(uint8_t cart_type)
{ {
#define MBC(x) read_gb_cart_ ## x, write_gb_cart_ ## x #define MBC(x) read_gb_cart_##x, write_gb_cart_##x
static const struct parsed_cart_type GB_CART_TYPES[] = static const struct parsed_cart_type GB_CART_TYPES[] =
{ {
{ MBC(normal), GED_NONE }, {MBC(normal), GED_NONE},
{ MBC(mbc1), GED_NONE }, {MBC(mbc1), GED_NONE},
{ MBC(mbc1), GED_RAM }, {MBC(mbc1), GED_RAM},
{ MBC(mbc1), GED_RAM | GED_BATTERY }, {MBC(mbc1), GED_RAM | GED_BATTERY},
{ MBC(mbc2), GED_NONE }, {MBC(mbc2), GED_NONE},
{ MBC(mbc2), GED_BATTERY }, {MBC(mbc2), GED_BATTERY},
{ MBC(normal), GED_RAM }, {MBC(normal), GED_RAM},
{ MBC(normal), GED_RAM | GED_BATTERY }, {MBC(normal), GED_RAM | GED_BATTERY},
{ MBC(mmm01), GED_NONE }, {MBC(mmm01), GED_NONE},
{ MBC(mmm01), GED_RAM }, {MBC(mmm01), GED_RAM},
{ MBC(mmm01), GED_RAM | GED_BATTERY }, {MBC(mmm01), GED_RAM | GED_BATTERY},
{ MBC(mbc3), GED_BATTERY | GED_RTC }, {MBC(mbc3), GED_BATTERY | GED_RTC},
{ MBC(mbc3), GED_RAM | GED_BATTERY | GED_RTC }, {MBC(mbc3), GED_RAM | GED_BATTERY | GED_RTC},
{ MBC(mbc3), GED_NONE }, {MBC(mbc3), GED_NONE},
{ MBC(mbc3), GED_RAM }, {MBC(mbc3), GED_RAM},
{ MBC(mbc3), GED_RAM | GED_BATTERY }, {MBC(mbc3), GED_RAM | GED_BATTERY},
{ MBC(mbc4), GED_NONE }, {MBC(mbc4), GED_NONE},
{ MBC(mbc4), GED_RAM }, {MBC(mbc4), GED_RAM},
{ MBC(mbc4), GED_RAM | GED_BATTERY }, {MBC(mbc4), GED_RAM | GED_BATTERY},
{ MBC(mbc5), GED_NONE }, {MBC(mbc5), GED_NONE},
{ MBC(mbc5), GED_RAM }, {MBC(mbc5), GED_RAM},
{ MBC(mbc5), GED_RAM | GED_BATTERY }, {MBC(mbc5), GED_RAM | GED_BATTERY},
{ MBC(mbc5), GED_RUMBLE }, {MBC(mbc5), GED_RUMBLE},
{ MBC(mbc5), GED_RAM | GED_RUMBLE }, {MBC(mbc5), GED_RAM | GED_RUMBLE},
{ MBC(mbc5), GED_RAM | GED_BATTERY | GED_RUMBLE }, {MBC(mbc5), GED_RAM | GED_BATTERY | GED_RUMBLE},
{ MBC(pocket_cam), GED_NONE }, {MBC(pocket_cam), GED_NONE},
{ MBC(bandai_tama5), GED_NONE }, {MBC(bandai_tama5), GED_NONE},
{ MBC(huc3), GED_NONE }, {MBC(huc3), GED_NONE},
{ MBC(huc1), GED_RAM | GED_BATTERY } {MBC(huc1), GED_RAM | GED_BATTERY}};
};
#undef MBC #undef MBC
switch (cart_type) switch (cart_type)
@ -676,13 +681,13 @@ static const struct parsed_cart_type* parse_cart_type(uint8_t cart_type)
case 0xFD: return &GB_CART_TYPES[26]; case 0xFD: return &GB_CART_TYPES[26];
case 0xFE: return &GB_CART_TYPES[27]; case 0xFE: return &GB_CART_TYPES[27];
case 0xFF: return &GB_CART_TYPES[28]; case 0xFF: return &GB_CART_TYPES[28];
default: return nullptr; default: return nullptr;
} }
} }
bool GBCart::init_gb_cart(struct gb_cart* gb_cart, const char* gb_file) bool GBCart::init_gb_cart(struct gb_cart * gb_cart, const char * gb_file)
{ {
const struct parsed_cart_type* type; const struct parsed_cart_type * type;
std::unique_ptr<uint8_t> rom; std::unique_ptr<uint8_t> rom;
size_t rom_size = 0; size_t rom_size = 0;
std::unique_ptr<uint8_t> ram; std::unique_ptr<uint8_t> ram;
@ -777,7 +782,7 @@ bool GBCart::init_gb_cart(struct gb_cart* gb_cart, const char* gb_file)
return true; return true;
} }
void GBCart::save_gb_cart(struct gb_cart* gb_cart) void GBCart::save_gb_cart(struct gb_cart * gb_cart)
{ {
CFile ramFile; CFile ramFile;
ramFile.Open(g_Settings->LoadStringVal(Game_Transferpak_Sav).c_str(), CFileBase::modeWrite | CFileBase::modeCreate); ramFile.Open(g_Settings->LoadStringVal(Game_Transferpak_Sav).c_str(), CFileBase::modeWrite | CFileBase::modeCreate);
@ -801,7 +806,7 @@ void GBCart::save_gb_cart(struct gb_cart* gb_cart)
ramFile.Close(); ramFile.Close();
} }
void GBCart::release_gb_cart(struct gb_cart* gb_cart) void GBCart::release_gb_cart(struct gb_cart * gb_cart)
{ {
if (gb_cart->rom != nullptr) if (gb_cart->rom != nullptr)
delete gb_cart->rom; delete gb_cart->rom;
@ -812,12 +817,12 @@ void GBCart::release_gb_cart(struct gb_cart* gb_cart)
memset(gb_cart, 0, sizeof(*gb_cart)); memset(gb_cart, 0, sizeof(*gb_cart));
} }
void GBCart::read_gb_cart(struct gb_cart* gb_cart, uint16_t address, uint8_t* data) void GBCart::read_gb_cart(struct gb_cart * gb_cart, uint16_t address, uint8_t * data)
{ {
gb_cart->read_gb_cart(gb_cart, address, data); gb_cart->read_gb_cart(gb_cart, address, data);
} }
void GBCart::write_gb_cart(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data) void GBCart::write_gb_cart(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data)
{ {
gb_cart->write_gb_cart(gb_cart, address, data); gb_cart->write_gb_cart(gb_cart, address, data);
} }

View File

@ -5,36 +5,36 @@
struct gb_cart struct gb_cart
{ {
uint8_t* rom; uint8_t * rom;
uint8_t* ram; uint8_t * ram;
size_t rom_size; size_t rom_size;
size_t ram_size; size_t ram_size;
unsigned int rom_bank; unsigned int rom_bank;
unsigned int ram_bank; unsigned int ram_bank;
bool has_rtc; bool has_rtc;
bool ram_bank_mode; bool ram_bank_mode;
bool ram_enabled; bool ram_enabled;
uint32_t rtc_latch; uint32_t rtc_latch;
int rtc_data[5]; int rtc_data[5];
int rtc_latch_data[5]; int rtc_latch_data[5];
time_t rtc_last_time; time_t rtc_last_time;
void(*read_gb_cart)(struct gb_cart* gb_cart, uint16_t address, uint8_t* data); void (*read_gb_cart)(struct gb_cart * gb_cart, uint16_t address, uint8_t * data);
void(*write_gb_cart)(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data); void (*write_gb_cart)(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data);
}; };
class GBCart class GBCart
{ {
public: public:
static bool init_gb_cart(struct gb_cart* gb_cart, const char* gb_file); static bool init_gb_cart(struct gb_cart * gb_cart, const char * gb_file);
static void release_gb_cart(struct gb_cart* gb_cart); static void release_gb_cart(struct gb_cart * gb_cart);
static void save_gb_cart(struct gb_cart* gb_cart); static void save_gb_cart(struct gb_cart * gb_cart);
static void read_gb_cart(struct gb_cart* gb_cart, uint16_t address, uint8_t* data); static void read_gb_cart(struct gb_cart * gb_cart, uint16_t address, uint8_t * data);
static void write_gb_cart(struct gb_cart* gb_cart, uint16_t address, const uint8_t* data); static void write_gb_cart(struct gb_cart * gb_cart, uint16_t address, const uint8_t * data);
}; };

View File

@ -1,20 +1,20 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h> #include <Common\MemoryManagement.h>
#include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\Debugger.h> #include <Project64-core\Debugger.h>
#include <Project64-core\ExceptionHandler.h> #include <Project64-core\ExceptionHandler.h>
#include <Common\MemoryManagement.h> #include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h>
#include <stdio.h> #include <stdio.h>
uint8_t * CMipsMemoryVM::m_Reserve1 = nullptr; uint8_t * CMipsMemoryVM::m_Reserve1 = nullptr;
uint8_t * CMipsMemoryVM::m_Reserve2 = nullptr; uint8_t * CMipsMemoryVM::m_Reserve2 = nullptr;
uint32_t CMipsMemoryVM::RegModValue; uint32_t CMipsMemoryVM::RegModValue;
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list #pragma warning(disable : 4355) // Disable 'this' : used in base member initializer list
CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) : CMipsMemoryVM::CMipsMemoryVM(CN64System & System, bool SavesReadOnly) :
CPifRam(SavesReadOnly), CPifRam(SavesReadOnly),
@ -92,7 +92,7 @@ void CMipsMemoryVM::Reset(bool /*EraseMemory*/)
if (g_Settings->LoadDword(Rdb_TLB_VAddrStart) != 0) if (g_Settings->LoadDword(Rdb_TLB_VAddrStart) != 0)
{ {
uint32_t Start = g_Settings->LoadDword(Rdb_TLB_VAddrStart); //0x7F000000; uint32_t Start = g_Settings->LoadDword(Rdb_TLB_VAddrStart); //0x7F000000;
uint32_t Len = g_Settings->LoadDword(Rdb_TLB_VAddrLen); //0x01000000; uint32_t Len = g_Settings->LoadDword(Rdb_TLB_VAddrLen); //0x01000000;
uint32_t PAddr = g_Settings->LoadDword(Rdb_TLB_PAddrStart); //0x10034b30; uint32_t PAddr = g_Settings->LoadDword(Rdb_TLB_PAddrStart); //0x10034b30;
uint32_t End = Start + Len; uint32_t End = Start + Len;
for (uint32_t Address = Start; Address < End; Address += 0x1000) for (uint32_t Address = Start; Address < End; Address += 0x1000)
@ -185,14 +185,14 @@ bool CMipsMemoryVM::Initialize(bool SyncSystem)
m_IMEM = (uint8_t *)(m_RDRAM + 0x04001000); m_IMEM = (uint8_t *)(m_RDRAM + 0x04001000);
CPifRam::Reset(); CPifRam::Reset();
m_MemoryReadMap = new size_t [0x100000]; m_MemoryReadMap = new size_t[0x100000];
if (m_MemoryReadMap == nullptr) if (m_MemoryReadMap == nullptr)
{ {
WriteTrace(TraceN64System, TraceError, "Failed to allocate m_MemoryReadMap (Size: 0x%X)", 0x100000 * sizeof(size_t)); WriteTrace(TraceN64System, TraceError, "Failed to allocate m_MemoryReadMap (Size: 0x%X)", 0x100000 * sizeof(size_t));
FreeMemory(); FreeMemory();
return false; return false;
} }
m_MemoryWriteMap = new size_t [0x100000]; m_MemoryWriteMap = new size_t[0x100000];
if (m_MemoryWriteMap == nullptr) if (m_MemoryWriteMap == nullptr)
{ {
WriteTrace(TraceN64System, TraceError, "Failed to allocate m_MemoryWriteMap (Size: 0x%X)", 0x100000 * sizeof(size_t)); WriteTrace(TraceN64System, TraceError, "Failed to allocate m_MemoryWriteMap (Size: 0x%X)", 0x100000 * sizeof(size_t));
@ -278,16 +278,16 @@ uint8_t * CMipsMemoryVM::MemoryPtr(uint32_t VAddr, uint32_t Size, bool Read)
uint32_t PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr; uint32_t PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr;
if ((PAddr + Size) < m_AllocatedRdramSize) if ((PAddr + Size) < m_AllocatedRdramSize)
{ {
return (uint8_t*)(m_RDRAM + PAddr); return (uint8_t *)(m_RDRAM + PAddr);
} }
if (PAddr >= 0x04000000 && (PAddr + Size) < 0x04001000) if (PAddr >= 0x04000000 && (PAddr + Size) < 0x04001000)
{ {
return (uint8_t*)(m_DMEM + (PAddr - 0x04000000)); return (uint8_t *)(m_DMEM + (PAddr - 0x04000000));
} }
if (PAddr >= 0x04001000 && (PAddr + Size) < 0x04002000) if (PAddr >= 0x04001000 && (PAddr + Size) < 0x04002000)
{ {
return (uint8_t*)(m_IMEM + (PAddr - 0x04001000)); return (uint8_t *)(m_IMEM + (PAddr - 0x04001000));
} }
if (Read && PAddr >= 0x10000000 && (PAddr + Size) < (0x10000000 + m_Rom.GetRomSize())) if (Read && PAddr >= 0x10000000 && (PAddr + Size) < (0x10000000 + m_Rom.GetRomSize()))
{ {
@ -296,7 +296,6 @@ uint8_t * CMipsMemoryVM::MemoryPtr(uint32_t VAddr, uint32_t Size, bool Read)
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return nullptr; return nullptr;
} }
bool CMipsMemoryVM::MemoryValue8(uint32_t VAddr, uint8_t & Value) bool CMipsMemoryVM::MemoryValue8(uint32_t VAddr, uint8_t & Value)
@ -317,7 +316,7 @@ bool CMipsMemoryVM::MemoryValue16(uint32_t VAddr, uint16_t & Value)
{ {
return false; return false;
} }
Value = *(uint16_t*)(ptr); Value = *(uint16_t *)(ptr);
return true; return true;
} }
@ -328,7 +327,7 @@ bool CMipsMemoryVM::MemoryValue32(uint32_t VAddr, uint32_t & Value)
{ {
return false; return false;
} }
Value = *(uint32_t*)(ptr); Value = *(uint32_t *)(ptr);
return true; return true;
} }
@ -339,8 +338,8 @@ bool CMipsMemoryVM::MemoryValue64(uint32_t VAddr, uint64_t & Value)
{ {
return false; return false;
} }
*((uint32_t*)(&Value) + 1) = *(uint32_t*)(ptr); *((uint32_t *)(&Value) + 1) = *(uint32_t *)(ptr);
*((uint32_t*)(&Value) + 0) = *(uint32_t*)(ptr + 4); *((uint32_t *)(&Value) + 0) = *(uint32_t *)(ptr + 4);
return true; return true;
} }
@ -362,7 +361,7 @@ bool CMipsMemoryVM::UpdateMemoryValue16(uint32_t VAddr, uint16_t Value)
{ {
return false; return false;
} }
*(uint16_t*)(ptr) = Value; *(uint16_t *)(ptr) = Value;
return true; return true;
} }
@ -373,11 +372,11 @@ bool CMipsMemoryVM::UpdateMemoryValue32(uint32_t VAddr, uint32_t Value)
{ {
return false; return false;
} }
*(uint32_t*)(ptr) = Value; *(uint32_t *)(ptr) = Value;
return true; return true;
} }
bool CMipsMemoryVM::LB_Memory(uint64_t VAddr, uint8_t& Value) bool CMipsMemoryVM::LB_Memory(uint64_t VAddr, uint8_t & Value)
{ {
if (!b32BitCore() && (uint64_t)((int32_t)VAddr) != VAddr) if (!b32BitCore() && (uint64_t)((int32_t)VAddr) != VAddr)
{ {
@ -390,10 +389,10 @@ bool CMipsMemoryVM::LB_Memory(uint64_t VAddr, uint8_t& Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t*)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
Value = *(uint8_t*)(MemoryPtr + (VAddr32 ^ 3)); Value = *(uint8_t *)(MemoryPtr + (VAddr32 ^ 3));
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -423,10 +422,10 @@ bool CMipsMemoryVM::LH_Memory(uint64_t VAddr, uint16_t & Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t*)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
Value = *(uint16_t*)(MemoryPtr + (VAddr32 ^ 2)); Value = *(uint16_t *)(MemoryPtr + (VAddr32 ^ 2));
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -455,10 +454,10 @@ bool CMipsMemoryVM::LW_Memory(uint64_t VAddr, uint32_t & Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
Value = *(uint32_t*)(MemoryPtr + VAddr32); Value = *(uint32_t *)(MemoryPtr + VAddr32);
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -470,7 +469,7 @@ bool CMipsMemoryVM::LW_Memory(uint64_t VAddr, uint32_t & Value)
return LW_NonMemory(VAddr32, Value); return LW_NonMemory(VAddr32, Value);
} }
bool CMipsMemoryVM::LD_Memory(uint64_t VAddr, uint64_t& Value) bool CMipsMemoryVM::LD_Memory(uint64_t VAddr, uint64_t & Value)
{ {
if (!b32BitCore() && (uint64_t)((int32_t)VAddr) != VAddr) if (!b32BitCore() && (uint64_t)((int32_t)VAddr) != VAddr)
{ {
@ -488,11 +487,11 @@ bool CMipsMemoryVM::LD_Memory(uint64_t VAddr, uint64_t& Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
*((uint32_t*)(&Value) + 1) = *(uint32_t*)(MemoryPtr + VAddr32); *((uint32_t *)(&Value) + 1) = *(uint32_t *)(MemoryPtr + VAddr32);
*((uint32_t*)(&Value) + 0) = *(uint32_t*)(MemoryPtr + VAddr32 + 4); *((uint32_t *)(&Value) + 0) = *(uint32_t *)(MemoryPtr + VAddr32 + 4);
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -516,10 +515,10 @@ bool CMipsMemoryVM::SB_Memory(uint64_t VAddr, uint32_t Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryWriteMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryWriteMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
*(uint8_t*)(MemoryPtr + (VAddr32 ^ 3)) = (uint8_t)Value; *(uint8_t *)(MemoryPtr + (VAddr32 ^ 3)) = (uint8_t)Value;
return true; return true;
} }
if (m_TLB_WriteMap[VAddr32 >> 12] == -1) if (m_TLB_WriteMap[VAddr32 >> 12] == -1)
@ -548,10 +547,10 @@ bool CMipsMemoryVM::SH_Memory(uint64_t VAddr, uint32_t Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryWriteMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryWriteMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
*(uint16_t*)(MemoryPtr + (VAddr32 ^ 2)) = (uint16_t)Value; *(uint16_t *)(MemoryPtr + (VAddr32 ^ 2)) = (uint16_t)Value;
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -581,10 +580,10 @@ bool CMipsMemoryVM::SW_Memory(uint64_t VAddr, uint32_t Value)
{ {
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryWriteMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryWriteMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
*(uint32_t*)(MemoryPtr + VAddr32) = Value; *(uint32_t *)(MemoryPtr + VAddr32) = Value;
return true; return true;
} }
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12]; uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -615,11 +614,11 @@ bool CMipsMemoryVM::SD_Memory(uint64_t VAddr, uint64_t Value)
return false; return false;
} }
uint8_t * MemoryPtr = (uint8_t*)m_MemoryWriteMap[VAddr32 >> 12]; uint8_t * MemoryPtr = (uint8_t *)m_MemoryWriteMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1) if (MemoryPtr != (uint8_t *)-1)
{ {
*(uint32_t*)(MemoryPtr + VAddr32 + 0) = *((uint32_t*)(&Value) + 1); *(uint32_t *)(MemoryPtr + VAddr32 + 0) = *((uint32_t *)(&Value) + 1);
*(uint32_t*)(MemoryPtr + VAddr32 + 4) = *((uint32_t*)(&Value)); *(uint32_t *)(MemoryPtr + VAddr32 + 4) = *((uint32_t *)(&Value));
return true; return true;
} }
if (m_TLB_WriteMap[VAddr32 >> 12] == -1) if (m_TLB_WriteMap[VAddr32 >> 12] == -1)
@ -635,7 +634,7 @@ bool CMipsMemoryVM::ValidVaddr(uint32_t VAddr) const
return m_TLB_ReadMap[VAddr >> 12] != -1; return m_TLB_ReadMap[VAddr >> 12] != -1;
} }
bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t &PAddr) const bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t & PAddr) const
{ {
if (m_TLB_ReadMap[VAddr >> 12] == -1) if (m_TLB_ReadMap[VAddr >> 12] == -1)
{ {
@ -792,7 +791,7 @@ bool CMipsMemoryVM::SB_NonMemory(uint32_t VAddr, uint32_t Value)
{ {
g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0xFFC, CRecompiler::Remove_ProtectedMem); g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0xFFC, CRecompiler::Remove_ProtectedMem);
::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE); ::ProtectMemory(m_RDRAM + (PAddr & ~0xFFF), 0xFFC, MEM_READWRITE);
*(uint8_t *)(m_RDRAM + (PAddr ^ 3)) = (uint8_t)Value; *(uint8_t *)(m_RDRAM + (PAddr ^ 3)) = (uint8_t)Value;
} }
break; break;
default: default:

View File

@ -1,9 +1,5 @@
#pragma once #pragma once
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Recompiler\RecompilerOps.h>
#include <Project64-core\N64System\Interpreter\InterpreterOps.h> #include <Project64-core\N64System\Interpreter\InterpreterOps.h>
#include <Project64-core\N64System\Mips\PifRam.h>
#include <Project64-core\N64System\SaveType\FlashRam.h>
#include <Project64-core\N64System\MemoryHandler\AudioInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\AudioInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address1Handler.h> #include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address1Handler.h>
#include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address3Handler.h> #include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address3Handler.h>
@ -17,9 +13,13 @@
#include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.h> #include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.h>
#include <Project64-core\N64System\MemoryHandler\RomMemoryHandler.h> #include <Project64-core\N64System\MemoryHandler\RomMemoryHandler.h>
#include <Project64-core\N64System\MemoryHandler\SerialInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\SPRegistersHandler.h> #include <Project64-core\N64System\MemoryHandler\SPRegistersHandler.h>
#include <Project64-core\N64System\MemoryHandler\SerialInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\VideoInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\VideoInterfaceHandler.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\PifRam.h>
#include <Project64-core\N64System\Recompiler\RecompilerOps.h>
#include <Project64-core\N64System\SaveType\FlashRam.h>
#include <Project64-core\Settings\GameSettings.h> #include <Project64-core\Settings\GameSettings.h>
#ifdef __arm__ #ifdef __arm__
@ -63,14 +63,35 @@ public:
bool Initialize(bool SyncSystem); bool Initialize(bool SyncSystem);
void Reset(bool EraseMemory); void Reset(bool EraseMemory);
uint8_t * Rdram() const { return m_RDRAM; } uint8_t * Rdram() const
uint32_t RdramSize() const { return m_AllocatedRdramSize; } {
uint8_t * Dmem() const { return m_DMEM; } return m_RDRAM;
uint8_t * Imem() const { return m_IMEM; } }
uint8_t * PifRam() { return &m_PifRam[0]; } uint32_t RdramSize() const
{
return m_AllocatedRdramSize;
}
uint8_t * Dmem() const
{
return m_DMEM;
}
uint8_t * Imem() const
{
return m_IMEM;
}
uint8_t * PifRam()
{
return &m_PifRam[0];
}
CSram & GetSram() { return m_CartridgeDomain2Address2Handler.Sram(); } CSram & GetSram()
CFlashRam & GetFlashRam() { return m_CartridgeDomain2Address2Handler.FlashRam(); } {
return m_CartridgeDomain2Address2Handler.Sram();
}
CFlashRam & GetFlashRam()
{
return m_CartridgeDomain2Address2Handler.FlashRam();
}
uint8_t * MemoryPtr(uint32_t VAddr, uint32_t Size, bool Read); uint8_t * MemoryPtr(uint32_t VAddr, uint32_t Size, bool Read);
@ -93,11 +114,11 @@ public:
bool SW_Memory(uint64_t VAddr, uint32_t Value); bool SW_Memory(uint64_t VAddr, uint32_t Value);
bool SD_Memory(uint64_t VAddr, uint64_t Value); bool SD_Memory(uint64_t VAddr, uint64_t Value);
int32_t MemoryFilter(uint32_t dwExptCode, void * lpExceptionPointer); int32_t MemoryFilter(uint32_t dwExptCode, void * lpExceptionPointer);
#ifndef _WIN32 #ifndef _WIN32
static bool SetupSegvHandler(void); static bool SetupSegvHandler(void);
static void segv_handler(int signal, siginfo_t *siginfo, void *sigcontext); static void segv_handler(int signal, siginfo_t * siginfo, void * sigcontext);
#endif #endif
void ClearMemoryWriteMap(uint32_t VAddr, uint32_t Length); void ClearMemoryWriteMap(uint32_t VAddr, uint32_t Length);
@ -116,14 +137,23 @@ public:
// Labels // Labels
const char * LabelName(uint32_t Address) const; const char * LabelName(uint32_t Address) const;
AudioInterfaceHandler & AudioInterface(void) { return m_AudioInterfaceHandler; } AudioInterfaceHandler & AudioInterface(void)
VideoInterfaceHandler & VideoInterface(void) { return m_VideoInterfaceHandler; } {
RomMemoryHandler & RomMemory(void) { return m_RomMemoryHandler; }; return m_AudioInterfaceHandler;
}
VideoInterfaceHandler & VideoInterface(void)
{
return m_VideoInterfaceHandler;
}
RomMemoryHandler & RomMemory(void)
{
return m_RomMemoryHandler;
};
private: private:
CMipsMemoryVM(); CMipsMemoryVM();
CMipsMemoryVM(const CMipsMemoryVM&); CMipsMemoryVM(const CMipsMemoryVM &);
CMipsMemoryVM& operator=(const CMipsMemoryVM&); CMipsMemoryVM & operator=(const CMipsMemoryVM &);
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
friend class CX86RecompilerOps; friend class CX86RecompilerOps;
@ -169,7 +199,7 @@ private:
#endif #endif
void FreeMemory(); void FreeMemory();
static uint8_t * m_Reserve1, *m_Reserve2; static uint8_t *m_Reserve1, *m_Reserve2;
CN64System & m_System; CN64System & m_System;
CRegisters & m_Reg; CRegisters & m_Reg;
AudioInterfaceHandler m_AudioInterfaceHandler; AudioInterfaceHandler m_AudioInterfaceHandler;
@ -188,7 +218,7 @@ private:
SerialInterfaceHandler m_SerialInterfaceHandler; SerialInterfaceHandler m_SerialInterfaceHandler;
SPRegistersHandler m_SPRegistersHandler; SPRegistersHandler m_SPRegistersHandler;
VideoInterfaceHandler m_VideoInterfaceHandler; VideoInterfaceHandler m_VideoInterfaceHandler;
uint8_t * m_RDRAM, *m_DMEM, *m_IMEM; uint8_t *m_RDRAM, *m_DMEM, *m_IMEM;
uint32_t m_AllocatedRdramSize; uint32_t m_AllocatedRdramSize;
CN64Rom & m_Rom; CN64Rom & m_Rom;

View File

@ -1,8 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "Mempak.h"
#include <stdio.h> #include "Mempak.h"
#include <Common/path.h> #include <Common/path.h>
#include <stdio.h>
CMempak::CMempak() CMempak::CMempak()
{ {
@ -10,7 +10,7 @@ CMempak::CMempak()
{ {
m_Formatted[i] = 0; m_Formatted[i] = 0;
m_SaveExists[i] = true; m_SaveExists[i] = true;
} }
memset(m_Mempaks, 0, sizeof(m_Mempaks)); memset(m_Mempaks, 0, sizeof(m_Mempaks));
} }
@ -67,6 +67,7 @@ void CMempak::LoadMempak(int32_t Control, bool Create)
void CMempak::Format(int32_t Control) void CMempak::Format(int32_t Control)
{ {
// clang-format off
static const uint8_t Initialize[] = { static const uint8_t Initialize[] = {
0x81, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x81, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@ -107,8 +108,9 @@ void CMempak::Format(int32_t Control)
0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03,
}; };
// clang-format on
memcpy(&m_Mempaks[Control][0], &Initialize[0], sizeof(Initialize)); memcpy(&m_Mempaks[Control][0], &Initialize[0], sizeof(Initialize));

View File

@ -11,8 +11,8 @@ public:
static uint8_t CalculateCrc(uint8_t * DataToCrc); static uint8_t CalculateCrc(uint8_t * DataToCrc);
private: private:
CMempak(const CMempak&); CMempak(const CMempak &);
CMempak& operator=(const CMempak&); CMempak & operator=(const CMempak &);
void LoadMempak(int32_t Control, bool Create); void LoadMempak(int32_t Control, bool Create);
void Format(int32_t Control); void Format(int32_t Control);

View File

@ -1,17 +1,17 @@
#include "stdafx.h" #include "stdafx.h"
#include <stdio.h> #include <stdio.h>
#include <Project64-core/Debugger.h>
#include <Project64-core/Logging.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/PifRam.h> #include <Project64-core/N64System/Mips/PifRam.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/Rumblepak.h>
#include <Project64-core/N64System/Mips/Transferpak.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/Plugins/ControllerPlugin.h> #include <Project64-core/Plugins/ControllerPlugin.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Mips/Transferpak.h>
#include <Project64-core/N64System/Mips/Rumblepak.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/Logging.h>
#include <Project64-core/Debugger.h>
#include <Project64-plugin-spec/Input.h> #include <Project64-plugin-spec/Input.h>
CPifRam::CPifRam(bool SavesReadOnly) : CPifRam::CPifRam(bool SavesReadOnly) :
@ -32,14 +32,16 @@ void CPifRam::Reset()
void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int32_t length) void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int32_t length)
{ {
// clang-format off
static char lut0[0x10] = { static char lut0[0x10] = {
0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1, 0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9 0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9,
}; };
static char lut1[0x10] = { static char lut1[0x10] = {
0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1, 0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9 0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9,
}; };
// clang-format on
char key, *lut; char key, *lut;
int32_t i, sgn, mag, mod; int32_t i, sgn, mag, mod;
@ -85,8 +87,11 @@ void CPifRam::PifRamRead()
break; break;
case 0xFD: CurPos = 0x40; break; case 0xFD: CurPos = 0x40; break;
case 0xFE: CurPos = 0x40; break; case 0xFE: CurPos = 0x40; break;
case 0xFF: break; case 0xFF:
case 0xB4: case 0x56: case 0xB8: break; case 0xB4:
case 0x56:
case 0xB8:
break;
default: default:
if ((m_PifRam[CurPos] & 0xC0) == 0) if ((m_PifRam[CurPos] & 0xC0) == 0)
{ {
@ -195,8 +200,11 @@ void CPifRam::PifRamWrite()
break; break;
case 0xFD: CurPos = 0x40; break; case 0xFD: CurPos = 0x40; break;
case 0xFE: CurPos = 0x40; break; case 0xFE: CurPos = 0x40; break;
case 0xFF: break; case 0xFF:
case 0xB4: case 0x56: case 0xB8: break; // ??? case 0xB4:
case 0x56:
case 0xB8:
break;
default: default:
if ((m_PifRam[CurPos] & 0xC0) == 0) if ((m_PifRam[CurPos] & 0xC0) == 0)
{ {
@ -305,8 +313,8 @@ void CPifRam::SI_DMA_READ()
AsciiData[0] = '\0'; AsciiData[0] = '\0';
} }
sprintf(Addon, "%02X %02X %02X %02X", sprintf(Addon, "%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]); m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(HexData, Addon); strcat(HexData, Addon);
if (((count + 1) % 4) != 0) if (((count + 1) % 4) != 0)
{ {
@ -315,8 +323,8 @@ void CPifRam::SI_DMA_READ()
} }
sprintf(Addon, "%c%c%c%c", sprintf(Addon, "%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]); m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(AsciiData, Addon); strcat(AsciiData, Addon);
if (((count + 1) % 4) == 0) if (((count + 1) % 4) == 0)
@ -327,9 +335,9 @@ void CPifRam::SI_DMA_READ()
LogMessage(""); LogMessage("");
} }
if(g_System->bRandomizeSIPIInterrupts()) if (g_System->bRandomizeSIPIInterrupts())
{ {
if(g_System->bDelaySI()) if (g_System->bDelaySI())
{ {
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900 + (g_Random->next() % 0x40), false); g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900 + (g_Random->next() % 0x40), false);
} }
@ -340,7 +348,7 @@ void CPifRam::SI_DMA_READ()
} }
else else
{ {
if(g_System->bDelaySI()) if (g_System->bDelaySI())
{ {
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false); g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false);
} }
@ -378,7 +386,8 @@ void CPifRam::SI_DMA_WRITE()
{ {
if (RdramPos < 0) if (RdramPos < 0)
{ {
m_PifRam[count] = 0; continue; m_PifRam[count] = 0;
continue;
} }
m_PifRam[count] = RDRAM[RdramPos ^ 3]; m_PifRam[count] = RDRAM[RdramPos ^ 3];
} }
@ -406,8 +415,8 @@ void CPifRam::SI_DMA_WRITE()
AsciiData[0] = '\0'; AsciiData[0] = '\0';
} }
sprintf(Addon, "%02X %02X %02X %02X", sprintf(Addon, "%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]); m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(HexData, Addon); strcat(HexData, Addon);
if (((count + 1) % 4) != 0) if (((count + 1) % 4) != 0)
{ {
@ -416,8 +425,8 @@ void CPifRam::SI_DMA_WRITE()
} }
sprintf(Addon, "%c%c%c%c", sprintf(Addon, "%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1], m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]); m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(AsciiData, Addon); strcat(AsciiData, Addon);
if (((count + 1) % 4) == 0) if (((count + 1) % 4) == 0)
@ -474,7 +483,8 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
case PLUGIN_RUMBLE_PAK: case PLUGIN_RUMBLE_PAK:
case PLUGIN_MEMPAK: case PLUGIN_MEMPAK:
case PLUGIN_RAW: case PLUGIN_RAW:
Command[5] = 1; break; Command[5] = 1;
break;
default: Command[5] = 0; break; default: Command[5] = 0; break;
} }
} }
@ -519,14 +529,19 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
if (Controllers[Control].Present != PRESENT_NONE) if (Controllers[Control].Present != PRESENT_NONE)
{ {
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0); uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
uint8_t* data = &Command[5]; uint8_t * data = &Command[5];
switch (Controllers[Control].Plugin) switch (Controllers[Control].Plugin)
{ {
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break; case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break;
case PLUGIN_MEMPAK: g_Mempak->ReadFrom(Control, address, data); break; case PLUGIN_MEMPAK: g_Mempak->ReadFrom(Control, address, data); break;
case PLUGIN_TRANSFER_PAK: Transferpak::ReadFrom((uint16_t)address, data); break; case PLUGIN_TRANSFER_PAK: Transferpak::ReadFrom((uint16_t)address, data); break;
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break; case PLUGIN_RAW:
if (g_Plugins->Control()->ControllerCommand)
{
g_Plugins->Control()->ControllerCommand(Control, Command);
}
break;
default: default:
memset(&Command[5], 0, 0x20); memset(&Command[5], 0, 0x20);
} }
@ -560,14 +575,19 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
if (Controllers[Control].Present != PRESENT_NONE) if (Controllers[Control].Present != PRESENT_NONE)
{ {
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0); uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
uint8_t* data = &Command[5]; uint8_t * data = &Command[5];
switch (Controllers[Control].Plugin) switch (Controllers[Control].Plugin)
{ {
case PLUGIN_MEMPAK: g_Mempak->WriteTo(Control, address, data); break; case PLUGIN_MEMPAK: g_Mempak->WriteTo(Control, address, data); break;
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break; case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break;
case PLUGIN_TRANSFER_PAK: Transferpak::WriteTo((uint16_t)address, data); break; case PLUGIN_TRANSFER_PAK: Transferpak::WriteTo((uint16_t)address, data); break;
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break; case PLUGIN_RAW:
if (g_Plugins->Control()->ControllerCommand)
{
g_Plugins->Control()->ControllerCommand(Control, Command);
}
break;
} }
if (Controllers[Control].Plugin != PLUGIN_RAW) if (Controllers[Control].Plugin != PLUGIN_RAW)
@ -603,7 +623,10 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{ {
if (bShowPifRamErrors()) if (bShowPifRamErrors())
{ {
if (Command[0] != 1 || Command[1] != 4) { g_Notify->DisplayError("What am I meant to do with this controller command?"); } if (Command[0] != 1 || Command[1] != 4)
{
g_Notify->DisplayError("What am I meant to do with this controller command?");
}
} }
const uint32_t buttons = g_BaseSystem->GetButtons(Control); const uint32_t buttons = g_BaseSystem->GetButtons(Control);
@ -615,7 +638,12 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{ {
switch (Controllers[Control].Plugin) switch (Controllers[Control].Plugin)
{ {
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break; case PLUGIN_RAW:
if (g_Plugins->Control()->ReadController)
{
g_Plugins->Control()->ReadController(Control, Command);
}
break;
} }
} }
break; break;
@ -624,7 +652,12 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{ {
switch (Controllers[Control].Plugin) switch (Controllers[Control].Plugin)
{ {
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break; case PLUGIN_RAW:
if (g_Plugins->Control()->ReadController)
{
g_Plugins->Control()->ReadController(Control, Command);
}
break;
} }
} }
break; break;
@ -647,8 +680,8 @@ void CPifRam::LogControllerPakData(const char * Description)
AsciiData[0] = '\0'; AsciiData[0] = '\0';
} }
sprintf(Addon, "%02X %02X %02X %02X", sprintf(Addon, "%02X %02X %02X %02X",
PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1], PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1],
PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3]); PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3]);
strcat(HexData, Addon); strcat(HexData, Addon);
if (((count + 1) % 4) != 0) if (((count + 1) % 4) != 0)
{ {

View File

@ -25,10 +25,13 @@ protected:
private: private:
CPifRam(); CPifRam();
CPifRam(const CPifRam&); CPifRam(const CPifRam &);
CPifRam& operator=(const CPifRam&); CPifRam & operator=(const CPifRam &);
enum { CHALLENGE_LENGTH = 0x20 }; enum
{
CHALLENGE_LENGTH = 0x20
};
void ProcessControllerCommand(int32_t Control, uint8_t * Command); void ProcessControllerCommand(int32_t Control, uint8_t * Command);
void ReadControllerCommand(int32_t Control, uint8_t * Command); void ReadControllerCommand(int32_t Control, uint8_t * Command);
void LogControllerPakData(const char * Description); void LogControllerPakData(const char * Description);

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Mips/Register.h>
#include "R4300iInstruction.h" #include "R4300iInstruction.h"
#include <Project64-core/N64System/Mips/Register.h>
R4300iInstruction::R4300iInstruction(uint32_t Address, uint32_t Instruction) : R4300iInstruction::R4300iInstruction(uint32_t Address, uint32_t Instruction) :
m_Address(Address) m_Address(Address)
@ -326,10 +327,22 @@ bool R4300iInstruction::DelaySlotEffectsCompare(uint32_t DelayInstruction) const
const char * R4300iInstruction::FPR_Type(uint32_t COP1OpCode) const char * R4300iInstruction::FPR_Type(uint32_t COP1OpCode)
{ {
if (COP1OpCode == R4300i_COP1_S) { return "S"; }; if (COP1OpCode == R4300i_COP1_S)
if (COP1OpCode == R4300i_COP1_D) { return "D"; }; {
if (COP1OpCode == R4300i_COP1_W) { return "W"; }; return "S";
if (COP1OpCode == R4300i_COP1_L) { return "L"; }; };
if (COP1OpCode == R4300i_COP1_D)
{
return "D";
};
if (COP1OpCode == R4300i_COP1_W)
{
return "W";
};
if (COP1OpCode == R4300i_COP1_L)
{
return "L";
};
return "?"; return "?";
} }
@ -1152,4 +1165,3 @@ void R4300iInstruction::DecodeCop1Name(void)
sprintf(m_Param, "0x%08X", m_Instruction.Value); sprintf(m_Param, "0x%08X", m_Instruction.Value);
} }
} }

View File

@ -16,8 +16,8 @@ public:
private: private:
R4300iInstruction(void); R4300iInstruction(void);
R4300iInstruction(const R4300iInstruction&); R4300iInstruction(const R4300iInstruction &);
R4300iInstruction& operator=(const R4300iInstruction&); R4300iInstruction & operator=(const R4300iInstruction &);
static const char * FPR_Type(uint32_t COP1OpCode); static const char * FPR_Type(uint32_t COP1OpCode);

View File

@ -50,12 +50,12 @@ union R4300iOpcode
unsigned : 6; unsigned : 6;
}; };
struct struct
{ {
unsigned : 6; unsigned : 6;
unsigned code : 20; unsigned code : 20;
unsigned : 6; unsigned : 6;
}; };
}; };
#pragma warning(pop) #pragma warning(pop)

View File

@ -1,8 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/Logging.h>
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/Logging.h>
const char * CRegName::GPR[32] = { const char * CRegName::GPR[32] = {
"R0", "R0",
@ -36,11 +37,10 @@ const char * CRegName::GPR[32] = {
"GP", "GP",
"SP", "SP",
"FP", "FP",
"RA" "RA",
}; };
const char *CRegName::GPR_Hi[32] = const char * CRegName::GPR_Hi[32] = {
{
"r0.HI", "r0.HI",
"at.HI", "at.HI",
"v0.HI", "v0.HI",
@ -72,11 +72,10 @@ const char *CRegName::GPR_Hi[32] =
"gp.HI", "gp.HI",
"sp.HI", "sp.HI",
"fp.HI", "fp.HI",
"ra.HI" "ra.HI",
}; };
const char *CRegName::GPR_Lo[32] = const char * CRegName::GPR_Lo[32] = {
{
"r0.LO", "r0.LO",
"at.LO", "at.LO",
"v0.LO", "v0.LO",
@ -108,11 +107,10 @@ const char *CRegName::GPR_Lo[32] =
"gp.LO", "gp.LO",
"sp.LO", "sp.LO",
"fp.LO", "fp.LO",
"ra.LO" "ra.LO",
}; };
const char * CRegName::Cop0[32] = const char * CRegName::Cop0[32] = {
{
"Index", "Index",
"Random", "Random",
"EntryLo0", "EntryLo0",
@ -144,11 +142,10 @@ const char * CRegName::Cop0[32] =
"TagLo", "TagLo",
"TagHi", "TagHi",
"ErrEPC", "ErrEPC",
"Reg31" "Reg31",
}; };
const char * CRegName::FPR[32] = const char * CRegName::FPR[32] = {
{
"F0", "F0",
"F1", "F1",
"F2", "F2",
@ -180,11 +177,10 @@ const char * CRegName::FPR[32] =
"F28", "F28",
"F29", "F29",
"F30", "F30",
"F31" "F31",
}; };
const char * CRegName::FPR_Ctrl[32] = const char * CRegName::FPR_Ctrl[32] = {
{
"Revision", "Revision",
"Unknown", "Unknown",
"Unknown", "Unknown",
@ -216,20 +212,20 @@ const char * CRegName::FPR_Ctrl[32] =
"Unknown", "Unknown",
"Unknown", "Unknown",
"Unknown", "Unknown",
"FCSR" "FCSR",
}; };
uint32_t * CSystemRegisters::_PROGRAM_COUNTER = nullptr; uint32_t * CSystemRegisters::_PROGRAM_COUNTER = nullptr;
MIPS_DWORD * CSystemRegisters::_GPR = nullptr; MIPS_DWORD * CSystemRegisters::_GPR = nullptr;
MIPS_DWORD * CSystemRegisters::_FPR = nullptr; MIPS_DWORD * CSystemRegisters::_FPR = nullptr;
uint64_t * CSystemRegisters::_CP0 = nullptr; uint64_t * CSystemRegisters::_CP0 = nullptr;
MIPS_DWORD * CSystemRegisters::_RegHI = nullptr; MIPS_DWORD * CSystemRegisters::_RegHI = nullptr;
MIPS_DWORD * CSystemRegisters::_RegLO = nullptr; MIPS_DWORD * CSystemRegisters::_RegLO = nullptr;
float ** CSystemRegisters::_FPR_S; float ** CSystemRegisters::_FPR_S;
double ** CSystemRegisters::_FPR_D; double ** CSystemRegisters::_FPR_D;
uint32_t * CSystemRegisters::_FPCR = nullptr; uint32_t * CSystemRegisters::_FPCR = nullptr;
uint32_t * CSystemRegisters::_LLBit = nullptr; uint32_t * CSystemRegisters::_LLBit = nullptr;
int32_t * CSystemRegisters::_RoundingModel = nullptr; int32_t * CSystemRegisters::_RoundingModel = nullptr;
CP0registers::CP0registers(uint64_t * _CP0) : CP0registers::CP0registers(uint64_t * _CP0) :
INDEX_REGISTER(_CP0[0]), INDEX_REGISTER(_CP0[0]),
@ -353,7 +349,7 @@ void CRegisters::Cop0_MT(uint32_t Reg, uint64_t Value)
if (LogCP0changes() && Reg <= 0x1F) if (LogCP0changes() && Reg <= 0x1F)
{ {
LogMessage("%08X: Writing 0x%I64U to %s register (originally: 0x%I64U)", (*_PROGRAM_COUNTER), Value, CRegName::Cop0[Reg], m_CP0[Reg]); LogMessage("%08X: Writing 0x%I64U to %s register (originally: 0x%I64U)", (*_PROGRAM_COUNTER), Value, CRegName::Cop0[Reg], m_CP0[Reg]);
if (Reg == 11) // Compare if (Reg == 11) // Compare
{ {
LogMessage("%08X: Cause register changed from %08X to %08X", (*_PROGRAM_COUNTER), CAUSE_REGISTER, (g_Reg->CAUSE_REGISTER & ~CAUSE_IP7)); LogMessage("%08X: Cause register changed from %08X to %08X", (*_PROGRAM_COUNTER), CAUSE_REGISTER, (g_Reg->CAUSE_REGISTER & ~CAUSE_IP7));
} }
@ -361,12 +357,12 @@ void CRegisters::Cop0_MT(uint32_t Reg, uint64_t Value)
switch (Reg) switch (Reg)
{ {
case 0: // Index case 0: // Index
case 2: // EntryLo0 case 2: // EntryLo0
case 3: // EntryLo1 case 3: // EntryLo1
case 5: // PageMask case 5: // PageMask
case 7: // Reg7 case 7: // Reg7
case 8: // BadVaddr case 8: // BadVaddr
case 10: // Entry Hi case 10: // Entry Hi
case 14: // EPC case 14: // EPC
case 15: // PRId case 15: // PRId
@ -579,7 +575,6 @@ void CRegisters::DoTrapException(bool DelaySlot)
EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER); EPC_REGISTER = (int64_t)((int32_t)m_PROGRAM_COUNTER);
} }
m_PROGRAM_COUNTER = 0x80000180; m_PROGRAM_COUNTER = 0x80000180;
} }
void CRegisters::DoCopUnusableException(bool DelaySlot, int32_t Coprocessor) void CRegisters::DoCopUnusableException(bool DelaySlot, int32_t Coprocessor)

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Common/Platform.h> #include <Common/Platform.h>
#include <Project64-core\N64System\N64Types.h> #include <Project64-core\Logging.h>
#include <Project64-core\N64System\MemoryHandler\AudioInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\AudioInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\CartridgeDomain2Address1Handler.h> #include <Project64-core\N64System\MemoryHandler\CartridgeDomain2Address1Handler.h>
#include <Project64-core\N64System\MemoryHandler\DisplayControlRegHandler.h> #include <Project64-core\N64System\MemoryHandler\DisplayControlRegHandler.h>
@ -9,12 +9,12 @@
#include <Project64-core\N64System\MemoryHandler\PeripheralInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\PeripheralInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.h> #include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.h>
#include <Project64-core\N64System\MemoryHandler\SerialInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\SPRegistersHandler.h> #include <Project64-core\N64System\MemoryHandler\SPRegistersHandler.h>
#include <Project64-core\N64System\MemoryHandler\SerialInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\VideoInterfaceHandler.h> #include <Project64-core\N64System\MemoryHandler\VideoInterfaceHandler.h>
#include <Project64-core\N64System\N64Types.h>
#include <Project64-core\Settings\DebugSettings.h> #include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Settings\GameSettings.h> #include <Project64-core\Settings\GameSettings.h>
#include <Project64-core\Logging.h>
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4201) // Non-standard extension used: nameless struct/union #pragma warning(disable : 4201) // Non-standard extension used: nameless struct/union
@ -51,7 +51,7 @@ union COP0XContext
class CP0registers class CP0registers
{ {
protected: protected:
CP0registers (uint64_t * _CP0); CP0registers(uint64_t * _CP0);
public: public:
uint64_t & INDEX_REGISTER; uint64_t & INDEX_REGISTER;
@ -78,19 +78,29 @@ public:
private: private:
CP0registers(); CP0registers();
CP0registers(const CP0registers&); CP0registers(const CP0registers &);
CP0registers& operator=(const CP0registers&); CP0registers & operator=(const CP0registers &);
}; };
// CPO register flags // CPO register flags
enum enum
{ {
// Status register // Status register
STATUS_IE = 0x00000001, STATUS_EXL = 0x00000002, STATUS_ERL = 0x00000004, STATUS_IE = 0x00000001,
STATUS_IP0 = 0x00000100, STATUS_IP1 = 0x00000200, STATUS_IP2 = 0x00000400, STATUS_EXL = 0x00000002,
STATUS_IP3 = 0x00000800, STATUS_IP4 = 0x00001000, STATUS_IP5 = 0x00002000, STATUS_ERL = 0x00000004,
STATUS_IP6 = 0x00004000, STATUS_IP7 = 0x00008000, STATUS_BEV = 0x00400000, STATUS_IP0 = 0x00000100,
STATUS_FR = 0x04000000, STATUS_CU0 = 0x10000000, STATUS_CU1 = 0x20000000, STATUS_IP1 = 0x00000200,
STATUS_IP2 = 0x00000400,
STATUS_IP3 = 0x00000800,
STATUS_IP4 = 0x00001000,
STATUS_IP5 = 0x00002000,
STATUS_IP6 = 0x00004000,
STATUS_IP7 = 0x00008000,
STATUS_BEV = 0x00400000,
STATUS_FR = 0x04000000,
STATUS_CU0 = 0x10000000,
STATUS_CU1 = 0x20000000,
// Cause flags // Cause flags
CAUSE_EXC_CODE = 0xFF, CAUSE_EXC_CODE = 0xFF,
@ -105,171 +115,170 @@ enum
CAUSE_BD = 0x80000000, CAUSE_BD = 0x80000000,
// Cause exception ID's // Cause exception ID's
EXC_INT = 0, // Interrupt EXC_INT = 0, // Interrupt
EXC_MOD = 4, // TLB mod EXC_MOD = 4, // TLB mod
EXC_RMISS = 8, // Read TLB miss EXC_RMISS = 8, // Read TLB miss
EXC_WMISS = 12, // Write TLB miss EXC_WMISS = 12, // Write TLB miss
EXC_RADE = 16, // Read address error EXC_RADE = 16, // Read address error
EXC_WADE = 20, // Write address error EXC_WADE = 20, // Write address error
EXC_IBE = 24, // Instruction bus error EXC_IBE = 24, // Instruction bus error
EXC_DBE = 28, // Data bus error EXC_DBE = 28, // Data bus error
EXC_SYSCALL = 32, // Syscall EXC_SYSCALL = 32, // Syscall
EXC_BREAK = 36, // Breakpoint EXC_BREAK = 36, // Breakpoint
EXC_II = 40, // Illegal instruction EXC_II = 40, // Illegal instruction
EXC_CPU = 44, // Co-processor unusable EXC_CPU = 44, // Co-processor unusable
EXC_OV = 48, // Overflow EXC_OV = 48, // Overflow
EXC_TRAP = 52, // Trap exception EXC_TRAP = 52, // Trap exception
EXC_VCEI = 56, // Virtual coherency on instruction fetch EXC_VCEI = 56, // Virtual coherency on instruction fetch
EXC_FPE = 60, // Floating point exception EXC_FPE = 60, // Floating point exception
EXC_WATCH = 92, // Watchpoint reference EXC_WATCH = 92, // Watchpoint reference
EXC_VCED = 124, // Virtual coherency on data read EXC_VCED = 124, // Virtual coherency on data read
}; };
// Float point control status register flags // Float point control status register flags
enum enum
{ {
FPCSR_FS = 0x01000000, // Flush denormalization to zero FPCSR_FS = 0x01000000, // Flush denormalization to zero
FPCSR_C = 0x00800000, // Condition bit FPCSR_C = 0x00800000, // Condition bit
FPCSR_CE = 0x00020000, // Cause: unimplemented operation FPCSR_CE = 0x00020000, // Cause: unimplemented operation
FPCSR_CV = 0x00010000, // Cause: invalid operation FPCSR_CV = 0x00010000, // Cause: invalid operation
FPCSR_CZ = 0x00008000, // Cause: division by zero FPCSR_CZ = 0x00008000, // Cause: division by zero
FPCSR_CO = 0x00004000, // Cause: overflow FPCSR_CO = 0x00004000, // Cause: overflow
FPCSR_CU = 0x00002000, // Cause: underflow FPCSR_CU = 0x00002000, // Cause: underflow
FPCSR_CI = 0x00001000, // Cause: inexact operation FPCSR_CI = 0x00001000, // Cause: inexact operation
FPCSR_EV = 0x00000800, // Enable: invalid operation FPCSR_EV = 0x00000800, // Enable: invalid operation
FPCSR_EZ = 0x00000400, // Enable: division by zero FPCSR_EZ = 0x00000400, // Enable: division by zero
FPCSR_EO = 0x00000200, // Enable: overflow FPCSR_EO = 0x00000200, // Enable: overflow
FPCSR_EU = 0x00000100, // Enable: underflow FPCSR_EU = 0x00000100, // Enable: underflow
FPCSR_EI = 0x00000080, // Enable: inexact operation FPCSR_EI = 0x00000080, // Enable: inexact operation
FPCSR_FV = 0x00000040, // Flag: invalid operation FPCSR_FV = 0x00000040, // Flag: invalid operation
FPCSR_FZ = 0x00000020, // Flag: division by zero FPCSR_FZ = 0x00000020, // Flag: division by zero
FPCSR_FO = 0x00000010, // Flag: overflow FPCSR_FO = 0x00000010, // Flag: overflow
FPCSR_FU = 0x00000008, // Flag: underflow FPCSR_FU = 0x00000008, // Flag: underflow
FPCSR_FI = 0x00000004, // Flag: inexact operation FPCSR_FI = 0x00000004, // Flag: inexact operation
FPCSR_RM_MASK = 0x00000003, // Rounding mode mask FPCSR_RM_MASK = 0x00000003, // Rounding mode mask
FPCSR_RM_RN = 0x00000000, // Round to nearest FPCSR_RM_RN = 0x00000000, // Round to nearest
FPCSR_RM_RZ = 0x00000001, // Round to zero FPCSR_RM_RZ = 0x00000001, // Round to zero
FPCSR_RM_RP = 0x00000002, // Round to positive infinity FPCSR_RM_RP = 0x00000002, // Round to positive infinity
FPCSR_RM_RM = 0x00000003, // Round to negative infinity FPCSR_RM_RM = 0x00000003, // Round to negative infinity
}; };
// MIPS interface flags // MIPS interface flags
enum enum
{ {
MI_MODE_INIT = 0x0080, // Bit 7: Initialization mode MI_MODE_INIT = 0x0080, // Bit 7: Initialization mode
MI_MODE_EBUS = 0x0100, // Bit 8: EBUS test mode MI_MODE_EBUS = 0x0100, // Bit 8: EBUS test mode
MI_MODE_RDRAM = 0x0200, // Bit 9: RDRAM register mode MI_MODE_RDRAM = 0x0200, // Bit 9: RDRAM register mode
MI_CLR_INIT = 0x0080, // Bit 7: Clear initialization mode MI_CLR_INIT = 0x0080, // Bit 7: Clear initialization mode
MI_SET_INIT = 0x0100, // Bit 8: Set initialization mode MI_SET_INIT = 0x0100, // Bit 8: Set initialization mode
MI_CLR_EBUS = 0x0200, // Bit 9: Clear EBUS test MI_CLR_EBUS = 0x0200, // Bit 9: Clear EBUS test
MI_SET_EBUS = 0x0400, // Bit 10: Set EBUS test mode MI_SET_EBUS = 0x0400, // Bit 10: Set EBUS test mode
MI_CLR_DP_INTR = 0x0800, // Bit 11: Clear DP interrupt MI_CLR_DP_INTR = 0x0800, // Bit 11: Clear DP interrupt
MI_CLR_RDRAM = 0x1000, // Bit 12: Clear RDRAM register MI_CLR_RDRAM = 0x1000, // Bit 12: Clear RDRAM register
MI_SET_RDRAM = 0x2000, // Bit 13: Set RDRAM register mode MI_SET_RDRAM = 0x2000, // Bit 13: Set RDRAM register mode
// Flags for writing to MI_INTR_MASK_REG // Flags for writing to MI_INTR_MASK_REG
MI_INTR_MASK_CLR_SP = 0x0001, // Bit 0: Clear SP mask MI_INTR_MASK_CLR_SP = 0x0001, // Bit 0: Clear SP mask
MI_INTR_MASK_SET_SP = 0x0002, // Bit 1: Set SP mask MI_INTR_MASK_SET_SP = 0x0002, // Bit 1: Set SP mask
MI_INTR_MASK_CLR_SI = 0x0004, // Bit 2: Clear SI mask MI_INTR_MASK_CLR_SI = 0x0004, // Bit 2: Clear SI mask
MI_INTR_MASK_SET_SI = 0x0008, // Bit 3: Set SI mask MI_INTR_MASK_SET_SI = 0x0008, // Bit 3: Set SI mask
MI_INTR_MASK_CLR_AI = 0x0010, // Bit 4: Clear AI mask MI_INTR_MASK_CLR_AI = 0x0010, // Bit 4: Clear AI mask
MI_INTR_MASK_SET_AI = 0x0020, // Bit 5: Set AI mask MI_INTR_MASK_SET_AI = 0x0020, // Bit 5: Set AI mask
MI_INTR_MASK_CLR_VI = 0x0040, // Bit 6: Clear VI mask MI_INTR_MASK_CLR_VI = 0x0040, // Bit 6: Clear VI mask
MI_INTR_MASK_SET_VI = 0x0080, // Bit 7: Set VI mask MI_INTR_MASK_SET_VI = 0x0080, // Bit 7: Set VI mask
MI_INTR_MASK_CLR_PI = 0x0100, // Bit 8: Clear PI mask MI_INTR_MASK_CLR_PI = 0x0100, // Bit 8: Clear PI mask
MI_INTR_MASK_SET_PI = 0x0200, // Bit 9: Set PI mask MI_INTR_MASK_SET_PI = 0x0200, // Bit 9: Set PI mask
MI_INTR_MASK_CLR_DP = 0x0400, // Bit 10: Clear DP mask MI_INTR_MASK_CLR_DP = 0x0400, // Bit 10: Clear DP mask
MI_INTR_MASK_SET_DP = 0x0800, // Bit 11: Set DP mask MI_INTR_MASK_SET_DP = 0x0800, // Bit 11: Set DP mask
// Flags for reading from MI_INTR_MASK_REG // Flags for reading from MI_INTR_MASK_REG
MI_INTR_MASK_SP = 0x01, // Bit 0: SP INTR mask MI_INTR_MASK_SP = 0x01, // Bit 0: SP INTR mask
MI_INTR_MASK_SI = 0x02, // Bit 1: SI INTR mask MI_INTR_MASK_SI = 0x02, // Bit 1: SI INTR mask
MI_INTR_MASK_AI = 0x04, // Bit 2: AI INTR mask MI_INTR_MASK_AI = 0x04, // Bit 2: AI INTR mask
MI_INTR_MASK_VI = 0x08, // Bit 3: VI INTR mask MI_INTR_MASK_VI = 0x08, // Bit 3: VI INTR mask
MI_INTR_MASK_PI = 0x10, // Bit 4: PI INTR mask MI_INTR_MASK_PI = 0x10, // Bit 4: PI INTR mask
MI_INTR_MASK_DP = 0x20, // Bit 5: DP INTR mask MI_INTR_MASK_DP = 0x20, // Bit 5: DP INTR mask
MI_INTR_SP = 0x01, // Bit 0: SP INTR MI_INTR_SP = 0x01, // Bit 0: SP INTR
MI_INTR_SI = 0x02, // Bit 1: SI INTR MI_INTR_SI = 0x02, // Bit 1: SI INTR
MI_INTR_AI = 0x04, // Bit 2: AI INTR MI_INTR_AI = 0x04, // Bit 2: AI INTR
MI_INTR_VI = 0x08, // Bit 3: VI INTR MI_INTR_VI = 0x08, // Bit 3: VI INTR
MI_INTR_PI = 0x10, // Bit 4: PI INTR MI_INTR_PI = 0x10, // Bit 4: PI INTR
MI_INTR_DP = 0x20, // Bit 5: DP INTR MI_INTR_DP = 0x20, // Bit 5: DP INTR
}; };
// Signal processor interface flags // Signal processor interface flags
enum enum
{ {
SP_CLR_HALT = 0x00001, // Bit 0: Clear halt SP_CLR_HALT = 0x00001, // Bit 0: Clear halt
SP_SET_HALT = 0x00002, // Bit 1: Set halt SP_SET_HALT = 0x00002, // Bit 1: Set halt
SP_CLR_BROKE = 0x00004, // Bit 2: Clear broke SP_CLR_BROKE = 0x00004, // Bit 2: Clear broke
SP_CLR_INTR = 0x00008, // Bit 3: Clear INTR SP_CLR_INTR = 0x00008, // Bit 3: Clear INTR
SP_SET_INTR = 0x00010, // Bit 4: Set INTR SP_SET_INTR = 0x00010, // Bit 4: Set INTR
SP_CLR_SSTEP = 0x00020, // Bit 5: Clear SSTEP SP_CLR_SSTEP = 0x00020, // Bit 5: Clear SSTEP
SP_SET_SSTEP = 0x00040, // Bit 6: Set SSTEP SP_SET_SSTEP = 0x00040, // Bit 6: Set SSTEP
SP_CLR_INTR_BREAK = 0x00080, // Bit 7: Clear INTR on break SP_CLR_INTR_BREAK = 0x00080, // Bit 7: Clear INTR on break
SP_SET_INTR_BREAK = 0x00100, // Bit 8: Set INTR on break SP_SET_INTR_BREAK = 0x00100, // Bit 8: Set INTR on break
SP_CLR_SIG0 = 0x00200, // Bit 9: Clear signal 0 SP_CLR_SIG0 = 0x00200, // Bit 9: Clear signal 0
SP_SET_SIG0 = 0x00400, // Bit 10: Set signal 0 SP_SET_SIG0 = 0x00400, // Bit 10: Set signal 0
SP_CLR_SIG1 = 0x00800, // Bit 11: Clear signal 1 SP_CLR_SIG1 = 0x00800, // Bit 11: Clear signal 1
SP_SET_SIG1 = 0x01000, // Bit 12: Set signal 1 SP_SET_SIG1 = 0x01000, // Bit 12: Set signal 1
SP_CLR_SIG2 = 0x02000, // Bit 13: Clear signal 2 SP_CLR_SIG2 = 0x02000, // Bit 13: Clear signal 2
SP_SET_SIG2 = 0x04000, // Bit 14: Set signal 2 SP_SET_SIG2 = 0x04000, // Bit 14: Set signal 2
SP_CLR_SIG3 = 0x08000, // Bit 15: Clear signal 3 SP_CLR_SIG3 = 0x08000, // Bit 15: Clear signal 3
SP_SET_SIG3 = 0x10000, // Bit 16: Set signal 3 SP_SET_SIG3 = 0x10000, // Bit 16: Set signal 3
SP_CLR_SIG4 = 0x20000, // Bit 17: Clear signal 4 SP_CLR_SIG4 = 0x20000, // Bit 17: Clear signal 4
SP_SET_SIG4 = 0x40000, // Bit 18: Set signal 4 SP_SET_SIG4 = 0x40000, // Bit 18: Set signal 4
SP_CLR_SIG5 = 0x80000, // Bit 19: Clear signal 5 SP_CLR_SIG5 = 0x80000, // Bit 19: Clear signal 5
SP_SET_SIG5 = 0x100000, // Bit 20: Set signal 5 SP_SET_SIG5 = 0x100000, // Bit 20: Set signal 5
SP_CLR_SIG6 = 0x200000, // Bit 21: Clear signal 6 SP_CLR_SIG6 = 0x200000, // Bit 21: Clear signal 6
SP_SET_SIG6 = 0x400000, // Bit 22: Set signal 6 SP_SET_SIG6 = 0x400000, // Bit 22: Set signal 6
SP_CLR_SIG7 = 0x800000, // Bit 23: Clear signal 7 SP_CLR_SIG7 = 0x800000, // Bit 23: Clear signal 7
SP_SET_SIG7 = 0x1000000, // Bit 24: Set signal 7 SP_SET_SIG7 = 0x1000000, // Bit 24: Set signal 7
SP_STATUS_HALT = 0x001, // Bit 0: Halt SP_STATUS_HALT = 0x001, // Bit 0: Halt
SP_STATUS_BROKE = 0x002, // Bit 1: Broke SP_STATUS_BROKE = 0x002, // Bit 1: Broke
SP_STATUS_DMA_BUSY = 0x004, // Bit 2: DMA busy SP_STATUS_DMA_BUSY = 0x004, // Bit 2: DMA busy
SP_STATUS_DMA_FULL = 0x008, // Bit 3: DMA full SP_STATUS_DMA_FULL = 0x008, // Bit 3: DMA full
SP_STATUS_IO_FULL = 0x010, // Bit 4: IO full SP_STATUS_IO_FULL = 0x010, // Bit 4: IO full
SP_STATUS_SSTEP = 0x020, // Bit 5: Single step SP_STATUS_SSTEP = 0x020, // Bit 5: Single step
SP_STATUS_INTR_BREAK = 0x040, // Bit 6: Interrupt on break SP_STATUS_INTR_BREAK = 0x040, // Bit 6: Interrupt on break
SP_STATUS_SIG0 = 0x080, // Bit 7: Signal 0 set SP_STATUS_SIG0 = 0x080, // Bit 7: Signal 0 set
SP_STATUS_SIG1 = 0x100, // Bit 8: Signal 1 set SP_STATUS_SIG1 = 0x100, // Bit 8: Signal 1 set
SP_STATUS_SIG2 = 0x200, // Bit 9: Signal 2 set SP_STATUS_SIG2 = 0x200, // Bit 9: Signal 2 set
SP_STATUS_SIG3 = 0x400, // Bit 10: Signal 3 set SP_STATUS_SIG3 = 0x400, // Bit 10: Signal 3 set
SP_STATUS_SIG4 = 0x800, // Bit 11: Signal 4 set SP_STATUS_SIG4 = 0x800, // Bit 11: Signal 4 set
SP_STATUS_SIG5 = 0x1000, // Bit 12: Signal 5 set SP_STATUS_SIG5 = 0x1000, // Bit 12: Signal 5 set
SP_STATUS_SIG6 = 0x2000, // Bit 13: Signal 6 set SP_STATUS_SIG6 = 0x2000, // Bit 13: Signal 6 set
SP_STATUS_SIG7 = 0x4000, // Bit 14: Signal 7 set SP_STATUS_SIG7 = 0x4000, // Bit 14: Signal 7 set
}; };
class CRegName class CRegName
{ {
public: public:
static const char *GPR[32]; static const char * GPR[32];
static const char *GPR_Hi[32]; static const char * GPR_Hi[32];
static const char *GPR_Lo[32]; static const char * GPR_Lo[32];
static const char *Cop0[32]; static const char * Cop0[32];
static const char *FPR[32]; static const char * FPR[32];
static const char *FPR_Ctrl[32]; static const char * FPR_Ctrl[32];
}; };
class CSystemRegisters class CSystemRegisters
{ {
protected: protected:
static uint32_t * _PROGRAM_COUNTER; static uint32_t * _PROGRAM_COUNTER;
static MIPS_DWORD * _GPR; static MIPS_DWORD * _GPR;
static MIPS_DWORD * _FPR; static MIPS_DWORD * _FPR;
static uint64_t * _CP0; static uint64_t * _CP0;
static MIPS_DWORD * _RegHI; static MIPS_DWORD * _RegHI;
static MIPS_DWORD * _RegLO; static MIPS_DWORD * _RegLO;
static float ** _FPR_S; static float ** _FPR_S;
static double ** _FPR_D; static double ** _FPR_D;
static uint32_t * _FPCR; static uint32_t * _FPCR;
static uint32_t * _LLBit; static uint32_t * _LLBit;
static int32_t * _RoundingModel; static int32_t * _RoundingModel;
}; };
class CN64System; class CN64System;
@ -296,16 +305,16 @@ public:
CRegisters(CN64System * System, CSystemEvents * SystemEvents); CRegisters(CN64System * System, CSystemEvents * SystemEvents);
void CheckInterrupts(); void CheckInterrupts();
void DoAddressError( bool DelaySlot, uint64_t BadVaddr, bool FromRead ); void DoAddressError(bool DelaySlot, uint64_t BadVaddr, bool FromRead);
void DoBreakException( bool DelaySlot ); void DoBreakException(bool DelaySlot);
void DoTrapException( bool DelaySlot ); void DoTrapException(bool DelaySlot);
void DoCopUnusableException( bool DelaySlot, int32_t Coprocessor ); void DoCopUnusableException(bool DelaySlot, int32_t Coprocessor);
bool DoIntrException( bool DelaySlot ); bool DoIntrException(bool DelaySlot);
void DoIllegalInstructionException(bool DelaySlot); void DoIllegalInstructionException(bool DelaySlot);
void DoOverflowException(bool DelaySlot); void DoOverflowException(bool DelaySlot);
void DoTLBReadMiss(bool DelaySlot, uint64_t BadVaddr); void DoTLBReadMiss(bool DelaySlot, uint64_t BadVaddr);
void DoTLBWriteMiss(bool DelaySlot, uint64_t BadVaddr); void DoTLBWriteMiss(bool DelaySlot, uint64_t BadVaddr);
void DoSysCallException ( bool DelaySlot); void DoSysCallException(bool DelaySlot);
void FixFpuLocations(); void FixFpuLocations();
void Reset(); void Reset();
void SetAsCurrentSystem(); void SetAsCurrentSystem();
@ -345,8 +354,8 @@ public:
private: private:
CRegisters(); CRegisters();
CRegisters(const CRegisters&); CRegisters(const CRegisters &);
CRegisters& operator=(const CRegisters&); CRegisters & operator=(const CRegisters &);
bool m_FirstInterupt; bool m_FirstInterupt;
CN64System * m_System; CN64System * m_System;

View File

@ -1,29 +1,29 @@
#include "stdafx.h" #include "stdafx.h"
#include "Rumblepak.h"
#include "Rumblepak.h"
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/Plugins/Plugin.h>
#include <Project64-core/Plugins/ControllerPlugin.h> #include <Project64-core/Plugins/ControllerPlugin.h>
#include <Project64-core/Plugins/Plugin.h>
void Rumblepak::ReadFrom(uint32_t address, uint8_t * data) void Rumblepak::ReadFrom(uint32_t address, uint8_t * data)
{ {
if ((address >= 0x8000) && (address < 0x9000)) if ((address >= 0x8000) && (address < 0x9000))
{ {
memset(data, 0x80, 0x20); memset(data, 0x80, 0x20);
} }
else else
{ {
memset(data, 0x00, 0x20); memset(data, 0x00, 0x20);
} }
} }
void Rumblepak::WriteTo(int32_t Control, uint32_t address, uint8_t * data) void Rumblepak::WriteTo(int32_t Control, uint32_t address, uint8_t * data)
{ {
if ((address) == 0xC000) if ((address) == 0xC000)
{ {
if (g_Plugins->Control()->RumbleCommand != nullptr) if (g_Plugins->Control()->RumbleCommand != nullptr)
{ {
g_Plugins->Control()->RumbleCommand(Control, *(int *)data); g_Plugins->Control()->RumbleCommand(Control, *(int *)data);
} }
} }
} }

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Mips/SystemEvents.h> #include <Project64-core/N64System/Mips/SystemEvents.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
const char * SystemEventName(SystemEvent event) const char * SystemEventName(SystemEvent event)
{ {

View File

@ -72,14 +72,14 @@ public:
private: private:
CSystemEvents(); CSystemEvents();
CSystemEvents(const CSystemEvents&); CSystemEvents(const CSystemEvents &);
CSystemEvents& operator=(const CSystemEvents&); CSystemEvents & operator=(const CSystemEvents &);
void ChangePluginFunc(); void ChangePluginFunc();
CN64System * m_System; CN64System * m_System;
CPlugins * m_Plugins; CPlugins * m_Plugins;
EventList m_Events; EventList m_Events;
int32_t m_bDoSomething; int32_t m_bDoSomething;
CriticalSection m_CS; CriticalSection m_CS;
}; };

View File

@ -1,12 +1,11 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/Disk.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/MemoryHandler/AudioInterfaceHandler.h>
#include <Project64-core/3rdParty/zip.h> #include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/MemoryHandler/AudioInterfaceHandler.h>
#include <Project64-core/N64System/Mips/Disk.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
CSystemTimer::CSystemTimer(CN64System & System) : CSystemTimer::CSystemTimer(CN64System & System) :
m_System(System), m_System(System),
@ -56,12 +55,12 @@ void CSystemTimer::SetTimer(TimerType Type, uint32_t Cycles, bool bRelative)
} }
else else
{ {
m_TimerDetatils[Type].CyclesToTimer = (int64_t)Cycles - (int64_t)m_NextTimer; // Replace the new cycles m_TimerDetatils[Type].CyclesToTimer = (int64_t)Cycles - (int64_t)m_NextTimer; // Replace the new cycles
} }
} }
else else
{ {
m_TimerDetatils[Type].CyclesToTimer = (int64_t)Cycles - (int64_t)m_NextTimer; // Replace the new cycles m_TimerDetatils[Type].CyclesToTimer = (int64_t)Cycles - (int64_t)m_NextTimer; // Replace the new cycles
} }
FixTimers(); FixTimers();
} }
@ -400,7 +399,7 @@ void CSystemTimer::LoadData(CFile & file)
file.Read((void *)&m_Current, sizeof(m_Current)); file.Read((void *)&m_Current, sizeof(m_Current));
} }
void CSystemTimer::RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer) void CSystemTimer::RecordDifference(CLog & LogFile, const CSystemTimer & rSystemTimer)
{ {
if (m_LastUpdate != rSystemTimer.m_LastUpdate) if (m_LastUpdate != rSystemTimer.m_LastUpdate)
{ {
@ -432,7 +431,7 @@ void CSystemTimer::RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTi
} }
} }
bool CSystemTimer::operator == (const CSystemTimer& rSystemTimer) const bool CSystemTimer::operator==(const CSystemTimer & rSystemTimer) const
{ {
if (m_LastUpdate != rSystemTimer.m_LastUpdate) if (m_LastUpdate != rSystemTimer.m_LastUpdate)
{ {
@ -465,7 +464,7 @@ bool CSystemTimer::operator == (const CSystemTimer& rSystemTimer) const
return true; return true;
} }
bool CSystemTimer::operator != (const CSystemTimer& rSystemTimer) const bool CSystemTimer::operator!=(const CSystemTimer & rSystemTimer) const
{ {
return !(*this == rSystemTimer); return !(*this == rSystemTimer);
} }

View File

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <Common/Log.h> #include <Common/Log.h>
#include <Project64-core/N64System/N64Types.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/3rdParty/zip.h> #include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/N64Types.h>
class AudioInterfaceHandler; class AudioInterfaceHandler;
class RomMemoryHandler;
class CSystemTimer class CSystemTimer
{ {
@ -42,7 +43,7 @@ public:
CSystemTimer(CN64System & System); CSystemTimer(CN64System & System);
void SetTimer(TimerType Type, uint32_t Cycles, bool bRelative); void SetTimer(TimerType Type, uint32_t Cycles, bool bRelative);
uint32_t GetTimer(TimerType Type); uint32_t GetTimer(TimerType Type);
void StopTimer(TimerType Type); void StopTimer(TimerType Type);
void UpdateTimers(); void UpdateTimers();
void TimerDone(); void TimerDone();
@ -55,17 +56,20 @@ public:
void LoadData(zipFile & file); void LoadData(zipFile & file);
void LoadData(CFile & file); void LoadData(CFile & file);
void RecordDifference(CLog &LogFile, const CSystemTimer& rSystemTimer); void RecordDifference(CLog & LogFile, const CSystemTimer & rSystemTimer);
TimerType CurrentType() const { return m_Current; } TimerType CurrentType() const
{
return m_Current;
}
bool operator == (const CSystemTimer& rSystemTimer) const; bool operator==(const CSystemTimer & rSystemTimer) const;
bool operator != (const CSystemTimer& rSystemTimer) const; bool operator!=(const CSystemTimer & rSystemTimer) const;
private: private:
CSystemTimer(void); CSystemTimer(void);
CSystemTimer(const CSystemTimer&); CSystemTimer(const CSystemTimer &);
CSystemTimer& operator=(const CSystemTimer&); CSystemTimer & operator=(const CSystemTimer &);
void SetCompareTimer(); void SetCompareTimer();
void FixTimers(); void FixTimers();

View File

@ -1,10 +1,11 @@
#include "stdafx.h" #include "stdafx.h"
#include "TLB.h" #include "TLB.h"
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/SystemGlobals.h>
CTLB::CTLB(CTLB_CB * CallBack) : CTLB::CTLB(CTLB_CB * CallBack) :
m_CB(CallBack) m_CB(CallBack)
{ {
WriteTrace(TraceTLB, TraceDebug, "Start"); WriteTrace(TraceTLB, TraceDebug, "Start");
memset(m_tlb, 0, sizeof(m_tlb)); memset(m_tlb, 0, sizeof(m_tlb));
@ -85,7 +86,7 @@ void CTLB::Probe()
if (TlbValueMasked == EntryHiMasked) if (TlbValueMasked == EntryHiMasked)
{ {
if ((TlbEntryHiValue & 0x100) != 0 || // Global if ((TlbEntryHiValue & 0x100) != 0 || // Global
((TlbEntryHiValue & 0xFF) == (g_Reg->ENTRYHI_REGISTER & 0xFF))) // SameAsid ((TlbEntryHiValue & 0xFF) == (g_Reg->ENTRYHI_REGISTER & 0xFF))) // SameAsid
{ {
g_Reg->INDEX_REGISTER = Counter; g_Reg->INDEX_REGISTER = Counter;
@ -262,7 +263,7 @@ bool CTLB::PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index)
return false; return false;
} }
void CTLB::RecordDifference(CLog &LogFile, const CTLB& rTLB) void CTLB::RecordDifference(CLog & LogFile, const CTLB & rTLB)
{ {
for (int i = 0, n = sizeof(m_tlb) / sizeof(m_tlb[0]); i < n; i++) for (int i = 0, n = sizeof(m_tlb) / sizeof(m_tlb[0]); i < n; i++)
{ {
@ -294,7 +295,7 @@ void CTLB::RecordDifference(CLog &LogFile, const CTLB& rTLB)
} }
} }
bool CTLB::operator == (const CTLB& rTLB) const bool CTLB::operator==(const CTLB & rTLB) const
{ {
const size_t n = sizeof(m_tlb) / sizeof(m_tlb[0]); const size_t n = sizeof(m_tlb) / sizeof(m_tlb[0]);
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
@ -318,7 +319,7 @@ bool CTLB::operator == (const CTLB& rTLB) const
return true; return true;
} }
bool CTLB::operator != (const CTLB& rTLB) const bool CTLB::operator!=(const CTLB & rTLB) const
{ {
return !(*this == rTLB); return !(*this == rTLB);
} }

View File

@ -103,10 +103,10 @@ public:
bool PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index); bool PAddrToVAddr(uint32_t PAddr, uint32_t & VAddr, uint32_t & Index);
void RecordDifference(CLog &LogFile, const CTLB& rTLB); void RecordDifference(CLog & LogFile, const CTLB & rTLB);
bool operator == (const CTLB& rTLB) const; bool operator==(const CTLB & rTLB) const;
bool operator != (const CTLB& rTLB) const; bool operator!=(const CTLB & rTLB) const;
private: private:
struct FASTTLB struct FASTTLB
@ -116,12 +116,12 @@ private:
uint32_t PHYSSTART; uint32_t PHYSSTART;
uint32_t PHYSEND; uint32_t PHYSEND;
uint32_t Length; uint32_t Length;
bool VALID; bool VALID;
bool DIRTY; bool DIRTY;
bool GLOBAL; bool GLOBAL;
bool ValidEntry; bool ValidEntry;
bool Random; bool Random;
bool Probed; bool Probed;
}; };
friend class CDebugTlb; // Enable debug window to read class friend class CDebugTlb; // Enable debug window to read class
@ -129,14 +129,14 @@ private:
CTLB_CB * const m_CB; CTLB_CB * const m_CB;
TLB_ENTRY m_tlb[32]; TLB_ENTRY m_tlb[32];
FASTTLB m_FastTlb[64]; FASTTLB m_FastTlb[64];
void SetupTLB_Entry(int32_t index, bool Random); void SetupTLB_Entry(int32_t index, bool Random);
private: private:
CTLB(); CTLB();
CTLB(const CTLB&); CTLB(const CTLB &);
CTLB& operator=(const CTLB&); CTLB & operator=(const CTLB &);
}; };
#pragma warning(pop) #pragma warning(pop)

View File

@ -5,6 +5,7 @@
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html // GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include "stdafx.h" #include "stdafx.h"
#include "GBCart.h" #include "GBCart.h"
#include "Transferpak.h" #include "Transferpak.h"
@ -36,42 +37,41 @@ void Transferpak::Release()
void Transferpak::ReadFrom(uint16_t address, uint8_t * data) void Transferpak::ReadFrom(uint16_t address, uint8_t * data)
{ {
if ((address >= 0x8000) && (address <= 0x8FFF)) if ((address >= 0x8000) && (address <= 0x8FFF))
{ {
// Ensure we actually have a ROM loaded in first // Ensure we actually have a ROM loaded in first
if (tpak.gb_cart.rom == nullptr) if (tpak.gb_cart.rom == nullptr)
{ {
Init(); Init();
} }
// Get whether the Game Boy cart is enabled or disabled // Get whether the Game Boy cart is enabled or disabled
uint8_t value = (tpak.enabled) ? 0x84 : 0x00; uint8_t value = (tpak.enabled) ? 0x84 : 0x00;
memset(data, value, 0x20); memset(data, value, 0x20);
} }
else if ((address >= 0xB000) && (address <= 0xBFFF)) else if ((address >= 0xB000) && (address <= 0xBFFF))
{ {
// Get the Game Boy cart access mode // Get the Game Boy cart access mode
if (tpak.enabled) if (tpak.enabled)
{ {
memset(data, tpak.access_mode, 0x20); memset(data, tpak.access_mode, 0x20);
if (tpak.access_mode != CART_NOT_INSERTED) if (tpak.access_mode != CART_NOT_INSERTED)
{ {
data[0] |= tpak.access_mode_changed; data[0] |= tpak.access_mode_changed;
} }
tpak.access_mode_changed = 0; tpak.access_mode_changed = 0;
} }
} }
else if (address >= 0xC000) else if (address >= 0xC000)
{ {
// Read the Game Boy cart // Read the Game Boy cart
if (tpak.enabled) if (tpak.enabled)
{ {
GBCart::read_gb_cart(&tpak.gb_cart, gb_cart_address(tpak.bank, address), data); GBCart::read_gb_cart(&tpak.gb_cart, gb_cart_address(tpak.bank, address), data);
} }
} }
} }
void Transferpak::WriteTo(uint16_t address, uint8_t * data) void Transferpak::WriteTo(uint16_t address, uint8_t * data)
@ -99,7 +99,7 @@ void Transferpak::WriteTo(uint16_t address, uint8_t * data)
break; break;
} }
} }
else if ((address >= 0xA000) && (address <= 0xAFFF)) else if ((address >= 0xA000) && (address <= 0xAFFF))
{ {
// Set the bank for the Game Boy cart // Set the bank for the Game Boy cart
if (tpak.enabled) if (tpak.enabled)

View File

@ -1,27 +1,27 @@
#pragma once #pragma once
#include "GBCart.h" #include "GBCart.h"
enum cart_access_mode enum cart_access_mode
{ {
CART_NOT_INSERTED = 0x40, CART_NOT_INSERTED = 0x40,
CART_ACCESS_MODE_0 = 0x80, CART_ACCESS_MODE_0 = 0x80,
CART_ACCESS_MODE_1 = 0x89 CART_ACCESS_MODE_1 = 0x89
}; };
struct transferpak struct transferpak
{ {
unsigned int enabled; unsigned int enabled;
unsigned int bank; unsigned int bank;
unsigned int access_mode; unsigned int access_mode;
unsigned int access_mode_changed; unsigned int access_mode_changed;
struct gb_cart gb_cart; struct gb_cart gb_cart;
}; };
class Transferpak class Transferpak
{ {
public: public:
static void Release(); static void Release();
static void Init(); static void Init();
static void ReadFrom(uint16_t address, uint8_t * command); static void ReadFrom(uint16_t address, uint8_t * command);
static void WriteTo(uint16_t address, uint8_t * command); static void WriteTo(uint16_t address, uint8_t * command);
}; };

View File

@ -1,9 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include "N64Disk.h" #include "N64Disk.h"
#include "SystemGlobals.h" #include "SystemGlobals.h"
#include <Common/md5.h>
#include <Common/Platform.h>
#include <Common/MemoryManagement.h> #include <Common/MemoryManagement.h>
#include <Common/Platform.h>
#include <Common/md5.h>
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#include <memory> #include <memory>
@ -193,9 +194,18 @@ bool CN64Disk::IsValidDiskImage(uint8_t Test[0x20])
if (ipl_load_addr < 0x80000000 && ipl_load_addr >= 0x80800000) return false; if (ipl_load_addr < 0x80000000 && ipl_load_addr >= 0x80800000) return false;
// Country code // Country code
if (*((uint32_t *)&Test[0]) == 0x16D348E8) { return true; } if (*((uint32_t *)&Test[0]) == 0x16D348E8)
else if (*((uint32_t *)&Test[0]) == 0x56EE6322) { return true; } {
else if (*((uint32_t *)&Test[0]) == 0x00000000) { return true; } return true;
}
else if (*((uint32_t *)&Test[0]) == 0x56EE6322)
{
return true;
}
else if (*((uint32_t *)&Test[0]) == 0x00000000)
{
return true;
}
return false; return false;
} }
@ -284,7 +294,7 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
uint8_t Test[0x100]; uint8_t Test[0x100];
bool isValidDisk = false; bool isValidDisk = false;
const uint8_t blocks[8] = { 0, 1, 2, 3, 8, 9, 10, 11 }; const uint8_t blocks[8] = {0, 1, 2, 3, 8, 9, 10, 11};
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
m_DiskFile.Seek(0x4D08 * blocks[i], CFileBase::SeekPosition::begin); m_DiskFile.Seek(0x4D08 * blocks[i], CFileBase::SeekPosition::begin);
@ -339,7 +349,10 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
for (count = 0; count < (int)DiskFileSize; count += ReadFromRomSection) for (count = 0; count < (int)DiskFileSize; count += ReadFromRomSection)
{ {
uint32_t dwToRead = DiskFileSize - count; uint32_t dwToRead = DiskFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; } if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
if (m_DiskFile.Read(&m_DiskImage[count], dwToRead) != dwToRead) if (m_DiskFile.Read(&m_DiskImage[count], dwToRead) != dwToRead)
{ {
@ -416,7 +429,10 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
for (count = 0; count < (int)DiskFileSize; count += ReadFromRomSection) for (count = 0; count < (int)DiskFileSize; count += ReadFromRomSection)
{ {
uint32_t dwToRead = DiskFileSize - count; uint32_t dwToRead = DiskFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; } if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
if (m_DiskFile.Read(&m_DiskImage[count], dwToRead) != dwToRead) if (m_DiskFile.Read(&m_DiskImage[count], dwToRead) != dwToRead)
{ {
@ -575,7 +591,7 @@ uint32_t CN64Disk::CalculateCrc()
uint32_t crc = 0; uint32_t crc = 0;
for (int i = 0; i < 0x4D08; i += 4) for (int i = 0; i < 0x4D08; i += 4)
{ {
crc += *(uint32_t*)(&GetDiskAddressRom()[i]); crc += *(uint32_t *)(&GetDiskAddressRom()[i]);
} }
return crc; return crc;
} }
@ -672,9 +688,9 @@ uint32_t CN64Disk::GetDiskAddressBlock(uint16_t head, uint16_t track, uint16_t b
else else
{ {
// D64 // D64
uint16_t ROM_LBA_END = *(uint16_t*)(&GetDiskAddressSys()[0xE2]); uint16_t ROM_LBA_END = *(uint16_t *)(&GetDiskAddressSys()[0xE2]);
uint16_t RAM_LBA_START = *(uint16_t*)(&GetDiskAddressSys()[0xE0]); uint16_t RAM_LBA_START = *(uint16_t *)(&GetDiskAddressSys()[0xE0]);
uint16_t RAM_LBA_END = *(uint16_t*)(&GetDiskAddressSys()[0xE6]); uint16_t RAM_LBA_END = *(uint16_t *)(&GetDiskAddressSys()[0xE6]);
uint16_t LBA = PhysToLBA(head, track, block); uint16_t LBA = PhysToLBA(head, track, block);
if (LBA < DISKID_LBA) if (LBA < DISKID_LBA)
{ {
@ -720,7 +736,7 @@ void CN64Disk::DetectSystemArea()
m_DiskRomAddress = SYSTEM_LBAS * 0x4D08; m_DiskRomAddress = SYSTEM_LBAS * 0x4D08;
// Handle system data // Handle system data
const uint16_t sysblocks[4] = { 9, 8, 1, 0 }; const uint16_t sysblocks[4] = {9, 8, 1, 0};
// Check if disk is development disk // Check if disk is development disk
bool isDevDisk = false; bool isDevDisk = false;
@ -790,12 +806,14 @@ bool CN64Disk::IsSysSectorGood(uint32_t block, uint32_t sectorsize)
return false; return false;
// Always 0xFFFFFFFF // Always 0xFFFFFFFF
if (*(uint32_t*)&m_DiskImage[(block * 0x4D08) + 0x18] != 0xFFFFFFFF) if (*(uint32_t *)&m_DiskImage[(block * 0x4D08) + 0x18] != 0xFFFFFFFF)
return false; return false;
uint8_t alt = 0xC; // Retail uint8_t alt = 0xC; // Retail
if ((block & 2) != 0) if ((block & 2) != 0)
alt = 0xA; // Development {
alt = 0xA; // Development
}
// Alternate tracks offsets (always the same) // Alternate tracks offsets (always the same)
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
@ -810,15 +828,15 @@ bool CN64Disk::IsSysSectorGood(uint32_t block, uint32_t sectorsize)
Country CN64Disk::GetDiskCountryCode() Country CN64Disk::GetDiskCountryCode()
{ {
switch (*(uint32_t*)&GetDiskAddressSys()[0]) switch (*(uint32_t *)&GetDiskAddressSys()[0])
{ {
case DISK_COUNTRY_JPN: case DISK_COUNTRY_JPN:
return Country_Japan; return Country_Japan;
case DISK_COUNTRY_USA: case DISK_COUNTRY_USA:
return Country_NorthAmerica; return Country_NorthAmerica;
case DISK_COUNTRY_DEV: case DISK_COUNTRY_DEV:
default: default:
return Country_Unknown; return Country_Unknown;
} }
} }
@ -834,13 +852,13 @@ void CN64Disk::InitSysDataD64()
// Expand RAM area for file format consistency // Expand RAM area for file format consistency
if (m_DiskType < 6) if (m_DiskType < 6)
{ {
*(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS; *(uint16_t *)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS;
*(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS; *(uint16_t *)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS;
} }
else else
{ {
*(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = 0xFFFF; *(uint16_t *)&GetDiskAddressSys()[0xE2 ^ 2] = 0xFFFF;
*(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = 0xFFFF; *(uint16_t *)&GetDiskAddressSys()[0xE4 ^ 2] = 0xFFFF;
} }
} }
@ -850,8 +868,8 @@ void CN64Disk::DeinitSysDataD64()
if (m_DiskFormat != DiskFormatD64) if (m_DiskFormat != DiskFormatD64)
return; return;
GetDiskAddressSys()[4^3] = 0x00; GetDiskAddressSys()[4 ^ 3] = 0x00;
GetDiskAddressSys()[5^3] &= 0x0F; GetDiskAddressSys()[5 ^ 3] &= 0x0F;
} }
void CN64Disk::GenerateLBAToPhysTable() void CN64Disk::GenerateLBAToPhysTable()
@ -875,14 +893,16 @@ void CN64Disk::DetectRamAddress()
} }
else //if (m_DiskFormat == DiskFormatD64) else //if (m_DiskFormat == DiskFormatD64)
{ {
m_DiskRamAddress = m_DiskRomAddress + LBAToByte(SYSTEM_LBAS, *(uint16_t*)(&GetDiskAddressSys()[0xE0 ^ 2]) + 1); m_DiskRamAddress = m_DiskRomAddress + LBAToByte(SYSTEM_LBAS, *(uint16_t *)(&GetDiskAddressSys()[0xE0 ^ 2]) + 1);
} }
} }
uint32_t CN64Disk::LBAToVZone(uint32_t lba) uint32_t CN64Disk::LBAToVZone(uint32_t lba)
{ {
for (uint32_t vzone = 0; vzone < 16; vzone++) { for (uint32_t vzone = 0; vzone < 16; vzone++)
if (lba < VZONE_LBA_TBL[m_DiskType][vzone]) { {
if (lba < VZONE_LBA_TBL[m_DiskType][vzone])
{
return vzone; return vzone;
} }
} }

View File

@ -9,55 +9,104 @@ public:
CN64Disk(); CN64Disk();
~CN64Disk(); ~CN64Disk();
bool LoadDiskImage(const char * FileLoc); bool LoadDiskImage(const char * FileLoc);
bool SaveDiskImage(); bool SaveDiskImage();
void SwapDiskImage(const char * FileLoc); void SwapDiskImage(const char * FileLoc);
static bool IsValidDiskImage(uint8_t Test[0x20]); static bool IsValidDiskImage(uint8_t Test[0x20]);
void SaveDiskSettingID(bool temp); void SaveDiskSettingID(bool temp);
void ClearDiskSettingID(); void ClearDiskSettingID();
uint8_t * GetDiskAddress() { return m_DiskImage; } uint8_t * GetDiskAddress()
uint8_t * GetDiskAddressBuffer() { return m_DiskImage + m_DiskBufAddress; } {
uint8_t * GetDiskAddressSys() { return m_DiskImage + m_DiskSysAddress; } return m_DiskImage;
uint8_t * GetDiskAddressID() { return m_DiskImage + m_DiskIDAddress; } }
uint8_t * GetDiskAddressRom() { return m_DiskImage + m_DiskRomAddress; } uint8_t * GetDiskAddressBuffer()
uint8_t * GetDiskAddressRam() { return m_DiskImage + m_DiskRamAddress; } {
uint32_t GetDiskSize() const { return m_DiskFileSize; } return m_DiskImage + m_DiskBufAddress;
uint8_t * GetDiskHeader() { return m_DiskHeader; } }
void SetDiskAddressBuffer(uint32_t address) { m_DiskBufAddress = address; } uint8_t * GetDiskAddressSys()
uint32_t GetDiskAddressBlock(uint16_t head, uint16_t track, uint16_t block, uint16_t sector, uint16_t sectorsize); {
uint32_t CalculateCrc(); return m_DiskImage + m_DiskSysAddress;
stdstr GetRomName() const { return m_RomName; } }
stdstr GetFileName() const { return m_FileName; } uint8_t * GetDiskAddressID()
stdstr GetDiskIdent() const { return m_DiskIdent; } {
Country GetCountry() const { return m_Country; } return m_DiskImage + m_DiskIDAddress;
void UnallocateDiskImage(); }
uint8_t * GetDiskAddressRom()
{
return m_DiskImage + m_DiskRomAddress;
}
uint8_t * GetDiskAddressRam()
{
return m_DiskImage + m_DiskRamAddress;
}
uint32_t GetDiskSize() const
{
return m_DiskFileSize;
}
uint8_t * GetDiskHeader()
{
return m_DiskHeader;
}
void SetDiskAddressBuffer(uint32_t address)
{
m_DiskBufAddress = address;
}
uint32_t GetDiskAddressBlock(uint16_t head, uint16_t track, uint16_t block, uint16_t sector, uint16_t sectorsize);
uint32_t CalculateCrc();
stdstr GetRomName() const
{
return m_RomName;
}
stdstr GetFileName() const
{
return m_FileName;
}
stdstr GetDiskIdent() const
{
return m_DiskIdent;
}
Country GetCountry() const
{
return m_Country;
}
void UnallocateDiskImage();
LanguageStringID GetError() const { return m_ErrorMsg; } LanguageStringID GetError() const
{
return m_ErrorMsg;
}
private: private:
bool AllocateDiskImage(uint32_t DiskFileSize); bool AllocateDiskImage(uint32_t DiskFileSize);
bool AllocateDiskHeader(); bool AllocateDiskHeader();
bool AllocateAndLoadDiskImage(const char * FileLoc); bool AllocateAndLoadDiskImage(const char * FileLoc);
bool LoadDiskRAMImage(); bool LoadDiskRAMImage();
void ByteSwapDisk(); void ByteSwapDisk();
void ForceByteSwapDisk(); void ForceByteSwapDisk();
void SetError(LanguageStringID ErrorMsg); void SetError(LanguageStringID ErrorMsg);
void DetectSystemArea(); void DetectSystemArea();
bool IsSysSectorGood(uint32_t block, uint32_t sectorsize); bool IsSysSectorGood(uint32_t block, uint32_t sectorsize);
Country GetDiskCountryCode(); Country GetDiskCountryCode();
void InitSysDataD64(); void InitSysDataD64();
void DeinitSysDataD64(); void DeinitSysDataD64();
void GenerateLBAToPhysTable(); void GenerateLBAToPhysTable();
void DetectRamAddress(); void DetectRamAddress();
uint32_t LBAToVZone(uint32_t lba); uint32_t LBAToVZone(uint32_t lba);
uint32_t LBAToByte(uint32_t lba, uint32_t nlbas); uint32_t LBAToByte(uint32_t lba, uint32_t nlbas);
uint16_t LBAToPhys(uint32_t lba); uint16_t LBAToPhys(uint32_t lba);
uint16_t PhysToLBA(uint16_t head, uint16_t track, uint16_t block); uint16_t PhysToLBA(uint16_t head, uint16_t track, uint16_t block);
// Constant values // Constant values
enum { ReadFromRomSection = 0x400000, MameFormatSize = 0x0435B0C0, SDKFormatSize = 0x03DEC800, enum
DiskFormatMAME = 0x0, DiskFormatSDK = 0x1, DiskFormatD64 = 0x2 }; {
ReadFromRomSection = 0x400000,
MameFormatSize = 0x0435B0C0,
SDKFormatSize = 0x03DEC800,
DiskFormatMAME = 0x0,
DiskFormatSDK = 0x1,
DiskFormatD64 = 0x2
};
// Class variables // Class variables
CFile m_DiskFile; CFile m_DiskFile;
@ -78,24 +127,24 @@ private:
uint8_t m_DiskType; uint8_t m_DiskType;
bool m_isShadowDisk; bool m_isShadowDisk;
// Disk defines // Disk defines
#define MAX_LBA 0x10DB #define MAX_LBA 0x10DB
#define SIZE_LBA MAX_LBA+1 #define SIZE_LBA MAX_LBA + 1
#define SYSTEM_LBAS 24 #define SYSTEM_LBAS 24
#define DISKID_LBA 14 #define DISKID_LBA 14
#define DISK_COUNTRY_JPN 0xE848D316 #define DISK_COUNTRY_JPN 0xE848D316
#define DISK_COUNTRY_USA 0x2263EE56 #define DISK_COUNTRY_USA 0x2263EE56
#define DISK_COUNTRY_DEV 0x00000000 #define DISK_COUNTRY_DEV 0x00000000
#define SECTORS_PER_BLOCK 85 #define SECTORS_PER_BLOCK 85
#define BLOCKS_PER_TRACK 2 #define BLOCKS_PER_TRACK 2
const uint32_t SECTORSIZE[16] = { 232, 216, 208, 192, 176, 160, 144, 128, const uint32_t SECTORSIZE[16] = {232, 216, 208, 192, 176, 160, 144, 128,
216, 208, 192, 176, 160, 144, 128, 112 }; 216, 208, 192, 176, 160, 144, 128, 112};
const uint32_t SECTORSIZE_P[9] = { 232, 216, 208, 192, 176, 160, 144, 128, 112 }; const uint32_t SECTORSIZE_P[9] = {232, 216, 208, 192, 176, 160, 144, 128, 112};
const uint32_t ZoneTracks[16] = { 158, 158, 149, 149, 149, 149, 149, 114, const uint32_t ZoneTracks[16] = {158, 158, 149, 149, 149, 149, 149, 114,
158, 158, 149, 149, 149, 149, 149, 114 }; 158, 158, 149, 149, 149, 149, 149, 114};
const uint16_t VZONE_LBA_TBL[7][16] = { const uint16_t VZONE_LBA_TBL[7][16] = {
{0x0124, 0x0248, 0x035A, 0x047E, 0x05A2, 0x06B4, 0x07C6, 0x08D8, 0x09EA, 0x0AB6, 0x0B82, 0x0C94, 0x0DA6, 0x0EB8, 0x0FCA, 0x10DC}, {0x0124, 0x0248, 0x035A, 0x047E, 0x05A2, 0x06B4, 0x07C6, 0x08D8, 0x09EA, 0x0AB6, 0x0B82, 0x0C94, 0x0DA6, 0x0EB8, 0x0FCA, 0x10DC},
@ -104,7 +153,7 @@ private:
{0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x08B4, 0x09C6, 0x0AEA, 0x0C0E, 0x0D20, 0x0DEC, 0x0EB8, 0x0FCA, 0x10DC}, {0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x08B4, 0x09C6, 0x0AEA, 0x0C0E, 0x0D20, 0x0DEC, 0x0EB8, 0x0FCA, 0x10DC},
{0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x08B4, 0x09C6, 0x0AD8, 0x0BEA, 0x0D0E, 0x0E32, 0x0EFE, 0x0FCA, 0x10DC}, {0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x08B4, 0x09C6, 0x0AD8, 0x0BEA, 0x0D0E, 0x0E32, 0x0EFE, 0x0FCA, 0x10DC},
{0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x086E, 0x0980, 0x0A92, 0x0BA4, 0x0CB6, 0x0DC8, 0x0EEC, 0x1010, 0x10DC}, {0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x086E, 0x0980, 0x0A92, 0x0BA4, 0x0CB6, 0x0DC8, 0x0EEC, 0x1010, 0x10DC},
{0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x086E, 0x093A, 0x0A4C, 0x0B5E, 0x0C70, 0x0D82, 0x0E94, 0x0FB8, 0x10DC} {0x0124, 0x0248, 0x035A, 0x046C, 0x057E, 0x0690, 0x07A2, 0x086E, 0x093A, 0x0A4C, 0x0B5E, 0x0C70, 0x0D82, 0x0E94, 0x0FB8, 0x10DC},
}; };
const uint8_t VZONE_PZONE_TBL[7][16] = { const uint8_t VZONE_PZONE_TBL[7][16] = {
@ -114,31 +163,31 @@ private:
{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0xC, 0xB, 0xA, 0x9, 0x8, 0x6, 0x7, 0xF, 0xE, 0xD}, {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0xC, 0xB, 0xA, 0x9, 0x8, 0x6, 0x7, 0xF, 0xE, 0xD},
{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8, 0x7, 0xF, 0xE}, {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8, 0x7, 0xF, 0xE},
{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8, 0xF}, {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8, 0xF},
{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xF, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8} {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xF, 0xE, 0xD, 0xC, 0xB, 0xA, 0x9, 0x8},
}; };
const uint16_t SCYL_ZONE_TBL[2][8] = { const uint16_t SCYL_ZONE_TBL[2][8] = {
{0x000, 0x09E, 0x13C, 0x1D1, 0x266, 0x2FB, 0x390, 0x425}, {0x000, 0x09E, 0x13C, 0x1D1, 0x266, 0x2FB, 0x390, 0x425},
{0x091, 0x12F, 0x1C4, 0x259, 0x2EE, 0x383, 0x418, 0x48A} {0x091, 0x12F, 0x1C4, 0x259, 0x2EE, 0x383, 0x418, 0x48A},
}; };
const uint16_t OUTERCYL_TBL[8] = { 0x000, 0x09E, 0x13C, 0x1D1, 0x266, 0x2FB, 0x390, 0x425 }; const uint16_t OUTERCYL_TBL[8] = {0x000, 0x09E, 0x13C, 0x1D1, 0x266, 0x2FB, 0x390, 0x425};
const uint16_t RAM_START_LBA[7] = { 0x5A2, 0x7C6, 0x9EA, 0xC0E, 0xE32, 0x1010, 0x10DC }; const uint16_t RAM_START_LBA[7] = {0x5A2, 0x7C6, 0x9EA, 0xC0E, 0xE32, 0x1010, 0x10DC};
const uint32_t RAM_SIZES[7] = { 0x24A9DC0, 0x1C226C0, 0x1450F00, 0xD35680, 0x6CFD40, 0x1DA240, 0x0 }; const uint32_t RAM_SIZES[7] = {0x24A9DC0, 0x1C226C0, 0x1450F00, 0xD35680, 0x6CFD40, 0x1DA240, 0x0};
#define BLOCKSIZE(_zone) SECTORSIZE[_zone] * SECTORS_PER_BLOCK #define BLOCKSIZE(_zone) SECTORSIZE[_zone] * SECTORS_PER_BLOCK
#define TRACKSIZE(_zone) BLOCKSIZE(_zone) * BLOCKS_PER_TRACK #define TRACKSIZE(_zone) BLOCKSIZE(_zone) * BLOCKS_PER_TRACK
#define ZONESIZE(_zone) TRACKSIZE(_zone) * ZoneTracks[_zone] #define ZONESIZE(_zone) TRACKSIZE(_zone) * ZoneTracks[_zone]
#define VZONESIZE(_zone) TRACKSIZE(_zone) * (ZoneTracks[_zone] - 0xC) #define VZONESIZE(_zone) TRACKSIZE(_zone) * (ZoneTracks[_zone] - 0xC)
#define VZoneToPZone(x, y) VZONE_PZONE_TBL[y][x] #define VZoneToPZone(x, y) VZONE_PZONE_TBL[y][x]
// Used for MAME format // Used for MAME format
const uint32_t MAMEStartOffset[16] = const uint32_t MAMEStartOffset[16] =
{ 0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0, {0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0,
0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200 }; 0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200};
// Used for SDK and D64 format // Used for SDK and D64 format
uint16_t LBAToPhysTable[SIZE_LBA]; uint16_t LBAToPhysTable[SIZE_LBA];

View File

@ -1,11 +1,12 @@
#include "stdafx.h" #include "stdafx.h"
#include "N64Rom.h" #include "N64Rom.h"
#include "SystemGlobals.h" #include "SystemGlobals.h"
#include <Project64-core/3rdParty/zip.h>
#include <Common/md5.h>
#include <Common/Platform.h>
#include <Common/MemoryManagement.h>
#include <Common/IniFile.h> #include <Common/IniFile.h>
#include <Common/MemoryManagement.h>
#include <Common/Platform.h>
#include <Common/md5.h>
#include <Project64-core/3rdParty/zip.h>
#include <memory> #include <memory>
#ifdef _WIN32 #ifdef _WIN32
@ -95,7 +96,10 @@ bool CN64Rom::AllocateAndLoadN64Image(const char * FileLoc, bool LoadBootCodeOnl
for (count = 0; count < (int)RomFileSize; count += ReadFromRomSection) for (count = 0; count < (int)RomFileSize; count += ReadFromRomSection)
{ {
uint32_t dwToRead = RomFileSize - count; uint32_t dwToRead = RomFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; } if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
if (m_RomFile.Read(&m_ROMImage[count], dwToRead) != dwToRead) if (m_RomFile.Read(&m_ROMImage[count], dwToRead) != dwToRead)
{ {
@ -181,7 +185,10 @@ bool CN64Rom::AllocateAndLoadZipImage(const char * FileLoc, bool LoadBootCodeOnl
for (count = 4; count < (int)RomFileSize; count += ReadFromRomSection) for (count = 4; count < (int)RomFileSize; count += ReadFromRomSection)
{ {
uint32_t dwToRead = RomFileSize - count; uint32_t dwToRead = RomFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; } if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
dwRead = unzReadCurrentFile(file, &m_ROMImage[count], dwToRead); dwRead = unzReadCurrentFile(file, &m_ROMImage[count], dwToRead);
if (dwRead == 0) if (dwRead == 0)
@ -267,10 +274,13 @@ CICChip CN64Rom::GetCicChipID(uint8_t * RomData, uint64_t * CRC)
for (count = 0x40; count < 0x1000; count += 4) for (count = 0x40; count < 0x1000; count += 4)
{ {
if (count == 0xC00) crcAleck64 = crc; //From 0x40 to 0xC00 (Aleck64) if (count == 0xC00) crcAleck64 = crc; //From 0x40 to 0xC00 (Aleck64)
crc += *(uint32_t *)(RomData + count); crc += *(uint32_t *)(RomData + count);
} }
if (CRC != nullptr) { *CRC = crc; } if (CRC != nullptr)
{
*CRC = crc;
}
switch (crc) switch (crc)
{ {
@ -289,7 +299,10 @@ CICChip CN64Rom::GetCicChipID(uint8_t * RomData, uint64_t * CRC)
//Aleck64 CIC //Aleck64 CIC
if (crcAleck64 == 0x000000A5F80BF620) if (crcAleck64 == 0x000000A5F80BF620)
{ {
if (CRC != nullptr) { *CRC = crcAleck64; } if (CRC != nullptr)
{
*CRC = crcAleck64;
}
return CIC_NUS_5101; return CIC_NUS_5101;
} }
return CIC_UNKNOWN; return CIC_UNKNOWN;
@ -343,9 +356,18 @@ void CN64Rom::CalculateRomCrc()
case CIC_NUS_6103: v0 = 0xA3886759; break; case CIC_NUS_6103: v0 = 0xA3886759; break;
case CIC_NUS_6105: v0 = 0xDF26F436; break; case CIC_NUS_6105: v0 = 0xDF26F436; break;
case CIC_NUS_6106: v0 = 0x1FEA617A; break; case CIC_NUS_6106: v0 = 0x1FEA617A; break;
case CIC_NUS_DDUS: length = 0x000A0000; v0 = 0x861AE3A7; break; case CIC_NUS_DDUS:
case CIC_NUS_8303: length = 0x000A0000; v0 = 0x8331D4CA; break; length = 0x000A0000;
case CIC_NUS_8401: length = 0x000A0000; v0 = 0x0D8303E2; break; v0 = 0x861AE3A7;
break;
case CIC_NUS_8303:
length = 0x000A0000;
v0 = 0x8331D4CA;
break;
case CIC_NUS_8401:
length = 0x000A0000;
v0 = 0x0D8303E2;
break;
case CIC_NUS_5101: v0 = 0x95104FDD; break; case CIC_NUS_5101: v0 = 0x95104FDD; break;
default: default:
return; return;
@ -353,7 +375,7 @@ void CN64Rom::CalculateRomCrc()
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READWRITE); ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READWRITE);
if (m_CicChip == CIC_NUS_5101 && (*(uint32_t*)(m_ROMImage + 0x8) == 0x80100400)) if (m_CicChip == CIC_NUS_5101 && (*(uint32_t *)(m_ROMImage + 0x8) == 0x80100400))
length = 0x003FE000; length = 0x003FE000;
v1 = 0; v1 = 0;
@ -374,7 +396,8 @@ void CN64Rom::CalculateRomCrc()
v1 = a3 + v0; v1 = a3 + v0;
a1 = v1; a1 = v1;
if (v1 < a3) { if (v1 < a3)
{
if (m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_8303) if (m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_8303)
{ {
t2 = t2 ^ t3; t2 = t2 ^ t3;
@ -408,7 +431,8 @@ void CN64Rom::CalculateRomCrc()
{ {
t4 = (v0 ^ (*(uint32_t *)(m_ROMImage + (0xFF & t0) + 0x750))) + t4; t4 = (v0 ^ (*(uint32_t *)(m_ROMImage + (0xFF & t0) + 0x750))) + t4;
} }
else t4 = (v0 ^ s0) + t4; else
t4 = (v0 ^ s0) + t4;
} }
if (m_CicChip == CIC_NUS_6103) if (m_CicChip == CIC_NUS_6103)
{ {
@ -444,10 +468,22 @@ CICChip CN64Rom::CicChipID()
bool CN64Rom::IsValidRomImage(uint8_t Test[4]) bool CN64Rom::IsValidRomImage(uint8_t Test[4])
{ {
if (*((uint32_t *)&Test[0]) == 0x40123780) { return true; } if (*((uint32_t *)&Test[0]) == 0x40123780)
if (*((uint32_t *)&Test[0]) == 0x12408037) { return true; } {
if (*((uint32_t *)&Test[0]) == 0x80371240) { return true; } return true;
if (*((uint32_t *)&Test[0]) == 0x40072780) { return true; } // 64DD IPL }
if (*((uint32_t *)&Test[0]) == 0x12408037)
{
return true;
}
if (*((uint32_t *)&Test[0]) == 0x80371240)
{
return true;
}
if (*((uint32_t *)&Test[0]) == 0x40072780)
{
return true;
} // 64DD IPL
return false; return false;
} }
@ -501,7 +537,8 @@ void CN64Rom::CleanRomName(char * RomName, bool byteswap)
{ {
switch (RomName[count]) switch (RomName[count])
{ {
case '/': case '\\': RomName[count] = '-'; break; case '/':
case '\\': RomName[count] = '-'; break;
case ':': RomName[count] = ';'; break; case ':': RomName[count] = ';'; break;
} }
} }
@ -528,16 +565,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
stdstr FullPath = FileLoc; stdstr FullPath = FileLoc;
// This should be a 7-zip file // This should be a 7-zip file
char * SubFile = strstr(const_cast<char*>(FullPath.c_str()), "?"); char * SubFile = strstr(const_cast<char *>(FullPath.c_str()), "?");
if (SubFile != nullptr) if (SubFile != nullptr)
{ {
*SubFile = '\0'; *SubFile = '\0';
SubFile += 1; SubFile += 1;
} }
//else load first found file until dialog is implemented //else load first found file until dialog is implemented
//{ //{
// Pop up a dialog and select file // Pop up a dialog and select file
// Allocate memory for sub name and copy selected file name to variable // Allocate memory for sub name and copy selected file name to variable
//} //}
C7zip ZipFile(FullPath.c_str()); C7zip ZipFile(FullPath.c_str());
@ -563,7 +600,10 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
// Get the size of the ROM and try to allocate the memory needed // Get the size of the ROM and try to allocate the memory needed
uint32_t RomFileSize = (uint32_t)f->Size; uint32_t RomFileSize = (uint32_t)f->Size;
// If loading boot code then just load the first 0x1000 bytes // If loading boot code then just load the first 0x1000 bytes
if (LoadBootCodeOnly) { RomFileSize = 0x1000; } if (LoadBootCodeOnly)
{
RomFileSize = 0x1000;
}
if (!AllocateRomImage(RomFileSize)) if (!AllocateRomImage(RomFileSize))
{ {
@ -582,11 +622,11 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (!IsValidRomImage(m_ROMImage)) if (!IsValidRomImage(m_ROMImage))
{ {
if (i < ZipFile.NumFiles() - 1) if (i < ZipFile.NumFiles() - 1)
{ {
UnallocateRomImage(); UnallocateRomImage();
continue; continue;
} }
SetError(MSG_FAIL_IMAGE); SetError(MSG_FAIL_IMAGE);
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)"); WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false; return false;
@ -674,7 +714,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (GameIdentifiers.find(m_RomIdent.c_str()) == GameIdentifiers.end()) if (GameIdentifiers.find(m_RomIdent.c_str()) == GameIdentifiers.end())
{ {
char InternalName[22] = { 0 }; char InternalName[22] = {0};
memcpy(InternalName, (void *)(m_ROMImage + 0x20), 20); memcpy(InternalName, (void *)(m_ROMImage + 0x20), 20);
CN64Rom::CleanRomName(InternalName); CN64Rom::CleanRomName(InternalName);
@ -697,7 +737,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
} }
else if (!IsLoadedRomDDIPL()) else if (!IsLoadedRomDDIPL())
{ {
g_Settings->SaveString(Game_GameName, m_RomName.c_str()); // Use base games save file if loaded in combo g_Settings->SaveString(Game_GameName, m_RomName.c_str()); // Use base games save file if loaded in combo
} }
} }
@ -724,7 +764,7 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
stdstr FullPath = FileLoc; stdstr FullPath = FileLoc;
// This should be a 7-zip file // This should be a 7-zip file
char * SubFile = strstr(const_cast<char*>(FullPath.c_str()), "?"); char * SubFile = strstr(const_cast<char *>(FullPath.c_str()), "?");
if (SubFile != nullptr) if (SubFile != nullptr)
{ {
*SubFile = '\0'; *SubFile = '\0';
@ -732,8 +772,8 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
} }
//else load first found file until dialog is implemented //else load first found file until dialog is implemented
//{ //{
// Pop up a dialog and select file // Pop up a dialog and select file
// Allocate memory for sub name and copy selected file name to variable // Allocate memory for sub name and copy selected file name to variable
//} //}
C7zip ZipFile(FullPath.c_str()); C7zip ZipFile(FullPath.c_str());
@ -759,7 +799,10 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
// Get the size of the ROM and try to allocate the memory needed // Get the size of the ROM and try to allocate the memory needed
uint32_t RomFileSize = (uint32_t)f->Size; uint32_t RomFileSize = (uint32_t)f->Size;
// If loading boot code then just load the first 0x1000 bytes // If loading boot code then just load the first 0x1000 bytes
if (LoadBootCodeOnly) { RomFileSize = 0x1000; } if (LoadBootCodeOnly)
{
RomFileSize = 0x1000;
}
if (!AllocateRomImage(RomFileSize)) if (!AllocateRomImage(RomFileSize))
{ {
@ -827,7 +870,7 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
if (strlen(RomName) == 0) if (strlen(RomName) == 0)
{ {
strcpy(RomName, CPath(FileLoc).GetName().c_str()); strcpy(RomName, CPath(FileLoc).GetName().c_str());
CN64Rom::CleanRomName(RomName,false); CN64Rom::CleanRomName(RomName, false);
} }
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName); WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Project64-core/Multilanguage.h>
#include <Project64-core/N64System/N64Types.h> #include <Project64-core/N64System/N64Types.h>
#include <Project64-core/Settings/DebugSettings.h> #include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/Multilanguage.h>
class CN64Rom : class CN64Rom :
protected CDebugSettings protected CDebugSettings
@ -18,17 +18,38 @@ public:
void SaveRomSettingID(bool temp); void SaveRomSettingID(bool temp);
void ClearRomSettingID(); void ClearRomSettingID();
CICChip CicChipID(); CICChip CicChipID();
uint8_t * GetRomAddress() const { return m_ROMImage; } uint8_t * GetRomAddress() const
uint32_t GetRomSize() const { return m_RomFileSize; } {
const std::string & GetRomMD5() const { return m_MD5; } return m_ROMImage;
const std::string & GetRomName() const { return m_RomName; } }
const std::string & GetFileName() const { return m_FileName; } uint32_t GetRomSize() const
Country GetCountry() const { return m_Country; } {
return m_RomFileSize;
}
const std::string & GetRomMD5() const
{
return m_MD5;
}
const std::string & GetRomName() const
{
return m_RomName;
}
const std::string & GetFileName() const
{
return m_FileName;
}
Country GetCountry() const
{
return m_Country;
}
bool IsPal(); bool IsPal();
void UnallocateRomImage(); void UnallocateRomImage();
// Get a message ID for the reason that you failed to load the ROM // Get a message ID for the reason that you failed to load the ROM
LanguageStringID GetError() const { return m_ErrorMsg; } LanguageStringID GetError() const
{
return m_ErrorMsg;
}
static CICChip GetCicChipID(uint8_t * RomData, uint64_t * CRC = nullptr); static CICChip GetCicChipID(uint8_t * RomData, uint64_t * CRC = nullptr);
static void CleanRomName(char * RomName, bool byteswap = true); static void CleanRomName(char * RomName, bool byteswap = true);
@ -44,7 +65,10 @@ private:
static void NotificationCB(const char * Status, CN64Rom * _this); static void NotificationCB(const char * Status, CN64Rom * _this);
// Constant values // Constant values
enum { ReadFromRomSection = 0x400000 }; enum
{
ReadFromRomSection = 0x400000
};
// Class variables // Class variables
CFile m_RomFile; CFile m_RomFile;

View File

@ -1,26 +1,27 @@
#include "stdafx.h" #include "stdafx.h"
#include "N64System.h" #include "N64System.h"
#include <Common/Util.h>
#include <Project64-core/3rdParty/zip.h> #include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/Debugger.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/Transferpak.h>
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Mips/Disk.h>
#include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/N64System/Enhancement/Enhancements.h>
#include <Project64-core/N64System/N64Rom.h>
#include <Project64-core/ExceptionHandler.h> #include <Project64-core/ExceptionHandler.h>
#include <Project64-core/Logging.h> #include <Project64-core/Logging.h>
#include <Project64-core/Debugger.h> #include <Project64-core/N64System/Enhancement/Enhancements.h>
#include <Common/Util.h> #include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
#include <Project64-core/N64System/Mips/Disk.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Mips/Transferpak.h>
#include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/N64System/N64Rom.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <float.h> #include <float.h>
#include <time.h> #include <time.h>
#if defined(ANDROID) #if defined(ANDROID)
#include <utime.h> #include <utime.h>
#endif #endif
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list #pragma warning(disable : 4355) // Disable 'this' : used in base member initializer list
CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) : CN64System::CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem) :
CSystemEvents(this, Plugins), CSystemEvents(this, Plugins),
@ -650,27 +651,27 @@ bool CN64System::SelectAndLoadFileImageIPL(Country country, bool combo)
LanguageStringID IPLROMError; LanguageStringID IPLROMError;
switch (country) switch (country)
{ {
case Country_Japan: case Country_Japan:
IPLROMPathSetting = File_DiskIPLPath; IPLROMPathSetting = File_DiskIPLPath;
IPLROMError = MSG_IPL_REQUIRED; IPLROMError = MSG_IPL_REQUIRED;
break; break;
case Country_NorthAmerica: case Country_NorthAmerica:
IPLROMPathSetting = File_DiskIPLUSAPath; IPLROMPathSetting = File_DiskIPLUSAPath;
IPLROMError = MSG_USA_IPL_REQUIRED; IPLROMError = MSG_USA_IPL_REQUIRED;
break; break;
case Country_Unknown: case Country_Unknown:
default: default:
IPLROMPathSetting = File_DiskIPLTOOLPath; IPLROMPathSetting = File_DiskIPLTOOLPath;
IPLROMError = MSG_TOOL_IPL_REQUIRED; IPLROMError = MSG_TOOL_IPL_REQUIRED;
if (combo && !CPath(g_Settings->LoadStringVal(File_DiskIPLTOOLPath).c_str()).Exists()) if (combo && !CPath(g_Settings->LoadStringVal(File_DiskIPLTOOLPath).c_str()).Exists())
{ {
// Development IPL is not needed for combo ROM + disk loading // Development IPL is not needed for combo ROM + disk loading
if (CPath(g_Settings->LoadStringVal(File_DiskIPLPath).c_str()).Exists()) if (CPath(g_Settings->LoadStringVal(File_DiskIPLPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLPath; IPLROMPathSetting = File_DiskIPLPath;
else if (CPath(g_Settings->LoadStringVal(File_DiskIPLUSAPath).c_str()).Exists()) else if (CPath(g_Settings->LoadStringVal(File_DiskIPLUSAPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLUSAPath; IPLROMPathSetting = File_DiskIPLUSAPath;
} }
break; break;
} }
if (!CPath(g_Settings->LoadStringVal(IPLROMPathSetting).c_str()).Exists()) if (!CPath(g_Settings->LoadStringVal(IPLROMPathSetting).c_str()).Exists())
@ -822,7 +823,8 @@ void CN64System::EndEmulation(void)
void CN64System::Pause() void CN64System::Pause()
{ {
if (m_Plugins && m_Plugins->Control()->EmulationPaused) { if (m_Plugins && m_Plugins->Control()->EmulationPaused)
{
m_Plugins->Control()->EmulationPaused(); m_Plugins->Control()->EmulationPaused();
} }
if (m_EndEmulation) if (m_EndEmulation)
@ -838,7 +840,7 @@ void CN64System::Pause()
} }
m_hPauseEvent.IsTriggered(SyncEvent::INFINITE_TIMEOUT); m_hPauseEvent.IsTriggered(SyncEvent::INFINITE_TIMEOUT);
m_hPauseEvent.Reset(); m_hPauseEvent.Reset();
g_Settings->SaveBool(GameRunning_CPU_Paused, (uint32_t)false); g_Settings->SaveBool(GameRunning_CPU_Paused, (uint32_t) false);
if (pause_type == PauseType_FromMenu) if (pause_type == PauseType_FromMenu)
{ {
g_Notify->DisplayMessage(2, MSG_CPU_RESUMED); g_Notify->DisplayMessage(2, MSG_CPU_RESUMED);
@ -1145,15 +1147,15 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU)
case CIC_NUS_6101: case CIC_NUS_6101:
m_Reg.m_GPR[22].DW = 0x000000000000003F; m_Reg.m_GPR[22].DW = 0x000000000000003F;
break; break;
case CIC_NUS_8303: // 64DD IPL CIC case CIC_NUS_8303: // 64DD IPL CIC
case CIC_NUS_8401: // 64DD IPL tool CIC case CIC_NUS_8401: // 64DD IPL tool CIC
case CIC_NUS_5167: // 64DD conversion CIC case CIC_NUS_5167: // 64DD conversion CIC
m_Reg.m_GPR[22].DW = 0x00000000000000DD; m_Reg.m_GPR[22].DW = 0x00000000000000DD;
break; break;
case CIC_NUS_DDUS: // 64DD US IPL CIC case CIC_NUS_DDUS: // 64DD US IPL CIC
m_Reg.m_GPR[22].DW = 0x00000000000000DE; m_Reg.m_GPR[22].DW = 0x00000000000000DE;
break; break;
case CIC_NUS_5101: // Aleck64 CIC case CIC_NUS_5101: // Aleck64 CIC
m_Reg.m_GPR[22].DW = 0x00000000000000AC; m_Reg.m_GPR[22].DW = 0x00000000000000AC;
break; break;
case CIC_UNKNOWN: case CIC_UNKNOWN:
@ -1266,8 +1268,8 @@ void CN64System::ExecuteCPU()
switch (cpuType) switch (cpuType)
{ {
case CPU_Recompiler: ExecuteRecompiler(); break; case CPU_Recompiler: ExecuteRecompiler(); break;
case CPU_SyncCores: ExecuteSyncCPU(); break; case CPU_SyncCores: ExecuteSyncCPU(); break;
default: ExecuteInterpret(); break; default: ExecuteInterpret(); break;
} }
WriteTrace(TraceN64System, TraceDebug, "CPU finished executing"); WriteTrace(TraceN64System, TraceDebug, "CPU finished executing");
CpuStopped(); CpuStopped();
@ -1307,7 +1309,7 @@ void CN64System::CpuStopped()
WriteTrace(TraceN64System, TraceDebug, "Start"); WriteTrace(TraceN64System, TraceDebug, "Start");
if (!m_InReset) if (!m_InReset)
{ {
g_Settings->SaveBool(GameRunning_CPU_Running, (uint32_t)false); g_Settings->SaveBool(GameRunning_CPU_Running, (uint32_t) false);
g_Notify->DisplayMessage(5, MSG_EMULATION_ENDED); g_Notify->DisplayMessage(5, MSG_EMULATION_ENDED);
} }
if (m_SyncCPU) if (m_SyncCPU)
@ -1323,10 +1325,16 @@ void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycl
// Update the number of cycles to skip // Update the number of cycles to skip
m_CyclesToSkip -= Cycles; m_CyclesToSkip -= Cycles;
if (m_CyclesToSkip < 0) { m_CyclesToSkip = 0; } if (m_CyclesToSkip < 0)
{
m_CyclesToSkip = 0;
}
// Run the other CPU For the same amount of cycles // Run the other CPU For the same amount of cycles
if (CyclesToExecute < 0) { return; } if (CyclesToExecute < 0)
{
return;
}
SecondCPU->SetActiveSystem(true); SecondCPU->SetActiveSystem(true);
CInterpreterCPU::ExecuteOps(Cycles); CInterpreterCPU::ExecuteOps(Cycles);
@ -1343,11 +1351,23 @@ void CN64System::SyncCPUPC(CN64System * const SecondCPU)
ErrorFound = true; ErrorFound = true;
} }
if (m_TLB != SecondCPU->m_TLB) { ErrorFound = true; } if (m_TLB != SecondCPU->m_TLB)
if (m_SystemTimer != SecondCPU->m_SystemTimer) { ErrorFound = true; } {
if (m_NextTimer != SecondCPU->m_NextTimer) { ErrorFound = true; } ErrorFound = true;
}
if (m_SystemTimer != SecondCPU->m_SystemTimer)
{
ErrorFound = true;
}
if (m_NextTimer != SecondCPU->m_NextTimer)
{
ErrorFound = true;
}
if (ErrorFound) { DumpSyncErrors(SecondCPU); } if (ErrorFound)
{
DumpSyncErrors(SecondCPU);
}
for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--)
{ {
@ -1364,7 +1384,8 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
g_SystemTimer->UpdateTimers(); g_SystemTimer->UpdateTimers();
#ifdef TEST_SP_TRACKING #ifdef TEST_SP_TRACKING
if (m_CurrentSP != GPR[29].UW[0]) { if (m_CurrentSP != GPR[29].UW[0])
{
ErrorFound = true; ErrorFound = true;
} }
#endif #endif
@ -1413,11 +1434,26 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
{ {
ErrorFound = true; ErrorFound = true;
} }
if (m_TLB != SecondCPU->m_TLB) { ErrorFound = true; } if (m_TLB != SecondCPU->m_TLB)
if (m_Reg.m_FPCR[0] != SecondCPU->m_Reg.m_FPCR[0]) { ErrorFound = true; } {
if (m_Reg.m_FPCR[31] != SecondCPU->m_Reg.m_FPCR[31]) { ErrorFound = true; } ErrorFound = true;
if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW) { ErrorFound = true; } }
if (m_Reg.m_LO.DW != SecondCPU->m_Reg.m_LO.DW) { ErrorFound = true; } if (m_Reg.m_FPCR[0] != SecondCPU->m_Reg.m_FPCR[0])
{
ErrorFound = true;
}
if (m_Reg.m_FPCR[31] != SecondCPU->m_Reg.m_FPCR[31])
{
ErrorFound = true;
}
if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW)
{
ErrorFound = true;
}
if (m_Reg.m_LO.DW != SecondCPU->m_Reg.m_LO.DW)
{
ErrorFound = true;
}
/*if (m_SyncCount > 4788000) /*if (m_SyncCount > 4788000)
{ {
if (memcmp(m_MMU_VM.Rdram(),SecondCPU->m_MMU_VM.Rdram(),RdramSize()) != 0) if (memcmp(m_MMU_VM.Rdram(),SecondCPU->m_MMU_VM.Rdram(),RdramSize()) != 0)
@ -1446,7 +1482,7 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
if (bFastSP() && m_Recomp) if (bFastSP() && m_Recomp)
{ {
#if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64) #if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__,__LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
#else #else
if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF)))
{ {
@ -1455,9 +1491,18 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
#endif #endif
} }
if (m_SystemTimer != SecondCPU->m_SystemTimer) { ErrorFound = true; } if (m_SystemTimer != SecondCPU->m_SystemTimer)
if (m_NextTimer != SecondCPU->m_NextTimer) { ErrorFound = true; } {
if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) { ErrorFound = true; } ErrorFound = true;
}
if (m_NextTimer != SecondCPU->m_NextTimer)
{
ErrorFound = true;
}
if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel)
{
ErrorFound = true;
}
for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i++) for (int i = 0, n = sizeof(m_Reg.m_Mips_Interface) / sizeof(m_Reg.m_Mips_Interface[0]); i < n; i++)
{ {
@ -1483,7 +1528,10 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
} }
} }
if (ErrorFound) { DumpSyncErrors(SecondCPU); } if (ErrorFound)
{
DumpSyncErrors(SecondCPU);
}
for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--) for (int i = (sizeof(m_LastSuccessSyncPC) / sizeof(m_LastSuccessSyncPC[0])) - 1; i > 0; i--)
{ {
@ -1530,8 +1578,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (m_Reg.m_GPR[count].UW[0] != SecondCPU->m_Reg.m_GPR[count].UW[0]) if (m_Reg.m_GPR[count].UW[0] != SecondCPU->m_Reg.m_GPR[count].UW[0])
{ {
Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count],
m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0],
SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]);
} }
} }
} }
@ -1542,8 +1590,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (m_Reg.m_GPR[count].DW != SecondCPU->m_Reg.m_GPR[count].DW) if (m_Reg.m_GPR[count].DW != SecondCPU->m_Reg.m_GPR[count].DW)
{ {
Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], Error.LogF("GPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count],
m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0],
SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]);
} }
} }
} }
@ -1552,8 +1600,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (m_Reg.m_FPR[count].DW != SecondCPU->m_Reg.m_FPR[count].DW) if (m_Reg.m_FPR[count].DW != SecondCPU->m_Reg.m_FPR[count].DW)
{ {
Error.LogF("FPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count], Error.LogF("FPR[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count],
m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0], m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0],
SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]); SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]);
} }
} }
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
@ -1561,7 +1609,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (m_Reg.m_FPCR[count] != SecondCPU->m_Reg.m_FPCR[count]) if (m_Reg.m_FPCR[count] != SecondCPU->m_Reg.m_FPCR[count])
{ {
Error.LogF("FPCR[%s] 0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count], Error.LogF("FPCR[%s] 0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count],
m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]); m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]);
} }
} }
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
@ -1569,7 +1617,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (m_Reg.m_CP0[count] != SecondCPU->m_Reg.m_CP0[count]) if (m_Reg.m_CP0[count] != SecondCPU->m_Reg.m_CP0[count])
{ {
Error.LogF("CP0[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::Cop0[count], Error.LogF("CP0[%s] 0x%08X%08X, 0x%08X%08X\r\n", CRegName::Cop0[count],
(uint32_t)(m_Reg.m_CP0[count] >> 32), (uint32_t)m_Reg.m_CP0[count], (uint32_t)(SecondCPU->m_Reg.m_CP0[count] >> 32), (uint32_t)(SecondCPU->m_Reg.m_CP0[count])); (uint32_t)(m_Reg.m_CP0[count] >> 32), (uint32_t)m_Reg.m_CP0[count], (uint32_t)(SecondCPU->m_Reg.m_CP0[count] >> 32), (uint32_t)(SecondCPU->m_Reg.m_CP0[count]));
} }
} }
if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW) if (m_Reg.m_HI.DW != SecondCPU->m_Reg.m_HI.DW)
@ -1616,7 +1664,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (bFastSP() && m_Recomp) if (bFastSP() && m_Recomp)
{ {
#if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64) #if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__,__LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
#else #else
if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF))) if (m_Recomp->MemoryStackPos() != (uint32_t)(m_MMU_VM.Rdram() + (m_Reg.m_GPR[29].W[0] & 0x1FFFFFFF)))
{ {
@ -1625,7 +1673,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
#endif #endif
} }
uint32_t * Rdram = (uint32_t *)m_MMU_VM.Rdram(), *Rdram2 = (uint32_t *)SecondCPU->m_MMU_VM.Rdram(); uint32_t *Rdram = (uint32_t *)m_MMU_VM.Rdram(), *Rdram2 = (uint32_t *)SecondCPU->m_MMU_VM.Rdram();
for (int z = 0, n = (RdramSize() >> 2); z < n; z++) for (int z = 0, n = (RdramSize() >> 2); z < n; z++)
{ {
if (Rdram[z] != Rdram2[z]) if (Rdram[z] != Rdram2[z])
@ -1634,7 +1682,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
} }
} }
uint32_t * Imem = (uint32_t *)m_MMU_VM.Imem(), *Imem2 = (uint32_t *)SecondCPU->m_MMU_VM.Imem(); uint32_t *Imem = (uint32_t *)m_MMU_VM.Imem(), *Imem2 = (uint32_t *)SecondCPU->m_MMU_VM.Imem();
for (int z = 0; z < (0x1000 >> 2); z++) for (int z = 0; z < (0x1000 >> 2); z++)
{ {
if (Imem[z] != Imem2[z]) if (Imem[z] != Imem2[z])
@ -1642,7 +1690,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
Error.LogF("IMEM[%X]: %X %X\r\n", z << 2, Imem[z], Imem2[z]); Error.LogF("IMEM[%X]: %X %X\r\n", z << 2, Imem[z], Imem2[z]);
} }
} }
uint32_t * Dmem = (uint32_t *)m_MMU_VM.Dmem(), *Dmem2 = (uint32_t *)SecondCPU->m_MMU_VM.Dmem(); uint32_t *Dmem = (uint32_t *)m_MMU_VM.Dmem(), *Dmem2 = (uint32_t *)SecondCPU->m_MMU_VM.Dmem();
for (int z = 0; z < (0x1000 >> 2); z++) for (int z = 0; z < (0x1000 >> 2); z++)
{ {
if (Dmem[z] != Dmem2[z]) if (Dmem[z] != Dmem2[z])
@ -1665,27 +1713,27 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("GPR[%s], 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count], Error.LogF("GPR[%s], 0x%08X%08X, 0x%08X%08X\r\n", CRegName::GPR[count],
m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0], m_Reg.m_GPR[count].W[1], m_Reg.m_GPR[count].W[0],
SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]); SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->m_Reg.m_GPR[count].W[0]);
} }
Error.Log("\r\n"); Error.Log("\r\n");
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("FPR[%s],%*s0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count], Error.LogF("FPR[%s],%*s0x%08X%08X, 0x%08X%08X\r\n", CRegName::FPR[count],
count < 10 ? 9 : 8, " ", m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0], count < 10 ? 9 : 8, " ", m_Reg.m_FPR[count].W[1], m_Reg.m_FPR[count].W[0],
SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]); SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->m_Reg.m_FPR[count].W[0]);
} }
Error.Log("\r\n"); Error.Log("\r\n");
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("FPR_S[%s],%*s%f, %f\r\n", CRegName::FPR[count], Error.LogF("FPR_S[%s],%*s%f, %f\r\n", CRegName::FPR[count],
count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_S[count]), *(SecondCPU->m_Reg.m_FPR_S[count])); count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_S[count]), *(SecondCPU->m_Reg.m_FPR_S[count]));
} }
Error.Log("\r\n"); Error.Log("\r\n");
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("FPR_D[%s],%*s%f, %f\r\n", CRegName::FPR[count], Error.LogF("FPR_D[%s],%*s%f, %f\r\n", CRegName::FPR[count],
count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_D[count]), *(SecondCPU->m_Reg.m_FPR_D[count])); count < 10 ? 7 : 6, " ", *(m_Reg.m_FPR_D[count]), *(SecondCPU->m_Reg.m_FPR_D[count]));
} }
Error.Log("\r\n"); Error.Log("\r\n");
Error.LogF("Rounding model, 0x%08X, 0x%08X\r\n", m_Reg.m_RoundingModel, SecondCPU->m_Reg.m_RoundingModel); Error.LogF("Rounding model, 0x%08X, 0x%08X\r\n", m_Reg.m_RoundingModel, SecondCPU->m_Reg.m_RoundingModel);
@ -1693,30 +1741,33 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count], Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count],
12 - strlen(CRegName::Cop0[count]), "", 12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]); m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
} }
Error.Log("\r\n"); Error.Log("\r\n");
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
Error.LogF("FPR_Ctrl[%s],%*s0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count], Error.LogF("FPR_Ctrl[%s],%*s0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count],
12 - strlen(CRegName::FPR_Ctrl[count]), "", 12 - strlen(CRegName::FPR_Ctrl[count]), "",
m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]); m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]);
} }
Error.Log("\r\n"); Error.Log("\r\n");
Error.LogF("HI 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_HI.UW[1], m_Reg.m_HI.UW[0], Error.LogF("HI 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_HI.UW[1], m_Reg.m_HI.UW[0],
SecondCPU->m_Reg.m_HI.UW[1], SecondCPU->m_Reg.m_HI.UW[0]); SecondCPU->m_Reg.m_HI.UW[1], SecondCPU->m_Reg.m_HI.UW[0]);
Error.LogF("LO 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_LO.UW[1], m_Reg.m_LO.UW[0], Error.LogF("LO 0x%08X%08X, 0x%08X%08X\r\n", m_Reg.m_LO.UW[1], m_Reg.m_LO.UW[0],
SecondCPU->m_Reg.m_LO.UW[1], SecondCPU->m_Reg.m_LO.UW[0]); SecondCPU->m_Reg.m_LO.UW[1], SecondCPU->m_Reg.m_LO.UW[0]);
Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count], Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count],
12 - strlen(CRegName::Cop0[count]), "", 12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]); m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
bool bHasTlb = false; bool bHasTlb = false;
for (count = 0; count < 32; count++) for (count = 0; count < 32; count++)
{ {
if (!m_TLB.TlbEntry(count).EntryDefined) { continue; } if (!m_TLB.TlbEntry(count).EntryDefined)
{
continue;
}
if (!bHasTlb) if (!bHasTlb)
{ {
Error.Log("\r\n"); Error.Log("\r\n");
@ -1724,9 +1775,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
bHasTlb = true; bHasTlb = true;
} }
Error.LogF("TLB[%2d], %08X, %08X, %08X, %08X\r\n", count, Error.LogF("TLB[%2d], %08X, %08X, %08X, %08X\r\n", count,
m_TLB.TlbEntry(count).EntryHi.Value, m_TLB.TlbEntry(count).PageMask.Value, m_TLB.TlbEntry(count).EntryHi.Value, m_TLB.TlbEntry(count).PageMask.Value,
SecondCPU->m_TLB.TlbEntry(count).EntryHi.Value, SecondCPU->m_TLB.TlbEntry(count).PageMask.Value SecondCPU->m_TLB.TlbEntry(count).EntryHi.Value, SecondCPU->m_TLB.TlbEntry(count).PageMask.Value);
);
} }
Error.Log("\r\n"); Error.Log("\r\n");
Error.Log("Code at PC:\r\n"); Error.Log("Code at PC:\r\n");
@ -1845,7 +1895,7 @@ bool CN64System::SaveState()
zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13); zipWriteInFileInZip(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8); zipWriteInFileInZip(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4); zipWriteInFileInZip(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
zipWriteInFileInZip(file, (void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); zipWriteInFileInZip(file, (void * const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
zipWriteInFileInZip(file, m_MMU_VM.PifRam(), 0x40); zipWriteInFileInZip(file, m_MMU_VM.PifRam(), 0x40);
zipWriteInFileInZip(file, m_MMU_VM.Rdram(), RdramSize); zipWriteInFileInZip(file, m_MMU_VM.Rdram(), RdramSize);
zipWriteInFileInZip(file, m_MMU_VM.Dmem(), 0x1000); zipWriteInFileInZip(file, m_MMU_VM.Dmem(), 0x1000);
@ -2073,7 +2123,7 @@ bool CN64System::LoadState(const char * FileName)
{ {
// Base ROM information (64DD IPL / compatible game ROM) and disk info check // Base ROM information (64DD IPL / compatible game ROM) and disk info check
if ((memcmp(LoadHeader, &g_Rom->GetRomAddress()[0x10], 0x20) != 0 || if ((memcmp(LoadHeader, &g_Rom->GetRomAddress()[0x10], 0x20) != 0 ||
memcmp(&LoadHeader[0x20], g_Disk->GetDiskAddressID(), 0x20) != 0) && memcmp(&LoadHeader[0x20], g_Disk->GetDiskAddressID(), 0x20) != 0) &&
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
{ {
return false; return false;
@ -2110,7 +2160,7 @@ bool CN64System::LoadState(const char * FileName)
unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13); unzReadCurrentFile(file, m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8); unzReadCurrentFile(file, m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4); unzReadCurrentFile(file, m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
unzReadCurrentFile(file, (void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); unzReadCurrentFile(file, (void * const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
unzReadCurrentFile(file, m_MMU_VM.PifRam(), 0x40); unzReadCurrentFile(file, m_MMU_VM.PifRam(), 0x40);
unzReadCurrentFile(file, m_MMU_VM.Rdram(), SaveRDRAMSize); unzReadCurrentFile(file, m_MMU_VM.Rdram(), SaveRDRAMSize);
unzReadCurrentFile(file, m_MMU_VM.Dmem(), 0x1000); unzReadCurrentFile(file, m_MMU_VM.Dmem(), 0x1000);
@ -2169,7 +2219,7 @@ bool CN64System::LoadState(const char * FileName)
{ {
// Base ROM information (64DD IPL / compatible game ROM) and disk info check // Base ROM information (64DD IPL / compatible game ROM) and disk info check
if ((memcmp(LoadHeader, &g_Rom->GetRomAddress()[0x10], 0x20) != 0 || if ((memcmp(LoadHeader, &g_Rom->GetRomAddress()[0x10], 0x20) != 0 ||
memcmp(&LoadHeader[0x20], g_Disk->GetDiskAddressID(), 0x20) != 0) && memcmp(&LoadHeader[0x20], g_Disk->GetDiskAddressID(), 0x20) != 0) &&
!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str())) !g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SAVE_STATE_HEADER).c_str()))
{ {
return false; return false;
@ -2205,7 +2255,7 @@ bool CN64System::LoadState(const char * FileName)
hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13); hSaveFile.Read(m_Reg.m_Peripheral_Interface, sizeof(uint32_t) * 13);
hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8); hSaveFile.Read(m_Reg.m_RDRAM_Interface, sizeof(uint32_t) * 8);
hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4); hSaveFile.Read(m_Reg.m_SerialInterface, sizeof(uint32_t) * 4);
hSaveFile.Read((void *const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32); hSaveFile.Read((void * const)&m_TLB.TlbEntry(0), sizeof(CTLB::TLB_ENTRY) * 32);
hSaveFile.Read(m_MMU_VM.PifRam(), 0x40); hSaveFile.Read(m_MMU_VM.PifRam(), 0x40);
hSaveFile.Read(m_MMU_VM.Rdram(), SaveRDRAMSize); hSaveFile.Read(m_MMU_VM.Rdram(), SaveRDRAMSize);
hSaveFile.Read(m_MMU_VM.Dmem(), 0x1000); hSaveFile.Read(m_MMU_VM.Dmem(), 0x1000);
@ -2283,7 +2333,10 @@ bool CN64System::LoadState(const char * FileName)
#ifdef TEST_SP_TRACKING #ifdef TEST_SP_TRACKING
m_CurrentSP = GPR[29].UW[0]; m_CurrentSP = GPR[29].UW[0];
#endif #endif
if (bFastSP() && m_Recomp) { m_Recomp->ResetMemoryStackPos(); } if (bFastSP() && m_Recomp)
{
m_Recomp->ResetMemoryStackPos();
}
if (g_Settings->LoadDword(Game_CpuType) == CPU_SyncCores) if (g_Settings->LoadDword(Game_CpuType) == CPU_SyncCores)
{ {
@ -2447,10 +2500,13 @@ void CN64System::RunRSP()
void CN64System::RefreshScreen() void CN64System::RefreshScreen()
{ {
PROFILE_TIMERS CPU_UsageAddr = Timer_None/*, ProfilingAddr = Timer_None*/; PROFILE_TIMERS CPU_UsageAddr = Timer_None /*, ProfilingAddr = Timer_None*/;
uint32_t VI_INTR_TIME = 500000; uint32_t VI_INTR_TIME = 500000;
if (bShowCPUPer()) { CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RefreshScreen); } if (bShowCPUPer())
{
CPU_UsageAddr = m_CPU_Usage.StartTimer(Timer_RefreshScreen);
}
// Calculate how many cycles to next refresh // Calculate how many cycles to next refresh
if (m_Reg.VI_V_SYNC_REG == 0) if (m_Reg.VI_V_SYNC_REG == 0)
@ -2482,16 +2538,19 @@ void CN64System::RefreshScreen()
} }
} }
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateScreen); } if (bShowCPUPer())
{
m_CPU_Usage.StartTimer(Timer_UpdateScreen);
}
__except_try() __except_try()
{ {
WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen starting"); WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen starting");
m_Plugins->Gfx()->UpdateScreen(); m_Plugins->Gfx()->UpdateScreen();
if (g_Debugger != nullptr && HaveDebugger()) if (g_Debugger != nullptr && HaveDebugger())
{ {
g_Debugger->FrameDrawn(); g_Debugger->FrameDrawn();
} }
WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen done"); WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen done");
} }
__except_catch() __except_catch()
@ -2502,18 +2561,27 @@ void CN64System::RefreshScreen()
if ((bBasicMode() || bLimitFPS()) && (!bSyncToAudio() || !FullSpeed())) if ((bBasicMode() || bLimitFPS()) && (!bSyncToAudio() || !FullSpeed()))
{ {
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_Idel); } if (bShowCPUPer())
{
m_CPU_Usage.StartTimer(Timer_Idel);
}
uint32_t FrameRate; uint32_t FrameRate;
if (m_Limiter.Timer_Process(&FrameRate) && bDisplayFrameRate()) if (m_Limiter.Timer_Process(&FrameRate) && bDisplayFrameRate())
{ {
m_FPS.DisplayViCounter(FrameRate, 0); m_FPS.DisplayViCounter(FrameRate, 0);
m_bCleanFrameBox = true; m_bCleanFrameBox = true;
} }
if (bShowCPUPer()) { m_CPU_Usage.StopTimer(); } if (bShowCPUPer())
{
m_CPU_Usage.StopTimer();
}
} }
else if (bDisplayFrameRate()) else if (bDisplayFrameRate())
{ {
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateFPS); } if (bShowCPUPer())
{
m_CPU_Usage.StartTimer(Timer_UpdateFPS);
}
m_FPS.UpdateViCounter(); m_FPS.UpdateViCounter();
m_bCleanFrameBox = true; m_bCleanFrameBox = true;
} }

View File

@ -3,22 +3,22 @@
#include <Common/Random.h> #include <Common/Random.h>
#include <Common/SyncEvent.h> #include <Common/SyncEvent.h>
#include <Common/Thread.h> #include <Common/Thread.h>
#include <Project64-core/Settings/N64SystemSettings.h> #include <Project64-core/Logging.h>
#include <Project64-core/N64System/Profiling.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/SystemEvents.h> #include <Project64-core/N64System/Mips/SystemEvents.h>
#include <Project64-core/N64System/Mips/SystemTiming.h> #include <Project64-core/N64System/Mips/SystemTiming.h>
#include <Project64-core/N64System/Mips/Mempak.h> #include <Project64-core/N64System/Profiling.h>
#include <Project64-core/Settings/DebugSettings.h> #include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/Plugin.h> #include <Project64-core/Plugin.h>
#include <Project64-core/Logging.h> #include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/Settings/N64SystemSettings.h>
#include "Mips/TLB.h"
#include "FramePerSecond.h" #include "FramePerSecond.h"
#include "Mips/TLB.h"
#include "SpeedLimiter.h" #include "SpeedLimiter.h"
typedef std::list<SystemEvent> EVENT_LIST; typedef std::list<SystemEvent> EVENT_LIST;
typedef std::map<uint32_t, uint32_t> FUNC_CALLS; typedef std::map<uint32_t, uint32_t> FUNC_CALLS;
@ -44,12 +44,12 @@ class CN64System :
protected CDebugSettings protected CDebugSettings
{ {
public: public:
typedef void(*CallBackFunction)(void *); typedef void (*CallBackFunction)(void *);
CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem); CN64System(CPlugins * Plugins, uint32_t randomizer_seed, bool SavesReadOnly, bool SyncSystem);
virtual ~CN64System(void); virtual ~CN64System(void);
bool m_EndEmulation; bool m_EndEmulation;
SAVE_CHIP_TYPE m_SaveUsing; SAVE_CHIP_TYPE m_SaveUsing;
// Methods // Methods
@ -70,10 +70,22 @@ public:
void ExternalEvent(SystemEvent action); // Covers GUI interactions and timers etc. void ExternalEvent(SystemEvent action); // Covers GUI interactions and timers etc.
void StartEmulation(bool NewThread); void StartEmulation(bool NewThread);
void EndEmulation(); void EndEmulation();
void AlterSpeed(const CSpeedLimiter::ESpeedChange SpeedChange) { m_Limiter.AlterSpeed(SpeedChange); } void AlterSpeed(const CSpeedLimiter::ESpeedChange SpeedChange)
void SetSpeed(int Speed) { m_Limiter.SetSpeed(Speed); } {
int GetSpeed(void) const { return m_Limiter.GetSpeed(); } m_Limiter.AlterSpeed(SpeedChange);
int GetBaseSpeed(void) const { return m_Limiter.GetBaseSpeed(); } }
void SetSpeed(int Speed)
{
m_Limiter.SetSpeed(Speed);
}
int GetSpeed(void) const
{
return m_Limiter.GetSpeed();
}
int GetBaseSpeed(void) const
{
return m_Limiter.GetBaseSpeed();
}
void Reset(bool bInitReg, bool ClearMenory); void Reset(bool bInitReg, bool ClearMenory);
void GameReset(); void GameReset();
void PluginReset(); void PluginReset();
@ -97,9 +109,18 @@ public:
void SyncSystem(); void SyncSystem();
void SyncSystemPC(); void SyncSystemPC();
CPlugins * GetPlugins() { return m_Plugins; } CPlugins * GetPlugins()
PIPELINE_STAGE PipelineStage() const { return m_PipelineStage; } {
uint32_t JumpToLocation() const { return m_JumpToLocation; } return m_Plugins;
}
PIPELINE_STAGE PipelineStage() const
{
return m_PipelineStage;
}
uint32_t JumpToLocation() const
{
return m_JumpToLocation;
}
private: private:
struct SETTING_CHANGED_CB struct SETTING_CHANGED_CB
@ -156,7 +177,7 @@ private:
void TLB_Changed(); void TLB_Changed();
SETTING_CALLBACK m_Callback; SETTING_CALLBACK m_Callback;
CPlugins * const m_Plugins; // The plugin container CPlugins * const m_Plugins; // The plugin container
CPlugins * m_SyncPlugins; CPlugins * m_SyncPlugins;
CN64System * m_SyncCPU; CN64System * m_SyncCPU;
CMipsMemoryVM m_MMU_VM; CMipsMemoryVM m_MMU_VM;
@ -199,7 +220,7 @@ private:
FUNC_CALLS m_FunctionCalls; FUNC_CALLS m_FunctionCalls;
// List of save state file IDs // List of save state file IDs
const uint32_t SaveID_0 = 0x23D8A6C8; // Main save state info (*.pj) const uint32_t SaveID_0 = 0x23D8A6C8; // Main save state info (*.pj)
const uint32_t SaveID_1 = 0x56D2CD23; // Extra data v1 (system timing) info (*.dat) const uint32_t SaveID_1 = 0x56D2CD23; // Extra data v1 (system timing) info (*.dat)
const uint32_t SaveID_2 = 0x750A6BEB; // Extra data v2 (timing + disk registers) (*.dat) const uint32_t SaveID_2 = 0x750A6BEB; // Extra data v2 (timing + disk registers) (*.dat)
}; };

View File

@ -31,44 +31,70 @@ enum PauseType
enum CPU_TYPE enum CPU_TYPE
{ {
CPU_Default = -1, CPU_Interpreter = 1, CPU_Recompiler = 2, CPU_SyncCores = 3 CPU_Default = -1,
CPU_Interpreter = 1,
CPU_Recompiler = 2,
CPU_SyncCores = 3
}; };
enum FRAMERATE_TYPE enum FRAMERATE_TYPE
{ {
FR_VIs = 0, FR_DLs = 1, FR_PERCENT = 2, FR_VIs_DLs = 3, FR_VIs = 0,
FR_DLs = 1,
FR_PERCENT = 2,
FR_VIs_DLs = 3,
}; };
enum SAVE_CHIP_TYPE enum SAVE_CHIP_TYPE
{ {
SaveChip_Auto = -1, SaveChip_Eeprom_4K, SaveChip_Eeprom_16K, SaveChip_Sram, SaveChip_FlashRam SaveChip_Auto = -1,
SaveChip_Eeprom_4K,
SaveChip_Eeprom_16K,
SaveChip_Sram,
SaveChip_FlashRam
}; };
enum SAVE_DISK_TYPE enum SAVE_DISK_TYPE
{ {
SaveDisk_ShadowFile = 0, SaveDisk_RAMFile = 1, SaveDisk_ShadowFile = 0,
SaveDisk_RAMFile = 1,
}; };
enum DISK_SEEK_TYPE enum DISK_SEEK_TYPE
{ {
DiskSeek_Turbo = 0, DiskSeek_Slow = 1, DiskSeek_Turbo = 0,
DiskSeek_Slow = 1,
}; };
enum FUNC_LOOKUP_METHOD enum FUNC_LOOKUP_METHOD
{ {
FuncFind_Default = -1, FuncFind_PhysicalLookup = 1, FuncFind_VirtualLookup = 2, FuncFind_ChangeMemory = 3, FuncFind_Default = -1,
FuncFind_PhysicalLookup = 1,
FuncFind_VirtualLookup = 2,
FuncFind_ChangeMemory = 3,
}; };
enum SYSTEM_TYPE enum SYSTEM_TYPE
{ {
SYSTEM_NTSC = 0, SYSTEM_PAL = 1, SYSTEM_MPAL = 2 SYSTEM_NTSC = 0,
SYSTEM_PAL = 1,
SYSTEM_MPAL = 2
}; };
enum CICChip enum CICChip
{ {
CIC_UNKNOWN = -1, CIC_NUS_6101 = 1, CIC_NUS_6102 = 2, CIC_NUS_6103 = 3, CIC_UNKNOWN = -1,
CIC_NUS_6104 = 4, CIC_NUS_6105 = 5, CIC_NUS_6106 = 6, CIC_NUS_5167 = 7, CIC_NUS_6101 = 1,
CIC_NUS_8303 = 8, CIC_NUS_DDUS = 9, CIC_NUS_8401 = 10, CIC_NUS_5101 = 11, CIC_NUS_6102 = 2,
CIC_NUS_6103 = 3,
CIC_NUS_6104 = 4,
CIC_NUS_6105 = 5,
CIC_NUS_6106 = 6,
CIC_NUS_5167 = 7,
CIC_NUS_8303 = 8,
CIC_NUS_DDUS = 9,
CIC_NUS_8401 = 10,
CIC_NUS_5101 = 11,
CIC_MINI_IPL3 = 12, CIC_MINI_IPL3 = 12,
}; };
@ -129,27 +155,27 @@ enum PIPELINE_STAGE
union MIPS_WORD union MIPS_WORD
{ {
int32_t W; int32_t W;
uint32_t UW; uint32_t UW;
int16_t HW[2]; int16_t HW[2];
uint16_t UHW[2]; uint16_t UHW[2];
int8_t B[4]; int8_t B[4];
uint8_t UB[4]; uint8_t UB[4];
float F; float F;
}; };
union MIPS_DWORD union MIPS_DWORD
{ {
int64_t DW; int64_t DW;
uint64_t UDW; uint64_t UDW;
int32_t W[2]; int32_t W[2];
uint32_t UW[2]; uint32_t UW[2];
int16_t HW[4]; int16_t HW[4];
uint16_t UHW[4]; uint16_t UHW[4];
int8_t B[8]; int8_t B[8];
uint8_t UB[8]; uint8_t UB[8];
double D; double D;
float F[2]; float F[2];
}; };

View File

@ -1,14 +1,18 @@
#include "stdafx.h" #include "stdafx.h"
#include <stdio.h> #include <stdio.h>
#include <Project64-core/N64System/Profiling.h>
#include <Common/Log.h> #include <Common/Log.h>
#include <Project64-core/N64System/Profiling.h>
enum { MAX_FRAMES = 13 }; enum
{
MAX_FRAMES = 13
};
CProfiling::CProfiling() : CProfiling::CProfiling() :
m_CurrentDisplayCount(MAX_FRAMES), m_CurrentDisplayCount(MAX_FRAMES),
m_CurrentTimerType(Timer_None) m_CurrentTimerType(Timer_None)
{ {
memset(m_Timers, 0, sizeof(m_Timers)); memset(m_Timers, 0, sizeof(m_Timers));
} }
@ -42,7 +46,10 @@ PROFILE_TIMERS CProfiling::StartTimer(PROFILE_TIMERS TimerType)
PROFILE_TIMERS CProfiling::StopTimer() PROFILE_TIMERS CProfiling::StopTimer()
{ {
if (m_CurrentTimerType == Timer_None) { return m_CurrentTimerType; } if (m_CurrentTimerType == Timer_None)
{
return m_CurrentTimerType;
}
HighResTimeStamp EndTime; HighResTimeStamp EndTime;
EndTime.SetToNow(); EndTime.SetToNow();
uint64_t TimeTaken = EndTime.GetMicroSeconds() - m_StartTime.GetMicroSeconds(); uint64_t TimeTaken = EndTime.GetMicroSeconds() - m_StartTime.GetMicroSeconds();
@ -71,7 +78,8 @@ void CProfiling::ShowCPU_Usage()
m_CurrentDisplayCount = MAX_FRAMES; m_CurrentDisplayCount = MAX_FRAMES;
g_Notify->DisplayMessage(0, stdstr_f("r4300i: %d.%02d%% GFX: %d.%02d%% Alist: %d.%02d%% Idle: %d.%02d%%", g_Notify->DisplayMessage(0, stdstr_f("r4300i: %d.%02d%% GFX: %d.%02d%% Alist: %d.%02d%% Idle: %d.%02d%%",
R4300 / 100, R4300 % 100, RSP_Dlist / 100, RSP_Dlist % 100, RSP_Alist / 100, RSP_Alist % 100, Idel / 100, Idel % 100).c_str()); R4300 / 100, R4300 % 100, RSP_Dlist / 100, RSP_Dlist % 100, RSP_Alist / 100, RSP_Alist % 100, Idel / 100, Idel % 100)
.c_str());
ResetTimers(); ResetTimers();
if (PreviousType != Timer_None) if (PreviousType != Timer_None)

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Project64-core/N64System/N64Types.h>
#include <Common/HighResTimeStamp.h> #include <Common/HighResTimeStamp.h>
#include <Project64-core/N64System/N64Types.h>
class CProfiling class CProfiling
{ {
@ -20,8 +20,8 @@ public:
void ResetTimers(void); void ResetTimers(void);
private: private:
CProfiling(const CProfiling&); CProfiling(const CProfiling &);
CProfiling& operator=(const CProfiling&); CProfiling & operator=(const CProfiling &);
uint32_t m_CurrentDisplayCount; uint32_t m_CurrentDisplayCount;
PROFILE_TIMERS m_CurrentTimerType; PROFILE_TIMERS m_CurrentTimerType;

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#if defined(__aarch64__) #if defined(__aarch64__)
#include <Project64-core/N64System/Recompiler/RegInfo.h>
#include <Project64-core/N64System/Recompiler/ExitInfo.h>
#include <Project64-core/N64System/Recompiler/Aarch64/Aarch64ops.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h> #include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/Recompiler/Aarch64/Aarch64ops.h>
#include <Project64-core/N64System/Recompiler/ExitInfo.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/RegInfo.h>
class CMipsMemoryVM; class CMipsMemoryVM;
class CCodeBlock; class CCodeBlock;
@ -213,18 +213,21 @@ public:
const R4300iOpcode & GetOpcode(void) const; const R4300iOpcode & GetOpcode(void) const;
void PreCompileOpcode(void); void PreCompileOpcode(void);
void PostCompileOpcode(void); void PostCompileOpcode(void);
void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, ExitReason reason); void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason reason);
void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true); void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true);
void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet); void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet);
void CompileExecuteBP(void); void CompileExecuteBP(void);
void CompileExecuteDelaySlotBP(void); void CompileExecuteDelaySlotBP(void);
CAarch64Ops & Assembler() { return m_Assembler; } CAarch64Ops & Assembler()
{
return m_Assembler;
}
private: private:
CAarch64RecompilerOps(const CAarch64RecompilerOps&); CAarch64RecompilerOps(const CAarch64RecompilerOps &);
CAarch64RecompilerOps& operator=(const CAarch64RecompilerOps&); CAarch64RecompilerOps & operator=(const CAarch64RecompilerOps &);
CAarch64RegInfo m_RegWorkingSet; CAarch64RegInfo m_RegWorkingSet;
CAarch64Ops m_Assembler; CAarch64Ops m_Assembler;

View File

@ -7,7 +7,7 @@ CAarch64RegInfo::CAarch64RegInfo(CCodeBlock & /*CodeBlock*/, CAarch64Ops & /*Ass
{ {
} }
CAarch64RegInfo::CAarch64RegInfo(const CAarch64RegInfo&) CAarch64RegInfo::CAarch64RegInfo(const CAarch64RegInfo &)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
@ -16,7 +16,7 @@ CAarch64RegInfo::~CAarch64RegInfo()
{ {
} }
CAarch64RegInfo& CAarch64RegInfo::operator=(const CAarch64RegInfo & right) CAarch64RegInfo & CAarch64RegInfo::operator=(const CAarch64RegInfo & right)
{ {
CRegBase::operator=(right); CRegBase::operator=(right);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);

View File

@ -10,13 +10,13 @@ class CAarch64RegInfo :
{ {
public: public:
CAarch64RegInfo(CCodeBlock & CodeBlock, CAarch64Ops & Assembler); CAarch64RegInfo(CCodeBlock & CodeBlock, CAarch64Ops & Assembler);
CAarch64RegInfo(const CAarch64RegInfo&); CAarch64RegInfo(const CAarch64RegInfo &);
~CAarch64RegInfo(); ~CAarch64RegInfo();
CAarch64RegInfo& operator=(const CAarch64RegInfo&); CAarch64RegInfo & operator=(const CAarch64RegInfo &);
bool operator==(const CAarch64RegInfo& right) const; bool operator==(const CAarch64RegInfo & right) const;
bool operator!=(const CAarch64RegInfo& right) const; bool operator!=(const CAarch64RegInfo & right) const;
}; };
#endif #endif

View File

@ -10,8 +10,8 @@ public:
private: private:
CAarch64Ops(void); CAarch64Ops(void);
CAarch64Ops(const CAarch64Ops&); CAarch64Ops(const CAarch64Ops &);
CAarch64Ops& operator=(const CAarch64Ops&); CAarch64Ops & operator=(const CAarch64Ops &);
CCodeBlock & m_CodeBlock; CCodeBlock & m_CodeBlock;
}; };

View File

@ -1,12 +1,12 @@
#include "stdafx.h" #include "stdafx.h"
#if defined(__arm__) || defined(_M_ARM) #if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOpCode.h> #include <Project64-core/N64System/Recompiler/Arm/ArmOpCode.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRegInfo.h> #include <Project64-core/N64System/Recompiler/Arm/ArmRegInfo.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h> #include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/SystemGlobals.h>
CArmOps::CArmOps(CCodeBlock & CodeBlock, CArmRegInfo & RegWorkingSet) : CArmOps::CArmOps(CCodeBlock & CodeBlock, CArmRegInfo & RegWorkingSet) :
m_CodeBlock(CodeBlock), m_CodeBlock(CodeBlock),
@ -42,7 +42,7 @@ void CArmOps::AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
if (DestReg <= 7 && SourceReg1 <= 7 && SourceReg2 <= 7) if (DestReg <= 7 && SourceReg1 <= 7 && SourceReg2 <= 7)
{ {
CodeLog(" add\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" add\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg.rt = DestReg; op.Reg.rt = DestReg;
op.Reg.rn = SourceReg1; op.Reg.rn = SourceReg1;
op.Reg.rm = SourceReg2; op.Reg.rm = SourceReg2;
@ -52,7 +52,7 @@ void CArmOps::AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
else else
{ {
CodeLog(" add.w\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" add.w\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = SourceReg1; op.imm5.rn = SourceReg1;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x758; op.imm5.opcode = 0x758;
@ -82,7 +82,7 @@ void CArmOps::AndConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
{ {
CodeLog(" and\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const); CodeLog(" and\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
uint16_t CompressedConst = ThumbCompressConst(Const); uint16_t CompressedConst = ThumbCompressConst(Const);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = SourceReg; op.imm8_3_1.rn = SourceReg;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0; op.imm8_3_1.opcode = 0;
@ -104,7 +104,7 @@ void CArmOps::AndConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
} }
} }
void CArmOps::AndConstToVariable(void *Variable, const char * VariableName, uint32_t Const) void CArmOps::AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const)
{ {
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
@ -135,7 +135,7 @@ void CArmOps::AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
else if ((Const & 0xFFFFFFF8) == 0 && DestReg <= 7 && SourceReg <= 7) else if ((Const & 0xFFFFFFF8) == 0 && DestReg <= 7 && SourceReg <= 7)
{ {
CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const); CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm3.rd = DestReg; op.Imm3.rd = DestReg;
op.Imm3.rn = SourceReg; op.Imm3.rn = SourceReg;
op.Imm3.imm3 = Const; op.Imm3.imm3 = Const;
@ -145,7 +145,7 @@ void CArmOps::AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
else if ((Const & 0xFFFFFF00) == 0 && DestReg <= 7 && DestReg == SourceReg) else if ((Const & 0xFFFFFF00) == 0 && DestReg <= 7 && DestReg == SourceReg)
{ {
CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const); CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm8.imm8 = Const; op.Imm8.imm8 = Const;
op.Imm8.rdn = DestReg; op.Imm8.rdn = DestReg;
op.Imm8.opcode = 0x6; op.Imm8.opcode = 0x6;
@ -154,7 +154,7 @@ void CArmOps::AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
else if ((Const & 0xFFFFFF80) == 0xFFFFFF80 && DestReg <= 7 && DestReg == SourceReg) else if ((Const & 0xFFFFFF80) == 0xFFFFFF80 && DestReg <= 7 && DestReg == SourceReg)
{ {
CodeLog(" sub\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (~Const) + 1); CodeLog(" sub\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (~Const) + 1);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm8.imm8 = ((~Const) + 1) & 0xFF; op.Imm8.imm8 = ((~Const) + 1) & 0xFF;
op.Imm8.rdn = DestReg; op.Imm8.rdn = DestReg;
op.Imm8.opcode = 0x7; op.Imm8.opcode = 0x7;
@ -164,7 +164,7 @@ void CArmOps::AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
{ {
CodeLog(" add.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const); CodeLog(" add.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
uint16_t CompressedConst = ThumbCompressConst(Const); uint16_t CompressedConst = ThumbCompressConst(Const);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = SourceReg; op.imm8_3_1.rn = SourceReg;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x8; op.imm8_3_1.opcode = 0x8;
@ -198,7 +198,7 @@ void CArmOps::AndArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
if (DestReg <= 0x7 && SourceReg2 <= 0x7 && SourceReg1 == DestReg) if (DestReg <= 0x7 && SourceReg2 <= 0x7 && SourceReg1 == DestReg)
{ {
CodeLog(" ands\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg2)); CodeLog(" ands\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg2.rn = DestReg; op.Reg2.rn = DestReg;
op.Reg2.rm = SourceReg2; op.Reg2.rm = SourceReg2;
op.Reg2.opcode = 0x100; op.Reg2.opcode = 0x100;
@ -207,7 +207,7 @@ void CArmOps::AndArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
else else
{ {
CodeLog(" and.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" and.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = SourceReg1; op.imm5.rn = SourceReg1;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x750; op.imm5.opcode = 0x750;
@ -245,7 +245,7 @@ void CArmOps::BranchLabel8(ArmCompareType CompareType, const char * Label)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label); CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
if (CompareType == ArmBranch_Always) if (CompareType == ArmBranch_Always)
{ {
op.BranchImm.imm = 0; op.BranchImm.imm = 0;
@ -265,7 +265,7 @@ void CArmOps::BranchLabel20(ArmCompareType CompareType, const char * Label)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label); CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.Branch20.imm6 = 0; op.Branch20.imm6 = 0;
op.Branch20.cond = CompareType == ArmBranch_Always ? 0 : CompareType; op.Branch20.cond = CompareType == ArmBranch_Always ? 0 : CompareType;
op.Branch20.S = 0; op.Branch20.S = 0;
@ -285,7 +285,7 @@ void CArmOps::CallFunction(void * Function, const char * FunctionName)
ArmReg reg = Arm_R4; ArmReg reg = Arm_R4;
MoveConstToArmReg(reg, (uint32_t)Function, FunctionName); MoveConstToArmReg(reg, (uint32_t)Function, FunctionName);
int32_t Offset = (int32_t)Function - (int32_t)*g_RecompPos; int32_t Offset = (int32_t)Function - (int32_t)*g_RecompPos;
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Branch.reserved = 0; op.Branch.reserved = 0;
op.Branch.rm = reg; op.Branch.rm = reg;
op.Branch.opcode = 0x8F; op.Branch.opcode = 0x8F;
@ -323,7 +323,7 @@ void CArmOps::MoveConstToArmReg(ArmReg Reg, uint16_t value, const char * comment
if ((value & 0xFF00) == 0 && Reg <= 7) if ((value & 0xFF00) == 0 && Reg <= 7)
{ {
CodeLog(" mov%s\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "s", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str()); CodeLog(" mov%s\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "s", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str());
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm8.imm8 = value; op.Imm8.imm8 = value;
op.Imm8.rdn = Reg; op.Imm8.rdn = Reg;
op.Imm8.opcode = 0x4; op.Imm8.opcode = 0x4;
@ -333,7 +333,7 @@ void CArmOps::MoveConstToArmReg(ArmReg Reg, uint16_t value, const char * comment
{ {
CodeLog(" mov%s.w\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str()); CodeLog(" mov%s.w\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str());
uint16_t CompressedValue = ThumbCompressConst(value); uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = 0xF; op.imm8_3_1.rn = 0xF;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x2; op.imm8_3_1.opcode = 0x2;
@ -350,7 +350,7 @@ void CArmOps::MoveConstToArmReg(ArmReg Reg, uint16_t value, const char * comment
{ {
CodeLog(" movw%s\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str()); CodeLog(" movw%s\t%s, #0x%X\t; %s", m_InItBlock ? ArmCurrentItCondition() : "", ArmRegName(Reg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str());
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm16.opcode = ArmMOV_IMM16; op.imm16.opcode = ArmMOV_IMM16;
op.imm16.i = ((value >> 11) & 0x1); op.imm16.i = ((value >> 11) & 0x1);
op.imm16.opcode2 = ArmMOVW_IMM16; op.imm16.opcode2 = ArmMOVW_IMM16;
@ -374,7 +374,7 @@ void CArmOps::MoveConstToArmRegTop(ArmReg DestReg, uint16_t Const, const char *
CodeLog(" movt\t%s, %s", ArmRegName(DestReg), comment != nullptr ? stdstr_f("#0x%X\t; %s", (uint32_t)Const, comment).c_str() : stdstr_f("#%d\t; 0x%X", (uint32_t)Const, (uint32_t)Const).c_str()); CodeLog(" movt\t%s, %s", ArmRegName(DestReg), comment != nullptr ? stdstr_f("#0x%X\t; %s", (uint32_t)Const, comment).c_str() : stdstr_f("#%d\t; 0x%X", (uint32_t)Const, (uint32_t)Const).c_str());
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm16.opcode = ArmMOV_IMM16; op.imm16.opcode = ArmMOV_IMM16;
op.imm16.i = ((Const >> 11) & 0x1); op.imm16.i = ((Const >> 11) & 0x1);
op.imm16.opcode2 = ArmMOVT_IMM16; op.imm16.opcode2 = ArmMOVT_IMM16;
@ -397,7 +397,7 @@ void CArmOps::CompareArmRegToConst(ArmReg Reg, uint32_t value)
if (Reg <= 0x7 && (value & 0xFFFFFF00) == 0) if (Reg <= 0x7 && (value & 0xFFFFFF00) == 0)
{ {
CodeLog(" cmp\t%s, #%d\t; 0x%X", ArmRegName(Reg), value, value); CodeLog(" cmp\t%s, #%d\t; 0x%X", ArmRegName(Reg), value, value);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm8.imm8 = value; op.Imm8.imm8 = value;
op.Imm8.rdn = Reg; op.Imm8.rdn = Reg;
op.Imm8.opcode = 0x5; op.Imm8.opcode = 0x5;
@ -407,7 +407,7 @@ void CArmOps::CompareArmRegToConst(ArmReg Reg, uint32_t value)
{ {
CodeLog(" cmp\t%s, #%d\t; 0x%X", ArmRegName(Reg), value, value); CodeLog(" cmp\t%s, #%d\t; 0x%X", ArmRegName(Reg), value, value);
uint16_t CompressedValue = ThumbCompressConst(value); uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = Reg; op.imm8_3_1.rn = Reg;
op.imm8_3_1.s = 1; op.imm8_3_1.s = 1;
op.imm8_3_1.opcode = 0xD; op.imm8_3_1.opcode = 0xD;
@ -436,7 +436,7 @@ void CArmOps::CompareArmRegToArmReg(ArmReg Reg1, ArmReg Reg2)
if (Reg1 <= 0x7 && Reg2 <= 0x7) if (Reg1 <= 0x7 && Reg2 <= 0x7)
{ {
CodeLog(" cmp\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2)); CodeLog(" cmp\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg2.rn = Reg1; op.Reg2.rn = Reg1;
op.Reg2.rm = Reg2; op.Reg2.rm = Reg2;
op.Reg2.opcode = 0x10A; op.Reg2.opcode = 0x10A;
@ -445,7 +445,7 @@ void CArmOps::CompareArmRegToArmReg(ArmReg Reg1, ArmReg Reg2)
else else
{ {
CodeLog(" cmp.w\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2)); CodeLog(" cmp.w\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = Reg1; op.imm5.rn = Reg1;
op.imm5.s = 1; op.imm5.s = 1;
op.imm5.opcode = 0x75D; op.imm5.opcode = 0x75D;
@ -480,7 +480,7 @@ void CArmOps::IfBlock(ArmItMask mask, ArmCompareType CompareType)
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.It.mask = computed_mask; op.It.mask = computed_mask;
op.It.firstcond = CompareType; op.It.firstcond = CompareType;
op.It.opcode = 0xBF; op.It.opcode = 0xBF;
@ -500,7 +500,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, u
return; return;
} }
CodeLog(" ldrb.w\t%s, [%s, #%d]", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)offset); CodeLog(" ldrb.w\t%s, [%s, #%d]", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)offset);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm12.rt = DestReg; op.imm12.rt = DestReg;
op.imm12.rn = RegPointer; op.imm12.rn = RegPointer;
op.imm12.imm = offset; op.imm12.imm = offset;
@ -510,7 +510,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, u
else else
{ {
CodeLog(" ldrb\t%s, [%s%s%s]", ArmRegName(DestReg), ArmRegName(RegPointer), offset == 0 ? "" : ",", offset == 0 ? "" : stdstr_f("#%d", offset).c_str()); CodeLog(" ldrb\t%s, [%s%s%s]", ArmRegName(DestReg), ArmRegName(RegPointer), offset == 0 ? "" : ",", offset == 0 ? "" : stdstr_f("#%d", offset).c_str());
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = RegPointer; op.Imm5.rn = RegPointer;
op.Imm5.imm5 = offset; op.Imm5.imm5 = offset;
@ -526,7 +526,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, A
if ((DestReg > 0x7 || RegPointer > 0x7 || RegPointer2 > 0x7) && (shift & ~3) == 0) if ((DestReg > 0x7 || RegPointer > 0x7 || RegPointer2 > 0x7) && (shift & ~3) == 0)
{ {
CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2)); CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.uint16.rn = RegPointer; op.uint16.rn = RegPointer;
op.uint16.opcode = 0xF81; op.uint16.opcode = 0xF81;
op.uint16.rm = RegPointer2; op.uint16.rm = RegPointer2;
@ -538,7 +538,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, A
else if (shift == 0 && DestReg <= 0x7 && RegPointer <= 0x7 && RegPointer2 <= 0x7) else if (shift == 0 && DestReg <= 0x7 && RegPointer <= 0x7 && RegPointer2 <= 0x7)
{ {
CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2)); CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg.rm = RegPointer2; op.Reg.rm = RegPointer2;
op.Reg.rt = DestReg; op.Reg.rt = DestReg;
op.Reg.rn = RegPointer; op.Reg.rn = RegPointer;
@ -564,7 +564,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, uint8
return; return;
} }
CodeLog(" ldr.w\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : ""); CodeLog(" ldr.w\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : "");
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm12.rt = DestReg; op.imm12.rt = DestReg;
op.imm12.rn = RegPointer; op.imm12.rn = RegPointer;
op.imm12.imm = Offset; op.imm12.imm = Offset;
@ -574,7 +574,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, uint8
else else
{ {
CodeLog(" ldr\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : ""); CodeLog(" ldr\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : "");
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = RegPointer; op.Imm5.rn = RegPointer;
op.Imm5.imm5 = Offset >> 2; op.Imm5.imm5 = Offset >> 2;
@ -596,7 +596,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, ArmRe
if (shift == 0 && DestReg <= 0x7 && RegPointer <= 0x7 && RegPointer2 <= 0x7) if (shift == 0 && DestReg <= 0x7 && RegPointer <= 0x7 && RegPointer2 <= 0x7)
{ {
CodeLog(" ldr\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2)); CodeLog(" ldr\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg.rm = RegPointer2; op.Reg.rm = RegPointer2;
op.Reg.rt = DestReg; op.Reg.rt = DestReg;
op.Reg.rn = RegPointer; op.Reg.rn = RegPointer;
@ -606,7 +606,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, ArmRe
else else
{ {
CodeLog(" ldr.w\t%s, [%s, %s, lsl #%d]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2), shift); CodeLog(" ldr.w\t%s, [%s, %s, lsl #%d]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2), shift);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm2.rm = RegPointer2; op.imm2.rm = RegPointer2;
op.imm2.imm = shift; op.imm2.imm = shift;
op.imm2.Opcode2 = 0; op.imm2.Opcode2 = 0;
@ -629,7 +629,7 @@ void CArmOps::LoadArmRegPointerToFloatReg(ArmReg RegPointer, ArmFpuSingle Reg, u
{ {
CodeLog(" vldr\t%s, [%s]", ArmFpuSingleName(Reg), ArmRegName(RegPointer)); CodeLog(" vldr\t%s, [%s]", ArmFpuSingleName(Reg), ArmRegName(RegPointer));
} }
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.RnVdImm8.Rn = RegPointer; op.RnVdImm8.Rn = RegPointer;
op.RnVdImm8.op3 = 1; op.RnVdImm8.op3 = 1;
op.RnVdImm8.D = Reg & 1; op.RnVdImm8.D = Reg & 1;
@ -654,7 +654,7 @@ void CArmOps::LoadFloatingPointControlReg(ArmReg DestReg)
PreOpCheck(DestReg, false, __FILE__, __LINE__); PreOpCheck(DestReg, false, __FILE__, __LINE__);
CodeLog(" vmrs\t%s, fpscr", ArmRegName(DestReg)); CodeLog(" vmrs\t%s, fpscr", ArmRegName(DestReg));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.fpscr.opcode2 = 0xA10; op.fpscr.opcode2 = 0xA10;
op.fpscr.rt = DestReg; op.fpscr.rt = DestReg;
op.fpscr.opcode = 0xEEF1; op.fpscr.opcode = 0xEEF1;
@ -669,7 +669,7 @@ void CArmOps::MoveConstToArmReg(ArmReg DestReg, uint32_t value, const char * com
CodeLog(" mov.w\t%s, #0x%X\t; %s", ArmRegName(DestReg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str()); CodeLog(" mov.w\t%s, #0x%X\t; %s", ArmRegName(DestReg), (uint32_t)value, comment != nullptr ? comment : stdstr_f("0x%X", (uint32_t)value).c_str());
uint16_t CompressedValue = ThumbCompressConst(value); uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = 0xF; op.imm8_3_1.rn = 0xF;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x2; op.imm8_3_1.opcode = 0x2;
@ -740,7 +740,7 @@ void CArmOps::OrArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceR
return; return;
} }
CodeLog(" orr.w\t%s, %s, %s%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2), shift ? stdstr_f(", lsl #%d", shift).c_str() : ""); CodeLog(" orr.w\t%s, %s, %s%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2), shift ? stdstr_f(", lsl #%d", shift).c_str() : "");
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = SourceReg1; op.imm5.rn = SourceReg1;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x752; op.imm5.opcode = 0x752;
@ -768,7 +768,7 @@ void CArmOps::OrConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t value)
{ {
uint16_t CompressedValue = ThumbCompressConst(value); uint16_t CompressedValue = ThumbCompressConst(value);
CodeLog(" orr\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), value); CodeLog(" orr\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), value);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = SourceReg; op.imm8_3_1.rn = SourceReg;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x2; op.imm8_3_1.opcode = 0x2;
@ -816,7 +816,7 @@ void CArmOps::MulF32(ArmFpuSingle DestReg, ArmFpuSingle SourceReg1, ArmFpuSingle
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" vmul.f32\t%s, %s, %s", ArmFpuSingleName(DestReg), ArmFpuSingleName(SourceReg1), ArmFpuSingleName(SourceReg2)); CodeLog(" vmul.f32\t%s, %s, %s", ArmFpuSingleName(DestReg), ArmFpuSingleName(SourceReg1), ArmFpuSingleName(SourceReg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.VnVmVd.vn = SourceReg1 >> 1; op.VnVmVd.vn = SourceReg1 >> 1;
op.VnVmVd.op1 = 0x2; op.VnVmVd.op1 = 0x2;
op.VnVmVd.d = DestReg & 1; op.VnVmVd.d = DestReg & 1;
@ -857,8 +857,14 @@ void CArmOps::PushArmReg(uint16_t Registers)
{ {
return; return;
} }
if ((Registers & ArmPushPop_SP) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); } if ((Registers & ArmPushPop_SP) != 0)
if ((Registers & ArmPushPop_PC) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); } {
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_PC) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_LR) == 0) if ((Registers & ArmPushPop_LR) == 0)
{ {
m_PushRegisters = Registers; m_PushRegisters = Registers;
@ -879,7 +885,7 @@ void CArmOps::PushArmReg(uint16_t Registers)
{ {
CodeLog("%X: push\t{%s}", (int32_t)*g_RecompPos, pushed.c_str()); CodeLog("%X: push\t{%s}", (int32_t)*g_RecompPos, pushed.c_str());
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.PushPop.register_list = Registers; op.PushPop.register_list = Registers;
op.PushPop.opcode = 0xE92D; op.PushPop.opcode = 0xE92D;
AddCode32(op.Hex); AddCode32(op.Hex);
@ -890,7 +896,7 @@ void CArmOps::PushArmReg(uint16_t Registers)
bool lr = (Registers & ArmPushPop_LR) != 0; bool lr = (Registers & ArmPushPop_LR) != 0;
Registers &= Registers & ~ArmPushPop_LR; Registers &= Registers & ~ArmPushPop_LR;
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Push.register_list = (uint8_t)Registers; op.Push.register_list = (uint8_t)Registers;
op.Push.m = lr ? 1 : 0; op.Push.m = lr ? 1 : 0;
op.Push.opcode = ArmPUSH; op.Push.opcode = ArmPUSH;
@ -918,8 +924,14 @@ void CArmOps::PopArmReg(uint16_t Registers)
CodeLog("%s: Setting m_PushRegisters: %X Registers: %X", __FUNCTION__, m_PushRegisters, Registers); CodeLog("%s: Setting m_PushRegisters: %X Registers: %X", __FUNCTION__, m_PushRegisters, Registers);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
if ((Registers & ArmPushPop_SP) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); } if ((Registers & ArmPushPop_SP) != 0)
if ((Registers & ArmPushPop_LR) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); } {
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_LR) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
m_PopRegisters = Registers; m_PopRegisters = Registers;
@ -949,7 +961,7 @@ void CArmOps::FlushPopArmReg(void)
{ {
CodeLog("%X pop\t{%s}", (int32_t)*g_RecompPos, pushed.c_str()); CodeLog("%X pop\t{%s}", (int32_t)*g_RecompPos, pushed.c_str());
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.PushPop.register_list = m_PopRegisters; op.PushPop.register_list = m_PopRegisters;
op.PushPop.opcode = 0xE8BD; op.PushPop.opcode = 0xE8BD;
AddCode32(op.Hex); AddCode32(op.Hex);
@ -960,7 +972,7 @@ void CArmOps::FlushPopArmReg(void)
bool pc = (m_PopRegisters & ArmPushPop_PC) != 0; bool pc = (m_PopRegisters & ArmPushPop_PC) != 0;
m_PopRegisters &= ~ArmPushPop_PC; m_PopRegisters &= ~ArmPushPop_PC;
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Pop.register_list = (uint8_t)m_PopRegisters; op.Pop.register_list = (uint8_t)m_PopRegisters;
op.Pop.p = pc ? 1 : 0; op.Pop.p = pc ? 1 : 0;
op.Pop.opcode = ArmPOP; op.Pop.opcode = ArmPOP;
@ -973,11 +985,10 @@ void CArmOps::FlushPopArmReg(void)
uint32_t CArmOps::PushPopRegisterSize(uint16_t Registers) uint32_t CArmOps::PushPopRegisterSize(uint16_t Registers)
{ {
static uint32_t RegisterList[] = static uint32_t RegisterList[] =
{ {
ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, ArmPushPop_R3, ArmPushPop_R4, ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, ArmPushPop_R3, ArmPushPop_R4,
ArmPushPop_R5, ArmPushPop_R6, ArmPushPop_R7, ArmPushPop_R8, ArmPushPop_R9, ArmPushPop_R5, ArmPushPop_R6, ArmPushPop_R7, ArmPushPop_R8, ArmPushPop_R9,
ArmPushPop_R10, ArmPushPop_R11, ArmPushPop_R12, ArmPushPop_LR, ArmPushPop_PC ArmPushPop_R10, ArmPushPop_R11, ArmPushPop_R12, ArmPushPop_LR, ArmPushPop_PC};
};
uint32_t size = 0; uint32_t size = 0;
for (uint32_t i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++) for (uint32_t i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++)
{ {
@ -991,18 +1002,40 @@ uint32_t CArmOps::PushPopRegisterSize(uint16_t Registers)
std::string CArmOps::PushPopRegisterList(uint16_t Registers) std::string CArmOps::PushPopRegisterList(uint16_t Registers)
{ {
static uint32_t PushPopRegisterList[] = static uint32_t PushPopRegisterList[] = {
{ ArmPushPop_R0,
ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, ArmPushPop_R3, ArmPushPop_R4, ArmPushPop_R1,
ArmPushPop_R5, ArmPushPop_R6, ArmPushPop_R7, ArmPushPop_R8, ArmPushPop_R9, ArmPushPop_R2,
ArmPushPop_R10, ArmPushPop_R11, ArmPushPop_R12, ArmPushPop_LR, ArmPushPop_PC ArmPushPop_R3,
ArmPushPop_R4,
ArmPushPop_R5,
ArmPushPop_R6,
ArmPushPop_R7,
ArmPushPop_R8,
ArmPushPop_R9,
ArmPushPop_R10,
ArmPushPop_R11,
ArmPushPop_R12,
ArmPushPop_LR,
ArmPushPop_PC,
}; };
static ArmReg RegisterList[] = static ArmReg RegisterList[] = {
{ Arm_R0,
Arm_R0, Arm_R1, Arm_R2, Arm_R3, Arm_R4, Arm_R1,
Arm_R5, Arm_R6, Arm_R7, Arm_R8, Arm_R9, Arm_R2,
Arm_R10, Arm_R11, Arm_R12, ArmRegLR, ArmRegPC, Arm_R3,
Arm_R4,
Arm_R5,
Arm_R6,
Arm_R7,
Arm_R8,
Arm_R9,
Arm_R10,
Arm_R11,
Arm_R12,
ArmRegLR,
ArmRegPC,
}; };
std::string RegisterResult; std::string RegisterResult;
@ -1027,7 +1060,7 @@ void CArmOps::ShiftRightSignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t shi
else if (DestReg > 0x7 || SourceReg > 0x7) else if (DestReg > 0x7 || SourceReg > 0x7)
{ {
CodeLog(" asrs.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift); CodeLog(" asrs.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = 0xF; op.imm5.rn = 0xF;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x752; op.imm5.opcode = 0x752;
@ -1044,7 +1077,7 @@ void CArmOps::ShiftRightSignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t shi
{ {
CodeLog(" asrs\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift); CodeLog(" asrs\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg; op.Imm5.rn = SourceReg;
op.Imm5.imm5 = shift; op.Imm5.imm5 = shift;
@ -1064,7 +1097,7 @@ void CArmOps::ShiftRightUnsignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t s
if (DestReg > 0x7 || SourceReg > 0x7) if (DestReg > 0x7 || SourceReg > 0x7)
{ {
CodeLog(" lsrs.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift); CodeLog(" lsrs.w\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = 0xF; op.imm5.rn = 0xF;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x752; op.imm5.opcode = 0x752;
@ -1081,7 +1114,7 @@ void CArmOps::ShiftRightUnsignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t s
{ {
CodeLog(" lsrs\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift); CodeLog(" lsrs\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg; op.Imm5.rn = SourceReg;
op.Imm5.imm5 = shift; op.Imm5.imm5 = shift;
@ -1101,7 +1134,7 @@ void CArmOps::ShiftLeftImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t shift)
} }
CodeLog(" lsls\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift); CodeLog(" lsls\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), (uint32_t)shift);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg; op.Imm5.rn = SourceReg;
op.Imm5.imm5 = shift; op.Imm5.imm5 = shift;
@ -1114,7 +1147,7 @@ void CArmOps::SignExtendByte(ArmReg Reg)
if (Reg > 0x7) if (Reg > 0x7)
{ {
CodeLog(" sxtb.w\t%s, %s", ArmRegName(Reg), ArmRegName(Reg)); CodeLog(" sxtb.w\t%s, %s", ArmRegName(Reg), ArmRegName(Reg));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.rotate.opcode = 0xFA4F; op.rotate.opcode = 0xFA4F;
op.rotate.rm = Reg; op.rotate.rm = Reg;
op.rotate.rotate = 0; op.rotate.rotate = 0;
@ -1126,7 +1159,7 @@ void CArmOps::SignExtendByte(ArmReg Reg)
else else
{ {
CodeLog(" sxtb\t%s, %s", ArmRegName(Reg), ArmRegName(Reg)); CodeLog(" sxtb\t%s, %s", ArmRegName(Reg), ArmRegName(Reg));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg2.rn = Reg; op.Reg2.rn = Reg;
op.Reg2.rm = Reg; op.Reg2.rm = Reg;
op.Reg2.opcode = 0x2C9; op.Reg2.opcode = 0x2C9;
@ -1140,10 +1173,14 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, uint
if (DestReg > 0x7 || RegPointer > 0x7 || (Offset & (~0x7C)) != 0) if (DestReg > 0x7 || RegPointer > 0x7 || (Offset & (~0x7C)) != 0)
{ {
if ((Offset & (~0xFFF)) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); return; } if ((Offset & (~0xFFF)) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
return;
}
CodeLog(" str\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : ""); CodeLog(" str\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : "");
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm12.rt = DestReg; op.imm12.rt = DestReg;
op.imm12.rn = RegPointer; op.imm12.rn = RegPointer;
op.imm12.imm = Offset; op.imm12.imm = Offset;
@ -1153,7 +1190,7 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, uint
else else
{ {
CodeLog(" str\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : ""); CodeLog(" str\t%s, [%s, #%d]%s%s", ArmRegName(DestReg), ArmRegName(RegPointer), (uint32_t)Offset, comment != nullptr ? "\t; " : "", comment != nullptr ? comment : "");
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg; op.Imm5.rt = DestReg;
op.Imm5.rn = RegPointer; op.Imm5.rn = RegPointer;
op.Imm5.imm5 = Offset >> 2; op.Imm5.imm5 = Offset >> 2;
@ -1170,7 +1207,7 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, ArmR
if (DestReg > 0x7 || RegPointer > 0x7 || RegPointer2 > 0x7 || shift != 0) if (DestReg > 0x7 || RegPointer > 0x7 || RegPointer2 > 0x7 || shift != 0)
{ {
CodeLog(" str.w\t%s, [%s, %s%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2), shift != 0 ? stdstr_f(", lsl #%d", shift).c_str() : ""); CodeLog(" str.w\t%s, [%s, %s%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2), shift != 0 ? stdstr_f(", lsl #%d", shift).c_str() : "");
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm2.rm = RegPointer2; op.imm2.rm = RegPointer2;
op.imm2.imm = shift; op.imm2.imm = shift;
op.imm2.Opcode2 = 0; op.imm2.Opcode2 = 0;
@ -1182,7 +1219,7 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, ArmR
else else
{ {
CodeLog(" str\t%s, [%s, %s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2)); CodeLog(" str\t%s, [%s, %s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg.rt = DestReg; op.Reg.rt = DestReg;
op.Reg.rn = RegPointer; op.Reg.rn = RegPointer;
op.Reg.rm = RegPointer2; op.Reg.rm = RegPointer2;
@ -1196,7 +1233,7 @@ void CArmOps::StoreFloatingPointControlReg(ArmReg SourceReg)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__); PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" vmsr\tfpscr, %s", ArmRegName(SourceReg)); CodeLog(" vmsr\tfpscr, %s", ArmRegName(SourceReg));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.fpscr.opcode2 = 0xA10; op.fpscr.opcode2 = 0xA10;
op.fpscr.rt = SourceReg; op.fpscr.rt = SourceReg;
op.fpscr.opcode = 0xEEE1; op.fpscr.opcode = 0xEEE1;
@ -1215,7 +1252,7 @@ void CArmOps::StoreFloatRegToArmRegPointer(ArmFpuSingle Reg, ArmReg RegPointer,
{ {
CodeLog(" vstr\t%s, [%s]", ArmFpuSingleName(Reg), ArmRegName(RegPointer)); CodeLog(" vstr\t%s, [%s]", ArmFpuSingleName(Reg), ArmRegName(RegPointer));
} }
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.RnVdImm8.Rn = RegPointer; op.RnVdImm8.Rn = RegPointer;
op.RnVdImm8.op3 = 0; op.RnVdImm8.op3 = 0;
op.RnVdImm8.D = Reg & 1; op.RnVdImm8.D = Reg & 1;
@ -1235,7 +1272,7 @@ void CArmOps::SubArmRegFromArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Sour
if (DestReg <= 7 && SourceReg1 <= 7 && SourceReg2 <= 7) if (DestReg <= 7 && SourceReg1 <= 7 && SourceReg2 <= 7)
{ {
CodeLog(" subs\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" subs\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg.rt = DestReg; op.Reg.rt = DestReg;
op.Reg.rn = SourceReg1; op.Reg.rn = SourceReg1;
op.Reg.rm = SourceReg2; op.Reg.rm = SourceReg2;
@ -1245,7 +1282,7 @@ void CArmOps::SubArmRegFromArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Sour
else else
{ {
CodeLog(" sub.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" sub.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = SourceReg1; op.imm5.rn = SourceReg1;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x75D; op.imm5.opcode = 0x75D;
@ -1267,7 +1304,7 @@ void CArmOps::SubConstFromArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Cons
if (DestReg <= 7 && DestReg == SourceReg && (Const & (~0xFF)) == 0) if (DestReg <= 7 && DestReg == SourceReg && (Const & (~0xFF)) == 0)
{ {
CodeLog(" subs\t%s, #0x%X", ArmRegName(DestReg), Const); CodeLog(" subs\t%s, #0x%X", ArmRegName(DestReg), Const);
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Imm8.imm8 = (uint8_t)Const; op.Imm8.imm8 = (uint8_t)Const;
op.Imm8.rdn = DestReg; op.Imm8.rdn = DestReg;
op.Imm8.opcode = 0x7; op.Imm8.opcode = 0x7;
@ -1276,7 +1313,7 @@ void CArmOps::SubConstFromArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Cons
else if ((Const & (~0x7FF)) == 0) else if ((Const & (~0x7FF)) == 0)
{ {
CodeLog(" sub.w\t%s, %s, #0x%X", ArmRegName(DestReg), ArmRegName(SourceReg), Const); CodeLog(" sub.w\t%s, %s, #0x%X", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.RnRdImm12.Rn = SourceReg; op.RnRdImm12.Rn = SourceReg;
op.RnRdImm12.s = 0; op.RnRdImm12.s = 0;
op.RnRdImm12.opcode = 0x15; op.RnRdImm12.opcode = 0x15;
@ -1340,7 +1377,7 @@ void CArmOps::XorArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg)
if (SourceReg <= 7 && DestReg <= 7) if (SourceReg <= 7 && DestReg <= 7)
{ {
CodeLog(" eors\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg)); CodeLog(" eors\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg));
ArmThumbOpcode op = { 0 }; ArmThumbOpcode op = {0};
op.Reg2.rn = DestReg; op.Reg2.rn = DestReg;
op.Reg2.rm = SourceReg; op.Reg2.rm = SourceReg;
op.Reg2.opcode = 0x101; op.Reg2.opcode = 0x101;
@ -1357,7 +1394,7 @@ void CArmOps::XorArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
PreOpCheck(DestReg, false, __FILE__, __LINE__); PreOpCheck(DestReg, false, __FILE__, __LINE__);
CodeLog(" eor.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2)); CodeLog(" eor.w\t%s, %s, %s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm5.rn = SourceReg1; op.imm5.rn = SourceReg1;
op.imm5.s = 0; op.imm5.s = 0;
op.imm5.opcode = 0x754; op.imm5.opcode = 0x754;
@ -1383,7 +1420,7 @@ void CArmOps::XorConstToArmReg(ArmReg DestReg, uint32_t value)
{ {
uint16_t CompressedValue = ThumbCompressConst(value); uint16_t CompressedValue = ThumbCompressConst(value);
CodeLog(" eor\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(DestReg), value); CodeLog(" eor\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(DestReg), value);
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.imm8_3_1.rn = DestReg; op.imm8_3_1.rn = DestReg;
op.imm8_3_1.s = 0; op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x4; op.imm8_3_1.opcode = 0x4;
@ -1534,7 +1571,7 @@ void CArmOps::SetJump20(uint32_t * Loc, uint32_t * JumpLoc)
CodeLog("%s: target %X pc %X immediate: %X", __FUNCTION__, target, pc, immediate); CodeLog("%s: target %X pc %X immediate: %X", __FUNCTION__, target, pc, immediate);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
Arm32Opcode op = { 0 }; Arm32Opcode op = {0};
op.Hex = *Loc; op.Hex = *Loc;
if (op.Branch20.val12 == 0) if (op.Branch20.val12 == 0)
{ {
@ -1615,12 +1652,30 @@ bool CArmOps::ArmCompareInverse(ArmCompareType CompareType)
CArmOps::ArmCompareType CArmOps::ArmCompareInverseType(ArmCompareType CompareType) CArmOps::ArmCompareType CArmOps::ArmCompareInverseType(ArmCompareType CompareType)
{ {
if (CompareType == ArmBranch_Equal) { return ArmBranch_Notequal; } if (CompareType == ArmBranch_Equal)
if (CompareType == ArmBranch_Notequal) { return ArmBranch_Equal; } {
if (CompareType == ArmBranch_GreaterThanOrEqual) { return ArmBranch_LessThan; } return ArmBranch_Notequal;
if (CompareType == ArmBranch_LessThan) { return ArmBranch_GreaterThanOrEqual; } }
if (CompareType == ArmBranch_GreaterThan) { return ArmBranch_LessThanOrEqual; } if (CompareType == ArmBranch_Notequal)
if (CompareType == ArmBranch_LessThanOrEqual) { return ArmBranch_GreaterThan; } {
return ArmBranch_Equal;
}
if (CompareType == ArmBranch_GreaterThanOrEqual)
{
return ArmBranch_LessThan;
}
if (CompareType == ArmBranch_LessThan)
{
return ArmBranch_GreaterThanOrEqual;
}
if (CompareType == ArmBranch_GreaterThan)
{
return ArmBranch_LessThanOrEqual;
}
if (CompareType == ArmBranch_LessThanOrEqual)
{
return ArmBranch_GreaterThan;
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return ArmBranch_Equal; return ArmBranch_Equal;
} }

View File

@ -158,7 +158,7 @@ public:
void AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceReg2); void AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceReg2);
void AddConstToArmReg(ArmReg DestReg, uint32_t Const); void AddConstToArmReg(ArmReg DestReg, uint32_t Const);
void AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const); void AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const);
void AndConstToVariable(void *Variable, const char * VariableName, uint32_t Const); void AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const);
void AndConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const); void AndConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const);
void AndArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceReg2); void AndArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceReg2);
void ArmBreakPoint(const char * FileName, uint32_t LineNumber); void ArmBreakPoint(const char * FileName, uint32_t LineNumber);
@ -218,8 +218,8 @@ public:
private: private:
CArmOps(void); CArmOps(void);
CArmOps(const CArmOps&); CArmOps(const CArmOps &);
CArmOps& operator=(const CArmOps&); CArmOps & operator=(const CArmOps &);
void CodeLog(_Printf_format_string_ const char * Text, ...); void CodeLog(_Printf_format_string_ const char * Text, ...);
@ -252,6 +252,6 @@ private:
uint16_t m_PushRegisters; uint16_t m_PushRegisters;
}; };
#define AddressOf(Addr) CArmOps::GetAddressOf(5,(Addr)) #define AddressOf(Addr) CArmOps::GetAddressOf(5, (Addr))
#endif #endif

View File

@ -1,17 +1,17 @@
#pragma once #pragma once
#if defined(__arm__) || defined(_M_ARM) #if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/Recompiler/ExitInfo.h>
#include <Project64-core/N64System/Recompiler/RegInfo.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/JumpInfo.h>
#include <Project64-core/N64System/Interpreter/InterpreterOps.h> #include <Project64-core/N64System/Interpreter/InterpreterOps.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/ExitInfo.h>
#include <Project64-core/N64System/Recompiler/JumpInfo.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/RegInfo.h>
#include <Project64-core/Settings/GameSettings.h>
#include <Project64-core/Settings/N64SystemSettings.h> #include <Project64-core/Settings/N64SystemSettings.h>
#include <Project64-core/Settings/RecompilerSettings.h> #include <Project64-core/Settings/RecompilerSettings.h>
#include <Project64-core/Settings/GameSettings.h>
class CCodeBlock; class CCodeBlock;
class CCodeSection; class CCodeSection;
@ -224,8 +224,8 @@ public:
const R4300iOpcode & GetOpcode(void) const; const R4300iOpcode & GetOpcode(void) const;
void PreCompileOpcode(void); void PreCompileOpcode(void);
void PostCompileOpcode(void); void PostCompileOpcode(void);
void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, ExitReason Reason); void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason Reason);
void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, ExitReason reason, CArmOps::ArmCompareType CompareType); void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason reason, CArmOps::ArmCompareType CompareType);
void CompileReadTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg); void CompileReadTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg);
void CompileWriteTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg); void CompileWriteTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg);
@ -235,43 +235,133 @@ public:
void CompileExecuteBP(void); void CompileExecuteBP(void);
void CompileExecuteDelaySlotBP(void); void CompileExecuteDelaySlotBP(void);
CArmOps & Assembler() { return m_Assembler; } CArmOps & Assembler()
{
return m_Assembler;
}
// Helper functions // Helper functions
typedef CRegInfo::REG_STATE REG_STATE; typedef CRegInfo::REG_STATE REG_STATE;
REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); } REG_STATE GetMipsRegState(int32_t Reg)
uint64_t GetMipsReg(int32_t Reg) { return m_RegWorkingSet.GetMipsReg(Reg); } {
uint32_t GetMipsRegLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo(Reg); } return m_RegWorkingSet.GetMipsRegState(Reg);
int32_t GetMipsRegLo_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo_S(Reg); } }
uint32_t GetMipsRegHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi(Reg); } uint64_t GetMipsReg(int32_t Reg)
int32_t GetMipsRegHi_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi_S(Reg); } {
CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapLo(Reg); } return m_RegWorkingSet.GetMipsReg(Reg);
CArmOps::ArmReg GetMipsRegMapHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapHi(Reg); } }
uint32_t GetMipsRegLo(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegLo(Reg);
}
int32_t GetMipsRegLo_S(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegLo_S(Reg);
}
uint32_t GetMipsRegHi(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegHi(Reg);
}
int32_t GetMipsRegHi_S(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegHi_S(Reg);
}
CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegMapLo(Reg);
}
CArmOps::ArmReg GetMipsRegMapHi(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegMapHi(Reg);
}
bool IsKnown(int32_t Reg) { return m_RegWorkingSet.IsKnown(Reg); } bool IsKnown(int32_t Reg)
bool IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); } {
bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); } return m_RegWorkingSet.IsKnown(Reg);
bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(Reg); } }
bool IsSigned(int32_t Reg) { return m_RegWorkingSet.IsSigned(Reg); } bool IsUnknown(int32_t Reg)
bool IsUnsigned(int32_t Reg) { return m_RegWorkingSet.IsUnsigned(Reg); } {
bool Is32Bit(int32_t Reg) { return m_RegWorkingSet.Is32Bit(Reg); } return m_RegWorkingSet.IsUnknown(Reg);
bool Is64Bit(int32_t Reg) { return m_RegWorkingSet.Is64Bit(Reg); } }
bool Is32BitMapped(int32_t Reg) { return m_RegWorkingSet.Is32BitMapped(Reg); } bool IsMapped(int32_t Reg)
bool Is64BitMapped(int32_t Reg) { return m_RegWorkingSet.Is64BitMapped(Reg); } {
void Map_GPR_32bit(int32_t Reg, bool SignValue, int32_t MipsRegToLoad) { m_RegWorkingSet.Map_GPR_32bit(Reg, SignValue, MipsRegToLoad); } return m_RegWorkingSet.IsMapped(Reg);
void Map_GPR_64bit(int32_t Reg, int32_t MipsRegToLoad) { m_RegWorkingSet.Map_GPR_64bit(Reg, MipsRegToLoad); } }
void UnMap_GPR(uint32_t Reg, bool WriteBackValue){ m_RegWorkingSet.UnMap_GPR(Reg, WriteBackValue); } bool IsConst(int32_t Reg)
void WriteBack_GPR(uint32_t Reg, bool Unmapping){ m_RegWorkingSet.WriteBack_GPR(Reg, Unmapping); } {
CArmOps::ArmReg Map_TempReg(CArmOps::ArmReg Reg, int32_t MipsReg, bool LoadHiWord) { return m_RegWorkingSet.Map_TempReg(Reg, MipsReg, LoadHiWord); } return m_RegWorkingSet.IsConst(Reg);
CArmOps::ArmReg Map_Variable(CArmRegInfo::VARIABLE_MAPPED variable, CArmOps::ArmReg Reg = CArmOps::Arm_Any) { return m_RegWorkingSet.Map_Variable(variable, Reg); } }
bool IsSigned(int32_t Reg)
{
return m_RegWorkingSet.IsSigned(Reg);
}
bool IsUnsigned(int32_t Reg)
{
return m_RegWorkingSet.IsUnsigned(Reg);
}
bool Is32Bit(int32_t Reg)
{
return m_RegWorkingSet.Is32Bit(Reg);
}
bool Is64Bit(int32_t Reg)
{
return m_RegWorkingSet.Is64Bit(Reg);
}
bool Is32BitMapped(int32_t Reg)
{
return m_RegWorkingSet.Is32BitMapped(Reg);
}
bool Is64BitMapped(int32_t Reg)
{
return m_RegWorkingSet.Is64BitMapped(Reg);
}
void Map_GPR_32bit(int32_t Reg, bool SignValue, int32_t MipsRegToLoad)
{
m_RegWorkingSet.Map_GPR_32bit(Reg, SignValue, MipsRegToLoad);
}
void Map_GPR_64bit(int32_t Reg, int32_t MipsRegToLoad)
{
m_RegWorkingSet.Map_GPR_64bit(Reg, MipsRegToLoad);
}
void UnMap_GPR(uint32_t Reg, bool WriteBackValue)
{
m_RegWorkingSet.UnMap_GPR(Reg, WriteBackValue);
}
void WriteBack_GPR(uint32_t Reg, bool Unmapping)
{
m_RegWorkingSet.WriteBack_GPR(Reg, Unmapping);
}
CArmOps::ArmReg Map_TempReg(CArmOps::ArmReg Reg, int32_t MipsReg, bool LoadHiWord)
{
return m_RegWorkingSet.Map_TempReg(Reg, MipsReg, LoadHiWord);
}
CArmOps::ArmReg Map_Variable(CArmRegInfo::VARIABLE_MAPPED variable, CArmOps::ArmReg Reg = CArmOps::Arm_Any)
{
return m_RegWorkingSet.Map_Variable(variable, Reg);
}
void ResetRegProtection() { m_RegWorkingSet.ResetRegProtection(); } void ResetRegProtection()
void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod) { m_RegWorkingSet.FixRoundModel(RoundMethod); } {
m_RegWorkingSet.ResetRegProtection();
}
void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod)
{
m_RegWorkingSet.FixRoundModel(RoundMethod);
}
void ProtectGPR(uint32_t Reg) { m_RegWorkingSet.ProtectGPR(Reg); } void ProtectGPR(uint32_t Reg)
void UnProtectGPR(uint32_t Reg) { m_RegWorkingSet.UnProtectGPR(Reg); } {
bool UnMap_ArmReg(CArmOps::ArmReg Reg) { return m_RegWorkingSet.UnMap_ArmReg(Reg); } m_RegWorkingSet.ProtectGPR(Reg);
}
void UnProtectGPR(uint32_t Reg)
{
m_RegWorkingSet.UnProtectGPR(Reg);
}
bool UnMap_ArmReg(CArmOps::ArmReg Reg)
{
return m_RegWorkingSet.UnMap_ArmReg(Reg);
}
void SW(bool bCheckLLbit); void SW(bool bCheckLLbit);
void SW_Const(uint32_t Value, uint32_t VAddr); void SW_Const(uint32_t Value, uint32_t VAddr);
@ -279,7 +369,7 @@ public:
void LW(bool ResultSigned, bool bRecordLLBit); void LW(bool ResultSigned, bool bRecordLLBit);
void LB_KnownAddress(CArmOps::ArmReg Reg, uint32_t VAddr, bool SignExtend); void LB_KnownAddress(CArmOps::ArmReg Reg, uint32_t VAddr, bool SignExtend);
void LW_KnownAddress(CArmOps::ArmReg Reg, uint32_t VAddr); void LW_KnownAddress(CArmOps::ArmReg Reg, uint32_t VAddr);
void CompileInterpterCall (void * Function, const char * FunctionName); void CompileInterpterCall(void * Function, const char * FunctionName);
void OverflowDelaySlot(bool TestTimer); void OverflowDelaySlot(bool TestTimer);
EXIT_LIST m_ExitInfo; EXIT_LIST m_ExitInfo;

View File

@ -1,10 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#if defined(__arm__) || defined(_M_ARM) #if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRegInfo.h> #include <Project64-core/N64System/Recompiler/Arm/ArmRegInfo.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/SystemGlobals.h>
CArmRegInfo::CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler) : CArmRegInfo::CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler) :
m_CodeBlock(CodeBlock), m_CodeBlock(CodeBlock),
@ -26,7 +26,7 @@ CArmRegInfo::CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler) :
} }
} }
CArmRegInfo::CArmRegInfo(const CArmRegInfo& rhs) : CArmRegInfo::CArmRegInfo(const CArmRegInfo & rhs) :
m_CodeBlock(rhs.m_CodeBlock), m_CodeBlock(rhs.m_CodeBlock),
m_Assembler(rhs.m_CodeBlock.RecompilerOps()->Assembler()) m_Assembler(rhs.m_CodeBlock.RecompilerOps()->Assembler())
{ {
@ -37,7 +37,7 @@ CArmRegInfo::~CArmRegInfo()
{ {
} }
CArmRegInfo& CArmRegInfo::operator=(const CArmRegInfo& right) CArmRegInfo & CArmRegInfo::operator=(const CArmRegInfo & right)
{ {
CRegBase::operator=(right); CRegBase::operator=(right);
@ -57,7 +57,7 @@ CArmRegInfo& CArmRegInfo::operator=(const CArmRegInfo& right)
return *this; return *this;
} }
bool CArmRegInfo::operator==(const CArmRegInfo& right) const bool CArmRegInfo::operator==(const CArmRegInfo & right) const
{ {
if (!CRegBase::operator==(right)) if (!CRegBase::operator==(right))
{ {
@ -66,16 +66,34 @@ bool CArmRegInfo::operator==(const CArmRegInfo& right) const
for (int32_t count = 0; count < 32; count++) for (int32_t count = 0; count < 32; count++)
{ {
if (m_RegMapHi[count] != right.m_RegMapHi[count]) { return false; } if (m_RegMapHi[count] != right.m_RegMapHi[count])
if (m_RegMapLo[count] != right.m_RegMapLo[count]) { return false; } {
return false;
}
if (m_RegMapLo[count] != right.m_RegMapLo[count])
{
return false;
}
} }
for (int32_t count = 0; count < 16; count++) for (int32_t count = 0; count < 16; count++)
{ {
if (m_ArmReg_MapOrder[count] != right.m_ArmReg_MapOrder[count]) { return false; } if (m_ArmReg_MapOrder[count] != right.m_ArmReg_MapOrder[count])
if (m_ArmReg_Protected[count] != right.m_ArmReg_Protected[count]) { return false; } {
if (m_ArmReg_MappedTo[count] != right.m_ArmReg_MappedTo[count]) { return false; } return false;
if (m_Variable_MappedTo[count] != right.m_Variable_MappedTo[count]) { return false; } }
if (m_ArmReg_Protected[count] != right.m_ArmReg_Protected[count])
{
return false;
}
if (m_ArmReg_MappedTo[count] != right.m_ArmReg_MappedTo[count])
{
return false;
}
if (m_Variable_MappedTo[count] != right.m_Variable_MappedTo[count])
{
return false;
}
} }
return true; return true;
} }
@ -95,18 +113,36 @@ bool CArmRegInfo::ShouldPushPopReg(CArmOps::ArmReg Reg)
void CArmRegInfo::BeforeCallDirect(void) void CArmRegInfo::BeforeCallDirect(void)
{ {
static uint32_t PushPopRegisterList[] = static uint32_t PushPopRegisterList[] = {
{ CArmOps::ArmPushPop_R0,
CArmOps::ArmPushPop_R0, CArmOps::ArmPushPop_R1, CArmOps::ArmPushPop_R2, CArmOps::ArmPushPop_R3, CArmOps::ArmPushPop_R4, CArmOps::ArmPushPop_R1,
CArmOps::ArmPushPop_R5, CArmOps::ArmPushPop_R6, CArmOps::ArmPushPop_R7, CArmOps::ArmPushPop_R8, CArmOps::ArmPushPop_R9, CArmOps::ArmPushPop_R2,
CArmOps::ArmPushPop_R10, CArmOps::ArmPushPop_R11, CArmOps::ArmPushPop_R12 CArmOps::ArmPushPop_R3,
CArmOps::ArmPushPop_R4,
CArmOps::ArmPushPop_R5,
CArmOps::ArmPushPop_R6,
CArmOps::ArmPushPop_R7,
CArmOps::ArmPushPop_R8,
CArmOps::ArmPushPop_R9,
CArmOps::ArmPushPop_R10,
CArmOps::ArmPushPop_R11,
CArmOps::ArmPushPop_R12,
}; };
static CArmOps::ArmReg RegisterList[] = static CArmOps::ArmReg RegisterList[] = {
{ CArmOps::Arm_R0,
CArmOps::Arm_R0, CArmOps::Arm_R1, CArmOps::Arm_R2, CArmOps::Arm_R3, CArmOps::Arm_R4, CArmOps::Arm_R1,
CArmOps::Arm_R5, CArmOps::Arm_R6, CArmOps::Arm_R7, CArmOps::Arm_R8, CArmOps::Arm_R9, CArmOps::Arm_R2,
CArmOps::Arm_R10, CArmOps::Arm_R11, CArmOps::Arm_R12 CArmOps::Arm_R3,
CArmOps::Arm_R4,
CArmOps::Arm_R5,
CArmOps::Arm_R6,
CArmOps::Arm_R7,
CArmOps::Arm_R8,
CArmOps::Arm_R9,
CArmOps::Arm_R10,
CArmOps::Arm_R11,
CArmOps::Arm_R12,
}; };
if (m_InCallDirect) if (m_InCallDirect)
@ -119,7 +155,10 @@ void CArmRegInfo::BeforeCallDirect(void)
int PushPopRegisters = 0; int PushPopRegisters = 0;
for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++) for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++)
{ {
if (ShouldPushPopReg(RegisterList[i])) { PushPopRegisters |= PushPopRegisterList[i]; } if (ShouldPushPopReg(RegisterList[i]))
{
PushPopRegisters |= PushPopRegisterList[i];
}
} }
if (PushPopRegisters == 0) if (PushPopRegisters == 0)
@ -148,7 +187,10 @@ void CArmRegInfo::BeforeCallDirect(void)
PushPopRegisters = 0; PushPopRegisters = 0;
for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++) for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++)
{ {
if (ShouldPushPopReg(RegisterList[i])) { PushPopRegisters |= PushPopRegisterList[i]; } if (ShouldPushPopReg(RegisterList[i]))
{
PushPopRegisters |= PushPopRegisterList[i];
}
} }
} }
if ((m_Assembler.PushPopRegisterSize(PushPopRegisters) % 8) != 0) if ((m_Assembler.PushPopRegisterSize(PushPopRegisters) % 8) != 0)
@ -162,18 +204,40 @@ void CArmRegInfo::BeforeCallDirect(void)
void CArmRegInfo::AfterCallDirect(void) void CArmRegInfo::AfterCallDirect(void)
{ {
static uint32_t PushPopRegisterList[] = static uint32_t PushPopRegisterList[] = {
{ CArmOps::ArmPushPop_R0,
CArmOps::ArmPushPop_R0, CArmOps::ArmPushPop_R1, CArmOps::ArmPushPop_R2, CArmOps::ArmPushPop_R3, CArmOps::ArmPushPop_R4, CArmOps::ArmPushPop_R1,
CArmOps::ArmPushPop_R5, CArmOps::ArmPushPop_R6, CArmOps::ArmPushPop_R7, CArmOps::ArmPushPop_R8, CArmOps::ArmPushPop_R9, CArmOps::ArmPushPop_R2,
CArmOps::ArmPushPop_R10, CArmOps::ArmPushPop_R11, CArmOps::ArmPushPop_R12, CArmOps::ArmPushPop_LR, CArmOps::ArmPushPop_PC CArmOps::ArmPushPop_R3,
CArmOps::ArmPushPop_R4,
CArmOps::ArmPushPop_R5,
CArmOps::ArmPushPop_R6,
CArmOps::ArmPushPop_R7,
CArmOps::ArmPushPop_R8,
CArmOps::ArmPushPop_R9,
CArmOps::ArmPushPop_R10,
CArmOps::ArmPushPop_R11,
CArmOps::ArmPushPop_R12,
CArmOps::ArmPushPop_LR,
CArmOps::ArmPushPop_PC,
}; };
static CArmOps::ArmReg RegisterList[] = static CArmOps::ArmReg RegisterList[] = {
{ CArmOps::Arm_R0,
CArmOps::Arm_R0, CArmOps::Arm_R1, CArmOps::Arm_R2, CArmOps::Arm_R3, CArmOps::Arm_R4, CArmOps::Arm_R1,
CArmOps::Arm_R5, CArmOps::Arm_R6, CArmOps::Arm_R7, CArmOps::Arm_R8, CArmOps::Arm_R9, CArmOps::Arm_R2,
CArmOps::Arm_R10, CArmOps::Arm_R11, CArmOps::Arm_R12, CArmOps::ArmRegLR, CArmOps::ArmRegPC, CArmOps::Arm_R3,
CArmOps::Arm_R4,
CArmOps::Arm_R5,
CArmOps::Arm_R6,
CArmOps::Arm_R7,
CArmOps::Arm_R8,
CArmOps::Arm_R9,
CArmOps::Arm_R10,
CArmOps::Arm_R11,
CArmOps::Arm_R12,
CArmOps::ArmRegLR,
CArmOps::ArmRegPC,
}; };
if (!m_InCallDirect) if (!m_InCallDirect)
@ -186,7 +250,10 @@ void CArmRegInfo::AfterCallDirect(void)
int PushPopRegisters = 0; int PushPopRegisters = 0;
for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++) for (int i = 0; i < (sizeof(RegisterList) / sizeof(RegisterList[0])); i++)
{ {
if (ShouldPushPopReg(RegisterList[i])) { PushPopRegisters |= PushPopRegisterList[i]; } if (ShouldPushPopReg(RegisterList[i]))
{
PushPopRegisters |= PushPopRegisterList[i];
}
} }
if (PushPopRegisters != 0) if (PushPopRegisters != 0)
@ -227,7 +294,7 @@ void CArmRegInfo::FixRoundModel(FPU_ROUND RoundMethod)
if (RoundMethod == RoundDefault) if (RoundMethod == RoundDefault)
{ {
BeforeCallDirect(); BeforeCallDirect();
m_Assembler.MoveVariableToArmReg(_RoundingModel, "_RoundingModel", CArmOps::Arm_R0); m_Assembler.MoveVariableToArmReg(_RoundingModel, "_RoundingModel", CArmOps::Arm_R0);
m_Assembler.CallFunction((void *)fesetround, "fesetround"); m_Assembler.CallFunction((void *)fesetround, "fesetround");
AfterCallDirect(); AfterCallDirect();
} }
@ -258,7 +325,10 @@ void CArmRegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg
Reg = FreeArmReg(false); Reg = FreeArmReg(false);
if (Reg < 0) if (Reg < 0)
{ {
if (HaveDebugger()) { g_Notify->DisplayError("Map_GPR_32bit\n\nOut of registers"); } if (HaveDebugger())
{
g_Notify->DisplayError("Map_GPR_32bit\n\nOut of registers");
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
@ -277,7 +347,7 @@ void CArmRegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg
} }
Reg = GetMipsRegMapLo(MipsReg); Reg = GetMipsRegMapLo(MipsReg);
} }
for (int32_t count = 0; count <= CArmOps::Arm_R15; count++) for (int32_t count = 0; count <= CArmOps::Arm_R15; count++)
{ {
uint32_t Count = GetArmRegMapOrder((CArmOps::ArmReg)count); uint32_t Count = GetArmRegMapOrder((CArmOps::ArmReg)count);
if (Count > 0) if (Count > 0)
@ -331,7 +401,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
if (MipsReg == 0) if (MipsReg == 0)
{ {
if (HaveDebugger()) { g_Notify->DisplayError("Map_GPR_64bit\n\nWhy are you trying to map register 0?"); } if (HaveDebugger())
{
g_Notify->DisplayError("Map_GPR_64bit\n\nWhy are you trying to map register 0?");
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
@ -342,7 +415,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
regHi = FreeArmReg(false); regHi = FreeArmReg(false);
if (regHi < 0) if (regHi < 0)
{ {
if (HaveDebugger()) { g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers"); } if (HaveDebugger())
{
g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers");
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
@ -351,7 +427,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
reglo = FreeArmReg(false); reglo = FreeArmReg(false);
if (reglo < 0) if (reglo < 0)
{ {
if (HaveDebugger()) { g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers"); } if (HaveDebugger())
{
g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers");
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
@ -369,7 +448,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
regHi = FreeArmReg(false); regHi = FreeArmReg(false);
if (regHi < 0) if (regHi < 0)
{ {
if (HaveDebugger()) { g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers"); } if (HaveDebugger())
{
g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers");
}
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
@ -475,7 +557,10 @@ void CArmRegInfo::UnMap_GPR(uint32_t MipsReg, bool WriteBackValue)
return; return;
} }
if (IsUnknown(MipsReg)) { return; } if (IsUnknown(MipsReg))
{
return;
}
//m_CodeBlock.Log("UnMap_GPR: State: %X\tReg: %s\tWriteBack: %s",State,CRegName::GPR[Reg],WriteBackValue?"true":"false"); //m_CodeBlock.Log("UnMap_GPR: State: %X\tReg: %s\tWriteBack: %s",State,CRegName::GPR[Reg],WriteBackValue?"true":"false");
if (IsConst(MipsReg)) if (IsConst(MipsReg))
{ {
@ -582,9 +667,18 @@ void CArmRegInfo::WriteBackRegisters()
UnMap_AllFPRs(); UnMap_AllFPRs();
int32_t ArmRegCount = sizeof(m_ArmReg_MappedTo) / sizeof(m_ArmReg_MappedTo[0]); int32_t ArmRegCount = sizeof(m_ArmReg_MappedTo) / sizeof(m_ArmReg_MappedTo[0]);
for (int32_t i = 1; i < 32; i++) { UnMap_GPR(i, true); } for (int32_t i = 1; i < 32; i++)
for (int32_t i = 0; i < ArmRegCount; i++) { UnMap_ArmReg((CArmOps::ArmReg)i); } {
for (int32_t i = 0; i < ArmRegCount; i++) { SetArmRegProtected((CArmOps::ArmReg)i, false); } UnMap_GPR(i, true);
}
for (int32_t i = 0; i < ArmRegCount; i++)
{
UnMap_ArmReg((CArmOps::ArmReg)i);
}
for (int32_t i = 0; i < ArmRegCount; i++)
{
SetArmRegProtected((CArmOps::ArmReg)i, false);
}
for (int32_t count = 1; count < 32; count++) for (int32_t count = 1; count < 32; count++)
{ {
@ -628,21 +722,57 @@ CArmOps::ArmReg CArmRegInfo::UnMap_TempReg(bool TempMapping)
} }
CArmOps::ArmReg Reg = CArmOps::Arm_Unknown; CArmOps::ArmReg Reg = CArmOps::Arm_Unknown;
if (GetArmRegMapped( CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R7)) { return CArmOps::Arm_R7; } if (GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R7))
if (GetArmRegMapped( CArmOps::Arm_R6) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R6)) { return CArmOps::Arm_R6; } {
if (GetArmRegMapped( CArmOps::Arm_R5) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R5)) { return CArmOps::Arm_R5; } return CArmOps::Arm_R7;
if (GetArmRegMapped( CArmOps::Arm_R4) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R4)) { return CArmOps::Arm_R4; } }
if (GetArmRegMapped( CArmOps::Arm_R3) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R3)) { return CArmOps::Arm_R3; } if (GetArmRegMapped(CArmOps::Arm_R6) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R6))
if (GetArmRegMapped( CArmOps::Arm_R2) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R2)) { return CArmOps::Arm_R2; } {
if (GetArmRegMapped( CArmOps::Arm_R1) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R1)) { return CArmOps::Arm_R1; } return CArmOps::Arm_R6;
if (GetArmRegMapped( CArmOps::Arm_R0) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R0)) { return CArmOps::Arm_R0; } }
if (GetArmRegMapped(CArmOps::Arm_R5) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R5))
{
return CArmOps::Arm_R5;
}
if (GetArmRegMapped(CArmOps::Arm_R4) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R4))
{
return CArmOps::Arm_R4;
}
if (GetArmRegMapped(CArmOps::Arm_R3) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R3))
{
return CArmOps::Arm_R3;
}
if (GetArmRegMapped(CArmOps::Arm_R2) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R2))
{
return CArmOps::Arm_R2;
}
if (GetArmRegMapped(CArmOps::Arm_R1) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R1))
{
return CArmOps::Arm_R1;
}
if (GetArmRegMapped(CArmOps::Arm_R0) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R0))
{
return CArmOps::Arm_R0;
}
if (TempMapping) if (TempMapping)
{ {
if (GetArmRegMapped( CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R11)) { return CArmOps::Arm_R11; } if (GetArmRegMapped(CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R11))
if (GetArmRegMapped( CArmOps::Arm_R10) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R10)) { return CArmOps::Arm_R10; } {
return CArmOps::Arm_R11;
}
if (GetArmRegMapped(CArmOps::Arm_R10) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R10))
{
return CArmOps::Arm_R10;
}
}
if (GetArmRegMapped(CArmOps::Arm_R9) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R9))
{
return CArmOps::Arm_R9;
}
if (GetArmRegMapped(CArmOps::Arm_R8) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R8))
{
return CArmOps::Arm_R8;
} }
if (GetArmRegMapped( CArmOps::Arm_R9) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R9)) { return CArmOps::Arm_R9; }
if (GetArmRegMapped( CArmOps::Arm_R8) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R8)) { return CArmOps::Arm_R8; }
if (Reg != CArmOps::Arm_Unknown) if (Reg != CArmOps::Arm_Unknown)
{ {
@ -742,34 +872,73 @@ CArmOps::ArmReg CArmRegInfo::FreeArmReg(bool TempMapping)
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return CArmOps::Arm_Unknown; return CArmOps::Arm_Unknown;
} }
if ((GetArmRegMapped( CArmOps::Arm_R7) == NotMapped || GetArmRegMapped( CArmOps::Arm_R7) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R7)) { return CArmOps::Arm_R7; } if ((GetArmRegMapped(CArmOps::Arm_R7) == NotMapped || GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R7))
if ((GetArmRegMapped( CArmOps::Arm_R6) == NotMapped || GetArmRegMapped( CArmOps::Arm_R6) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R6)) { return CArmOps::Arm_R6; } {
if ((GetArmRegMapped( CArmOps::Arm_R5) == NotMapped || GetArmRegMapped( CArmOps::Arm_R5) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R5)) { return CArmOps::Arm_R5; } return CArmOps::Arm_R7;
if ((GetArmRegMapped( CArmOps::Arm_R4) == NotMapped || GetArmRegMapped( CArmOps::Arm_R4) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R4)) { return CArmOps::Arm_R4; } }
if ((GetArmRegMapped( CArmOps::Arm_R3) == NotMapped || GetArmRegMapped( CArmOps::Arm_R3) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R3)) { return CArmOps::Arm_R3; } if ((GetArmRegMapped(CArmOps::Arm_R6) == NotMapped || GetArmRegMapped(CArmOps::Arm_R6) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R6))
if ((GetArmRegMapped( CArmOps::Arm_R2) == NotMapped || GetArmRegMapped( CArmOps::Arm_R2) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R2)) { return CArmOps::Arm_R2; } {
if ((GetArmRegMapped( CArmOps::Arm_R1) == NotMapped || GetArmRegMapped( CArmOps::Arm_R1) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R1)) { return CArmOps::Arm_R1; } return CArmOps::Arm_R6;
if ((GetArmRegMapped( CArmOps::Arm_R0) == NotMapped || GetArmRegMapped( CArmOps::Arm_R0) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R0)) { return CArmOps::Arm_R0; } }
if ((GetArmRegMapped(CArmOps::Arm_R5) == NotMapped || GetArmRegMapped(CArmOps::Arm_R5) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R5))
{
return CArmOps::Arm_R5;
}
if ((GetArmRegMapped(CArmOps::Arm_R4) == NotMapped || GetArmRegMapped(CArmOps::Arm_R4) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R4))
{
return CArmOps::Arm_R4;
}
if ((GetArmRegMapped(CArmOps::Arm_R3) == NotMapped || GetArmRegMapped(CArmOps::Arm_R3) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R3))
{
return CArmOps::Arm_R3;
}
if ((GetArmRegMapped(CArmOps::Arm_R2) == NotMapped || GetArmRegMapped(CArmOps::Arm_R2) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R2))
{
return CArmOps::Arm_R2;
}
if ((GetArmRegMapped(CArmOps::Arm_R1) == NotMapped || GetArmRegMapped(CArmOps::Arm_R1) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R1))
{
return CArmOps::Arm_R1;
}
if ((GetArmRegMapped(CArmOps::Arm_R0) == NotMapped || GetArmRegMapped(CArmOps::Arm_R0) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R0))
{
return CArmOps::Arm_R0;
}
if (TempMapping) if (TempMapping)
{ {
if ((GetArmRegMapped( CArmOps::Arm_R11) == NotMapped || GetArmRegMapped( CArmOps::Arm_R11) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R11)) { return CArmOps::Arm_R11; } if ((GetArmRegMapped(CArmOps::Arm_R11) == NotMapped || GetArmRegMapped(CArmOps::Arm_R11) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R11))
if ((GetArmRegMapped( CArmOps::Arm_R10) == NotMapped || GetArmRegMapped( CArmOps::Arm_R10) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R10)) { return CArmOps::Arm_R10; } {
return CArmOps::Arm_R11;
}
if ((GetArmRegMapped(CArmOps::Arm_R10) == NotMapped || GetArmRegMapped(CArmOps::Arm_R10) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R10))
{
return CArmOps::Arm_R10;
}
}
if ((GetArmRegMapped(CArmOps::Arm_R9) == NotMapped || GetArmRegMapped(CArmOps::Arm_R9) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R9))
{
return CArmOps::Arm_R9;
}
if ((GetArmRegMapped(CArmOps::Arm_R8) == NotMapped || GetArmRegMapped(CArmOps::Arm_R8) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R8))
{
return CArmOps::Arm_R8;
} }
if ((GetArmRegMapped( CArmOps::Arm_R9) == NotMapped || GetArmRegMapped( CArmOps::Arm_R9) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R9)) { return CArmOps::Arm_R9; }
if ((GetArmRegMapped( CArmOps::Arm_R8) == NotMapped || GetArmRegMapped( CArmOps::Arm_R8) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R8)) { return CArmOps::Arm_R8; }
CArmOps::ArmReg Reg = UnMap_TempReg(TempMapping); CArmOps::ArmReg Reg = UnMap_TempReg(TempMapping);
if (Reg != CArmOps::Arm_Unknown) { return Reg; } if (Reg != CArmOps::Arm_Unknown)
{
return Reg;
}
int32_t MapCount[ CArmOps::Arm_R12]; int32_t MapCount[CArmOps::Arm_R12];
CArmOps::ArmReg MapReg[ CArmOps::Arm_R12]; CArmOps::ArmReg MapReg[CArmOps::Arm_R12];
for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++) for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++)
{ {
MapCount[i] = GetArmRegMapOrder((CArmOps::ArmReg)i); MapCount[i] = GetArmRegMapOrder((CArmOps::ArmReg)i);
MapReg[i] = (CArmOps::ArmReg)i; MapReg[i] = (CArmOps::ArmReg)i;
} }
for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++) for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++)
{ {
bool changed = false; bool changed = false;
for (int32_t z = 0; z < n - 1; z++) for (int32_t z = 0; z < n - 1; z++)
@ -792,7 +961,7 @@ CArmOps::ArmReg CArmRegInfo::FreeArmReg(bool TempMapping)
} }
} }
for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++) for (int32_t i = 0, n = TempMapping ? CArmOps::Arm_R12 : CArmOps::Arm_R10; i < n; i++)
{ {
if (((MapCount[i] > 0 && GetArmRegMapped(MapReg[i]) == GPR_Mapped) || GetArmRegMapped(MapReg[i]) == Variable_Mapped) && !GetArmRegProtected((CArmOps::ArmReg)MapReg[i])) if (((MapCount[i] > 0 && GetArmRegMapped(MapReg[i]) == GPR_Mapped) || GetArmRegMapped(MapReg[i]) == Variable_Mapped) && !GetArmRegProtected((CArmOps::ArmReg)MapReg[i]))
{ {
@ -842,13 +1011,12 @@ void CArmRegInfo::LogRegisterState(void)
} }
m_CodeBlock.Log("GetArmRegMapped(%s) = %X%s%s Protected: %s MapOrder: %d", m_CodeBlock.Log("GetArmRegMapped(%s) = %X%s%s Protected: %s MapOrder: %d",
m_Assembler.ArmRegName((CArmOps::ArmReg)i), m_Assembler.ArmRegName((CArmOps::ArmReg)i),
GetArmRegMapped((CArmOps::ArmReg)i), GetArmRegMapped((CArmOps::ArmReg)i),
GetArmRegMapped((CArmOps::ArmReg)i) == CArmRegInfo::Variable_Mapped ? stdstr_f(" (%s)", CArmRegInfo::VariableMapName(GetVariableMappedTo((CArmOps::ArmReg)i))).c_str() : "", GetArmRegMapped((CArmOps::ArmReg)i) == CArmRegInfo::Variable_Mapped ? stdstr_f(" (%s)", CArmRegInfo::VariableMapName(GetVariableMappedTo((CArmOps::ArmReg)i))).c_str() : "",
regname.length() > 0 ? stdstr_f(" (%s)", regname.c_str()).c_str() : "", regname.length() > 0 ? stdstr_f(" (%s)", regname.c_str()).c_str() : "",
GetArmRegProtected((CArmOps::ArmReg)i) ? "true" : "false", GetArmRegProtected((CArmOps::ArmReg)i) ? "true" : "false",
GetArmRegMapOrder((CArmOps::ArmReg)i) GetArmRegMapOrder((CArmOps::ArmReg)i));
);
} }
} }
@ -864,18 +1032,54 @@ CArmOps::ArmReg CArmRegInfo::Map_TempReg(CArmOps::ArmReg Reg, int32_t MipsReg, b
if (Reg == CArmOps::Arm_Any) if (Reg == CArmOps::Arm_Any)
{ {
if (GetArmRegMapped( CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R7)) { Reg = CArmOps::Arm_R7; } if (GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R7))
else if (GetArmRegMapped( CArmOps::Arm_R6) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R6)) { Reg = CArmOps::Arm_R6; } {
else if (GetArmRegMapped( CArmOps::Arm_R5) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R5)) { Reg = CArmOps::Arm_R5; } Reg = CArmOps::Arm_R7;
else if (GetArmRegMapped( CArmOps::Arm_R4) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R4)) { Reg = CArmOps::Arm_R4; } }
else if (GetArmRegMapped( CArmOps::Arm_R3) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R3)) { Reg = CArmOps::Arm_R3; } else if (GetArmRegMapped(CArmOps::Arm_R6) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R6))
else if (GetArmRegMapped( CArmOps::Arm_R2) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R2)) { Reg = CArmOps::Arm_R2; } {
else if (GetArmRegMapped( CArmOps::Arm_R1) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R1)) { Reg = CArmOps::Arm_R1; } Reg = CArmOps::Arm_R6;
else if (GetArmRegMapped( CArmOps::Arm_R0) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R0)) { Reg = CArmOps::Arm_R0; } }
else if (GetArmRegMapped( CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R11)) { Reg = CArmOps::Arm_R11; } else if (GetArmRegMapped(CArmOps::Arm_R5) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R5))
else if (GetArmRegMapped( CArmOps::Arm_R10) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R10)) { Reg = CArmOps::Arm_R10; } {
else if (GetArmRegMapped( CArmOps::Arm_R9) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R9)) { Reg = CArmOps::Arm_R9; } Reg = CArmOps::Arm_R5;
else if (GetArmRegMapped( CArmOps::Arm_R8) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R8)) { Reg = CArmOps::Arm_R8; } }
else if (GetArmRegMapped(CArmOps::Arm_R4) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R4))
{
Reg = CArmOps::Arm_R4;
}
else if (GetArmRegMapped(CArmOps::Arm_R3) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R3))
{
Reg = CArmOps::Arm_R3;
}
else if (GetArmRegMapped(CArmOps::Arm_R2) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R2))
{
Reg = CArmOps::Arm_R2;
}
else if (GetArmRegMapped(CArmOps::Arm_R1) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R1))
{
Reg = CArmOps::Arm_R1;
}
else if (GetArmRegMapped(CArmOps::Arm_R0) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R0))
{
Reg = CArmOps::Arm_R0;
}
else if (GetArmRegMapped(CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R11))
{
Reg = CArmOps::Arm_R11;
}
else if (GetArmRegMapped(CArmOps::Arm_R10) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R10))
{
Reg = CArmOps::Arm_R10;
}
else if (GetArmRegMapped(CArmOps::Arm_R9) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R9))
{
Reg = CArmOps::Arm_R9;
}
else if (GetArmRegMapped(CArmOps::Arm_R8) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R8))
{
Reg = CArmOps::Arm_R8;
}
if (Reg == CArmOps::Arm_Any) if (Reg == CArmOps::Arm_Any)
{ {
@ -1013,7 +1217,7 @@ CArmOps::ArmReg CArmRegInfo::Map_Variable(VARIABLE_MAPPED variable, CArmOps::Arm
return Reg; return Reg;
} }
Reg = variable == VARIABLE_GPR ? CArmOps::Arm_R12 : FreeArmReg(false); Reg = variable == VARIABLE_GPR ? CArmOps::Arm_R12 : FreeArmReg(false);
if (Reg == CArmOps::Arm_Unknown) if (Reg == CArmOps::Arm_Unknown)
{ {
WriteTrace(TraceRegisterCache, TraceError, "Failed to find a free register"); WriteTrace(TraceRegisterCache, TraceError, "Failed to find a free register");
@ -1035,13 +1239,34 @@ CArmOps::ArmReg CArmRegInfo::Map_Variable(VARIABLE_MAPPED variable, CArmOps::Arm
m_CodeBlock.Log(" regcache: allocate %s as pointer to %s", m_Assembler.ArmRegName(Reg), VariableMapName(variable)); m_CodeBlock.Log(" regcache: allocate %s as pointer to %s", m_Assembler.ArmRegName(Reg), VariableMapName(variable));
m_Variable_MappedTo[Reg] = variable; m_Variable_MappedTo[Reg] = variable;
if (variable == VARIABLE_GPR) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_GPR, "_GPR"); } if (variable == VARIABLE_GPR)
else if (variable == VARIABLE_FPR) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_FPR_S, "_FPR_S"); } {
else if (variable == VARIABLE_TLB_READMAP) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_MMU->m_TLB_ReadMap), "MMU->TLB_ReadMap"); } m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_GPR, "_GPR");
else if (variable == VARIABLE_TLB_WRITEMAP) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_MMU->m_TLB_WriteMap), "MMU->m_TLB_WriteMap"); } }
else if (variable == VARIABLE_TLB_LOAD_ADDRESS) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_TLBLoadAddress), "g_TLBLoadAddress"); } else if (variable == VARIABLE_FPR)
else if (variable == VARIABLE_TLB_STORE_ADDRESS) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_TLBStoreAddress), "g_TLBStoreAddress"); } {
else if (variable == VARIABLE_NEXT_TIMER) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_NextTimer), "g_NextTimer"); } m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_FPR_S, "_FPR_S");
}
else if (variable == VARIABLE_TLB_READMAP)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_MMU->m_TLB_ReadMap), "MMU->TLB_ReadMap");
}
else if (variable == VARIABLE_TLB_WRITEMAP)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_MMU->m_TLB_WriteMap), "MMU->m_TLB_WriteMap");
}
else if (variable == VARIABLE_TLB_LOAD_ADDRESS)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_TLBLoadAddress), "g_TLBLoadAddress");
}
else if (variable == VARIABLE_TLB_STORE_ADDRESS)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_TLBStoreAddress), "g_TLBStoreAddress");
}
else if (variable == VARIABLE_NEXT_TIMER)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)(g_NextTimer), "g_NextTimer");
}
else else
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#if defined(__arm__) || defined(_M_ARM) #if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/Recompiler/RegBase.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/RegBase.h>
class CArmRegInfo : class CArmRegInfo :
public CRegBase, public CRegBase,
@ -32,13 +32,13 @@ public:
}; };
CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler); CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler);
CArmRegInfo(const CArmRegInfo&); CArmRegInfo(const CArmRegInfo &);
~CArmRegInfo(); ~CArmRegInfo();
CArmRegInfo& operator=(const CArmRegInfo&); CArmRegInfo & operator=(const CArmRegInfo &);
bool operator==(const CArmRegInfo& right) const; bool operator==(const CArmRegInfo & right) const;
bool operator!=(const CArmRegInfo& right) const; bool operator!=(const CArmRegInfo & right) const;
void BeforeCallDirect(void); void BeforeCallDirect(void);
void AfterCallDirect(void); void AfterCallDirect(void);
@ -61,21 +61,57 @@ public:
bool UnMap_ArmReg(CArmOps::ArmReg Reg); bool UnMap_ArmReg(CArmOps::ArmReg Reg);
void ResetRegProtection(); void ResetRegProtection();
inline CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; } inline CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg) const
inline CArmOps::ArmReg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; } {
inline void SetMipsRegMapLo(int32_t GetMipsReg, CArmOps::ArmReg Reg) { m_RegMapLo[GetMipsReg] = Reg; } return m_RegMapLo[Reg];
inline void SetMipsRegMapHi(int32_t GetMipsReg, CArmOps::ArmReg Reg) { m_RegMapHi[GetMipsReg] = Reg; } }
inline CArmOps::ArmReg GetMipsRegMapHi(int32_t Reg) const
{
return m_RegMapHi[Reg];
}
inline void SetMipsRegMapLo(int32_t GetMipsReg, CArmOps::ArmReg Reg)
{
m_RegMapLo[GetMipsReg] = Reg;
}
inline void SetMipsRegMapHi(int32_t GetMipsReg, CArmOps::ArmReg Reg)
{
m_RegMapHi[GetMipsReg] = Reg;
}
inline uint32_t GetArmRegMapOrder(CArmOps::ArmReg Reg) const { return m_ArmReg_MapOrder[Reg]; } inline uint32_t GetArmRegMapOrder(CArmOps::ArmReg Reg) const
inline bool GetArmRegProtected(CArmOps::ArmReg Reg) const { return m_ArmReg_Protected[Reg]; } {
inline REG_MAPPED GetArmRegMapped(CArmOps::ArmReg Reg) const { return m_ArmReg_MappedTo[Reg]; } return m_ArmReg_MapOrder[Reg];
}
inline bool GetArmRegProtected(CArmOps::ArmReg Reg) const
{
return m_ArmReg_Protected[Reg];
}
inline REG_MAPPED GetArmRegMapped(CArmOps::ArmReg Reg) const
{
return m_ArmReg_MappedTo[Reg];
}
inline void SetArmRegMapOrder(CArmOps::ArmReg Reg, uint32_t Order) { m_ArmReg_MapOrder[Reg] = Order; } inline void SetArmRegMapOrder(CArmOps::ArmReg Reg, uint32_t Order)
inline void SetArmRegProtected(CArmOps::ArmReg Reg, bool Protected) { m_ArmReg_Protected[Reg] = Protected; } {
inline void SetArmRegMapped(CArmOps::ArmReg Reg, REG_MAPPED Mapping) { m_ArmReg_MappedTo[Reg] = Mapping; } m_ArmReg_MapOrder[Reg] = Order;
}
inline void SetArmRegProtected(CArmOps::ArmReg Reg, bool Protected)
{
m_ArmReg_Protected[Reg] = Protected;
}
inline void SetArmRegMapped(CArmOps::ArmReg Reg, REG_MAPPED Mapping)
{
m_ArmReg_MappedTo[Reg] = Mapping;
}
inline VARIABLE_MAPPED GetVariableMappedTo(CArmOps::ArmReg Reg) const { return m_Variable_MappedTo[Reg]; } inline VARIABLE_MAPPED GetVariableMappedTo(CArmOps::ArmReg Reg) const
inline void SetVariableMappedTo(CArmOps::ArmReg Reg, VARIABLE_MAPPED variable) { m_Variable_MappedTo[Reg] = variable; } {
return m_Variable_MappedTo[Reg];
}
inline void SetVariableMappedTo(CArmOps::ArmReg Reg, VARIABLE_MAPPED variable)
{
m_Variable_MappedTo[Reg] = variable;
}
static const char * VariableMapName(VARIABLE_MAPPED variable); static const char * VariableMapName(VARIABLE_MAPPED variable);
void LogRegisterState(void); void LogRegisterState(void);
@ -86,7 +122,7 @@ private:
CCodeBlock & m_CodeBlock; CCodeBlock & m_CodeBlock;
CArmOps & m_Assembler; CArmOps & m_Assembler;
bool ShouldPushPopReg (CArmOps::ArmReg Reg); bool ShouldPushPopReg(CArmOps::ArmReg Reg);
CArmOps::ArmReg m_RegMapHi[32]; CArmOps::ArmReg m_RegMapHi[32];
CArmOps::ArmReg m_RegMapLo[32]; CArmOps::ArmReg m_RegMapLo[32];

View File

@ -1,15 +1,16 @@
#include "stdafx.h" #include "stdafx.h"
#include <string.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h> #include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h> #include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h> #include <string.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM)) #if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM))
/* bug-fix to implement __clear_cache (missing in Android; http://code.google.com/p/android/issues/detail?id=1803) */ /* bug-fix to implement __clear_cache (missing in Android; http://code.google.com/p/android/issues/detail?id=1803) */
extern "C" void __clear_cache_android(uint8_t* begin, uint8_t *end); extern "C" void __clear_cache_android(uint8_t * begin, uint8_t * end);
#endif #endif
CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation) : CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation) :
@ -26,7 +27,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi
// Make sure function starts at an odd address so that the system knows it is in thumb mode // Make sure function starts at an odd address so that the system knows it is in thumb mode
if (((uint32_t)m_CompiledLocation % 2) == 0) if (((uint32_t)m_CompiledLocation % 2) == 0)
{ {
m_CompiledLocation+=1; m_CompiledLocation += 1;
} }
#endif #endif
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
@ -97,7 +98,7 @@ CCodeBlock::~CCodeBlock()
} }
} }
bool CCodeBlock::SetSection(CCodeSection * & Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC) bool CCodeBlock::SetSection(CCodeSection *& Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC)
{ {
if (Section != nullptr) if (Section != nullptr)
{ {
@ -451,22 +452,53 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_SPECIAL: case R4300i_SPECIAL:
switch (Command.funct) switch (Command.funct)
{ {
case R4300i_SPECIAL_SLL: case R4300i_SPECIAL_SRL: case R4300i_SPECIAL_SRA: case R4300i_SPECIAL_SLL:
case R4300i_SPECIAL_SLLV: case R4300i_SPECIAL_SRLV: case R4300i_SPECIAL_SRAV: case R4300i_SPECIAL_SRL:
case R4300i_SPECIAL_MFHI: case R4300i_SPECIAL_MTHI: case R4300i_SPECIAL_MFLO: case R4300i_SPECIAL_SRA:
case R4300i_SPECIAL_MTLO: case R4300i_SPECIAL_DSLLV: case R4300i_SPECIAL_DSRLV: case R4300i_SPECIAL_SLLV:
case R4300i_SPECIAL_DSRAV: case R4300i_SPECIAL_ADD: case R4300i_SPECIAL_ADDU: case R4300i_SPECIAL_SRLV:
case R4300i_SPECIAL_SUB: case R4300i_SPECIAL_SUBU: case R4300i_SPECIAL_AND: case R4300i_SPECIAL_SRAV:
case R4300i_SPECIAL_OR: case R4300i_SPECIAL_XOR: case R4300i_SPECIAL_NOR: case R4300i_SPECIAL_MFHI:
case R4300i_SPECIAL_SLT: case R4300i_SPECIAL_SLTU: case R4300i_SPECIAL_DADD: case R4300i_SPECIAL_MTHI:
case R4300i_SPECIAL_DADDU: case R4300i_SPECIAL_DSUB: case R4300i_SPECIAL_DSUBU: case R4300i_SPECIAL_MFLO:
case R4300i_SPECIAL_DSLL: case R4300i_SPECIAL_DSRL: case R4300i_SPECIAL_DSRA: case R4300i_SPECIAL_MTLO:
case R4300i_SPECIAL_DSLL32: case R4300i_SPECIAL_DSRL32: case R4300i_SPECIAL_DSRA32: case R4300i_SPECIAL_DSLLV:
case R4300i_SPECIAL_MULT: case R4300i_SPECIAL_MULTU: case R4300i_SPECIAL_DIV: case R4300i_SPECIAL_DSRLV:
case R4300i_SPECIAL_DIVU: case R4300i_SPECIAL_DMULT: case R4300i_SPECIAL_DMULTU: case R4300i_SPECIAL_DSRAV:
case R4300i_SPECIAL_DDIV: case R4300i_SPECIAL_DDIVU: case R4300i_SPECIAL_TEQ: case R4300i_SPECIAL_ADD:
case R4300i_SPECIAL_TNE: case R4300i_SPECIAL_TGE: case R4300i_SPECIAL_TGEU: case R4300i_SPECIAL_ADDU:
case R4300i_SPECIAL_TLT: case R4300i_SPECIAL_TLTU: 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:
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:
case R4300i_SPECIAL_TEQ:
case R4300i_SPECIAL_TNE:
case R4300i_SPECIAL_TGE:
case R4300i_SPECIAL_TGEU:
case R4300i_SPECIAL_TLT:
case R4300i_SPECIAL_TLTU:
break; break;
case R4300i_SPECIAL_JALR: case R4300i_SPECIAL_JALR:
case R4300i_SPECIAL_JR: case R4300i_SPECIAL_JR:
@ -563,8 +595,12 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
LikelyBranch = true; LikelyBranch = true;
IncludeDelaySlot = true; IncludeDelaySlot = true;
break; break;
case R4300i_REGIMM_TEQI: case R4300i_REGIMM_TNEI: case R4300i_REGIMM_TGEI: case R4300i_REGIMM_TEQI:
case R4300i_REGIMM_TGEIU: case R4300i_REGIMM_TLTI: case R4300i_REGIMM_TLTIU: case R4300i_REGIMM_TNEI:
case R4300i_REGIMM_TGEI:
case R4300i_REGIMM_TGEIU:
case R4300i_REGIMM_TLTI:
case R4300i_REGIMM_TLTIU:
break; break;
default: default:
if (Command.Value == 0x0407000D) if (Command.Value == 0x0407000D)
@ -639,15 +675,18 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_CP0: case R4300i_CP0:
switch (Command.rs) switch (Command.rs)
{ {
case R4300i_COP0_MT: case R4300i_COP0_MF: case R4300i_COP0_MT:
case R4300i_COP0_MF:
break; break;
default: default:
if ((Command.rs & 0x10) != 0) if ((Command.rs & 0x10) != 0)
{ {
switch (Command.funct) switch (Command.funct)
{ {
case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI: case R4300i_COP0_CO_TLBR:
case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP: case R4300i_COP0_CO_TLBWI:
case R4300i_COP0_CO_TLBWR:
case R4300i_COP0_CO_TLBP:
break; break;
case R4300i_COP0_CO_ERET: case R4300i_COP0_CO_ERET:
EndBlock = true; EndBlock = true;
@ -668,12 +707,20 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_CP1: case R4300i_CP1:
switch (Command.fmt) switch (Command.fmt)
{ {
case R4300i_COP1_MF: case R4300i_COP1_DMF: case R4300i_COP1_CF: case R4300i_COP1_MT: case R4300i_COP1_MF:
case R4300i_COP1_DMT: case R4300i_COP1_CT: case R4300i_COP1_S: case R4300i_COP1_D: case R4300i_COP1_DMF:
case R4300i_COP1_W: case R4300i_COP1_L: case R4300i_COP1_CF:
case R4300i_COP1_MT:
case R4300i_COP1_DMT:
case R4300i_COP1_CT:
case R4300i_COP1_S:
case R4300i_COP1_D:
case R4300i_COP1_W:
case R4300i_COP1_L:
break; break;
case R4300i_COP1_BC: case R4300i_COP1_BC:
switch (Command.ft) { switch (Command.ft)
{
case R4300i_COP1_BC_BCF: case R4300i_COP1_BC_BCF:
case R4300i_COP1_BC_BCT: case R4300i_COP1_BC_BCT:
TargetPC = PC + ((int16_t)Command.offset << 2) + 4; TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
@ -711,15 +758,42 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
return false; return false;
} }
break; break;
case R4300i_ANDI: case R4300i_ORI: case R4300i_XORI: case R4300i_LUI: case R4300i_ANDI:
case R4300i_ADDI: case R4300i_ADDIU: case R4300i_SLTI: case R4300i_SLTIU: case R4300i_ORI:
case R4300i_DADDI: case R4300i_DADDIU: case R4300i_LDL: case R4300i_LDR: case R4300i_XORI:
case R4300i_LB: case R4300i_LH: case R4300i_LWL: case R4300i_LW: case R4300i_LUI:
case R4300i_LBU: case R4300i_LHU: case R4300i_LWR: case R4300i_LWU: case R4300i_ADDI:
case R4300i_SB: case R4300i_SH: case R4300i_SWL: case R4300i_SW: case R4300i_ADDIU:
case R4300i_SDL: case R4300i_SDR: case R4300i_SWR: case R4300i_CACHE: case R4300i_SLTI:
case R4300i_LL: case R4300i_LWC1: case R4300i_LDC1: case R4300i_LD: case R4300i_SLTIU:
case R4300i_SC: case R4300i_SWC1: case R4300i_SDC1: case R4300i_SD: case R4300i_DADDI:
case R4300i_DADDIU:
case R4300i_LDL:
case R4300i_LDR:
case R4300i_LB:
case R4300i_LH:
case R4300i_LWL:
case R4300i_LW:
case R4300i_LBU:
case R4300i_LHU:
case R4300i_LWR:
case R4300i_LWU:
case R4300i_SB:
case R4300i_SH:
case R4300i_SWL:
case R4300i_SW:
case R4300i_SDL:
case R4300i_SDR:
case R4300i_SWR:
case R4300i_CACHE:
case R4300i_LL:
case R4300i_LWC1:
case R4300i_LDC1:
case R4300i_LD:
case R4300i_SC:
case R4300i_SWC1:
case R4300i_SDC1:
case R4300i_SD:
break; break;
case R4300i_BEQL: case R4300i_BEQL:
TargetPC = PC + ((int16_t)Command.offset << 2) + 4; TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
@ -786,7 +860,8 @@ bool CCodeBlock::Compile()
m_RecompilerOps->EnterCodeBlock(); m_RecompilerOps->EnterCodeBlock();
if (g_System->bLinkBlocks()) if (g_System->bLinkBlocks())
{ {
while (m_EnterSection !=nullptr && m_EnterSection->GenerateNativeCode(NextTest())); while (m_EnterSection != nullptr && m_EnterSection->GenerateNativeCode(NextTest()))
;
} }
else else
{ {
@ -807,7 +882,7 @@ bool CCodeBlock::Compile()
} }
MD5(BlockPtr, BlockSize).get_digest(m_Hash); MD5(BlockPtr, BlockSize).get_digest(m_Hash);
#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM)) #if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM))
__clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocationEnd); __clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocationEnd);
#endif #endif
return true; return true;
} }
@ -831,7 +906,7 @@ void CCodeBlock::Log(_Printf_format_string_ const char * Text, ...)
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
size_t nlen = _vscprintf(Text, args) + 1; size_t nlen = _vscprintf(Text, args) + 1;
char * buffer = (char*)alloca(nlen * sizeof(char)); char * buffer = (char *)alloca(nlen * sizeof(char));
buffer[nlen - 1] = 0; buffer[nlen - 1] = 0;
if (buffer != nullptr) if (buffer != nullptr)
{ {

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Common/md5.h> #include <Common/md5.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/CodeSection.h> #include <Project64-core/N64System/Recompiler/CodeSection.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#if !defined(_MSC_VER) && !defined(_Printf_format_string_) #if !defined(_MSC_VER) && !defined(_Printf_format_string_)
#define _Printf_format_string_ #define _Printf_format_string_
@ -17,25 +17,73 @@ public:
bool Compile(); bool Compile();
uint32_t VAddrEnter() const { return m_VAddrEnter; } uint32_t VAddrEnter() const
uint32_t VAddrFirst() const { return m_VAddrFirst; } {
uint32_t VAddrLast() const { return m_VAddrLast; } return m_VAddrEnter;
uint8_t * CompiledLocation() const { return m_CompiledLocation; } }
uint8_t * CompiledLocationEnd() const { return m_CompiledLocationEnd; } uint32_t VAddrFirst() const
int32_t NoOfSections() const { return (int32_t)m_Sections.size() - 1; } {
const CCodeSection & EnterSection() const { return *m_EnterSection; } return m_VAddrFirst;
const MD5Digest & Hash() const { return m_Hash; } }
CRecompilerOps *& RecompilerOps() { return m_RecompilerOps; } uint32_t VAddrLast() const
const std::string & CodeLog() const { return m_CodeLog; } {
return m_VAddrLast;
}
uint8_t * CompiledLocation() const
{
return m_CompiledLocation;
}
uint8_t * CompiledLocationEnd() const
{
return m_CompiledLocationEnd;
}
int32_t NoOfSections() const
{
return (int32_t)m_Sections.size() - 1;
}
const CCodeSection & EnterSection() const
{
return *m_EnterSection;
}
const MD5Digest & Hash() const
{
return m_Hash;
}
CRecompilerOps *& RecompilerOps()
{
return m_RecompilerOps;
}
const std::string & CodeLog() const
{
return m_CodeLog;
}
void SetVAddrFirst(uint32_t VAddr) { m_VAddrFirst = VAddr; } void SetVAddrFirst(uint32_t VAddr)
void SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; } {
m_VAddrFirst = VAddr;
}
void SetVAddrLast(uint32_t VAddr)
{
m_VAddrLast = VAddr;
}
CCodeSection * ExistingSection(uint32_t Addr) { return m_EnterSection->ExistingSection(Addr, NextTest()); } CCodeSection * ExistingSection(uint32_t Addr)
bool SectionAccessible(uint32_t m_SectionID) { return m_EnterSection->SectionAccessible(m_SectionID, NextTest()); } {
return m_EnterSection->ExistingSection(Addr, NextTest());
}
bool SectionAccessible(uint32_t m_SectionID)
{
return m_EnterSection->SectionAccessible(m_SectionID, NextTest());
}
uint64_t MemContents(int32_t i) const { return m_MemContents[i]; } uint64_t MemContents(int32_t i) const
uint64_t * MemLocation(int32_t i) const { return m_MemLocation[i]; } {
return m_MemContents[i];
}
uint64_t * MemLocation(int32_t i) const
{
return m_MemLocation[i];
}
uint32_t NextTest(); uint32_t NextTest();
@ -43,21 +91,21 @@ public:
private: private:
CCodeBlock(); CCodeBlock();
CCodeBlock(const CCodeBlock&); CCodeBlock(const CCodeBlock &);
CCodeBlock& operator=(const CCodeBlock&); CCodeBlock & operator=(const CCodeBlock &);
bool AnalyseBlock(); bool AnalyseBlock();
bool CreateBlockLinkage(CCodeSection * EnterSection); bool CreateBlockLinkage(CCodeSection * EnterSection);
void DetermineLoops(); void DetermineLoops();
void LogSectionInfo(); void LogSectionInfo();
bool SetSection(CCodeSection * & Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC); bool SetSection(CCodeSection *& Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC);
bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop); bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop);
uint32_t m_VAddrEnter; uint32_t m_VAddrEnter;
uint32_t m_VAddrFirst; // The address of the first opcode in the block uint32_t m_VAddrFirst; // The address of the first opcode in the block
uint32_t m_VAddrLast; // The address of the first opcode in the block uint32_t m_VAddrLast; // The address of the first opcode in the block
uint8_t * m_CompiledLocation; // What address is this compiled at? uint8_t * m_CompiledLocation; // What address is this compiled at?
uint8_t * m_CompiledLocationEnd; // What address is this compiled at? uint8_t * m_CompiledLocationEnd; // What address is this compiled at?
typedef std::map<uint32_t, CCodeSection *> SectionMap; typedef std::map<uint32_t, CCodeSection *> SectionMap;

View File

@ -1,16 +1,17 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Recompiler/CodeSection.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h> #include <Project64-core/Debugger.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/ExceptionHandler.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h> #include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/Recompiler/CodeSection.h>
#include <Project64-core/N64System/Recompiler/LoopAnalysis.h> #include <Project64-core/N64System/Recompiler/LoopAnalysis.h>
#include <Project64-core/N64System/Recompiler/SectionInfo.h> #include <Project64-core/N64System/Recompiler/SectionInfo.h>
#include <Project64-core/ExceptionHandler.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/Debugger.h>
CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) : CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) :
m_CodeBlock(CodeBlock), m_CodeBlock(CodeBlock),
@ -41,8 +42,8 @@ CCodeSection::~CCodeSection()
void CCodeSection::GenerateSectionLinkage() void CCodeSection::GenerateSectionLinkage()
{ {
CCodeSection * TargetSection[] = { m_ContinueSection, m_JumpSection }; CCodeSection * TargetSection[] = {m_ContinueSection, m_JumpSection};
CJumpInfo * JumpInfo[] = { &m_Cont, &m_Jump }; CJumpInfo * JumpInfo[] = {&m_Cont, &m_Jump};
int i; int i;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
@ -90,8 +91,14 @@ void CCodeSection::GenerateSectionLinkage()
} }
else if (TargetSection[i] != nullptr && JumpInfo[i] != nullptr) else if (TargetSection[i] != nullptr && JumpInfo[i] != nullptr)
{ {
if (!JumpInfo[i]->FallThrough) { continue; } if (!JumpInfo[i]->FallThrough)
if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC) { continue; } {
continue;
}
if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC)
{
continue;
}
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1); m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason); m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason);
//FreeSection(TargetSection[i],Section); //FreeSection(TargetSection[i],Section);
@ -100,9 +107,15 @@ void CCodeSection::GenerateSectionLinkage()
} }
else else
{ {
if (m_Cont.LinkLocation == nullptr && m_Cont.FallThrough == false) { m_ContinueSection = nullptr; } if (m_Cont.LinkLocation == nullptr && m_Cont.FallThrough == false)
if (m_Jump.LinkLocation == nullptr && m_Jump.FallThrough == false) { m_JumpSection = nullptr; } {
if (m_JumpSection == nullptr && m_ContinueSection == nullptr) m_ContinueSection = nullptr;
}
if (m_Jump.LinkLocation == nullptr && m_Jump.FallThrough == false)
{
m_JumpSection = nullptr;
}
if (m_JumpSection == nullptr && m_ContinueSection == nullptr)
{ {
//FreeSection(TargetSection[0],Section); //FreeSection(TargetSection[0],Section);
} }
@ -111,9 +124,16 @@ void CCodeSection::GenerateSectionLinkage()
TargetSection[0] = m_ContinueSection; TargetSection[0] = m_ContinueSection;
TargetSection[1] = m_JumpSection; TargetSection[1] = m_JumpSection;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++)
if (TargetSection[i] == nullptr) { continue; } {
if (!JumpInfo[i]->FallThrough) { continue; } if (TargetSection[i] == nullptr)
{
continue;
}
if (!JumpInfo[i]->FallThrough)
{
continue;
}
if (TargetSection[i]->m_CompiledLocation != nullptr) if (TargetSection[i]->m_CompiledLocation != nullptr)
{ {
@ -147,14 +167,26 @@ void CCodeSection::GenerateSectionLinkage()
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
if (TargetSection[i] == nullptr) { continue; } if (TargetSection[i] == nullptr)
if (TargetSection[i]->m_ParentSection.empty()) { continue; } {
continue;
}
if (TargetSection[i]->m_ParentSection.empty())
{
continue;
}
for (SECTION_LIST::iterator iter = TargetSection[i]->m_ParentSection.begin(); iter != TargetSection[i]->m_ParentSection.end(); iter++) for (SECTION_LIST::iterator iter = TargetSection[i]->m_ParentSection.begin(); iter != TargetSection[i]->m_ParentSection.end(); iter++)
{ {
CCodeSection * Parent = *iter; CCodeSection * Parent = *iter;
if (Parent->m_CompiledLocation != nullptr) { continue; } if (Parent->m_CompiledLocation != nullptr)
if (Parent->m_InLoop) { continue; } {
continue;
}
if (Parent->m_InLoop)
{
continue;
}
if (JumpInfo[i]->PermLoop) if (JumpInfo[i]->PermLoop)
{ {
m_CodeBlock.Log("PermLoop *** 2"); m_CodeBlock.Log("PermLoop *** 2");
@ -195,7 +227,10 @@ void CCodeSection::GenerateSectionLinkage()
//CodeLog("Section %d",m_SectionID); //CodeLog("Section %d",m_SectionID);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
if (JumpInfo[i]->LinkLocation == nullptr) { continue; } if (JumpInfo[i]->LinkLocation == nullptr)
{
continue;
}
if (TargetSection[i] == nullptr) if (TargetSection[i] == nullptr)
{ {
m_CodeBlock.Log("ExitBlock (from %d):", m_SectionID); m_CodeBlock.Log("ExitBlock (from %d):", m_SectionID);
@ -269,8 +304,14 @@ bool CCodeSection::ParentContinue()
for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++)
{ {
CCodeSection * Parent = *iter; CCodeSection * Parent = *iter;
if (Parent->m_CompiledLocation != nullptr) { continue; } if (Parent->m_CompiledLocation != nullptr)
if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest())) { continue; } {
continue;
}
if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest()))
{
continue;
}
return false; return false;
} }
m_RecompilerOps->SetCurrentSection(this); m_RecompilerOps->SetCurrentSection(this);
@ -291,8 +332,14 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
return false; return false;
} }
m_Test = Test; m_Test = Test;
if (m_ContinueSection != nullptr && m_ContinueSection->GenerateNativeCode(Test)) { return true; } if (m_ContinueSection != nullptr && m_ContinueSection->GenerateNativeCode(Test))
if (m_JumpSection != nullptr && m_JumpSection->GenerateNativeCode(Test)) { return true; } {
return true;
}
if (m_JumpSection != nullptr && m_JumpSection->GenerateNativeCode(Test))
{
return true;
}
return false; return false;
} }
@ -389,9 +436,9 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_SPECIAL_TGEU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TGEU); break; case R4300i_SPECIAL_TGEU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TGEU); break;
case R4300i_SPECIAL_TLT: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLT); break; case R4300i_SPECIAL_TLT: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLT); break;
case R4300i_SPECIAL_TLTU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTU); break; case R4300i_SPECIAL_TLTU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTU); break;
break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_REGIMM: case R4300i_REGIMM:
@ -410,7 +457,8 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_REGIMM_TLTI: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTI); break; case R4300i_REGIMM_TLTI: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTI); break;
case R4300i_REGIMM_TLTIU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTIU); break; case R4300i_REGIMM_TLTIU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTIU); break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_BEQ: m_RecompilerOps->Compile_Branch(RecompilerBranchCompare_BEQ, false); break; case R4300i_BEQ: m_RecompilerOps->Compile_Branch(RecompilerBranchCompare_BEQ, false); break;
@ -468,7 +516,8 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_COP1_BC_BCFL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_COP1BCF, false); break; case R4300i_COP1_BC_BCFL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_COP1BCF, false); break;
case R4300i_COP1_BC_BCTL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_COP1BCT, false); break; case R4300i_COP1_BC_BCTL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_COP1BCT, false); break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_COP1_S: case R4300i_COP1_S:
@ -493,17 +542,27 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_S_CVT_D(); break; case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_S_CVT_D(); break;
case R4300i_COP1_FUNCT_CVT_W: m_RecompilerOps->COP1_S_CVT_W(); break; case R4300i_COP1_FUNCT_CVT_W: m_RecompilerOps->COP1_S_CVT_W(); break;
case R4300i_COP1_FUNCT_CVT_L: m_RecompilerOps->COP1_S_CVT_L(); break; case R4300i_COP1_FUNCT_CVT_L: m_RecompilerOps->COP1_S_CVT_L(); break;
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: case R4300i_COP1_FUNCT_C_F:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: case R4300i_COP1_FUNCT_C_EQ:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: case R4300i_COP1_FUNCT_C_OLT:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: case R4300i_COP1_FUNCT_C_OLE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: case R4300i_COP1_FUNCT_C_ULE:
m_RecompilerOps->COP1_S_CMP(); break; 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:
m_RecompilerOps->COP1_S_CMP();
break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_COP1_D: case R4300i_COP1_D:
@ -528,17 +587,27 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_D_CVT_S(); break; case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_D_CVT_S(); break;
case R4300i_COP1_FUNCT_CVT_W: m_RecompilerOps->COP1_D_CVT_W(); break; case R4300i_COP1_FUNCT_CVT_W: m_RecompilerOps->COP1_D_CVT_W(); break;
case R4300i_COP1_FUNCT_CVT_L: m_RecompilerOps->COP1_D_CVT_L(); break; case R4300i_COP1_FUNCT_CVT_L: m_RecompilerOps->COP1_D_CVT_L(); break;
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN: case R4300i_COP1_FUNCT_C_F:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT: case R4300i_COP1_FUNCT_C_EQ:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE: case R4300i_COP1_FUNCT_C_OLT:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE: case R4300i_COP1_FUNCT_C_OLE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT: case R4300i_COP1_FUNCT_C_ULE:
m_RecompilerOps->COP1_D_CMP(); break; 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:
m_RecompilerOps->COP1_D_CMP();
break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_COP1_W: case R4300i_COP1_W:
@ -547,7 +616,8 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_W_CVT_S(); break; case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_W_CVT_S(); break;
case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_W_CVT_D(); break; case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_W_CVT_D(); break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_COP1_L: case R4300i_COP1_L:
@ -556,11 +626,13 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_L_CVT_S(); break; case R4300i_COP1_FUNCT_CVT_S: m_RecompilerOps->COP1_L_CVT_S(); break;
case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_L_CVT_D(); break; case R4300i_COP1_FUNCT_CVT_D: m_RecompilerOps->COP1_L_CVT_D(); break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
break; break;
case R4300i_BEQL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_BEQ, false); break; case R4300i_BEQL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_BEQ, false); break;
@ -596,7 +668,8 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
case R4300i_SDC1: m_RecompilerOps->SDC1(); break; case R4300i_SDC1: m_RecompilerOps->SDC1(); break;
case R4300i_SD: m_RecompilerOps->SD(); break; case R4300i_SD: m_RecompilerOps->SD(); break;
default: default:
m_RecompilerOps->UnknownOpcode(); break; m_RecompilerOps->UnknownOpcode();
break;
} }
m_RecompilerOps->PostCompileOpcode(); m_RecompilerOps->PostCompileOpcode();
@ -829,13 +902,22 @@ CCodeSection * CCodeSection::ExistingSection(uint32_t Addr, uint32_t Test)
{ {
return this; return this;
} }
if (m_Test == Test) { return nullptr; } if (m_Test == Test)
{
return nullptr;
}
m_Test = Test; m_Test = Test;
CCodeSection * Section = m_JumpSection ? m_JumpSection->ExistingSection(Addr, Test) : nullptr; CCodeSection * Section = m_JumpSection ? m_JumpSection->ExistingSection(Addr, Test) : nullptr;
if (Section != nullptr) { return Section; } if (Section != nullptr)
{
return Section;
}
Section = m_ContinueSection ? m_ContinueSection->ExistingSection(Addr, Test) : nullptr; Section = m_ContinueSection ? m_ContinueSection->ExistingSection(Addr, Test) : nullptr;
if (Section != nullptr) { return Section; } if (Section != nullptr)
{
return Section;
}
return nullptr; return nullptr;
} }
@ -847,7 +929,10 @@ bool CCodeSection::SectionAccessible(uint32_t SectionId, uint32_t Test)
return true; return true;
} }
if (m_Test == Test) { return false; } if (m_Test == Test)
{
return false;
}
m_Test = Test; m_Test = Test;
if (m_ContinueSection && m_ContinueSection->SectionAccessible(SectionId, Test)) if (m_ContinueSection && m_ContinueSection->SectionAccessible(SectionId, Test))
@ -937,18 +1022,39 @@ void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection)
bool CCodeSection::IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test) bool CCodeSection::IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test)
{ {
if (IgnoreIfCompiled && Parent->m_CompiledLocation != nullptr) { return true; } if (IgnoreIfCompiled && Parent->m_CompiledLocation != nullptr)
if (!m_InLoop) { return false; } {
if (!Parent->m_InLoop) { return false; } return true;
if (Parent->m_ParentSection.empty()) { return false; } }
if (this == Parent) { return true; } if (!m_InLoop)
if (Parent->m_Test == Test) { return true; } {
return false;
}
if (!Parent->m_InLoop)
{
return false;
}
if (Parent->m_ParentSection.empty())
{
return false;
}
if (this == Parent)
{
return true;
}
if (Parent->m_Test == Test)
{
return true;
}
Parent->m_Test = Test; Parent->m_Test = Test;
for (SECTION_LIST::iterator iter = Parent->m_ParentSection.begin(); iter != Parent->m_ParentSection.end(); iter++) for (SECTION_LIST::iterator iter = Parent->m_ParentSection.begin(); iter != Parent->m_ParentSection.end(); iter++)
{ {
CCodeSection * ParentSection = *iter; CCodeSection * ParentSection = *iter;
if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test)) { return false; } if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test))
{
return false;
}
} }
return true; return true;
} }
@ -959,12 +1065,21 @@ bool CCodeSection::DisplaySectionInformation(uint32_t ID, uint32_t Test)
{ {
return false; return false;
} }
if (m_Test == Test) { return false; } if (m_Test == Test)
{
return false;
}
m_Test = Test; m_Test = Test;
if (m_SectionID != ID) if (m_SectionID != ID)
{ {
if (m_ContinueSection != nullptr && m_ContinueSection->DisplaySectionInformation(ID, Test)) { return true; } if (m_ContinueSection != nullptr && m_ContinueSection->DisplaySectionInformation(ID, Test))
if (m_JumpSection != nullptr && m_JumpSection->DisplaySectionInformation(ID, Test)) { return true; } {
return true;
}
if (m_JumpSection != nullptr && m_JumpSection->DisplaySectionInformation(ID, Test))
{
return true;
}
return false; return false;
} }
DisplaySectionInformation(); DisplaySectionInformation();

View File

@ -35,14 +35,14 @@ public:
uint32_t m_EndPC; uint32_t m_EndPC;
CCodeSection * m_ContinueSection; CCodeSection * m_ContinueSection;
CCodeSection * m_JumpSection; CCodeSection * m_JumpSection;
bool m_EndSection; // If this section does not link, are other sections allowed to find block to link to it? bool m_EndSection; // If this section does not link, are other sections allowed to find block to link to it?
bool m_LinkAllowed; bool m_LinkAllowed;
uint32_t m_Test; uint32_t m_Test;
uint32_t m_Test2; uint32_t m_Test2;
uint8_t * m_CompiledLocation; uint8_t * m_CompiledLocation;
bool m_InLoop; bool m_InLoop;
bool m_DelaySlot; bool m_DelaySlot;
CRecompilerOps * & m_RecompilerOps; CRecompilerOps *& m_RecompilerOps;
// Register info // Register info
CRegInfo m_RegEnter; CRegInfo m_RegEnter;
@ -53,8 +53,8 @@ public:
private: private:
CCodeSection(void); CCodeSection(void);
CCodeSection(const CCodeSection&); CCodeSection(const CCodeSection &);
CCodeSection& operator=(const CCodeSection&); CCodeSection & operator=(const CCodeSection &);
void UnlinkParent(CCodeSection * Parent, bool ContinueSection); void UnlinkParent(CCodeSection * Parent, bool ContinueSection);
void InheritConstants(); void InheritConstants();

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core\N64System\Recompiler\ExitInfo.h>
#include <Project64-core\N64System\Recompiler\CodeBlock.h> #include <Project64-core\N64System\Recompiler\CodeBlock.h>
#include <Project64-core\N64System\Recompiler\ExitInfo.h>
CExitInfo::CExitInfo(CCodeBlock & CodeBlock) : CExitInfo::CExitInfo(CCodeBlock & CodeBlock) :
ID(0), ID(0),

Some files were not shown because too many files have changed in this diff Show More