mirror of
https://github.com/LumaTeam/Luma3DS.git
synced 2026-02-22 01:44:38 +00:00
Closes #2137. Even though (when running TWL/AGB FIRM) the SoC is in O3DS mode, and the GPU also is, as well as most other components behaving as such (external RAM, L2C not usable, etc.), this is NOT the case for the LCD and adaptive backlight logic which retains FULL N3DS functionality, including a feature where the window is blended with a given color depending on the overall relative luminance of that window. However, Nintendo's own code mistakenly assumes the opposite, and clearly so ("if GPU in N3DS mode" checks, not passing N3DS extra adaptive backlight (ABL) to TWL/AGB_FIRM). This has implications: - Powersaving (ABL) settings in TWL/AGB_FIRM is inconsistent with *both* O3DS (because the new RGB blend LUT has been set to its current value by NATIVE_FIRM) and N3DS (because "pwn_cnt" and "inertia" are missing their N3DS-only bits) - "rave party" when booting into TWL/AGB_FIRM or O3DS NATIVE_FIRM without these regs (well, the LUT) initialized. Easiest way to do so is by leveraging the "DSi autooboot" feature Luma provides. It is worth noting at least the LUT survives hardware reboots (if Nintendo were using DSi software that was using TLNC-based reboots, they wouldn't have noticed). Only touch the autoboot path, for now
125 lines
3.5 KiB
C
125 lines
3.5 KiB
C
/*
|
|
* This file is part of Luma3DS
|
|
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
* author attributions in that material or in the Appropriate Legal
|
|
* Notices displayed by works containing it.
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
* or requiring that modified versions of such material be marked in
|
|
* reasonable ways as different from the original version.
|
|
*/
|
|
|
|
/*
|
|
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others
|
|
* Screen deinit code by tiniVi
|
|
*/
|
|
|
|
#include "screen.h"
|
|
#include "config.h"
|
|
#include "memory.h"
|
|
#include "i2c.h"
|
|
#include "utils.h"
|
|
|
|
bool needToSetupScreens = true;
|
|
|
|
struct fb fbs[2] =
|
|
{
|
|
{
|
|
.top_left = (u8 *)0x18300000,
|
|
.top_right = (u8 *)0x18300000,
|
|
.bottom = (u8 *)0x18346500,
|
|
},
|
|
{
|
|
.top_left = (u8 *)0x18400000,
|
|
.top_right = (u8 *)0x18400000,
|
|
.bottom = (u8 *)0x18446500,
|
|
},
|
|
};
|
|
|
|
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
|
|
|
|
static volatile Arm11Operation *operation = (volatile Arm11Operation *)0x1FF80004;
|
|
|
|
static void invokeArm11Function(Arm11Operation op)
|
|
{
|
|
while(*operation != ARM11_READY);
|
|
*operation = op;
|
|
while(*operation != ARM11_READY);
|
|
}
|
|
|
|
void prepareArm11ForFirmlaunch(void)
|
|
{
|
|
invokeArm11Function(PREPARE_ARM11_FOR_FIRMLAUNCH);
|
|
}
|
|
|
|
void deinitScreens(void)
|
|
{
|
|
if(ARESCREENSINITIALIZED) invokeArm11Function(DEINIT_SCREENS);
|
|
}
|
|
|
|
void updateBrightness(u32 brightnessIndex)
|
|
{
|
|
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[brightnessIndex];
|
|
invokeArm11Function(UPDATE_BRIGHTNESS);
|
|
}
|
|
|
|
void swapFramebuffers(bool isAlternate)
|
|
{
|
|
*(volatile bool *)ARM11_PARAMETERS_ADDRESS = isAlternate;
|
|
invokeArm11Function(SWAP_FRAMEBUFFERS);
|
|
}
|
|
|
|
void clearScreens(bool isAlternate)
|
|
{
|
|
struct fb *fbTemp = isAlternate ? &fbs[1] : &fbs[0];
|
|
|
|
*(volatile struct fb *)ARM11_PARAMETERS_ADDRESS = *fbTemp;
|
|
invokeArm11Function(CLEAR_SCREENS);
|
|
}
|
|
|
|
void initScreens(void)
|
|
{
|
|
if(needToSetupScreens)
|
|
{
|
|
if(!ARESCREENSINITIALIZED || bootType == FIRMLAUNCH)
|
|
{
|
|
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
|
|
memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs));
|
|
invokeArm11Function(INIT_SCREENS);
|
|
|
|
//Turn on backlight
|
|
I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A);
|
|
wait(5);
|
|
}
|
|
else updateBrightness(MULTICONFIG(BRIGHTNESS));
|
|
|
|
memcpy((void *)ARM11_PARAMETERS_ADDRESS, fbs, sizeof(fbs));
|
|
invokeArm11Function(SETUP_FRAMEBUFFERS);
|
|
|
|
clearScreens(true);
|
|
needToSetupScreens = false;
|
|
}
|
|
|
|
clearScreens(false);
|
|
swapFramebuffers(false);
|
|
}
|
|
|
|
void zerofillN3dsAblRegisters(void)
|
|
{
|
|
invokeArm11Function(ZEROFILL_N3DS_ABL_REGISTERS);
|
|
} |