Skip to content

Commit

Permalink
Changed default to be more compatible; added more options
Browse files Browse the repository at this point in the history
  • Loading branch information
xzn committed Jan 22, 2024
1 parent 5fd3647 commit 4c8b21b
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 177 deletions.
1 change: 1 addition & 0 deletions include/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define FUNC_H


extern int cpuClockLockValue;
void setCpuClockLock(int v);
void lockCpuClock(void);
void setExitFlag(void);
Expand Down
4 changes: 3 additions & 1 deletion include/ns/ns.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ typedef struct _NS_CONFIG {
u32 rpConfigLock;
u32 rpGamePid;
u32 rpCapturePreviousFrameThanCurrent;
u32 plgDisabled;
u32 plgNoCTRPFCompat;
u32 plgRemotePlayCallback;
u32 plgNoLoaderMem;
u32 plgCTRPFCompat;
} NS_CONFIG;

#define NS_INITMODE_FROMBOOT 0
Expand Down
4 changes: 3 additions & 1 deletion include/ntr_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ typedef struct _NTR_CONFIG {
/* BootNTR's NTR_CONFIG ends here */
u32 debugMore;
u32 gameHasPlugins;
u32 ctrpfCompat;
u32 noCTRPFCompat;
u32 remotePlayBoost;
u32 nightShiftLevel;
} NTR_CONFIG;

#define NTR_MEMMODE_DEFAULT (0)
Expand Down
90 changes: 44 additions & 46 deletions source/dsp/nightshift.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "global.h"

extern PLGLOADER_INFO *g_plgInfo;

#define NIGHT_SHIFT_RGB565_B(level) \
pix = *((u32*)(sp)); \
pix = (pix & 0xffe0ffe0) | (((pix & 0x001f001f) >> level) & 0x001f001f); \
*((u32*)(sp)) = pix; \
sp += 2;
sp += 2;

#define NIGHT_SHIFT_RGB888_B(level) \
pix = *((u32*)(sp)); \
Expand All @@ -16,13 +14,13 @@ extern PLGLOADER_INFO *g_plgInfo;
sp[2] >>= level; \
sp += 4; \
sp[1] >>= level; \
sp += 4;
sp += 4;

#define NIGHT_SHIFT_RGB565_B_G(levelb, levelg) \
pix = *((u32*)(sp)); \
pix = (pix & 0xf800f800) | (((pix & 0x07e007e0) >> levelg) & 0x07e007e0) | (((pix & 0x001f001f) >> levelb) & 0x001f001f) ; \
*((u32*)(sp)) = pix; \
sp += 2;
sp += 2;

#define REPEAT_8(a) a;a;a;a;a;a;a;a;
#define REPEAT_4(a) a;a;a;a;
Expand All @@ -36,15 +34,15 @@ extern PLGLOADER_INFO *g_plgInfo;
pix |= b >> levelb; \
pix |= (g >> levelg) << 5; \
*sp = pix; \
sp++;
sp++;

#define NIGHT_SHIFT_RGB565_B_UNALIGNED(levelb) \
pix = *sp; \
b = (pix & 0x1f); \
pix &= 0xffe0; \
pix |= b >> levelb; \
*sp = pix; \
sp++;
sp++;

#define NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg) \
sp[0] >>= levelb; \
Expand All @@ -58,7 +56,7 @@ extern PLGLOADER_INFO *g_plgInfo;
sp += 3; \
sp[0] >>= levelb; \
sp[1] >>= levelg; \
sp += 3;
sp += 3;


#define INVERT_RGB888_UNALIGNED() \
Expand All @@ -67,25 +65,25 @@ extern PLGLOADER_INFO *g_plgInfo;
*((u32*)sp) = 0xffffffffUL - *((u32*)sp); \
sp += 4; \
*((u32*)sp) = 0xffffffffUL - *((u32*)sp); \
sp += 4;
sp += 4;


#define INVERT_RGB565_UNALIGNED() \
*((u32*)sp) = 0xffffffffUL - *((u32*)sp); \
sp += 2;
sp += 2;

