Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nintendo 3DS port #408

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "lib/BRender-v1.3.2"]
path = lib/BRender-v1.3.2
url = https://github.com/dethrace-labs/BRender-v1.3.2.git
url = https://github.com/MrHuu/BRender-v1.3.2.git
branch = 3DS
55 changes: 55 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,58 @@ if(DETHRACE_INSTALL)

include(CPack)
endif()

if (NINTENDO_3DS)
set(APP_TITLE "${PROJECT_NAME}")
set(APP_DESCRIPTION "${PROJECT_NAME} port for 3DS")
set(APP_AUTHOR "dethrace-labs")
set(APP_UNIQUE_ID "0xF02F6")
set(APP_ICON "${PROJECT_SOURCE_DIR}/packaging/ctr/icon.png")
set(APP_BANNER "${PROJECT_SOURCE_DIR}/packaging/ctr/banner.png")
set(APP_AUDIO "${PROJECT_SOURCE_DIR}/packaging/ctr/audio_silent.wav")
set(APP_ROMFS_DIR "${PROJECT_SOURCE_DIR}/packaging/ctr/romfs")
set(APP_RSF "${PROJECT_SOURCE_DIR}/packaging/ctr/template.rsf")

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.3dsx
COMMAND 3dsxtool ${PROJECT_NAME}.elf ${PROJECT_NAME}${ROM}.3dsx
--romfs=${APP_ROMFS_DIR}
--smdh=${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.smdh
DEPENDS ${PROJECT_NAME} ${PROJECT_NAME}.smdh
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cia
COMMAND makerom -f cia
-target t
-exefslogo
-o ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.cia
-elf ${PROJECT_NAME}.elf
-rsf ${APP_RSF}
-DAPP_TITLE=${APP_TITLE}
-DAPP_UNIQUE_ID=${APP_UNIQUE_ID}
-DAPP_ROMFS_DIR=${APP_ROMFS_DIR}
-banner ${PROJECT_NAME}.bnr
-icon ${PROJECT_NAME}.smdh
DEPENDS ${PROJECT_NAME} ${APP_RSF} ${PROJECT_NAME}.smdh ${PROJECT_NAME}.bnr
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.smdh
COMMAND bannertool makesmdh -o ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.smdh
-s ${APP_TITLE}
-l ${APP_DESCRIPTION}
-p ${APP_AUTHOR}
-i ${APP_ICON}

OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bnr
COMMAND bannertool makebanner -o ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bnr
-i ${APP_BANNER}
-a ${APP_AUDIO}
)

