3ds: Port refactor.

This commit does the following changes to the 3ds port:

- Rename the target from ctru to 3ds.
- Rename all files and functions with the ctru naming convention to 3ds.
- Created a new file and folder structure that will better integrate future console ports that share the same codebase.
- Fixed a buffer overflow bug in pcm code.

Change-Id: I17c6f86df64eb99dd2b653485d70832ff46b2ba8
This commit is contained in:
Mauricio Garrido 2026-08-31 18:02:32 -06:00 • committed by Solomon Peachy
parent 8e965d9159
commit e498c0171a
130 changed files with 1429 additions and 1112 deletions

View file

@ -300,8 +300,8 @@ keymaps/keymap-echor1.c
keymaps/keymap-surfansf28.c
#elif CONFIG_KEYPAD == RG_NANO_PAD
keymaps/keymap-rgnano.c
#elif CONFIG_KEYPAD == CTRU_PAD
keymaps/keymap-ctru.c
#elif CONFIG_KEYPAD == N3DS_PAD
keymaps/keymap-3ds.c
#elif CONFIG_KEYPAD == HIBY_R3PROII_PAD
keymaps/keymap-hibyr3proii.c
#elif CONFIG_KEYPAD == HIDIZS_AP80MAX_PAD

View file

@ -18,7 +18,7 @@
*
****************************************************************************/
/* Button Code Definitions for Civic Type R (ctru) target */
/* Button Code Definitions for the Nintendo 3DS target */
#include <stdio.h>
#include <string.h>

View file