#define GRAYSCALE_RGB888_UNALIGNED() \
gray = (u16)(sp[0] + sp[1] + sp[2]) / 3; \
sp[0] = gray; \
sp[1] = gray; \
sp[2] = gray; \
sp += 3;
sp += 3;

#define GRAYSCALE_RGB565_UNALIGNED() \
pix = *sp; \
gray = (u16)((pix & 0x1f) + ((pix >> 6) & 0x1f) + ((pix >> 11) & 0x1f)) / 3; \
*sp = gray | (gray << 6) | (gray << 11); \
sp++;
sp++;

/*
BGRB GRBG RBGR
Expand Down Expand Up @@ -158,22 +156,22 @@ NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel3, 3);
NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel2, 2);
NIGHT_SHIFT_TEMPLATE_B(plgNightShiftFramebufferLevel1, 1);*/

static inline __attribute__((always_inline)) u32 plgNightShift3(u32 addr, u32 stride, u32 height, u32 format, u32 levelb, u32 levelg, u32 isAligned) {
format &= 0x0f;
u32 r;
if (format == 2) {
for (r = 0; r < height; r++) {
u16* sp = (u16*)addr;
u16* spEnd = (u16*)(addr + 240 * 2);
while (sp < spEnd) {
static inline __attribute__((always_inline)) u32 plgNightShift3(u32 addr, u32 stride, u32 height, u32 format, u32 levelb, u32 levelg, u32 isAligned) {
format &= 0x0f;
u32 r;
if (format == 2) {
for (r = 0; r < height; r++) {
u16* sp = (u16*)addr;
u16* spEnd = (u16*)(addr + 240 * 2);
while (sp < spEnd) {

if (isAligned) {
if (levelg) {
u32 pix;
REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg));
REPEAT_8(NIGHT_SHIFT_RGB565_B_G(levelb, levelg));
} else {
u32 pix;
REPEAT_8(NIGHT_SHIFT_RGB565_B(levelb));
REPEAT_8(NIGHT_SHIFT_RGB565_B(levelb));
}
} else {
if (levelg) {
Expand All @@ -187,28 +185,28 @@ static inline __attribute__((always_inline)) u32 plgNightShift3(u32 addr, u32 st
}
}

}
addr += stride;
}
}
else if (format == 1) {
for (r = 0; r < height; r++) {
u8* sp = (u8*)addr;
u8* spEnd = (u8*)(addr + 240 * 3);
while (sp < spEnd) {
}
addr += stride;
}
}
else if (format == 1) {
for (r = 0; r < height; r++) {
u8* sp = (u8*)addr;
u8* spEnd = (u8*)(addr + 240 * 3);
while (sp < spEnd) {
if (isAligned && (levelg == 0)) {
u32 pix;
REPEAT_4(NIGHT_SHIFT_RGB888_B(levelb));
} else {
REPEAT_4(NIGHT_SHIFT_RGB888_B_G_UNALIGNED(levelb, levelg));
}
}
addr += stride;
}
}
svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, stride * height);
return 0;

}
addr += stride;
}
}
svc_flushProcessDataCache(CURRENT_PROCESS_HANDLE, (u32)addr, stride * height);
return 0;
}

