仅合并libn3ds所需要的前端代码改动

This commit is contained in:
root 2023-10-12 16:29:11 +08:00
parent e97d8006a1
commit 66f12d92e5
7 changed files with 226 additions and 32 deletions

View File

@ -21,9 +21,9 @@ BUILD := build
SOURCES := ../libn3ds/kernel/source ../libn3ds/source ../libn3ds/source/drivers/mmc \
../libn3ds/source/drivers ../libn3ds/source/arm11 ../libn3ds/source/arm11/allocator \
../libn3ds/source/arm11/drivers ../libn3ds/source/arm11/util/rbtree ../source/arm11 \
../thirdparty/inih
../thirdparty/inih ../source
DATA :=
INCLUDES := ../libn3ds/include ../libn3ds/kernel/include ../libn3ds/thirdparty ../include \
INCLUDES := ../libn3ds/include ../libn3ds/include/arm11 ../libn3ds/kernel/include ../libn3ds/thirdparty ../include \
../thirdparty
DEFINES := -DARM11 -D_3DS -DVERS_STRING=\"$(VERS_STRING)\" \
-DVERS_MAJOR=$(VERS_MAJOR) -DVERS_MINOR=$(VERS_MINOR)

View File

@ -21,7 +21,7 @@ BUILD := build
SOURCES := ../libn3ds/source ../libn3ds/source/drivers/mmc ../libn3ds/source/drivers ../libn3ds/source/arm9 \
../libn3ds/source/arm9/drivers ../libn3ds/thirdparty/fatfs ../source/arm9
DATA :=
INCLUDES := ../libn3ds/include ../libn3ds/thirdparty ../include ../thirdparty
INCLUDES := ../libn3ds/include ../libn3ds/include/arm9 ../libn3ds/thirdparty ../include ../thirdparty
DEFINES := -DARM9 -D_3DS -DVERS_STRING=\"$(VERS_STRING)\" \
-DVERS_MAJOR=$(VERS_MAJOR) -DVERS_MINOR=$(VERS_MINOR)

44
include/oaf_error_codes.h Normal file
View File

@ -0,0 +1,44 @@
#pragma once
/*
* This file is part of open_agb_firm
* Copyright (C) 2022 derrek, profi200
*
* 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/>.
*/
#include "error_codes.h"
#define MAKE_CUSTOM_ERR(e) (CUSTOM_ERR_OFFSET + (e))
// Keep errors in the range of 0-CUSTOM_ERR_OFFSET - 1.
enum
{
// Custom errors.
RES_ROM_TOO_BIG = MAKE_CUSTOM_ERR(0u),
RES_INVALID_PATCH = MAKE_CUSTOM_ERR(1u),
MAX_OAF_RES_VALUE = RES_ROM_TOO_BIG
};
#undef MAKE_CUSTOM_ERR
const char* oafResult2String(Result res);
#ifdef ARM11
void printError(Result res);
void printErrorWaitInput(Result res, u32 waitKeys);
#endif // ifdef ARM11

View File

