Homebrew [Release] SDL-3DS 1.2.15 - Simple DirectMedia Layer for 3DS

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
SDL_logo.png
1.2.15​

This summer I decided to complete the SDL 1.2 port to 3ds started by @Rikku2000 in this thread: https://gbatemp.net/threads/sdl-for-3ds.374519/
After some months studying the SDL 1.2 internals and experimenting with the Citro3D lib, here is my version of the SDL lib for 3DS. The release number starts from 0.4 because the last Rikku version was v0.3.

In my version I tried to make a clean port, so when the port is completed, will be possible to easily merge it in the official SDL release (don't know if old v1.2.15 is maintained anymore, but I hope yes).

In my version I introduced a set of custom flags and functions to handle the 3ds hw peculiarity. Refer to the following post or to the github readme for details.

I'm porting only the base SDL lib, other libs (SDL_Image, SDL_TTF, SDL_Mixer) don't need any change to be compiled for 3DS, as long as SDLlib is correctly compiled and installed in your DevkitArm toolchain. To help people to compile and install the whole set of libraries, I'll provide later a set of makefiles.

I' hope that with this well known library available for the 3ds, we will see more and more developers coding for this console.

PS: After completing the SDL 1.2 port, I'm planning to reuse the code to finish the @xerpi port of SDL 2.0. I know a lot of people prefer SDL2, but I know SDL1.2 better.

Source code: https://github.com/nop90/SDL-3DS

Changelog


v0.9 - (27/07/2017)
- reduced video thread priority to avoid conflicts with ctulib threads, mainly the NDSP handler one
- fixed a crash callingSDL_SetVideoMode a secont time, caused by not releasing the scene (shader ans Rendertargets) before loading it again with the new video mode

v0.8 - (29/05/2017)
- Fixed bottom screen zoom/positioning in dual screen mode
- Changed code to maintain screen aspect ratio using SDL_FITWIDTH or SDL_FITHEIGHT custom video flags
- Aligned mouse movement area to bottom screen visible part in dual screen mode

v0.7 - (07/04/2017)
- Video code reworked - GPU freezing highly reduced (played severals SDL games for long time on old and new 3ds without freezes)
- Fixed SDL_QUIT event triggering on closing the application from Home menu
- Fixed Audio and Video Therads to not acces DSP ang GPU on app pause and app exiting (SDL_QUIT)
- Udated to use tatest DevKitPro and ctrulib
- Using latest fix on Citro3d lib ("Next" branch on github) to reduce GPU freezes
- added SDL_net. Compiling but untested

v0.6 - (22/03/2017)

- Fixed Video Fickering
- Minor tunings

v0.5 - (17/02/2017)

- Fixed Audio, Threads and Timer (by @Wenting )
- Fixed Joystick
- Added 8bpp video mode (from @Wenting)
- Minor tuning
- Moved lib installation path from portilibs/armv6k to portilibs/3ds (reinslalling please delete the old lib and the include forlder by hand)
- Fixed the makefile for compiling the pica shader file

v0.4 - (30/01/2017)
Respect to Rikku's v0.3 the video device code was completly rewritten using C3D for the final rendering. This means that there is no need to rotate the screen anymore, both top and bottom screens are supported, there are no limits to video sizes (with possibility to HW stretching the video to the 3ds screen size) and there are four available video modes (RGBA8, RGB8, RGB565, RGB5A1).

Note that the internal drawing routines aren't HW acelerated, C3DS is used only for the final blitting from the videobuffer to the HW framebuffer, allowing for HW screen scaling. So do not expect high farmerate using this lib. Maybe I'll add some optimizations to one of the next releases, but this lib is for simplify the developement on the 3ds, if you need performance there are other low level tools available.

At the moment the video part is almost completed, the input part is at 50% and the sound device is under developement (so no sound support yet)

Installation

Run make install on the provided Makefile.n3ds. This will compile the lib and instal it in the portlibs directory of your devkitarm toolchain.

To use the lib remember to declare all the libraries dependencies in you makefile ( at least -lSDL -lcitro3d -lctru , for other dependencies refer to the standard SDL 1.2 documentation).

Known Bugs

-

To Do List

-

Retroguru games using SDL 1.2 for 3DS (closed source)

icon.png
Hermes - Ported by @Nop90 Released at REVISION 2017, SAARBRÜCKEN (GBATemp Link)

icon.png
Sqrxz3 - Ported by @Nop90 (GBATemp Link)

Game Engines and Emulators using SDL 1.2 for 3DS

icon.png
NeoPop - Ported by @Nop90 (GBATemp Link)

ons-en.png
Onscripter-EN - Ported by @Nop90 (GBATemp Link)

List of Homebrews using SDL 1.2 for 3DS

SDLPal.png
SDLPal - Ported by @Wenting (GBATemp Link)
Meritous.png
Meritous - Ported by @nop90 (GBATemp link)
Opentyrian.png
Opentyrian - Ported by @nop90 (GBATemp link)
icon.png
Xrich - Ported by @nop90 (GBATemp link)
hexahop.png
Hex a Hop - Ported by @nop90 (GBATemp link)
supertux.png
Supertux Milestone 1 - Ported by @nop90 (GBATemp link)
KETM.png
KETM - Ported by @nop90 (GBATemp link)
Zelda3T.png
Zelda 3T - Ported by @nop90 (GBATemp link)
icon.png
Maze of Galious - Ported by @nop90 (GBATemp link)
icon.png
Amphetamine - Ported by @nop90 (GBATemp link)
FyWod.png
Fy.Wod! - Ported by @nop90 (GBATemp link)
C-Dogs.png
C-Dogs - Ported by @MrHuu (GBATemp link)
 
Last edited by nop90,

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
SDL
Version 1.2.15 Nintendo 3DS port​
TOC
- Video
- Events
- Key input
- Joystick
- Mousepointer
- Multithread
- Audio

VIDEO - 100% completed
the video device will be rendered centered on the HW screen (default screen is the TOP one)

five bpp modes supported : 32 (RGBA8), 24 (RGB8), 16 (RGB565), 15 (RGB555_A1), 8 (paletted)

With these video sizes can be used the following options:

The following custom options for the video device are defined:
- SDL_FULLSCREEN option stretchs the video device on the HW screen.
- SDL_TOPSCR: select the top screen for rendering the video device (it's the default option, so you don't really need to set this flag)
- SDL_BOTTOMSCR: select the bottom screen for rendering the video device
- SDL_DUALSCR: draws the upper half of the video device on the top screeen and the lower half on the bottom screen
- SDL_FITWIDTH: resizes the video device to fit the selected screen width (if SDL_DUALSCR is set, its' resized to 400 pixel width)
- SDL_FITHEIGHT: resizes the video device to fit the screen/screens width
- SDL_CONSOLETOP: enables console output on the top screen (only if SDL_TOPSCR or SDL_FULLSCREEN are not set)
- SDL_CONSOLEBOTTOM: enables console output on the bottom screen (only if SDL_BOTTOMSCR or SDL_FULLSCREEN are not set)

Note: using the SDL_FULLSCREEN flag is the same of using (SDL_TOPSCR | SDL_BOTTOMSCR)

EVENTS - 100% completed

SDL events handles the interaction with the 3ds home menu in homebrews released in installable format (CIA). The lib puts the code in the sleep mode when closing the lid and triggers a SDL_QUIT event when closing the app from the 3ds home menu.

Rmember that once the SDL_QUIT event is triggered, the code can't access anymore to the video services or thecode will hung.

KEY INPUT
- 100% completed
default key bindings are:

KEY_A -> SDLK_a
KEY_B -> SDLK_b
KEY_X -> SDLK_x
KEY_Y -> SDLK-y
KEY_L -> SDLK_l
KEY_R -> SDLK_r
KEY_ZL -> SDLK_LSHIFT
KEY_ZR -> SDLK_RSHIFT
KEY_START -> SDLK_RETURN
KEY_SELECT -> SDLK_ESCAPE
KEY_RIGHT -> SDLK_RIGHT
KEY_LEFT -> SDLK_LEFT
SDLK_UP -> KEY_UP
KEY_DOWN -> SDLK_DOWN
there is a custom function to bind one or more N3DS keys to a SDL key value:

void SDL_N3DSKeyBind(unsigned int hidkey, SDLKey key)

NOTE: circle pad and C-Stick are not mapped to the direction key by default( circle pad is mapped to the default Joystick) but if someone wants to make this mapping can use the following code:

Code:
   SDL_N3DSKeyBind(KEY_CPAD_UP|KEY_CSTICK_UP, SDLK_UP);
   SDL_N3DSKeyBind(KEY_CPAD_DOWN|KEY_CSTICK_DOWN, SDLK_DOWN);
   SDL_N3DSKeyBind(KEY_CPAD_LEFT|KEY_CSTICK_LEFT, SDLK_LEFT);
   SDL_N3DSKeyBind(KEY_CPAD_DOWN|KEY_CSTICK_DOWN, SDLK_DOWN);

It's not possible to bind a N3DS key to two or more SDL Key values.

JOYSTICK - 100% completed

Joystick support is enabled

MOUSEPOINTER
- 90% completed

Mouse pointer is controlled with the touchpad. Touching the bottom screen controls the pointer position and trigger a left button click.

MULTITHREAD - 100% completed

Multithread is supported. But please bear in mind that due to the design of 3DS' OS, thread won't evenly share CPU time. You would have to use SDL_Delay to give other threads CPU time to run. All threads would be created with a higher priority than the main thread, and they would start running as soon as you create them.

AUDIO
- 100% completed

Supported audio format are AUDIO_S8 and AUDIO_S16.

Audio uses the DSP, so to use it with a homebrew compiled as a CIA you need to dump the DSp Firm in the 3ds folder. Audio thread would have a higher priority than the main thread, but it would give main thread a fixed time to process the audio. If you are experiencing problems with the audio, try using a larger sample buffer or change the delay time in SDL_n3dsaudio.c
 
Last edited by nop90,

DogParty

Well-Known Member
Member
Joined
Sep 15, 2015
Messages
172
Trophies
0
Age
32
XP
908
Country
United States
For those who don't know, this is huge. SDL is akin to a 2D version of OpenGL which means a lot of 2D homebrew is based on it. With a proper port of the lib, we can presumably cross compile a lot of games meant for Linux or other systems with homebrew.
 

MajinCubyan

The Funky Super Saiyan
Member
Joined
Nov 24, 2014
Messages
783
Trophies
2
Age
35
Location
Orre
XP
2,124
Country
United States
Wow, awesome job! Maybe now my dream of Super Mario War on the 3ds can come true, which is coded in SDL. Can't wait to see what happens now. :D
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
Wow, awesome job! Maybe now my dream of Super Mario War on the 3ds can come true, which is coded in SDL. Can't wait to see what happens now. :D
My goal with this lib is to port SMW with a standard SDL lib, instead of changing a lot of code to make it work with a fake SDL layer calling ctruib lowlevel functions.

I'll try to compile it after completing the audio device code.
 

MajinCubyan

The Funky Super Saiyan
Member
Joined
Nov 24, 2014
Messages
783
Trophies
2
Age
35
Location
Orre
XP
2,124
Country
United States
My goal with this lib is to port SMW with a standard SDL lib, instead of changing a lot of code to make it work with a fake SDL layer calling ctruib lowlevel functions.

I'll try to compile it after completing the audio device code.

You, sir, are my hero. I've made custom graphics, maps, and sprites for that game. Thank you.

I was just looking for the source code to share it with people too, Haha.
 
Last edited by MajinCubyan,

realWinterMute

Well-Known Member
Member
Joined
Feb 24, 2011
Messages
117
Trophies
1
XP
553
Country
In my version I tried to make a clean port, so when the port is completed, will be possible to easily merge it in the official SDL release (don't know if old v1.2.15 is maintained anymore, but I hope yes).

You'll get a cleaner port if you start with the git mirror instead of just starting your own git repo.

I did make a start eons ago but never really found the time to actually learn enough SDL to figure out the rest of the port.

https://github.com/SDL-mirror is the official mirror.

Run make install on the provided Makefile.n3ds. This will compile the lib and instal it in the portlibs directory of your devkitarm toolchain.

Please don't do this. The msys setup provided with devkitARM will allow configure && make which will perform various tests against the toolchains & set things up properly.

This port should also go in $DEVKITPRO/portlibs/3ds since it is a 3ds specific port rather than generic armv6k

The way you've set up your repository makes it very difficult to see what changes you've actually made to the upstream sources unfortunately.

I've dug out the intitial changes I did to get the autotools setup working & put them up at https://github.com/WinterMute/SDL.

git checkout SDL-1.2-3DS, run ./autogen to get configure then
Code:
PATH=$DEVKITARM/bin:$PATH
mkdir 3ds-build
cd 3ds-build
../configure --host=arm-none-eabi \
--prefix=$DEVKITPRO/portlibs/3ds \
--with-platform=3ds

to get your code in & building you can add the video files to src/video/3ds then add something like this to the arm-none-eabi section
Code:
# Set up files for the video library
if test x$enable_video = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_3DS)
SOURCES="$SOURCES $srcdir/src/video/3ds/*.c"
have_video=yes
fi

or I guess n3ds folder if you prefer.Rerun autogen when you do this.

Hit me up on irc or devkitpro forums if you need some help with the build system.
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
You'll get a cleaner port if you start with the git mirror instead of just starting your own git repo.

I did make a start eons ago but never really found the time to actually learn enough SDL to figure out the rest of the port.

https://github.com/SDL-mirror is the official mirror.



Please don't do this. The msys setup provided with devkitARM will allow configure && make which will perform various tests against the toolchains & set things up properly.

This port should also go in $DEVKITPRO/portlibs/3ds since it is a 3ds specific port rather than generic armv6k

The way you've set up your repository makes it very difficult to see what changes you've actually made to the upstream sources unfortunately.

I've dug out the intitial changes I did to get the autotools setup working & put them up at https://github.com/WinterMute/SDL.

git checkout SDL-1.2-3DS, run ./autogen to get configure then
Code:
PATH=$DEVKITARM/bin:$PATH
mkdir 3ds-build
cd 3ds-build
../configure --host=arm-none-eabi \
--prefix=$DEVKITPRO/portlibs/3ds \
--with-platform=3ds

to get your code in & building you can add the video files to src/video/3ds then add something like this to the arm-none-eabi section
Code:
# Set up files for the video library
if test x$enable_video = xyes; then
AC_DEFINE(SDL_VIDEO_DRIVER_3DS)
SOURCES="$SOURCES $srcdir/src/video/3ds/*.c"
have_video=yes
fi

or I guess n3ds folder if you prefer.Rerun autogen when you do this.

Hit me up on irc or devkitpro forums if you need some help with the build system.

Thank you for your hints but for the moment I prefer to work with a private repositoy so I can try all the tricks and workaraunds I need to figure out how the sdl internals work.

I did this way with the video code, than cleaned the most part of it and put it in a std sdl version.

I'm going to do the same with the audio part.

I'm worried about the non standard flags and functions I introduced too.

Probably people will suggest a lot of smart changes. So it's to early to think about merging with the standard repository.

About the config script I know how to make it work on windows, but it's tricky and some people could find it difficoult, so I used a premade config header file. Other platforms do the same. I could change this later.

Let me finish the audio code then I'll ask your help to clean everything
 
Last edited by nop90,

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
@Wenting forked my project and fixed the sound part (http://gbatemp.net/threads/wip-libsdl-1-2-15-for-3ds.461023/).

This is a big step ahed; now I'm going to check his code to merge it with my local copy of the project, that has some part not released yet.

I hope to release a new version for this week end.

Next things planned are:
- Implementing the changes proposed by @realWinterMute to have a clean and standard SDL port
- working on HW acceleration (at the moment the video part is very slow)
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
Updated on github the new code merged with the fixes and the addons made by @Wenting

Now the lib is complete (added sound, thread and Joystic), but a lot of things can be improved.

Warning: I moved the installation path from portilibs/armv6k to portilibs/3ds, so before installing the new version remember to delete the old lib and the include folder.
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
Man that's amazing, though I'm not using SDL 1.2, SDL2 is much better in all points (personnal though and preference)

The code used for SDL 1.2 will be used to complete the SDL 2 porr started by @xerpi .

But my time is very limited, if someone want s to contribute to the SDl 2 project he is welcome. Knowing a little of the internals of SDL, completing a first working version of SDL 2 ia s matter of few hours of work.

I dont want to start a new project before finishing to tune up of this lib, there are a lot of small thing to fix to make it work smooth and flawless
 

nop90

Well-Known Member
OP
Member
Joined
Jan 11, 2014
Messages
1,556
Trophies
0
Location
Rome
XP
3,036
Country
Italy
Just released Meritous compiled with this lib.

Porting the game was very easy, and I used it totest and fix le code of the lib.

There is only a graphic glitch diagonally on the sceen to solve, but thw lib seems to works very fine.

I'm working on OpenTyrian too (working but no sound yet)
 
  • Like
Reactions: MajinCubyan

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Sicklyboy @ Sicklyboy: Switching my home routing/firewall solution from pfsense to OPNsense. Boy how I hate networking...