static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 stride, u32 height, u32 format, u32 type) {
Expand Down Expand Up @@ -260,25 +258,25 @@ static inline __attribute__((always_inline)) u32 plgScreenFilter(u32 addr, u32 s


static inline __attribute__((always_inline)) u32 plgNightShift2(u32 addr, u32 stride, u32 height, u32 format, u32 isAligned) {
if (g_plgInfo->nightShiftLevel == 1) {
if (ntrConfig->nightShiftLevel == 1) {
return plgNightShift3(addr, stride, height, format, 1, 0, isAligned);
}
if (g_plgInfo->nightShiftLevel == 2) {
if (ntrConfig->nightShiftLevel == 2) {
return plgNightShift3(addr, stride, height, format, 2, 0, isAligned);
}
if (g_plgInfo->nightShiftLevel == 3) {
if (ntrConfig->nightShiftLevel == 3) {
return plgNightShift3(addr, stride, height, format, 3, 0, isAligned);
}
if (g_plgInfo->nightShiftLevel == 4) {
if (ntrConfig->nightShiftLevel == 4) {
return plgNightShift3(addr, stride, height, format, 3, 1, isAligned);
}
if (g_plgInfo->nightShiftLevel == 5) {
if (ntrConfig->nightShiftLevel == 5) {
return plgNightShift3(addr, stride, height, format, 4, 1, isAligned);
}
if (g_plgInfo->nightShiftLevel == 6) {
if (ntrConfig->nightShiftLevel == 6) {
return plgScreenFilter(addr, stride, height, format, 1);
}
if (g_plgInfo->nightShiftLevel == 7) {
if (ntrConfig->nightShiftLevel == 7) {
return plgScreenFilter(addr, stride, height, format, 2);
}
return 0;
Expand Down
5 changes: 3 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,9 @@ int main(void) {

threadStack = (u32*)((u32)NS_CONFIGURE_ADDR + 0x1000);
if (
(ntrConfig->debugMore && currentPid == ntrConfig->PMPid) ||
isInDebugMode() ||
(ntrConfig->debugMore &&
(currentPid == ntrConfig->PMPid || g_nsConfig->startupCommand == NS_STARTCMD_INJECTGAME)
) ||
(g_nsConfig->startupCommand == NS_STARTCMD_DEBUG)
) {
svc_createThread(&handle, (void*)startupFromInject, 0, &threadStack[(STACK_SIZE / 4) - 10], 0x3f, 0xFFFFFFFE);
Expand Down
17 changes: 11 additions & 6 deletions source/ns/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,11 @@ static inline int nsRemotePlayControl(RP_CONFIG *config, u8 skipControl) {
}

static int nsInitRemotePlay(RP_CONFIG *config, u32 skipControl) {
if (!ntrConfig->isNew3DS) {
showDbg("Remote Play is available on New 3DS only.", 0, 0);
return -1;
}

if (!((config->quality >= 10) && (config->quality <= 100))) {
nsDbgPrint("out-of-range quality for remote play, limiting to between 10 and 100\n");
if (config->quality < 10)
Expand Down Expand Up @@ -2338,11 +2343,6 @@ static int nsInitRemotePlay(RP_CONFIG *config, u32 skipControl) {

u8 desiredHeader[16] = { 0x04, 0x00, 0x2D, 0xE5, 0x4F, 0x00, 0x00, 0xEF, 0x00, 0x20, 0x9D, 0xE5, 0x00, 0x10, 0x82, 0xE5 };
u8 buf[16] = { 0 };
if (!(ntrConfig->isNew3DS)) {
nsDbgPrint("Remote Play is available on New 3DS only.", 0, 0);
ret = -1;
goto final;
}

int isFirmwareSupported = 0;
int firmwareType = 0;
Expand Down Expand Up @@ -2380,7 +2380,7 @@ static int nsInitRemotePlay(RP_CONFIG *config, u32 skipControl) {
svc_closeHandle(hProcess);
}
if (ret) {
showDbg("Starting remote play failed: %d, retry maybe.", ret, 0);
showDbg("Starting remote play failed: %d. Retry maybe...", ret, 0);
__atomic_clear(&nsIsRemotePlayStarted, __ATOMIC_RELAXED);
}
return ret;
Expand Down Expand Up @@ -2664,6 +2664,11 @@ static void rpChangeFrameCaptureMode(void) {
}

int remotePlayMenu(u32 localaddr) {
if (!ntrConfig->isNew3DS) {
showDbg("Remote Play is available on New 3DS only.", 0, 0);
return 0;
}

u32 daddrCurrent = REG(&g_nsConfig->rpConfig.dstAddr);

rpConfig.dstAddr = daddrCurrent;
Expand Down

0 comments on commit 4c8b21b

Please sign in to comment.