@ -1,7 +1,9 @@
#include <string.h>
#include "fs.h"
#include "fsutil.h"
#include "drivers/lgy.h"
// @MERGE 231006 START
#include "drivers/lgy11.h"
// @MERGE 231006 END
#include "arm11/keyremix.h"
key_remix_t g_keyremixConfig[KEY_REMIX_LIMIT];
@ -105,7 +107,13 @@ void keyremix_update( uint16_t active_cheatkey )
}
else if( frozen_end == frozen_start )// 空白键位设置,走原来流程就好
{
LGY_handleOverrides();
// @MERGE 231006 START
if( now & KEY_CPAD_MASK ){
*hid_set = (now>>24) ^ KEY_DPAD_MASK;
*hid_mode = KEY_DPAD_MASK;
}
else *hid_mode = 0;
// @MERGE 231006 END
}
else
{

View File

@ -25,6 +25,9 @@
#include "arm11/drivers/hid.h"
#include "arm11/power.h"
#include "arm11/acf.h"
// @MERGE 231006 START
#include "oaf_error_codes.h"
// @MERGE 231006 END
static void setBacklight(void)
{

View File

@ -24,7 +24,9 @@
#include "util.h"
#include "drivers/sha.h"
#include "arm11/drivers/hid.h"
#include "drivers/lgy.h"
// @MERGE 231006 START
#include "drivers/lgy_common.h"
// @MERGE 231006 END
#include "arm11/drivers/lgyfb.h"
#include "arm11/console.h"
#include "arm11/fmt.h"
@ -45,6 +47,9 @@
#include "kernel.h"
#include "kevent.h"
#include "arm11/drivers/codec.h"
// @MERGE 231006 START
#include "oaf_error_codes.h"
// @MERGE 231006 END
#define OAF_WORK_DIR "sdmc:/3ds/open_agb_firm"
@ -113,22 +118,22 @@ Result dump_rom( u32 size )
if( (res=fOpen(&file, "dump.gba", FA_OPEN_ALWAYS|FA_WRITE)) != RES_OK )
return res;
u8 *p = ROM_LOC;
u8 *p = LGY_ROM_LOC;
u32 len;
ee_printf("dumping into dump.gba, file size %ld\n", size);
for( u8 *p=ROM_LOC; size > 0; size-=len, p+=len )
for( u8 *p=LGY_ROM_LOC; size > 0; size-=len, p+=len )
{
res = fWrite( file, p, size < 256 ? size : 256, &len );
if( res != RES_OK )
break;
if( ((u32)p-ROM_LOC) % (1024*4) == 0)
if( ((u32)p-LGY_ROM_LOC) % (1024*4) == 0)
{
res = fSync( file );
if( res != RES_OK)
break;
if( ((u32)p-ROM_LOC) % (1024*64) == 0)
if( ((u32)p-LGY_ROM_LOC) % (1024*64) == 0)
ee_printf("\x1b[3;1Hremaining %ld bytes to dump.\n", size);
}
}
@ -213,14 +218,14 @@ static u32 fixRomPadding(u32 romFileSize)
// Smallest retail ROM chip is 8 Mbit (1 MiB).
u32 romSize = nextPow2(romFileSize);
if(romSize < 0x100000u) romSize = 0x100000u;
memset((void*)(ROM_LOC + romFileSize), 0xFFFFFFFFu, romSize - romFileSize);
memset((void*)(LGY_ROM_LOC + romFileSize), 0xFFFFFFFFu, romSize - romFileSize);
if(romSize > 0x100000u) // >1 MiB.
{
// Fake "open bus" padding.
u32 padding = (ROM_LOC + romSize) / 2;
u32 padding = (LGY_ROM_LOC + romSize) / 2;
padding = __pkhbt(padding, padding + 1, 16); // Copy lower half + 1 to upper half.
for(uintptr_t i = ROM_LOC + romSize; i < ROM_LOC + MAX_ROM_SIZE; i += 4)
for(uintptr_t i = LGY_ROM_LOC + romSize; i < LGY_ROM_LOC + LGY_MAX_ROM_SIZE; i += 4)
{
*(u32*)i = padding;
padding = __uadd16(padding, 0x00020002u); // Unsigned parallel halfword-wise addition.
@ -230,10 +235,10 @@ static u32 fixRomPadding(u32 romFileSize)
{
// ROM mirroring (Classic NES Series/possibly others with 8 Mbit ROM).
// Mirror ROM across the entire 32 MiB area.
for(uintptr_t i = ROM_LOC + romSize; i < ROM_LOC + MAX_ROM_SIZE; i += romSize)
for(uintptr_t i = LGY_ROM_LOC + romSize; i < LGY_ROM_LOC + LGY_MAX_ROM_SIZE; i += romSize)
{
//memcpy((void*)i, (void*)(i - romSize), romSize); // 0x23A15DD
memcpy((void*)i, (void*)ROM_LOC, romSize); // 0x237109B
memcpy((void*)i, (void*)LGY_ROM_LOC, romSize); // 0x237109B
}
}
@ -270,10 +275,17 @@ static Result loadGbaRom(const char *const path, u32 *const romSizeOut)
FHandle f;
if((res = fOpen(&f, path, FA_OPEN_EXISTING | FA_READ)) == RES_OK)
{
u32 fileSize;
if((fileSize = fSize(f)) <= MAX_ROM_SIZE)
// @MERGE 231006 START
u32 fileSize = fSize(f);
if(fileSize > LGY_MAX_ROM_SIZE)
{
u8 *ptr = (u8*)ROM_LOC;
fileSize = LGY_MAX_ROM_SIZE;
ee_puts("Warning: ROM file is too big. Expect crashes.");
}
{
// @MERGE 231006 END
u8 *ptr = (u8*)LGY_ROM_LOC;
u32 read;
while((res = fRead(f, ptr, 0x100000u, &read)) == RES_OK && read == 0x100000u)
ptr += 0x100000u;
@ -284,7 +296,7 @@ static Result loadGbaRom(const char *const path, u32 *const romSizeOut)
&& info_current_cheat(NULL, NULL) == CCHT_OK )
{
char gamecode[5];
memcpy( gamecode, (void*)(ROM_LOC+0xac), 4 );
memcpy( gamecode, (void*)(LGY_ROM_LOC+0xac), 4 );
gamecode[4] = '\0';
acl_open_lib( "gba.acl" );
acl_select_game( gamecode, 0, NULL );
@ -302,11 +314,13 @@ static Result loadGbaRom(const char *const path, u32 *const romSizeOut)
dump_rom( fileSize );
}
#endif
}
else
{
res = RES_ROM_TOO_BIG;
fClose(f);
// @MERGE 231006 START
// else
// {
// res = RES_ROM_TOO_BIG;
// fClose(f);
// }
// @MERGE 231006 END
}
}
@ -366,7 +380,7 @@ static u16 checkSaveOverride(u32 gameCode) // Save type overrides for modern hom
static u16 detectSaveType(u32 romSize)
{
const u32 *romPtr = (u32*)ROM_LOC;
const u32 *romPtr = (u32*)LGY_ROM_LOC;
u16 saveType;
if( g_oafConfig.savePolicy == SAVE_POLICY_SRAM )
{
@ -387,7 +401,7 @@ static u16 detectSaveType(u32 romSize)
else
saveType = defaultSave;
for(; romPtr < (u32*)(ROM_LOC + romSize); romPtr++)
for(; romPtr < (u32*)(LGY_ROM_LOC + romSize); romPtr++)
{
u32 tmp = *romPtr;
@ -508,7 +522,7 @@ static u16 getSaveType(u32 romSize, const char *const savePath)
//const bool saveExists = fStat(savePath, &fi) == RES_OK;
u64 sha1[3];
sha((u32*)ROM_LOC, romSize, (u32*)sha1, SHA_IN_BIG | SHA_1_MODE, SHA_OUT_BIG);
sha((u32*)LGY_ROM_LOC, romSize, (u32*)sha1, SHA_IN_BIG | SHA_1_MODE, SHA_OUT_BIG);
Result res;
GameDbEntry dbEntry;
@ -708,7 +722,9 @@ static void gbaGfxHandler(void *args)
GFX_swapFramebufs();
//if(hidKeysDown() == (KEY_Y | KEY_SELECT)) dumpFrameTex();
CODEC_soundSwitchOutput();
// @MERGE 231006 START
CODEC_runHeadphoneDetection();
// @MERGE 231006 END
}
taskExit();
@ -882,6 +898,57 @@ u16 oafGetBacklightConfig(void)
return g_oafConfig.backlight;
}
// @MERGE 231006 START
KHandle setupFrameCapture(const u8 scaler)
{
const bool is240x160 = scaler < 2;
static const s16 matrix[12 * 8] =
{
// Vertical.
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0x24B0, 0x4000, 0, 0x24B0, 0x4000, 0, 0,
0x4000, 0x2000, 0, 0x4000, 0x2000, 0, 0, 0,
0, -0x4B0, 0, 0, -0x4B0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
// Horizontal.
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0x24B0, 0, 0, 0x24B0, 0, 0,
0x4000, 0x4000, 0x2000, 0x4000, 0x4000, 0x2000, 0, 0,
0, 0, -0x4B0, 0, 0, -0x4B0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
ScalerCfg gbaCfg;
gbaCfg.w = (is240x160 ? 240 : 360);
gbaCfg.h = (is240x160 ? 160 : 240);
gbaCfg.vLen = 6;
gbaCfg.vPatt = 0b00011011;
memcpy(gbaCfg.vMatrix, matrix, 6 * 8 * 2);
gbaCfg.hLen = 6;
gbaCfg.hPatt = (is240x160 ? 0b00111111 : 0b00011011);
if(is240x160)
{
memset(gbaCfg.hMatrix, 0, 6 * 8 * 2);
s16 *const identityRow = &gbaCfg.hMatrix[3 * 8];
for(unsigned i = 0; i < 6; i++)
{
// Set identity entries.
identityRow[i] = 0x4000;
}
}
else
{
memcpy(gbaCfg.hMatrix, &matrix[6 * 8], 6 * 8 * 2);
}
return LGYFB_init(&gbaCfg);
}
// @MERGE 231006 END
Result oafInitAndRun(void)
{
Result res;
@ -937,9 +1004,11 @@ Result oafInitAndRun(void)
#endif
// Initialize the legacy frame buffer and frame handler.
const KHandle frameReadyEvent = createEvent(false);
// @MERGE 231006 START
const KHandle frameReadyEvent = setupFrameCapture(g_oafConfig.scaler);
{
LGYFB_init(frameReadyEvent, g_oafConfig.scaler); // 这里把GBA的输出转换成0x18200000处512x512大小的纹理
//LGYFB_init(frameReadyEvent, g_oafConfig.scaler); // 这里把GBA的输出转换成0x18200000处512x512大小的纹理
// @MERGE 231006 END
patchGbaGpuCmdList(g_oafConfig.scaler);
if( g_oafConfig.scaler == 3u )
{
@ -954,7 +1023,9 @@ Result oafInitAndRun(void)
// Adjust gamma table and sync LgyFb start with LCD VBlank.
adjustGammaTableForGba();
GFX_waitForVBlank0();
LGY_switchMode();
// @MERGE 231006 START
LGY11_switchMode();
// @MERGE 231006 END
}
} while(0);
}
@ -979,5 +1050,7 @@ void oafFinish(void)
deleteEvent(g_frameReadyEvent); // gbaGfxHandler() will automatically terminate.
g_frameReadyEvent = 0;
}
LGY_deinit();
// @MERGE 231006 START
LGY11_deinit();
// @MERGE 231006 END
}

66
source/oaf_error_codes.c Normal file
View File

@ -0,0 +1,66 @@
/*
* This file is part of open_agb_firm
* Copyright (C) 2022 derrek, profi200
*
* 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/>.
*/
#include "oaf_error_codes.h"
#include "drivers/gfx.h"
#ifdef ARM11
#include "arm11/fmt.h"
#include "arm11/drivers/hid.h"
#endif
const char* oafResult2String(Result res)
{
static const char *const oafResultStrings[] =
{
"ROM too big. Max 32 MiB",
"Invalid patch file"
};
return (res < CUSTOM_ERR_OFFSET ? result2String(res) : oafResultStrings[res - CUSTOM_ERR_OFFSET]);
}
#ifdef ARM11
void printError(Result res)
{
ee_printf("Error: %s.\n", oafResult2String(res));
}
void printErrorWaitInput(Result res, u32 waitKeys)
{
printError(res);
// In case we were already in the process of powering off
// don't do so now. Ask the user to press power again.
// Error messages will get lost otherwise.
// Do not clear the power held flag here because the system
// is powering off soon.
(void)hidGetExtraKeys(KEY_POWER);
while(1)
{
GFX_waitForVBlank0();
hidScanInput();
if(hidKeysDown() & waitKeys) break;
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) break;
}
}
#endif // ifdef ARM11