add_custom_target( N3DS ALL
DEPENDS ${PROJECT_NAME}.3dsx
${PROJECT_NAME}.cia
)
endif ()
2 changes: 1 addition & 1 deletion lib/BRender-v1.3.2
9 changes: 8 additions & 1 deletion lib/miniaudio/include/miniaudio/miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16116,9 +16116,11 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
#endif
} else if (priority == ma_thread_priority_realtime) {
#ifdef SCHED_FIFO
#ifndef __3DS__
if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO) == 0) {
scheduler = SCHED_FIFO;
}
#endif
#endif
#ifdef MA_LINUX
} else {
Expand All @@ -16131,7 +16133,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
if (stackSize > 0) {
pthread_attr_setstacksize(&attr, stackSize);
}

#ifndef __3DS__
if (scheduler != -1) {
int priorityMin = sched_get_priority_min(scheduler);
int priorityMax = sched_get_priority_max(scheduler);
Expand All @@ -16157,6 +16159,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
pthread_attr_setschedparam(&attr, &sched);
}
}
#endif
}
#else
/* It's the emscripten build. We'll have a few unused parameters. */
Expand Down Expand Up @@ -74085,6 +74088,10 @@ static ma_uint64 ma_engine_node_get_required_input_frame_count(const ma_engine_n

static ma_result ma_engine_node_set_volume(ma_engine_node* pEngineNode, float volume)
{
#ifdef __3DS__
// Without this hack, some sounds overflow causing horrible crackling
volume /= 2.0f;
#endif
if (pEngineNode == NULL) {
return MA_INVALID_ARGS;
}
Expand Down
Binary file added packaging/ctr/audio_silent.wav
Binary file not shown.
Binary file added packaging/ctr/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packaging/ctr/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packaging/ctr/romfs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
219 changes: 219 additions & 0 deletions packaging/ctr/template.rsf
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
BasicInfo:
Title : $(APP_TITLE)
ProductCode : $(APP_PRODUCT_CODE)
Logo : Nintendo # Nintendo / Licensed / Distributed / iQue / iQueForSystem

RomFs:
# Specifies the root path of the read only file system to include in the ROM.
RootPath : $(APP_ROMFS)

TitleInfo:
Category : Application
UniqueId : $(APP_UNIQUE_ID)

Option:
UseOnSD : true # true if App is to be installed to SD
FreeProductCode : true # Removes limitations on ProductCode
MediaFootPadding : false # If true CCI files are created with padding
EnableCrypt : false # Enables encryption for NCCH and CIA
EnableCompress : false # Compresses where applicable (currently only exefs:/.code)

AccessControlInfo:
CoreVersion : 2

# Exheader Format Version
DescVersion : 2

# Minimum Required Kernel Version (below is for 4.5.0)
ReleaseKernelMajor : "02"
ReleaseKernelMinor : "33"

# ExtData
UseExtSaveData : false # enables ExtData
#ExtSaveDataId : 0x300 # only set this when the ID is different to the UniqueId

# FS:USER Archive Access Permissions
# Uncomment as required
FileSystemAccess:
#- CategorySystemApplication
#- CategoryHardwareCheck
- CategoryFileSystemTool
#- Debug
#- TwlCardBackup
#- TwlNandData
#- Boss
- DirectSdmc
#- Core
#- CtrNandRo
#- CtrNandRw
#- CtrNandRoWrite
#- CategorySystemSettings
#- CardBoard
#- ExportImportIvs
#- DirectSdmcWrite
#- SwitchCleanup
#- SaveDataMove
#- Shop
#- Shell
#- CategoryHomeMenu

# Process Settings
MemoryType : Application # Application/System/Base
SystemMode : 80MB # 64MB(Default)/96MB/80MB/72MB/32MB
IdealProcessor : 0
AffinityMask : 1
Priority : 16
MaxCpu : 0x9E # Default
HandleTableSize : 0x200
DisableDebug : false
EnableForceDebug : false
CanWriteSharedPage : true
CanUsePrivilegedPriority : false
CanUseNonAlphabetAndNumber : true
PermitMainFunctionArgument : true
CanShareDeviceMemory : true
RunnableOnSleep : false
SpecialMemoryArrange : true

# New3DS Exclusive Process Settings
SystemModeExt : 124MB # Legacy(Default)/124MB/178MB Legacy:Use Old3DS SystemMode
CpuSpeed : 804MHz # 256MHz(Default)/804MHz
EnableL2Cache : true # false(default)/true
CanAccessCore2 : true

# Virtual Address Mappings
IORegisterMapping:
- 1ff00000-1ff7ffff # DSP memory
MemoryMapping:
- 1f000000-1f5fffff:r # VRAM

# Accessible SVCs, <Name>:<ID>
SystemCallAccess:
ArbitrateAddress: 34
Backdoor: 123
Break: 60
CancelTimer: 28
ClearEvent: 25
ClearTimer: 29
CloseHandle: 35
ConnectToPort: 45
ControlMemory: 1
ControlProcessMemory: 112
CreateAddressArbiter: 33
CreateEvent: 23
CreateMemoryBlock: 30
CreateMutex: 19
CreateSemaphore: 21
CreateThread: 8
CreateTimer: 26
DuplicateHandle: 39
ExitProcess: 3
ExitThread: 9
GetCurrentProcessorNumber: 17
GetHandleInfo: 41
GetProcessId: 53
GetProcessIdOfThread: 54
GetProcessIdealProcessor: 6
GetProcessInfo: 43
GetResourceLimit: 56
GetResourceLimitCurrentValues: 58
GetResourceLimitLimitValues: 57
GetSystemInfo: 42
GetSystemTick: 40
GetThreadContext: 59
GetThreadId: 55
GetThreadIdealProcessor: 15
GetThreadInfo: 44
GetThreadPriority: 11
MapMemoryBlock: 31
OutputDebugString: 61
QueryMemory: 2
ReleaseMutex: 20
ReleaseSemaphore: 22
SendSyncRequest1: 46
SendSyncRequest2: 47
SendSyncRequest3: 48
SendSyncRequest4: 49
SendSyncRequest: 50
SetThreadPriority: 12
SetTimer: 27
SignalEvent: 24
SleepThread: 10
UnmapMemoryBlock: 32
WaitSynchronization1: 36
WaitSynchronizationN: 37

# Service List
# Maximum 34 services (32 if firmware is prior to 9.6.0)
ServiceAccessControl:
- APT:U
- ac:u
- am:net
- boss:U
- cam:u
- cecd:u
- cfg:nor
- cfg:u
- csnd:SND
- dsp::DSP
- frd:u
- fs:USER
- gsp::Gpu
- hid:USER
- http:C
- ir:rst
- ir:u
- ir:USER
- mic:u
- ndm:u
- news:u
- nwm::UDS
- ptm:u
- pxi:dev
- soc:U
- ssl:C
- y2r:u


SystemControlInfo:
SaveDataSize: 0KB # Change if the app uses savedata
RemasterVersion: 2
StackSize: 0x40000

# Modules that run services listed above should be included below
# Maximum 48 dependencies
# <module name>:<module titleid>
Dependency:
ac: 0x0004013000002402
act: 0x0004013000003802
am: 0x0004013000001502
boss: 0x0004013000003402
camera: 0x0004013000001602
cecd: 0x0004013000002602
cfg: 0x0004013000001702
codec: 0x0004013000001802
csnd: 0x0004013000002702
dlp: 0x0004013000002802
dsp: 0x0004013000001a02
friends: 0x0004013000003202
gpio: 0x0004013000001b02
gsp: 0x0004013000001c02
hid: 0x0004013000001d02
http: 0x0004013000002902
i2c: 0x0004013000001e02
ir: 0x0004013000003302
mcu: 0x0004013000001f02
mic: 0x0004013000002002
ndm: 0x0004013000002b02
news: 0x0004013000003502
nfc: 0x0004013000004002
nim: 0x0004013000002c02
nwm: 0x0004013000002d02
pdn: 0x0004013000002102
ps: 0x0004013000003102
ptm: 0x0004013000002202
qtm: 0x0004013020004202
ro: 0x0004013000003702
socket: 0x0004013000002e02
spi: 0x0004013000002302
ssl: 0x0004013000002f02
11 changes: 11 additions & 0 deletions src/DETHRACE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ else()
-Wstrict-prototypes
)
endif()

if (NINTENDO_3DS)
target_compile_options(dethrace_obj PRIVATE
-O3 -funroll-loops -fno-math-errno -ffast-math
)
endif()

target_compile_definitions(dethrace_obj PRIVATE INSIDE_DETHRACE)
if(DETHRACE_FIX_BUGS)
target_compile_definitions(dethrace_obj PRIVATE DETHRACE_FIX_BUGS)
Expand Down Expand Up @@ -183,6 +190,10 @@ if(MSVC)
target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED -DWIN32_LEAN_AND_MEAN)
endif()

if (NINTENDO_3DS)
target_compile_definitions(dethrace PRIVATE -DSDL_MAIN_HANDLED)
endif()

if(DETHRACE_IDE_ROOT_DIR)
set_target_properties(dethrace PROPERTIES
VS_DEBUGGER_ENVIRONMENT "DETHRACE_ROOT_DIR=${DETHRACE_IDE_ROOT_DIR}"
Expand Down
Loading