diff --git a/apps/SOURCES b/apps/SOURCES index bf39273405..f81261f766 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -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 diff --git a/apps/keymaps/keymap-ctru.c b/apps/keymaps/keymap-3ds.c similarity index 99% rename from apps/keymaps/keymap-ctru.c rename to apps/keymaps/keymap-3ds.c index 76f5e132d6..ab4f4c66c8 100644 --- a/apps/keymaps/keymap-ctru.c +++ b/apps/keymaps/keymap-3ds.c @@ -18,7 +18,7 @@ * ****************************************************************************/ -/* Button Code Definitions for Civic Type R (ctru) target */ +/* Button Code Definitions for the Nintendo 3DS target */ #include #include diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS index 1ba38c97bb..b035fc9f50 100644 --- a/apps/plugins/SUBDIRS +++ b/apps/plugins/SUBDIRS @@ -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 diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 4b2d90588c..5a129c6136 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c @@ -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" diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index 233c3e760d..d90fed287f 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c @@ -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" diff --git a/apps/plugins/brickmania.c b/apps/plugins/brickmania.c index b588000cdb..08a6e36a3e 100644 --- a/apps/plugins/brickmania.c +++ b/apps/plugins/brickmania.c @@ -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 diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c index 252618865c..a42564dd2a 100644 --- a/apps/plugins/calculator.c +++ b/apps/plugins/calculator.c @@ -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 diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 2b6813c3f4..37f3d75d33 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c @@ -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 diff --git a/apps/plugins/chessbox/chessbox_pgn.h b/apps/plugins/chessbox/chessbox_pgn.h index d046b1ed8b..f4f505ef20 100644 --- a/apps/plugins/chessbox/chessbox_pgn.h +++ b/apps/plugins/chessbox/chessbox_pgn.h @@ -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 diff --git a/apps/plugins/chessclock.c b/apps/plugins/chessclock.c index fd9bc92708..971af2d90e 100644 --- a/apps/plugins/chessclock.c +++ b/apps/plugins/chessclock.c @@ -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 diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c index df583bb04c..bf22fcb0b9 100644 --- a/apps/plugins/chip8.c +++ b/apps/plugins/chip8.c @@ -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 diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c index 8dfa68a2b8..cb4816c2f6 100644 --- a/apps/plugins/chopper.c +++ b/apps/plugins/chopper.c @@ -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 diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c index 356021f826..6309cf1e83 100644 --- a/apps/plugins/clix.c +++ b/apps/plugins/clix.c @@ -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 diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c index 9a48b37a37..3936bca565 100644 --- a/apps/plugins/cube.c +++ b/apps/plugins/cube.c @@ -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 diff --git a/apps/plugins/doom/i_video.c b/apps/plugins/doom/i_video.c index 5f3eb68cbe..e5cca93d31 100644 --- a/apps/plugins/doom/i_video.c +++ b/apps/plugins/doom/i_video.c @@ -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 diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c index 673dadbb3e..c33a22a709 100644 --- a/apps/plugins/flipit.c +++ b/apps/plugins/flipit.c @@ -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 diff --git a/apps/plugins/fractals/fractal.h b/apps/plugins/fractals/fractal.h index 84a932d713..f1f5bee424 100644 --- a/apps/plugins/fractals/fractal.h +++ b/apps/plugins/fractals/fractal.h @@ -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 diff --git a/apps/plugins/goban/goban.h b/apps/plugins/goban/goban.h index 4ecabcca76..d6c68178ae 100644 --- a/apps/plugins/goban/goban.h +++ b/apps/plugins/goban/goban.h @@ -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 diff --git a/apps/plugins/imageviewer/imageviewer_button.h b/apps/plugins/imageviewer/imageviewer_button.h index cbfce5bc9a..7eeb41df86 100644 --- a/apps/plugins/imageviewer/imageviewer_button.h +++ b/apps/plugins/imageviewer/imageviewer_button.h @@ -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 diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c index 294b4b3c3f..3b12307d0e 100644 --- a/apps/plugins/invadrox.c +++ b/apps/plugins/invadrox.c @@ -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 diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index ce2de05330..02953847b1 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c @@ -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 diff --git a/apps/plugins/lib/keymaps.h b/apps/plugins/lib/keymaps.h index 51e9f65395..b67a7aeabe 100644 --- a/apps/plugins/lib/keymaps.h +++ b/apps/plugins/lib/keymaps.h @@ -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 diff --git a/apps/plugins/lib/pluginlib_actions.c b/apps/plugins/lib/pluginlib_actions.c index a45a0a0399..6dadfbc784 100644 --- a/apps/plugins/lib/pluginlib_actions.c +++ b/apps/plugins/lib/pluginlib_actions.c @@ -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}, diff --git a/apps/plugins/midi/midiplay.c b/apps/plugins/midi/midiplay.c index 647273bf4a..ee5b1f13f9 100644 --- a/apps/plugins/midi/midiplay.c +++ b/apps/plugins/midi/midiplay.c @@ -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 diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c index a482ace68b..81bc2c4413 100644 --- a/apps/plugins/mikmod/mikmod.c +++ b/apps/plugins/mikmod/mikmod.c @@ -6,7 +6,7 @@ #undef SYNC -#if defined(SIMULATOR) || defined(CTRU) +#if defined(SIMULATOR) || defined(N3DS) #define SYNC #else #define USETHREADS diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c index 704c659a40..6e50e12ab0 100644 --- a/apps/plugins/minesweeper.c +++ b/apps/plugins/minesweeper.c @@ -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 diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index f6423a4329..9a8acecf88 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c @@ -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 diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c index 8475f26b7f..c3db0336ec 100644 --- a/apps/plugins/mpegplayer/mpeg_settings.c +++ b/apps/plugins/mpegplayer/mpeg_settings.c @@ -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 diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c index 761c95cde0..869d691574 100644 --- a/apps/plugins/mpegplayer/mpegplayer.c +++ b/apps/plugins/mpegplayer/mpegplayer.c @@ -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 diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c index c0bef75cd4..d8b3c74eaa 100644 --- a/apps/plugins/oscilloscope.c +++ b/apps/plugins/oscilloscope.c @@ -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 diff --git a/apps/plugins/pacbox/pacbox.h b/apps/plugins/pacbox/pacbox.h index 855e3c536c..86fbeb8ef1 100644 --- a/apps/plugins/pacbox/pacbox.h +++ b/apps/plugins/pacbox/pacbox.h @@ -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 diff --git a/apps/plugins/pdbox/pdbox.h b/apps/plugins/pdbox/pdbox.h index 2fd628fea2..e1144b5f22 100644 --- a/apps/plugins/pdbox/pdbox.h +++ b/apps/plugins/pdbox/pdbox.h @@ -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 diff --git a/apps/plugins/pegbox.c b/apps/plugins/pegbox.c index bd17965ef6..3572320a3f 100644 --- a/apps/plugins/pegbox.c +++ b/apps/plugins/pegbox.c @@ -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 diff --git a/apps/plugins/plugin_crt0.c b/apps/plugins/plugin_crt0.c index a9270c4fa0..f64becec2e 100644 --- a/apps/plugins/plugin_crt0.c +++ b/apps/plugins/plugin_crt0.c @@ -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; } diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c index 5cc79de1d1..d044563cd7 100644 --- a/apps/plugins/pong.c +++ b/apps/plugins/pong.c @@ -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 diff --git a/apps/plugins/reversi/reversi-gui.h b/apps/plugins/reversi/reversi-gui.h index 79755f620a..cc8b305825 100644 --- a/apps/plugins/reversi/reversi-gui.h +++ b/apps/plugins/reversi/reversi-gui.h @@ -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 diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index b310cf65bd..ac23ff7b6f 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c @@ -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 diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index 7d7c9f1b01..3c4bcb829d 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c @@ -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; diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index 7ed5b4104a..b0731afb38 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c @@ -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 diff --git a/apps/plugins/sdl/sdl.make b/apps/plugins/sdl/sdl.make index 8b27c49341..325b430028 100644 --- a/apps/plugins/sdl/sdl.make +++ b/apps/plugins/sdl/sdl.make @@ -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 diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c index 562384ac6a..b3a940bfda 100644 --- a/apps/plugins/sliding_puzzle.c +++ b/apps/plugins/sliding_puzzle.c @@ -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 diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c index 2ae29ee6c0..3eb08271cb 100644 --- a/apps/plugins/snake.c +++ b/apps/plugins/snake.c @@ -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 diff --git a/apps/plugins/snake2.c b/apps/plugins/snake2.c index 6b225713e4..cc8eb06e35 100644 --- a/apps/plugins/snake2.c +++ b/apps/plugins/snake2.c @@ -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 diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c index 625a2679fd..5a539fd9ef 100644 --- a/apps/plugins/sokoban.c +++ b/apps/plugins/sokoban.c @@ -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 diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index abe2143ef8..17e24cbc54 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -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 diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index 95338d0ef9..56bae2125b 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c @@ -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 diff --git a/apps/plugins/star.c b/apps/plugins/star.c index 86e95fc2ce..92b56447d2 100644 --- a/apps/plugins/star.c +++ b/apps/plugins/star.c @@ -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 diff --git a/apps/plugins/stopwatch.c b/apps/plugins/stopwatch.c index 550904efd9..87b1857921 100644 --- a/apps/plugins/stopwatch.c +++ b/apps/plugins/stopwatch.c @@ -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 diff --git a/apps/plugins/sudoku/sudoku.h b/apps/plugins/sudoku/sudoku.h index 8926bd68af..410d15acf0 100644 --- a/apps/plugins/sudoku/sudoku.h +++ b/apps/plugins/sudoku/sudoku.h @@ -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 diff --git a/apps/plugins/text_viewer/tv_button.h b/apps/plugins/text_viewer/tv_button.h index e64ba00e58..c42afdc91b 100644 --- a/apps/plugins/text_viewer/tv_button.h +++ b/apps/plugins/text_viewer/tv_button.h @@ -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 diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c index 22f5fe4b31..1789b9bb89 100644 --- a/apps/plugins/vu_meter.c +++ b/apps/plugins/vu_meter.c @@ -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 diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c index af1e0c9662..065769e7ea 100644 --- a/apps/plugins/wormlet.c +++ b/apps/plugins/wormlet.c @@ -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 diff --git a/apps/plugins/xobox.c b/apps/plugins/xobox.c index 12c9c4fd2b..d29ac579b2 100644 --- a/apps/plugins/xobox.c +++ b/apps/plugins/xobox.c @@ -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 diff --git a/apps/plugins/zxbox/keymaps.h b/apps/plugins/zxbox/keymaps.h index e87c6afff3..d2ffb33fe6 100644 --- a/apps/plugins/zxbox/keymaps.h +++ b/apps/plugins/zxbox/keymaps.h @@ -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 diff --git a/apps/plugins/zxbox/zxbox_keyb.c b/apps/plugins/zxbox/zxbox_keyb.c index 053215ce6d..55629d4f60 100644 --- a/apps/plugins/zxbox/zxbox_keyb.c +++ b/apps/plugins/zxbox/zxbox_keyb.c @@ -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 diff --git a/apps/tree.c b/apps/tree.c index 7f3bee1113..85cf14e465 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -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) diff --git a/apps/tree.h b/apps/tree.h index cf8b4833c1..7d646ffed5 100644 --- a/apps/tree.h +++ b/apps/tree.h @@ -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 diff --git a/firmware/SOURCES b/firmware/SOURCES index 08d81c6edc..f7bcd5d2b9 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -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 diff --git a/firmware/drivers/audio/ctru.c b/firmware/drivers/audio/3ds.c similarity index 100% rename from firmware/drivers/audio/ctru.c rename to firmware/drivers/audio/3ds.c diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index 75e65e05a4..6525cc0452 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -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" diff --git a/firmware/export/config.h b/firmware/export/config.h index 1a70ad7bdb..c826aa513f 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -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 diff --git a/firmware/export/config/ctru.h b/firmware/export/config/3ds.h similarity index 94% rename from firmware/export/config/ctru.h rename to firmware/export/config/3ds.h index 414c99757c..302c671935 100644 --- a/firmware/export/config/ctru.h +++ b/firmware/export/config/3ds.h @@ -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 */ diff --git a/firmware/export/debug.h b/firmware/export/debug.h index 0cda5618bd..114f0b951a 100644 --- a/firmware/export/debug.h +++ b/firmware/export/debug.h @@ -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 */ diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h index 08691eb0a3..de4a3bbb71 100644 --- a/firmware/export/rbpaths.h +++ b/firmware/export/rbpaths.h @@ -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 diff --git a/firmware/include/dir.h b/firmware/include/dir.h index 9cc32f522c..844b56ac1d 100644 --- a/firmware/include/dir.h +++ b/firmware/include/dir.h @@ -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) diff --git a/firmware/include/file.h b/firmware/include/file.h index 72d8cbcafc..470550a2a7 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h @@ -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) diff --git a/firmware/include/rbendian.h b/firmware/include/rbendian.h index 039d3f9521..97bdcd80ab 100644 --- a/firmware/include/rbendian.h +++ b/firmware/include/rbendian.h @@ -27,7 +27,7 @@ #endif #ifndef __MINGW32__ -#if defined(__APPLE__) || defined(CTRU) +#if defined(__APPLE__) || defined(N3DS) #include #else #include diff --git a/firmware/kernel/include/thread.h b/firmware/kernel/include/thread.h index f23c4d9572..286fd97026 100644 --- a/firmware/kernel/include/thread.h +++ b/firmware/kernel/include/thread.h @@ -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" diff --git a/firmware/kernel/mutex.c b/firmware/kernel/mutex.c index 92e8594efe..8c8ddd224d 100644 --- a/firmware/kernel/mutex.c +++ b/firmware/kernel/mutex.c @@ -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 */ diff --git a/firmware/kernel/thread-common.c b/firmware/kernel/thread-common.c index 7fd071b026..25c49069f9 100644 --- a/firmware/kernel/thread-common.c +++ b/firmware/kernel/thread-common.c @@ -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 = diff --git a/firmware/kernel/thread-internal.h b/firmware/kernel/thread-internal.h index 427e6dd033..fcf9bb56d9 100644 --- a/firmware/kernel/thread-internal.h +++ b/firmware/kernel/thread-internal.h @@ -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 */ diff --git a/firmware/target/hosted/ctru/timer-ctru_sys.c b/firmware/target/hosted/ctru/timer-ctru_sys.c deleted file mode 100644 index 2b40fa1343..0000000000 --- a/firmware/target/hosted/ctru/timer-ctru_sys.c +++ /dev/null @@ -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; -} diff --git a/firmware/target/hosted/filesystem-app.h b/firmware/target/hosted/filesystem-app.h index 423e723dd1..c526a1bdcf 100644 --- a/firmware/target/hosted/filesystem-app.h +++ b/firmware/target/hosted/filesystem-app.h @@ -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" diff --git a/firmware/target/hosted/ctru/filesystem-ctru.h b/firmware/target/hosted/filesystem-console.h similarity index 55% rename from firmware/target/hosted/ctru/filesystem-ctru.h rename to firmware/target/hosted/filesystem-console.h index 086af83a67..ee10a725e5 100644 --- a/firmware/target/hosted/ctru/filesystem-ctru.h +++ b/firmware/target/hosted/filesystem-console.h @@ -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 -#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 -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_ */ diff --git a/firmware/target/hosted/ctru/backlight-ctru.c b/firmware/target/hosted/game_console/3ds/backlight-3ds.c similarity index 99% rename from firmware/target/hosted/ctru/backlight-ctru.c rename to firmware/target/hosted/game_console/3ds/backlight-3ds.c index f72ea46d1e..c171e5af56 100644 --- a/firmware/target/hosted/ctru/backlight-ctru.c +++ b/firmware/target/hosted/game_console/3ds/backlight-3ds.c @@ -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 diff --git a/firmware/target/hosted/ctru/button-ctru.c b/firmware/target/hosted/game_console/3ds/button-3ds.c similarity index 99% rename from firmware/target/hosted/ctru/button-ctru.c rename to firmware/target/hosted/game_console/3ds/button-3ds.c index 7c11025fb2..a7144b99e5 100644 --- a/firmware/target/hosted/ctru/button-ctru.c +++ b/firmware/target/hosted/game_console/3ds/button-3ds.c @@ -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" diff --git a/firmware/target/hosted/ctru/filesystem-ctru.c b/firmware/target/hosted/game_console/3ds/filesystem-3ds.c similarity index 100% rename from firmware/target/hosted/ctru/filesystem-ctru.c rename to firmware/target/hosted/game_console/3ds/filesystem-3ds.c diff --git a/firmware/target/hosted/ctru/lc-ctru.c b/firmware/target/hosted/game_console/3ds/lc-3ds.c similarity index 90% rename from firmware/target/hosted/ctru/lc-ctru.c rename to firmware/target/hosted/game_console/3ds/lc-3ds.c index af7cfc8655..110e992804 100644 --- a/firmware/target/hosted/ctru/lc-ctru.c +++ b/firmware/target/hosted/game_console/3ds/lc-3ds.c @@ -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); */ diff --git a/firmware/target/hosted/ctru/lc-program-resolver.c b/firmware/target/hosted/game_console/3ds/lc-program-resolver.c similarity index 100% rename from firmware/target/hosted/ctru/lc-program-resolver.c rename to firmware/target/hosted/game_console/3ds/lc-program-resolver.c diff --git a/firmware/target/hosted/ctru/lcd-bitmap.c b/firmware/target/hosted/game_console/3ds/lcd-bitmap-3ds.c similarity index 99% rename from firmware/target/hosted/ctru/lcd-bitmap.c rename to firmware/target/hosted/game_console/3ds/lcd-bitmap-3ds.c index 20e344e349..1d5b6bf1d5 100644 --- a/firmware/target/hosted/ctru/lcd-bitmap.c +++ b/firmware/target/hosted/game_console/3ds/lcd-bitmap-3ds.c @@ -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" diff --git a/firmware/target/hosted/ctru/luminance-ctru.c b/firmware/target/hosted/game_console/3ds/luminance-3ds.c similarity index 99% rename from firmware/target/hosted/ctru/luminance-ctru.c rename to firmware/target/hosted/game_console/3ds/luminance-3ds.c index 7d1d0a3310..6e59686a2a 100644 --- a/firmware/target/hosted/ctru/luminance-ctru.c +++ b/firmware/target/hosted/game_console/3ds/luminance-3ds.c @@ -28,7 +28,7 @@ #include <3ds.h> #include -#include "luminance-ctru.h" +#include "luminance-3ds.h" // For accessing physmem uncached (and directly) #define PA_PTR(addr) (void *)((u32)(addr) | 1 << 31) diff --git a/firmware/target/hosted/ctru/luminance-ctru.h b/firmware/target/hosted/game_console/3ds/luminance-3ds.h similarity index 93% rename from firmware/target/hosted/ctru/luminance-ctru.h rename to firmware/target/hosted/game_console/3ds/luminance-3ds.h index 148935b790..c28117aa3e 100644 --- a/firmware/target/hosted/ctru/luminance-ctru.h +++ b/firmware/target/hosted/game_console/3ds/luminance-3ds.h @@ -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_ */ diff --git a/firmware/target/hosted/ctru/pcm-ctru.c b/firmware/target/hosted/game_console/3ds/pcm-3ds.c similarity index 97% rename from firmware/target/hosted/ctru/pcm-ctru.c rename to firmware/target/hosted/game_console/3ds/pcm-3ds.c index 999b87ca0e..01335febde 100644 --- a/firmware/target/hosted/ctru/pcm-ctru.c +++ b/firmware/target/hosted/game_console/3ds/pcm-3ds.c @@ -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) diff --git a/firmware/target/hosted/ctru/powermgmt-ctru.c b/firmware/target/hosted/game_console/3ds/powermgmt-3ds.c similarity index 100% rename from firmware/target/hosted/ctru/powermgmt-ctru.c rename to firmware/target/hosted/game_console/3ds/powermgmt-3ds.c diff --git a/firmware/target/hosted/ctru/system-ctru.c b/firmware/target/hosted/game_console/3ds/system-3ds.c similarity index 97% rename from firmware/target/hosted/ctru/system-ctru.c rename to firmware/target/hosted/game_console/3ds/system-3ds.c index 0a9fb1b2ec..473a91c699 100644 --- a/firmware/target/hosted/ctru/system-ctru.c +++ b/firmware/target/hosted/game_console/3ds/system-3ds.c @@ -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" diff --git a/firmware/target/hosted/ctru/app/adc-target.h b/firmware/target/hosted/game_console/adc-target.h similarity index 100% rename from firmware/target/hosted/ctru/app/adc-target.h rename to firmware/target/hosted/game_console/adc-target.h diff --git a/firmware/target/hosted/ctru/app/backlight-target.h b/firmware/target/hosted/game_console/backlight-target.h similarity index 100% rename from firmware/target/hosted/ctru/app/backlight-target.h rename to firmware/target/hosted/game_console/backlight-target.h diff --git a/firmware/target/hosted/ctru/button-ctru.h b/firmware/target/hosted/game_console/button-console.h similarity index 92% rename from firmware/target/hosted/ctru/button-ctru.h rename to firmware/target/hosted/game_console/button-console.h index 606c7d09f4..2cfea0cfea 100644 --- a/firmware/target/hosted/ctru/button-ctru.h +++ b/firmware/target/hosted/game_console/button-console.h @@ -19,8 +19,8 @@ ****************************************************************************/ -#ifndef __BUTTON_CTRU_H__ -#define __BUTTON_CTRU_H__ +#ifndef __BUTTON_CONSOLE_H__ +#define __BUTTON_CONSOLE_H__ #include #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__ */ diff --git a/firmware/target/hosted/ctru/app/button-target.h b/firmware/target/hosted/game_console/button-target.h similarity index 100% rename from firmware/target/hosted/ctru/app/button-target.h rename to firmware/target/hosted/game_console/button-target.h diff --git a/firmware/target/hosted/ctru/buttonmap.h b/firmware/target/hosted/game_console/buttonmap.h similarity index 100% rename from firmware/target/hosted/ctru/buttonmap.h rename to firmware/target/hosted/game_console/buttonmap.h diff --git a/firmware/target/hosted/ctru/kernel-ctru.c b/firmware/target/hosted/game_console/kernel-console.c similarity index 87% rename from firmware/target/hosted/ctru/kernel-ctru.c rename to firmware/target/hosted/game_console/kernel-console.c index 27d7f2cee0..f68b807a71 100644 --- a/firmware/target/hosted/ctru/kernel-ctru.c +++ b/firmware/target/hosted/game_console/kernel-console.c @@ -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 #include #include -#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); -} - +} \ No newline at end of file diff --git a/firmware/target/hosted/ctru/lcd-bitmap.h b/firmware/target/hosted/game_console/lcd-bitmap.h similarity index 100% rename from firmware/target/hosted/ctru/lcd-bitmap.h rename to firmware/target/hosted/game_console/lcd-bitmap.h diff --git a/firmware/target/hosted/ctru/lcd-target.h b/firmware/target/hosted/game_console/lcd-target.h similarity index 100% rename from firmware/target/hosted/ctru/lcd-target.h rename to firmware/target/hosted/game_console/lcd-target.h diff --git a/firmware/target/hosted/ctru/lib/bfile/bfile.c b/firmware/target/hosted/game_console/lib/bfile/bfile-3ds.c similarity index 84% rename from firmware/target/hosted/ctru/lib/bfile/bfile.c rename to firmware/target/hosted/game_console/lib/bfile/bfile-3ds.c index e7a8625e71..2aa5f53f64 100644 --- a/firmware/target/hosted/ctru/lib/bfile/bfile.c +++ b/firmware/target/hosted/game_console/lib/bfile/bfile-3ds.c @@ -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) { diff --git a/firmware/target/hosted/ctru/lib/bfile/bfile-internal.h b/firmware/target/hosted/game_console/lib/bfile/bfile-internal.h similarity index 74% rename from firmware/target/hosted/ctru/lib/bfile/bfile-internal.h rename to firmware/target/hosted/game_console/lib/bfile/bfile-internal.h index 62977a68ad..745dfc4a87 100644 --- a/firmware/target/hosted/ctru/lib/bfile/bfile-internal.h +++ b/firmware/target/hosted/game_console/lib/bfile/bfile-internal.h @@ -9,17 +9,7 @@ #include #include -#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_ */ diff --git a/firmware/target/hosted/game_console/lib/bfile/bfile-rwmutex.c b/firmware/target/hosted/game_console/lib/bfile/bfile-rwmutex.c new file mode 100644 index 0000000000..d7ff6a2807 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/bfile/bfile-rwmutex.c @@ -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); +} \ No newline at end of file diff --git a/firmware/target/hosted/ctru/lib/bfile/bfile.h b/firmware/target/hosted/game_console/lib/bfile/bfile.h similarity index 100% rename from firmware/target/hosted/ctru/lib/bfile/bfile.h rename to firmware/target/hosted/game_console/lib/bfile/bfile.h diff --git a/firmware/target/hosted/game_console/lib/sys_atomic.c b/firmware/target/hosted/game_console/lib/sys_atomic.c new file mode 100644 index 0000000000..22ad664ba1 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_atomic.c @@ -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 +#include +#include +#include +#include +#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); +} diff --git a/firmware/target/hosted/game_console/lib/sys_atomic.h b/firmware/target/hosted/game_console/lib/sys_atomic.h new file mode 100644 index 0000000000..722eff2a77 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_atomic.h @@ -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__ */ + diff --git a/firmware/target/hosted/game_console/lib/sys_cond_generic.c b/firmware/target/hosted/game_console/lib/sys_cond_generic.c new file mode 100644 index 0000000000..15b58c1505 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_cond_generic.c @@ -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 +#include +#include +#include +#include +#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; +} diff --git a/firmware/target/hosted/ctru/lib/sys_dir.c b/firmware/target/hosted/game_console/lib/sys_dir_3ds.c similarity index 91% rename from firmware/target/hosted/ctru/lib/sys_dir.c rename to firmware/target/hosted/game_console/lib/sys_dir_3ds.c index 1088110b94..91a441987f 100644 --- a/firmware/target/hosted/ctru/lib/sys_dir.c +++ b/firmware/target/hosted/game_console/lib/sys_dir_3ds.c @@ -26,6 +26,7 @@ #include <3ds/util/utf.h> /* this includes a couple of 3ds headers */ #include "sys_file.h" +#include "sys_file_internal.h" #include "config.h" #include "debug.h" @@ -46,7 +47,7 @@ static struct dirstr_desc { struct filestr_base stream; /* basic stream info (first!) */ struct dirent entry; /* current parsed entry information */ -} open_streams[MAX_OPEN_DIRS] = +} open_dir_streams[MAX_OPEN_DIRS] = { [0 ... MAX_OPEN_FILES-1] = { .stream = { .cache = NULL } } }; @@ -58,7 +59,7 @@ static struct dirstr_desc * get_dirstr(DIR *dirp) { struct dirstr_desc *dir = (struct dirstr_desc *)dirp; - if (!PTR_IN_ARRAY(open_streams, dir, MAX_OPEN_DIRS)) + if (!PTR_IN_ARRAY(open_dir_streams, dir, MAX_OPEN_DIRS)) dir = NULL; else if (dir->stream.cache != NULL) return dir; @@ -71,7 +72,7 @@ static struct dirstr_desc * get_dirstr(DIR *dirp) } else { - logf("dir #%d: dir not open\n", (int)(dir - open_streams)); + logf("dir #%d: dir not open\n", (int)(dir - open_dir_streams)); errnum = EBADF; } @@ -104,7 +105,7 @@ static struct dirstr_desc * alloc_dirstr(void) { for (unsigned int dd = 0; dd < MAX_OPEN_DIRS; dd++) { - struct dirstr_desc *dir = &open_streams[dd]; + struct dirstr_desc *dir = &open_dir_streams[dd]; if (dir->stream.cache == NULL) return dir; } @@ -119,19 +120,10 @@ u32 fs_error(void) { return err; } -/* Initialize the base descriptor */ -static void filestr_base_init(struct filestr_base *stream) -{ - stream->cache = NULL; - stream->handle = 0; - stream->size = 0; - LightLock_Init(&stream->mtx); -} - /** POSIX interface **/ /* open a directory */ -DIR * ctru_opendir(const char *dirname) +DIR * console_opendir(const char *dirname) { logf("opendir(dirname=\"%s\")\n", dirname); @@ -161,7 +153,7 @@ DIR * ctru_opendir(const char *dirname) dir->stream.size = 0; dir->stream.flags = 0; - /* we will use file path to implement ctru_samedir function */ + /* we will use file path to implement console_samedir function */ strcpy(dir->stream.path, dirname); dirp = (DIR *)dir; @@ -175,7 +167,7 @@ file_error: } /* close a directory stream */ -int ctru_closedir(DIR *dirp) +int console_closedir(DIR *dirp) { int rc; @@ -183,14 +175,14 @@ int ctru_closedir(DIR *dirp) /* needs to work even if marked "nonexistant" */ struct dirstr_desc * const dir = (struct dirstr_desc *)dirp; - if (!PTR_IN_ARRAY(open_streams, dir, MAX_OPEN_DIRS)) + if (!PTR_IN_ARRAY(open_dir_streams, dir, MAX_OPEN_DIRS)) FILE_ERROR(EFAULT, -1); logf("closedir(dirname=\"%s\")\n", dir->stream.path); if (dir->stream.cache == NULL) { - logf("dir #%d: dir not open\n", (int)(dir - open_streams)); + logf("dir #%d: dir not open\n", (int)(dir - open_dir_streams)); FILE_ERROR(EBADF, -2); } @@ -236,7 +228,7 @@ void dirstr_entry_init(FS_DirectoryEntry *dirEntry, struct dirent *entry) } /* read a directory */ -struct dirent * ctru_readdir(DIR *dirp) +struct dirent * console_readdir(DIR *dirp) { struct dirstr_desc * const dir = GET_DIRSTR(READER, dirp); if (!dir) @@ -294,7 +286,7 @@ enum }; /* make a directory */ -int ctru_mkdir(const char *path) +int console_mkdir(const char *path) { logf("mkdir(path=\"%s\")\n", path); @@ -321,7 +313,7 @@ file_error: } /* remove a directory */ -int ctru_rmdir(const char *name) +int console_rmdir(const char *name) { logf("rmdir(name=\"%s\")\n", name); @@ -355,7 +347,7 @@ file_error: /** Extended interface **/ /* return if two directory streams refer to the same directory */ -int ctru_samedir(DIR *dirp1, DIR *dirp2) +int console_samedir(DIR *dirp1, DIR *dirp2) { struct dirstr_desc * const dir1 = GET_DIRSTR(WRITER, dirp1); if (!dir1) @@ -373,7 +365,7 @@ int ctru_samedir(DIR *dirp1, DIR *dirp2) } /* test directory existence (returns 'false' if a file) */ -bool ctru_dir_exists(const char *dirname) +bool console_dir_exists(const char *dirname) { file_internal_lock_WRITER(); @@ -421,7 +413,7 @@ file_error: return (struct dirinfo){ .attribute = 0 }; } -const char* ctru_root_realpath(void) +const char* console_root_realpath(void) { /* Native only, for APP and SIM see respective filesystem-.c files */ return PATH_ROOTSTR; /* rb_namespace.c */ diff --git a/firmware/target/hosted/ctru/lib/sys_file.h b/firmware/target/hosted/game_console/lib/sys_file.h similarity index 87% rename from firmware/target/hosted/ctru/lib/sys_file.h rename to firmware/target/hosted/game_console/lib/sys_file.h index 4640b16db4..925b014716 100644 --- a/firmware/target/hosted/ctru/lib/sys_file.h +++ b/firmware/target/hosted/game_console/lib/sys_file.h @@ -27,27 +27,24 @@ #define strlcpy_from_os strlcpy -#define AtomicLoad(ptr) __atomic_load_n((u32*)(ptr), __ATOMIC_SEQ_CST) -#define AtomicAdd(ptr, value) __atomic_add_fetch((u32*)(ptr), value, __ATOMIC_SEQ_CST) - struct filestr_base { - PageReader* cache; /* buffer IO implementation (cache) */ - Handle handle; /* file handle */ - u64 size; /* file size */ - int flags; /* stream flags */ - char path[MAX_PATH+1]; + PageReader* cache; /* buffer IO implementation (cache) */ + sys_handle_type handle; /* file handle */ + u64 size; /* file size */ + int flags; /* stream flags */ + char path[MAX_PATH+1]; - LightLock mtx; /* serialization for this stream */ + sysMutex mtx; /* serialization for this stream */ }; static inline void filestr_lock(struct filestr_base *stream) { - LightLock_Lock(&stream->mtx); + sys_mutex_lock(&stream->mtx); } static inline void filestr_unlock(struct filestr_base *stream) { - LightLock_Unlock(&stream->mtx); + sys_mutex_unlock(&stream->mtx); } /* stream lock doesn't have to be used if getting RW lock writer access */ diff --git a/firmware/target/hosted/ctru/lib/sys_file.c b/firmware/target/hosted/game_console/lib/sys_file_3ds.c similarity index 50% rename from firmware/target/hosted/ctru/lib/sys_file.c rename to firmware/target/hosted/game_console/lib/sys_file_3ds.c index 72ebfa8fcd..924572ef0d 100644 --- a/firmware/target/hosted/ctru/lib/sys_file.c +++ b/firmware/target/hosted/game_console/lib/sys_file_3ds.c @@ -26,6 +26,7 @@ /* this includes a couple of 3ds headers */ #include "sys_file.h" +#include "sys_file_internal.h" #define RB_FILESYSTEM_OS #include "config.h" @@ -40,77 +41,8 @@ // #define LOGF_ENABLE #include "logf.h" -/** - * These functions provide a roughly POSIX-compatible file I/O API. - * Important: the bufferio I/O library (bfile) used in the 3ds does not work - * with write-only files due to an internal limitation. - * So all files will be opened with the read flag by default. - */ - -/* structure used for open file descriptors */ -static struct filestr_desc -{ - struct filestr_base stream; /* basic stream info (first!) */ - file_size_t offset; /* current offset for stream */ - u64 *sizep; /* shortcut to file size in fileobj */ -} open_streams[MAX_OPEN_FILES] = -{ - [0 ... MAX_OPEN_FILES-1] = { .stream = { .cache = NULL, .flags = 0 } } -}; - extern FS_Archive sdmcArchive; -/* check and return a struct filestr_desc* from a file descriptor number */ -static struct filestr_desc * get_filestr(int fildes) -{ - struct filestr_desc *file = &open_streams[fildes]; - - if ((unsigned int)fildes >= MAX_OPEN_FILES) - file = NULL; - else if (file->stream.cache != NULL) - return file; - - logf("fildes %d: bad file number\n", fildes); - errno = (file && (file->stream.cache == NULL)) ? ENXIO : EBADF; - return NULL; -} - -#define GET_FILESTR(type, fildes) \ - ({ \ - file_internal_lock_##type(); \ - struct filestr_desc * _file = get_filestr(fildes); \ - if (_file) \ - FILESTR_LOCK(type, &_file->stream); \ - else { \ - file_internal_unlock_##type(); \ - }\ - _file; \ - }) - -/* release the lock on the filestr_desc* */ -#define RELEASE_FILESTR(type, file) \ - ({ \ - FILESTR_UNLOCK(type, &(file)->stream); \ - file_internal_unlock_##type(); \ - }) - -/* find a free file descriptor */ -static int alloc_filestr(struct filestr_desc **filep) -{ - for (int fildes = 0; fildes < MAX_OPEN_FILES; fildes++) - { - struct filestr_desc *file = &open_streams[fildes]; - if (file->stream.cache == NULL) - { - *filep = file; - return fildes; - } - } - - logf("Too many files open\n"); - return -1; -} - /* check for file existence */ int test_stream_exists_internal(const char *path) { @@ -148,146 +80,6 @@ file_error: return rc; } -/* set the file pointer */ -static off_t lseek_internal(struct filestr_desc *file, off_t offset, - int whence) -{ - off_t rc; - off_t pos; - - off_t size = MIN(*file->sizep, FILE_SIZE_MAX); - off_t file_offset = AtomicLoad(&file->offset); - - switch (whence) - { - case SEEK_SET: - if (offset < 0 || (off_t)offset > size) - FILE_ERROR(EINVAL, -1); - - pos = offset; - break; - - case SEEK_CUR: - if ((offset < 0 && (off_t)-offset > file_offset) || - (offset > 0 && (off_t)offset > size - file_offset)) - FILE_ERROR(EINVAL, -1); - - pos = file_offset + offset; - break; - - case SEEK_END: - if (offset > 0 || (off_t)-offset > size) - FILE_ERROR(EINVAL, -1); - - pos = size + offset; - break; - - default: - FILE_ERROR(EINVAL, -1); - } - - AtomicSwap(&file->offset, pos); - - return pos; -file_error: - return rc; -} - -/* read from or write to the file; back end to read() and write() */ -static ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte, - bool write) -{ -#ifndef LOGF_ENABLE /* wipes out log before you can save it */ - /* DEBUGF("readwrite(%p,%lx,%lu,%s)\n", - file, (long)buf, (unsigned long)nbyte, write ? "write" : "read"); */ -#endif - - const file_size_t size = *file->sizep; - size_t filerem; - - if (write) - { - /* if opened in append mode, move pointer to end */ - if (file->stream.flags & O_APPEND) - AtomicSwap(&file->offset, MIN(size, FILE_SIZE_MAX)); - - filerem = FILE_SIZE_MAX - AtomicLoad(&file->offset); - } - else - { - /* limit to maximum possible offset (EOF or FILE_SIZE_MAX) */ - filerem = MIN(size, FILE_SIZE_MAX) - AtomicLoad(&file->offset); - } - - if (nbyte > filerem) - { - nbyte = filerem; - if (nbyte > 0) - {} - else if (write) - FILE_ERROR_RETURN(EFBIG, -1); /* would get too large */ - else if (AtomicLoad(&file->offset) >= FILE_SIZE_MAX) - FILE_ERROR_RETURN(EOVERFLOW, -2); /* can't read here */ - } - - if (nbyte == 0) - return 0; - - int rc = 0; - int_error_t n_err; - - if (write) { - n_err = PageReader_WriteAt(file->stream.cache, - buf, - nbyte, - AtomicLoad(&file->offset), - file->stream.flags & O_RDWR ? true : false); - } - else { - n_err = PageReader_ReadAt(file->stream.cache, - buf, - nbyte, - AtomicLoad(&file->offset)); - } - - if ((n_err.err != NULL) && strcmp(n_err.err, "io.EOF")) { - FILE_ERROR(ERRNO, -3); - } - -file_error:; -#ifdef DEBUG - if (errno == ENOSPC) - logf("No space left on device\n"); -#endif - - size_t done = n_err.n; - if (done) - { - /* error or not, update the file offset and size if anything was - transferred */ - AtomicAdd(&file->offset, done); -#ifndef LOGF_ENABLE /* wipes out log before you can save it */ - /* DEBUGF("file offset: %lld\n", file->offset); */ -#endif - /* adjust file size to length written */ - if (write && AtomicLoad(&file->offset) > size) - *file->sizep = AtomicLoad(&file->offset); - - return done; - } - - return rc; -} - -/* initialize the base descriptor */ -static void filestr_base_init(struct filestr_base *stream) -{ - stream->cache = NULL; - stream->handle = 0; - stream->size = 0; - LightLock_Init(&stream->mtx); -} - int open_internal_inner2(Handle *handle, const char *path, u32 openFlags, u32 attributes) { int rc; @@ -305,7 +97,7 @@ file_error: return rc; } -static int open_internal_inner1(const char *path, int oflag) +int open_internal_inner1(const char *path, int oflag) { int rc; struct filestr_desc *file; @@ -391,9 +183,9 @@ static int open_internal_inner1(const char *path, int oflag) file->stream.flags = oflag; file->stream.size = size; file->sizep = &file->stream.size; - AtomicSwap(&file->offset, 0); + AtomicSet(&file->offset, 0); - /* we will use file path to implement ctru_fsamefile function */ + /* we will use file path to implement console_fsamefile function */ strcpy(file->stream.path, path); return fildes; @@ -413,27 +205,7 @@ file_error: return rc; } -static int open_internal_locked(const char *path, int oflag) -{ - file_internal_lock_WRITER(); - int rc = open_internal_inner1(path, oflag); - file_internal_unlock_WRITER(); - return rc; -} - -int ctru_open(const char *path, int oflag, ...) -{ - logf("open(path=\"%s\",oflag=%X)\n", path, (unsigned)oflag); - return open_internal_locked(path, oflag); -} - -int ctru_creat(const char *path, mode_t mode) -{ - logf("creat(path=\"%s\")\n", path); - return ctru_open(path, O_WRONLY|O_CREAT|O_TRUNC, mode); -} - -int ctru_close(int fildes) +int console_close(int fildes) { logf("close(fd=%d)\n", fildes); @@ -466,7 +238,7 @@ file_error: } /* truncate a file to a specified length */ -int ctru_ftruncate(int fildes, off_t length) +int console_ftruncate(int fildes, off_t length) { logf("ftruncate(fd=%d,len=%ld)\n", fildes, (long)length); @@ -502,7 +274,7 @@ file_error: } /* synchronize changes to a file */ -int ctru_fsync(int fildes) +int console_fsync(int fildes) { logf("fsync(fd=%d)\n", fildes); @@ -530,79 +302,8 @@ file_error: return rc; } -/* move the read/write file offset */ -off_t ctru_lseek(int fildes, off_t offset, int whence) -{ -#ifndef LOGF_ENABLE /* wipes out log before you can save it */ - /* DEBUGF("lseek(fd=%d,ofs=%ld,wh=%d)\n", fildes, (long)offset, whence); */ -#endif - struct filestr_desc * const file = GET_FILESTR(READER, fildes); - if (!file) - FILE_ERROR_RETURN(ERRNO, -1); - - off_t rc = lseek_internal(file, offset, whence); - if (rc < 0) - FILE_ERROR(ERRNO, rc * 10 - 2); - -file_error: - RELEASE_FILESTR(READER, file); - return rc; -} - -/* read from a file */ -ssize_t ctru_read(int fildes, void *buf, size_t nbyte) -{ - struct filestr_desc * const file = GET_FILESTR(READER, fildes); - if (!file) - FILE_ERROR_RETURN(ERRNO, -1); - - ssize_t rc; - - if (file->stream.flags & O_WRONLY) - { - logf("read(fd=%d,buf=%p,nb=%lu) - " - "descriptor is write-only mode\n", - fildes, buf, (unsigned long)nbyte); - FILE_ERROR(EBADF, -2); - } - - rc = readwrite(file, buf, nbyte, false); - if (rc < 0) - FILE_ERROR(ERRNO, rc * 10 - 3); - -file_error: - RELEASE_FILESTR(READER, file); - return rc; -} - -/* write on a file */ -ssize_t ctru_write(int fildes, const void *buf, size_t nbyte) -{ - struct filestr_desc * const file = GET_FILESTR(READER, fildes); - if (!file) - FILE_ERROR_RETURN(ERRNO, -1); - - ssize_t rc; - - if (file->stream.flags & O_RDONLY) - { - logf("write(fd=%d,buf=%p,nb=%lu) - " - "descriptor is read-only mode\n", - fildes, buf, (unsigned long)nbyte); - FILE_ERROR(EBADF, -2); - } - - rc = readwrite(file, (void *)buf, nbyte, true); - if (rc < 0) - FILE_ERROR(ERRNO, rc * 10 - 3); - -file_error: - RELEASE_FILESTR(READER, file); - return rc; -} - /* remove a file */ -int ctru_remove(const char *path) +int console_remove(const char *path) { logf("remove(path=\"%s\")\n", path); @@ -621,7 +322,7 @@ file_error: } /* rename a file */ -int ctru_rename(const char *old, const char *new) +int console_rename(const char *old, const char *new) { /* note: move by rename does not work in devkitARM toolchain */ logf("rename(old=\"%s\",new=\"%s\")\n", old, new); @@ -698,7 +399,7 @@ file_error: /** Extensions **/ /* todo: utime does not work in devkitARM toolchain */ -int ctru_modtime(const char *path, time_t modtime) +int console_modtime(const char *path, time_t modtime) { struct utimbuf times = { @@ -709,66 +410,8 @@ int ctru_modtime(const char *path, time_t modtime) return utime(path, ×); } -/* get the binary size of a file (in bytes) */ -off_t ctru_filesize(int fildes) -{ - struct filestr_desc * const file = GET_FILESTR(READER, fildes); - if (!file) - FILE_ERROR_RETURN(ERRNO, -1); - - off_t rc; - file_size_t size = *file->sizep; - - if (size > FILE_SIZE_MAX) - FILE_ERROR(EOVERFLOW, -2); - - rc = (off_t)size; -file_error: - RELEASE_FILESTR(READER, file); - return rc; -} - -/* test if two file descriptors refer to the same file */ -int ctru_fsamefile(int fildes1, int fildes2) -{ - struct filestr_desc * const file1 = GET_FILESTR(WRITER, fildes1); - if (!file1) - FILE_ERROR_RETURN(ERRNO, -1); - - int rc = -2; - - struct filestr_desc * const file2 = get_filestr(fildes2); - if (file2) - rc = strcmp(file1->stream.path, file2->stream.path) == 0 ? 1 : 0; - - RELEASE_FILESTR(WRITER, file1); - return rc; -} - -/* tell the relationship of path1 to path2 */ -int ctru_relate(const char *path1, const char *path2) -{ - /* FAT32 file system does not support symbolic links, - therefore, comparing the two full paths should be enough - to tell relationship */ - logf("relate(path1=\"%s\",path2=\"%s\")\n", path1, path2); - int rc = RELATE_DIFFERENT; - if (strcmp(path1, path2) == 0) - rc = RELATE_SAME; - return rc; -} - -/* test file or directory existence */ -bool ctru_file_exists(const char *path) -{ - file_internal_lock_WRITER(); - bool rc = test_stream_exists_internal(path) > 0; - file_internal_unlock_WRITER(); - return rc; -} - /* note: no symbolic links support in devkitARM */ -ssize_t ctru_readlink(const char *path, char *buf, size_t bufsiz) +ssize_t console_readlink(const char *path, char *buf, size_t bufsiz) { return readlink(path, buf, bufsiz); } diff --git a/firmware/target/hosted/game_console/lib/sys_file_common.c b/firmware/target/hosted/game_console/lib/sys_file_common.c new file mode 100644 index 0000000000..2eab3dd4a3 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_file_common.c @@ -0,0 +1,384 @@ +/*************************************************************************** + * __________ __ ___. + * 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 +#include +#include +#include +#include +#include "fs_defines.h" + +/* this includes a couple of 3ds headers */ +#include "sys_file.h" +#include "sys_file_internal.h" + +#define RB_FILESYSTEM_OS +#include "config.h" +#include "system.h" +#include "file.h" +#include "debug.h" +#include "string-extra.h" + +/* This file is based on firmware/common/file.c */ + +/* Define LOGF_ENABLE to enable logf output in this file */ +// #define LOGF_ENABLE +#include "logf.h" + +/** + * These functions provide a roughly POSIX-compatible file I/O API. + * Important: the bufferio I/O library (bfile) used in the 3ds does not work + * with write-only files due to an internal limitation. + * So all files will be opened with the read flag by default. + */ + +struct filestr_desc open_streams[MAX_OPEN_FILES] = +{ + [0 ... MAX_OPEN_FILES-1] = { .stream = { .cache = NULL, .flags = 0 } } +}; + +/* check and return a struct filestr_desc* from a file descriptor number */ +struct filestr_desc * get_filestr(int fildes) +{ + struct filestr_desc *file = &open_streams[fildes]; + + if ((unsigned int)fildes >= MAX_OPEN_FILES) + file = NULL; + else if (file->stream.cache != NULL) + return file; + + logf("fildes %d: bad file number\n", fildes); + errno = (file && (file->stream.cache == NULL)) ? ENXIO : EBADF; + return NULL; +} + +/* find a free file descriptor */ +int alloc_filestr(struct filestr_desc **filep) +{ + for (int fildes = 0; fildes < MAX_OPEN_FILES; fildes++) + { + struct filestr_desc *file = &open_streams[fildes]; + if (file->stream.cache == NULL) + { + *filep = file; + return fildes; + } + } + + logf("Too many files open\n"); + return -1; +} + +/* set the file pointer */ +off_t lseek_internal(struct filestr_desc *file, off_t offset, + int whence) +{ + off_t rc; + off_t pos; + + off_t size = MIN(*file->sizep, FILE_SIZE_MAX); + off_t file_offset = AtomicGet(&file->offset); + + switch (whence) + { + case SEEK_SET: + if (offset < 0 || (off_t)offset > size) + FILE_ERROR(EINVAL, -1); + + pos = offset; + break; + + case SEEK_CUR: + if ((offset < 0 && (off_t)-offset > file_offset) || + (offset > 0 && (off_t)offset > size - file_offset)) + FILE_ERROR(EINVAL, -1); + + pos = file_offset + offset; + break; + + case SEEK_END: + if (offset > 0 || (off_t)-offset > size) + FILE_ERROR(EINVAL, -1); + + pos = size + offset; + break; + + default: + FILE_ERROR(EINVAL, -1); + } + + AtomicSet(&file->offset, pos); + + return pos; +file_error: + return rc; +} + +/* read from or write to the file; back end to read() and write() */ +ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte, + bool write) +{ +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ + /* DEBUGF("readwrite(%p,%lx,%lu,%s)\n", + file, (long)buf, (unsigned long)nbyte, write ? "write" : "read"); */ +#endif + + const file_size_t size = *file->sizep; + size_t filerem; + + if (write) + { + /* if opened in append mode, move pointer to end */ + if (file->stream.flags & O_APPEND) + AtomicSet(&file->offset, MIN(size, FILE_SIZE_MAX)); + + filerem = FILE_SIZE_MAX - AtomicGet(&file->offset); + } + else + { + /* limit to maximum possible offset (EOF or FILE_SIZE_MAX) */ + filerem = MIN(size, FILE_SIZE_MAX) - AtomicGet(&file->offset); + } + + if (nbyte > filerem) + { + nbyte = filerem; + if (nbyte > 0) + {} + else if (write) + FILE_ERROR_RETURN(EFBIG, -1); /* would get too large */ + else if (AtomicGet(&file->offset) >= FILE_SIZE_MAX) + FILE_ERROR_RETURN(EOVERFLOW, -2); /* can't read here */ + } + + if (nbyte == 0) + return 0; + + int rc = 0; + int_error_t n_err; + + if (write) { + n_err = PageReader_WriteAt(file->stream.cache, + buf, + nbyte, + AtomicGet(&file->offset), + file->stream.flags & O_RDWR ? true : false); + } + else { + n_err = PageReader_ReadAt(file->stream.cache, + buf, + nbyte, + AtomicGet(&file->offset)); + } + + if ((n_err.err != NULL) && strcmp(n_err.err, "io.EOF")) { + FILE_ERROR(ERRNO, -3); + } + +file_error:; +#ifdef DEBUG + if (errno == ENOSPC) + logf("No space left on device\n"); +#endif + + size_t done = n_err.n; + if (done) + { + /* error or not, update the file offset and size if anything was + transferred */ + AtomicAdd(&file->offset, done); +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ + /* DEBUGF("file offset: %lld\n", file->offset); */ +#endif + /* adjust file size to length written */ + if (write && AtomicGet(&file->offset) > size) + *file->sizep = AtomicGet(&file->offset); + + return done; + } + + return rc; +} + +/* initialize the base descriptor */ +void filestr_base_init(struct filestr_base *stream) +{ + stream->cache = NULL; + stream->handle = 0; + stream->size = 0; + sys_mutex_init(&stream->mtx); +} + +int open_internal_inner1(const char *path, int oflag); +int open_internal_locked(const char *path, int oflag) +{ + file_internal_lock_WRITER(); + int rc = open_internal_inner1(path, oflag); + file_internal_unlock_WRITER(); + return rc; +} + +int console_open(const char *path, int oflag, ...) +{ + logf("open(path=\"%s\",oflag=%X)\n", path, (unsigned)oflag); + + /* we need to wait a little here when playing a folder with many small files + to prevent other threads starvation */ + sleep(10); + + return open_internal_locked(path, oflag); +} + +int console_creat(const char *path, mode_t mode) +{ + logf("creat(path=\"%s\")\n", path); + return console_open(path, O_WRONLY|O_CREAT|O_TRUNC, mode); +} + +/* move the read/write file offset */ +off_t console_lseek(int fildes, off_t offset, int whence) +{ +#ifndef LOGF_ENABLE /* wipes out log before you can save it */ + /* DEBUGF("lseek(fd=%d,ofs=%ld,wh=%d)\n", fildes, (long)offset, whence); */ +#endif + struct filestr_desc * const file = GET_FILESTR(READER, fildes); + if (!file) + FILE_ERROR_RETURN(ERRNO, -1); + + off_t rc = lseek_internal(file, offset, whence); + if (rc < 0) + FILE_ERROR(ERRNO, rc * 10 - 2); + +file_error: + RELEASE_FILESTR(READER, file); + return rc; +} + +/* read from a file */ +ssize_t console_read(int fildes, void *buf, size_t nbyte) +{ + struct filestr_desc * const file = GET_FILESTR(READER, fildes); + if (!file) + FILE_ERROR_RETURN(ERRNO, -1); + + ssize_t rc; + + if (file->stream.flags & O_WRONLY) + { + logf("read(fd=%d,buf=%p,nb=%lu) - " + "descriptor is write-only mode\n", + fildes, buf, (unsigned long)nbyte); + FILE_ERROR(EBADF, -2); + } + + rc = readwrite(file, buf, nbyte, false); + if (rc < 0) + FILE_ERROR(ERRNO, rc * 10 - 3); + +file_error: + RELEASE_FILESTR(READER, file); + return rc; +} + +/* write on a file */ +ssize_t console_write(int fildes, const void *buf, size_t nbyte) +{ + struct filestr_desc * const file = GET_FILESTR(READER, fildes); + if (!file) + FILE_ERROR_RETURN(ERRNO, -1); + + ssize_t rc; + + if (file->stream.flags & O_RDONLY) + { + logf("write(fd=%d,buf=%p,nb=%lu) - " + "descriptor is read-only mode\n", + fildes, buf, (unsigned long)nbyte); + FILE_ERROR(EBADF, -2); + } + + rc = readwrite(file, (void *)buf, nbyte, true); + if (rc < 0) + FILE_ERROR(ERRNO, rc * 10 - 3); + +file_error: + RELEASE_FILESTR(READER, file); + return rc; +} + +/** Extensions **/ + +/* get the binary size of a file (in bytes) */ +off_t console_filesize(int fildes) +{ + struct filestr_desc * const file = GET_FILESTR(READER, fildes); + if (!file) + FILE_ERROR_RETURN(ERRNO, -1); + + off_t rc; + file_size_t size = *file->sizep; + + if (size > FILE_SIZE_MAX) + FILE_ERROR(EOVERFLOW, -2); + + rc = (off_t)size; +file_error: + RELEASE_FILESTR(READER, file); + return rc; +} + +/* test if two file descriptors refer to the same file */ +int console_fsamefile(int fildes1, int fildes2) +{ + struct filestr_desc * const file1 = GET_FILESTR(WRITER, fildes1); + if (!file1) + FILE_ERROR_RETURN(ERRNO, -1); + + int rc = -2; + + struct filestr_desc * const file2 = get_filestr(fildes2); + if (file2) + rc = strcmp(file1->stream.path, file2->stream.path) == 0 ? 1 : 0; + + RELEASE_FILESTR(WRITER, file1); + return rc; +} + +/* tell the relationship of path1 to path2 */ +int console_relate(const char *path1, const char *path2) +{ + /* FAT32 file system does not support symbolic links, + therefore, comparing the two full paths should be enough + to tell relationship */ + logf("relate(path1=\"%s\",path2=\"%s\")\n", path1, path2); + int rc = RELATE_DIFFERENT; + if (strcmp(path1, path2) == 0) + rc = RELATE_SAME; + return rc; +} + +/* test file or directory existence */ +int test_stream_exists_internal(const char *path); +bool console_file_exists(const char *path) +{ + file_internal_lock_WRITER(); + bool rc = test_stream_exists_internal(path) > 0; + file_internal_unlock_WRITER(); + return rc; +} \ No newline at end of file diff --git a/firmware/target/hosted/game_console/lib/sys_file_internal.h b/firmware/target/hosted/game_console/lib/sys_file_internal.h new file mode 100644 index 0000000000..cb800c7dd9 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_file_internal.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2025 by 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 _SYS_FILE_INTERNAL_H +#define _SYS_FILE_INTERNAL_H + +/* structure used for open file descriptors */ +struct filestr_base; +struct filestr_desc +{ + struct filestr_base stream; /* basic stream info (first!) */ + file_size_t offset; /* current offset for stream */ + u64 *sizep; /* shortcut to file size in fileobj */ +}; + +extern struct filestr_desc open_streams[MAX_OPEN_FILES]; + +int test_stream_exists_internal(const char *path); +int alloc_filestr(struct filestr_desc **filep); +struct filestr_desc * get_filestr(int fildes); +off_t lseek_internal(struct filestr_desc *file, off_t offset, + int whence); +ssize_t readwrite(struct filestr_desc *file, void *buf, size_t nbyte, + bool write); +void filestr_base_init(struct filestr_base *stream); +int open_internal_locked(const char *path, int oflag); + +#define GET_FILESTR(type, fildes) \ + ({ \ + file_internal_lock_##type(); \ + struct filestr_desc * _file = get_filestr(fildes); \ + if (_file) \ + FILESTR_LOCK(type, &_file->stream); \ + else { \ + file_internal_unlock_##type(); \ + }\ + _file; \ + }) + +/* release the lock on the filestr_desc* */ +#define RELEASE_FILESTR(type, file) \ + ({ \ + FILESTR_UNLOCK(type, &(file)->stream); \ + file_internal_unlock_##type(); \ + }) +#endif /* _SYS_FILE_INTERNAL_H */ + diff --git a/firmware/target/hosted/ctru/lib/sys_thread.h b/firmware/target/hosted/game_console/lib/sys_thread.h similarity index 68% rename from firmware/target/hosted/ctru/lib/sys_thread.h rename to firmware/target/hosted/game_console/lib/sys_thread.h index d6dea134c5..cbdc294720 100644 --- a/firmware/target/hosted/ctru/lib/sys_thread.h +++ b/firmware/target/hosted/game_console/lib/sys_thread.h @@ -21,20 +21,11 @@ #ifndef __SYSTHREAD_H__ #define __SYSTHREAD_H__ -#include <3ds/synchronization.h> -#include <3ds/thread.h> -#include <3ds/services/apt.h> +#include "sys_types.h" +#include "sys_atomic.h" #include "thread.h" -/* Complementary atomic operations */ -bool _AtomicCAS(u32 *ptr, int oldval, int newval); -#define AtomicGet(ptr) __atomic_load_n((u32*)(ptr), __ATOMIC_SEQ_CST) -#define AtomicSet(ptr, value) AtomicSwap(ptr, value) -#define AtomicCAS(ptr, oldvalue, newvalue) _AtomicCAS((u32 *)(ptr), oldvalue, newvalue) -void AtomicLock(int *lock); -void AtomicUnlock(int *lock); - /* This code was taken from SDL2 thread implementation */ enum thread_state_t @@ -48,7 +39,7 @@ enum thread_state_t typedef struct _thread { int threadid; - Thread handle; + sys_thread_type handle; int status; int state; size_t stacksize; @@ -57,31 +48,52 @@ typedef struct _thread void *data; } sysThread; +typedef struct _mutex +{ + sys_mutex_type lock; +} sysMutex; + +typedef struct _sem +{ + sys_sem_type semaphore; +} sysSem; + typedef struct _cond { - RecursiveLock lock; + sysMutex lock; int waiting; int signals; - LightSemaphore wait_sem; - LightSemaphore wait_done; + sysSem wait_sem; + sysSem wait_done; } sysCond; -int sys_sem_wait(LightSemaphore *sem); -int sys_sem_wait_timeout(LightSemaphore *sem, u32 timeout); -int sys_sem_try_wait(LightSemaphore *sem); -u32 sys_sem_value(LightSemaphore *sem); +sysMutex *sys_mutex_create(void); +void sys_mutex_init(sysMutex *mutex); +int sys_mutex_lock(sysMutex *mutex); +int sys_mutex_try_lock(sysMutex *mutex); +int sys_mutex_unlock(sysMutex *mutex); -sysThread *sys_create_thread(int(*fn)(void *), const char *name, const size_t stacksize, +sysSem *sys_sem_create(u32 initial_value); +void sys_sem_init(sysSem *sem, u32 initial_value); +int sys_sem_wait(sysSem *sem); +int sys_sem_wait_timeout(sysSem *sem, u32 timeout); +int sys_sem_try_wait(sysSem *sem); +u32 sys_sem_value(sysSem *sem); +int sys_sem_post(sysSem *sem); + +sysCond *sys_cond_create(void); +void sys_cond_init(sysCond *cond); +void sys_cond_destroy(sysCond *cond); +int sys_cond_signal(sysCond *cond); +int sys_cond_broadcast(sysCond *cond); +int sys_cond_wait(sysCond *cond, sysMutex *mutex); + +sysThread *sys_thread_create(int(*fn)(void *), const char *name, const size_t stacksize, void *data IF_PRIO(, int priority) IF_COP(, unsigned int core)); void sys_run_thread(sysThread *thread); void sys_wait_thread(sysThread *thread, int *status); int sys_thread_id(void); int sys_set_thread_priority(sysThread *thread, int priority); -sysCond *sys_cond_create(void); -void sys_cond_destroy(sysCond *cond); -int sys_cond_signal(sysCond *cond); -int sys_cond_broadcast(sysCond *cond); -int sys_cond_wait(sysCond *cond, RecursiveLock *mutex); #endif /* #ifndef __SYSTHREAD_H__ */ diff --git a/firmware/target/hosted/ctru/lib/sys_thread.c b/firmware/target/hosted/game_console/lib/sys_thread_3ds.c similarity index 58% rename from firmware/target/hosted/ctru/lib/sys_thread.c rename to firmware/target/hosted/game_console/lib/sys_thread_3ds.c index 1634fb3d7f..d280aa39f2 100644 --- a/firmware/target/hosted/ctru/lib/sys_thread.c +++ b/firmware/target/hosted/game_console/lib/sys_thread_3ds.c @@ -28,49 +28,129 @@ #include "debug.h" #include "logf.h" -bool _AtomicCAS(u32 *ptr, int oldval, int newval) +/* sysMutex */ +sysMutex *sys_mutex_create(void) { - int expected = oldval; - int desired = newval; - return __atomic_compare_exchange(ptr, &expected, &desired, false, - __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); -} - -bool _AtomicTryLock(int *lock) -{ - int result; - asm volatile( - "ldrex %0, [%2] \n" - "teq %0, #0 \n" - "strexeq %0, %1, [%2] \n" - : "=&r"(result) - : "r"(1), "r"(lock) - : "cc", "memory" - ); - return result == 0; -} - -#define CPUPauseInstruction() asm volatile("yield" ::: "memory") -void AtomicLock(int *lock) -{ - int iterations = 0; - while (!_AtomicTryLock(lock)) { - if (iterations < 32) { - iterations++; - CPUPauseInstruction(); - } else { - sys_delay(0); - } + sysMutex *m = (sysMutex *) malloc(sizeof(sysMutex)); + if (m == NULL) { + DEBUGF("sys_create_mutex: no memory\n"); + return NULL; } + + sys_mutex_init(m); + return m; } -void AtomicUnlock(int *lock) +void sys_mutex_init(sysMutex *mutex) { - *lock = 0; + memset(mutex, 0, sizeof(sysMutex)); + RecursiveLock_Init(&mutex->lock); } +int sys_mutex_lock(sysMutex *mutex) +{ + RecursiveLock_Lock(&mutex->lock); + return 0; +} + +int sys_mutex_try_lock(sysMutex *mutex) +{ + int res = RecursiveLock_TryLock(&mutex->lock); + if (res < 0) { + logf("RecursiveLock_TryLock: %d", res); + return -1; + } + + return 0; +} + +int sys_mutex_unlock(sysMutex *mutex) +{ + RecursiveLock_Unlock(&mutex->lock); + return 0; +} + +/* sysSem */ +void sys_sem_init(sysSem *sem, u32 initial_value) +{ + LightSemaphore_Init(&sem->semaphore, initial_value, ((s16)0x7FFF)); +} + +sysSem *sys_sem_create(u32 initial_value) +{ + sysSem *s = (sysSem *) malloc(sizeof(sysSem)); + if (s == NULL) + { + DEBUGF("sys_create_sem: no memory\n"); + return NULL; + } + + sys_sem_init(s, initial_value); + return s; +} + +int wait_on_semaphore_for(sysSem *sem, u32 timeout) +{ + u64 stop_time = sys_get_ticks64() + timeout; + u64 current_time = sys_get_ticks64(); + while (current_time < stop_time) { + if (LightSemaphore_TryAcquire(&sem->semaphore, 1) == 0) { + return 0; + } + /* 100 microseconds seems to be the sweet spot */ + svcSleepThread(100000LL); + current_time = sys_get_ticks64(); + } + + /* If we failed, yield to avoid starvation on busy waits */ + svcSleepThread(1); + return 1; +} + +int sys_sem_try_wait(sysSem *sem) +{ + if (LightSemaphore_TryAcquire(&sem->semaphore, 1) != 0) { + /* If we failed, yield to avoid starvation on busy waits */ + svcSleepThread(1); + return 1; + } + + return 0; +} + +int sys_sem_wait_timeout(sysSem *sem, u32 timeout) +{ + if (timeout == (~(u32)0)) { + LightSemaphore_Acquire(&sem->semaphore, 1); + return 0; + } + + if (LightSemaphore_TryAcquire(&sem->semaphore, 1) != 0) { + return wait_on_semaphore_for(sem, timeout); + } + + return 0; +} + +int sys_sem_wait(sysSem *sem) +{ + return sys_sem_wait_timeout(sem, (~(u32)0)); +} + +u32 sys_sem_value(sysSem *sem) +{ + return sem->semaphore.current_count; +} + +int sys_sem_post(sysSem *sem) +{ + LightSemaphore_Release(&sem->semaphore, 1); + return 0; +} + +/* sysThread */ /* Convert rockbox priority value to libctru value */ -int get_ctru_thread_priority(int priority) +int get_3ds_thread_priority(int priority) { if ((priority == PRIORITY_REALTIME_1) || (priority == PRIORITY_REALTIME_2) || (priority == PRIORITY_REALTIME_3) || (priority == PRIORITY_REALTIME_4) || @@ -106,59 +186,6 @@ static void thread_entry(void *arg) threadExit(0); } -int wait_on_semaphore_for(LightSemaphore *sem, u32 timeout) -{ - u64 stop_time = sys_get_ticks64() + timeout; - u64 current_time = sys_get_ticks64(); - while (current_time < stop_time) { - if (LightSemaphore_TryAcquire(sem, 1) == 0) { - return 0; - } - /* 100 microseconds seems to be the sweet spot */ - svcSleepThread(100000LL); - current_time = sys_get_ticks64(); - } - - /* If we failed, yield to avoid starvation on busy waits */ - svcSleepThread(1); - return 1; -} - -int sys_sem_try_wait(LightSemaphore *sem) -{ - if (LightSemaphore_TryAcquire(sem, 1) != 0) { - /* If we failed, yield to avoid starvation on busy waits */ - svcSleepThread(1); - return 1; - } - - return 0; -} - -int sys_sem_wait_timeout(LightSemaphore *sem, u32 timeout) -{ - if (timeout == (~(u32)0)) { - LightSemaphore_Acquire(sem, 1); - return 0; - } - - if (LightSemaphore_TryAcquire(sem, 1) != 0) { - return wait_on_semaphore_for(sem, timeout); - } - - return 0; -} - -int sys_sem_wait(LightSemaphore *sem) -{ - return sys_sem_wait_timeout(sem, (~(u32)0)); -} - -u32 sys_sem_value(LightSemaphore *sem) -{ - return sem->current_count; -} - int sys_thread_id(void) { u32 thread_ID = 0; @@ -188,7 +215,7 @@ void sys_run_thread(sysThread *thread) } } -sysThread *sys_create_thread(int(*fn)(void *), const char *name, const size_t stacksize, +sysThread *sys_thread_create(int(*fn)(void *), const char *name, const size_t stacksize, void *data IF_PRIO(, int priority) IF_COP(, unsigned int core)) { sys_ticks_init(); @@ -216,7 +243,7 @@ sysThread *sys_create_thread(int(*fn)(void *), const char *name, const size_t st thread->handle = threadCreate(thread_entry, thread, get_thread_stack_size(stacksize), - get_ctru_thread_priority(priority), + get_3ds_thread_priority(priority), cpu, false); @@ -275,127 +302,10 @@ int sys_set_thread_priority(sysThread *thread, int priority) { Handle h = threadGetHandle(thread->handle); int old_priority = priority; - Result res = svcSetThreadPriority(h, get_ctru_thread_priority(priority)); + Result res = svcSetThreadPriority(h, get_3ds_thread_priority(priority)); if (R_SUCCEEDED(res)) { return priority; } return old_priority; -} - -/* sysCond */ -sysCond *sys_cond_create(void) -{ - sysCond *cond; - - cond = (sysCond *)malloc(sizeof(sysCond)); - if (cond) { - RecursiveLock_Init(&cond->lock); - LightSemaphore_Init(&cond->wait_sem, 0, ((s16)0x7FFF)); - LightSemaphore_Init(&cond->wait_done, 0, ((s16)0x7FFF)); - cond->waiting = cond->signals = 0; - } 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. - */ - RecursiveLock_Lock(&cond->lock); - if (cond->waiting > cond->signals) { - ++cond->signals; - LightSemaphore_Release(&cond->wait_sem, 1); - RecursiveLock_Unlock(&cond->lock); - LightSemaphore_Acquire(&cond->wait_done, 1); - } else { - RecursiveLock_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. - */ - RecursiveLock_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) { - LightSemaphore_Release(&cond->wait_sem, 1); - } - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - RecursiveLock_Unlock(&cond->lock); - for (i = 0; i < num_waiting; ++i) { - LightSemaphore_Acquire(&cond->wait_done, 1); - } - } else { - RecursiveLock_Unlock(&cond->lock); - } - - return 0; -} - -int sys_cond_wait(sysCond *cond, RecursiveLock *mutex) -{ - if (!cond) { - DEBUGF("sys_cond_signal: Invalid param 'cond'\n"); - return -1; - } - - RecursiveLock_Lock(&cond->lock); - ++cond->waiting; - RecursiveLock_Unlock(&cond->lock); - - /* Unlock the mutex, as is required by condition variable semantics */ - RecursiveLock_Unlock(mutex); - - /* Wait for a signal */ - LightSemaphore_Acquire(&cond->wait_sem, 1); - - RecursiveLock_Lock(&cond->lock); - if (cond->signals > 0) { - /* We always notify the signal thread that we are done */ - LightSemaphore_Release(&cond->wait_done, 1); - - /* Signal handshake complete */ - --cond->signals; - } - --cond->waiting; - RecursiveLock_Unlock(&cond->lock); - - /* Lock the mutex, as is required by condition variable semantics */ - RecursiveLock_Lock(mutex); - - return 0; -} +} \ No newline at end of file diff --git a/firmware/target/hosted/ctru/lib/sys_timer.h b/firmware/target/hosted/game_console/lib/sys_timer.h similarity index 100% rename from firmware/target/hosted/ctru/lib/sys_timer.h rename to firmware/target/hosted/game_console/lib/sys_timer.h diff --git a/firmware/target/hosted/game_console/lib/sys_timer_3ds.c b/firmware/target/hosted/game_console/lib/sys_timer_3ds.c new file mode 100644 index 0000000000..8500567688 --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_timer_3ds.c @@ -0,0 +1,71 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2006 Dan Everton + * + * 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 +#include +#include +#include +#include + +#include <3ds/os.h> + +#include "debug.h" +#include "logf.h" + +static bool ticks_started = false; +static u64 start_tick; + +#define NSEC_PER_MSEC 1000000ULL + +void sys_ticks_init(void) +{ + if (ticks_started) { + return; + } + ticks_started = true; + + start_tick = svcGetSystemTick(); +} + +void sys_ticks_quit(void) +{ + ticks_started = false; +} + +u64 sys_get_ticks64(void) +{ + u64 elapsed; + if (!ticks_started) { + sys_ticks_init(); + } + + elapsed = svcGetSystemTick() - start_tick; + return elapsed / CPU_TICKS_PER_MSEC; +} + +u32 sys_get_ticks(void) +{ + return (u32)(sys_get_ticks64() & 0xFFFFFFFF); +} + +void sys_delay(u32 ms) +{ + svcSleepThread(ms * NSEC_PER_MSEC); +} \ No newline at end of file diff --git a/firmware/target/hosted/ctru/lib/sys_timer.c b/firmware/target/hosted/game_console/lib/sys_timer_common.c similarity index 84% rename from firmware/target/hosted/ctru/lib/sys_timer.c rename to firmware/target/hosted/game_console/lib/sys_timer_common.c index 8cc5fa334a..8fea61df21 100644 --- a/firmware/target/hosted/ctru/lib/sys_timer.c +++ b/firmware/target/hosted/game_console/lib/sys_timer_common.c @@ -24,8 +24,6 @@ #include #include -#include <3ds/os.h> -/* these include a couple of 3ds headers */ #include "sys_thread.h" #include "sys_timer.h" @@ -34,47 +32,7 @@ #define CACHELINE_SIZE 128 -static bool ticks_started = false; -static u64 start_tick; - -#define NSEC_PER_MSEC 1000000ULL - -void sys_ticks_init(void) -{ - if (ticks_started) { - return; - } - ticks_started = true; - - start_tick = svcGetSystemTick(); -} - -void sys_ticks_quit(void) -{ - ticks_started = false; -} - -u64 sys_get_ticks64(void) -{ - u64 elapsed; - if (!ticks_started) { - sys_ticks_init(); - } - - elapsed = svcGetSystemTick() - start_tick; - return elapsed / CPU_TICKS_PER_MSEC; -} - -u32 sys_get_ticks(void) -{ - return (u32)(sys_get_ticks64() & 0xFFFFFFFF); -} - -void sys_delay(u32 ms) -{ - svcSleepThread(ms * NSEC_PER_MSEC); -} - +/* sysTimer */ typedef struct _timer { int timerID; @@ -97,17 +55,17 @@ typedef struct _timer_map typedef struct { /* Data used by the main thread */ - Thread thread; + sysThread *thread; int nextID; timerMap *timermap; - RecursiveLock timermap_lock; + sysMutex *timermap_lock; /* Padding to separate cache lines between threads */ char cache_pad[CACHELINE_SIZE]; /* Data used to communicate with the timer thread */ int lock; - LightSemaphore sem; + sysSem sem; sysTimer *pending; sysTimer *freelist; int active; @@ -144,9 +102,9 @@ static void add_timer_interval(timerData *data, sysTimer *timer) timer->next = curr; } -static void timer_thread(void *_data) +static int timer_thread(void *_data) { - timerData *data = (timerData *)_data; + timerData *data = (timerData *) _data; sysTimer *pending; sysTimer *current; sysTimer *freelist_head = NULL; @@ -246,6 +204,8 @@ static void timer_thread(void *_data) */ sys_sem_wait_timeout(&data->sem, delay); } + + return 0; } int sys_timer_init(void) @@ -253,17 +213,22 @@ int sys_timer_init(void) timerData *data = &timer_data; if (!AtomicGet(&data->active)) { - RecursiveLock_Init(&data->timermap_lock); - LightSemaphore_Init(&data->sem, 0, ((s16)0x7FFF)); + data->timermap_lock = (sysMutex *) malloc(sizeof(sysMutex)); + if (!data->timermap_lock) { + return -1; + } + sys_mutex_init(data->timermap_lock); + sys_sem_init(&data->sem, 0); + AtomicSet(&data->active, 1); /* Timer threads use a callback into the app, so we can't set a limited stack size here. */ - data->thread = threadCreate(timer_thread, - data, - 32 * 1024, - 0x28, - -1, - false); + data->thread = sys_thread_create(timer_thread, + "timer", + 32 * 1024, /* 32 kB */ + data + IF_PRIO( , PRIORITY_REALTIME ) /* Realtime priority */ + IF_COP( , 0 )); if (!data->thread) { sys_timer_quit(); return -1; @@ -283,9 +248,8 @@ void sys_timer_quit(void) if (AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */ /* Shutdown the timer thread */ if (data->thread) { - LightSemaphore_Release(&data->sem, 1); - threadJoin(data->thread, U64_MAX); - threadFree(data->thread); + sys_sem_post(&data->sem); + sys_wait_thread(data->thread, NULL); data->thread = NULL; } @@ -305,6 +269,9 @@ void sys_timer_quit(void) data->timermap = entry->next; free(entry); } + + free(data->timermap_lock); + data->timermap_lock = NULL; } } @@ -353,10 +320,10 @@ int sys_add_timer(u32 interval, timer_callback_ptr callback, void *param) entry->timer = timer; entry->timerID = timer->timerID; - RecursiveLock_Lock(&data->timermap_lock); + sys_mutex_lock(data->timermap_lock); entry->next = data->timermap; data->timermap = entry; - RecursiveLock_Unlock(&data->timermap_lock); + sys_mutex_unlock(data->timermap_lock); /* Add the timer to the pending list for the timer thread */ AtomicLock(&data->lock); @@ -365,7 +332,7 @@ int sys_add_timer(u32 interval, timer_callback_ptr callback, void *param) AtomicUnlock(&data->lock); /* Wake up the timer thread if necessary */ - LightSemaphore_Release(&data->sem, 1); + sys_sem_post(&data->sem); return entry->timerID; } @@ -377,7 +344,7 @@ bool sys_remove_timer(int id) bool canceled = false; /* Find the timer */ - RecursiveLock_Lock(&data->timermap_lock); + sys_mutex_lock(data->timermap_lock); prev = NULL; for (entry = data->timermap; entry; prev = entry, entry = entry->next) { if (entry->timerID == id) { @@ -389,7 +356,7 @@ bool sys_remove_timer(int id) break; } } - RecursiveLock_Unlock(&data->timermap_lock); + sys_mutex_unlock(data->timermap_lock); if (entry) { if (!AtomicGet(&entry->timer->canceled)) { @@ -399,5 +366,4 @@ bool sys_remove_timer(int id) free(entry); } return canceled; -} - +} \ No newline at end of file diff --git a/firmware/target/hosted/game_console/lib/sys_types.h b/firmware/target/hosted/game_console/lib/sys_types.h new file mode 100644 index 0000000000..f62670bffe --- /dev/null +++ b/firmware/target/hosted/game_console/lib/sys_types.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +#ifndef __SYSTYPES_H__ +#define __SYSTYPES_H__ + +#ifdef N3DS +#include <3ds/svc.h> +#include <3ds/types.h> +#include <3ds/thread.h> +#include <3ds/result.h> +#include <3ds/services/apt.h> +#include <3ds/services/fs.h> +#include <3ds/synchronization.h> + +typedef Thread sys_thread_type; +typedef RecursiveLock sys_mutex_type; +typedef LightSemaphore sys_sem_type; +typedef Handle sys_handle_type; +#endif + +#endif /* __SYSTYPES_H__ */ + diff --git a/firmware/target/hosted/ctru/system-ctru.h b/firmware/target/hosted/game_console/system-console.h similarity index 100% rename from firmware/target/hosted/ctru/system-ctru.h rename to firmware/target/hosted/game_console/system-console.h diff --git a/firmware/target/hosted/ctru/system-target.h b/firmware/target/hosted/game_console/system-target.h similarity index 54% rename from firmware/target/hosted/ctru/system-target.h rename to firmware/target/hosted/game_console/system-target.h index 79df842405..6ec0f3ae7f 100644 --- a/firmware/target/hosted/ctru/system-target.h +++ b/firmware/target/hosted/game_console/system-target.h @@ -1,4 +1,4 @@ -#include "system-ctru.h" +#include "system-console.h" #define NEED_GENERIC_BYTESWAPS diff --git a/firmware/target/hosted/ctru/thread-ctru.c b/firmware/target/hosted/game_console/thread-console.c similarity index 82% rename from firmware/target/hosted/ctru/thread-ctru.c rename to firmware/target/hosted/game_console/thread-console.c index 6dc057e333..3be2c59024 100644 --- a/firmware/target/hosted/ctru/thread-ctru.c +++ b/firmware/target/hosted/game_console/thread-console.c @@ -5,8 +5,9 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ + * $Id$ * - * Copyright (C) 2006 Dan Everton + * 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 @@ -18,19 +19,19 @@ * ****************************************************************************/ -#include "autoconf.h" - #include #include #include #include /* memset() */ #include -#include "system-ctru.h" -#include "thread-ctru.h" -#include "sys_thread.h" +#include "system-console.h" +#include "thread-console.h" #include "../kernel-internal.h" #include "core_alloc.h" +#include "sys_thread.h" +#include "sys_timer.h" + /* Define this as 1 to show informational messages that are not errors. */ #define THREAD_DEBUGF_ENABLED 0 @@ -54,7 +55,7 @@ static jmp_buf thread_jmpbufs[MAXTHREADS]; /* this mutex locks out other Rockbox threads while one runs, * that enables us to simulate a cooperative environment even if * the host is preemptive */ -static RecursiveLock m; +static sysMutex *m; #define THREADS_RUN 0 #define THREADS_EXIT 1 #define THREADS_EXIT_COMMAND_DONE 2 @@ -78,7 +79,7 @@ void sim_thread_shutdown(void) threads_status = THREADS_EXIT; /* Take control */ - RecursiveLock_Lock(&m); + sys_mutex_lock(m); /* Signal all threads on delay or block */ for (i = 0; i < MAXTHREADS; i++) @@ -86,7 +87,7 @@ void sim_thread_shutdown(void) struct thread_entry *thread = __thread_slot_entry(i); if (thread->context.s == NULL) continue; - LightSemaphore_Release(thread->context.s, 1); + sys_sem_post(thread->context.s); } /* Wait for all threads to finish and cleanup old ones. */ @@ -97,11 +98,11 @@ void sim_thread_shutdown(void) if (t != NULL) { - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); /* Wait for it to finish */ sys_wait_thread(t, NULL); /* Relock for next thread signal */ - RecursiveLock_Lock(&m); + sys_mutex_lock(m); /* Already waited and exiting thread would have waited .told, * replacing it with t. */ thread->context.told = NULL; @@ -117,7 +118,7 @@ void sim_thread_shutdown(void) } } - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); /* Signal completion of operation */ threads_status = THREADS_EXIT_COMMAND_DONE; @@ -136,7 +137,7 @@ void sim_thread_exception_wait(void) /* A way to yield and leave the threading system for extended periods */ void sim_thread_lock(void *me) { - RecursiveLock_Lock(&m); + sys_mutex_lock(m); __running_self_entry() = (struct thread_entry *)me; if (threads_status != THREADS_RUN) @@ -146,7 +147,7 @@ void sim_thread_lock(void *me) void * sim_thread_unlock(void) { struct thread_entry *current = __running_self_entry(); - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); return current; } @@ -160,9 +161,9 @@ void switch_thread(void) { case STATE_RUNNING: { - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); /* Any other thread waiting already will get it first */ - RecursiveLock_Lock(&m); + sys_mutex_lock(m); break; } /* STATE_RUNNING: */ @@ -170,9 +171,9 @@ void switch_thread(void) { int oldlevel; - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); sys_sem_wait(current->context.s); - RecursiveLock_Lock(&m); + sys_mutex_lock(m); oldlevel = disable_irq_save(); current->state = STATE_RUNNING; @@ -184,9 +185,9 @@ void switch_thread(void) { int result, oldlevel; - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); result = sys_sem_wait_timeout(current->context.s, current->tmo_tick); - RecursiveLock_Lock(&m); + sys_mutex_lock(m); oldlevel = disable_irq_save(); @@ -207,9 +208,9 @@ void switch_thread(void) case STATE_SLEEPING: { - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); sys_sem_wait_timeout(current->context.s, current->tmo_tick); - RecursiveLock_Lock(&m); + sys_mutex_lock(m); current->state = STATE_RUNNING; break; } /* STATE_SLEEPING: */ @@ -252,7 +253,7 @@ void block_thread_(struct thread_entry *current, int ticks) } unsigned int wakeup_thread_(struct thread_entry *thread - IF_PRIO(, enum wakeup_thread_protocol proto)) + IF_PRIO(, enum wakeup_thread_protocol proto)) { switch (thread->state) { @@ -260,7 +261,7 @@ unsigned int wakeup_thread_(struct thread_entry *thread case STATE_BLOCKED_W_TMO: wait_queue_remove(thread); thread->state = STATE_RUNNING; - LightSemaphore_Release(thread->context.s, 1); + sys_sem_post(thread->context.s); return THREAD_OK; } @@ -275,15 +276,48 @@ void thread_thaw(unsigned int thread_id) if (thread->id == thread_id && thread->state == STATE_FROZEN) { thread->state = STATE_RUNNING; - LightSemaphore_Release(thread->context.s, 1); + sys_sem_post(thread->context.s); } } +#ifdef HAVE_SCHEDULER_BOOSTCTRL +/*--------------------------------------------------------------------------- + * Change the boost state of a thread boosting or unboosting the CPU + * as required. + *--------------------------------------------------------------------------- + */ +static inline void boost_thread(struct thread_entry *thread, bool boost) +{ + if ((thread->cpu_boost != 0) != boost) + { + thread->cpu_boost = boost; +#ifdef CPU_BOOST_LOGGING + const char fmt[] = __FILE__" thread[%s]"; + char pathbuf[sizeof(fmt) + 32]; /* thread name 32 */ + snprintf(pathbuf, sizeof(pathbuf), fmt, thread->name); + cpu_boost_(boost, pathbuf, __LINE__); +#else + cpu_boost(boost); +#endif + } +} + +void trigger_cpu_boost(void) +{ + boost_thread(__running_self_entry(), true); +} + +void cancel_cpu_boost(void) +{ + boost_thread(__running_self_entry(), false); +} +#endif + int runthread(void *data) { /* Cannot access thread variables before locking the mutex as the data structures may not be filled-in yet. */ - RecursiveLock_Lock(&m); + sys_mutex_lock(m); struct thread_entry *current = (struct thread_entry *)data; __running_self_entry() = current; @@ -296,18 +330,18 @@ int runthread(void *data) /* Run the thread routine */ if (current->state == STATE_FROZEN) { - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); sys_sem_wait(current->context.s); - RecursiveLock_Lock(&m); + sys_mutex_lock(m); __running_self_entry() = current; } if (threads_status == THREADS_RUN) { current->context.start(); - THREAD_DEBUGF("Thread Done: %d (%s)\n", - THREAD_ID_SLOT(current->id), - THREAD_GET_NAME(current)); + THREAD_DEBUGF("Thread Done: %ld (%s)\n", + THREAD_ID_SLOT(current->id), + THREAD_GET_NAME(current)); /* Thread routine returned - suicide */ } @@ -316,7 +350,7 @@ int runthread(void *data) else { /* Unlock and exit */ - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); } return 0; @@ -337,16 +371,14 @@ unsigned int create_thread(void (*function)(void), return 0; } - LightSemaphore *s = (LightSemaphore *) malloc(sizeof(LightSemaphore)); + sysSem *s = sys_sem_create(0); if (s == NULL) { DEBUGF("Failed to create semaphore\n"); return 0; } - LightSemaphore_Init(s, 0, 255); - - sysThread *t = sys_create_thread(runthread, + sysThread *t = sys_thread_create(runthread, name, stack_size, thread @@ -365,11 +397,10 @@ unsigned int create_thread(void (*function)(void), thread->context.start = function; thread->context.t = t; thread->context.s = s; - thread->priority = priority; THREAD_DEBUGF("New Thread: %lu (%s)\n", - (unsigned long)thread->id, - THREAD_GET_NAME(thread)); + (unsigned long)thread->id, + THREAD_GET_NAME(thread)); return thread->id; (void)stack; @@ -382,15 +413,14 @@ void thread_exit(void) int oldlevel = disable_irq_save(); sysThread *t = current->context.t; - LightSemaphore *s = current->context.s; + sysSem *s = current->context.s; - /* Wait the last thread here and keep this one or ctru will leak it since + /* Wait the last thread here and keep this one or the app will leak it since * it doesn't free its own library allocations unless a wait is performed. * Such behavior guards against the memory being invalid by the time * sys_wait_thread is reached and also against two different threads having * the same pointer. It also makes sys_wait_thread a non-concurrent function. * - * However, see more below about sys_kill_thread. */ sys_wait_thread(current->context.told, NULL); @@ -448,8 +478,18 @@ int thread_get_priority(unsigned int thread_id) /* Initialize threading */ void init_threads(void) { - RecursiveLock_Init(&m); - RecursiveLock_Lock(&m); + m = sys_mutex_create(); + if (m == NULL) + { + fprintf(stderr, "Failed to create mutex\n"); + return; + } + + if (sys_mutex_lock(m) == -1) + { + fprintf(stderr, "Couldn't lock mutex\n"); + return; + } thread_alloc_init(); @@ -461,12 +501,11 @@ void init_threads(void) } /* Slot 0 is reserved for the main thread - initialize it here and - then create the thread - it is possible to have a quick, early - shutdown try to access the structure. */ + then create the system thread - it is possible to have a quick, + early shutdown try to access the structure. */ thread->name = __main_thread_name; thread->state = STATE_RUNNING; - thread->context.s = (LightSemaphore *) malloc(sizeof(LightSemaphore)); - LightSemaphore_Init(thread->context.s, 0, 255); + thread->context.s = sys_sem_create(0); thread->context.t = NULL; /* NULL for the implicit main thread */ __running_self_entry() = thread; @@ -485,18 +524,19 @@ void init_threads(void) if (setjmp(thread_jmpbufs[THREAD_ID_SLOT(thread->id)]) == 0) { THREAD_DEBUGF("Main Thread: %lu (%s)\n", - (unsigned long)thread->id, - THREAD_GET_NAME(thread)); + (unsigned long)thread->id, + THREAD_GET_NAME(thread)); return; } - RecursiveLock_Unlock(&m); + sys_mutex_unlock(m); /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */ while (threads_status < THREADS_EXIT_COMMAND_DONE) sys_delay(10); + free(m); + /* We're the main thead - perform exit - doesn't return. */ sim_do_exit(); } - diff --git a/firmware/target/hosted/ctru/thread-ctru.h b/firmware/target/hosted/game_console/thread-console.h similarity index 92% rename from firmware/target/hosted/ctru/thread-ctru.h rename to firmware/target/hosted/game_console/thread-console.h index 6f18576991..d9cd815a04 100644 --- a/firmware/target/hosted/ctru/thread-ctru.h +++ b/firmware/target/hosted/game_console/thread-console.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __THREAD_CTRU_H__ -#define __THREAD_CTRU_H__ +#ifndef __THREAD_CONSOLE_H__ +#define __THREAD_CONSOLE_H__ /* extra thread functions that only apply when running on hosting platforms */ void sim_thread_lock(void *me); @@ -27,5 +27,5 @@ void * sim_thread_unlock(void); void sim_thread_exception_wait(void); void sim_thread_shutdown(void); /* Shut down all kernel threads gracefully */ -#endif /* #ifndef __THREAD_CTRU_H__ */ +#endif /* #ifndef __THREAD_CONSOLE_H__ */ diff --git a/firmware/target/hosted/ctru/timer-ctru.c b/firmware/target/hosted/game_console/timer-console.c similarity index 100% rename from firmware/target/hosted/ctru/timer-ctru.c rename to firmware/target/hosted/game_console/timer-console.c diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c index 959b1cb8c1..9cb00b6422 100644 --- a/firmware/target/hosted/rtc.c +++ b/firmware/target/hosted/rtc.c @@ -23,7 +23,7 @@ #include #if !defined(WIN32) #include -#if !defined(__APPLE__) && !defined(CTRU) +#if !defined(__APPLE__) && !defined(N3DS) #include #endif #include @@ -48,7 +48,7 @@ int rtc_read_datetime(struct tm *tm) int rtc_write_datetime(const struct tm *tm) { -#if !defined(WIN32) && !defined(__APPLE__) && !defined(CTRU) +#if !defined(WIN32) && !defined(__APPLE__) && !defined(N3DS) struct timeval tv; struct tm *tm_time; diff --git a/lib/rbcodec/codecs/codec_crt0.c b/lib/rbcodec/codecs/codec_crt0.c index d3bde77339..831af0924b 100644 --- a/lib/rbcodec/codecs/codec_crt0.c +++ b/lib/rbcodec/codecs/codec_crt0.c @@ -30,7 +30,7 @@ extern unsigned char plugin_end_addr[]; * avoid warning with certain compilers */ int _start(void) {return 0;} -#ifdef CTRU +#ifdef N3DS /* dummy undefined symbols */ void __aeabi_unwind_cpp_pr0(void) {} struct _reent * _EXFUN(__getreent, (void)) { return NULL; } diff --git a/packaging/ctru/ctru.make b/packaging/3ds/3ds.make similarity index 93% rename from packaging/ctru/ctru.make rename to packaging/3ds/3ds.make index 838ff12b90..744bae8747 100644 --- a/packaging/ctru/ctru.make +++ b/packaging/3ds/3ds.make @@ -31,13 +31,13 @@ VERSION_MICRO := 0 APP_TITLE := rockbox APP_DESCRIPTION := Open Source Jukebox Firmware APP_AUTHOR := rockbox.org -APP_ICON := $(ROOTDIR)/packaging/ctru/res/icon.png +APP_ICON := $(ROOTDIR)/packaging/3ds/res/icon.png # CIA -BANNER_AUDIO := $(ROOTDIR)/packaging/ctru/res/banner.wav -BANNER_IMAGE := $(ROOTDIR)/packaging/ctru/res/banner.cgfx -RSF_PATH := $(ROOTDIR)/packaging/ctru/res/app.rsf -#LOGO := $(ROOTDIR)/packaging/ctru/logo.lz11 +BANNER_AUDIO := $(ROOTDIR)/packaging/3ds/res/banner.wav +BANNER_IMAGE := $(ROOTDIR)/packaging/3ds/res/banner.cgfx +RSF_PATH := $(ROOTDIR)/packaging/3ds/res/app.rsf +#LOGO := $(ROOTDIR)/packaging/3ds/logo.lz11 UNIQUE_ID := 0xCB001 PRODUCT_CODE := CTR-ROCKBOX ICON_FLAGS := nosavebackups,visible diff --git a/packaging/ctru/res/app.rsf b/packaging/3ds/res/app.rsf similarity index 100% rename from packaging/ctru/res/app.rsf rename to packaging/3ds/res/app.rsf diff --git a/packaging/ctru/res/banner.cgfx b/packaging/3ds/res/banner.cgfx similarity index 100% rename from packaging/ctru/res/banner.cgfx rename to packaging/3ds/res/banner.cgfx diff --git a/packaging/ctru/res/banner.png b/packaging/3ds/res/banner.png similarity index 100% rename from packaging/ctru/res/banner.png rename to packaging/3ds/res/banner.png diff --git a/packaging/ctru/res/banner.wav b/packaging/3ds/res/banner.wav similarity index 100% rename from packaging/ctru/res/banner.wav rename to packaging/3ds/res/banner.wav diff --git a/packaging/ctru/res/banner_.cgfx b/packaging/3ds/res/banner_.cgfx similarity index 100% rename from packaging/ctru/res/banner_.cgfx rename to packaging/3ds/res/banner_.cgfx diff --git a/packaging/ctru/res/icon.png b/packaging/3ds/res/icon.png similarity index 100% rename from packaging/ctru/res/icon.png rename to packaging/3ds/res/icon.png diff --git a/packaging/ctru/res/icon_yellow.png b/packaging/3ds/res/icon_yellow.png similarity index 100% rename from packaging/ctru/res/icon_yellow.png rename to packaging/3ds/res/icon_yellow.png diff --git a/packaging/ctru/rockbox.xml b/packaging/3ds/rockbox.xml similarity index 100% rename from packaging/ctru/rockbox.xml rename to packaging/3ds/rockbox.xml diff --git a/tools/buildzip.pl b/tools/buildzip.pl index 8f546db270..b8f9c12530 100755 --- a/tools/buildzip.pl +++ b/tools/buildzip.pl @@ -424,7 +424,7 @@ sub buildzip { glob_copy("$ROOT/firmware/drivers/libertas/firmware/*", "$temp_dir/libertas/"); } # add hbmenu shortcut's icon and 3dsx executable - if ($modelname =~ /ctru/) { + if ($modelname =~ /3ds/) { glob_copy("icon.icn", "$temp_dir/"); glob_copy("rockbox.3dsx", "$temp_dir/"); } @@ -755,12 +755,12 @@ sub runone { } # add hbmenu shortcut and cia file to zip file - if ($modelname =~ /ctru/) { + if ($modelname =~ /3ds/) { copy("rockbox.cia", "3ds"); - copy("$ROOT/packaging/ctru/rockbox.xml", "3ds"); + copy("$ROOT/packaging/3ds/rockbox.xml", "3ds"); system("$ziptool -u $output 3ds/rockbox.xml $target >/dev/null"); - print "$ziptool $output $ROOT/packaging/ctru/rockbox.xml $target >/dev/null\n" if $verbose; + print "$ziptool $output $ROOT/packaging/3ds/rockbox.xml $target >/dev/null\n" if $verbose; system("$ziptool -u $output 3ds/rockbox.cia $target >/dev/null"); print "$ziptool $output rockbox.cia $target >/dev/null\n" if $verbose; } diff --git a/tools/configure b/tools/configure index 08ceb746ba..b4063cd2f1 100755 --- a/tools/configure +++ b/tools/configure @@ -4154,12 +4154,12 @@ fi sysfontbl="16-Terminus" ;; - 290|ctru) + 290|3ds) target_id=122 application="yes" - modelname="ctru" - app_type="ctru-app" - target="CTRU" + modelname="3ds" + app_type="3ds-homebrew" + target="N3DS" memory=16 uname=`uname` devkitarmcc @@ -4172,8 +4172,8 @@ fi appextra="recorder:gui" plugins="yes" t_cpu="hosted" - t_manufacturer="ctru" - t_model="app" + t_manufacturer="game_console" + t_model="3ds" ;; 300|hibyr3proii) @@ -4850,9 +4850,9 @@ if test -n "$t_cpu"; then if [ "$simulator" = "yes" ]; then # a few more includes for the sim target tree TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/sdl" TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted" - elif [ "$application" = "yes" ] && [ "$t_manufacturer" = "ctru" ]; then - TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ctru/lib" - TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/ctru/lib/bfile" + elif [ "$application" = "yes" ] && [ "$t_manufacturer" = "game_console" ]; then + TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/game_console/lib" + TARGET_INC="$TARGET_INC -I\$(FIRMDIR)/target/hosted/game_console/lib/bfile" fi if [ "$tinyalsa" = "yes" ]; then diff --git a/tools/root.make b/tools/root.make index 46acf85e78..878ecd1c36 100644 --- a/tools/root.make +++ b/tools/root.make @@ -176,8 +176,8 @@ else # core include $(ROOTDIR)/packaging/rgnano/rgnano.make endif - ifneq (,$(findstring ctru, $(APP_TYPE))) - include $(ROOTDIR)/packaging/ctru/ctru.make + ifneq (,$(findstring 3ds-homebrew, $(APP_TYPE))) + include $(ROOTDIR)/packaging/3ds/3ds.make endif endif # bootloader