Merge branch 'master' into archive-polishing

This commit is contained in:
Madhav Kanbur 2021-01-18 09:34:10 +05:30
commit 29c290f45a
15 changed files with 96 additions and 57 deletions

View File

@ -21,7 +21,9 @@ jobs:
- name: Install dependencies - name: Install dependencies
working-directory: ${{runner.workspace}} working-directory: ${{runner.workspace}}
run: | run: |
brew install cmake sdl2 qt5 libslirp libarchive rm -rf /usr/local/bin/2to3 # Temporary workaround suggested here - https://github.com/actions/virtual-environments/issues/2322#issuecomment-749211076
brew update
brew install sdl2 qt@5 libslirp libarchive
- name: Create build environment - name: Create build environment
run: mkdir ${{runner.workspace}}/build run: mkdir ${{runner.workspace}}/build
- name: Configure - name: Configure

View File

@ -86,7 +86,7 @@ If everything went well, melonDS should now be in the `dist` folder.
### macOS: ### macOS:
1. Install the [Homebrew Package Manager](https://brew.sh) 1. Install the [Homebrew Package Manager](https://brew.sh)
2. Install dependencies: `brew install git pkg-config cmake sdl2 qt5 libslirp libarchive` 2. Install dependencies: `brew install git pkg-config cmake sdl2 qt@5 libslirp libarchive`
3. Compile: 3. Compile:
```zsh ```zsh
git clone https://github.com/Arisotura/melonDS.git git clone https://github.com/Arisotura/melonDS.git

View File

@ -101,8 +101,8 @@ if (ENABLE_JIT)
endif() endif()
if (APPLE) if (APPLE)
target_include_directories(core PUBLIC /usr/local/include) target_include_directories(core PUBLIC /usr/local/include /opt/homebrew/include)
target_link_directories(core PUBLIC /usr/local/lib) target_link_directories(core PUBLIC /usr/local/lib /opt/homebrew/lib)
endif() endif()
if (ENABLE_OGLRENDERER) if (ENABLE_OGLRENDERER)

View File

@ -74,6 +74,9 @@ DSi_NDMA* NDMAs[8];
DSi_SDHost* SDMMC; DSi_SDHost* SDMMC;
DSi_SDHost* SDIO; DSi_SDHost* SDIO;
FILE* SDMMCFile;
FILE* SDIOFile;
u64 ConsoleID; u64 ConsoleID;
u8 eMMC_CID[16]; u8 eMMC_CID[16];
@ -122,6 +125,8 @@ void DeInit()
delete SDMMC; delete SDMMC;
delete SDIO; delete SDIO;
CloseDSiNAND();
} }
void Reset() void Reset()
@ -302,12 +307,11 @@ bool LoadNAND()
memset(NWRAMEnd, 0, sizeof(NWRAMEnd)); memset(NWRAMEnd, 0, sizeof(NWRAMEnd));
memset(NWRAMMask, 0, sizeof(NWRAMMask)); memset(NWRAMMask, 0, sizeof(NWRAMMask));
FILE* f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb"); if (SDMMCFile)
if (f)
{ {
u32 bootparams[8]; u32 bootparams[8];
fseek(f, 0x220, SEEK_SET); fseek(SDMMCFile, 0x220, SEEK_SET);
fread(bootparams, 4, 8, f); fread(bootparams, 4, 8, SDMMCFile);
printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n", printf("ARM9: offset=%08X size=%08X RAM=%08X size_aligned=%08X\n",
bootparams[0], bootparams[1], bootparams[2], bootparams[3]); bootparams[0], bootparams[1], bootparams[2], bootparams[3]);
@ -320,8 +324,8 @@ bool LoadNAND()
MBK[1][8] = 0; MBK[1][8] = 0;
u32 mbk[12]; u32 mbk[12];
fseek(f, 0x380, SEEK_SET); fseek(SDMMCFile, 0x380, SEEK_SET);
fread(mbk, 4, 12, f); fread(mbk, 4, 12, SDMMCFile);
MapNWRAM_A(0, mbk[0] & 0xFF); MapNWRAM_A(0, mbk[0] & 0xFF);
MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF); MapNWRAM_A(1, (mbk[0] >> 8) & 0xFF);
@ -375,12 +379,12 @@ bool LoadNAND()
AES_init_ctx_iv(&ctx, boot2key, boot2iv); AES_init_ctx_iv(&ctx, boot2key, boot2iv);
fseek(f, bootparams[0], SEEK_SET); fseek(SDMMCFile, bootparams[0], SEEK_SET);
dstaddr = bootparams[2]; dstaddr = bootparams[2];
for (u32 i = 0; i < bootparams[3]; i += 16) for (u32 i = 0; i < bootparams[3]; i += 16)
{ {
u8 data[16]; u8 data[16];
fread(data, 16, 1, f); fread(data, 16, 1, SDMMCFile);
for (int j = 0; j < 16; j++) tmp[j] = data[15-j]; for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
AES_CTR_xcrypt_buffer(&ctx, tmp, 16); AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
@ -400,12 +404,12 @@ bool LoadNAND()
AES_init_ctx_iv(&ctx, boot2key, boot2iv); AES_init_ctx_iv(&ctx, boot2key, boot2iv);
fseek(f, bootparams[4], SEEK_SET); fseek(SDMMCFile, bootparams[4], SEEK_SET);
dstaddr = bootparams[6]; dstaddr = bootparams[6];
for (u32 i = 0; i < bootparams[7]; i += 16) for (u32 i = 0; i < bootparams[7]; i += 16)
{ {
u8 data[16]; u8 data[16];
fread(data, 16, 1, f); fread(data, 16, 1, SDMMCFile);
for (int j = 0; j < 16; j++) tmp[j] = data[15-j]; for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
AES_CTR_xcrypt_buffer(&ctx, tmp, 16); AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
@ -427,25 +431,22 @@ bool LoadNAND()
// read the nocash footer // read the nocash footer
fseek(f, -0x40, SEEK_END); fseek(SDMMCFile, -0x40, SEEK_END);
char nand_footer[16]; char nand_footer[16];
const char* nand_footer_ref = "DSi eMMC CID/CPU"; const char* nand_footer_ref = "DSi eMMC CID/CPU";
fread(nand_footer, 1, 16, f); fread(nand_footer, 1, 16, SDMMCFile);
if (memcmp(nand_footer, nand_footer_ref, 16)) if (memcmp(nand_footer, nand_footer_ref, 16))
{ {
printf("ERROR: NAND missing nocash footer\n"); printf("ERROR: NAND missing nocash footer\n");
fclose(f);
return false; return false;
} }
fread(eMMC_CID, 1, 16, f); fread(eMMC_CID, 1, 16, SDMMCFile);
fread(&ConsoleID, 1, 8, f); fread(&ConsoleID, 1, 8, SDMMCFile);
printf("eMMC CID: "); printhex(eMMC_CID, 16); printf("eMMC CID: "); printhex(eMMC_CID, 16);
printf("Console ID: %016llX\n", ConsoleID); printf("Console ID: %016llX\n", ConsoleID);
fclose(f);
} }
memset(ITCMInit, 0, 0x8000); memset(ITCMInit, 0, 0x8000);
@ -463,6 +464,13 @@ bool LoadNAND()
return true; return true;
} }
void CloseDSiNAND()
{
if (DSi::SDMMCFile)
fclose(DSi::SDMMCFile);
if (DSi::SDIOFile)
fclose(DSi::SDIOFile);
}
void RunNDMAs(u32 cpu) void RunNDMAs(u32 cpu)
{ {

View File

@ -36,6 +36,9 @@ extern u64 ConsoleID;
extern DSi_SDHost* SDMMC; extern DSi_SDHost* SDMMC;
extern DSi_SDHost* SDIO; extern DSi_SDHost* SDIO;
extern FILE* SDMMCFile;
extern FILE* SDIOFile;
const u32 NWRAMSize = 0x40000; const u32 NWRAMSize = 0x40000;
extern u8* NWRAM_A; extern u8* NWRAM_A;
@ -59,6 +62,8 @@ void SoftReset();
bool LoadBIOS(); bool LoadBIOS();
bool LoadNAND(); bool LoadNAND();
void CloseDSiNAND();
void RunNDMAs(u32 cpu); void RunNDMAs(u32 cpu);
void StallNDMAs(); void StallNDMAs();
bool NDMAsInMode(u32 cpu, u32 mode); bool NDMAsInMode(u32 cpu, u32 mode);

View File

@ -114,14 +114,14 @@ void DSi_SDHost::Reset()
if (Config::DSiSDEnable) if (Config::DSiSDEnable)
{ {
sd = new DSi_MMCStorage(this, false, Config::DSiSDPath); sd = new DSi_MMCStorage(this, false, DSi::SDIOFile);
u8 sd_cid[16] = {0xBD, 0x12, 0x34, 0x56, 0x78, 0x03, 0x4D, 0x30, 0x30, 0x46, 0x50, 0x41, 0x00, 0x00, 0x15, 0x00}; u8 sd_cid[16] = {0xBD, 0x12, 0x34, 0x56, 0x78, 0x03, 0x4D, 0x30, 0x30, 0x46, 0x50, 0x41, 0x00, 0x00, 0x15, 0x00};
sd->SetCID(sd_cid); sd->SetCID(sd_cid);
} }
else else
sd = nullptr; sd = nullptr;
mmc = new DSi_MMCStorage(this, true, Config::DSiNANDPath); mmc = new DSi_MMCStorage(this, true, DSi::SDMMCFile);
mmc->SetCID(DSi::eMMC_CID); mmc->SetCID(DSi::eMMC_CID);
Ports[0] = sd; Ports[0] = sd;
@ -706,30 +706,14 @@ void DSi_SDHost::CheckSwapFIFO()
#define MMC_DESC (Internal?"NAND":"SDcard") #define MMC_DESC (Internal?"NAND":"SDcard")
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path) : DSi_SDDevice(host) DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, FILE* file) : DSi_SDDevice(host)
{ {
Internal = internal; Internal = internal;
strncpy(FilePath, path, 1023); FilePath[1023] = '\0'; File = file;
File = Platform::OpenLocalFile(path, "r+b");
if (!File)
{
if (internal)
{
// TODO: proper failure
printf("!! MMC file %s does not exist\n", path);
}
else
{
File = Platform::OpenLocalFile(path, "w+b");
}
}
} }
DSi_MMCStorage::~DSi_MMCStorage() DSi_MMCStorage::~DSi_MMCStorage()
{ {}
if (File) fclose(File);
}
void DSi_MMCStorage::Reset() void DSi_MMCStorage::Reset()
{ {

View File

@ -120,7 +120,7 @@ protected:
class DSi_MMCStorage : public DSi_SDDevice class DSi_MMCStorage : public DSi_SDDevice
{ {
public: public:
DSi_MMCStorage(DSi_SDHost* host, bool internal, const char* path); DSi_MMCStorage(DSi_SDHost* host, bool internal, FILE* file);
~DSi_MMCStorage(); ~DSi_MMCStorage();
void Reset(); void Reset();
@ -134,7 +134,6 @@ public:
private: private:
bool Internal; bool Internal;
char FilePath[1024];
FILE* File; FILE* File;
u8 CID[16]; u8 CID[16];

View File

@ -65,7 +65,7 @@ struct
float uFogDensity[34][4]; // float[34] 168 / 136 float uFogDensity[34][4]; // float[34] 168 / 136
u32 uFogOffset; // int 304 / 1 u32 uFogOffset; // int 304 / 1
u32 uFogShift; // int 305 / 1 u32 uFogShift; // int 305 / 1
u32 _pad1[2]; // int 306 / 2
} ShaderConfig; } ShaderConfig;
GLuint ShaderConfigUBO; GLuint ShaderConfigUBO;
@ -284,7 +284,8 @@ bool Init()
glGenBuffers(1, &ShaderConfigUBO); glGenBuffers(1, &ShaderConfigUBO);
glBindBuffer(GL_UNIFORM_BUFFER, ShaderConfigUBO); glBindBuffer(GL_UNIFORM_BUFFER, ShaderConfigUBO);
glBufferData(GL_UNIFORM_BUFFER, (sizeof(ShaderConfig) + 15) & ~15, &ShaderConfig, GL_STATIC_DRAW); static_assert((sizeof(ShaderConfig) & 15) == 0);
glBufferData(GL_UNIFORM_BUFFER, sizeof(ShaderConfig), &ShaderConfig, GL_STATIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, ShaderConfigUBO); glBindBufferBase(GL_UNIFORM_BUFFER, 0, ShaderConfigUBO);

View File

@ -123,7 +123,8 @@ void EnableCheats(bool enable);
// 2 = emphasize bottom screen // 2 = emphasize bottom screen
// * screenGap: size of the gap between the two screens // * screenGap: size of the gap between the two screens
// * integerScale: force screens to be scaled up at integer scaling factors // * integerScale: force screens to be scaled up at integer scaling factors
void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale); // * screenSwap: whether to swap the position of both screens
void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale, int swapScreens);
// get a 2x3 transform matrix for each screen // get a 2x3 transform matrix for each screen
// note: the transform assumes an origin point at the top left of the display, // note: the transform assumes an origin point at the top left of the display,

