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 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,
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)
{

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 <Common/StdString.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
C7zip::C7zip(const char * FileName) :
m_FileSize(0),
m_CurrentFile(-1),
m_blockIndex(0xFFFFFFFF),
m_outBuffer(0),
m_outBufferSize(0),
m_NotfyCallback(NotfyCallbackDefault),
m_NotfyCallbackInfo(nullptr),
m_db(nullptr),
m_Opened(false)
m_FileSize(0),
m_CurrentFile(-1),
m_blockIndex(0xFFFFFFFF),
m_outBuffer(0),
m_outBufferSize(0),
m_NotfyCallback(NotfyCallbackDefault),
m_NotfyCallbackInfo(nullptr),
m_db(nullptr),
m_Opened(false)
{
memset(&m_FileName, 0, sizeof(m_FileName));
memset(&m_archiveLookStream, 0, sizeof(m_archiveLookStream));
@ -78,7 +78,6 @@ void C7zip::SetNotificationCallback(LP7ZNOTIFICATION NotfyFnc, void * CBInfo)
m_NotfyCallbackInfo = CBInfo;
}
bool C7zip::GetFile(int index, Byte * Data, size_t DataLen)
{
m_CurrentFile = -1;
@ -101,9 +100,9 @@ bool C7zip::GetFile(int index, Byte * Data, size_t DataLen)
m_NotfyCallback(Msg, m_NotfyCallbackInfo);
SRes res = SzArEx_Extract(m_db, &m_archiveLookStream.s, index,
&m_blockIndex, &m_outBuffer, &m_outBufferSize,
&offset, &outSizeProcessed,
&m_allocImp, &m_allocTempImp);
&m_blockIndex, &m_outBuffer, &m_outBufferSize,
&offset, &outSizeProcessed,
&m_allocImp, &m_allocTempImp);
if (res != SZ_OK)
{
m_CurrentFile = -1;
@ -126,7 +125,7 @@ void * C7zip::AllocAllocImp(void * /*p*/, size_t size)
//return new BYTE[size];
}
void C7zip::AllocFreeImp(void * /*p*/, void *address)
void C7zip::AllocFreeImp(void * /*p*/, void * address)
{
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;
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;
}
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;
switch (origin)

View File

@ -2,11 +2,12 @@
#include <string>
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#include "7zip/7zCrc.h"
#include "7zip/7z.h"
#include "7zip/7zCrc.h"
#include "7zip/7zFile.h"
#include "7zip/Types.h"
@ -17,18 +18,29 @@ extern "C" {
class C7zip
{
public:
C7zip(const char * FileName);
~C7zip();
typedef void (*LP7ZNOTIFICATION)(const char * Status, void * CBInfo);
inline int NumFiles(void) const { return m_db ? m_db->db.NumFiles : 0; }
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; }
inline int NumFiles(void) const
{
return m_db ? m_db->db.NumFiles : 0;
}
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;
std::wstring FileNameIndex(int index);
@ -36,8 +48,8 @@ public:
private:
C7zip(void);
C7zip(const C7zip&);
C7zip& operator=(const C7zip&);
C7zip(const C7zip &);
C7zip & operator=(const C7zip &);
CSzArEx * m_db;
CFileInStream m_archiveStream;
@ -50,19 +62,21 @@ private:
bool m_Opened;
// Used for extraction
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
size_t m_outBufferSize; // 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
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 AllocFreeImp(void *p, void *address); // Address can be 0
static void * AllocAllocImp(void * p, size_t size);
static void AllocFreeImp(void * p, void * address); // Address can be 0
static SRes SzFileReadImp(void *object, void *buffer, size_t *processedSize);
static SRes SzFileSeekImp(void *p, Int64 *pos, ESzSeek origin);
static SRes SzFileReadImp(void * object, void * buffer, size_t * processedSize);
static SRes SzFileSeekImp(void * p, Int64 * pos, ESzSeek origin);
//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;
void * m_NotfyCallbackInfo;

View File

@ -2,5 +2,5 @@
#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);

View File

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

View File

@ -168,37 +168,37 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
switch (*(TypePos + 1))
{
case 0xB6:
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value;
}
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
case 0xB7:
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value;
}
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
case 0xBE:
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(int32_t *)Reg = (int8_t)Value;
}
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(int32_t *)Reg = (int8_t)Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
case 0xBF:
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(int32_t *)Reg = (int16_t)Value;
}
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(int32_t *)Reg = (int16_t)Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
default:
if (HaveDebugger())
{
@ -211,13 +211,13 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
switch (*(TypePos + 1))
{
case 0x8B:
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value;
}
{
uint16_t Value = 0;
g_MMU->LH_NonMemory((MemAddress | 0x80000000) ^ 2, Value);
*(uint32_t *)Reg = Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
case 0x89:
g_MMU->SH_NonMemory((MemAddress | 0x80000000) ^ 2, *(uint16_t *)Reg);
*context.Eip = (uint32_t)ReadPos;
@ -247,13 +247,13 @@ bool CMipsMemoryVM::FilterX86Exception(uint32_t MemAddress, X86_CONTEXT & contex
*context.Eip = (uint32_t)ReadPos;
return true;
case 0x8A:
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value;
}
{
uint8_t Value = 0;
g_MMU->LB_NonMemory((MemAddress | 0x80000000) ^ 3, Value);
*(uint32_t *)Reg = Value;
*context.Eip = (uint32_t)ReadPos;
return true;
}
case 0x8B:
g_MMU->LW_NonMemory(MemAddress | 0x80000000, *((uint32_t *)Reg));
*context.Eip = (uint32_t)ReadPos;
@ -379,12 +379,23 @@ bool CMipsMemoryVM::FilterArmException(uint32_t MemAddress, mcontext_t & context
return false;
}
uint32_t * ArmRegisters[16] =
{
(uint32_t*)&context.arm_r0, (uint32_t*)&context.arm_r1, (uint32_t*)&context.arm_r2, (uint32_t*)&context.arm_r3,
(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,
uint32_t * ArmRegisters[16] = {
(uint32_t *)&context.arm_r0,
(uint32_t *)&context.arm_r1,
(uint32_t *)&context.arm_r2,
(uint32_t *)&context.arm_r3,
(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;
@ -569,9 +580,9 @@ bool CMipsMemoryVM::SetupSegvHandler(void)
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, "info.si_signo = %d", signal);
@ -597,15 +608,15 @@ void CMipsMemoryVM::segv_handler(int signal, siginfo_t *siginfo, void *sigcontex
}
X86_CONTEXT context;
context.Edi = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EDI];
context.Esi = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ESI];
context.Ebx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EBX];
context.Edx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EDX];
context.Ecx = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ECX];
context.Eax = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EAX];
context.Eip = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EIP];
context.Esp = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_ESP];
context.Ebp = (uint32_t*)&ucontext->uc_mcontext.gregs[REG_EBP];
context.Edi = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EDI];
context.Esi = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ESI];
context.Ebx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EBX];
context.Edx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EDX];
context.Ecx = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ECX];
context.Eax = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EAX];
context.Eip = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EIP];
context.Esp = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_ESP];
context.Ebp = (uint32_t *)&ucontext->uc_mcontext.gregs[REG_EBP];
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();
X86_CONTEXT context;
context.Edi = (uint32_t*)&lpEP->ContextRecord->Edi;
context.Esi = (uint32_t*)&lpEP->ContextRecord->Esi;
context.Ebx = (uint32_t*)&lpEP->ContextRecord->Ebx;
context.Edx = (uint32_t*)&lpEP->ContextRecord->Edx;
context.Ecx = (uint32_t*)&lpEP->ContextRecord->Ecx;
context.Eax = (uint32_t*)&lpEP->ContextRecord->Eax;
context.Eip = (uint32_t*)&lpEP->ContextRecord->Eip;
context.Esp = (uint32_t*)&lpEP->ContextRecord->Esp;
context.Ebp = (uint32_t*)&lpEP->ContextRecord->Ebp;
context.Edi = (uint32_t *)&lpEP->ContextRecord->Edi;
context.Esi = (uint32_t *)&lpEP->ContextRecord->Esi;
context.Ebx = (uint32_t *)&lpEP->ContextRecord->Ebx;
context.Edx = (uint32_t *)&lpEP->ContextRecord->Edx;
context.Ecx = (uint32_t *)&lpEP->ContextRecord->Ecx;
context.Eax = (uint32_t *)&lpEP->ContextRecord->Eax;
context.Eip = (uint32_t *)&lpEP->ContextRecord->Eip;
context.Esp = (uint32_t *)&lpEP->ContextRecord->Esp;
context.Ebp = (uint32_t *)&lpEP->ContextRecord->Ebp;
if (FilterX86Exception(MemAddress, context))
{
@ -658,7 +669,7 @@ int32_t CMipsMemoryVM::MemoryFilter(uint32_t dwExptCode, void * lpExceptionPoint
}
return EXCEPTION_EXECUTE_HANDLER;
#else
dwExptCode = dwExptCode; //unreferenced formal parameter
dwExptCode = dwExptCode; //unreferenced formal parameter
lpExceptionPointer = lpExceptionPointer; // unreferenced formal parameter
return EXCEPTION_EXECUTE_HANDLER;
#endif

View File

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

View File

@ -1,12 +1,12 @@
#pragma once
#pragma warning(disable:4786)
#include <string>
#include <map>
#pragma warning(disable : 4786)
#include <list>
#include <map>
#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;
struct LanguageFile
@ -28,11 +28,14 @@ public:
void SetLanguage(const char * LanguageName);
bool LoadCurrentStrings(void);
bool IsCurrentLang(LanguageFile & File);
bool IsLanguageLoaded(void) const { return m_LanguageLoaded; }
bool IsLanguageLoaded(void) const
{
return m_LanguageLoaded;
}
private:
CLanguage(const CLanguage&);
CLanguage& operator=(const CLanguage&);
CLanguage(const CLanguage &);
CLanguage & operator=(const CLanguage &);
static void StaticResetStrings(CLanguage * _this)
{

View File

@ -1,12 +1,13 @@
#include "stdafx.h"
#include <Common/Util.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/Notification.h>
#include <Common/Util.h>
void CN64System::StartEmulationThead()
void CN64System::StartEmulationThead()
{
WriteTrace(TraceN64System, TraceDebug, "Start");
CThread * thread = new CThread((CThread::CTHREAD_START_ROUTINE)StartEmulationThread);
thread->Start(thread);
WriteTrace(TraceN64System, TraceDebug, "Done");

View File

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

View File

@ -36,21 +36,66 @@ public:
void SetOnByDefault(bool OnByDefault);
void SetOverClock(bool OverClock, uint32_t OverClockModifier);
inline const std::string & GetName(void) const { return m_Name; }
inline const std::string & GetNameAndExtension(void) const { return m_NameAndExtension; }
inline const std::string & GetAuthor(void) const { return m_Author; }
inline const std::string & GetNote(void) const { 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); }
inline const std::string & GetName(void) const
{
return m_Name;
}
inline const std::string & GetNameAndExtension(void) const
{
return m_NameAndExtension;
}
inline const std::string & GetAuthor(void) const
{
return m_Author;
}
inline const std::string & GetNote(void) const
{
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:
CEnhancement();

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#include <Project64-core/N64System/Enhancement/EnhancementFile.h>
#pragma warning(disable:4996)
#pragma warning(disable : 4996)
CEnhancmentFile::CEnhancmentFile(const char * FileName, const char * Ident) :
m_Ident(Ident),
@ -106,7 +106,7 @@ bool CEnhancmentFile::RemoveEnhancements(const char * Section)
return true;
}
bool CEnhancmentFile::GetName(const char * Section, std::string &Name)
bool CEnhancmentFile::GetName(const char * Section, std::string & Name)
{
CGuard Guard(m_CS);
if (!m_File.IsOpen())
@ -192,8 +192,14 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
// We only care about sections
char * CurrentSection = Input;
@ -203,9 +209,15 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
CurrentSection += 3;
}
if (CurrentSection[0] != '[') { continue; }
if (CurrentSection[0] != '[')
{
continue;
}
int lineEndPos = (int)strlen(CurrentSection) - 1;
if (CurrentSection[lineEndPos] != ']') { continue; }
if (CurrentSection[lineEndPos] != ']')
{
continue;
}
// Take off the ']' from the end of the string
CurrentSection[lineEndPos] = 0;
CurrentSection += 1;
@ -236,9 +248,18 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (strlen(CleanLine(Input)) <= 1) { continue; }
if (Input[0] == '[') { break; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1)
{
continue;
}
if (Input[0] == '[')
{
break;
}
char * Pos = strchr(Input, '=');
if (Input[0] == '$')
{
@ -246,7 +267,7 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1 || strlen(CleanLine(Input)) <= 1)
if (result <= 1 || strlen(CleanLine(Input)) <= 1)
{
break;
}
@ -264,7 +285,7 @@ bool CEnhancmentFile::MoveToSection(const char * Section, bool ChangeCurrentSect
}
}
else if (Pos != nullptr)
{
{
char * Value = &Pos[1];
char * Pos1 = Pos - 1;
@ -323,7 +344,7 @@ void CEnhancmentFile::SaveCurrentSection(void)
}
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())
{
@ -352,7 +373,7 @@ void CEnhancmentFile::SaveCurrentSection(void)
if (Enhancement.CodeOptionSize() == 4)
{
Section += stdstr_f("%04X %s%s", Options[i].Value, Options[i].Name.c_str(), m_LineFeed);
}
}
else if (Enhancement.CodeOptionSize() == 2)
{
Section += stdstr_f("%02X %s%s", Options[i].Value, Options[i].Name.c_str(), m_LineFeed);
@ -379,7 +400,7 @@ void CEnhancmentFile::SaveCurrentSection(void)
m_File.Write(SectionName.get(), (int)strlen(SectionName.get()));
m_CurrentSectionFilePos = m_File.GetPosition();
m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection, m_CurrentSectionFilePos));
}
}
else
{
int NeededBufferLen = (int)Section.length();
@ -397,7 +418,10 @@ void CEnhancmentFile::SaveCurrentSection(void)
do
{
result = GetStringFromFile(Input, Data, MaxDataSize, DataSize, ReadPos);
if (result <= 1) { continue; }
if (result <= 1)
{
continue;
}
if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
{
EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);
@ -423,9 +447,12 @@ void CEnhancmentFile::SaveCurrentSection(void)
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)
{
ReadPos = 0;
@ -531,9 +558,9 @@ const char * CEnhancmentFile::CleanLine(char * Line)
// Strip any spaces or line feeds from the end of the line
for (int32_t i = (int32_t)strlen(&Line[0]) - 1; i >= 0; i--)
{
if (Line[i] != ' ' && Line[i] != '\r')
{
break;
if (Line[i] != ' ' && Line[i] != '\r')
{
break;
}
Line[i] = 0;
}
@ -542,7 +569,10 @@ const char * CEnhancmentFile::CleanLine(char * Line)
void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
{
enum { fIS_MvSize = 0x2000 };
enum
{
fIS_MvSize = 0x2000
};
unsigned char Data[fIS_MvSize + 1];
int SizeToRead, result;
@ -558,7 +588,10 @@ void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
do
{
SizeToRead = end - Pos;
if (SizeToRead > fIS_MvSize) { SizeToRead = fIS_MvSize; }
if (SizeToRead > fIS_MvSize)
{
SizeToRead = fIS_MvSize;
}
if (SizeToRead > 0)
{
m_File.Seek(SizeToRead * -1, CFileBase::current);
@ -582,7 +615,10 @@ void CEnhancmentFile::fInsertSpaces(int Pos, int NoOfSpaces)
do
{
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.Read(Data, SizeToRead);
m_File.Seek(WritePos, CFileBase::begin);

View File

@ -1,19 +1,19 @@
#pragma once
#include <Common/CriticalSection.h>
#include <Common/File.h>
#include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <Project64-core/N64System/Enhancement/EnhancementList.h>
#include <Common/File.h>
#include <Common/CriticalSection.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <map>
#include <vector>
#include <memory>
class CEnhancmentFile
{
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;
}
@ -38,17 +38,20 @@ public:
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:
CEnhancmentFile();
CEnhancmentFile(const CEnhancmentFile&);
CEnhancmentFile& operator=(const CEnhancmentFile&);
CEnhancmentFile(const CEnhancmentFile &);
CEnhancmentFile & operator=(const CEnhancmentFile &);
bool AddEnhancement(const CEnhancement & Details);
void OpenFile(void);
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);
void fInsertSpaces(int32_t Pos, int32_t NoOfSpaces);
void ClearSectionPosList(long FilePos);

View File

@ -1,12 +1,12 @@
#pragma once
#include <vector>
#include <string>
#include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <Common/Platform.h>
#include <Project64-core/N64System/Enhancement/Enhancement.h>
#include <string>
#include <vector>
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;
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <Common/CriticalSection.h>
#include <Common/Thread.h>
#include <Project64-core/N64System/Enhancement/EnhancementFile.h>
#include <Project64-core/N64System/Enhancement/EnhancementList.h>
#include <Common/Thread.h>
#include <Common/CriticalSection.h>
#include <map>
#include <string>
@ -19,7 +19,7 @@ class CEnhancements
public:
CEnhancements();
~CEnhancements();
void ApplyActive(CMipsMemoryVM & MMU, CPlugins * Plugins, bool UpdateChanges);
void ApplyGSButton(CMipsMemoryVM & MMU, bool UpdateChanges);
void UpdateCheats(const CEnhancementList & Cheats);
@ -36,17 +36,29 @@ private:
class GAMESHARK_CODE
{
public:
GAMESHARK_CODE(const GAMESHARK_CODE&);
GAMESHARK_CODE(const GAMESHARK_CODE &);
GAMESHARK_CODE(uint32_t Command, uint16_t Value, bool HasDisableValue, uint16_t DisableValue);
uint32_t Command(void) const { return m_Command; }
uint16_t Value(void) const { return m_Value; }
bool HasDisableValue(void) const { return m_HasDisableValue; }
uint16_t DisableValue(void) const { return m_DisableValue; }
uint32_t Command(void) const
{
return m_Command;
}
uint16_t Value(void) const
{
return m_Value;
}
bool HasDisableValue(void) const
{
return m_HasDisableValue;
}
uint16_t DisableValue(void) const
{
return m_DisableValue;
}
private:
GAMESHARK_CODE();
GAMESHARK_CODE& operator=(const GAMESHARK_CODE&);
GAMESHARK_CODE & operator=(const GAMESHARK_CODE &);
uint32_t m_Command;
uint16_t m_Value;
@ -86,7 +98,11 @@ private:
static uint32_t ConvertXP64Address(uint32_t Address);
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;
SectionFiles m_CheatFiles, m_EnhancementFiles;

View File

@ -1,4 +1,5 @@
#include "stdafx.h"
#include "FramePerSecond.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 (DisplayString.length() > 0) { DisplayString += " "; }
if (DisplayString.length() > 0)
{
DisplayString += " ";
}
DisplayString += stdstr_f(m_DlistFrameRate >= 0 ? "DL/s: %.1f" : "DL/s: -.--", m_DlistFrameRate);
}
g_Notify->DisplayMessage2(DisplayString.c_str());

View File

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

View File

@ -10,11 +10,11 @@ public:
static void ExecuteCPU();
static void ExecuteOps(int32_t Cycles);
static void InPermLoop();
private:
CInterpreterCPU();
CInterpreterCPU(const CInterpreterCPU&);
CInterpreterCPU& operator=(const CInterpreterCPU&);
CInterpreterCPU(const CInterpreterCPU &);
CInterpreterCPU & operator=(const CInterpreterCPU &);
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)
{
#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)
{
@ -2155,9 +2155,18 @@ __inline void Float_RoundToInteger32(int32_t * Dest, const float * Source, int R
*Dest = roundf(*Source);
}
}
else if (RoundType == FE_TOWARDZERO) { *Dest = truncf(*Source); }
else if (RoundType == FE_UPWARD) { *Dest = ceilf(*Source); }
else if (RoundType == FE_DOWNWARD) { *Dest = floorf(*Source); }
else if (RoundType == FE_TOWARDZERO)
{
*Dest = truncf(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceilf(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floorf(*Source);
}
#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)
{
#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)
{
@ -2187,9 +2196,18 @@ __inline void Float_RoundToInteger64(int64_t * Dest, const float * Source, int R
*Dest = roundf(*Source);
}
}
else if (RoundType == FE_TOWARDZERO) { *Dest = truncf(*Source); }
else if (RoundType == FE_UPWARD) { *Dest = ceilf(*Source); }
else if (RoundType == FE_DOWNWARD) { *Dest = floorf(*Source); }
else if (RoundType == FE_TOWARDZERO)
{
*Dest = truncf(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceilf(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floorf(*Source);
}
#pragma warning(pop)
}
@ -2353,7 +2371,7 @@ void R4300iOp::COP1_S_CMP()
}
condition = ((m_Opcode.funct & 4) && less) | ((m_Opcode.funct & 2) && equal) |
((m_Opcode.funct & 1) && unorded);
((m_Opcode.funct & 1) && unorded);
if (condition)
{
@ -2370,7 +2388,7 @@ void R4300iOp::COP1_S_CMP()
__inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int RoundType)
{
#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)
{
@ -2392,9 +2410,18 @@ __inline void Double_RoundToInteger32(int32_t * Dest, const double * Source, int
*Dest = round(*Source);
}
}
else if (RoundType == FE_TOWARDZERO) { *Dest = trunc(*Source); }
else if (RoundType == FE_UPWARD) { *Dest = ceil(*Source); }
else if (RoundType == FE_DOWNWARD) { *Dest = floor(*Source); }
else if (RoundType == FE_TOWARDZERO)
{
*Dest = trunc(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceil(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floor(*Source);
}
else
{
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)
{
#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)
{
@ -2428,9 +2455,18 @@ __inline void Double_RoundToInteger64(int64_t * Dest, const double * Source, int
*Dest = round(*Source);
}
}
else if (RoundType == FE_TOWARDZERO) { *Dest = trunc(*Source); }
else if (RoundType == FE_UPWARD) { *Dest = ceil(*Source); }
else if (RoundType == FE_DOWNWARD) { *Dest = floor(*Source); }
else if (RoundType == FE_TOWARDZERO)
{
*Dest = trunc(*Source);
}
else if (RoundType == FE_UPWARD)
{
*Dest = ceil(*Source);
}
else if (RoundType == FE_DOWNWARD)
{
*Dest = floor(*Source);
}
else
{
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) |
((m_Opcode.funct & 1) && unorded);
((m_Opcode.funct & 1) && unorded);
if (condition)
{

View File

@ -1,8 +1,8 @@
#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/Register.h>
#include <Project64-core/Settings/DebugSettings.h>
class R4300iOp :
public CLogging,
@ -10,7 +10,7 @@ class R4300iOp :
protected CSystemRegisters
{
public:
typedef void(*Func)();
typedef void (*Func)();
// Opcode functions
static void J();
@ -101,12 +101,12 @@ public:
static void SPECIAL_DADDU();
static void SPECIAL_DSUB();
static void SPECIAL_DSUBU();
static void SPECIAL_TGE();
static void SPECIAL_TGEU();
static void SPECIAL_TLT();
static void SPECIAL_TLTU();
static void SPECIAL_TGE();
static void SPECIAL_TGEU();
static void SPECIAL_TLT();
static void SPECIAL_TLTU();
static void SPECIAL_TEQ();
static void SPECIAL_TNE();
static void SPECIAL_TNE();
static void SPECIAL_DSLL();
static void SPECIAL_DSRL();
static void SPECIAL_DSRA();
@ -167,11 +167,11 @@ public:
static void COP1_S_NEG();
static void COP1_S_ROUND_L();
static void COP1_S_TRUNC_L();
static void COP1_S_CEIL_L();
static void COP1_S_FLOOR_L();
static void COP1_S_CEIL_L();
static void COP1_S_FLOOR_L();
static void COP1_S_ROUND_W();
static void COP1_S_TRUNC_W();
static void COP1_S_CEIL_W();
static void COP1_S_CEIL_W();
static void COP1_S_FLOOR_W();
static void COP1_S_CVT_D();
static void COP1_S_CVT_W();
@ -188,13 +188,13 @@ public:
static void COP1_D_MOV();
static void COP1_D_NEG();
static void COP1_D_ROUND_L();
static void COP1_D_TRUNC_L();
static void COP1_D_CEIL_L();
static void COP1_D_FLOOR_L();
static void COP1_D_TRUNC_L();
static void COP1_D_CEIL_L();
static void COP1_D_FLOOR_L();
static void COP1_D_ROUND_W();
static void COP1_D_TRUNC_W();
static void COP1_D_CEIL_W();
static void COP1_D_FLOOR_W();
static void COP1_D_CEIL_W();
static void COP1_D_FLOOR_W();
static void COP1_D_CVT_S();
static void COP1_D_CVT_W();
static void COP1_D_CVT_L();
@ -212,12 +212,12 @@ public:
static void ReservedInstruction();
static void UnknownOpcode();
static Func* BuildInterpreter();
static Func * BuildInterpreter();
static bool m_TestTimer;
static R4300iOpcode m_Opcode;
static bool MemoryBreakpoint();
static bool MemoryBreakpoint();
protected:
static void SPECIAL();

View File

@ -1,20 +1,22 @@
#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 \
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;\
#include "InterpreterOps32.h"
#include <Project64-core/Debugger.h>
#include <Project64-core/Logging.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/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()
@ -1261,7 +1263,10 @@ void R4300iOp32::COP1_CF()
TEST_COP1_USABLE_EXCEPTION
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;
}
_GPR[m_Opcode.rt].W[0] = (int32_t)_FPCR[m_Opcode.fs];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
#include "stdafx.h"
#include "CartridgeDomain2Address2Handler.h"
#include <Project64-core\N64System\N64System.h>
@ -91,7 +92,7 @@ bool CartridgeDomain2Address2Handler::DMARead()
}
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_INTERRUPT;
m_Reg.MI_INTR_REG |= MI_INTR_PI;

View File

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

View File

@ -1,11 +1,12 @@
#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 <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) :
DisplayControlReg(Reg.m_Display_ControlReg),
@ -143,4 +144,3 @@ bool DisplayControlRegHandler::Write32(uint32_t Address, uint32_t Value, uint32_
}
return true;
}

View File

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

View File

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

View File

@ -2,8 +2,8 @@
#include "MemoryHandler.h"
#include <Common/File.h>
#include <memory>
#include <vector>
#include <stdint.h>
#include <vector>
class CN64System;
@ -21,7 +21,10 @@ private:
ISViewerHandler(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);
void SystemReset(void);

View File

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

View File

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

View File

@ -1,14 +1,15 @@
#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 <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) :
PI_DRAM_ADDR_REG(PeripheralInterface[0]),
@ -216,7 +217,7 @@ void PeripheralInterfaceHandler::PI_DMA_READ()
}
// 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)
{
PI_RD_LEN += 1;
@ -351,7 +352,7 @@ void PeripheralInterfaceHandler::PI_DMA_WRITE()
uint32_t WritePos = PI_DRAM_ADDR_REG & 0x7FFFFE;
uint32_t ReadPos = PI_CART_ADDR_REG;
if (ReadPos >= 0x05000580 && ReadPos <= 0x050005BF)
{
// 64DD MSEQ (don't care)
@ -412,7 +413,7 @@ void PeripheralInterfaceHandler::PI_DMA_WRITE()
TransferLen += (BlockLen + 7) & ~7;
FirstBlock = false;
}
if (ReadPos >= 0x05000000 && ReadPos <= 0x050004FF)
{
// 64DD buffers read and 64DD user sector

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,9 @@
#include "stdafx.h"
#include "RomMemoryHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h>
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 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;
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
#include "MemoryHandler.h"
#include <Project64-core\Settings\DebugSettings.h>
#include <Project64-core\Logging.h>
#include <Project64-core\Settings\DebugSettings.h>
#include <stdint.h>
class CRegisters;
@ -23,14 +23,20 @@ public:
private:
RomMemoryHandler();
RomMemoryHandler(const RomMemoryHandler&);
RomMemoryHandler& operator=(const RomMemoryHandler&);
RomMemoryHandler(const RomMemoryHandler &);
RomMemoryHandler & operator=(const RomMemoryHandler &);
void SystemReset(void);
void LoadedGameState(void);
static void stSystemReset(RomMemoryHandler * _this) { _this->SystemReset(); }
static void stLoadedGameState(RomMemoryHandler * _this) { _this->LoadedGameState(); }
static void stSystemReset(RomMemoryHandler * _this)
{
_this->SystemReset();
}
static void stLoadedGameState(RomMemoryHandler * _this)
{
_this->LoadedGameState();
}
uint32_t & m_PC;
CRegisters & m_Reg;

View File

@ -1,8 +1,9 @@
#include "stdafx.h"
#include "SPRegistersHandler.h"
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Mips\MemoryVirtualMem.h>
#include <Project64-core\N64System\Mips\Register.h>
#include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\SystemGlobals.h>
SPRegistersReg::SPRegistersReg(uint32_t * SignalProcessorInterface) :
@ -32,7 +33,7 @@ SPRegistersHandler::SPRegistersHandler(CN64System & System, CMipsMemoryVM & MMU,
m_PC(Reg.m_PROGRAM_COUNTER)
{
System.RegisterCallBack(CN64SystemCB_Reset, this, (CN64System::CallBackFunction)stSystemReset);
System.RegisterCallBack(CN64SystemCB_LoadedGameState, this, (CN64System::CallBackFunction)stLoadedGameState);
System.RegisterCallBack(CN64SystemCB_LoadedGameState, this, (CN64System::CallBackFunction)stLoadedGameState);
}
bool SPRegistersHandler::Read32(uint32_t Address, uint32_t & Value)
@ -109,7 +110,7 @@ bool SPRegistersHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask
switch (Address & 0x1FFFFFFF)
{
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:
SP_RD_LEN_REG = MaskedValue;
SP_DMA_READ();
@ -119,36 +120,111 @@ bool SPRegistersHandler::Write32(uint32_t Address, uint32_t Value, uint32_t Mask
SP_DMA_WRITE();
break;
case 0x04040010:
if ((MaskedValue & SP_CLR_HALT) != 0) { 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_HALT) != 0)
{
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)
{
MI_INTR_REG &= ~MI_INTR_SP;
m_RspIntrReg &= ~MI_INTR_SP;
m_Reg.CheckInterrupts();
}
if ((MaskedValue & SP_SET_INTR) != 0) { if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); } }
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 ((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; }
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_INTR) != 0)
{
if (BreakOnUnhandledMemory())
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
}
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 ((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;
}
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())
{
MI_INTR_REG |= MI_INTR_SP;
@ -218,7 +294,10 @@ void SPRegistersHandler::SP_DMA_READ()
if ((CopyLength + ReadPos) > m_MMU.RdramSize())
{
int32_t CopyAmount = m_MMU.RdramSize() - ReadPos;
if (CopyAmount < 0) { CopyAmount = 0; }
if (CopyAmount < 0)
{
CopyAmount = 0;
}
NullLen = CopyLength - CopyAmount;
if (CopyAmount > 0)

View File

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

View File

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

View File

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

View File

@ -1,11 +1,12 @@
#include "stdafx.h"
#include "VideoInterfaceHandler.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\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\Plugin.h>
VideoInterfaceReg::VideoInterfaceReg(uint32_t * VideoInterface) :
VI_STATUS_REG(VideoInterface[0]),

View File

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

View File

@ -1,11 +1,12 @@
// Based on MAME's N64DD driver code by Happy_
#include "stdafx.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/SystemTiming.h>
#include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
#ifdef _WIN32
#include <Windows.h>
@ -41,7 +42,7 @@ void DiskCommand()
time_t ltime;
ltime = time(&ltime);
struct tm result = { 0 };
struct tm result = {0};
localtime_r(&ltime, &result);
// BCD format needed for 64DD RTC
@ -72,7 +73,8 @@ void DiskCommand()
break;
case 0x00080000:
// Unset disk changed bit
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG; break;
g_Reg->ASIC_STATUS &= ~DD_STATUS_DISK_CHNG;
break;
case 0x00090000:
// Unset reset and disk changed bit bit
g_Reg->ASIC_STATUS &= ~DD_STATUS_RST_STATE;
@ -84,16 +86,20 @@ void DiskCommand()
break;
case 0x00120000:
// 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:
// 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:
// 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:
// Disk inquiry
g_Reg->ASIC_DATA = 0x00000000; break;
g_Reg->ASIC_DATA = 0x00000000;
break;
}
if (isSeek)
@ -188,7 +194,7 @@ void DiskReset(void)
void DiskBMControl(void)
{
g_Reg->ASIC_CUR_SECTOR = g_Reg->ASIC_BM_CTL & 0x00FF0000;
if ((g_Reg->ASIC_CUR_SECTOR >> 16) == 0x00)
{
dd_start_block = 0;
@ -199,7 +205,7 @@ void DiskBMControl(void)
dd_start_block = 1;
dd_current = 0;
}
if (g_Reg->ASIC_BM_CTL & DD_BM_CTL_BLK_TRANS)
g_Reg->ASIC_BM_STATUS |= DD_BM_STATUS_BLOCK;
@ -355,7 +361,7 @@ bool DiskBMReadWrite(bool /*write*/)
uint16_t block = (uint16_t)dd_start_block;
uint16_t sector = (uint16_t)dd_current;
uint16_t sectorsize = (((g_Reg->ASIC_HOST_SECBYTE & 0x00FF0000) >> 16) + 1);
uint32_t addr = g_Disk->GetDiskAddressBlock(head, track, block, sector, sectorsize);
if (addr == 0xFFFFFFFF)

View File

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

View File

@ -5,12 +5,12 @@
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include "stdafx.h"
#include "GBCart.h"
#include <time.h>
#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;
@ -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;
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;
@ -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;
@ -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
{
gb_cart->rom_bank &= 0x60; // Keep MSB
gb_cart->rom_bank &= 0x60; // Keep MSB
gb_cart->rom_bank |= data[0] & 0x1F;
// 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;
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->rom_bank &= 0x1F; // Zero out bits 5 and 6 to keep consistency
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
}
else
{
gb_cart->rom_bank &= 0x1F;
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;
@ -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;
@ -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 diff = now - gb_cart->rtc_last_time;
if (diff > 0) {
if (diff > 0)
{
// Update the clock according to the last update time
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[1]++;
}
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[2]++;
}
diff /= 60;
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[3]++;
}
diff /= 24;
gb_cart->rtc_data[3] += (int)(diff & 0xFFFFFFFF);
if (gb_cart->rtc_data[3] > 255) {
if (gb_cart->rtc_data[3] > 511) {
if (gb_cart->rtc_data[3] > 255)
{
if (gb_cart->rtc_data[3] > 511)
{
gb_cart->rtc_data[3] %= 512;
gb_cart->rtc_data[3] |= 0x80;
}
@ -267,7 +273,7 @@ void memoryUpdateMBC3Clock(struct gb_cart* gb_cart)
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;
@ -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;
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;
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 --
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;
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
gb_cart->ram_enabled = (data[0] & 0x0F) == 0x0A;
@ -603,46 +609,45 @@ enum gbcart_extra_devices
struct parsed_cart_type
{
void(*read_gb_cart)(struct gb_cart*, uint16_t, uint8_t*);
void(*write_gb_cart)(struct gb_cart*, uint16_t, const 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 *);
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[] =
{
{ MBC(normal), GED_NONE },
{ MBC(mbc1), GED_NONE },
{ MBC(mbc1), GED_RAM },
{ MBC(mbc1), GED_RAM | GED_BATTERY },
{ MBC(mbc2), GED_NONE },
{ MBC(mbc2), GED_BATTERY },
{ MBC(normal), GED_RAM },
{ MBC(normal), GED_RAM | GED_BATTERY },
{ MBC(mmm01), GED_NONE },
{ MBC(mmm01), GED_RAM },
{ MBC(mmm01), GED_RAM | GED_BATTERY },
{ MBC(mbc3), GED_BATTERY | GED_RTC },
{ MBC(mbc3), GED_RAM | GED_BATTERY | GED_RTC },
{ MBC(mbc3), GED_NONE },
{ MBC(mbc3), GED_RAM },
{ MBC(mbc3), GED_RAM | GED_BATTERY },
{ MBC(mbc4), GED_NONE },
{ MBC(mbc4), GED_RAM },
{ MBC(mbc4), GED_RAM | GED_BATTERY },
{ MBC(mbc5), GED_NONE },
{ MBC(mbc5), GED_RAM },
{ MBC(mbc5), GED_RAM | GED_BATTERY },
{ MBC(mbc5), GED_RUMBLE },
{ MBC(mbc5), GED_RAM | GED_RUMBLE },
{ MBC(mbc5), GED_RAM | GED_BATTERY | GED_RUMBLE },
{ MBC(pocket_cam), GED_NONE },
{ MBC(bandai_tama5), GED_NONE },
{ MBC(huc3), GED_NONE },
{ MBC(huc1), GED_RAM | GED_BATTERY }
};
{
{MBC(normal), GED_NONE},
{MBC(mbc1), GED_NONE},
{MBC(mbc1), GED_RAM},
{MBC(mbc1), GED_RAM | GED_BATTERY},
{MBC(mbc2), GED_NONE},
{MBC(mbc2), GED_BATTERY},
{MBC(normal), GED_RAM},
{MBC(normal), GED_RAM | GED_BATTERY},
{MBC(mmm01), GED_NONE},
{MBC(mmm01), GED_RAM},
{MBC(mmm01), GED_RAM | GED_BATTERY},
{MBC(mbc3), GED_BATTERY | GED_RTC},
{MBC(mbc3), GED_RAM | GED_BATTERY | GED_RTC},
{MBC(mbc3), GED_NONE},
{MBC(mbc3), GED_RAM},
{MBC(mbc3), GED_RAM | GED_BATTERY},
{MBC(mbc4), GED_NONE},
{MBC(mbc4), GED_RAM},
{MBC(mbc4), GED_RAM | GED_BATTERY},
{MBC(mbc5), GED_NONE},
{MBC(mbc5), GED_RAM},
{MBC(mbc5), GED_RAM | GED_BATTERY},
{MBC(mbc5), GED_RUMBLE},
{MBC(mbc5), GED_RAM | GED_RUMBLE},
{MBC(mbc5), GED_RAM | GED_BATTERY | GED_RUMBLE},
{MBC(pocket_cam), GED_NONE},
{MBC(bandai_tama5), GED_NONE},
{MBC(huc3), GED_NONE},
{MBC(huc1), GED_RAM | GED_BATTERY}};
#undef MBC
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 0xFE: return &GB_CART_TYPES[27];
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;
size_t rom_size = 0;
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;
}
void GBCart::save_gb_cart(struct gb_cart* gb_cart)
void GBCart::save_gb_cart(struct gb_cart * gb_cart)
{
CFile ramFile;
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();
}
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)
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));
}
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);
}
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);
}

View File

@ -5,36 +5,36 @@
struct gb_cart
{
uint8_t* rom;
uint8_t* ram;
uint8_t * rom;
uint8_t * ram;
size_t rom_size;
size_t ram_size;
size_t rom_size;
size_t ram_size;
unsigned int rom_bank;
unsigned int ram_bank;
unsigned int rom_bank;
unsigned int ram_bank;
bool has_rtc;
bool ram_bank_mode;
bool ram_enabled;
bool has_rtc;
bool ram_bank_mode;
bool ram_enabled;
uint32_t rtc_latch;
int rtc_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(*write_gb_cart)(struct gb_cart* gb_cart, uint16_t address, const 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);
};
class GBCart
{
public:
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 save_gb_cart(struct gb_cart* gb_cart);
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 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 write_gb_cart(struct gb_cart* gb_cart, uint16_t address, const 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);
};

View File

@ -1,20 +1,20 @@
#include "stdafx.h"
#include <Project64-core\N64System\Mips\MemoryVirtualMem.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 <Common\MemoryManagement.h>
#include <Project64-core\Debugger.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>
uint8_t * CMipsMemoryVM::m_Reserve1 = nullptr;
uint8_t * CMipsMemoryVM::m_Reserve2 = nullptr;
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) :
CPifRam(SavesReadOnly),
@ -92,7 +92,7 @@ void CMipsMemoryVM::Reset(bool /*EraseMemory*/)
if (g_Settings->LoadDword(Rdb_TLB_VAddrStart) != 0)
{
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 End = Start + Len;
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);
CPifRam::Reset();
m_MemoryReadMap = new size_t [0x100000];
m_MemoryReadMap = new size_t[0x100000];
if (m_MemoryReadMap == nullptr)
{
WriteTrace(TraceN64System, TraceError, "Failed to allocate m_MemoryReadMap (Size: 0x%X)", 0x100000 * sizeof(size_t));
FreeMemory();
return false;
}
m_MemoryWriteMap = new size_t [0x100000];
m_MemoryWriteMap = new size_t[0x100000];
if (m_MemoryWriteMap == nullptr)
{
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;
if ((PAddr + Size) < m_AllocatedRdramSize)
{
return (uint8_t*)(m_RDRAM + PAddr);
return (uint8_t *)(m_RDRAM + PAddr);
}
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)
{
return (uint8_t*)(m_IMEM + (PAddr - 0x04001000));
return (uint8_t *)(m_IMEM + (PAddr - 0x04001000));
}
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__);
return nullptr;
}
bool CMipsMemoryVM::MemoryValue8(uint32_t VAddr, uint8_t & Value)
@ -317,7 +316,7 @@ bool CMipsMemoryVM::MemoryValue16(uint32_t VAddr, uint16_t & Value)
{
return false;
}
Value = *(uint16_t*)(ptr);
Value = *(uint16_t *)(ptr);
return true;
}
@ -328,7 +327,7 @@ bool CMipsMemoryVM::MemoryValue32(uint32_t VAddr, uint32_t & Value)
{
return false;
}
Value = *(uint32_t*)(ptr);
Value = *(uint32_t *)(ptr);
return true;
}
@ -339,8 +338,8 @@ bool CMipsMemoryVM::MemoryValue64(uint32_t VAddr, uint64_t & Value)
{
return false;
}
*((uint32_t*)(&Value) + 1) = *(uint32_t*)(ptr);
*((uint32_t*)(&Value) + 0) = *(uint32_t*)(ptr + 4);
*((uint32_t *)(&Value) + 1) = *(uint32_t *)(ptr);
*((uint32_t *)(&Value) + 0) = *(uint32_t *)(ptr + 4);
return true;
}
@ -362,7 +361,7 @@ bool CMipsMemoryVM::UpdateMemoryValue16(uint32_t VAddr, uint16_t Value)
{
return false;
}
*(uint16_t*)(ptr) = Value;
*(uint16_t *)(ptr) = Value;
return true;
}
@ -373,11 +372,11 @@ bool CMipsMemoryVM::UpdateMemoryValue32(uint32_t VAddr, uint32_t Value)
{
return false;
}
*(uint32_t*)(ptr) = Value;
*(uint32_t *)(ptr) = Value;
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)
{
@ -390,10 +389,10 @@ bool CMipsMemoryVM::LB_Memory(uint64_t VAddr, uint8_t& Value)
{
return false;
}
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t*)-1)
uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1)
{
Value = *(uint8_t*)(MemoryPtr + (VAddr32 ^ 3));
Value = *(uint8_t *)(MemoryPtr + (VAddr32 ^ 3));
return true;
}
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -423,10 +422,10 @@ bool CMipsMemoryVM::LH_Memory(uint64_t VAddr, uint16_t & Value)
{
return false;
}
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t*)-1)
uint8_t * MemoryPtr = (uint8_t *)m_MemoryReadMap[VAddr32 >> 12];
if (MemoryPtr != (uint8_t *)-1)
{
Value = *(uint16_t*)(MemoryPtr + (VAddr32 ^ 2));
Value = *(uint16_t *)(MemoryPtr + (VAddr32 ^ 2));
return true;
}
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -455,10 +454,10 @@ bool CMipsMemoryVM::LW_Memory(uint64_t VAddr, uint32_t & Value)
{
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)
{
Value = *(uint32_t*)(MemoryPtr + VAddr32);
Value = *(uint32_t *)(MemoryPtr + VAddr32);
return true;
}
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);
}
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)
{
@ -488,11 +487,11 @@ bool CMipsMemoryVM::LD_Memory(uint64_t VAddr, uint64_t& Value)
{
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)
{
*((uint32_t*)(&Value) + 1) = *(uint32_t*)(MemoryPtr + VAddr32);
*((uint32_t*)(&Value) + 0) = *(uint32_t*)(MemoryPtr + VAddr32 + 4);
*((uint32_t *)(&Value) + 1) = *(uint32_t *)(MemoryPtr + VAddr32);
*((uint32_t *)(&Value) + 0) = *(uint32_t *)(MemoryPtr + VAddr32 + 4);
return true;
}
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -516,10 +515,10 @@ bool CMipsMemoryVM::SB_Memory(uint64_t VAddr, uint32_t Value)
{
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)
{
*(uint8_t*)(MemoryPtr + (VAddr32 ^ 3)) = (uint8_t)Value;
*(uint8_t *)(MemoryPtr + (VAddr32 ^ 3)) = (uint8_t)Value;
return true;
}
if (m_TLB_WriteMap[VAddr32 >> 12] == -1)
@ -548,10 +547,10 @@ bool CMipsMemoryVM::SH_Memory(uint64_t VAddr, uint32_t Value)
{
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)
{
*(uint16_t*)(MemoryPtr + (VAddr32 ^ 2)) = (uint16_t)Value;
*(uint16_t *)(MemoryPtr + (VAddr32 ^ 2)) = (uint16_t)Value;
return true;
}
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -581,10 +580,10 @@ bool CMipsMemoryVM::SW_Memory(uint64_t VAddr, uint32_t Value)
{
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)
{
*(uint32_t*)(MemoryPtr + VAddr32) = Value;
*(uint32_t *)(MemoryPtr + VAddr32) = Value;
return true;
}
uint32_t BaseAddress = m_TLB_ReadMap[VAddr32 >> 12];
@ -615,11 +614,11 @@ bool CMipsMemoryVM::SD_Memory(uint64_t VAddr, uint64_t Value)
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)
{
*(uint32_t*)(MemoryPtr + VAddr32 + 0) = *((uint32_t*)(&Value) + 1);
*(uint32_t*)(MemoryPtr + VAddr32 + 4) = *((uint32_t*)(&Value));
*(uint32_t *)(MemoryPtr + VAddr32 + 0) = *((uint32_t *)(&Value) + 1);
*(uint32_t *)(MemoryPtr + VAddr32 + 4) = *((uint32_t *)(&Value));
return true;
}
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;
}
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)
{
@ -792,7 +791,7 @@ bool CMipsMemoryVM::SB_NonMemory(uint32_t VAddr, uint32_t Value)
{
g_Recompiler->ClearRecompCode_Phys(PAddr & ~0xFFF, 0xFFC, CRecompiler::Remove_ProtectedMem);
::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;
default:
@ -919,7 +918,7 @@ bool CMipsMemoryVM::SW_NonMemory(uint32_t VAddr, uint32_t Value)
case 0x06000000: m_CartridgeDomain1Address1Handler.Write32(PAddr, Value, 0xFFFFFFFF); break;
case 0x08000000:
case 0x0fe00000:
m_CartridgeDomain2Address2Handler.Write32(PAddr, Value, 0xFFFFFFFF);
m_CartridgeDomain2Address2Handler.Write32(PAddr, Value, 0xFFFFFFFF);
break;
case 0x13F00000: m_ISViewerHandler.Write32(PAddr, Value, 0xFFFFFFFF); break;
case 0x1FC00000: m_PifRamHandler.Write32(PAddr, Value, 0xFFFFFFFF); break;

View File

@ -1,9 +1,5 @@
#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\Mips\PifRam.h>
#include <Project64-core\N64System\SaveType\FlashRam.h>
#include <Project64-core\N64System\MemoryHandler\AudioInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address1Handler.h>
#include <Project64-core\N64System\MemoryHandler\CartridgeDomain1Address3Handler.h>
@ -17,9 +13,13 @@
#include <Project64-core\N64System\MemoryHandler\RDRAMInterfaceHandler.h>
#include <Project64-core\N64System\MemoryHandler\RDRAMRegistersHandler.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\SerialInterfaceHandler.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>
#ifdef __arm__
@ -63,14 +63,35 @@ public:
bool Initialize(bool SyncSystem);
void Reset(bool EraseMemory);
uint8_t * Rdram() const { return m_RDRAM; }
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]; }
uint8_t * Rdram() const
{
return m_RDRAM;
}
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(); }
CFlashRam & GetFlashRam() { return m_CartridgeDomain2Address2Handler.FlashRam(); }
CSram & GetSram()
{
return m_CartridgeDomain2Address2Handler.Sram();
}
CFlashRam & GetFlashRam()
{
return m_CartridgeDomain2Address2Handler.FlashRam();
}
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 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
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
void ClearMemoryWriteMap(uint32_t VAddr, uint32_t Length);
@ -116,14 +137,23 @@ public:
// Labels
const char * LabelName(uint32_t Address) const;
AudioInterfaceHandler & AudioInterface(void) { return m_AudioInterfaceHandler; }
VideoInterfaceHandler & VideoInterface(void) { return m_VideoInterfaceHandler; }
RomMemoryHandler & RomMemory(void) { return m_RomMemoryHandler; };
AudioInterfaceHandler & AudioInterface(void)
{
return m_AudioInterfaceHandler;
}
VideoInterfaceHandler & VideoInterface(void)
{
return m_VideoInterfaceHandler;
}
RomMemoryHandler & RomMemory(void)
{
return m_RomMemoryHandler;
};
private:
CMipsMemoryVM();
CMipsMemoryVM(const CMipsMemoryVM&);
CMipsMemoryVM& operator=(const CMipsMemoryVM&);
CMipsMemoryVM(const CMipsMemoryVM &);
CMipsMemoryVM & operator=(const CMipsMemoryVM &);
#if defined(__i386__) || defined(_M_IX86)
friend class CX86RecompilerOps;
@ -169,7 +199,7 @@ private:
#endif
void FreeMemory();
static uint8_t * m_Reserve1, *m_Reserve2;
static uint8_t *m_Reserve1, *m_Reserve2;
CN64System & m_System;
CRegisters & m_Reg;
AudioInterfaceHandler m_AudioInterfaceHandler;
@ -188,7 +218,7 @@ private:
SerialInterfaceHandler m_SerialInterfaceHandler;
SPRegistersHandler m_SPRegistersHandler;
VideoInterfaceHandler m_VideoInterfaceHandler;
uint8_t * m_RDRAM, *m_DMEM, *m_IMEM;
uint8_t *m_RDRAM, *m_DMEM, *m_IMEM;
uint32_t m_AllocatedRdramSize;
CN64Rom & m_Rom;