@ -74,7 +74,7 @@ mikmod
(CONFIG_KEYPAD == SANSA_FUZE_PAD) || (CONFIG_KEYPAD == SANSA_E200_PAD) || \
(CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
(CONFIG_KEYPAD == IPOD_1G2G_PAD || CONFIG_KEYPAD == SAMSUNG_YPR0_PAD) || \
(CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD) || (CONFIG_KEYPAD == CTRU_PAD) || (CONFIG_KEYPAD == EROSQ_PAD)
(CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD) || (CONFIG_KEYPAD == N3DS_PAD) || (CONFIG_KEYPAD == EROSQ_PAD)
/* PDBox is confirmed to run on these player models. */
pdbox
#endif

View file

@ -258,7 +258,7 @@ struct battery_tables_t {
#define BATTERY_ON_TXT "A"
#define BATTERY_OFF_TXT "X"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define BATTERY_ON BUTTON_SELECT
#define BATTERY_OFF BUTTON_BACK
#define BATTERY_ON_TXT "A - start"

View file

@ -611,7 +611,7 @@ enum {
#define BJACK_RIGHT BUTTON_RIGHT
#define BJACK_LEFT BUTTON_LEFT
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define BJACK_SELECT_NAME "A"
#define BJACK_STAY_NAME "X"
#define BJACK_QUIT_NAME "B"

View file

@ -373,7 +373,7 @@ CONFIG_KEYPAD == SANSA_M200_PAD
#define UP BUTTON_UP
#define DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define QUIT BUTTON_BACK
#define LEFT BUTTON_LEFT
#define RIGHT BUTTON_RIGHT

View file

@ -546,7 +546,7 @@ F3: equal to "="
#define CALCULATOR_CALC BUTTON_X
#define CALCULATOR_CLEAR BUTTON_B
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define CALCULATOR_LEFT BUTTON_LEFT
#define CALCULATOR_RIGHT BUTTON_RIGHT

View file

@ -432,7 +432,7 @@
#define CALENDAR_PREV_MONTH BUTTON_L
#define CALENDAR_EVENT_MENU_NAME "A"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define CALENDAR_QUIT BUTTON_BACK
#define CALENDAR_SELECT BUTTON_SELECT
#define CALENDAR_NEXT_WEEK BUTTON_DOWN

View file

@ -599,7 +599,7 @@
#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
#define CB_RC_QUIT BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define CB_SELECT BUTTON_SELECT
#define CB_UP BUTTON_UP
#define CB_DOWN BUTTON_DOWN

View file

@ -407,7 +407,7 @@
#define CHC_SETTINGS_OK BUTTON_A
#define CHC_SETTINGS_CANCEL BUTTON_B
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define CHC_QUIT BUTTON_BACK
#define CHC_STARTSTOP BUTTON_SELECT
#define CHC_RESET BUTTON_USER

View file

@ -1301,7 +1301,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define CHIP8_KEY9 BUTTON_R
#define CHIP8_KEY0 BUTTON_L
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
#define CHIP8_OFF (BUTTON_BACK|BUTTON_REPEAT)
#define CHIP8_KEY1 BUTTON_MENU
#define CHIP8_KEY2 BUTTON_UP

View file

@ -206,7 +206,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define ACTION2 BUTTON_B
#define ACTIONTEXT "A"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define QUIT BUTTON_BACK
#define ACTION BUTTON_SELECT
#define ACTION2 BUTTON_MENU

View file

@ -324,7 +324,7 @@
#define CLIX_BUTTON_UP BUTTON_UP
#define CLIX_BUTTON_DOWN BUTTON_DOWN
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
#define CLIX_BUTTON_QUIT BUTTON_BACK
#define CLIX_BUTTON_LEFT BUTTON_LEFT
#define CLIX_BUTTON_RIGHT BUTTON_RIGHT

View file

@ -414,7 +414,7 @@
#define CUBE_PAUSE BUTTON_A
#define CUBE_HIGHSPEED BUTTON_Y
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
#define CUBE_QUIT BUTTON_BACK
#define CUBE_NEXT BUTTON_RIGHT
#define CUBE_PREV BUTTON_LEFT

View file

@ -632,7 +632,7 @@ void I_ShutdownGraphics(void)
#define DOOMBUTTON_WEAPON BUTTON_X
#define DOOMBUTTON_MAP BUTTON_Y
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define DOOMBUTTON_UP BUTTON_UP
#define DOOMBUTTON_DOWN BUTTON_DOWN
#define DOOMBUTTON_LEFT BUTTON_LEFT

View file

@ -510,7 +510,7 @@
#define FLIPIT_STEP_BY_STEP BUTTON_Y
#define FLIPIT_TOGGLE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define FLIPIT_LEFT BUTTON_LEFT
#define FLIPIT_RIGHT BUTTON_RIGHT

View file

@ -518,7 +518,7 @@
#define FRACTAL_PRECISION_DEC BUTTON_L
#define FRACTAL_RESET BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define FRACTAL_QUIT BUTTON_BACK
#define FRACTAL_UP BUTTON_UP
#define FRACTAL_DOWN BUTTON_DOWN

View file

@ -509,7 +509,7 @@
#define GBN_BUTTON_CONTEXT BUTTON_X
#define GBN_BUTTON_NEXT_VAR BUTTON_Y
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
#define GBN_BUTTON_UP BUTTON_UP
#define GBN_BUTTON_DOWN BUTTON_DOWN
#define GBN_BUTTON_LEFT BUTTON_LEFT

View file

@ -559,7 +559,7 @@
#define IMGVIEW_MENU BUTTON_B
#define IMGVIEW_QUIT BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define IMGVIEW_ZOOM_IN BUTTON_POWER
#define IMGVIEW_ZOOM_OUT BUTTON_USER
#define IMGVIEW_UP BUTTON_UP

View file

@ -297,7 +297,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define RIGHT BUTTON_RIGHT
#define FIRE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define QUIT BUTTON_POWER
#define LEFT BUTTON_LEFT

View file

@ -389,7 +389,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define HK_SELECT "A"
#define HK_CANCEL "START"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define JEWELS_UP BUTTON_UP
#define JEWELS_DOWN BUTTON_DOWN
#define JEWELS_LEFT BUTTON_LEFT

View file

@ -274,7 +274,7 @@
#define BTN_FIRE BUTTON_A
#define BTN_PAUSE BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define BTN_UP BUTTON_UP
#define BTN_DOWN BUTTON_DOWN
#define BTN_LEFT BUTTON_LEFT
@ -319,7 +319,7 @@
(CONFIG_KEYPAD != SHANLING_Q1_PAD) && \
(CONFIG_KEYPAD != HIBY_R3PROII_PAD) && \
(CONFIG_KEYPAD != HIDIZS_AP80MAX_PAD) && \
(CONFIG_KEYPAD != CTRU_PAD)
(CONFIG_KEYPAD != N3DS_PAD)
#define BTN_FIRE BUTTON_BOTTOMLEFT
#define BTN_PAUSE BUTTON_TOPLEFT
#endif

View file

@ -284,7 +284,7 @@ const struct button_mapping pla_main_ctx[] =
{ PLA_DOWN_REPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
{ PLA_LEFT_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
{ PLA_RIGHT_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
{ PLA_UP, BUTTON_UP, BUTTON_NONE },
{ PLA_DOWN, BUTTON_DOWN, BUTTON_NONE },
{ PLA_LEFT, BUTTON_LEFT, BUTTON_NONE },
@ -543,7 +543,7 @@ const struct button_mapping pla_main_ctx[] =
{PLA_SELECT, BUTTON_A, BUTTON_NONE},
{PLA_SELECT_REL, BUTTON_A|BUTTON_REL, BUTTON_A},
{PLA_SELECT_REPEAT, BUTTON_A|BUTTON_REPEAT, BUTTON_NONE},
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
{PLA_CANCEL, BUTTON_BACK, BUTTON_NONE},
{PLA_EXIT, BUTTON_MENU, BUTTON_NONE},
{PLA_SELECT, BUTTON_SELECT, BUTTON_NONE},

View file

@ -335,7 +335,7 @@
#define MIDI_VOL_DOWN BUTTON_DOWN
#define MIDI_PLAYPAUSE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define MIDI_QUIT BUTTON_BACK
#define MIDI_FFWD BUTTON_RIGHT
#define MIDI_REWIND BUTTON_LEFT

View file

@ -6,7 +6,7 @@
#undef SYNC
#if defined(SIMULATOR) || defined(CTRU)
#if defined(SIMULATOR) || defined(N3DS)
#define SYNC
#else
#define USETHREADS

View file

@ -454,7 +454,7 @@ CONFIG_KEYPAD == MROBE500_PAD
# define MINESWP_DISCOVER BUTTON_A
# define MINESWP_INFO BUTTON_Y
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
# define MINESWP_LEFT BUTTON_LEFT
# define MINESWP_RIGHT BUTTON_RIGHT
# define MINESWP_UP BUTTON_UP

View file

@ -2593,7 +2593,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define MP3ENC_DONE BUTTON_START
#define MP3ENC_SELECT BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define MP3ENC_PREV BUTTON_UP
#define MP3ENC_NEXT BUTTON_DOWN
#define MP3ENC_DONE BUTTON_POWER

View file

@ -365,7 +365,7 @@ struct mpeg_settings settings;
#define MPEG_START_TIME_DOWN BUTTON_DOWN
#define MPEG_START_TIME_EXIT BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define MPEG_START_TIME_SELECT BUTTON_SELECT
#define MPEG_START_TIME_LEFT BUTTON_LEFT
#define MPEG_START_TIME_RIGHT BUTTON_RIGHT

View file

@ -497,7 +497,7 @@ CONFIG_KEYPAD == SANSA_M200_PAD
#define MPEG_RW BUTTON_LEFT
#define MPEG_FF BUTTON_RIGHT
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define MPEG_MENU BUTTON_MENU
#define MPEG_PAUSE BUTTON_SELECT
#define MPEG_STOP BUTTON_POWER

View file

@ -564,7 +564,7 @@
#define OSCILLOSCOPE_VOL_UP BUTTON_UP
#define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define OSCILLOSCOPE_QUIT BUTTON_BACK
#define OSCILLOSCOPE_DRAWMODE BUTTON_USER
#define OSCILLOSCOPE_ADVMODE BUTTON_MENU

View file

@ -417,7 +417,7 @@
#define PACMAN_COIN BUTTON_A
#define PACMAN_MENU BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define PACMAN_UP BUTTON_UP
#define PACMAN_DOWN BUTTON_DOWN

View file

@ -306,7 +306,7 @@ enum pd_key_id
#define PDPOD_WHEELLEFT BUTTON_UP
#define PDPOD_WHEELRIGHT BUTTON_DOWN
#define PDPOD_ACTION BUTTON_SELECT
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
#define PDPOD_QUIT BUTTON_BACK
#define PDPOD_PLAY BUTTON_USER
#define PDPOD_PREVIOUS BUTTON_LEFT

View file

@ -730,7 +730,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define LVL_UP_TEXT "R"
#define LVL_DOWN_TEXT "L"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define PEGBOX_SELECT BUTTON_SELECT
#define PEGBOX_QUIT BUTTON_BACK
#define PEGBOX_RESTART BUTTON_MENU

View file

@ -24,7 +24,7 @@
PLUGIN_HEADER
#ifdef CTRU
#ifdef N3DS
/* dummy undefined symbols to build plugins for ctru */
void __aeabi_unwind_cpp_pr0(void) {}
struct _reent * _EXFUN(__getreent, (void)) { return NULL; }

View file

@ -336,7 +336,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define PONG_RIGHT_UP BUTTON_X
#define PONG_RIGHT_DOWN BUTTON_Y
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define PONG_QUIT BUTTON_BACK
#define PONG_PAUSE BUTTON_SELECT
#define PONG_LEFT_UP BUTTON_UP

View file

@ -372,7 +372,7 @@
#define REVERSI_BUTTON_MAKE_MOVE BUTTON_A
#define REVERSI_BUTTON_MENU BUTTON_B
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define REVERSI_BUTTON_QUIT BUTTON_BACK
#define REVERSI_BUTTON_UP BUTTON_UP
#define REVERSI_BUTTON_DOWN BUTTON_DOWN

View file

@ -482,7 +482,7 @@
#define ROCKBLOX_DROP BUTTON_A
#define ROCKBLOX_RESTART BUTTON_B
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define ROCKBLOX_OFF BUTTON_BACK
#define ROCKBLOX_ROTATE_CCW BUTTON_POWER

View file

@ -482,7 +482,7 @@ static void setoptions (void)
options.SELECT = BUTTON_FN;
options.MENU = BUTTON_X;
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
options.UP = BUTTON_UP;
options.DOWN = BUTTON_DOWN;
options.LEFT = BUTTON_LEFT;
@ -510,7 +510,7 @@ static void setoptions (void)
#error No Keymap Defined!
#endif
#if defined(HAVE_TOUCHSCREEN) && (CONFIG_KEYPAD != CTRU_PAD)
#if defined(HAVE_TOUCHSCREEN) && (CONFIG_KEYPAD != N3DS_PAD)
options.UP = BUTTON_TOPMIDDLE;
options.DOWN = BUTTON_BOTTOMMIDDLE;
options.START = BUTTON_TOPRIGHT;

View file

@ -428,7 +428,7 @@
#define ROCKPAINT_LEFT BUTTON_LEFT
#define ROCKPAINT_RIGHT BUTTON_RIGHT
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define ROCKPAINT_QUIT BUTTON_BACK
#define ROCKPAINT_DRAW BUTTON_SELECT
#define ROCKPAINT_MENU BUTTON_MENU

View file

@ -38,8 +38,8 @@ SDLFLAGS = -I$(SDL_SRCDIR)/include $(filter-out -O%,$(PLUGINFLAGS)) \
#-ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations \
#-D_GNU_SOURCE=1 -D_REENTRANT -DSDL -DELF
# CTRU does need these to avoid compiler errors
ifeq ($(APP_TYPE),ctru-app)
# N3DS does need these to avoid compiler errors
ifeq ($(APP_TYPE),3ds-homebrew)
SDLFLAGS += -Wno-int-conversion -Wno-incompatible-pointer-types \
-Wno-implicit-function-declaration -Wno-implicit-int
endif

View file

@ -368,7 +368,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define PUZZLE_SHUFFLE BUTTON_B
#define PUZZLE_PICTURE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define PUZZLE_QUIT BUTTON_BACK
#define PUZZLE_LEFT BUTTON_LEFT
#define PUZZLE_RIGHT BUTTON_RIGHT

View file

@ -323,7 +323,7 @@ dir is the current direction of the snake - 0=up, 1=right, 2=down, 3=left;
#define SNAKE_DOWN BUTTON_DOWN
#define SNAKE_PLAYPAUSE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define SNAKE_QUIT BUTTON_BACK
#define SNAKE_LEFT BUTTON_LEFT
#define SNAKE_RIGHT BUTTON_RIGHT

View file

@ -469,7 +469,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define SNAKE2_PLAYPAUSE BUTTON_A
#define SNAKE2_PLAYPAUSE_TEXT "A"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define SNAKE2_LEFT BUTTON_LEFT
#define SNAKE2_RIGHT BUTTON_RIGHT
#define SNAKE2_UP BUTTON_UP

View file

@ -712,7 +712,7 @@
#define BUTTON_SAVE BUTTON_A
#define BUTTON_SAVE_NAME "A"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define SOKOBAN_LEFT BUTTON_LEFT
#define SOKOBAN_RIGHT BUTTON_RIGHT
#define SOKOBAN_UP BUTTON_UP

View file

@ -742,7 +742,7 @@ CONFIG_KEYPAD == MROBE500_PAD
# define HK_CUR2STACK "B"
# define HK_REM2STACK "R"
#elif (CONFIG_KEYPAD == CTRU_PAD)
#elif (CONFIG_KEYPAD == N3DS_PAD)
# define SOL_QUIT BUTTON_BACK
# define SOL_UP BUTTON_UP
# define SOL_DOWN BUTTON_DOWN

View file

@ -383,7 +383,7 @@
#define AST_RIGHT BUTTON_RIGHT
#define AST_FIRE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define AST_PAUSE BUTTON_MENU
#define AST_QUIT BUTTON_BACK
#define AST_THRUST BUTTON_UP

View file

@ -687,7 +687,7 @@
#define STAR_LEVEL_DOWN_NAME "L"
#define STAR_LEVEL_REPEAT_NAME "B"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define STAR_QUIT BUTTON_BACK
#define STAR_LEFT BUTTON_LEFT

View file

@ -305,7 +305,7 @@
#define STOPWATCH_SCROLL_UP BUTTON_UP
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define STOPWATCH_QUIT BUTTON_BACK
#define STOPWATCH_START_STOP BUTTON_SELECT
#define STOPWATCH_RESET_TIMER BUTTON_MENU

View file

@ -472,7 +472,7 @@
#define SUDOKU_BUTTON_MENU BUTTON_B
#define SUDOKU_BUTTON_POSSIBLE BUTTON_X
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define SUDOKU_BUTTON_QUIT BUTTON_BACK
#define SUDOKU_BUTTON_UP BUTTON_UP
#define SUDOKU_BUTTON_DOWN BUTTON_DOWN

View file

@ -587,7 +587,7 @@
#define TV_LINE_DOWN BUTTON_L
#define TV_BOOKMARK BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define TV_QUIT BUTTON_BACK
#define TV_SCROLL_UP BUTTON_UP
#define TV_SCROLL_DOWN BUTTON_DOWN

View file

@ -468,7 +468,7 @@
#define LABEL_MENU "B"
#define LABEL_VOLUME "UP/DOWN"
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define VUMETER_QUIT BUTTON_BACK
#define VUMETER_HELP BUTTON_USER
#define VUMETER_MENU BUTTON_MENU

View file

@ -418,7 +418,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define BTN_QUIT BUTTON_START
#define BTN_STOPRESET BUTTON_B
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define BTN_DIR_UP BUTTON_UP
#define BTN_DIR_DOWN BUTTON_DOWN

View file

@ -362,7 +362,7 @@ CONFIG_KEYPAD == MROBE500_PAD
#define DOWN BUTTON_DOWN
#define PAUSE BUTTON_A
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define QUIT BUTTON_BACK
#define LEFT BUTTON_LEFT

View file

@ -301,7 +301,7 @@
#define ZX_SELECT BUTTON_A
#define ZX_MENU BUTTON_START
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define ZX_UP BUTTON_UP
#define ZX_DOWN BUTTON_DOWN

View file

@ -291,7 +291,7 @@
#define KBD_UP BUTTON_UP
#define KBD_DOWN BUTTON_DOWN
#elif CONFIG_KEYPAD == CTRU_PAD
#elif CONFIG_KEYPAD == N3DS_PAD
#define KBD_SELECT BUTTON_SELECT
#define KBD_ABORT BUTTON_BACK

View file

@ -570,7 +570,7 @@ void resume_directory(const char *dir)
/* Returns the current working directory and also writes cwd to buf if
non-NULL. In case of error, returns NULL. */
#ifdef CTRU
#ifdef N3DS
char *__wrap_getcwd(char *buf, getcwd_size_t size)
#else
char *getcwd(char *buf, getcwd_size_t size)

View file

@ -127,7 +127,7 @@ void tree_unlock_cache(struct tree_context *t);
#else
#define getcwd_size_t size_t
#endif
#ifdef CTRU
#ifdef N3DS
/* devkitarm already defines getcwd */
char *__wrap_getcwd(char *buf, getcwd_size_t size);
#else

View file

@ -25,7 +25,7 @@ target/hosted/rtc.c
#if (CONFIG_PLATFORM & PLATFORM_ANDROID) == 0 && \
!defined(DX50) && !defined(DX90) && \
(defined(DEBUG) || defined(SIMULATOR) || defined(CTRU)) /* sim should define DEBUG instead */
(defined(DEBUG) || defined(SIMULATOR) || defined(N3DS)) /* sim should define DEBUG instead */
target/hosted/debug-hosted.c
#endif
@ -101,14 +101,14 @@ target/hosted/sdl/app/button-application.c
#ifdef WIN32
target/hosted/filesystem-win32.c
#else /* !WIN32 */
#ifndef CTRU
#if !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
target/hosted/filesystem-unix.c
#endif /* CTRU */
#endif /* PLATFORM_GAME_CONSOLE */
#endif /* WIN32 */
#endif /* APPLICATION */
#endif /* HAVE_SDL */
#if defined(APPLICATION) && !defined(CTRU)
#if defined(APPLICATION) && !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
target/hosted/filesystem-app.c
#endif /* APPLICATION */
@ -624,8 +624,8 @@ target/hosted/sdl/pcm-sdl.c
drivers/audio/as3514.c
#elif defined(SAMSUNG_YPR1) && defined(HAVE_WM8978)
drivers/audio/wm8978.c
#elif defined(CTRU)
drivers/audio/ctru.c
#elif defined(N3DS)
drivers/audio/3ds.c
#endif
#endif /* (CONFIG_PLATFORM & PLATFORM_NATIVE) */
#endif /* !defined(BOOTLOADER) */
@ -2046,26 +2046,35 @@ target/hosted/tinyalsa/mixer.c
target/hosted/tinyalsa/pcm.c
#endif
#if (CONFIG_PLATFORM & PLATFORM_CTRU)
#if (CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
#ifdef CPU_ARM
asm/arm/lcd-as-memframe.S
target/hosted/ctru/backlight-ctru.c
target/hosted/ctru/button-ctru.c
target/hosted/ctru/kernel-ctru.c
target/hosted/ctru/thread-ctru.c
target/hosted/ctru/lcd-bitmap.c
target/hosted/ctru/luminance-ctru.c
target/hosted/ctru/system-ctru.c
target/hosted/ctru/filesystem-ctru.c
target/hosted/ctru/lc-ctru.c
target/hosted/ctru/lc-program-resolver.c
target/hosted/ctru/powermgmt-ctru.c
target/hosted/ctru/timer-ctru.c
target/hosted/ctru/pcm-ctru.c
target/hosted/ctru/lib/sys_file.c
target/hosted/ctru/lib/sys_dir.c
target/hosted/ctru/lib/sys_thread.c
target/hosted/ctru/lib/sys_timer.c
target/hosted/ctru/lib/bfile/bfile.c
#endif
target/hosted/game_console/kernel-console.c
target/hosted/game_console/thread-console.c
target/hosted/game_console/timer-console.c
target/hosted/game_console/lib/sys_atomic.c
target/hosted/game_console/lib/sys_file_common.c
target/hosted/game_console/lib/sys_timer_common.c
target/hosted/game_console/lib/bfile/bfile-rwmutex.c
target/hosted/game_console/lib/sys_cond_generic.c
#ifdef N3DS
target/hosted/game_console/lib/sys_file_3ds.c
target/hosted/game_console/lib/sys_dir_3ds.c
target/hosted/game_console/lib/sys_thread_3ds.c
target/hosted/game_console/lib/sys_timer_3ds.c
target/hosted/game_console/lib/bfile/bfile-3ds.c
target/hosted/game_console/3ds/backlight-3ds.c
target/hosted/game_console/3ds/button-3ds.c
target/hosted/game_console/3ds/filesystem-3ds.c
target/hosted/game_console/3ds/lc-3ds.c
target/hosted/game_console/3ds/lcd-bitmap-3ds.c
target/hosted/game_console/3ds/lc-program-resolver.c
target/hosted/game_console/3ds/luminance-3ds.c
target/hosted/game_console/3ds/pcm-3ds.c
target/hosted/game_console/3ds/powermgmt-3ds.c
target/hosted/game_console/3ds/system-3ds.c
#endif /* N3DS */
#endif
#else /* defined(SIMULATOR) */
@ -2122,7 +2131,7 @@ kernel/semaphore.c
#endif
#ifdef HAVE_SDL_THREADS
target/hosted/sdl/thread-sdl.c
#elif !defined(CTRU)
#elif !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
kernel/thread.c
#endif
kernel/thread-common.c

View file

@ -222,7 +222,7 @@ struct sound_settings_info
#include "es9218.h"
#elif (CONFIG_PLATFORM & PLATFORM_ANDROID)
#include "android_codec.h"
#elif ((CONFIG_PLATFORM & (PLATFORM_SDL | PLATFORM_CTRU)) | defined(RG_NANO))
#elif ((CONFIG_PLATFORM & (PLATFORM_SDL | PLATFORM_GAME_CONSOLE)) | defined(RG_NANO))
#include "sdl_codec.h"
#elif defined(DX50)
#include "codec-dx50.h"

View file

@ -88,11 +88,11 @@
* bit fields to allow PLATFORM_HOSTED to be OR'ed e.g. with a
* possible future PLATFORM_ANDROID (some OSes might need totally different
* handling to run on them than a stand-alone application) */
#define PLATFORM_NATIVE (1<<0)
#define PLATFORM_HOSTED (1<<1)
#define PLATFORM_ANDROID (1<<2)
#define PLATFORM_SDL (1<<3)
#define PLATFORM_CTRU (1<<4)
#define PLATFORM_NATIVE (1<<0)
#define PLATFORM_HOSTED (1<<1)
#define PLATFORM_ANDROID (1<<2)
#define PLATFORM_SDL (1<<3)
#define PLATFORM_GAME_CONSOLE (1<<4)
/* CONFIG_KEYPAD */
#define IRIVER_H100_PAD 4
@ -155,7 +155,7 @@
#define ECHO_R1_PAD 75
#define SURFANS_F28_PAD 76
#define RG_NANO_PAD 77
#define CTRU_PAD 78
#define N3DS_PAD 78
#define HIBY_R3PROII_PAD 79
#define HIDIZS_AP80MAX_PAD 80
@ -575,8 +575,8 @@ Lyre prototype 1 */
#include "config/surfansf28.h"
#elif defined(RG_NANO)
#include "config/rgnano.h"
#elif defined(CTRU)
#include "config/ctru.h"
#elif defined(N3DS)
#include "config/3ds.h"
#elif defined(HIBY_R3PROII)
#include "config/hibyr3proii.h"
#elif defined(HIBY_R1)
@ -1015,7 +1015,7 @@ Lyre prototype 1 */
#if defined(ASSEMBLER_THREADS) \
|| defined(HAVE_WIN32_FIBER_THREADS) \
|| defined(HAVE_SIGALTSTACK_THREADS) \
|| defined(CTRU)
|| defined(N3DS)
#define HAVE_PRIORITY_SCHEDULING
#endif

View file

@ -3,12 +3,12 @@
*/
/* We don't run on hardware directly */
#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_CTRU)
#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_GAME_CONSOLE)
#define HAVE_FPU
/* For Rolo and boot loader */
#define MODEL_NUMBER 100s
#define MODEL_NAME "CTRU"
#define MODEL_NAME "N3DS"
#define USB_NONE
@ -73,9 +73,9 @@
/* #define HAVE_SCROLLWHEEL */
#define CONFIG_KEYPAD CTRU_PAD
#define CONFIG_KEYPAD N3DS_PAD
#define HAVE_CTRU_AUDIO
#define HAVE_3DS_AUDIO
#define HAVE_HEADPHONE_DETECTION
#define HAVE_SW_TONE_CONTROLS
/* #define HAVE_SW_VOLUME_CONTROL */

View file

@ -34,8 +34,8 @@ extern void ldebugf(const char* file, int line, const char *fmt, ...)
|| (defined(APPLICATION) && defined(DEBUG))
#define DEBUGF debugf
#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
#elif (CONFIG_PLATFORM & PLATFORM_CTRU)
/* let's use second display for debug output */
#elif (CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
/* always keep debugf available for console platforms */
#define DEBUGF debugf
#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__)
#elif defined(DEBUG) /* DEBUG on native targets */

View file

@ -40,7 +40,7 @@
/* NOTE: target-specific hosted HOME_DIR resides in filesystem-app.c */
#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU)
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(N3DS)
#define HOME_DIR "/"
@ -87,7 +87,7 @@
#if defined(APPLICATION) && \
!(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(CTRU))
defined(HIBY_LINUX) || defined(FIIO_M3K_LINUX) || defined(N3DS))
#define PLUGIN_DATA_DIR ROCKBOX_DIR "/rocks.data"
#define PLUGIN_GAMES_DATA_DIR PLUGIN_DATA_DIR

View file

@ -27,8 +27,8 @@
#include "fs_attr.h"
#include "fs_defines.h"
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#if (CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE) && !defined(SIMULATOR)
#include "filesystem-console.h"
#elif defined (APPLICATION) || defined(CHECKWPS)
#include "filesystem-app.h"
#elif defined(SIMULATOR) || defined(DBTOOL)

View file

@ -39,8 +39,8 @@ enum relate_result
RELATE_PREFIX, /* the path2 contains path1 as a prefix */
};
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#if (CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE) && !defined(SIMULATOR)
#include "filesystem-console.h"
#elif defined(APPLICATION) || defined(CHECKWPS)
#include "filesystem-app.h"
#elif defined(SIMULATOR) || defined(DBTOOL)

View file

@ -27,7 +27,7 @@
#endif
#ifndef __MINGW32__
#if defined(__APPLE__) || defined(CTRU)
#if defined(__APPLE__) || defined(N3DS)
#include <sys/types.h>
#else
#include <endian.h>

View file

@ -88,7 +88,7 @@ struct thread_entry;
*
* simulator (possibly) doesn't simulate stack usage anyway but well ... */
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(CTRU)
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(N3DS)
#define DEFAULT_STACK_SIZE 0x100 /* tiny, ignored anyway */
#else
#include "asm/thread.h"

View file

@ -74,7 +74,7 @@ void mutex_lock(struct mutex *m)
/* Release ownership of a mutex object - only owning thread must call this */
void mutex_unlock(struct mutex *m)
{
#ifndef CTRU
#ifndef N3DS
/* FIXME: synchronization primitives does not behave
correctly between different cores */
/* unlocker not being the owner is an unlocking violation */

View file

@ -230,7 +230,7 @@ void format_thread_name(char *buf, size_t bufsize,
snprintf(buf, bufsize, fmt, name, thread->id);
}
#if !defined(HAVE_SDL_THREADS) && !defined(CTRU)
#if !defined(HAVE_SDL_THREADS) && !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
/*---------------------------------------------------------------------------
* Returns the maximum percentage of the stack ever used during runtime.
*---------------------------------------------------------------------------
@ -251,7 +251,7 @@ static unsigned int stack_usage(uintptr_t *stackptr, size_t stack_size)
return usage;
}
#endif /* !defined(HAVE_SDL_THREADS) && !defined(CTRU) */
#endif /* !defined(HAVE_SDL_THREADS) && !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE) */
#if NUM_CORES > 1
int core_get_debug_info(unsigned int core, struct core_debug_info *infop)
@ -303,7 +303,7 @@ int thread_get_debug_info(unsigned int thread_id,
#ifdef HAVE_SCHEDULER_BOOSTCTRL
cpu_boost = thread->cpu_boost;
#endif
#if !defined(HAVE_SDL_THREADS) && !defined(CTRU)
#if !defined(HAVE_SDL_THREADS) && !(CONFIG_PLATFORM & PLATFORM_GAME_CONSOLE)
infop->stack_usage = stack_usage(thread->stack, thread->stack_size);
size_t stack_used_current =

View file

@ -31,7 +31,7 @@
*
* simulator (possibly) doesn't simulate stack usage anyway but well ... */
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(CTRU)
#if defined(HAVE_SDL_THREADS) || defined(__PCTOOL__) || defined(N3DS)
struct regs
{
void *t; /* OS thread */

View file

@ -1,60 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 Mauricio G.
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "sys_timer.h"
#include "timer.h"
static int timer_prio = -1;
void (*global_timer_callback)(void);
int timerId;
u32 _timer_callback(u32 interval, void *param){
(void)param;
global_timer_callback();
return(interval);
}
#define cycles_to_miliseconds(cycles) \
((int)((1000*cycles)/TIMER_FREQ))
bool timer_register(int reg_prio, void (*unregister_callback)(void),
long cycles, void (*timer_callback)(void))
{
(void)unregister_callback;
if (reg_prio <= timer_prio || cycles == 0)
return false;
timer_prio=reg_prio;
global_timer_callback=timer_callback;
timerId=sys_add_timer(cycles_to_miliseconds(cycles), _timer_callback, 0);
return true;
}
bool timer_set_period(long cycles)
{
sys_remove_timer(timerId);
timerId=sys_add_timer(cycles_to_miliseconds(cycles), _timer_callback, 0);
return true;
}
void timer_unregister(void)
{
sys_remove_timer(timerId);
timer_prio = -1;
}

View file

@ -57,11 +57,7 @@ const char * handle_special_dirs(const char *dir, unsigned flags,
#ifdef WIN32
#include "filesystem-win32.h"
#else /* !WIN32 */
#if defined(CTRU) && !defined(SIMULATOR)
#include "filesystem-ctru.h"
#else
#include "filesystem-unix.h"
#endif
#endif /* WIN32 */
#include "filesystem-hosted.h"

View file

@ -17,8 +17,8 @@
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _FILESYSTEM_CTRU_H_
#define _FILESYSTEM_CTRU_H_
#ifndef _FILESYSTEM_CONSOLE_H_
#define _FILESYSTEM_CONSOLE_H_
#if defined(PLUGIN) || defined(CODEC)
#define FILEFUNCTIONS_DECLARED
@ -29,17 +29,17 @@
#endif /* PLUGIN || CODEC */
#ifndef OSFUNCTIONS_DECLARED
#define FS_PREFIX(_x_) ctru_ ## _x_
#define FS_PREFIX(_x_) console_ ## _x_
void paths_init(void);
#endif /* !OSFUNCTIONS_DECLARED */
#endif /* _FILESYSTEM_CTRU_H_ */
#endif /* _FILESYSTEM_CONSOLE_H_ */
#ifdef _FILE_H_
#include <unistd.h>
#ifndef _FILESYSTEM_CTRU__FILE_H_
#define _FILESYSTEM_CTRU__FILE_H_
#ifndef _FILESYSTEM_CONSOLE__FILE_H_
#define _FILESYSTEM_CONSOLE__FILE_H_
#ifdef RB_FILESYSTEM_OS
#define FILEFUNCTIONS_DEFINED
@ -52,31 +52,31 @@ void paths_init(void);
#include <time.h>
int ctru_open(const char *name, int oflag, ...);
int ctru_creat(const char *name, mode_t mode);
int ctru_close(int fildes);
int ctru_ftruncate(int fildes, off_t length);
int ctru_fsync(int fildes);
off_t ctru_lseek(int fildes, off_t offset, int whence);
ssize_t ctru_read(int fildes, void *buf, size_t nbyte);
ssize_t ctru_write(int fildes, const void *buf, size_t nbyte);
int ctru_remove(const char *path);
int ctru_rename(const char *old, const char *new);
int ctru_modtime(const char *path, time_t modtime);
off_t ctru_filesize(int fildes);
int ctru_fsamefile(int fildes1, int fildes2);
int ctru_relate(const char *path1, const char *path2);
bool ctru_file_exists(const char *path);
ssize_t ctru_readlink(const char *path, char *buf, size_t bufsiz);
int console_open(const char *name, int oflag, ...);
int console_creat(const char *name, mode_t mode);
int console_close(int fildes);
int console_ftruncate(int fildes, off_t length);
int console_fsync(int fildes);
off_t console_lseek(int fildes, off_t offset, int whence);
ssize_t console_read(int fildes, void *buf, size_t nbyte);
ssize_t console_write(int fildes, const void *buf, size_t nbyte);
int console_remove(const char *path);
int console_rename(const char *old, const char *new);
int console_modtime(const char *path, time_t modtime);
off_t console_filesize(int fildes);
int console_fsamefile(int fildes1, int fildes2);
int console_relate(const char *path1, const char *path2);
bool console_file_exists(const char *path);
ssize_t console_readlink(const char *path, char *buf, size_t bufsiz);
#endif /* !FILEFUNCTIONS_DECLARED */
#endif /* _FILESYSTEM_CTRU__FILE_H_ */
#endif /* _FILESYSTEM_CONSOLE__FILE_H_ */
#endif /* _FILE_H_ */
#ifdef _DIR_H_
#ifndef _FILESYSTEM_CTRU__DIR_H_
#define _FILESYSTEM_CTRU__DIR_H_
#ifndef _FILESYSTEM_CONSOLE__DIR_H_
#define _FILESYSTEM_CONSOLE__DIR_H_
#define DIRENT dirent
struct dirent;
@ -99,17 +99,17 @@ typedef struct {} DIR;
#define DIRFUNCTIONS_DEFINED
#endif
DIR * ctru_opendir(const char *dirname);
struct dirent * ctru_readdir(DIR *dirp);
int ctru_readdir_r(DIR *dirp, struct dirent *entry,
DIR * console_opendir(const char *dirname);
struct dirent * console_readdir(DIR *dirp);
int console_readdir_r(DIR *dirp, struct dirent *entry,
struct dirent **result);
void ctru_rewinddir(DIR *dirp);
int ctru_closedir(DIR *dirp);
int ctru_mkdir(const char *path);
int ctru_rmdir(const char *path);
int ctru_samedir(DIR *dirp1, DIR *dirp2);
bool ctru_dir_exists(const char *dirname);
void console_rewinddir(DIR *dirp);
int console_closedir(DIR *dirp);
int console_mkdir(const char *path);
int console_rmdir(const char *path);
int console_samedir(DIR *dirp1, DIR *dirp2);
bool console_dir_exists(const char *dirname);
#endif /* !DIRFUNCTIONS_DECLARED */
#endif /* _FILESYSTEM_CTRU__DIR_H_ */
#endif /* _FILESYSTEM_CONSOLE__DIR_H_ */
#endif /* _DIR_H_ */

View file

@ -34,7 +34,7 @@
#include "lcd.h"
#include "debug.h"
#include "luminance-ctru.h"
#include "luminance-3ds.h"
/* TODO: To use calibrated values in rockbox,
MIN_BRIGHTNESS_SETTING (etc) would need to be

View file

@ -33,7 +33,7 @@
#include "kernel.h"
#include "backlight.h"
#include "system.h"
#include "button-ctru.h"
#include "button-console.h"
#include "buttonmap.h"
#include "debug.h"
#include "powermgmt.h"

View file

@ -29,20 +29,19 @@
#include "system.h"
#include "load_code.h"
#include "filesystem-ctru.h"
#include "filesystem-console.h"
#include "debug.h"
extern u32 __ctrl_code_allocator_pages;
/* reserve only the required memory for rockbox app,
the rest will be used to load .so objects */
u32 __ctru_heap_size = MEMORYSIZE * 1024 * 1024;
u32 __ctru_linear_heap_size = MEMORYSIZE * 1024 * 1024;
void* programResolver(const char* sym, void *userData);
void * lc_open(const char *filename, unsigned char *buf, size_t buf_size)
{
DEBUGF("dlopen(path=\"%s\")\n", filename);
/* We need to increase __ctrl_code_allocator_pages value to 8 MB
to enable big plugins */
__ctrl_code_allocator_pages = 2048;
/* note: the 3ds dlopen implementation needs a custom resolver
for the unresolved symbols in shared objects */
/* void *handle = dlopen(filename, RTLD_NOW | RTLD_LOCAL); */

View file

@ -33,7 +33,7 @@
#include "debug.h"
#include "system.h"
#include "button-ctru.h"
#include "button-console.h"
#include "screendump.h"
#include "lcd-target.h"

View file

@ -28,7 +28,7 @@
#include <3ds.h>
#include <math.h>
#include "luminance-ctru.h"
#include "luminance-3ds.h"
// For accessing physmem uncached (and directly)
#define PA_PTR(addr) (void *)((u32)(addr) | 1 << 31)

View file

@ -24,8 +24,8 @@
* reasonable ways as different from the original version.
*/
#ifndef _LUMINANCE_CTRU_H_
#define _LUMINANCE_CTRU_H_
#ifndef _LUMINANCE_CONSOLE_H_
#define _LUMINANCE_CONSOLE_H_
#include <3ds/types.h>
@ -37,4 +37,4 @@ u32 getMinLuminancePreset(void);
u32 getMaxLuminancePreset(void);
u32 getCurrentLuminance(bool top);
#endif /* _LUMINANCE_CTRU_H_ */
#endif /* _LUMINANCE_CONSOLE_H_ */

View file

@ -56,12 +56,6 @@
/*#define LOGF_ENABLE*/
#include "logf.h"
#ifdef DEBUG
extern bool debug_audio;
#endif
extern const char *audiodev;
/* Bytes left in the Rockbox PCM frame buffer. */
static size_t _pcm_buffer_size = 0;
@ -207,7 +201,7 @@ static void sink_set_freq_nolock(uint16_t freq)
mix[1] = 1.0;
ndspChnSetMix(0, mix);
memset(_dsp_wave_bufs, 0, sizeof(_dsp_wave_bufs) * ARRAY_SIZE(_dsp_wave_bufs));
memset(_dsp_wave_bufs, 0, sizeof(ndspWaveBuf) * ARRAY_SIZE(_dsp_wave_bufs));
const size_t wave_buffer_size = MIX_FRAME_SAMPLES * 2 * sizeof(s16);
size_t buffer_size = wave_buffer_size * ARRAY_SIZE(_dsp_wave_bufs);
@ -233,7 +227,7 @@ static void sink_set_freq_nolock(uint16_t freq)
NULL,
32 * 1024, /* 32kB stack size */
0x18, /* high priority */
-1, /* run on any core */ false);
-1, /* run on any core */ false);
}
static void sink_dma_start(const void *addr, size_t size)

View file

@ -32,9 +32,9 @@
#include "system.h"
#include "kernel.h"
#include "thread-ctru.h"
#include "system-ctru.h"
#include "button-ctru.h"
#include "thread-console.h"
#include "system-console.h"
#include "button-console.h"
#include "lcd-bitmap.h"
#include "panic.h"
#include "debug.h"

View file

@ -19,8 +19,8 @@
****************************************************************************/
#ifndef __BUTTON_CTRU_H__
#define __BUTTON_CTRU_H__
#ifndef __BUTTON_CONSOLE_H__
#define __BUTTON_CONSOLE_H__
#include <stdbool.h>
#include "config.h"
@ -30,4 +30,4 @@ bool button_hold(void);
void button_init_device(void);
int button_read_device(int *data);
#endif /* __BUTTON_CTRU_H__ */
#endif /* __BUTTON_CONSOLE_H__ */

View file

@ -5,8 +5,9 @@
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2025 Mauricio G.
* Copyright (C) 2002 by Felix Arends
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -21,13 +22,16 @@
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include "system-ctru.h"
#include "thread-ctru.h"
#include "system-console.h"
#include "thread-console.h"
#include "kernel.h"
#include "thread.h"
#include "panic.h"
#include "debug.h"
#include "sys_thread.h"
#include "sys_timer.h"
static int tick_timer_id;
long start_tick;
@ -35,7 +39,7 @@ long start_tick;
static sysCond *sim_thread_cond;
/* Mutex to serialize changing levels and exclude other threads while
* inside a handler */
static RecursiveLock sim_irq_mtx;
static sysMutex *sim_irq_mtx;
/* Level: 0 = enabled, not 0 = disabled */
static int volatile interrupt_level = HIGHEST_IRQ_LEVEL;
/* How many handers waiting? Not strictly needed because CondSignal is a
@ -54,7 +58,7 @@ static int status_reg = 0;
*/
int set_irq_level(int level)
{
RecursiveLock_Lock(&sim_irq_mtx);
sys_mutex_lock(sim_irq_mtx);
int oldlevel = interrupt_level;
@ -68,13 +72,13 @@ int set_irq_level(int level)
interrupt_level = level; /* save new level */
RecursiveLock_Unlock(&sim_irq_mtx);
sys_mutex_unlock(sim_irq_mtx);
return oldlevel;
}
void sim_enter_irq_handler(void)
{
RecursiveLock_Lock(&sim_irq_mtx);
sys_mutex_lock(sim_irq_mtx);
handlers_pending++;
/* Check each time before proceeding: disabled->enabled->...->disabled
@ -82,7 +86,7 @@ void sim_enter_irq_handler(void)
* the mutex; a handler can also leave "interrupts" disabled during
* its execution */
while (interrupt_level != 0)
sys_cond_wait(sim_thread_cond, &sim_irq_mtx);
sys_cond_wait(sim_thread_cond, sim_irq_mtx);
status_reg = 1;
}
@ -94,12 +98,18 @@ void sim_exit_irq_handler(void)
sys_cond_signal(sim_thread_cond);
status_reg = 0;
RecursiveLock_Unlock(&sim_irq_mtx);
sys_mutex_unlock(sim_irq_mtx);
}
static bool sim_kernel_init(void)
{
RecursiveLock_Init(&sim_irq_mtx);
sim_irq_mtx = (sysMutex *) sys_mutex_create();
if (sim_irq_mtx == NULL)
{
panicf("Cannot create sim_irq_mtx\n");
return false;
}
sim_thread_cond = sys_cond_create();
if (sim_thread_cond == NULL)
{
@ -116,7 +126,8 @@ void sim_kernel_shutdown(void)
while(handlers_pending > 0)
sys_delay(10);
sys_cond_destroy(sim_thread_cond);
free(sim_irq_mtx);
free(sim_thread_cond);
}
u32 tick_timer(u32 interval, void *param)
@ -161,5 +172,4 @@ void tick_start(unsigned int interval_in_ms)
}
tick_timer_id = sys_add_timer(interval_in_ms, tick_timer, NULL);
}
}

View file

@ -12,59 +12,6 @@
#endif
#include "logf.h"
// rw mutex implementation
void sync_RWMutexInit(sync_RWMutex *m) {
LightLock_Init(&m->shared);
CondVar_Init(&m->reader_q);
CondVar_Init(&m->writer_q);
m->active_readers = 0;
m->active_writers = 0;
m->waiting_writers = 0;
}
static inline LightLock *unique_lock(LightLock *lk) {
LightLock_Lock(lk);
return lk;
}
void sync_RWMutexRLock(sync_RWMutex *m) {
LightLock *lk = unique_lock(&m->shared);
while (m->waiting_writers != 0) {
CondVar_Wait(&m->reader_q, lk);
}
++m->active_readers;
LightLock_Unlock(lk);
}
void sync_RWMutexRUnlock(sync_RWMutex *m) {
LightLock *lk = unique_lock(&m->shared);
--m->active_readers;
LightLock_Unlock(lk);
CondVar_Signal(&m->writer_q);
}
void sync_RWMutexLock(sync_RWMutex *m) {
LightLock *lk = unique_lock(&m->shared);
++m->waiting_writers;
while ((m->active_readers != 0) || (m->active_writers != 0)) {
CondVar_Wait(&m->writer_q, lk);
}
++m->active_writers;
LightLock_Unlock(lk);
}
void sync_RWMutexUnlock(sync_RWMutex *m) {
LightLock *lk = unique_lock(&m->shared);
--m->waiting_writers;
--m->active_writers;
if (m->waiting_writers > 0) {
CondVar_Signal(&m->writer_q);
} else {
CondVar_Broadcast(&m->reader_q);
}
LightLock_Unlock(lk);
}
// page reader implementation
file_error_t readPage(PageReader *p, u64 offset)
{

View file

@ -9,17 +9,7 @@
#include <sys/stat.h>
#include <math.h>
#include <3ds/gfx.h>
#ifdef RGB565
#undef RGB565
#endif
#include <3ds/svc.h>
#include <3ds/types.h>
#include <3ds/thread.h>
#include <3ds/result.h>
#include <3ds/services/fs.h>
#include <3ds/synchronization.h>
#include "sys_thread.h"
/* #define MALLOC_DEBUG
#include "rmalloc/rmalloc.h" */
@ -32,29 +22,29 @@ typedef struct { \
} type_name##_t;
/* single mutex implementation */
#define sync_Mutex LightLock
#define sync_Mutex sysMutex
static inline void sync_MutexInit(sync_Mutex* m) {
LightLock_Init(m);
sys_mutex_init(m);
}
/* mutex unlock */
static inline void sync_MutexLock(sync_Mutex* m) {
LightLock_Lock(m);
sys_mutex_lock(m);
}
/* mutex lock */
static inline void sync_MutexUnlock(sync_Mutex* m) {
LightLock_Unlock(m);
sys_mutex_unlock(m);
}
/* read_write mutex implementation */
typedef struct {
sync_Mutex shared;
CondVar reader_q;
CondVar writer_q;
int active_readers;
int active_writers;
int waiting_writers;
sync_Mutex shared;
sysCond reader_q;
sysCond writer_q;
int active_readers;
int active_writers;
int waiting_writers;
} sync_RWMutex;
void sync_RWMutexInit(sync_RWMutex *m);
@ -68,6 +58,7 @@ two_type_value(int, const char*, n, err, int_error);
two_type_value(struct stat, const char*, fi, err, stat_error);
typedef const char* file_error_t;
#ifdef N3DS
typedef struct {
Handle file;
s64 start;
@ -77,5 +68,6 @@ typedef struct {
u8 *buffer;
} PageReader;
#endif
#endif /* _BFILE_INTERNAL_H_ */

View file

@ -0,0 +1,61 @@
#include "bfile.h"
/* Define LOGF_ENABLE to enable logf output in this file */
#if 0
#define LOGF_ENABLE
#endif
#include "logf.h"
/* rw mutex implementation */
void sync_RWMutexInit(sync_RWMutex *m) {
sys_mutex_init(&m->shared);
sys_cond_init(&m->reader_q);
sys_cond_init(&m->writer_q);
m->active_readers = 0;
m->active_writers = 0;
m->waiting_writers = 0;
}
static inline sysMutex *unique_lock(sysMutex *lk) {
sys_mutex_lock(lk);
return lk;
}
void sync_RWMutexRLock(sync_RWMutex *m) {
sysMutex *lk = unique_lock(&m->shared);
while (m->waiting_writers != 0) {
sys_cond_wait(&m->reader_q, lk);
}
++m->active_readers;
sys_mutex_unlock(lk);
}
void sync_RWMutexRUnlock(sync_RWMutex *m) {
sysMutex *lk = unique_lock(&m->shared);
--m->active_readers;
sys_mutex_unlock(lk);
sys_cond_signal(&m->writer_q);
}
void sync_RWMutexLock(sync_RWMutex *m) {
sysMutex *lk = unique_lock(&m->shared);
++m->waiting_writers;
while ((m->active_readers != 0) || (m->active_writers != 0)) {
sys_cond_wait(&m->writer_q, lk);
}
++m->active_writers;
sys_mutex_unlock(lk);
}
void sync_RWMutexUnlock(sync_RWMutex *m) {
sysMutex *lk = unique_lock(&m->shared);
--m->waiting_writers;
--m->active_writers;
if (m->waiting_writers > 0) {
sys_cond_signal(&m->writer_q);
} else {
sys_cond_broadcast(&m->reader_q);
}
sys_mutex_unlock(lk);
}

View file

@ -0,0 +1,60 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2026 Mauricio G.
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "debug.h"
#include "logf.h"
#include "sys_atomic.h"
bool _AtomicCAS(u32 *ptr, int oldval, int newval)
{
return (bool) __sync_bool_compare_and_swap(ptr, oldval, newval);
}
bool _AtomicTryLock(int *lock)
{
return __sync_lock_test_and_set(lock, 1) == 0;
}
void sys_delay(u32 ms);
#define CPUPauseInstruction()
void AtomicLock(int *lock)
{
int iterations = 0;
while (!_AtomicTryLock(lock)) {
if (iterations < 32) {
iterations++;
CPUPauseInstruction();
} else {
sys_delay(0);
}
}
}
void AtomicUnlock(int *lock)
{
__sync_lock_release(lock);
}

View file

@ -0,0 +1,37 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2026 Mauricio G.
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __SYSATOMIC_H__
#define __SYSATOMIC_H__
#include "sys_types.h"
#define AtomicAdd(ptr, value) __sync_fetch_and_add((u32 *)(ptr), value)
bool _AtomicCAS(u32 *ptr, int oldval, int newval);
#define AtomicGet(ptr) __atomic_load_n((u32*)(ptr), __ATOMIC_SEQ_CST)
#define AtomicSet(ptr, value) __sync_lock_test_and_set((u32 *)(ptr), value)
#define AtomicCAS(ptr, oldvalue, newvalue) _AtomicCAS((u32 *)(ptr), oldvalue, newvalue)
void AtomicLock(int *lock);
void AtomicUnlock(int *lock);
#endif /* #ifndef __SYSATOMIC_H__ */

View file

@ -0,0 +1,154 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2025 Mauricio Ga.
*
* 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 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "sys_thread.h"
#include "sys_timer.h"
#include "debug.h"
#include "logf.h"
/* sysCond */
void sys_cond_init(sysCond *cond)
{
if (cond) {
memset(cond, 0, sizeof(sysCond));
sys_mutex_init(&cond->lock);
sys_sem_init(&cond->wait_sem, 0);
sys_sem_init(&cond->wait_done, 0);
cond->waiting = cond->signals = 0;
}
}
sysCond *sys_cond_create(void)
{
sysCond *cond;
cond = (sysCond *) malloc(sizeof(sysCond));
if (cond) {
sys_cond_init(cond);
} else {
DEBUGF("sys_cond_create: out of memory.\n");
}
return cond;
}
/* Destroy a condition variable */
void sys_cond_destroy(sysCond *cond)
{
if (cond) {
free(cond);
}
}
/* Restart one of the threads that are waiting on the condition variable */
int sys_cond_signal(sysCond *cond)
{
if (!cond) {
DEBUGF("sys_cond_signal: Invalid param 'cond'\n");
return -1;
}
/* If there are waiting threads not already signalled, then
signal the condition and wait for the thread to respond.
*/
sys_mutex_lock(&cond->lock);
if (cond->waiting > cond->signals) {
++cond->signals;
sys_sem_post(&cond->wait_sem);
sys_mutex_unlock(&cond->lock);
sys_sem_wait(&cond->wait_done);
} else {
sys_mutex_unlock(&cond->lock);
}
return 0;
}
/* Restart all threads that are waiting on the condition variable */
int sys_cond_broadcast(sysCond *cond)
{
if (!cond) {
DEBUGF("sys_cond_signal: Invalid param 'cond'\n");
return -1;
}
/* If there are waiting threads not already signalled, then
signal the condition and wait for the thread to respond.
*/
sys_mutex_lock(&cond->lock);
if (cond->waiting > cond->signals) {
int i, num_waiting;
num_waiting = (cond->waiting - cond->signals);
cond->signals = cond->waiting;
for (i = 0; i < num_waiting; ++i) {
sys_sem_post(&cond->wait_sem);
}
/* Now all released threads are blocked here, waiting for us.
Collect them all (and win fabulous prizes!) :-)
*/
sys_mutex_unlock(&cond->lock);
for (i = 0; i < num_waiting; ++i) {
sys_sem_wait(&cond->wait_done);
}
} else {
sys_mutex_unlock(&cond->lock);
}
return 0;
}
int sys_cond_wait(sysCond *cond, sysMutex *mutex)
{
if (!cond) {
DEBUGF("sys_cond_signal: Invalid param 'cond'\n");
return -1;
}
sys_mutex_lock(&cond->lock);
++cond->waiting;
sys_mutex_unlock(&cond->lock);
/* Unlock the mutex, as is required by condition variable semantics */
sys_mutex_unlock(mutex);
/* Wait for a signal */
int retval = sys_sem_wait(&cond->wait_sem);
sys_mutex_lock(&cond->lock);
if (cond->signals > 0) {
/* We always notify the signal thread that we are done */
sys_sem_post(&cond->wait_done);
/* Signal handshake complete */
--cond->signals;
}
--cond->waiting;
sys_mutex_unlock(&cond->lock);
/* Lock the mutex, as is required by condition variable semantics */
sys_mutex_lock(mutex);
return retval;
}

Some files were not shown because too many files have changed in this diff Show more