View File

@ -26,6 +26,7 @@
#include "Platform.h" #include "Platform.h"
#include "NDS.h" #include "NDS.h"
#include "DSi.h"
#include "GBACart.h" #include "GBACart.h"
#include "AREngine.h" #include "AREngine.h"
@ -202,18 +203,27 @@ int VerifyDSiFirmware()
return Load_OK; return Load_OK;
} }
int VerifyDSiNAND() int SetupDSiNAND()
{ {
FILE* f; FILE* f;
long len; long len;
f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb"); f = Platform::OpenLocalFile(Config::DSiNANDPath, "r+b");
if (!f) return Load_DSiNANDMissing; if (!f) return Load_DSiNANDMissing;
// TODO: some basic checks // TODO: some basic checks
// check that it has the nocash footer, and all // check that it has the nocash footer, and all
fclose(f); DSi::SDMMCFile = f;
if (Config::DSiSDEnable)
{
f = Platform::OpenLocalFile(Config::DSiSDPath, "r+b");
if (f)
DSi::SDIOFile = f;
else
DSi::SDIOFile = Platform::OpenLocalFile(Config::DSiSDPath, "w+b");
}
return Load_OK; return Load_OK;
} }
@ -246,6 +256,8 @@ void LoadCheats()
int LoadBIOS() int LoadBIOS()
{ {
DSi::CloseDSiNAND();
int res; int res;
res = VerifyDSBIOS(); res = VerifyDSBIOS();
@ -259,7 +271,7 @@ int LoadBIOS()
res = VerifyDSiFirmware(); res = VerifyDSiFirmware();
if (res != Load_OK) return res; if (res != Load_OK) return res;
res = VerifyDSiNAND(); res = SetupDSiNAND();
if (res != Load_OK) return res; if (res != Load_OK) return res;
} }
else else
@ -366,6 +378,8 @@ int LoadROM(const u8 *romdata, u32 romlength, const char *archivefilename, const
int LoadROM(const char* file, int slot) int LoadROM(const char* file, int slot)
{ {
DSi::CloseDSiNAND();
int res; int res;
bool directboot = Config::DirectBoot != 0; bool directboot = Config::DirectBoot != 0;
@ -386,7 +400,7 @@ int LoadROM(const char* file, int slot)
res = VerifyDSiFirmware(); res = VerifyDSiFirmware();
if (res != Load_OK) return res; if (res != Load_OK) return res;
res = VerifyDSiNAND(); res = SetupDSiNAND();
if (res != Load_OK) return res; if (res != Load_OK) return res;
GBACart::Eject(); GBACart::Eject();
@ -457,10 +471,14 @@ void UnloadROM(int slot)
} }
ROMPath[slot][0] = '\0'; ROMPath[slot][0] = '\0';
DSi::CloseDSiNAND();
} }
int Reset() int Reset()
{ {
DSi::CloseDSiNAND();
int res; int res;
bool directboot = Config::DirectBoot != 0; bool directboot = Config::DirectBoot != 0;
@ -475,7 +493,7 @@ int Reset()
res = VerifyDSiFirmware(); res = VerifyDSiFirmware();
if (res != Load_OK) return res; if (res != Load_OK) return res;
res = VerifyDSiNAND(); res = SetupDSiNAND();
if (res != Load_OK) return res; if (res != Load_OK) return res;
GBACart::Eject(); GBACart::Eject();

View File

@ -109,7 +109,7 @@ void M23_Transform(float* m, float& x, float& y)
} }
void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale) void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int rotation, int sizing, int screenGap, bool integerScale, int swapScreens)
{ {
float refpoints[4][2] = float refpoints[4][2] =
{ {
@ -152,7 +152,7 @@ void SetupScreenLayout(int screenWidth, int screenHeight, int screenLayout, int
(((layout == 0 && (rotation % 2 == 0)) || (layout == 1 && (rotation % 2 == 1)) (((layout == 0 && (rotation % 2 == 0)) || (layout == 1 && (rotation % 2 == 1))
? 192.f : 256.f) ? 192.f : 256.f)
+ screenGap) / 2.f; + screenGap) / 2.f;
if (rotation == 1 || rotation == 2) if ((rotation == 1 || rotation == 2) ^ swapScreens)
offset *= -1.f; offset *= -1.f;
M23_Translate(TopScreenMtx, (idx==0)?-offset:0, (idx==1)?-offset:0); M23_Translate(TopScreenMtx, (idx==0)?-offset:0, (idx==1)?-offset:0);

View File

@ -39,6 +39,7 @@ int WindowMaximized;
int ScreenRotation; int ScreenRotation;
int ScreenGap; int ScreenGap;
int ScreenLayout; int ScreenLayout;
int ScreenSwap;
int ScreenSizing; int ScreenSizing;
int IntegerScaling; int IntegerScaling;
int ScreenFilter; int ScreenFilter;
@ -135,6 +136,7 @@ ConfigEntry PlatformConfigFile[] =
{"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0}, {"ScreenRotation", 0, &ScreenRotation, 0, NULL, 0},
{"ScreenGap", 0, &ScreenGap, 0, NULL, 0}, {"ScreenGap", 0, &ScreenGap, 0, NULL, 0},
{"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0}, {"ScreenLayout", 0, &ScreenLayout, 0, NULL, 0},
{"ScreenSwap", 0, &ScreenSwap, 0, NULL, 0},
{"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0}, {"ScreenSizing", 0, &ScreenSizing, 0, NULL, 0},
{"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0}, {"IntegerScaling", 0, &IntegerScaling, 0, NULL, 0},
{"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0}, {"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0},

View File

@ -53,6 +53,7 @@ extern int WindowMaximized;
extern int ScreenRotation; extern int ScreenRotation;
extern int ScreenGap; extern int ScreenGap;
extern int ScreenLayout; extern int ScreenLayout;
extern int ScreenSwap;
extern int ScreenSizing; extern int ScreenSizing;
extern int IntegerScaling; extern int IntegerScaling;
extern int ScreenFilter; extern int ScreenFilter;

View File

@ -647,7 +647,8 @@ void ScreenHandler::screenSetupLayout(int w, int h)
Config::ScreenRotation, Config::ScreenRotation,
sizing, sizing,
Config::ScreenGap, Config::ScreenGap,
Config::IntegerScaling != 0); Config::IntegerScaling != 0,
Config::ScreenSwap != 0);
Frontend::GetScreenTransforms(screenMatrix[0], screenMatrix[1]); Frontend::GetScreenTransforms(screenMatrix[0], screenMatrix[1]);
} }
@ -1232,6 +1233,12 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
} }
connect(grpScreenLayout, &QActionGroup::triggered, this, &MainWindow::onChangeScreenLayout); connect(grpScreenLayout, &QActionGroup::triggered, this, &MainWindow::onChangeScreenLayout);
submenu->addSeparator();
actScreenSwap = submenu->addAction("Swap screens");
actScreenSwap->setCheckable(true);
connect(actScreenSwap, &QAction::triggered, this, &MainWindow::onChangeScreenSwap);
} }
{ {
QMenu* submenu = menu->addMenu("Screen sizing"); QMenu* submenu = menu->addMenu("Screen sizing");
@ -1315,6 +1322,8 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
actScreenSizing[Config::ScreenSizing]->setChecked(true); actScreenSizing[Config::ScreenSizing]->setChecked(true);
actIntegerScaling->setChecked(Config::IntegerScaling != 0); actIntegerScaling->setChecked(Config::IntegerScaling != 0);
actScreenSwap->setChecked(Config::ScreenSwap != 0);
actScreenFiltering->setChecked(Config::ScreenFilter != 0); actScreenFiltering->setChecked(Config::ScreenFilter != 0);
actShowOSD->setChecked(Config::ShowOSD != 0); actShowOSD->setChecked(Config::ShowOSD != 0);
@ -2163,6 +2172,13 @@ void MainWindow::onChangeScreenLayout(QAction* act)
emit screenLayoutChange(); emit screenLayoutChange();
} }
void MainWindow::onChangeScreenSwap(bool checked)
{
Config::ScreenSwap = checked?1:0;
emit screenLayoutChange();
}
void MainWindow::onChangeScreenSizing(QAction* act) void MainWindow::onChangeScreenSizing(QAction* act)
{ {
int sizing = act->data().toInt(); int sizing = act->data().toInt();

View File

@ -222,6 +222,7 @@ private slots:
void onChangeScreenRotation(QAction* act); void onChangeScreenRotation(QAction* act);
void onChangeScreenGap(QAction* act); void onChangeScreenGap(QAction* act);
void onChangeScreenLayout(QAction* act); void onChangeScreenLayout(QAction* act);
void onChangeScreenSwap(bool checked);
void onChangeScreenSizing(QAction* act); void onChangeScreenSizing(QAction* act);
void onChangeIntegerScaling(bool checked); void onChangeIntegerScaling(bool checked);
void onChangeScreenFiltering(bool checked); void onChangeScreenFiltering(bool checked);
@ -282,6 +283,7 @@ public:
QAction* actScreenGap[6]; QAction* actScreenGap[6];
QActionGroup* grpScreenLayout; QActionGroup* grpScreenLayout;
QAction* actScreenLayout[3]; QAction* actScreenLayout[3];
QAction* actScreenSwap;
QActionGroup* grpScreenSizing; QActionGroup* grpScreenSizing;
QAction* actScreenSizing[4]; QAction* actScreenSizing[4];
QAction* actIntegerScaling; QAction* actIntegerScaling;