View File

@ -1,8 +1,8 @@
#include "stdafx.h"
#include "Mempak.h"
#include <stdio.h>
#include "Mempak.h"
#include <Common/path.h>
#include <stdio.h>
CMempak::CMempak()
{
@ -10,7 +10,7 @@ CMempak::CMempak()
{
m_Formatted[i] = 0;
m_SaveExists[i] = true;
}
}
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)
{
// clang-format off
static const uint8_t Initialize[] = {
0x81, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
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,
};
// clang-format on
memcpy(&m_Mempaks[Control][0], &Initialize[0], sizeof(Initialize));

View File

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

View File

@ -1,17 +1,17 @@
#include "stdafx.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/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/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>
CPifRam::CPifRam(bool SavesReadOnly) :
@ -32,14 +32,16 @@ void CPifRam::Reset()
void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int32_t length)
{
// clang-format off
static char lut0[0x10] = {
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] = {
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;
int32_t i, sgn, mag, mod;
@ -85,8 +87,11 @@ void CPifRam::PifRamRead()
break;
case 0xFD: CurPos = 0x40; break;
case 0xFE: CurPos = 0x40; break;
case 0xFF: break;
case 0xB4: case 0x56: case 0xB8: break;
case 0xFF:
case 0xB4:
case 0x56:
case 0xB8:
break;
default:
if ((m_PifRam[CurPos] & 0xC0) == 0)
{
@ -195,8 +200,11 @@ void CPifRam::PifRamWrite()
break;
case 0xFD: CurPos = 0x40; break;
case 0xFE: CurPos = 0x40; break;
case 0xFF: break;
case 0xB4: case 0x56: case 0xB8: break; // ???
case 0xFF:
case 0xB4:
case 0x56:
case 0xB8:
break;
default:
if ((m_PifRam[CurPos] & 0xC0) == 0)
{
@ -305,8 +313,8 @@ void CPifRam::SI_DMA_READ()
AsciiData[0] = '\0';
}
sprintf(Addon, "%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(HexData, Addon);
if (((count + 1) % 4) != 0)
{
@ -315,8 +323,8 @@ void CPifRam::SI_DMA_READ()
}
sprintf(Addon, "%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(AsciiData, Addon);
if (((count + 1) % 4) == 0)
@ -327,9 +335,9 @@ void CPifRam::SI_DMA_READ()
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);
}
@ -340,7 +348,7 @@ void CPifRam::SI_DMA_READ()
}
else
{
if(g_System->bDelaySI())
if (g_System->bDelaySI())
{
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false);
}
@ -378,7 +386,8 @@ void CPifRam::SI_DMA_WRITE()
{
if (RdramPos < 0)
{
m_PifRam[count] = 0; continue;
m_PifRam[count] = 0;
continue;
}
m_PifRam[count] = RDRAM[RdramPos ^ 3];
}
@ -406,8 +415,8 @@ void CPifRam::SI_DMA_WRITE()
AsciiData[0] = '\0';
}
sprintf(Addon, "%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(HexData, Addon);
if (((count + 1) % 4) != 0)
{
@ -416,8 +425,8 @@ void CPifRam::SI_DMA_WRITE()
}
sprintf(Addon, "%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
strcat(AsciiData, Addon);
if (((count + 1) % 4) == 0)
@ -474,7 +483,8 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
case PLUGIN_RUMBLE_PAK:
case PLUGIN_MEMPAK:
case PLUGIN_RAW:
Command[5] = 1; break;
Command[5] = 1;
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)
{
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
uint8_t* data = &Command[5];
uint8_t * data = &Command[5];
switch (Controllers[Control].Plugin)
{
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(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_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:
memset(&Command[5], 0, 0x20);
}
@ -560,14 +575,19 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
if (Controllers[Control].Present != PRESENT_NONE)
{
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
uint8_t* data = &Command[5];
uint8_t * data = &Command[5];
switch (Controllers[Control].Plugin)
{
case PLUGIN_MEMPAK: g_Mempak->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_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)
@ -603,7 +623,10 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{
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);
@ -615,7 +638,12 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{
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;
@ -624,7 +652,12 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
{
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;
@ -647,8 +680,8 @@ void CPifRam::LogControllerPakData(const char * Description)
AsciiData[0] = '\0';
}
sprintf(Addon, "%02X %02X %02X %02X",
PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1],
PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3]);
PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1],
PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3]);
strcat(HexData, Addon);
if (((count + 1) % 4) != 0)
{

View File

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

View File

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

View File

@ -16,16 +16,16 @@ public:
private:
R4300iInstruction(void);
R4300iInstruction(const R4300iInstruction&);
R4300iInstruction& operator=(const R4300iInstruction&);
R4300iInstruction(const R4300iInstruction &);
R4300iInstruction & operator=(const R4300iInstruction &);
static const char * FPR_Type(uint32_t COP1OpCode);
void DecodeName(void);
void DecodeSpecialName(void);
void DecodeRegImmName(void);
void DecodeCop1Name(void);
uint32_t m_Address;
R4300iOpcode m_Instruction;
char m_Name[40];

View File

@ -50,120 +50,120 @@ union R4300iOpcode
unsigned : 6;
};
struct
{
unsigned : 6;
unsigned code : 20;
unsigned : 6;
};
struct
{
unsigned : 6;
unsigned code : 20;
unsigned : 6;
};
};
#pragma warning(pop)
enum R4300iOpCodes
{
R4300i_SPECIAL = 0,
R4300i_REGIMM = 1,
R4300i_J = 2,
R4300i_SPECIAL = 0,
R4300i_REGIMM = 1,
R4300i_J = 2,
R4300i_JAL = 3,
R4300i_BEQ = 4,
R4300i_BNE = 5,
R4300i_BLEZ = 6,
R4300i_BEQ = 4,
R4300i_BNE = 5,
R4300i_BLEZ = 6,
R4300i_BGTZ = 7,
R4300i_ADDI = 8,
R4300i_ADDIU = 9,
R4300i_SLTI = 10,
R4300i_ADDI = 8,
R4300i_ADDIU = 9,
R4300i_SLTI = 10,
R4300i_SLTIU = 11,
R4300i_ANDI = 12,
R4300i_ORI = 13,
R4300i_XORI = 14,
R4300i_ANDI = 12,
R4300i_ORI = 13,
R4300i_XORI = 14,
R4300i_LUI = 15,
R4300i_CP0 = 16,
R4300i_CP1 = 17,
R4300i_BEQL = 20,
R4300i_CP0 = 16,
R4300i_CP1 = 17,
R4300i_BEQL = 20,
R4300i_BNEL = 21,
R4300i_BLEZL = 22,
R4300i_BGTZL = 23,
R4300i_DADDI = 24,
R4300i_BLEZL = 22,
R4300i_BGTZL = 23,
R4300i_DADDI = 24,
R4300i_DADDIU = 25,
R4300i_LDL = 26,
R4300i_LDR = 27,
R4300i_LDL = 26,
R4300i_LDR = 27,
R4300i_RESERVED31 = 31,
R4300i_LB = 32,
R4300i_LH = 33,
R4300i_LWL = 34,
R4300i_LW = 35,
R4300i_LBU = 36,
R4300i_LWL = 34,
R4300i_LW = 35,
R4300i_LBU = 36,
R4300i_LHU = 37,
R4300i_LWR = 38,
R4300i_LWU = 39,
R4300i_SB = 40,
R4300i_LWR = 38,
R4300i_LWU = 39,
R4300i_SB = 40,
R4300i_SH = 41,
R4300i_SWL = 42,
R4300i_SW = 43,
R4300i_SDL = 44,
R4300i_SWL = 42,
R4300i_SW = 43,
R4300i_SDL = 44,
R4300i_SDR = 45,
R4300i_SWR = 46,
R4300i_CACHE = 47,
R4300i_LL = 48,
R4300i_SWR = 46,
R4300i_CACHE = 47,
R4300i_LL = 48,
R4300i_LWC1 = 49,
R4300i_LDC1 = 53,
R4300i_LDC1 = 53,
R4300i_LD = 55,
R4300i_SC = 56,
R4300i_SC = 56,
R4300i_SWC1 = 57,
R4300i_SDC1 = 61,
R4300i_SDC2 = 62,
R4300i_SDC1 = 61,
R4300i_SDC2 = 62,
R4300i_SD = 63
};
enum R4300iSpecialOpCodes
{
R4300i_SPECIAL_SLL = 0,
R4300i_SPECIAL_SRL = 2,
R4300i_SPECIAL_SLL = 0,
R4300i_SPECIAL_SRL = 2,
R4300i_SPECIAL_SRA = 3,
R4300i_SPECIAL_SLLV = 4,
R4300i_SPECIAL_SRLV = 6,
R4300i_SPECIAL_SLLV = 4,
R4300i_SPECIAL_SRLV = 6,
R4300i_SPECIAL_SRAV = 7,
R4300i_SPECIAL_JR = 8,
R4300i_SPECIAL_JALR = 9,
R4300i_SPECIAL_JR = 8,
R4300i_SPECIAL_JALR = 9,
R4300i_SPECIAL_SYSCALL = 12,
R4300i_SPECIAL_BREAK = 13,
R4300i_SPECIAL_SYNC = 15,
R4300i_SPECIAL_SYNC = 15,
R4300i_SPECIAL_MFHI = 16,
R4300i_SPECIAL_MTHI = 17,
R4300i_SPECIAL_MTHI = 17,
R4300i_SPECIAL_MFLO = 18,
R4300i_SPECIAL_MTLO = 19,
R4300i_SPECIAL_DSLLV = 20,
R4300i_SPECIAL_DSLLV = 20,
R4300i_SPECIAL_DSRLV = 22,
R4300i_SPECIAL_DSRAV = 23,
R4300i_SPECIAL_MULT = 24,
R4300i_SPECIAL_MULTU = 25,
R4300i_SPECIAL_MULT = 24,
R4300i_SPECIAL_MULTU = 25,
R4300i_SPECIAL_DIV = 26,
R4300i_SPECIAL_DIVU = 27,
R4300i_SPECIAL_DMULT = 28,
R4300i_SPECIAL_DMULT = 28,
R4300i_SPECIAL_DMULTU = 29,
R4300i_SPECIAL_DDIV = 30,
R4300i_SPECIAL_DDIVU = 31,
R4300i_SPECIAL_ADD = 32,
R4300i_SPECIAL_ADDU = 33,
R4300i_SPECIAL_SUB = 34,
R4300i_SPECIAL_SUB = 34,
R4300i_SPECIAL_SUBU = 35,
R4300i_SPECIAL_AND = 36,
R4300i_SPECIAL_OR = 37,
R4300i_SPECIAL_OR = 37,
R4300i_SPECIAL_XOR = 38,
R4300i_SPECIAL_NOR = 39,
R4300i_SPECIAL_NOR = 39,
R4300i_SPECIAL_SLT = 42,
R4300i_SPECIAL_SLTU = 43,
R4300i_SPECIAL_DADD = 44,
R4300i_SPECIAL_DADDU = 45,
R4300i_SPECIAL_DADDU = 45,
R4300i_SPECIAL_DSUB = 46,
R4300i_SPECIAL_DSUBU = 47,
R4300i_SPECIAL_TGE = 48,
R4300i_SPECIAL_TGE = 48,
R4300i_SPECIAL_TGEU = 49,
R4300i_SPECIAL_TLT = 50,
R4300i_SPECIAL_TLTU = 51,
R4300i_SPECIAL_TLTU = 51,
R4300i_SPECIAL_TEQ = 52,
R4300i_SPECIAL_TNE = 54,
R4300i_SPECIAL_DSLL = 56,
R4300i_SPECIAL_DSLL = 56,
R4300i_SPECIAL_DSRL = 58,
R4300i_SPECIAL_DSRA = 59,
R4300i_SPECIAL_DSLL32 = 60,
@ -174,18 +174,18 @@ enum R4300iSpecialOpCodes
enum R4300iRegImmOpCodes
{
R4300i_REGIMM_BLTZ = 0,
R4300i_REGIMM_BGEZ = 1,
R4300i_REGIMM_BGEZ = 1,
R4300i_REGIMM_BLTZL = 2,
R4300i_REGIMM_BGEZL = 3,
R4300i_REGIMM_TGEI = 8,
R4300i_REGIMM_BGEZL = 3,
R4300i_REGIMM_TGEI = 8,
R4300i_REGIMM_TGEIU = 9,
R4300i_REGIMM_TLTI = 10,
R4300i_REGIMM_TLTIU = 11,
R4300i_REGIMM_TLTI = 10,
R4300i_REGIMM_TLTIU = 11,
R4300i_REGIMM_TEQI = 12,
R4300i_REGIMM_TNEI = 14,
R4300i_REGIMM_BLTZAL = 16,
R4300i_REGIMM_TNEI = 14,
R4300i_REGIMM_BLTZAL = 16,
R4300i_REGIMM_BGEZAL = 17,
R4300i_REGIMM_BLTZALL = 18,
R4300i_REGIMM_BLTZALL = 18,
R4300i_REGIMM_BGEZALL = 19,
};
@ -199,70 +199,70 @@ enum R4300iCOP0OpCodes
enum R4300iCOP0C0OpCodes
{
R4300i_COP0_CO_TLBR = 1,
R4300i_COP0_CO_TLBWI = 2,
R4300i_COP0_CO_TLBR = 1,
R4300i_COP0_CO_TLBWI = 2,
R4300i_COP0_CO_TLBWR = 6,
R4300i_COP0_CO_TLBP = 8,
R4300i_COP0_CO_TLBP = 8,
R4300i_COP0_CO_ERET = 24,
};
enum R4300iCOP1OpCodes
{
R4300i_COP1_MF = 0,
R4300i_COP1_DMF = 1,
R4300i_COP1_CF = 2,
R4300i_COP1_MF = 0,
R4300i_COP1_DMF = 1,
R4300i_COP1_CF = 2,
R4300i_COP1_MT = 4,
R4300i_COP1_DMT = 5,
R4300i_COP1_CT = 6,
R4300i_COP1_CT = 6,
R4300i_COP1_BC = 8,
R4300i_COP1_S = 16,
R4300i_COP1_D = 17,
R4300i_COP1_W = 20,
R4300i_COP1_D = 17,
R4300i_COP1_W = 20,
R4300i_COP1_L = 21,
};
enum R4300iCOP1BcOpCodes
{
R4300i_COP1_BC_BCF = 0,
R4300i_COP1_BC_BCT = 1,
R4300i_COP1_BC_BCT = 1,
R4300i_COP1_BC_BCFL = 2,
R4300i_COP1_BC_BCTL = 3,
};
enum R4300iCOP1FuntOpCodes
{
R4300i_COP1_FUNCT_ADD = 0,
R4300i_COP1_FUNCT_ADD = 0,
R4300i_COP1_FUNCT_SUB = 1,
R4300i_COP1_FUNCT_MUL = 2,
R4300i_COP1_FUNCT_DIV = 3,
R4300i_COP1_FUNCT_SQRT = 4,
R4300i_COP1_FUNCT_SQRT = 4,
R4300i_COP1_FUNCT_ABS = 5,
R4300i_COP1_FUNCT_MOV = 6,
R4300i_COP1_FUNCT_NEG = 7,
R4300i_COP1_FUNCT_ROUND_L = 8,
R4300i_COP1_FUNCT_TRUNC_L = 9,
R4300i_COP1_FUNCT_CEIL_L = 10,
R4300i_COP1_FUNCT_TRUNC_L = 9,
R4300i_COP1_FUNCT_CEIL_L = 10,
R4300i_COP1_FUNCT_FLOOR_L = 11,
R4300i_COP1_FUNCT_ROUND_W = 12,
R4300i_COP1_FUNCT_ROUND_W = 12,
R4300i_COP1_FUNCT_TRUNC_W = 13,
R4300i_COP1_FUNCT_CEIL_W = 14,
R4300i_COP1_FUNCT_FLOOR_W = 15,
R4300i_COP1_FUNCT_CVT_S = 32,
R4300i_COP1_FUNCT_CVT_S = 32,
R4300i_COP1_FUNCT_CVT_D = 33,
R4300i_COP1_FUNCT_CVT_W = 36,
R4300i_COP1_FUNCT_CVT_L = 37,
R4300i_COP1_FUNCT_C_F = 48,
R4300i_COP1_FUNCT_C_UN = 49,
R4300i_COP1_FUNCT_C_EQ = 50,
R4300i_COP1_FUNCT_C_UN = 49,
R4300i_COP1_FUNCT_C_EQ = 50,
R4300i_COP1_FUNCT_C_UEQ = 51,
R4300i_COP1_FUNCT_C_OLT = 52,
R4300i_COP1_FUNCT_C_ULT = 53,
R4300i_COP1_FUNCT_C_OLT = 52,
R4300i_COP1_FUNCT_C_ULT = 53,
R4300i_COP1_FUNCT_C_OLE = 54,
R4300i_COP1_FUNCT_C_ULE = 55,
R4300i_COP1_FUNCT_C_SF = 56,
R4300i_COP1_FUNCT_C_ULE = 55,
R4300i_COP1_FUNCT_C_SF = 56,
R4300i_COP1_FUNCT_C_NGLE = 57,
R4300i_COP1_FUNCT_C_SEQ = 58,
R4300i_COP1_FUNCT_C_NGL = 59,
R4300i_COP1_FUNCT_C_NGL = 59,
R4300i_COP1_FUNCT_C_LT = 60,
R4300i_COP1_FUNCT_C_NGE = 61,
R4300i_COP1_FUNCT_C_LE = 62,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,11 @@
#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/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) :
m_System(System),
@ -56,12 +55,12 @@ void CSystemTimer::SetTimer(TimerType Type, uint32_t Cycles, bool bRelative)
}
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
{
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();
}
@ -400,7 +399,7 @@ void CSystemTimer::LoadData(CFile & file)
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)
{
@ -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)
{
@ -465,7 +464,7 @@ bool CSystemTimer::operator == (const CSystemTimer& rSystemTimer) const
return true;
}
bool CSystemTimer::operator != (const CSystemTimer& rSystemTimer) const
bool CSystemTimer::operator!=(const CSystemTimer & rSystemTimer) const
{
return !(*this == rSystemTimer);
}

View File

@ -1,11 +1,12 @@
#pragma once
#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/N64System/Mips/Register.h>
#include <Project64-core/N64System/N64Types.h>
class AudioInterfaceHandler;
class RomMemoryHandler;
class CSystemTimer
{
@ -32,7 +33,7 @@ public:
struct TIMER_DETAILS
{
union
union
{
int64_t reserved;
bool Active;
@ -42,7 +43,7 @@ public:
CSystemTimer(CN64System & System);
void SetTimer(TimerType Type, uint32_t Cycles, bool bRelative);
uint32_t GetTimer(TimerType Type);
uint32_t GetTimer(TimerType Type);
void StopTimer(TimerType Type);
void UpdateTimers();
void TimerDone();
@ -55,21 +56,24 @@ public:
void LoadData(zipFile & 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:
CSystemTimer(void);
CSystemTimer(const CSystemTimer&);
CSystemTimer& operator=(const CSystemTimer&);
CSystemTimer(const CSystemTimer &);
CSystemTimer & operator=(const CSystemTimer &);
void SetCompareTimer();
void FixTimers();
CN64System & m_System;
TIMER_DETAILS m_TimerDetatils[MaxTimer];
int32_t m_LastUpdate;

View File

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

View File

@ -103,10 +103,10 @@ public:
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:
struct FASTTLB
@ -116,12 +116,12 @@ private:
uint32_t PHYSSTART;
uint32_t PHYSEND;
uint32_t Length;
bool VALID;
bool DIRTY;
bool GLOBAL;
bool ValidEntry;
bool Random;
bool Probed;
bool VALID;
bool DIRTY;
bool GLOBAL;
bool ValidEntry;
bool Random;
bool Probed;
};
friend class CDebugTlb; // Enable debug window to read class
@ -129,14 +129,14 @@ private:
CTLB_CB * const m_CB;
TLB_ENTRY m_tlb[32];
FASTTLB m_FastTlb[64];
FASTTLB m_FastTlb[64];
void SetupTLB_Entry(int32_t index, bool Random);
private:
CTLB();
CTLB(const CTLB&);
CTLB& operator=(const CTLB&);
CTLB(const CTLB &);
CTLB & operator=(const CTLB &);
};
#pragma warning(pop)

View File

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

View File

@ -1,27 +1,27 @@
#pragma once
#include "GBCart.h"
enum cart_access_mode
{
CART_NOT_INSERTED = 0x40,
CART_ACCESS_MODE_0 = 0x80,
CART_ACCESS_MODE_1 = 0x89
CART_NOT_INSERTED = 0x40,
CART_ACCESS_MODE_0 = 0x80,
CART_ACCESS_MODE_1 = 0x89
};
struct transferpak
{
unsigned int enabled;
unsigned int bank;
unsigned int access_mode;
unsigned int access_mode_changed;
struct gb_cart gb_cart;
unsigned int enabled;
unsigned int bank;
unsigned int access_mode;
unsigned int access_mode_changed;
struct gb_cart gb_cart;
};
class Transferpak
{
public:
static void Release();
static void Init();
static void ReadFrom(uint16_t address, uint8_t * command);
static void WriteTo(uint16_t address, uint8_t * command);
static void ReadFrom(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 "N64Disk.h"
#include "SystemGlobals.h"
#include <Common/md5.h>
#include <Common/Platform.h>
#include <Common/MemoryManagement.h>
#include <Common/Platform.h>
#include <Common/md5.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <memory>
@ -193,9 +194,18 @@ bool CN64Disk::IsValidDiskImage(uint8_t Test[0x20])
if (ipl_load_addr < 0x80000000 && ipl_load_addr >= 0x80800000) return false;
// Country code
if (*((uint32_t *)&Test[0]) == 0x16D348E8) { return true; }
else if (*((uint32_t *)&Test[0]) == 0x56EE6322) { return true; }
else if (*((uint32_t *)&Test[0]) == 0x00000000) { return true; }
if (*((uint32_t *)&Test[0]) == 0x16D348E8)
{
return true;
}
else if (*((uint32_t *)&Test[0]) == 0x56EE6322)
{
return true;
}
else if (*((uint32_t *)&Test[0]) == 0x00000000)
{
return true;
}
return false;
}
@ -284,7 +294,7 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc)
uint8_t Test[0x100];
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++)
{
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)
{
uint32_t dwToRead = DiskFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
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)
{
uint32_t dwToRead = DiskFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
if (m_DiskFile.Read(&m_DiskImage[count], dwToRead) != dwToRead)
{
@ -575,7 +591,7 @@ uint32_t CN64Disk::CalculateCrc()
uint32_t crc = 0;
for (int i = 0; i < 0x4D08; i += 4)
{
crc += *(uint32_t*)(&GetDiskAddressRom()[i]);
crc += *(uint32_t *)(&GetDiskAddressRom()[i]);
}
return crc;
}
@ -672,9 +688,9 @@ uint32_t CN64Disk::GetDiskAddressBlock(uint16_t head, uint16_t track, uint16_t b
else
{
// D64
uint16_t ROM_LBA_END = *(uint16_t*)(&GetDiskAddressSys()[0xE2]);
uint16_t RAM_LBA_START = *(uint16_t*)(&GetDiskAddressSys()[0xE0]);
uint16_t RAM_LBA_END = *(uint16_t*)(&GetDiskAddressSys()[0xE6]);
uint16_t ROM_LBA_END = *(uint16_t *)(&GetDiskAddressSys()[0xE2]);
uint16_t RAM_LBA_START = *(uint16_t *)(&GetDiskAddressSys()[0xE0]);
uint16_t RAM_LBA_END = *(uint16_t *)(&GetDiskAddressSys()[0xE6]);
uint16_t LBA = PhysToLBA(head, track, block);
if (LBA < DISKID_LBA)
{
@ -720,7 +736,7 @@ void CN64Disk::DetectSystemArea()
m_DiskRomAddress = SYSTEM_LBAS * 0x4D08;
// 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
bool isDevDisk = false;
@ -790,12 +806,14 @@ bool CN64Disk::IsSysSectorGood(uint32_t block, uint32_t sectorsize)
return false;
// Always 0xFFFFFFFF
if (*(uint32_t*)&m_DiskImage[(block * 0x4D08) + 0x18] != 0xFFFFFFFF)
if (*(uint32_t *)&m_DiskImage[(block * 0x4D08) + 0x18] != 0xFFFFFFFF)
return false;
uint8_t alt = 0xC; // Retail
uint8_t alt = 0xC; // Retail
if ((block & 2) != 0)
alt = 0xA; // Development
{
alt = 0xA; // Development
}
// Alternate tracks offsets (always the same)
for (int i = 0; i < 16; i++)
@ -810,15 +828,15 @@ bool CN64Disk::IsSysSectorGood(uint32_t block, uint32_t sectorsize)
Country CN64Disk::GetDiskCountryCode()
{
switch (*(uint32_t*)&GetDiskAddressSys()[0])
switch (*(uint32_t *)&GetDiskAddressSys()[0])
{
case DISK_COUNTRY_JPN:
return Country_Japan;
case DISK_COUNTRY_USA:
return Country_NorthAmerica;
case DISK_COUNTRY_DEV:
default:
return Country_Unknown;
case DISK_COUNTRY_JPN:
return Country_Japan;
case DISK_COUNTRY_USA:
return Country_NorthAmerica;
case DISK_COUNTRY_DEV:
default:
return Country_Unknown;
}
}
@ -834,13 +852,13 @@ void CN64Disk::InitSysDataD64()
// Expand RAM area for file format consistency
if (m_DiskType < 6)
{
*(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS;
*(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS;
*(uint16_t *)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS;
*(uint16_t *)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS;
}
else
{
*(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = 0xFFFF;
*(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = 0xFFFF;
*(uint16_t *)&GetDiskAddressSys()[0xE2 ^ 2] = 0xFFFF;
*(uint16_t *)&GetDiskAddressSys()[0xE4 ^ 2] = 0xFFFF;
}
}
@ -850,8 +868,8 @@ void CN64Disk::DeinitSysDataD64()
if (m_DiskFormat != DiskFormatD64)
return;
GetDiskAddressSys()[4^3] = 0x00;
GetDiskAddressSys()[5^3] &= 0x0F;
GetDiskAddressSys()[4 ^ 3] = 0x00;
GetDiskAddressSys()[5 ^ 3] &= 0x0F;
}
void CN64Disk::GenerateLBAToPhysTable()
@ -875,14 +893,16 @@ void CN64Disk::DetectRamAddress()
}
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)
{
for (uint32_t vzone = 0; vzone < 16; vzone++) {
if (lba < VZONE_LBA_TBL[m_DiskType][vzone]) {
for (uint32_t vzone = 0; vzone < 16; vzone++)
{
if (lba < VZONE_LBA_TBL[m_DiskType][vzone])
{
return vzone;
}
}

View File

@ -9,55 +9,104 @@ public:
CN64Disk();
~CN64Disk();
bool LoadDiskImage(const char * FileLoc);
bool SaveDiskImage();
void SwapDiskImage(const char * FileLoc);
bool LoadDiskImage(const char * FileLoc);
bool SaveDiskImage();
void SwapDiskImage(const char * FileLoc);
static bool IsValidDiskImage(uint8_t Test[0x20]);
void SaveDiskSettingID(bool temp);
void ClearDiskSettingID();
uint8_t * GetDiskAddress() { return m_DiskImage; }
uint8_t * GetDiskAddressBuffer() { return m_DiskImage + m_DiskBufAddress; }
uint8_t * GetDiskAddressSys() { return m_DiskImage + m_DiskSysAddress; }
uint8_t * GetDiskAddressID() { return m_DiskImage + m_DiskIDAddress; }
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();
void SaveDiskSettingID(bool temp);
void ClearDiskSettingID();
uint8_t * GetDiskAddress()
{
return m_DiskImage;
}
uint8_t * GetDiskAddressBuffer()
{
return m_DiskImage + m_DiskBufAddress;
}
uint8_t * GetDiskAddressSys()
{
return m_DiskImage + m_DiskSysAddress;
}
uint8_t * GetDiskAddressID()
{
return m_DiskImage + m_DiskIDAddress;
}
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:
bool AllocateDiskImage(uint32_t DiskFileSize);
bool AllocateDiskHeader();
bool AllocateAndLoadDiskImage(const char * FileLoc);
bool LoadDiskRAMImage();
void ByteSwapDisk();
void ForceByteSwapDisk();
void SetError(LanguageStringID ErrorMsg);
bool AllocateDiskImage(uint32_t DiskFileSize);
bool AllocateDiskHeader();
bool AllocateAndLoadDiskImage(const char * FileLoc);
bool LoadDiskRAMImage();
void ByteSwapDisk();
void ForceByteSwapDisk();
void SetError(LanguageStringID ErrorMsg);
void DetectSystemArea();
bool IsSysSectorGood(uint32_t block, uint32_t sectorsize);
void DetectSystemArea();
bool IsSysSectorGood(uint32_t block, uint32_t sectorsize);
Country GetDiskCountryCode();
void InitSysDataD64();
void DeinitSysDataD64();
void GenerateLBAToPhysTable();
void DetectRamAddress();
void InitSysDataD64();
void DeinitSysDataD64();
void GenerateLBAToPhysTable();
void DetectRamAddress();
uint32_t LBAToVZone(uint32_t lba);
uint32_t LBAToByte(uint32_t lba, uint32_t nlbas);
uint16_t LBAToPhys(uint32_t lba);
uint16_t PhysToLBA(uint16_t head, uint16_t track, uint16_t block);
// Constant values
enum { ReadFromRomSection = 0x400000, MameFormatSize = 0x0435B0C0, SDKFormatSize = 0x03DEC800,
DiskFormatMAME = 0x0, DiskFormatSDK = 0x1, DiskFormatD64 = 0x2 };
enum
{
ReadFromRomSection = 0x400000,
MameFormatSize = 0x0435B0C0,
SDKFormatSize = 0x03DEC800,
DiskFormatMAME = 0x0,
DiskFormatSDK = 0x1,
DiskFormatD64 = 0x2
};
// Class variables
CFile m_DiskFile;
@ -78,24 +127,24 @@ private:
uint8_t m_DiskType;
bool m_isShadowDisk;
// Disk defines
#define MAX_LBA 0x10DB
#define SIZE_LBA MAX_LBA+1
#define SYSTEM_LBAS 24
#define DISKID_LBA 14
// Disk defines
#define MAX_LBA 0x10DB
#define SIZE_LBA MAX_LBA + 1
#define SYSTEM_LBAS 24
#define DISKID_LBA 14
#define DISK_COUNTRY_JPN 0xE848D316
#define DISK_COUNTRY_USA 0x2263EE56
#define DISK_COUNTRY_DEV 0x00000000
#define DISK_COUNTRY_JPN 0xE848D316
#define DISK_COUNTRY_USA 0x2263EE56
#define DISK_COUNTRY_DEV 0x00000000
#define SECTORS_PER_BLOCK 85
#define BLOCKS_PER_TRACK 2
#define SECTORS_PER_BLOCK 85
#define BLOCKS_PER_TRACK 2
const uint32_t SECTORSIZE[16] = { 232, 216, 208, 192, 176, 160, 144, 128,
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,
158, 158, 149, 149, 149, 149, 149, 114 };
const uint32_t SECTORSIZE[16] = {232, 216, 208, 192, 176, 160, 144, 128,
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,
158, 158, 149, 149, 149, 149, 149, 114};
const uint16_t VZONE_LBA_TBL[7][16] = {
{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, 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, 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] = {
@ -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, 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, 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] = {
{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 TRACKSIZE(_zone) BLOCKSIZE(_zone) * BLOCKS_PER_TRACK
#define ZONESIZE(_zone) TRACKSIZE(_zone) * ZoneTracks[_zone]
#define VZONESIZE(_zone) TRACKSIZE(_zone) * (ZoneTracks[_zone] - 0xC)
#define VZoneToPZone(x, y) VZONE_PZONE_TBL[y][x]
#define BLOCKSIZE(_zone) SECTORSIZE[_zone] * SECTORS_PER_BLOCK
#define TRACKSIZE(_zone) BLOCKSIZE(_zone) * BLOCKS_PER_TRACK
#define ZONESIZE(_zone) TRACKSIZE(_zone) * ZoneTracks[_zone]
#define VZONESIZE(_zone) TRACKSIZE(_zone) * (ZoneTracks[_zone] - 0xC)
#define VZoneToPZone(x, y) VZONE_PZONE_TBL[y][x]
// Used for MAME format
const uint32_t MAMEStartOffset[16] =
{ 0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0,
0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200 };
{0x0, 0x5F15E0, 0xB79D00, 0x10801A0, 0x1523720, 0x1963D80, 0x1D414C0, 0x20BBCE0,
0x23196E0, 0x28A1E00, 0x2DF5DC0, 0x3299340, 0x36D99A0, 0x3AB70E0, 0x3E31900, 0x4149200};
// Used for SDK and D64 format
uint16_t LBAToPhysTable[SIZE_LBA];

View File

@ -1,11 +1,12 @@
#include "stdafx.h"
#include "N64Rom.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/MemoryManagement.h>
#include <Common/Platform.h>
#include <Common/md5.h>
#include <Project64-core/3rdParty/zip.h>
#include <memory>
#ifdef _WIN32
@ -95,7 +96,10 @@ bool CN64Rom::AllocateAndLoadN64Image(const char * FileLoc, bool LoadBootCodeOnl
for (count = 0; count < (int)RomFileSize; count += ReadFromRomSection)
{
uint32_t dwToRead = RomFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
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)
{
uint32_t dwToRead = RomFileSize - count;
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
if (dwToRead > ReadFromRomSection)
{
dwToRead = ReadFromRomSection;
}
dwRead = unzReadCurrentFile(file, &m_ROMImage[count], dwToRead);
if (dwRead == 0)
@ -267,10 +274,13 @@ CICChip CN64Rom::GetCicChipID(uint8_t * RomData, uint64_t * CRC)
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);
}
if (CRC != nullptr) { *CRC = crc; }
if (CRC != nullptr)
{
*CRC = crc;
}
switch (crc)
{
@ -289,7 +299,10 @@ CICChip CN64Rom::GetCicChipID(uint8_t * RomData, uint64_t * CRC)
//Aleck64 CIC
if (crcAleck64 == 0x000000A5F80BF620)
{
if (CRC != nullptr) { *CRC = crcAleck64; }
if (CRC != nullptr)
{
*CRC = crcAleck64;
}
return CIC_NUS_5101;
}
return CIC_UNKNOWN;
@ -343,9 +356,18 @@ void CN64Rom::CalculateRomCrc()
case CIC_NUS_6103: v0 = 0xA3886759; break;
case CIC_NUS_6105: v0 = 0xDF26F436; break;
case CIC_NUS_6106: v0 = 0x1FEA617A; break;
case CIC_NUS_DDUS: length = 0x000A0000; v0 = 0x861AE3A7; break;
case CIC_NUS_8303: length = 0x000A0000; v0 = 0x8331D4CA; break;
case CIC_NUS_8401: length = 0x000A0000; v0 = 0x0D8303E2; break;
case CIC_NUS_DDUS:
length = 0x000A0000;
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;
default:
return;
@ -353,7 +375,7 @@ void CN64Rom::CalculateRomCrc()
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;
v1 = 0;
@ -374,7 +396,8 @@ void CN64Rom::CalculateRomCrc()
v1 = a3 + v0;
a1 = v1;
if (v1 < a3) {
if (v1 < a3)
{
if (m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_8303)
{
t2 = t2 ^ t3;
@ -408,7 +431,8 @@ void CN64Rom::CalculateRomCrc()
{
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)
{
@ -444,10 +468,22 @@ CICChip CN64Rom::CicChipID()
bool CN64Rom::IsValidRomImage(uint8_t Test[4])
{
if (*((uint32_t *)&Test[0]) == 0x40123780) { return true; }
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
if (*((uint32_t *)&Test[0]) == 0x40123780)
{
return true;
}
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;
}
@ -501,7 +537,8 @@ void CN64Rom::CleanRomName(char * RomName, bool byteswap)
{
switch (RomName[count])
{
case '/': case '\\': RomName[count] = '-'; break;
case '/':
case '\\': RomName[count] = '-'; break;
case ':': RomName[count] = ';'; break;
}
}
@ -528,16 +565,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
stdstr FullPath = FileLoc;
// 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)
{
*SubFile = '\0';
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
// Allocate memory for sub name and copy selected file name to variable
// Pop up a dialog and select file
// Allocate memory for sub name and copy selected file name to variable
//}
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
uint32_t RomFileSize = (uint32_t)f->Size;
// If loading boot code then just load the first 0x1000 bytes
if (LoadBootCodeOnly) { RomFileSize = 0x1000; }
if (LoadBootCodeOnly)
{
RomFileSize = 0x1000;
}
if (!AllocateRomImage(RomFileSize))
{
@ -582,11 +622,11 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (!IsValidRomImage(m_ROMImage))
{
if (i < ZipFile.NumFiles() - 1)
{
if (i < ZipFile.NumFiles() - 1)
{
UnallocateRomImage();
continue;
}
}
SetError(MSG_FAIL_IMAGE);
WriteTrace(TraceN64System, TraceDebug, "Done (res: false)");
return false;
@ -674,7 +714,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
if (GameIdentifiers.find(m_RomIdent.c_str()) == GameIdentifiers.end())
{
char InternalName[22] = { 0 };
char InternalName[22] = {0};
memcpy(InternalName, (void *)(m_ROMImage + 0x20), 20);
CN64Rom::CleanRomName(InternalName);
@ -697,7 +737,7 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
}
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;
// 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)
{
*SubFile = '\0';
@ -732,8 +772,8 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
}
//else load first found file until dialog is implemented
//{
// Pop up a dialog and select file
// Allocate memory for sub name and copy selected file name to variable
// Pop up a dialog and select file
// Allocate memory for sub name and copy selected file name to variable
//}
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
uint32_t RomFileSize = (uint32_t)f->Size;
// If loading boot code then just load the first 0x1000 bytes
if (LoadBootCodeOnly) { RomFileSize = 0x1000; }
if (LoadBootCodeOnly)
{
RomFileSize = 0x1000;
}
if (!AllocateRomImage(RomFileSize))
{
@ -827,7 +870,7 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
if (strlen(RomName) == 0)
{
strcpy(RomName, CPath(FileLoc).GetName().c_str());
CN64Rom::CleanRomName(RomName,false);
CN64Rom::CleanRomName(RomName, false);
}
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);

View File

@ -1,8 +1,8 @@
#pragma once
#include <Project64-core/Multilanguage.h>
#include <Project64-core/N64System/N64Types.h>
#include <Project64-core/Settings/DebugSettings.h>
#include <Project64-core/Multilanguage.h>
class CN64Rom :
protected CDebugSettings
@ -18,17 +18,38 @@ public:
void SaveRomSettingID(bool temp);
void ClearRomSettingID();
CICChip CicChipID();
uint8_t * GetRomAddress() const { return m_ROMImage; }
uint32_t GetRomSize() const { 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; }
uint8_t * GetRomAddress() const
{
return m_ROMImage;
}
uint32_t GetRomSize() const
{
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();
void UnallocateRomImage();
// 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 void CleanRomName(char * RomName, bool byteswap = true);
@ -44,7 +65,10 @@ private:
static void NotificationCB(const char * Status, CN64Rom * _this);
// Constant values
enum { ReadFromRomSection = 0x400000 };
enum
{
ReadFromRomSection = 0x400000
};
// Class variables
CFile m_RomFile;

View File

@ -1,26 +1,27 @@
#include "stdafx.h"
#include "N64System.h"
#include <Common/Util.h>
#include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/SystemGlobals.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/Debugger.h>
#include <Project64-core/ExceptionHandler.h>
#include <Project64-core/Logging.h>
#include <Project64-core/Debugger.h>
#include <Common/Util.h>
#include <Project64-core/N64System/Enhancement/Enhancements.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 <time.h>
#if defined(ANDROID)
#include <utime.h>
#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) :
CSystemEvents(this, Plugins),
@ -650,27 +651,27 @@ bool CN64System::SelectAndLoadFileImageIPL(Country country, bool combo)
LanguageStringID IPLROMError;
switch (country)
{
case Country_Japan:
IPLROMPathSetting = File_DiskIPLPath;
IPLROMError = MSG_IPL_REQUIRED;
break;
case Country_NorthAmerica:
IPLROMPathSetting = File_DiskIPLUSAPath;
IPLROMError = MSG_USA_IPL_REQUIRED;
break;
case Country_Unknown:
default:
IPLROMPathSetting = File_DiskIPLTOOLPath;
IPLROMError = MSG_TOOL_IPL_REQUIRED;
if (combo && !CPath(g_Settings->LoadStringVal(File_DiskIPLTOOLPath).c_str()).Exists())
{
// Development IPL is not needed for combo ROM + disk loading
if (CPath(g_Settings->LoadStringVal(File_DiskIPLPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLPath;
else if (CPath(g_Settings->LoadStringVal(File_DiskIPLUSAPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLUSAPath;
}
break;
case Country_Japan:
IPLROMPathSetting = File_DiskIPLPath;
IPLROMError = MSG_IPL_REQUIRED;
break;
case Country_NorthAmerica:
IPLROMPathSetting = File_DiskIPLUSAPath;
IPLROMError = MSG_USA_IPL_REQUIRED;
break;
case Country_Unknown:
default:
IPLROMPathSetting = File_DiskIPLTOOLPath;
IPLROMError = MSG_TOOL_IPL_REQUIRED;
if (combo && !CPath(g_Settings->LoadStringVal(File_DiskIPLTOOLPath).c_str()).Exists())
{
// Development IPL is not needed for combo ROM + disk loading
if (CPath(g_Settings->LoadStringVal(File_DiskIPLPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLPath;
else if (CPath(g_Settings->LoadStringVal(File_DiskIPLUSAPath).c_str()).Exists())
IPLROMPathSetting = File_DiskIPLUSAPath;
}
break;
}
if (!CPath(g_Settings->LoadStringVal(IPLROMPathSetting).c_str()).Exists())
@ -822,7 +823,8 @@ void CN64System::EndEmulation(void)
void CN64System::Pause()
{
if (m_Plugins && m_Plugins->Control()->EmulationPaused) {
if (m_Plugins && m_Plugins->Control()->EmulationPaused)
{
m_Plugins->Control()->EmulationPaused();
}
if (m_EndEmulation)
@ -838,7 +840,7 @@ void CN64System::Pause()
}
m_hPauseEvent.IsTriggered(SyncEvent::INFINITE_TIMEOUT);
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)
{
g_Notify->DisplayMessage(2, MSG_CPU_RESUMED);
@ -1145,15 +1147,15 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU)
case CIC_NUS_6101:
m_Reg.m_GPR[22].DW = 0x000000000000003F;
break;
case CIC_NUS_8303: // 64DD IPL CIC
case CIC_NUS_8401: // 64DD IPL tool CIC
case CIC_NUS_5167: // 64DD conversion CIC
case CIC_NUS_8303: // 64DD IPL CIC
case CIC_NUS_8401: // 64DD IPL tool CIC
case CIC_NUS_5167: // 64DD conversion CIC
m_Reg.m_GPR[22].DW = 0x00000000000000DD;
break;
case CIC_NUS_DDUS: // 64DD US IPL CIC
case CIC_NUS_DDUS: // 64DD US IPL CIC
m_Reg.m_GPR[22].DW = 0x00000000000000DE;
break;
case CIC_NUS_5101: // Aleck64 CIC
case CIC_NUS_5101: // Aleck64 CIC
m_Reg.m_GPR[22].DW = 0x00000000000000AC;
break;
case CIC_UNKNOWN:
@ -1266,8 +1268,8 @@ void CN64System::ExecuteCPU()
switch (cpuType)
{
case CPU_Recompiler: ExecuteRecompiler(); break;
case CPU_SyncCores: ExecuteSyncCPU(); break;
default: ExecuteInterpret(); break;
case CPU_SyncCores: ExecuteSyncCPU(); break;
default: ExecuteInterpret(); break;
}
WriteTrace(TraceN64System, TraceDebug, "CPU finished executing");
CpuStopped();
@ -1307,7 +1309,7 @@ void CN64System::CpuStopped()
WriteTrace(TraceN64System, TraceDebug, "Start");
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);
}
if (m_SyncCPU)
@ -1323,10 +1325,16 @@ void CN64System::UpdateSyncCPU(CN64System * const SecondCPU, uint32_t const Cycl
// Update the number of cycles to skip
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
if (CyclesToExecute < 0) { return; }
if (CyclesToExecute < 0)
{
return;
}
SecondCPU->SetActiveSystem(true);
CInterpreterCPU::ExecuteOps(Cycles);
@ -1343,11 +1351,23 @@ void CN64System::SyncCPUPC(CN64System * const SecondCPU)
ErrorFound = true;
}
if (m_TLB != SecondCPU->m_TLB) { ErrorFound = true; }
if (m_SystemTimer != SecondCPU->m_SystemTimer) { ErrorFound = true; }
if (m_NextTimer != SecondCPU->m_NextTimer) { ErrorFound = true; }
if (m_TLB != SecondCPU->m_TLB)
{
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--)
{
@ -1364,7 +1384,8 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
g_SystemTimer->UpdateTimers();
#ifdef TEST_SP_TRACKING
if (m_CurrentSP != GPR[29].UW[0]) {
if (m_CurrentSP != GPR[29].UW[0])
{
ErrorFound = true;
}
#endif
@ -1409,15 +1430,30 @@ void CN64System::SyncCPU(CN64System * const SecondCPU)
}
}
if (m_Random.get_state() != SecondCPU->m_Random.get_state())
if (m_Random.get_state() != SecondCPU->m_Random.get_state())
{
ErrorFound = true;
ErrorFound = true;
}
if (m_TLB != SecondCPU->m_TLB)
{
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_TLB != SecondCPU->m_TLB) { 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 (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 defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__,__LINE__);
g_Notify->BreakPoint(__FILE__, __LINE__);
#else
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
}
if (m_SystemTimer != SecondCPU->m_SystemTimer) { ErrorFound = true; }
if (m_NextTimer != SecondCPU->m_NextTimer) { ErrorFound = true; }
if (m_Reg.m_RoundingModel != SecondCPU->m_Reg.m_RoundingModel) { ErrorFound = true; }
if (m_SystemTimer != SecondCPU->m_SystemTimer)
{
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++)
{
@ -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--)
{
@ -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])
{
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],
SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->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]);
}
}
}
@ -1542,8 +1590,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
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],
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]);
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]);
}
}
}
@ -1552,8 +1600,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
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],
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]);
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]);
}
}
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])
{
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++)
@ -1569,7 +1617,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
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],
(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)
@ -1616,7 +1664,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
if (bFastSP() && m_Recomp)
{
#if defined(__aarch64__) || defined(__amd64__) || defined(_M_X64)
g_Notify->BreakPoint(__FILE__,__LINE__);
g_Notify->BreakPoint(__FILE__, __LINE__);
#else
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
}
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++)
{
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++)
{
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]);
}
}
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++)
{
if (Dmem[z] != Dmem2[z])
@ -1665,27 +1713,27 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
for (count = 0; count < 32; 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],
SecondCPU->m_Reg.m_GPR[count].W[1], SecondCPU->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]);
}
Error.Log("\r\n");
for (count = 0; count < 32; 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],
SecondCPU->m_Reg.m_FPR[count].W[1], SecondCPU->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]);
}
Error.Log("\r\n");
for (count = 0; count < 32; 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");
for (count = 0; count < 32; 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.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++)
{
Error.LogF("CP0[%s],%*s0x%08X, 0x%08X\r\n", CRegName::Cop0[count],
12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
}
Error.Log("\r\n");
for (count = 0; count < 32; count++)
{
Error.LogF("FPR_Ctrl[%s],%*s0x%08X, 0x%08X\r\n", CRegName::FPR_Ctrl[count],
12 - strlen(CRegName::FPR_Ctrl[count]), "",
m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]);
12 - strlen(CRegName::FPR_Ctrl[count]), "",
m_Reg.m_FPCR[count], SecondCPU->m_Reg.m_FPCR[count]);
}
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],
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],
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],
12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
12 - strlen(CRegName::Cop0[count]), "",
m_Reg.m_CP0[count], SecondCPU->m_Reg.m_CP0[count]);
bool bHasTlb = false;
for (count = 0; count < 32; count++)
{
if (!m_TLB.TlbEntry(count).EntryDefined) { continue; }
if (!m_TLB.TlbEntry(count).EntryDefined)
{
continue;
}
if (!bHasTlb)
{
Error.Log("\r\n");
@ -1724,9 +1775,8 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
bHasTlb = true;
}
Error.LogF("TLB[%2d], %08X, %08X, %08X, %08X\r\n", count,
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
);
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);
}
Error.Log("\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_RDRAM_Interface, sizeof(uint32_t) * 8);
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.Rdram(), RdramSize);
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
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()))
{
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_RDRAM_Interface, sizeof(uint32_t) * 8);
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.Rdram(), SaveRDRAMSize);
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
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()))
{
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_RDRAM_Interface, sizeof(uint32_t) * 8);
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.Rdram(), SaveRDRAMSize);
hSaveFile.Read(m_MMU_VM.Dmem(), 0x1000);
@ -2283,7 +2333,10 @@ bool CN64System::LoadState(const char * FileName)
#ifdef TEST_SP_TRACKING
m_CurrentSP = GPR[29].UW[0];
#endif
if (bFastSP() && m_Recomp) { m_Recomp->ResetMemoryStackPos(); }
if (bFastSP() && m_Recomp)
{
m_Recomp->ResetMemoryStackPos();
}
if (g_Settings->LoadDword(Game_CpuType) == CPU_SyncCores)
{
@ -2307,7 +2360,7 @@ bool CN64System::LoadState(const char * FileName)
}
uint32_t CN64System::GetButtons(int32_t Control) const
{
{
CControl_Plugin::fnGetKeys GetKeys = m_Plugins->Control()->GetKeys;
if (!UpdateControllerOnRefresh() && GetKeys != nullptr)
{
@ -2316,7 +2369,7 @@ uint32_t CN64System::GetButtons(int32_t Control) const
GetKeys(Control, &Keys);
return Keys.Value;
}
return m_Buttons[Control];
return m_Buttons[Control];
}
void CN64System::DisplayRSPListCount()
@ -2447,10 +2500,13 @@ void CN64System::RunRSP()
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;
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
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()
{
WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen starting");
m_Plugins->Gfx()->UpdateScreen();
if (g_Debugger != nullptr && HaveDebugger())
{
g_Debugger->FrameDrawn();
}
if (g_Debugger != nullptr && HaveDebugger())
{
g_Debugger->FrameDrawn();
}
WriteTrace(TraceVideoPlugin, TraceDebug, "UpdateScreen done");
}
__except_catch()
@ -2502,18 +2561,27 @@ void CN64System::RefreshScreen()
if ((bBasicMode() || bLimitFPS()) && (!bSyncToAudio() || !FullSpeed()))
{
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_Idel); }
if (bShowCPUPer())
{
m_CPU_Usage.StartTimer(Timer_Idel);
}
uint32_t FrameRate;
if (m_Limiter.Timer_Process(&FrameRate) && bDisplayFrameRate())
{
m_FPS.DisplayViCounter(FrameRate, 0);
m_bCleanFrameBox = true;
}
if (bShowCPUPer()) { m_CPU_Usage.StopTimer(); }
if (bShowCPUPer())
{
m_CPU_Usage.StopTimer();
}
}
else if (bDisplayFrameRate())
{
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateFPS); }
if (bShowCPUPer())
{
m_CPU_Usage.StartTimer(Timer_UpdateFPS);
}
m_FPS.UpdateViCounter();
m_bCleanFrameBox = true;
}

View File

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

View File

@ -31,44 +31,70 @@ enum PauseType
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
{
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
{
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
{
SaveDisk_ShadowFile = 0, SaveDisk_RAMFile = 1,
SaveDisk_ShadowFile = 0,
SaveDisk_RAMFile = 1,
};
enum DISK_SEEK_TYPE
{
DiskSeek_Turbo = 0, DiskSeek_Slow = 1,
DiskSeek_Turbo = 0,
DiskSeek_Slow = 1,
};
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
{
SYSTEM_NTSC = 0, SYSTEM_PAL = 1, SYSTEM_MPAL = 2
SYSTEM_NTSC = 0,
SYSTEM_PAL = 1,
SYSTEM_MPAL = 2
};
enum CICChip
{
CIC_UNKNOWN = -1, CIC_NUS_6101 = 1, 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_UNKNOWN = -1,
CIC_NUS_6101 = 1,
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,
};
@ -129,27 +155,27 @@ enum PIPELINE_STAGE
union MIPS_WORD
{
int32_t W;
int32_t W;
uint32_t UW;
int16_t HW[2];
int16_t HW[2];
uint16_t UHW[2];
int8_t B[4];
uint8_t UB[4];
int8_t B[4];
uint8_t UB[4];
float F;
float F;
};
union MIPS_DWORD
{
int64_t DW;
int64_t DW;
uint64_t UDW;
int32_t W[2];
int32_t W[2];
uint32_t UW[2];
int16_t HW[4];
int16_t HW[4];
uint16_t UHW[4];
int8_t B[8];
uint8_t UB[8];
int8_t B[8];
uint8_t UB[8];
double D;
float F[2];
double D;
float F[2];
};

View File

@ -1,14 +1,18 @@
#include "stdafx.h"
#include <stdio.h>
#include <Project64-core/N64System/Profiling.h>
#include <Common/Log.h>
#include <Project64-core/N64System/Profiling.h>
enum { MAX_FRAMES = 13 };
enum
{
MAX_FRAMES = 13
};
CProfiling::CProfiling() :
m_CurrentDisplayCount(MAX_FRAMES),
m_CurrentTimerType(Timer_None)
m_CurrentDisplayCount(MAX_FRAMES),
m_CurrentTimerType(Timer_None)
{
memset(m_Timers, 0, sizeof(m_Timers));
}
@ -42,7 +46,10 @@ PROFILE_TIMERS CProfiling::StartTimer(PROFILE_TIMERS TimerType)
PROFILE_TIMERS CProfiling::StopTimer()
{
if (m_CurrentTimerType == Timer_None) { return m_CurrentTimerType; }
if (m_CurrentTimerType == Timer_None)
{
return m_CurrentTimerType;
}
HighResTimeStamp EndTime;
EndTime.SetToNow();
uint64_t TimeTaken = EndTime.GetMicroSeconds() - m_StartTime.GetMicroSeconds();
@ -71,7 +78,8 @@ void CProfiling::ShowCPU_Usage()
m_CurrentDisplayCount = MAX_FRAMES;
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();
if (PreviousType != Timer_None)

View File

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

View File

@ -249,7 +249,7 @@ void CAarch64RecompilerOps::SC()
g_Notify->BreakPoint(__FILE__, __LINE__);
}
void CAarch64RecompilerOps::SWC1()
void CAarch64RecompilerOps::SWC1()
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}

View File

@ -1,11 +1,11 @@
#pragma once
#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/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 CCodeBlock;
@ -13,7 +13,7 @@ class CCodeSection;
class CAarch64Ops;
struct CJumpInfo;
class CAarch64RecompilerOps
class CAarch64RecompilerOps
{
public:
CAarch64RecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock);
@ -213,18 +213,21 @@ public:
const R4300iOpcode & GetOpcode(void) const;
void PreCompileOpcode(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 CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet);
void CompileExecuteBP(void);
void CompileExecuteDelaySlotBP(void);
CAarch64Ops & Assembler() { return m_Assembler; }
CAarch64Ops & Assembler()
{
return m_Assembler;
}
private:
CAarch64RecompilerOps(const CAarch64RecompilerOps&);
CAarch64RecompilerOps& operator=(const CAarch64RecompilerOps&);
CAarch64RecompilerOps(const CAarch64RecompilerOps &);
CAarch64RecompilerOps & operator=(const CAarch64RecompilerOps &);
CAarch64RegInfo m_RegWorkingSet;
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__);
}
@ -16,7 +16,7 @@ CAarch64RegInfo::~CAarch64RegInfo()
{
}
CAarch64RegInfo& CAarch64RegInfo::operator=(const CAarch64RegInfo & right)
CAarch64RegInfo & CAarch64RegInfo::operator=(const CAarch64RegInfo & right)
{
CRegBase::operator=(right);
g_Notify->BreakPoint(__FILE__, __LINE__);

View File

@ -10,13 +10,13 @@ class CAarch64RegInfo :
{
public:
CAarch64RegInfo(CCodeBlock & CodeBlock, CAarch64Ops & Assembler);
CAarch64RegInfo(const CAarch64RegInfo&);
CAarch64RegInfo(const 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

View File

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

View File

@ -1,12 +1,12 @@
#include "stdafx.h"
#if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/SystemGlobals.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/ArmOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRegInfo.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/SystemGlobals.h>
CArmOps::CArmOps(CCodeBlock & CodeBlock, CArmRegInfo & RegWorkingSet) :
m_CodeBlock(CodeBlock),
@ -42,7 +42,7 @@ void CArmOps::AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
if (DestReg <= 7 && SourceReg1 <= 7 && SourceReg2 <= 7)
{
CodeLog(" add\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg.rt = DestReg;
op.Reg.rn = SourceReg1;
op.Reg.rm = SourceReg2;
@ -52,7 +52,7 @@ void CArmOps::AddArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
else
{
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.s = 0;
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);
uint16_t CompressedConst = ThumbCompressConst(Const);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm8_3_1.rn = SourceReg;
op.imm8_3_1.s = 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__);
@ -135,7 +135,7 @@ void CArmOps::AddConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Const)
else if ((Const & 0xFFFFFFF8) == 0 && DestReg <= 7 && SourceReg <= 7)
{
CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm3.rd = DestReg;
op.Imm3.rn = SourceReg;
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)
{
CodeLog(" adds\t%s, %s, #%d", ArmRegName(DestReg), ArmRegName(SourceReg), Const);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm8.imm8 = Const;
op.Imm8.rdn = DestReg;
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)
{
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.rdn = DestReg;
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);
uint16_t CompressedConst = ThumbCompressConst(Const);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm8_3_1.rn = SourceReg;
op.imm8_3_1.s = 0;
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)
{
CodeLog(" ands\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg2.rn = DestReg;
op.Reg2.rm = SourceReg2;
op.Reg2.opcode = 0x100;
@ -207,7 +207,7 @@ void CArmOps::AndArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
else
{
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.s = 0;
op.imm5.opcode = 0x750;
@ -245,7 +245,7 @@ void CArmOps::BranchLabel8(ArmCompareType CompareType, const char * Label)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
if (CompareType == ArmBranch_Always)
{
op.BranchImm.imm = 0;
@ -265,7 +265,7 @@ void CArmOps::BranchLabel20(ArmCompareType CompareType, const char * Label)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" b%s\t%s", ArmCompareSuffix(CompareType), Label);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.Branch20.imm6 = 0;
op.Branch20.cond = CompareType == ArmBranch_Always ? 0 : CompareType;
op.Branch20.S = 0;
@ -285,7 +285,7 @@ void CArmOps::CallFunction(void * Function, const char * FunctionName)
ArmReg reg = Arm_R4;
MoveConstToArmReg(reg, (uint32_t)Function, FunctionName);
int32_t Offset = (int32_t)Function - (int32_t)*g_RecompPos;
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Branch.reserved = 0;
op.Branch.rm = reg;
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)
{
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.rdn = Reg;
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());
uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm8_3_1.rn = 0xF;
op.imm8_3_1.s = 0;
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());
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm16.opcode = ArmMOV_IMM16;
op.imm16.i = ((value >> 11) & 0x1);
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());
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm16.opcode = ArmMOV_IMM16;
op.imm16.i = ((Const >> 11) & 0x1);
op.imm16.opcode2 = ArmMOVT_IMM16;
@ -397,7 +397,7 @@ void CArmOps::CompareArmRegToConst(ArmReg Reg, uint32_t value)
if (Reg <= 0x7 && (value & 0xFFFFFF00) == 0)
{
CodeLog(" cmp\t%s, #%d\t; 0x%X", ArmRegName(Reg), value, value);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm8.imm8 = value;
op.Imm8.rdn = Reg;
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);
uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm8_3_1.rn = Reg;
op.imm8_3_1.s = 1;
op.imm8_3_1.opcode = 0xD;
@ -436,7 +436,7 @@ void CArmOps::CompareArmRegToArmReg(ArmReg Reg1, ArmReg Reg2)
if (Reg1 <= 0x7 && Reg2 <= 0x7)
{
CodeLog(" cmp\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg2.rn = Reg1;
op.Reg2.rm = Reg2;
op.Reg2.opcode = 0x10A;
@ -445,7 +445,7 @@ void CArmOps::CompareArmRegToArmReg(ArmReg Reg1, ArmReg Reg2)
else
{
CodeLog(" cmp.w\t%s, %s", ArmRegName(Reg1), ArmRegName(Reg2));
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm5.rn = Reg1;
op.imm5.s = 1;
op.imm5.opcode = 0x75D;
@ -480,7 +480,7 @@ void CArmOps::IfBlock(ArmItMask mask, ArmCompareType CompareType)
g_Notify->BreakPoint(__FILE__, __LINE__);
}
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.It.mask = computed_mask;
op.It.firstcond = CompareType;
op.It.opcode = 0xBF;
@ -500,7 +500,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, u
return;
}
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.rn = RegPointer;
op.imm12.imm = offset;
@ -510,7 +510,7 @@ void CArmOps::LoadArmRegPointerByteToArmReg(ArmReg DestReg, ArmReg RegPointer, u
else
{
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.rn = RegPointer;
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)
{
CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.uint16.rn = RegPointer;
op.uint16.opcode = 0xF81;
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)
{
CodeLog(" ldrb\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg.rm = RegPointer2;
op.Reg.rt = DestReg;
op.Reg.rn = RegPointer;
@ -564,7 +564,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, uint8
return;
}
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.rn = RegPointer;
op.imm12.imm = Offset;
@ -574,7 +574,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, uint8
else
{
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.rn = RegPointer;
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)
{
CodeLog(" ldr\t%s, [%s,%s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg.rm = RegPointer2;
op.Reg.rt = DestReg;
op.Reg.rn = RegPointer;
@ -606,7 +606,7 @@ void CArmOps::LoadArmRegPointerToArmReg(ArmReg DestReg, ArmReg RegPointer, ArmRe
else
{
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.imm = shift;
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));
}
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.RnVdImm8.Rn = RegPointer;
op.RnVdImm8.op3 = 1;
op.RnVdImm8.D = Reg & 1;
@ -654,7 +654,7 @@ void CArmOps::LoadFloatingPointControlReg(ArmReg DestReg)
PreOpCheck(DestReg, false, __FILE__, __LINE__);
CodeLog(" vmrs\t%s, fpscr", ArmRegName(DestReg));
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.fpscr.opcode2 = 0xA10;
op.fpscr.rt = DestReg;
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());
uint16_t CompressedValue = ThumbCompressConst(value);
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm8_3_1.rn = 0xF;
op.imm8_3_1.s = 0;
op.imm8_3_1.opcode = 0x2;
@ -740,7 +740,7 @@ void CArmOps::OrArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg SourceR
return;
}
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.s = 0;
op.imm5.opcode = 0x752;
@ -768,7 +768,7 @@ void CArmOps::OrConstToArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t value)
{
uint16_t CompressedValue = ThumbCompressConst(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.s = 0;
op.imm8_3_1.opcode = 0x2;
@ -816,7 +816,7 @@ void CArmOps::MulF32(ArmFpuSingle DestReg, ArmFpuSingle SourceReg1, ArmFpuSingle
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
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.op1 = 0x2;
op.VnVmVd.d = DestReg & 1;
@ -857,8 +857,14 @@ void CArmOps::PushArmReg(uint16_t Registers)
{
return;
}
if ((Registers & ArmPushPop_SP) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); }
if ((Registers & ArmPushPop_PC) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); }
if ((Registers & ArmPushPop_SP) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_PC) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_LR) == 0)
{
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());
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.PushPop.register_list = Registers;
op.PushPop.opcode = 0xE92D;
AddCode32(op.Hex);
@ -890,7 +896,7 @@ void CArmOps::PushArmReg(uint16_t Registers)
bool lr = (Registers & ArmPushPop_LR) != 0;
Registers &= Registers & ~ArmPushPop_LR;
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Push.register_list = (uint8_t)Registers;
op.Push.m = lr ? 1 : 0;
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);
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_SP) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); }
if ((Registers & ArmPushPop_LR) != 0) { g_Notify->BreakPoint(__FILE__, __LINE__); }
if ((Registers & ArmPushPop_SP) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
if ((Registers & ArmPushPop_LR) != 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
m_PopRegisters = Registers;
@ -949,7 +961,7 @@ void CArmOps::FlushPopArmReg(void)
{
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.opcode = 0xE8BD;
AddCode32(op.Hex);
@ -960,7 +972,7 @@ void CArmOps::FlushPopArmReg(void)
bool pc = (m_PopRegisters & ArmPushPop_PC) != 0;
m_PopRegisters &= ~ArmPushPop_PC;
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Pop.register_list = (uint8_t)m_PopRegisters;
op.Pop.p = pc ? 1 : 0;
op.Pop.opcode = ArmPOP;
@ -973,11 +985,10 @@ void CArmOps::FlushPopArmReg(void)
uint32_t CArmOps::PushPopRegisterSize(uint16_t Registers)
{
static uint32_t RegisterList[] =
{
ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, ArmPushPop_R3, ArmPushPop_R4,
ArmPushPop_R5, ArmPushPop_R6, ArmPushPop_R7, ArmPushPop_R8, ArmPushPop_R9,
ArmPushPop_R10, ArmPushPop_R11, ArmPushPop_R12, ArmPushPop_LR, ArmPushPop_PC
};
{
ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, ArmPushPop_R3, ArmPushPop_R4,
ArmPushPop_R5, ArmPushPop_R6, ArmPushPop_R7, ArmPushPop_R8, ArmPushPop_R9,
ArmPushPop_R10, ArmPushPop_R11, ArmPushPop_R12, ArmPushPop_LR, ArmPushPop_PC};
uint32_t size = 0;
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)
{
static uint32_t PushPopRegisterList[] =
{
ArmPushPop_R0, ArmPushPop_R1, ArmPushPop_R2, 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 uint32_t PushPopRegisterList[] = {
ArmPushPop_R0,
ArmPushPop_R1,
ArmPushPop_R2,
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[] =
{
Arm_R0, Arm_R1, Arm_R2, Arm_R3, Arm_R4,
Arm_R5, Arm_R6, Arm_R7, Arm_R8, Arm_R9,
Arm_R10, Arm_R11, Arm_R12, ArmRegLR, ArmRegPC,
static ArmReg RegisterList[] = {
Arm_R0,
Arm_R1,
Arm_R2,
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;
@ -1027,7 +1060,7 @@ void CArmOps::ShiftRightSignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t shi
else if (DestReg > 0x7 || SourceReg > 0x7)
{
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.s = 0;
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);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg;
op.Imm5.imm5 = shift;
@ -1064,7 +1097,7 @@ void CArmOps::ShiftRightUnsignImmed(ArmReg DestReg, ArmReg SourceReg, uint32_t s
if (DestReg > 0x7 || SourceReg > 0x7)
{
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.s = 0;
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);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg;
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);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm5.rt = DestReg;
op.Imm5.rn = SourceReg;
op.Imm5.imm5 = shift;
@ -1114,7 +1147,7 @@ void CArmOps::SignExtendByte(ArmReg Reg)
if (Reg > 0x7)
{
CodeLog(" sxtb.w\t%s, %s", ArmRegName(Reg), ArmRegName(Reg));
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.rotate.opcode = 0xFA4F;
op.rotate.rm = Reg;
op.rotate.rotate = 0;
@ -1126,7 +1159,7 @@ void CArmOps::SignExtendByte(ArmReg Reg)
else
{
CodeLog(" sxtb\t%s, %s", ArmRegName(Reg), ArmRegName(Reg));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg2.rn = Reg;
op.Reg2.rm = Reg;
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 ((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 : "");
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.imm12.rt = DestReg;
op.imm12.rn = RegPointer;
op.imm12.imm = Offset;
@ -1153,7 +1190,7 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, uint
else
{
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.rn = RegPointer;
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)
{
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.imm = shift;
op.imm2.Opcode2 = 0;
@ -1182,7 +1219,7 @@ void CArmOps::StoreArmRegToArmRegPointer(ArmReg DestReg, ArmReg RegPointer, ArmR
else
{
CodeLog(" str\t%s, [%s, %s]", ArmRegName(DestReg), ArmRegName(RegPointer), ArmRegName(RegPointer2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg.rt = DestReg;
op.Reg.rn = RegPointer;
op.Reg.rm = RegPointer2;
@ -1196,7 +1233,7 @@ void CArmOps::StoreFloatingPointControlReg(ArmReg SourceReg)
PreOpCheck(Arm_Unknown, false, __FILE__, __LINE__);
CodeLog(" vmsr\tfpscr, %s", ArmRegName(SourceReg));
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.fpscr.opcode2 = 0xA10;
op.fpscr.rt = SourceReg;
op.fpscr.opcode = 0xEEE1;
@ -1215,7 +1252,7 @@ void CArmOps::StoreFloatRegToArmRegPointer(ArmFpuSingle Reg, ArmReg RegPointer,
{
CodeLog(" vstr\t%s, [%s]", ArmFpuSingleName(Reg), ArmRegName(RegPointer));
}
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.RnVdImm8.Rn = RegPointer;
op.RnVdImm8.op3 = 0;
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)
{
CodeLog(" subs\t%s,%s,%s", ArmRegName(DestReg), ArmRegName(SourceReg1), ArmRegName(SourceReg2));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg.rt = DestReg;
op.Reg.rn = SourceReg1;
op.Reg.rm = SourceReg2;
@ -1245,7 +1282,7 @@ void CArmOps::SubArmRegFromArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Sour
else
{
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.s = 0;
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)
{
CodeLog(" subs\t%s, #0x%X", ArmRegName(DestReg), Const);
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Imm8.imm8 = (uint8_t)Const;
op.Imm8.rdn = DestReg;
op.Imm8.opcode = 0x7;
@ -1276,7 +1313,7 @@ void CArmOps::SubConstFromArmReg(ArmReg DestReg, ArmReg SourceReg, uint32_t Cons
else if ((Const & (~0x7FF)) == 0)
{
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.s = 0;
op.RnRdImm12.opcode = 0x15;
@ -1340,7 +1377,7 @@ void CArmOps::XorArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg)
if (SourceReg <= 7 && DestReg <= 7)
{
CodeLog(" eors\t%s, %s", ArmRegName(DestReg), ArmRegName(SourceReg));
ArmThumbOpcode op = { 0 };
ArmThumbOpcode op = {0};
op.Reg2.rn = DestReg;
op.Reg2.rm = SourceReg;
op.Reg2.opcode = 0x101;
@ -1357,7 +1394,7 @@ void CArmOps::XorArmRegToArmReg(ArmReg DestReg, ArmReg SourceReg1, ArmReg Source
PreOpCheck(DestReg, false, __FILE__, __LINE__);
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.s = 0;
op.imm5.opcode = 0x754;
@ -1383,7 +1420,7 @@ void CArmOps::XorConstToArmReg(ArmReg DestReg, uint32_t value)
{
uint16_t CompressedValue = ThumbCompressConst(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.s = 0;
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);
g_Notify->BreakPoint(__FILE__, __LINE__);
}
Arm32Opcode op = { 0 };
Arm32Opcode op = {0};
op.Hex = *Loc;
if (op.Branch20.val12 == 0)
{
@ -1615,12 +1652,30 @@ bool CArmOps::ArmCompareInverse(ArmCompareType CompareType)
CArmOps::ArmCompareType CArmOps::ArmCompareInverseType(ArmCompareType CompareType)
{
if (CompareType == ArmBranch_Equal) { return ArmBranch_Notequal; }
if (CompareType == ArmBranch_Notequal) { 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; }
if (CompareType == ArmBranch_Equal)
{
return ArmBranch_Notequal;
}
if (CompareType == ArmBranch_Notequal)
{
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__);
return ArmBranch_Equal;
}

View File

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

View File

@ -1,17 +1,17 @@
#pragma once
#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/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/RecompilerSettings.h>
#include <Project64-core/Settings/GameSettings.h>
class CCodeBlock;
class CCodeSection;
@ -224,8 +224,8 @@ public:
const R4300iOpcode & GetOpcode(void) const;
void PreCompileOpcode(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, CArmOps::ArmCompareType CompareType);
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 CompileReadTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg);
void CompileWriteTLBMiss(CArmOps::ArmReg AddressReg, CArmOps::ArmReg LookUpReg);
@ -235,43 +235,133 @@ public:
void CompileExecuteBP(void);
void CompileExecuteDelaySlotBP(void);
CArmOps & Assembler() { return m_Assembler; }
CArmOps & Assembler()
{
return m_Assembler;
}
// Helper functions
typedef CRegInfo::REG_STATE REG_STATE;
REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); }
uint64_t GetMipsReg(int32_t Reg) { return m_RegWorkingSet.GetMipsReg(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); }
REG_STATE GetMipsRegState(int32_t Reg)
{
return m_RegWorkingSet.GetMipsRegState(Reg);
}
uint64_t GetMipsReg(int32_t Reg)
{
return m_RegWorkingSet.GetMipsReg(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 IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); }
bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); }
bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(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); }
bool IsKnown(int32_t Reg)
{
return m_RegWorkingSet.IsKnown(Reg);
}
bool IsUnknown(int32_t Reg)
{
return m_RegWorkingSet.IsUnknown(Reg);
}
bool IsMapped(int32_t Reg)
{
return m_RegWorkingSet.IsMapped(Reg);
}
bool IsConst(int32_t Reg)
{
return m_RegWorkingSet.IsConst(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 FixRoundModel(CRegInfo::FPU_ROUND RoundMethod) { m_RegWorkingSet.FixRoundModel(RoundMethod); }
void ResetRegProtection()
{
m_RegWorkingSet.ResetRegProtection();
}
void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod)
{
m_RegWorkingSet.FixRoundModel(RoundMethod);
}
void ProtectGPR(uint32_t 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 ProtectGPR(uint32_t 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_Const(uint32_t Value, uint32_t VAddr);
@ -279,7 +369,7 @@ public:
void LW(bool ResultSigned, bool bRecordLLBit);
void LB_KnownAddress(CArmOps::ArmReg Reg, uint32_t VAddr, bool SignExtend);
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);
EXIT_LIST m_ExitInfo;

View File

@ -1,10 +1,10 @@
#include "stdafx.h"
#if defined(__arm__) || defined(_M_ARM)
#include <Project64-core/N64System/SystemGlobals.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/Recompiler.h>
#include <Project64-core/N64System/SystemGlobals.h>
CArmRegInfo::CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler) :
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_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);
@ -57,7 +57,7 @@ CArmRegInfo& CArmRegInfo::operator=(const CArmRegInfo& right)
return *this;
}
bool CArmRegInfo::operator==(const CArmRegInfo& right) const
bool CArmRegInfo::operator==(const CArmRegInfo & right) const
{
if (!CRegBase::operator==(right))
{
@ -66,16 +66,34 @@ bool CArmRegInfo::operator==(const CArmRegInfo& right) const
for (int32_t count = 0; count < 32; count++)
{
if (m_RegMapHi[count] != right.m_RegMapHi[count]) { return false; }
if (m_RegMapLo[count] != right.m_RegMapLo[count]) { return false; }
if (m_RegMapHi[count] != right.m_RegMapHi[count])
{
return false;
}
if (m_RegMapLo[count] != right.m_RegMapLo[count])
{
return false;
}
}
for (int32_t count = 0; count < 16; count++)
{
if (m_ArmReg_MapOrder[count] != right.m_ArmReg_MapOrder[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; }
if (m_ArmReg_MapOrder[count] != right.m_ArmReg_MapOrder[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;
}
@ -95,18 +113,36 @@ bool CArmRegInfo::ShouldPushPopReg(CArmOps::ArmReg Reg)
void CArmRegInfo::BeforeCallDirect(void)
{
static uint32_t PushPopRegisterList[] =
{
CArmOps::ArmPushPop_R0, CArmOps::ArmPushPop_R1, CArmOps::ArmPushPop_R2, 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 uint32_t PushPopRegisterList[] = {
CArmOps::ArmPushPop_R0,
CArmOps::ArmPushPop_R1,
CArmOps::ArmPushPop_R2,
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[] =
{
CArmOps::Arm_R0, CArmOps::Arm_R1, CArmOps::Arm_R2, 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
static CArmOps::ArmReg RegisterList[] = {
CArmOps::Arm_R0,
CArmOps::Arm_R1,
CArmOps::Arm_R2,
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)
@ -119,7 +155,10 @@ void CArmRegInfo::BeforeCallDirect(void)
int PushPopRegisters = 0;
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)
@ -148,7 +187,10 @@ void CArmRegInfo::BeforeCallDirect(void)
PushPopRegisters = 0;
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)
@ -162,18 +204,40 @@ void CArmRegInfo::BeforeCallDirect(void)
void CArmRegInfo::AfterCallDirect(void)
{
static uint32_t PushPopRegisterList[] =
{
CArmOps::ArmPushPop_R0, CArmOps::ArmPushPop_R1, CArmOps::ArmPushPop_R2, 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 uint32_t PushPopRegisterList[] = {
CArmOps::ArmPushPop_R0,
CArmOps::ArmPushPop_R1,
CArmOps::ArmPushPop_R2,
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[] =
{
CArmOps::Arm_R0, CArmOps::Arm_R1, CArmOps::Arm_R2, 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,
static CArmOps::ArmReg RegisterList[] = {
CArmOps::Arm_R0,
CArmOps::Arm_R1,
CArmOps::Arm_R2,
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)
@ -186,7 +250,10 @@ void CArmRegInfo::AfterCallDirect(void)
int PushPopRegisters = 0;
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)
@ -227,7 +294,7 @@ void CArmRegInfo::FixRoundModel(FPU_ROUND RoundMethod)
if (RoundMethod == RoundDefault)
{
BeforeCallDirect();
m_Assembler.MoveVariableToArmReg(_RoundingModel, "_RoundingModel", CArmOps::Arm_R0);
m_Assembler.MoveVariableToArmReg(_RoundingModel, "_RoundingModel", CArmOps::Arm_R0);
m_Assembler.CallFunction((void *)fesetround, "fesetround");
AfterCallDirect();
}
@ -258,7 +325,10 @@ void CArmRegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg
Reg = FreeArmReg(false);
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__);
return;
}
@ -277,7 +347,7 @@ void CArmRegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t 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);
if (Count > 0)
@ -331,7 +401,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
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__);
return;
}
@ -342,7 +415,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
regHi = FreeArmReg(false);
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__);
return;
}
@ -351,7 +427,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
reglo = FreeArmReg(false);
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__);
return;
}
@ -369,7 +448,10 @@ void CArmRegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
regHi = FreeArmReg(false);
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__);
return;
}
@ -475,7 +557,10 @@ void CArmRegInfo::UnMap_GPR(uint32_t MipsReg, bool WriteBackValue)
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");
if (IsConst(MipsReg))
{
@ -582,9 +667,18 @@ void CArmRegInfo::WriteBackRegisters()
UnMap_AllFPRs();
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 = 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 i = 1; i < 32; i++)
{
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++)
{
@ -628,21 +722,57 @@ CArmOps::ArmReg CArmRegInfo::UnMap_TempReg(bool TempMapping)
}
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_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; }
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 (GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R7))
{
return 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;
}
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 (GetArmRegMapped( CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R11)) { return CArmOps::Arm_R11; }
if (GetArmRegMapped( CArmOps::Arm_R10) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R10)) { return CArmOps::Arm_R10; }
if (GetArmRegMapped(CArmOps::Arm_R11) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R11))
{
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)
{
@ -742,34 +872,73 @@ CArmOps::ArmReg CArmRegInfo::FreeArmReg(bool TempMapping)
g_Notify->BreakPoint(__FILE__, __LINE__);
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_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; }
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 ((GetArmRegMapped(CArmOps::Arm_R7) == NotMapped || GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R7))
{
return 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;
}
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 ((GetArmRegMapped( CArmOps::Arm_R11) == NotMapped || GetArmRegMapped( CArmOps::Arm_R11) == Temp_Mapped) && !GetArmRegProtected( CArmOps::Arm_R11)) { 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_R11) == NotMapped || GetArmRegMapped(CArmOps::Arm_R11) == Temp_Mapped) && !GetArmRegProtected(CArmOps::Arm_R11))
{
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);
if (Reg != CArmOps::Arm_Unknown) { return Reg; }
if (Reg != CArmOps::Arm_Unknown)
{
return Reg;
}
int32_t MapCount[ CArmOps::Arm_R12];
CArmOps::ArmReg MapReg[ CArmOps::Arm_R12];
int32_t MapCount[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);
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;
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]))
{
@ -842,13 +1011,12 @@ void CArmRegInfo::LogRegisterState(void)
}
m_CodeBlock.Log("GetArmRegMapped(%s) = %X%s%s Protected: %s MapOrder: %d",
m_Assembler.ArmRegName((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() : "",
regname.length() > 0 ? stdstr_f(" (%s)", regname.c_str()).c_str() : "",
GetArmRegProtected((CArmOps::ArmReg)i) ? "true" : "false",
GetArmRegMapOrder((CArmOps::ArmReg)i)
);
m_Assembler.ArmRegName((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() : "",
regname.length() > 0 ? stdstr_f(" (%s)", regname.c_str()).c_str() : "",
GetArmRegProtected((CArmOps::ArmReg)i) ? "true" : "false",
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 (GetArmRegMapped( CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected( CArmOps::Arm_R7)) { Reg = 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; }
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 (GetArmRegMapped(CArmOps::Arm_R7) == Temp_Mapped && !GetArmRegProtected(CArmOps::Arm_R7))
{
Reg = 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;
}
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)
{
@ -1013,7 +1217,7 @@ CArmOps::ArmReg CArmRegInfo::Map_Variable(VARIABLE_MAPPED variable, CArmOps::Arm
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)
{
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_Variable_MappedTo[Reg] = variable;
if (variable == VARIABLE_GPR) { m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_GPR, "_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"); }
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"); }
if (variable == VARIABLE_GPR)
{
m_Assembler.MoveConstToArmReg(Reg, (uint32_t)_GPR, "_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");
}
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
{
g_Notify->BreakPoint(__FILE__, __LINE__);

View File

@ -1,8 +1,8 @@
#pragma once
#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/Recompiler/Arm/ArmOps.h>
#include <Project64-core/N64System/Recompiler/RegBase.h>
class CArmRegInfo :
public CRegBase,
@ -32,13 +32,13 @@ public:
};
CArmRegInfo(CCodeBlock & CodeBlock, CArmOps & Assembler);
CArmRegInfo(const CArmRegInfo&);
CArmRegInfo(const 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 AfterCallDirect(void);
@ -61,21 +61,57 @@ public:
bool UnMap_ArmReg(CArmOps::ArmReg Reg);
void ResetRegProtection();
inline CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[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 CArmOps::ArmReg GetMipsRegMapLo(int32_t Reg) const
{
return m_RegMapLo[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 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 uint32_t GetArmRegMapOrder(CArmOps::ArmReg Reg) const
{
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 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 void SetArmRegMapOrder(CArmOps::ArmReg Reg, uint32_t Order)
{
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 void SetVariableMappedTo(CArmOps::ArmReg Reg, VARIABLE_MAPPED variable) { m_Variable_MappedTo[Reg] = variable; }
inline VARIABLE_MAPPED GetVariableMappedTo(CArmOps::ArmReg Reg) const
{
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);
void LogRegisterState(void);
@ -86,7 +122,7 @@ private:
CCodeBlock & m_CodeBlock;
CArmOps & m_Assembler;
bool ShouldPushPopReg (CArmOps::ArmReg Reg);
bool ShouldPushPopReg(CArmOps::ArmReg Reg);
CArmOps::ArmReg m_RegMapHi[32];
CArmOps::ArmReg m_RegMapLo[32];

View File

@ -1,15 +1,16 @@
#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/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <string.h>
#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) */
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
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
if (((uint32_t)m_CompiledLocation % 2) == 0)
{
m_CompiledLocation+=1;
m_CompiledLocation += 1;
}
#endif
#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)
{
@ -451,22 +452,53 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_SPECIAL:
switch (Command.funct)
{
case R4300i_SPECIAL_SLL: case R4300i_SPECIAL_SRL: case R4300i_SPECIAL_SRA:
case R4300i_SPECIAL_SLLV: case R4300i_SPECIAL_SRLV: case R4300i_SPECIAL_SRAV:
case R4300i_SPECIAL_MFHI: case R4300i_SPECIAL_MTHI: case R4300i_SPECIAL_MFLO:
case R4300i_SPECIAL_MTLO: case R4300i_SPECIAL_DSLLV: case R4300i_SPECIAL_DSRLV:
case R4300i_SPECIAL_DSRAV: case R4300i_SPECIAL_ADD: case R4300i_SPECIAL_ADDU:
case R4300i_SPECIAL_SUB: case R4300i_SPECIAL_SUBU: case R4300i_SPECIAL_AND:
case R4300i_SPECIAL_OR: case R4300i_SPECIAL_XOR: case R4300i_SPECIAL_NOR:
case R4300i_SPECIAL_SLT: case R4300i_SPECIAL_SLTU: case R4300i_SPECIAL_DADD:
case R4300i_SPECIAL_DADDU: case R4300i_SPECIAL_DSUB: case R4300i_SPECIAL_DSUBU:
case R4300i_SPECIAL_DSLL: case R4300i_SPECIAL_DSRL: case R4300i_SPECIAL_DSRA:
case R4300i_SPECIAL_DSLL32: case R4300i_SPECIAL_DSRL32: case R4300i_SPECIAL_DSRA32:
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:
case R4300i_SPECIAL_SLL:
case R4300i_SPECIAL_SRL:
case R4300i_SPECIAL_SRA:
case R4300i_SPECIAL_SLLV:
case R4300i_SPECIAL_SRLV:
case R4300i_SPECIAL_SRAV:
case R4300i_SPECIAL_MFHI:
case R4300i_SPECIAL_MTHI:
case R4300i_SPECIAL_MFLO:
case R4300i_SPECIAL_MTLO:
case R4300i_SPECIAL_DSLLV:
case R4300i_SPECIAL_DSRLV:
case R4300i_SPECIAL_DSRAV:
case R4300i_SPECIAL_ADD:
case R4300i_SPECIAL_ADDU:
case R4300i_SPECIAL_SUB:
case R4300i_SPECIAL_SUBU:
case R4300i_SPECIAL_AND:
case R4300i_SPECIAL_OR:
case R4300i_SPECIAL_XOR:
case R4300i_SPECIAL_NOR:
case R4300i_SPECIAL_SLT:
case R4300i_SPECIAL_SLTU:
case R4300i_SPECIAL_DADD:
case R4300i_SPECIAL_DADDU:
case R4300i_SPECIAL_DSUB:
case R4300i_SPECIAL_DSUBU:
case R4300i_SPECIAL_DSLL:
case R4300i_SPECIAL_DSRL:
case R4300i_SPECIAL_DSRA:
case R4300i_SPECIAL_DSLL32:
case R4300i_SPECIAL_DSRL32:
case R4300i_SPECIAL_DSRA32:
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;
case R4300i_SPECIAL_JALR:
case R4300i_SPECIAL_JR:
@ -563,8 +595,12 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
LikelyBranch = true;
IncludeDelaySlot = true;
break;
case R4300i_REGIMM_TEQI: case R4300i_REGIMM_TNEI: case R4300i_REGIMM_TGEI:
case R4300i_REGIMM_TGEIU: case R4300i_REGIMM_TLTI: case R4300i_REGIMM_TLTIU:
case R4300i_REGIMM_TEQI:
case R4300i_REGIMM_TNEI:
case R4300i_REGIMM_TGEI:
case R4300i_REGIMM_TGEIU:
case R4300i_REGIMM_TLTI:
case R4300i_REGIMM_TLTIU:
break;
default:
if (Command.Value == 0x0407000D)
@ -601,8 +637,8 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
ContinuePC = PC + 8;
}
R4300iOpcode DelaySlot;
if (TargetPC == PC &&
g_MMU->MemoryValue32(PC + 4, DelaySlot.Value) &&
if (TargetPC == PC &&
g_MMU->MemoryValue32(PC + 4, DelaySlot.Value) &&
!R4300iInstruction(PC, Command.Value).DelaySlotEffectsCompare(DelaySlot.Value))
{
PermLoop = true;
@ -639,15 +675,18 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_CP0:
switch (Command.rs)
{
case R4300i_COP0_MT: case R4300i_COP0_MF:
case R4300i_COP0_MT:
case R4300i_COP0_MF:
break;
default:
if ((Command.rs & 0x10) != 0)
{
switch (Command.funct)
{
case R4300i_COP0_CO_TLBR: case R4300i_COP0_CO_TLBWI:
case R4300i_COP0_CO_TLBWR: case R4300i_COP0_CO_TLBP:
case R4300i_COP0_CO_TLBR:
case R4300i_COP0_CO_TLBWI:
case R4300i_COP0_CO_TLBWR:
case R4300i_COP0_CO_TLBP:
break;
case R4300i_COP0_CO_ERET:
EndBlock = true;
@ -668,12 +707,20 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
case R4300i_CP1:
switch (Command.fmt)
{
case R4300i_COP1_MF: case R4300i_COP1_DMF: 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:
case R4300i_COP1_MF:
case R4300i_COP1_DMF:
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;
case R4300i_COP1_BC:
switch (Command.ft) {
switch (Command.ft)
{
case R4300i_COP1_BC_BCF:
case R4300i_COP1_BC_BCT:
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;
}
break;
case R4300i_ANDI: case R4300i_ORI: case R4300i_XORI: case R4300i_LUI:
case R4300i_ADDI: case R4300i_ADDIU: case R4300i_SLTI: case R4300i_SLTIU:
case R4300i_DADDI: case R4300i_DADDIU: case R4300i_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:
case R4300i_ANDI:
case R4300i_ORI:
case R4300i_XORI:
case R4300i_LUI:
case R4300i_ADDI:
case R4300i_ADDIU:
case R4300i_SLTI:
case R4300i_SLTIU:
case R4300i_DADDI:
case R4300i_DADDIU:
case R4300i_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;
case R4300i_BEQL:
TargetPC = PC + ((int16_t)Command.offset << 2) + 4;
@ -786,7 +860,8 @@ bool CCodeBlock::Compile()
m_RecompilerOps->EnterCodeBlock();
if (g_System->bLinkBlocks())
{
while (m_EnterSection !=nullptr && m_EnterSection->GenerateNativeCode(NextTest()));
while (m_EnterSection != nullptr && m_EnterSection->GenerateNativeCode(NextTest()))
;
}
else
{
@ -807,7 +882,7 @@ bool CCodeBlock::Compile()
}
MD5(BlockPtr, BlockSize).get_digest(m_Hash);
#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
return true;
}
@ -831,7 +906,7 @@ void CCodeBlock::Log(_Printf_format_string_ const char * Text, ...)
#pragma warning(push)
#pragma warning(disable : 4996)
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;
if (buffer != nullptr)
{

View File

@ -1,7 +1,7 @@
#pragma once
#include <Common/md5.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/CodeSection.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#if !defined(_MSC_VER) && !defined(_Printf_format_string_)
#define _Printf_format_string_
@ -17,25 +17,73 @@ public:
bool Compile();
uint32_t VAddrEnter() const { return m_VAddrEnter; }
uint32_t VAddrFirst() const { return m_VAddrFirst; }
uint32_t VAddrLast() const { 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; }
uint32_t VAddrEnter() const
{
return m_VAddrEnter;
}
uint32_t VAddrFirst() const
{
return m_VAddrFirst;
}
uint32_t VAddrLast() const
{
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 SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; }
void SetVAddrFirst(uint32_t VAddr)
{
m_VAddrFirst = VAddr;
}
void SetVAddrLast(uint32_t VAddr)
{
m_VAddrLast = VAddr;
}
CCodeSection * ExistingSection(uint32_t Addr) { return m_EnterSection->ExistingSection(Addr, NextTest()); }
bool SectionAccessible(uint32_t m_SectionID) { return m_EnterSection->SectionAccessible(m_SectionID, NextTest()); }
CCodeSection * ExistingSection(uint32_t Addr)
{
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 * MemLocation(int32_t i) const { return m_MemLocation[i]; }
uint64_t MemContents(int32_t i) const
{
return m_MemContents[i];
}
uint64_t * MemLocation(int32_t i) const
{
return m_MemLocation[i];
}
uint32_t NextTest();
@ -43,21 +91,21 @@ public:
private:
CCodeBlock();
CCodeBlock(const CCodeBlock&);
CCodeBlock& operator=(const CCodeBlock&);
CCodeBlock(const CCodeBlock &);
CCodeBlock & operator=(const CCodeBlock &);
bool AnalyseBlock();
bool CreateBlockLinkage(CCodeSection * EnterSection);
void DetermineLoops();
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);
uint32_t m_VAddrEnter;
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
uint8_t * m_CompiledLocation; // What address is this compiled at?
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
uint8_t * m_CompiledLocation; // What address is this compiled at?
uint8_t * m_CompiledLocationEnd; // What address is this compiled at?
typedef std::map<uint32_t, CCodeSection *> SectionMap;

View File

@ -1,16 +1,17 @@
#include "stdafx.h"
#include <Project64-core/N64System/Recompiler/CodeSection.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.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/Debugger.h>
#include <Project64-core/ExceptionHandler.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/SectionInfo.h>
#include <Project64-core/ExceptionHandler.h>
#include <Project64-core/Debugger.h>
#include <Project64-core/N64System/SystemGlobals.h>
CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) :
m_CodeBlock(CodeBlock),
@ -41,8 +42,8 @@ CCodeSection::~CCodeSection()
void CCodeSection::GenerateSectionLinkage()
{
CCodeSection * TargetSection[] = { m_ContinueSection, m_JumpSection };
CJumpInfo * JumpInfo[] = { &m_Cont, &m_Jump };
CCodeSection * TargetSection[] = {m_ContinueSection, m_JumpSection};
CJumpInfo * JumpInfo[] = {&m_Cont, &m_Jump};
int i;
for (i = 0; i < 2; i++)
@ -90,8 +91,14 @@ void CCodeSection::GenerateSectionLinkage()
}
else if (TargetSection[i] != nullptr && JumpInfo[i] != nullptr)
{
if (!JumpInfo[i]->FallThrough) { continue; }
if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC) { continue; }
if (!JumpInfo[i]->FallThrough)
{
continue;
}
if (JumpInfo[i]->TargetPC == TargetSection[i]->m_EnterPC)
{
continue;
}
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->Reason);
//FreeSection(TargetSection[i],Section);
@ -100,9 +107,15 @@ void CCodeSection::GenerateSectionLinkage()
}
else
{
if (m_Cont.LinkLocation == nullptr && m_Cont.FallThrough == false) { m_ContinueSection = nullptr; }
if (m_Jump.LinkLocation == nullptr && m_Jump.FallThrough == false) { m_JumpSection = nullptr; }
if (m_JumpSection == nullptr && m_ContinueSection == nullptr)
if (m_Cont.LinkLocation == nullptr && m_Cont.FallThrough == false)
{
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);
}
@ -111,9 +124,16 @@ void CCodeSection::GenerateSectionLinkage()
TargetSection[0] = m_ContinueSection;
TargetSection[1] = m_JumpSection;
for (i = 0; i < 2; i++) {
if (TargetSection[i] == nullptr) { continue; }
if (!JumpInfo[i]->FallThrough) { continue; }
for (i = 0; i < 2; i++)
{
if (TargetSection[i] == nullptr)
{
continue;
}
if (!JumpInfo[i]->FallThrough)
{
continue;
}
if (TargetSection[i]->m_CompiledLocation != nullptr)
{
@ -147,14 +167,26 @@ void CCodeSection::GenerateSectionLinkage()
for (i = 0; i < 2; i++)
{
if (TargetSection[i] == nullptr) { continue; }
if (TargetSection[i]->m_ParentSection.empty()) { continue; }
if (TargetSection[i] == nullptr)
{
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++)
{
CCodeSection * Parent = *iter;
if (Parent->m_CompiledLocation != nullptr) { continue; }
if (Parent->m_InLoop) { continue; }
if (Parent->m_CompiledLocation != nullptr)
{
continue;
}
if (Parent->m_InLoop)
{
continue;
}
if (JumpInfo[i]->PermLoop)
{
m_CodeBlock.Log("PermLoop *** 2");
@ -195,7 +227,10 @@ void CCodeSection::GenerateSectionLinkage()
//CodeLog("Section %d",m_SectionID);
for (i = 0; i < 2; i++)
{
if (JumpInfo[i]->LinkLocation == nullptr) { continue; }
if (JumpInfo[i]->LinkLocation == nullptr)
{
continue;
}
if (TargetSection[i] == nullptr)
{
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++)
{
CCodeSection * Parent = *iter;
if (Parent->m_CompiledLocation != nullptr) { continue; }
if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest())) { continue; }
if (Parent->m_CompiledLocation != nullptr)
{
continue;
}
if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest()))
{
continue;
}
return false;
}
m_RecompilerOps->SetCurrentSection(this);
@ -291,8 +332,14 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
return false;
}
m_Test = Test;
if (m_ContinueSection != nullptr && m_ContinueSection->GenerateNativeCode(Test)) { return true; }
if (m_JumpSection != nullptr && m_JumpSection->GenerateNativeCode(Test)) { return true; }
if (m_ContinueSection != nullptr && m_ContinueSection->GenerateNativeCode(Test))
{
return true;
}
if (m_JumpSection != nullptr && m_JumpSection->GenerateNativeCode(Test))
{
return true;
}
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_TLT: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLT); break;
case R4300i_SPECIAL_TLTU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTU); break;
break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
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_TLTIU: m_RecompilerOps->Compile_TrapCompare(RecompilerTrapCompare_TLTIU); break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
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_BCTL: m_RecompilerOps->Compile_BranchLikely(RecompilerBranchCompare_COP1BCT, false); break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
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_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_C_F: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
m_RecompilerOps->COP1_S_CMP(); break;
case R4300i_COP1_FUNCT_C_F:
case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ:
case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT:
case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE:
case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF:
case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ:
case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT:
case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE:
case R4300i_COP1_FUNCT_C_NGT:
m_RecompilerOps->COP1_S_CMP();
break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
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_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_C_F: case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
m_RecompilerOps->COP1_D_CMP(); break;
case R4300i_COP1_FUNCT_C_F:
case R4300i_COP1_FUNCT_C_UN:
case R4300i_COP1_FUNCT_C_EQ:
case R4300i_COP1_FUNCT_C_UEQ:
case R4300i_COP1_FUNCT_C_OLT:
case R4300i_COP1_FUNCT_C_ULT:
case R4300i_COP1_FUNCT_C_OLE:
case R4300i_COP1_FUNCT_C_ULE:
case R4300i_COP1_FUNCT_C_SF:
case R4300i_COP1_FUNCT_C_NGLE:
case R4300i_COP1_FUNCT_C_SEQ:
case R4300i_COP1_FUNCT_C_NGL:
case R4300i_COP1_FUNCT_C_LT:
case R4300i_COP1_FUNCT_C_NGE:
case R4300i_COP1_FUNCT_C_LE:
case R4300i_COP1_FUNCT_C_NGT:
m_RecompilerOps->COP1_D_CMP();
break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
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_D: m_RecompilerOps->COP1_W_CVT_D(); break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
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_D: m_RecompilerOps->COP1_L_CVT_D(); break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
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_SD: m_RecompilerOps->SD(); break;
default:
m_RecompilerOps->UnknownOpcode(); break;
m_RecompilerOps->UnknownOpcode();
break;
}
m_RecompilerOps->PostCompileOpcode();
@ -829,13 +902,22 @@ CCodeSection * CCodeSection::ExistingSection(uint32_t Addr, uint32_t Test)
{
return this;
}
if (m_Test == Test) { return nullptr; }
if (m_Test == Test)
{
return nullptr;
}
m_Test = Test;
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;
if (Section != nullptr) { return Section; }
if (Section != nullptr)
{
return Section;
}
return nullptr;
}
@ -847,7 +929,10 @@ bool CCodeSection::SectionAccessible(uint32_t SectionId, uint32_t Test)
return true;
}
if (m_Test == Test) { return false; }
if (m_Test == Test)
{
return false;
}
m_Test = 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)
{
if (IgnoreIfCompiled && Parent->m_CompiledLocation != nullptr) { return true; }
if (!m_InLoop) { 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; }
if (IgnoreIfCompiled && Parent->m_CompiledLocation != nullptr)
{
return true;
}
if (!m_InLoop)
{
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;
for (SECTION_LIST::iterator iter = Parent->m_ParentSection.begin(); iter != Parent->m_ParentSection.end(); iter++)
{
CCodeSection * ParentSection = *iter;
if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test)) { return false; }
if (!IsAllParentLoops(ParentSection, IgnoreIfCompiled, Test))
{
return false;
}
}
return true;
}
@ -959,12 +1065,21 @@ bool CCodeSection::DisplaySectionInformation(uint32_t ID, uint32_t Test)
{
return false;
}
if (m_Test == Test) { return false; }
if (m_Test == Test)
{
return false;
}
m_Test = Test;
if (m_SectionID != ID)
{
if (m_ContinueSection != nullptr && m_ContinueSection->DisplaySectionInformation(ID, Test)) { return true; }
if (m_JumpSection != nullptr && m_JumpSection->DisplaySectionInformation(ID, Test)) { return true; }
if (m_ContinueSection != nullptr && m_ContinueSection->DisplaySectionInformation(ID, Test))
{
return true;
}
if (m_JumpSection != nullptr && m_JumpSection->DisplaySectionInformation(ID, Test))
{
return true;
}
return false;
}
DisplaySectionInformation();

View File

@ -35,14 +35,14 @@ public:
uint32_t m_EndPC;
CCodeSection * m_ContinueSection;
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;
uint32_t m_Test;
uint32_t m_Test2;
uint8_t * m_CompiledLocation;
bool m_InLoop;
bool m_DelaySlot;
CRecompilerOps * & m_RecompilerOps;
CRecompilerOps *& m_RecompilerOps;
// Register info
CRegInfo m_RegEnter;
@ -53,8 +53,8 @@ public:
private:
CCodeSection(void);
CCodeSection(const CCodeSection&);
CCodeSection& operator=(const CCodeSection&);
CCodeSection(const CCodeSection &);
CCodeSection & operator=(const CCodeSection &);
void UnlinkParent(CCodeSection * Parent, bool ContinueSection);
void InheritConstants();

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