├── .DS_Store ├── 3ds-examples-master ├── graphics │ ├── gpu │ │ ├── normal_mapping │ │ │ ├── gfx │ │ │ │ ├── normal.t3s │ │ │ │ ├── diffuse.t3s │ │ │ │ ├── diffuse.png │ │ │ │ └── normal.png │ │ │ └── source │ │ │ │ └── vshader.v.pica │ │ ├── cubemap │ │ │ ├── gfx │ │ │ │ ├── skybox.t3s │ │ │ │ └── skybox.png │ │ │ └── source │ │ │ │ └── skybox.v.pica │ │ ├── textured_cube │ │ │ ├── gfx │ │ │ │ ├── kitten.t3s │ │ │ │ └── kitten.png │ │ │ └── source │ │ │ │ └── vshader.v.pica │ │ ├── mipmap_fog │ │ │ ├── gfx │ │ │ │ ├── kitten.t3s │ │ │ │ └── kitten.png │ │ │ └── source │ │ │ │ └── vshader.v.pica │ │ ├── gpusprites │ │ │ ├── gfx │ │ │ │ ├── ufoRed.png │ │ │ │ ├── ufoBlue.png │ │ │ │ ├── ufoGreen.png │ │ │ │ ├── enemyBlack1.png │ │ │ │ ├── enemyBlack2.png │ │ │ │ ├── enemyBlack3.png │ │ │ │ ├── enemyBlack4.png │ │ │ │ ├── enemyBlack5.png │ │ │ │ ├── enemyBlue1.png │ │ │ │ ├── enemyBlue2.png │ │ │ │ ├── enemyBlue3.png │ │ │ │ ├── enemyBlue4.png │ │ │ │ ├── enemyBlue5.png │ │ │ │ ├── enemyGreen1.png │ │ │ │ ├── enemyGreen2.png │ │ │ │ ├── enemyGreen3.png │ │ │ │ ├── enemyGreen4.png │ │ │ │ ├── enemyGreen5.png │ │ │ │ ├── enemyRed1.png │ │ │ │ ├── enemyRed2.png │ │ │ │ ├── enemyRed3.png │ │ │ │ ├── enemyRed4.png │ │ │ │ ├── enemyRed5.png │ │ │ │ ├── ufoYellow.png │ │ │ │ ├── meteorBrown_big1.png │ │ │ │ ├── meteorBrown_big2.png │ │ │ │ ├── meteorBrown_big3.png │ │ │ │ ├── meteorBrown_big4.png │ │ │ │ ├── meteorBrown_med1.png │ │ │ │ ├── meteorBrown_med3.png │ │ │ │ ├── meteorGrey_big1.png │ │ │ │ ├── meteorGrey_big2.png │ │ │ │ ├── meteorGrey_big3.png │ │ │ │ ├── meteorGrey_big4.png │ │ │ │ ├── meteorGrey_med1.png │ │ │ │ ├── meteorGrey_med2.png │ │ │ │ ├── meteorGrey_tiny1.png │ │ │ │ ├── meteorGrey_tiny2.png │ │ │ │ ├── playerShip1_blue.png │ │ │ │ ├── playerShip1_red.png │ │ │ │ ├── playerShip2_blue.png │ │ │ │ ├── playerShip2_red.png │ │ │ │ ├── playerShip3_blue.png │ │ │ │ ├── playerShip3_red.png │ │ │ │ ├── meteorBrown_small1.png │ │ │ │ ├── meteorBrown_small2.png │ │ │ │ ├── meteorBrown_tiny1.png │ │ │ │ ├── meteorBrown_tiny2.png │ │ │ │ ├── meteorGrey_small1.png │ │ │ │ ├── meteorGrey_small2.png │ │ │ │ ├── playerShip1_green.png │ │ │ │ ├── playerShip1_orange.png │ │ │ │ ├── playerShip2_green.png │ │ │ │ ├── playerShip2_orange.png │ │ │ │ ├── playerShip3_green.png │ │ │ │ ├── playerShip3_orange.png │ │ │ │ └── sprites.t3s │ │ │ └── source │ │ │ │ └── main.c │ │ ├── loop_subdivision │ │ │ ├── data │ │ │ │ └── texture.bin │ │ │ └── source │ │ │ │ └── program.v.pica │ │ ├── toon_shading │ │ │ └── source │ │ │ │ ├── teapot.h │ │ │ │ └── vshader.v.pica │ │ ├── lenny │ │ │ └── source │ │ │ │ ├── lenny.h │ │ │ │ └── vshader.v.pica │ │ ├── wide_mode_3d │ │ │ └── source │ │ │ │ ├── lenny.h │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── composite_scene │ │ │ └── source │ │ │ │ ├── lenny.h │ │ │ │ └── vshader.v.pica │ │ ├── geoshader │ │ │ └── source │ │ │ │ ├── program.v.pica │ │ │ │ ├── program.g.pica │ │ │ │ └── main.c │ │ ├── both_screens │ │ │ └── source │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── multiple_buf │ │ │ └── source │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── proctex │ │ │ └── source │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── simple_tri │ │ │ └── source │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── immediate │ │ │ └── source │ │ │ │ ├── vshader.v.pica │ │ │ │ └── main.c │ │ ├── fragment_light │ │ │ └── source │ │ │ │ └── vshader.v.pica │ │ ├── particles │ │ │ └── source │ │ │ │ └── particle.v.pica │ │ └── 2d_shapes │ │ │ └── source │ │ │ └── main.c │ ├── printing │ │ ├── custom-font │ │ │ ├── README │ │ │ ├── gfx │ │ │ │ └── liberationitalic.ttf │ │ │ └── source │ │ │ │ └── main.c │ │ ├── .DS_Store │ │ ├── hello-world │ │ │ ├── .DS_Store │ │ │ ├── Homebrew │ │ │ │ ├── .DS_Store │ │ │ │ └── 3ds-examples-master │ │ │ │ │ ├── .DS_Store │ │ │ │ │ └── graphics │ │ │ │ │ ├── .DS_Store │ │ │ │ │ └── printing │ │ │ │ │ ├── .DS_Store │ │ │ │ │ └── hello-world │ │ │ │ │ └── .DS_Store │ │ │ └── source │ │ │ │ └── main.c │ │ ├── wide-console │ │ │ └── source │ │ │ │ └── main.c │ │ ├── both-screen-text │ │ │ └── source │ │ │ │ └── main.c │ │ ├── multiple-windows-text │ │ │ └── source │ │ │ │ └── main.c │ │ ├── colored-text │ │ │ └── source │ │ │ │ └── main.c │ │ └── system-font │ │ │ └── source │ │ │ └── main.c │ └── bitmap │ │ └── 24bit-color │ │ ├── gfx │ │ └── brew.png │ │ ├── README.md │ │ └── source │ │ └── main.c ├── templates │ ├── library │ │ ├── source │ │ │ └── templatelib.c │ │ ├── README.md │ │ ├── include │ │ │ └── templatelib.h │ │ └── Makefile │ └── application │ │ ├── README.md │ │ └── source │ │ └── main.c ├── romfs │ ├── romfs │ │ ├── フォルダ │ │ │ └── ファイル.txt │ │ └── folder │ │ │ └── file.txt │ └── source │ │ └── main.c ├── sdmc │ ├── README.md │ ├── source │ │ ├── costable.h │ │ ├── main.c │ │ └── costable.c │ └── test.bin ├── .gitignore ├── get_system_language │ ├── README.md │ └── source │ │ └── main.c ├── qtm │ ├── README.md │ └── source │ │ └── main.c ├── audio │ ├── opus-decoding │ │ ├── romfs │ │ │ └── sample.opus │ │ └── README.md │ ├── modplug-decoding │ │ ├── romfs │ │ │ └── space_debris.mod │ │ └── source │ │ │ └── main.c │ ├── mic │ │ ├── README.md │ │ └── source │ │ │ └── main.c │ ├── streaming │ │ └── source │ │ │ └── main.c │ └── filters │ │ └── source │ │ └── main.c ├── network │ ├── sslc │ │ ├── data │ │ │ └── builtin_rootca.der │ │ └── source │ │ │ └── ssl.c │ ├── http_post │ │ └── README.md │ ├── http │ │ ├── README.md │ │ └── source │ │ │ └── main.c │ ├── boss │ │ ├── build_bossdata.sh │ │ ├── README.md │ │ └── source │ │ │ └── main.c │ ├── 3dslink-demo │ │ └── source │ │ │ └── 3dslink-demo.c │ └── sockets │ │ └── source │ │ └── sockets.c ├── camera │ ├── image │ │ ├── image.xml │ │ └── README.md │ └── video │ │ ├── video.xml │ │ └── README.md ├── README.md ├── mvd │ ├── mvd.xml │ └── README.md ├── app_launch │ ├── README.md │ └── source │ │ └── main.c ├── nfc │ └── README.md ├── Makefile ├── threads │ ├── event │ │ └── source │ │ │ └── main.c │ └── thread-basic │ │ └── source │ │ └── main.c ├── input │ ├── touch-screen │ │ └── source │ │ │ └── main.c │ ├── read-controls │ │ └── source │ │ │ └── main.c │ └── software-keyboard │ │ └── source │ │ └── main.c ├── libapplet_launch │ └── source │ │ └── main.c ├── time │ └── rtc │ │ └── source │ │ └── main.c └── mii_selector │ └── source │ └── main.c ├── images ├── .DS_Store ├── helloworld.png ├── labday2022.png ├── newsoftware.bmp ├── screenshot1.bmp ├── HelloOutdoorsy.jpeg ├── installing_from_fbi.png └── homescreen_installed.png └── lab_day_project ├── .DS_Store ├── build └── main.o ├── qrcode.png ├── lab_day_project.cia ├── lab_day_project.cxi ├── lab_day_project.elf ├── lab_day_project.3dsx ├── lab_day_project.smdh └── source └── main.c /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/normal_mapping/gfx/normal.t3s: -------------------------------------------------------------------------------- 1 | -f rgb -z auto 2 | normal.png 3 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/cubemap/gfx/skybox.t3s: -------------------------------------------------------------------------------- 1 | --skybox -f etc1 -z auto 2 | skybox.png 3 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/normal_mapping/gfx/diffuse.t3s: -------------------------------------------------------------------------------- 1 | -f etc1 -z auto 2 | diffuse.png 3 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/textured_cube/gfx/kitten.t3s: -------------------------------------------------------------------------------- 1 | -f auto-etc1 -z auto 2 | kitten.png 3 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/mipmap_fog/gfx/kitten.t3s: -------------------------------------------------------------------------------- 1 | -f auto-etc1 -z auto -m cubic 2 | kitten.png 3 | -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/.DS_Store -------------------------------------------------------------------------------- /images/helloworld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/helloworld.png -------------------------------------------------------------------------------- /images/labday2022.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/labday2022.png -------------------------------------------------------------------------------- /images/newsoftware.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/newsoftware.bmp -------------------------------------------------------------------------------- /images/screenshot1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/screenshot1.bmp -------------------------------------------------------------------------------- /3ds-examples-master/templates/library/source/templatelib.c: -------------------------------------------------------------------------------- 1 | int myLibFunction() { 2 | 3 | 4 | return 42; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /lab_day_project/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/romfs/romfs/フォルダ/ファイル.txt: -------------------------------------------------------------------------------- 1 | The path to this file contains UTF-16 2 | characters that fall outside ASCII. 3 | -------------------------------------------------------------------------------- /images/HelloOutdoorsy.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/HelloOutdoorsy.jpeg -------------------------------------------------------------------------------- /lab_day_project/build/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/build/main.o -------------------------------------------------------------------------------- /lab_day_project/qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/qrcode.png -------------------------------------------------------------------------------- /3ds-examples-master/sdmc/README.md: -------------------------------------------------------------------------------- 1 | sdmc 2 | ======= 3 | 4 | very simple example of how to access SD files with libctru; 5 | 6 | -------------------------------------------------------------------------------- /3ds-examples-master/templates/application/README.md: -------------------------------------------------------------------------------- 1 | # template 2 | 3 | This is a template for starting new 3DS libctru projects. 4 | -------------------------------------------------------------------------------- /3ds-examples-master/templates/library/README.md: -------------------------------------------------------------------------------- 1 | # template 2 | 3 | This is a template for starting new 3DS library projects. 4 | -------------------------------------------------------------------------------- /images/installing_from_fbi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/installing_from_fbi.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/custom-font/README: -------------------------------------------------------------------------------- 1 | Font license available at https://www.fontsquirrel.com/license/liberation-serif -------------------------------------------------------------------------------- /3ds-examples-master/sdmc/source/costable.h: -------------------------------------------------------------------------------- 1 | #ifndef COSTABLE_H 2 | #define COSTABLE_H 3 | 4 | extern s32 costable[]; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /3ds-examples-master/sdmc/test.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/sdmc/test.bin -------------------------------------------------------------------------------- /images/homescreen_installed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/images/homescreen_installed.png -------------------------------------------------------------------------------- /3ds-examples-master/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | build/ 3 | lib/ 4 | .*/ 5 | *.3dsx 6 | *.smdh 7 | *.elf 8 | *.t3x 9 | *.bcfnt 10 | *~ 11 | -------------------------------------------------------------------------------- /lab_day_project/lab_day_project.cia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/lab_day_project.cia -------------------------------------------------------------------------------- /lab_day_project/lab_day_project.cxi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/lab_day_project.cxi -------------------------------------------------------------------------------- /lab_day_project/lab_day_project.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/lab_day_project.elf -------------------------------------------------------------------------------- /lab_day_project/lab_day_project.3dsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/lab_day_project.3dsx -------------------------------------------------------------------------------- /lab_day_project/lab_day_project.smdh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/lab_day_project/lab_day_project.smdh -------------------------------------------------------------------------------- /3ds-examples-master/get_system_language/README.md: -------------------------------------------------------------------------------- 1 | get_system_language 2 | ======= 3 | 4 | This is an example on how to get the system language on the 3DS. 5 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/cubemap/gfx/skybox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/cubemap/gfx/skybox.png -------------------------------------------------------------------------------- /3ds-examples-master/qtm/README.md: -------------------------------------------------------------------------------- 1 | # qtm 2 | 3 | This is an example for using New3DS QTM for head-tracking. 4 | 5 | This is currently not usable from the homebrew launcher. 6 | 7 | -------------------------------------------------------------------------------- /3ds-examples-master/templates/library/include/templatelib.h: -------------------------------------------------------------------------------- 1 | #ifndef _templatelib_h_ 2 | #define _templatelib_h_ 3 | 4 | int myLibFunction(); 5 | 6 | #endif // _templatelib_h_ 7 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/opus-decoding/romfs/sample.opus: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/audio/opus-decoding/romfs/sample.opus -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoRed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoRed.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/mipmap_fog/gfx/kitten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/mipmap_fog/gfx/kitten.png -------------------------------------------------------------------------------- /3ds-examples-master/network/sslc/data/builtin_rootca.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/network/sslc/data/builtin_rootca.der -------------------------------------------------------------------------------- /3ds-examples-master/graphics/bitmap/24bit-color/gfx/brew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/bitmap/24bit-color/gfx/brew.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoBlue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoBlue.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoGreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoGreen.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/camera/image/image.xml: -------------------------------------------------------------------------------- 1 | 2 | 0004001000021400 3 | 0004001000022400 4 | 5 | -------------------------------------------------------------------------------- /3ds-examples-master/camera/video/video.xml: -------------------------------------------------------------------------------- 1 | 2 | 0004001000021400 3 | 0004001000022400 4 | 5 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlack5.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyBlue5.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyGreen5.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/enemyRed5.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoYellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/ufoYellow.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/normal_mapping/gfx/diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/normal_mapping/gfx/diffuse.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/normal_mapping/gfx/normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/normal_mapping/gfx/normal.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/textured_cube/gfx/kitten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/textured_cube/gfx/kitten.png -------------------------------------------------------------------------------- /3ds-examples-master/audio/modplug-decoding/romfs/space_debris.mod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/audio/modplug-decoding/romfs/space_debris.mod -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_big4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_med1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_med1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_med3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_med3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big3.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_big4.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_med1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_med1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_med2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_med2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_tiny1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_tiny1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_tiny2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_tiny2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_blue.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_red.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_blue.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_red.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_blue.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_red.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/loop_subdivision/data/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/loop_subdivision/data/texture.bin -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/toon_shading/source/teapot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern const float vertex_array[7752]; 4 | extern const u16 vertex_elements[7392]; 5 | #define vertex_element_count 7392 6 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/Homebrew/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/Homebrew/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/romfs/romfs/folder/file.txt: -------------------------------------------------------------------------------- 1 | Hello, this is the libctru romfs example. 2 | This text is being read off a file in romfs. 3 | 4 | >>3DS Homebrew is Cool<< 5 | 6 | Signed off, fincs 7 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_small1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_small1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_small2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_small2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_tiny1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_tiny1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_tiny2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorBrown_tiny2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_small1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_small1.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_small2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/meteorGrey_small2.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_green.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip1_orange.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_green.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip2_orange.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_green.png -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_orange.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/gpu/gpusprites/gfx/playerShip3_orange.png -------------------------------------------------------------------------------- /3ds-examples-master/network/http_post/README.md: -------------------------------------------------------------------------------- 1 | # http_post 2 | 3 | This is an example for using HTTPC to send a POST request. This sends a request to a site that returns information about your POST request. 4 | 5 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/custom-font/gfx/liberationitalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/custom-font/gfx/liberationitalic.ttf -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/camera/video/README.md: -------------------------------------------------------------------------------- 1 | video 2 | ======= 3 | 4 | Example for using the camera to capture 3D videos with libctru. 5 | 6 | Currently this example does not make use of the 3DS camera's calibration data to get a correct 3D effect. 7 | 8 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/network/http/README.md: -------------------------------------------------------------------------------- 1 | # http 2 | 3 | This is an example for using HTTPC. This downloads a raw image for displaying on the top-screen. The URL used here is a LAN-only one, hence this URL must be changed before building+running this example. 4 | 5 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/printing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/printing/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/README.md: -------------------------------------------------------------------------------- 1 | # 3ds-examples 2 | 3 | Examples for 3DS using devkitARM, libctru and citro3d 4 | 5 |

Public Domain Mark

6 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/lenny/source/lenny.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct 4 | { 5 | float x, y, z; 6 | float nx, ny, nz; 7 | } vertex; 8 | 9 | extern const vertex vertex_list[3345]; 10 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 11 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/wide_mode_3d/source/lenny.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct 4 | { 5 | float x, y, z; 6 | float nx, ny, nz; 7 | } vertex; 8 | 9 | extern const vertex vertex_list[3345]; 10 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 11 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/composite_scene/source/lenny.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct 4 | { 5 | float x, y, z; 6 | float nx, ny, nz; 7 | } vertex; 8 | 9 | extern const vertex vertex_list[3345]; 10 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 11 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/printing/hello-world/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdriselvato/3DS-Homebrew-development/HEAD/3ds-examples-master/graphics/printing/hello-world/Homebrew/3ds-examples-master/graphics/printing/hello-world/.DS_Store -------------------------------------------------------------------------------- /3ds-examples-master/audio/mic/README.md: -------------------------------------------------------------------------------- 1 | mic 2 | ======= 3 | 4 | Example for using the microphone with libctru. Hold down the A button to record, the app will then play the recorded audio once the A button is released. Roughly 32 seconds of audio can be recorded with the default audiobuf size in this app. 5 | 6 | -------------------------------------------------------------------------------- /3ds-examples-master/camera/image/README.md: -------------------------------------------------------------------------------- 1 | image 2 | ======= 3 | 4 | Example for using the camera to take 3D pictures with libctru. Press the R button to take a picture - it will be displayed on the top screen. 5 | 6 | Currently this example does not make use of the 3DS camera's calibration data to get a correct 3D effect. 7 | 8 | -------------------------------------------------------------------------------- /3ds-examples-master/mvd/mvd.xml: -------------------------------------------------------------------------------- 1 | 2 | 0004001000020000 3 | 0004001000021000 4 | 0004001000022000 5 | 0004001000026000 6 | 0004001000027000 7 | 0004001000028000 8 | 9 | -------------------------------------------------------------------------------- /3ds-examples-master/app_launch/README.md: -------------------------------------------------------------------------------- 1 | app_launch 2 | ======= 3 | 4 | Example for launching other apps/applets with libctru. Press the A button to launch the app or applet specified in the source. 5 | 6 | 7 | Note: The title ID of the EUR Nintendo 3DS Camera app is hardcoded and you need to change it if your 3DS is not an european one. See here for title IDs: http://3dbrew.org/wiki/Title_list#00040010_-_System_Applications 8 | This example only works if launched as regular app by the home menu. It will not work with the homebrew menu. 9 | 10 | -------------------------------------------------------------------------------- /3ds-examples-master/templates/application/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include <3ds.h> 5 | 6 | int main(int argc, char* argv[]) 7 | { 8 | gfxInitDefault(); 9 | consoleInit(GFX_TOP, NULL); 10 | 11 | printf("Hello, world!\n"); 12 | 13 | // Main loop 14 | while (aptMainLoop()) 15 | { 16 | gspWaitForVBlank(); 17 | gfxSwapBuffers(); 18 | hidScanInput(); 19 | 20 | // Your code goes here 21 | u32 kDown = hidKeysDown(); 22 | if (kDown & KEY_START) 23 | break; // break in order to return to hbmenu 24 | } 25 | 26 | gfxExit(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /3ds-examples-master/nfc/README.md: -------------------------------------------------------------------------------- 1 | This example is for using NFC for accessing amiibo. 2 | 3 | The amiibo AppID for AppData used here is hard-coded for Super Smash Bros. This example saves the read amiibo AppData to SD, and can write AppData from SD to the amiibo as well. 4 | 5 | The \*hax payload will automatically handle running this under the required process for using the "nfc:u" service, on New3DS. What title to run under on Old3DS hasn't been determined yet(Old3DS doesn't have any system-applications that could be used for this unlike New3DS). With Old3DS the target would need nfcu service access, and bitmask 0xF0000000 clear in the tidlow for the NFC-sysmodule dependency in the exheader. 6 | 7 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/geoshader/source/program.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Constants 4 | .constf myconst(0.0, 1.0, -1.0, -0.5) 5 | .alias zeros myconst.xxxx ; Vector full of zeros 6 | .alias ones myconst.yyyy ; Vector full of ones 7 | 8 | ; Outputs - since we are also using a geoshader the output type isn't really used 9 | .out outpos position 10 | .out outclr color 11 | 12 | ; Inputs (defined as aliases for convenience) 13 | .alias inpos v0 14 | .alias inclr v1 15 | 16 | .entry vmain 17 | .proc vmain 18 | ; Pass through both inputs to the geoshader 19 | mov outpos.xyz, inpos 20 | mov outpos.w, ones 21 | mov outclr, inclr 22 | 23 | ; We're finished 24 | end 25 | .end 26 | -------------------------------------------------------------------------------- /3ds-examples-master/app_launch/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include <3ds.h> 5 | 6 | int main() 7 | { 8 | gfxInitDefault(); 9 | consoleInit(GFX_TOP, NULL); 10 | 11 | printf("APT chainload example\n"); 12 | printf("Press A to chainload to EUR camera app\n"); 13 | printf("Press START to exit\n"); 14 | 15 | while (aptMainLoop()) 16 | { 17 | gspWaitForVBlank(); 18 | gfxSwapBuffers(); 19 | hidScanInput(); 20 | 21 | u32 kDown = hidKeysDown(); 22 | 23 | if (kDown & KEY_START) 24 | break; 25 | 26 | if (kDown & KEY_A) // If the A button got pressed, start the app launch 27 | { 28 | aptSetChainloader(0x0004001000022400LL, 0); // *EUR* camera app title ID 29 | break; 30 | } 31 | } 32 | 33 | gfxExit(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /3ds-examples-master/mvd/README.md: -------------------------------------------------------------------------------- 1 | This example is for using New3DS MVD, for hardware color-format conversion + video processing. 2 | 3 | To build this you need "romfs:/video.h264", this isn't included in git currently. See the source for size limits. You can use this for generating that: "avconv -i {input video} -s 240x400 -vf transpose=1 romfs/video.h264" 4 | 5 | To actually use this example on New3DS, you must either run under modded-FIRM which allows you to access MVDSTD, or ninjhax 1.x(\*hax payloads >=v2.x currently don't have a way implemented to access MVDSTD). The process you run this under must also have kernel-release-version >=2.44(FIRM v8.0) in the exheader, such as System Settings. 6 | 7 | Video playback with this is *very* *slow* currently due to displaying each frame immediately after rendering without any buffering. 8 | -------------------------------------------------------------------------------- /3ds-examples-master/network/boss/build_bossdata.sh: -------------------------------------------------------------------------------- 1 | # Usage: ./build_bossdata.sh {additional param(s) if any for bosstool} 2 | # Requires bosstool from: https://github.com/yellows8/3dscrypto-tools 3 | # Builds the bossdata files @ web/boss/ used by this app. 4 | 5 | params="--input=bossinput --build --nsdataid=0x57524248" 6 | echo -n "TestHello world from BOSS!" > bossinput 7 | mkdir -p web/boss 8 | bosstool --output=web/boss/JPN_bossdata0.bin --programID=0004003000008202 $params $1 9 | bosstool --output=web/boss/USA_bossdata0.bin --programID=0004003000008f02 $params $1 10 | bosstool --output=web/boss/EUR_bossdata0.bin --programID=0004003000009802 $params $1 11 | bosstool --output=web/boss/CHN_bossdata0.bin --programID=000400300000a102 $params $1 12 | bosstool --output=web/boss/KOR_bossdata0.bin --programID=000400300000a902 $params $1 13 | bosstool --output=web/boss/TWN_bossdata0.bin --programID=000400300000b102 $params $1 14 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/both_screens/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.1) 8 | .constf myconst2(0.3, 0.0, 0.0, 0.0) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias inclr v1 19 | 20 | .proc main 21 | ; Force the w component of inpos to be 1.0 22 | mov r0.xyz, inpos 23 | mov r0.w, ones 24 | 25 | ; outpos = projectionMatrix * inpos 26 | dp4 outpos.x, projection[0], r0 27 | dp4 outpos.y, projection[1], r0 28 | dp4 outpos.z, projection[2], r0 29 | dp4 outpos.w, projection[3], r0 30 | 31 | ; outclr = inclr 32 | mov outclr, inclr 33 | 34 | ; We're finished 35 | end 36 | .end 37 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/multiple_buf/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.1) 8 | .constf myconst2(0.3, 0.0, 0.0, 0.0) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias inclr v1 19 | 20 | .proc main 21 | ; Force the w component of inpos to be 1.0 22 | mov r0.xyz, inpos 23 | mov r0.w, ones 24 | 25 | ; outpos = projectionMatrix * inpos 26 | dp4 outpos.x, projection[0], r0 27 | dp4 outpos.y, projection[1], r0 28 | dp4 outpos.z, projection[2], r0 29 | dp4 outpos.w, projection[3], r0 30 | 31 | ; outclr = inclr 32 | mov outclr, inclr 33 | 34 | ; We're finished 35 | end 36 | .end 37 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/proctex/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.1) 8 | .constf myconst2(0.3, 0.0, 0.0, 0.0) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outtc0 texcoord0 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias intc0 v1 19 | 20 | .proc main 21 | ; Force the w component of inpos to be 1.0 22 | mov r0.xyz, inpos 23 | mov r0.w, ones 24 | 25 | ; outpos = projectionMatrix * inpos 26 | dp4 outpos.x, projection[0], r0 27 | dp4 outpos.y, projection[1], r0 28 | dp4 outpos.z, projection[2], r0 29 | dp4 outpos.w, projection[3], r0 30 | 31 | ; outtc0 = intc0 32 | mov outtc0, intc0 33 | 34 | ; We're finished 35 | end 36 | .end 37 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/simple_tri/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.1) 8 | .constf myconst2(0.3, 0.0, 0.0, 0.0) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias inclr v1 19 | 20 | .proc main 21 | ; Force the w component of inpos to be 1.0 22 | mov r0.xyz, inpos 23 | mov r0.w, ones 24 | 25 | ; outpos = projectionMatrix * inpos 26 | dp4 outpos.x, projection[0], r0 27 | dp4 outpos.y, projection[1], r0 28 | dp4 outpos.z, projection[2], r0 29 | dp4 outpos.w, projection[3], r0 30 | 31 | ; outclr = inclr 32 | mov outclr, inclr 33 | 34 | ; We're finished 35 | end 36 | .end 37 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/immediate/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.1) 8 | .constf myconst2(0.3, 0.0, 0.0, 0.0) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias inclr v1 19 | 20 | .bool test 21 | 22 | .proc main 23 | ; Force the w component of inpos to be 1.0 24 | mov r0.xyz, inpos 25 | mov r0.w, ones 26 | 27 | ; outpos = projectionMatrix * inpos 28 | dp4 outpos.x, projection[0], r0 29 | dp4 outpos.y, projection[1], r0 30 | dp4 outpos.z, projection[2], r0 31 | dp4 outpos.w, projection[3], r0 32 | 33 | ; outclr = inclr 34 | mov outclr, inclr 35 | 36 | ; We're finished 37 | end 38 | .end 39 | -------------------------------------------------------------------------------- /3ds-examples-master/get_system_language/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <3ds.h> 4 | 5 | 6 | int main(int argc, char** argv) 7 | { 8 | // Initialize services 9 | gfxInitDefault(); 10 | cfguInit(); 11 | 12 | 13 | u8 language = 0; 14 | Result res; 15 | 16 | // Init console for text output 17 | consoleInit(GFX_BOTTOM, NULL); 18 | 19 | // Read the language field from the config savegame. 20 | res = CFGU_GetSystemLanguage(&language); 21 | 22 | // Print return value and language code 23 | printf(" Result: 0x%x\n", (int)res); 24 | printf("Language code: %d", (int)language); 25 | 26 | 27 | // Main loop 28 | while (aptMainLoop()) 29 | { 30 | hidScanInput(); 31 | 32 | u32 kDown = hidKeysDown(); 33 | if (kDown & KEY_START) 34 | break; // break in order to return to hbmenu 35 | 36 | // Flush and swap framebuffers 37 | gfxFlushBuffers(); 38 | gfxSwapBuffers(); 39 | gspWaitForVBlank(); 40 | } 41 | 42 | // Exit services 43 | cfguExit(); 44 | gfxExit(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/cubemap/source/skybox.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, -0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | 11 | ; Outputs 12 | .out outpos position 13 | .out outtc0 texcoord0.st 14 | .out - texcoord0w outtc0.p 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | 19 | .proc main 20 | ; Force the w component of inpos to be 1.0 21 | mov r0.xyz, inpos 22 | mov r0.w, ones 23 | 24 | ; r1 = modelView * inpos 25 | dp4 r1.x, modelView[0], r0 26 | dp4 r1.y, modelView[1], r0 27 | dp4 r1.z, modelView[2], r0 28 | dp4 r1.w, modelView[3], r0 29 | 30 | ; outpos = projection * r1 31 | dp4 outpos.x, projection[0], r1 32 | dp4 outpos.y, projection[1], r1 33 | dp4 outpos.z, projection[2], r1 34 | dp4 outpos.w, projection[3], r1 35 | 36 | ; outtc0 = position 37 | mov outtc0, inpos 38 | 39 | ; We're finished 40 | end 41 | .end 42 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/loop_subdivision/source/program.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, -0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | 11 | ; Outputs 12 | .out outpos position 13 | .out outtc0 texcoord0.st 14 | .out outval dummy.x 15 | 16 | ; Inputs (defined as aliases for convenience) 17 | .alias inpos v0 18 | .alias intc0 v1 19 | .alias inval v2 20 | 21 | .entry vmain 22 | .proc vmain 23 | ; Set the position (projection * modelView * inpos) 24 | dp4 r15.x, modelView[0], inpos 25 | dp4 r15.y, modelView[1], inpos 26 | dp4 r15.z, modelView[2], inpos 27 | dp4 r15.w, modelView[3], inpos 28 | dp4 outpos.x, projection[0], r15 29 | dp4 outpos.y, projection[1], r15 30 | dp4 outpos.z, projection[2], r15 31 | dp4 outpos.w, projection[3], r15 32 | 33 | ; Set the texcoord 34 | mov outtc0.st, intc0 35 | mov outtc0.pq, zeros 36 | 37 | ; Set the valence 38 | mov outval, inval.x 39 | 40 | ; We're finished 41 | end 42 | .end 43 | -------------------------------------------------------------------------------- /3ds-examples-master/network/boss/README.md: -------------------------------------------------------------------------------- 1 | # boss 2 | 3 | This is an example for using SpotPass. This can only be used if bosshaxx from ctr-httpwn >=v1.2 is active, or if you're using "CFW"(when using unsigned SpotPass content). 4 | 5 | When running under \*hax payload, the required \*hax payload version is >=v2.8. In that case, the registered BOSS task is associated with Home Menu, with the SpotPass content being stored under the NAND extdata specified by Home Menu for SpotPass data storage. The task+content are automatically deleted by this example once finished. Due to being associated with Home Menu, seperate bossdata URLs for each region is required. 6 | 7 | If you prefer to use BOSS with the title your application is running under instead, you can use this: bossInit(0, true); You might have to use bossSetStorageInfo() if BOSS wasn't setup for use with that title. 8 | 9 | See build_bossdata.sh for building the bossdata files. NOTE: bosstool currently uses a hard-coded timestamp for building the BOSS-container, it's unknown whether this needs to be changed for tasks that run more than once when updating the content. 10 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/wide-console/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | gfxInitDefault(); 7 | gfxSetWide(true); // Enable wide mode 8 | consoleInit(GFX_TOP, NULL); 9 | 10 | printf("\x1b[2;38HHello wide screen world!"); 11 | printf("\x1b[4;1H"); 12 | 13 | printf("800px wide mode can be used with the libctru console. All you need to do is call gfxSetWide(true);\n"); 14 | printf("before initializing the console, and there you go! A nice 100x30 character console ready for use :)\n\n"); 15 | 16 | printf("Don't forget: wide mode is not compatible with Old 2DS consoles (however bizarrely enough, it *is*\n"); 17 | printf("compatible with New 2DS XL consoles. All other 3DS models seem to be compatible as well.\n"); 18 | 19 | printf("\x1b[28;40HPress Start to exit.\n"); 20 | 21 | while (aptMainLoop()) 22 | { 23 | hidScanInput(); 24 | 25 | u32 kDown = hidKeysDown(); 26 | if (kDown & KEY_START) 27 | break; 28 | 29 | gfxFlushBuffers(); 30 | gfxSwapBuffers(); 31 | gspWaitForVBlank(); 32 | } 33 | 34 | gfxExit(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/bitmap/24bit-color/README.md: -------------------------------------------------------------------------------- 1 | 24bit Bitmap Example 2 | ======= 3 | 4 | This example shows on bottom screen an upscaled version of the nds examples Drunken Coders logo that can be found in devkitPro. 5 | 6 | If you want to try with your own image follow these steps: 7 | 8 | 1. Download & install: http://www.imagemagick.org/ (If you get an option to add the application to the path make sure to check it!). 9 | 2. convert fileIn.png -channel B -separate fileIn.png -channel G -separate fileIn.png -channel R -separate -channel RGB -combine -rotate 90 fileOut.rgb 10 | 3. Rename fileOut.rgb in fileOut.bin 11 | 4. Copy fileOut.bin in the data folder of your project 12 | 5. Replace any reference of drunkenlogo_bin in main.cpp with fileOut_bin (or however you named it) 13 | 6. Re-Build the project 14 | 15 | 16 | As you can see from the previos steps the image is clockwise rotated by 90 degrees and its B and R channels are swapped. The first operation is done because the 3DS screens are actually portrait screens rotated by 90 degrees (in a counter-clockwise direction), while the second one is done because the 3DS screens' framebuffers have a BGR888 color format, by default. -------------------------------------------------------------------------------- /3ds-examples-master/Makefile: -------------------------------------------------------------------------------- 1 | DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d) 2 | 3 | MAKEFILES := $(shell find . -mindepth 2 -name Makefile) 4 | 5 | #--------------------------------------------------------------------------------- 6 | all: examples 7 | #--------------------------------------------------------------------------------- 8 | @rm -fr bin 9 | @mkdir -p bin 10 | @find . -name "*.3dsx" ! -path "./bin/*" -exec cp -fv {} bin \; 11 | 12 | #--------------------------------------------------------------------------------- 13 | examples: 14 | #--------------------------------------------------------------------------------- 15 | @for i in $(MAKEFILES); do $(MAKE) -C `dirname $$i` || exit 1; done; 16 | 17 | #--------------------------------------------------------------------------------- 18 | clean: 19 | #--------------------------------------------------------------------------------- 20 | @rm -fr bin 21 | @rm -f *.bz2 22 | @for i in $(MAKEFILES); do $(MAKE) -C `dirname $$i` clean || exit 1; done; 23 | 24 | #--------------------------------------------------------------------------------- 25 | dist: clean 26 | #--------------------------------------------------------------------------------- 27 | @tar -cvjf 3ds-examples-$(DATESTRING).tar.bz2 * 28 | -------------------------------------------------------------------------------- /3ds-examples-master/romfs/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include <3ds.h> 5 | 6 | void printfile(const char* path) 7 | { 8 | FILE* f = fopen(path, "r"); 9 | if (f) 10 | { 11 | char mystring[100]; 12 | while (fgets(mystring, sizeof(mystring), f)) 13 | { 14 | int a = strlen(mystring); 15 | if (mystring[a-1] == '\n') 16 | { 17 | mystring[a-1] = 0; 18 | if (mystring[a-2] == '\r') 19 | mystring[a-2] = 0; 20 | } 21 | puts(mystring); 22 | } 23 | printf(">>EOF<<\n"); 24 | fclose(f); 25 | } 26 | } 27 | 28 | int main() 29 | { 30 | gfxInitDefault(); 31 | consoleInit(GFX_TOP, NULL); 32 | 33 | Result rc = romfsInit(); 34 | if (rc) 35 | printf("romfsInit: %08lX\n", rc); 36 | else 37 | { 38 | printf("romfs Init Successful!\n"); 39 | printfile("romfs:/folder/file.txt"); 40 | // Test reading a file with non-ASCII characters in the name 41 | printfile("romfs:/フォルダ/ファイル.txt"); 42 | } 43 | 44 | // Main loop 45 | while (aptMainLoop()) 46 | { 47 | gspWaitForVBlank(); 48 | hidScanInput(); 49 | 50 | u32 kDown = hidKeysDown(); 51 | if (kDown & KEY_START) 52 | break; // break in order to return to hbmenu 53 | } 54 | 55 | romfsExit(); 56 | gfxExit(); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/gfx/sprites.t3s: -------------------------------------------------------------------------------- 1 | --atlas -f rgba8888 -z auto 2 | enemyBlack1.png 3 | enemyBlack2.png 4 | enemyBlack3.png 5 | enemyBlack4.png 6 | enemyBlack5.png 7 | enemyBlue1.png 8 | enemyBlue2.png 9 | enemyBlue3.png 10 | enemyBlue4.png 11 | enemyBlue5.png 12 | enemyGreen1.png 13 | enemyGreen2.png 14 | enemyGreen3.png 15 | enemyGreen4.png 16 | enemyGreen5.png 17 | enemyRed1.png 18 | enemyRed2.png 19 | enemyRed3.png 20 | enemyRed4.png 21 | enemyRed5.png 22 | meteorBrown_big1.png 23 | meteorBrown_big2.png 24 | meteorBrown_big3.png 25 | meteorBrown_big4.png 26 | meteorBrown_med1.png 27 | meteorBrown_med3.png 28 | meteorBrown_small1.png 29 | meteorBrown_small2.png 30 | meteorBrown_tiny1.png 31 | meteorBrown_tiny2.png 32 | meteorGrey_big1.png 33 | meteorGrey_big2.png 34 | meteorGrey_big3.png 35 | meteorGrey_big4.png 36 | meteorGrey_med1.png 37 | meteorGrey_med2.png 38 | meteorGrey_small1.png 39 | meteorGrey_small2.png 40 | meteorGrey_tiny1.png 41 | meteorGrey_tiny2.png 42 | playerShip1_blue.png 43 | playerShip1_green.png 44 | playerShip1_orange.png 45 | playerShip1_red.png 46 | playerShip2_blue.png 47 | playerShip2_green.png 48 | playerShip2_orange.png 49 | playerShip2_red.png 50 | playerShip3_blue.png 51 | playerShip3_green.png 52 | playerShip3_orange.png 53 | playerShip3_red.png 54 | ufoBlue.png 55 | ufoGreen.png 56 | ufoRed.png 57 | ufoYellow.png 58 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/hello-world/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Hello World example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/12/2014 21:00 UTC+1 4 | */ 5 | 6 | #include <3ds.h> 7 | #include 8 | 9 | int main(int argc, char **argv) 10 | { 11 | gfxInitDefault(); 12 | 13 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 14 | consoleInit(GFX_TOP, NULL); 15 | 16 | //Move the cursor to row 15 and column 19 and then prints "Hello World!" 17 | //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively 18 | //the row and column where you want your cursor to move 19 | //The top screen has 30 rows and 50 columns 20 | //The bottom screen has 30 rows and 40 columns 21 | printf("\x1b[16;20HHello World!"); 22 | 23 | printf("\x1b[30;16HPress Start to exit."); 24 | 25 | // Main loop 26 | while (aptMainLoop()) 27 | { 28 | //Scan all the inputs. This should be done once for each frame 29 | hidScanInput(); 30 | 31 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 32 | u32 kDown = hidKeysDown(); 33 | 34 | if (kDown & KEY_START) break; // break in order to return to hbmenu 35 | 36 | // Flush and swap framebuffers 37 | gfxFlushBuffers(); 38 | gfxSwapBuffers(); 39 | 40 | //Wait for VBlank 41 | gspWaitForVBlank(); 42 | } 43 | 44 | gfxExit(); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /3ds-examples-master/threads/event/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include <3ds.h> 8 | 9 | Thread threadHandle; 10 | Handle threadRequest; 11 | 12 | #define STACKSIZE (4 * 1024) 13 | 14 | volatile bool runThread = true; 15 | 16 | volatile int threadcount=0; 17 | 18 | void threadMain(void *arg) { 19 | 20 | while(runThread) { 21 | svcWaitSynchronization(threadRequest, U64_MAX); 22 | svcClearEvent(threadRequest); 23 | 24 | threadcount++; 25 | } 26 | } 27 | 28 | int main(int argc, char** argv) 29 | { 30 | gfxInitDefault(); 31 | consoleInit(GFX_TOP, NULL); 32 | 33 | svcCreateEvent(&threadRequest,0); 34 | threadHandle = threadCreate(threadMain, 0, STACKSIZE, 0x3f, -2, true); 35 | 36 | printf("thread handle: %p\n", threadHandle); 37 | 38 | // Main loop 39 | while (aptMainLoop()) 40 | { 41 | gspWaitForVBlank(); 42 | hidScanInput(); 43 | 44 | printf("\x1b[6;1H"); 45 | printf("thread counter = %d\n",threadcount); 46 | 47 | u32 kDown = hidKeysDown(); 48 | if (kDown & KEY_START) 49 | break; // break in order to return to hbmenu 50 | 51 | if (kDown & KEY_A) 52 | svcSignalEvent(threadRequest); 53 | 54 | // Flush and swap framebuffers 55 | gfxFlushBuffers(); 56 | gfxSwapBuffers(); 57 | } 58 | 59 | // tell thread to exit 60 | runThread = false; 61 | 62 | // signal the thread and wait for it to exit 63 | svcSignalEvent(threadRequest); 64 | threadJoin(threadHandle, U64_MAX); 65 | 66 | // close event handle 67 | svcCloseHandle(threadRequest); 68 | 69 | gfxExit(); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /lab_day_project/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | // Initialize services 7 | gfxInitDefault(); 8 | 9 | //In this example we need one PrintConsole for each screen 10 | PrintConsole topScreen, bottomScreen; 11 | 12 | //Initialize console for both screen using the two different PrintConsole we have defined 13 | consoleInit(GFX_TOP, &topScreen); 14 | consoleInit(GFX_BOTTOM, &bottomScreen); 15 | 16 | //Before doing any text printing we should select the PrintConsole in which we are willing to write, otherwise the library will print on the last selected/initialized one 17 | //Let's start by printing something on the top screen 18 | consoleSelect(&topScreen); 19 | printf("Hello Outdoorsy!\nI hope your lab day is going well~"); 20 | 21 | //Now write something else on the bottom screen 22 | consoleSelect(&bottomScreen); 23 | printf("This a demo app\nbuilt by one of your programmers."); 24 | 25 | consoleSelect(&topScreen); 26 | printf("\x1b[30;16HPress Start to exit."); 27 | 28 | // Main loop 29 | while (aptMainLoop()) 30 | { 31 | //Scan all the inputs. This should be done once for each frame 32 | hidScanInput(); 33 | 34 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 35 | u32 kDown = hidKeysDown(); 36 | 37 | if (kDown & KEY_START) break; // break in order to return to hbmenu 38 | 39 | // Flush and swap framebuffers 40 | gfxFlushBuffers(); 41 | gfxSwapBuffers(); 42 | 43 | //Wait for VBlank 44 | gspWaitForVBlank(); 45 | } 46 | 47 | // Exit services 48 | gfxExit(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /3ds-examples-master/threads/thread-basic/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <3ds.h> 4 | 5 | #define NUMTHREADS 3 6 | #define STACKSIZE (4 * 1024) 7 | 8 | volatile bool runThreads = true; 9 | 10 | void threadMain(void *arg) 11 | { 12 | u64 sleepDuration = 1000000ULL * (u32)arg; 13 | int i = 0; 14 | while (runThreads) 15 | { 16 | printf("thread%d says %d\n", (int)arg, i++); 17 | svcSleepThread(sleepDuration); 18 | } 19 | } 20 | 21 | int main(int argc, char** argv) 22 | { 23 | gfxInitDefault(); 24 | consoleInit(GFX_TOP, NULL); 25 | 26 | Thread threads[NUMTHREADS]; 27 | int i; 28 | s32 prio = 0; 29 | svcGetThreadPriority(&prio, CUR_THREAD_HANDLE); 30 | printf("Main thread prio: 0x%lx\n", prio); 31 | 32 | for (i = 0; i < NUMTHREADS; i ++) 33 | { 34 | // The priority of these child threads must be higher (aka the value is lower) than that 35 | // of the main thread, otherwise there is thread starvation due to stdio being locked. 36 | threads[i] = threadCreate(threadMain, (void*)((i+1)*250), STACKSIZE, prio-1, -2, false); 37 | printf("created thread %d: %p\n", i, threads[i]); 38 | } 39 | 40 | // Main loop 41 | while (aptMainLoop()) 42 | { 43 | gspWaitForVBlank(); 44 | hidScanInput(); 45 | 46 | u32 kDown = hidKeysDown(); 47 | if (kDown & KEY_START) 48 | break; // break in order to return to hbmenu 49 | 50 | // Flush and swap framebuffers 51 | gfxFlushBuffers(); 52 | gfxSwapBuffers(); 53 | } 54 | 55 | // tell threads to exit & wait for them to exit 56 | runThreads = false; 57 | for (i = 0; i < NUMTHREADS; i ++) 58 | { 59 | threadJoin(threads[i], U64_MAX); 60 | threadFree(threads[i]); 61 | } 62 | 63 | gfxExit(); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/lenny/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias half myconst.wwww 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | .out outview view 16 | .out outnq normalquat 17 | 18 | ; Inputs (defined as aliases for convenience) 19 | .in inpos v0 20 | .in innrm v1 21 | 22 | .proc main 23 | ; Force the w component of inpos to be 1.0 24 | mov r0.xyz, inpos 25 | mov r0.w, ones 26 | 27 | ; r1 = modelView * inpos 28 | dp4 r1.x, modelView[0], r0 29 | dp4 r1.y, modelView[1], r0 30 | dp4 r1.z, modelView[2], r0 31 | dp4 r1.w, modelView[3], r0 32 | 33 | ; outview = -r1 34 | mov outview, -r1 35 | 36 | ; outpos = projection * r1 37 | dp4 outpos.x, projection[0], r1 38 | dp4 outpos.y, projection[1], r1 39 | dp4 outpos.z, projection[2], r1 40 | dp4 outpos.w, projection[3], r1 41 | 42 | ; Transform the normal vector with the modelView matrix 43 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 44 | dp3 r14.x, modelView[0], innrm 45 | dp3 r14.y, modelView[1], innrm 46 | dp3 r14.z, modelView[2], innrm 47 | dp3 r6.x, r14, r14 48 | rsq r6.x, r6.x 49 | mul r14.xyz, r14.xyz, r6.x 50 | 51 | mov r0, myconst.yxxx 52 | add r4, ones, r14.z 53 | mul r4, half, r4 54 | cmp zeros, ge, ge, r4.x 55 | rsq r4, r4.x 56 | mul r5, half, r14 57 | jmpc cmp.x, degenerate 58 | 59 | rcp r0.z, r4.x 60 | mul r0.xy, r5, r4 61 | 62 | degenerate: 63 | mov outnq, r0 64 | mov outclr, ones 65 | 66 | ; We're finished 67 | end 68 | .end 69 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/composite_scene/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias half myconst.wwww 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | .out outview view 16 | .out outnq normalquat 17 | 18 | ; Inputs (defined as aliases for convenience) 19 | .in inpos v0 20 | .in innrm v1 21 | 22 | .proc main 23 | ; Force the w component of inpos to be 1.0 24 | mov r0.xyz, inpos 25 | mov r0.w, ones 26 | 27 | ; r1 = modelView * inpos 28 | dp4 r1.x, modelView[0], r0 29 | dp4 r1.y, modelView[1], r0 30 | dp4 r1.z, modelView[2], r0 31 | dp4 r1.w, modelView[3], r0 32 | 33 | ; outview = -r1 34 | mov outview, -r1 35 | 36 | ; outpos = projection * r1 37 | dp4 outpos.x, projection[0], r1 38 | dp4 outpos.y, projection[1], r1 39 | dp4 outpos.z, projection[2], r1 40 | dp4 outpos.w, projection[3], r1 41 | 42 | ; Transform the normal vector with the modelView matrix 43 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 44 | dp3 r14.x, modelView[0], innrm 45 | dp3 r14.y, modelView[1], innrm 46 | dp3 r14.z, modelView[2], innrm 47 | dp3 r6.x, r14, r14 48 | rsq r6.x, r6.x 49 | mul r14.xyz, r14.xyz, r6.x 50 | 51 | mov r0, myconst.yxxx 52 | add r4, ones, r14.z 53 | mul r4, half, r4 54 | cmp zeros, ge, ge, r4.x 55 | rsq r4, r4.x 56 | mul r5, half, r14 57 | jmpc cmp.x, degenerate 58 | 59 | rcp r0.z, r4.x 60 | mul r0.xy, r5, r4 61 | 62 | degenerate: 63 | mov outnq, r0 64 | mov outclr, ones 65 | 66 | ; We're finished 67 | end 68 | .end 69 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/toon_shading/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias half myconst.wwww 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | .out outview view 16 | .out outnq normalquat 17 | 18 | ; Inputs (defined as aliases for convenience) 19 | .in inpos v0 20 | .in innrm v1 21 | 22 | .proc main 23 | ; Force the w component of inpos to be 1.0 24 | mov r0.xyz, inpos 25 | mov r0.w, ones 26 | 27 | ; r1 = modelView * inpos 28 | dp4 r1.x, modelView[0], r0 29 | dp4 r1.y, modelView[1], r0 30 | dp4 r1.z, modelView[2], r0 31 | dp4 r1.w, modelView[3], r0 32 | 33 | ; outview = -r1 34 | mov outview, -r1 35 | 36 | ; outpos = projection * r1 37 | dp4 outpos.x, projection[0], r1 38 | dp4 outpos.y, projection[1], r1 39 | dp4 outpos.z, projection[2], r1 40 | dp4 outpos.w, projection[3], r1 41 | 42 | ; Transform the normal vector with the modelView matrix 43 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 44 | dp3 r14.x, modelView[0], innrm 45 | dp3 r14.y, modelView[1], innrm 46 | dp3 r14.z, modelView[2], innrm 47 | dp3 r6.x, r14, r14 48 | rsq r6.x, r6.x 49 | mul r14.xyz, r14.xyz, r6.x 50 | 51 | mov r0, myconst.yxxx 52 | add r4, ones, r14.z 53 | mul r4, half, r4 54 | cmp zeros, ge, ge, r4.x 55 | rsq r4, r4.x 56 | mul r5, half, r14 57 | jmpc cmp.x, degenerate 58 | 59 | rcp r0.z, r4.x 60 | mul r0.xy, r5, r4 61 | 62 | degenerate: 63 | mov outnq, r0 64 | mov outclr, ones 65 | 66 | ; We're finished 67 | end 68 | .end 69 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/wide_mode_3d/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias half myconst.wwww 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outclr color 15 | .out outview view 16 | .out outnq normalquat 17 | 18 | ; Inputs (defined as aliases for convenience) 19 | .in inpos v0 20 | .in innrm v1 21 | 22 | .proc main 23 | ; Force the w component of inpos to be 1.0 24 | mov r0.xyz, inpos 25 | mov r0.w, ones 26 | 27 | ; r1 = modelView * inpos 28 | dp4 r1.x, modelView[0], r0 29 | dp4 r1.y, modelView[1], r0 30 | dp4 r1.z, modelView[2], r0 31 | dp4 r1.w, modelView[3], r0 32 | 33 | ; outview = -r1 34 | mov outview, -r1 35 | 36 | ; outpos = projection * r1 37 | dp4 outpos.x, projection[0], r1 38 | dp4 outpos.y, projection[1], r1 39 | dp4 outpos.z, projection[2], r1 40 | dp4 outpos.w, projection[3], r1 41 | 42 | ; Transform the normal vector with the modelView matrix 43 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 44 | dp3 r14.x, modelView[0], innrm 45 | dp3 r14.y, modelView[1], innrm 46 | dp3 r14.z, modelView[2], innrm 47 | dp3 r6.x, r14, r14 48 | rsq r6.x, r6.x 49 | mul r14.xyz, r14.xyz, r6.x 50 | 51 | mov r0, myconst.yxxx 52 | add r4, ones, r14.z 53 | mul r4, half, r4 54 | cmp zeros, ge, ge, r4.x 55 | rsq r4, r4.x 56 | mul r5, half, r14 57 | jmpc cmp.x, degenerate 58 | 59 | rcp r0.z, r4.x 60 | mul r0.xy, r5, r4 61 | 62 | degenerate: 63 | mov outnq, r0 64 | mov outclr, ones 65 | 66 | ; We're finished 67 | end 68 | .end 69 | -------------------------------------------------------------------------------- /3ds-examples-master/input/touch-screen/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Touch Screen example made by Aurelio Mannara for libctru 3 | Please refer to https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/hid.h for more information 4 | This code was modified for the last time on: 12/13/2014 2:30 UTC+1 5 | 6 | This wouldn't be possible without the amazing work done by: 7 | -Smealum 8 | -fincs 9 | -WinterMute 10 | -yellows8 11 | -plutoo 12 | -mtheall 13 | -Many others who worked on 3DS and I'm surely forgetting about 14 | */ 15 | 16 | #include <3ds.h> 17 | #include 18 | 19 | int main(int argc, char **argv) 20 | { 21 | gfxInitDefault(); 22 | 23 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 24 | consoleInit(GFX_TOP, NULL); 25 | 26 | printf("\x1b[0;0HPress Start to exit."); 27 | printf("\x1b[1;0HTouch Screen position:"); 28 | 29 | // Main loop 30 | while (aptMainLoop()) 31 | { 32 | //Scan all the inputs. This should be done once for each frame 33 | hidScanInput(); 34 | 35 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 36 | u32 kDown = hidKeysDown(); 37 | 38 | if (kDown & KEY_START) break; // break in order to return to hbmenu 39 | 40 | touchPosition touch; 41 | 42 | //Read the touch screen coordinates 43 | hidTouchRead(&touch); 44 | 45 | //Print the touch screen coordinates 46 | printf("\x1b[2;0H%03d; %03d", touch.px, touch.py); 47 | 48 | 49 | // Flush and swap framebuffers 50 | gfxFlushBuffers(); 51 | gfxSwapBuffers(); 52 | 53 | //Wait for VBlank 54 | gspWaitForVBlank(); 55 | } 56 | 57 | // Exit services 58 | gfxExit(); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/fragment_light/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, -1.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias half myconst.wwww 11 | 12 | ; Outputs 13 | .out outpos position 14 | .out outtc0 texcoord0 15 | .out outclr color 16 | .out outview view 17 | .out outnq normalquat 18 | 19 | ; Inputs (defined as aliases for convenience) 20 | .alias inpos v0 21 | .alias intex v1 22 | .alias innrm v2 23 | 24 | .proc main 25 | ; Force the w component of inpos to be 1.0 26 | mov r0.xyz, inpos 27 | mov r0.w, ones 28 | 29 | ; r1 = modelView * inpos 30 | dp4 r1.x, modelView[0], r0 31 | dp4 r1.y, modelView[1], r0 32 | dp4 r1.z, modelView[2], r0 33 | dp4 r1.w, modelView[3], r0 34 | 35 | ; outview = -r1 36 | mov outview, -r1 37 | 38 | ; outpos = projection * r1 39 | dp4 outpos.x, projection[0], r1 40 | dp4 outpos.y, projection[1], r1 41 | dp4 outpos.z, projection[2], r1 42 | dp4 outpos.w, projection[3], r1 43 | 44 | ; outtex = intex 45 | mov outtc0, intex 46 | 47 | ; Transform the normal vector with the modelView matrix 48 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 49 | dp3 r14.x, modelView[0], innrm 50 | dp3 r14.y, modelView[1], innrm 51 | dp3 r14.z, modelView[2], innrm 52 | dp3 r6.x, r14, r14 53 | rsq r6.x, r6.x 54 | mul r14.xyz, r14.xyz, r6.x 55 | 56 | mov r0, myconst.yxxx 57 | add r4, ones, r14.z 58 | mul r4, half, r4 59 | cmp zeros, ge, ge, r4.x 60 | rsq r4, r4.x 61 | mul r5, half, r14 62 | jmpc cmp.x, degenerate 63 | 64 | rcp r0.z, r4.x 65 | mul r0.xy, r5, r4 66 | 67 | degenerate: 68 | mov outnq, r0 69 | mov outclr, ones 70 | 71 | ; We're finished 72 | end 73 | .end 74 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/both-screen-text/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Both Screen Text example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/12/2014 23:20 UTC+1 4 | 5 | */ 6 | 7 | #include <3ds.h> 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | // Initialize services 13 | gfxInitDefault(); 14 | 15 | //In this example we need one PrintConsole for each screen 16 | PrintConsole topScreen, bottomScreen; 17 | 18 | //Initialize console for both screen using the two different PrintConsole we have defined 19 | consoleInit(GFX_TOP, &topScreen); 20 | consoleInit(GFX_BOTTOM, &bottomScreen); 21 | 22 | //Before doing any text printing we should select the PrintConsole in which we are willing to write, otherwise the library will print on the last selected/initialized one 23 | //Let's start by printing something on the top screen 24 | consoleSelect(&topScreen); 25 | printf("This is the top screen. We have lot of space here!\n"); 26 | 27 | //Now write something else on the bottom screen 28 | consoleSelect(&bottomScreen); 29 | printf("This is the bottom screen. We don't have much space...\nStill better than DS screens :D"); 30 | 31 | consoleSelect(&topScreen); 32 | printf("\x1b[30;16HPress Start to exit."); 33 | 34 | // Main loop 35 | while (aptMainLoop()) 36 | { 37 | //Scan all the inputs. This should be done once for each frame 38 | hidScanInput(); 39 | 40 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 41 | u32 kDown = hidKeysDown(); 42 | 43 | if (kDown & KEY_START) break; // break in order to return to hbmenu 44 | 45 | // Flush and swap framebuffers 46 | gfxFlushBuffers(); 47 | gfxSwapBuffers(); 48 | 49 | //Wait for VBlank 50 | gspWaitForVBlank(); 51 | } 52 | 53 | // Exit services 54 | gfxExit(); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /3ds-examples-master/libapplet_launch/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | 5 | static bool allowed = false; 6 | 7 | // If you define this function, you can monitor/debug APT events 8 | void _aptDebug(int a, int b) 9 | { 10 | if (allowed) 11 | printf("_aptDebug(%d,%x)\n", a, b); 12 | } 13 | 14 | int main() 15 | { 16 | gfxInitDefault(); 17 | consoleInit(GFX_TOP, NULL); 18 | allowed = true; 19 | 20 | u32 aptbuf[0x400/4]; 21 | 22 | printf("Press A to launch extrapad\n"); 23 | printf("Press B to launch error\n"); 24 | printf("Press X to launch appleted (Mii Editor)\n"); 25 | printf("Press Y to launch memolib\n"); 26 | printf("Press L to launch Photo Selector\n"); 27 | printf("Press R to launch Sound Selector\n"); 28 | printf("Press ^ to launch mint (eShop)\n"); 29 | printf("Press < to launch software keyboard\n"); 30 | 31 | // Main loop 32 | while (aptMainLoop()) 33 | { 34 | gspWaitForVBlank(); 35 | gfxSwapBuffers(); 36 | hidScanInput(); 37 | 38 | u32 kDown = hidKeysDown(); 39 | if (kDown & KEY_START) 40 | break; // break in order to return to hbmenu 41 | 42 | gfxFlushBuffers(); 43 | 44 | if (kDown) 45 | { 46 | NS_APPID appId; 47 | 48 | if (kDown & KEY_A) appId = APPID_EXTRAPAD; 49 | else if (kDown & KEY_B) appId = APPID_ERROR; 50 | else if (kDown & KEY_X) appId = APPID_APPLETED; 51 | else if (kDown & KEY_Y) appId = APPID_MEMOLIB; 52 | else if (kDown & KEY_L) appId = APPID_PNOTE_AP; 53 | else if (kDown & KEY_R) appId = APPID_SNOTE_AP; 54 | else if (kDown & KEY_UP) appId = APPID_MINT; 55 | else if (kDown & KEY_LEFT) appId = APPID_SOFTWARE_KEYBOARD; 56 | else continue; 57 | 58 | memset(aptbuf, 0, sizeof(aptbuf)); 59 | aptLaunchLibraryApplet(appId, aptbuf, sizeof(aptbuf), 0); 60 | printf("Library applet exited\n"); 61 | } 62 | } 63 | 64 | // Exit services 65 | allowed = false; 66 | gfxExit(); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/bitmap/24bit-color/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Hello World example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/13/2014 01:00 UTC+1 4 | 5 | This wouldn't be possible without the amazing work done by: 6 | -Smealum 7 | -fincs 8 | -WinterMute 9 | -yellows8 10 | -plutoo 11 | -mtheall 12 | -Many others who worked on 3DS and I'm surely forgetting about 13 | */ 14 | 15 | #include <3ds.h> 16 | #include 17 | #include 18 | 19 | //This include a header containing definitions of our image 20 | #include "brew_bgr.h" 21 | 22 | int main(int argc, char **argv) 23 | { 24 | gfxInitDefault(); 25 | 26 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 27 | consoleInit(GFX_TOP, NULL); 28 | 29 | printf("Why so sad Smealum? We can haz 3DS homebrew!"); 30 | 31 | printf("\x1b[21;16HPress Start to exit."); 32 | 33 | //We don't need double buffering in this example. In this way we can draw our image only once on screen. 34 | gfxSetDoubleBuffering(GFX_BOTTOM, false); 35 | 36 | //Get the bottom screen's frame buffer 37 | u8* fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); 38 | 39 | //Copy our image in the bottom screen's frame buffer 40 | memcpy(fb, brew_bgr, brew_bgr_size); 41 | 42 | // Main loop 43 | while (aptMainLoop()) 44 | { 45 | //Scan all the inputs. This should be done once for each frame 46 | hidScanInput(); 47 | 48 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 49 | u32 kDown = hidKeysDown(); 50 | 51 | if (kDown & KEY_START) break; // break in order to return to hbmenu 52 | 53 | // Flush and swap framebuffers 54 | gfxFlushBuffers(); 55 | gfxSwapBuffers(); 56 | 57 | //Wait for VBlank 58 | gspWaitForVBlank(); 59 | } 60 | 61 | // Exit services 62 | gfxExit(); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/particles/source/particle.v.pica: -------------------------------------------------------------------------------- 1 | ; Particle vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, 3.0, 0.5) 8 | .alias zeros myconst.x 9 | .alias ones myconst.y 10 | 11 | ; Outputs 12 | .out oCenter dummy 13 | .out oAttrib dummy 14 | .out oMatrix0 dummy 15 | .out oMatrix1 dummy 16 | .out oMatrix2 dummy 17 | .out oMatrix3 dummy 18 | 19 | ; Inputs 20 | .in iCenter v0 21 | .in iRadius v1 22 | .in iAttrib v2 23 | 24 | .entry particle_vsh_main 25 | .proc particle_vsh_main 26 | mov r0, iCenter 27 | mov r0.w, ones 28 | 29 | ; r1 = modelView * vec4(iCenter, 1.0) 30 | dp4 r1.x, modelView[0], r0 31 | dp4 r1.y, modelView[1], r0 32 | dp4 r1.z, modelView[2], r0 33 | dp4 r1.w, modelView[3], r0 34 | 35 | ; oCenter = projection * r1 36 | dp4 oCenter.x, projection[0], r1 37 | dp4 oCenter.y, projection[1], r1 38 | dp4 oCenter.z, projection[2], r1 39 | dp4 oCenter.w, projection[3], r1 40 | 41 | ; oAttrib = iAttrib 42 | mov oAttrib, iAttrib 43 | 44 | ; oMatrix = projection * modelView * diagonal4x3(iRadius) 45 | mul r2.x, modelView[0].x, iRadius.x 46 | mul r2.y, modelView[1].x, iRadius.x 47 | mul r2.z, modelView[2].x, iRadius.x 48 | mul r3.x, modelView[0].y, iRadius.y 49 | mul r3.y, modelView[1].y, iRadius.y 50 | mul r3.z, modelView[2].y, iRadius.y 51 | mul r4.x, modelView[0].z, iRadius.z 52 | mul r4.y, modelView[1].z, iRadius.z 53 | mul r4.z, modelView[2].z, iRadius.z 54 | dp3 oMatrix0.x, projection[0], r2 55 | dp3 oMatrix0.y, projection[0], r3 56 | dp3 oMatrix0.z, projection[0], r4 57 | mov oMatrix0.w, zeros 58 | dp3 oMatrix1.x, projection[1], r2 59 | dp3 oMatrix1.y, projection[1], r3 60 | dp3 oMatrix1.z, projection[1], r4 61 | mov oMatrix1.w, zeros 62 | dp3 oMatrix2.x, projection[2], r2 63 | dp3 oMatrix2.y, projection[2], r3 64 | dp3 oMatrix2.z, projection[2], r4 65 | mov oMatrix2.w, zeros 66 | dp3 oMatrix3.x, projection[3], r2 67 | dp3 oMatrix3.y, projection[3], r3 68 | dp3 oMatrix3.z, projection[3], r4 69 | mov oMatrix3.w, zeros 70 | end 71 | .end 72 | -------------------------------------------------------------------------------- /3ds-examples-master/qtm/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include <3ds.h> 4 | 5 | int main() 6 | { 7 | u32 pos; 8 | u32 x, y; 9 | Result ret; 10 | bool qtm_usable; 11 | QTM_HeadTrackingInfo qtminfo; 12 | u32 colors[4] = {0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF}; 13 | 14 | gfxInitDefault(); 15 | //gfxSet3D(true); // uncomment if using stereoscopic 3D 16 | 17 | qtmInit(); 18 | 19 | consoleInit(GFX_BOTTOM, NULL); 20 | 21 | printf("qtm example\n"); 22 | 23 | qtm_usable = qtmCheckInitialized(); 24 | if(!qtm_usable)printf("QTM is not usable, therefore this example won't do anything with QTM.\n"); 25 | 26 | // Main loop 27 | while (aptMainLoop()) 28 | { 29 | gspWaitForVBlank(); 30 | hidScanInput(); 31 | 32 | u32 kDown = hidKeysDown(); 33 | if (kDown & KEY_START) 34 | break; // break in order to return to hbmenu 35 | 36 | if(qtm_usable) 37 | { 38 | u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 39 | memset(fb, 0, 400*240*3); 40 | 41 | ret = QTM_GetHeadTrackingInfo(0, &qtminfo); 42 | if(ret==0) 43 | { 44 | consoleClear(); 45 | 46 | for(pos=0; pos<5; pos++) 47 | { 48 | printf("flags[%x]=0x%x", (unsigned int)pos, qtminfo.flags[pos]); 49 | if(pos<4)printf(", "); 50 | } 51 | 52 | printf("\nfloatdata_x08: %f\n", qtminfo.floatdata_x08); 53 | 54 | printf("coords0: "); 55 | for(pos=0; pos<4; pos++) 56 | { 57 | printf("[%x].x=%f, y=%f", (unsigned int)pos, qtminfo.coords0[pos].x, qtminfo.coords0[pos].y); 58 | if(pos<3)printf(", "); 59 | } 60 | 61 | printf("\n"); 62 | 63 | if(qtmCheckHeadFullyDetected(&qtminfo)) 64 | { 65 | for(pos=0; pos<4; pos++) 66 | { 67 | ret = qtmConvertCoordToScreen(&qtminfo.coords0[pos], NULL, NULL, &x, &y); 68 | 69 | if(ret==0)memcpy(&fb[(x*240 + y) * 3], &colors[pos], 3); 70 | } 71 | } 72 | } 73 | } 74 | 75 | // Flush and swap framebuffers 76 | gfxFlushBuffers(); 77 | gfxSwapBuffers(); 78 | } 79 | 80 | // Exit services 81 | qtmExit(); 82 | gfxExit(); 83 | return 0; 84 | } 85 | 86 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/geoshader/source/program.g.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 geometry shader 2 | .gsh point c0 3 | 4 | ; Uniforms 5 | .fvec projection[4] 6 | 7 | ; Constants 8 | .constf myconst(0.0, 1.0, -1.0, 0.5) 9 | .alias zeros myconst.xxxx ; Vector full of zeros 10 | .alias ones myconst.yyyy ; Vector full of ones 11 | .alias half myconst.wwww 12 | 13 | ; Outputs - this time the type *is* used 14 | .out outpos position 15 | .out outclr color 16 | 17 | ; Inputs: we will receive the following inputs: 18 | ; v0-v1: position/color of the first vertex 19 | ; v2-v3: position/color of the second vertex 20 | ; v4-v5: position/color of the third vertex 21 | 22 | .entry gmain 23 | .proc gmain 24 | ; Calculate the midpoints of the vertices 25 | mov r4, v0 26 | add r4, v2, r4 27 | mul r4, half, r4 28 | mov r5, v2 29 | add r5, v4, r5 30 | mul r5, half, r5 31 | mov r6, v4 32 | add r6, v0, r6 33 | mul r6, half, r6 34 | 35 | ; Emit the first triangle 36 | mov r0, v0 37 | mov r1, r4 38 | mov r2, r6 39 | call emit_triangle 40 | 41 | ; Emit the second triangle 42 | mov r0, r4 43 | mov r1, v2 44 | mov r2, r5 45 | call emit_triangle 46 | 47 | ; Emit the third triangle 48 | mov r0, r6 49 | mov r1, r5 50 | mov r2, v4 51 | call emit_triangle 52 | 53 | ; We're finished 54 | end 55 | .end 56 | 57 | .proc emit_triangle 58 | ; Emit the first vertex 59 | setemit 0 60 | mov r8, r0 61 | mov r9, v1 62 | call process_vertex 63 | emit 64 | 65 | ; Emit the second vertex 66 | setemit 1 67 | mov r8, r1 68 | mov r9, v3 69 | call process_vertex 70 | emit 71 | 72 | ; Emit the third vertex and finish the primitive 73 | setemit 2, prim 74 | mov r8, r2 75 | mov r9, v5 76 | call process_vertex 77 | emit 78 | .end 79 | 80 | ; Subroutine 81 | ; Inputs: 82 | ; r8: vertex position 83 | ; r9: vertex color 84 | .proc process_vertex 85 | ; outpos = projectionMatrix * r8 86 | dp4 outpos.x, projection[0], r8 87 | dp4 outpos.y, projection[1], r8 88 | dp4 outpos.z, projection[2], r8 89 | dp4 outpos.w, projection[3], r8 90 | 91 | ; outclr = r9 92 | mov outclr, r9 93 | .end 94 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/opus-decoding/README.md: -------------------------------------------------------------------------------- 1 | # Opus decoding example 2 | 3 | This is a heavily-commented example of how to carry out fast, threaded Opus audio streaming from the filesystem (in this case, RomFS) on 3DS using libopusfile, even on O3DS. 4 | 5 | ## Necessary packages 6 | 7 | This example uses `libopusfile` (which in turn depends on `libogg` and `libopus`) to read and decode Opus audio files. The makefile also uses `pkg-config` to discover the necessary include paths and flags for the library. 8 | 9 | You can install the necessary packages with the following command: 10 | ```bash 11 | pacman -S 3ds-opusfile 3ds-pkg-config 12 | ``` 13 | 14 | Note that on some systems, you may need to use `dkp-pacman` instead of `pacman`, and you may need to prefix the installation commands with `sudo`. 15 | 16 | Additionally, if you do not already have `pkg-config` installed on your *host system*, you will need to install it using your package manager. 17 | 18 | On Windows: 19 | ```bash 20 | pacman -S pkg-config 21 | ``` 22 | 23 | On macOS: 24 | ```bash 25 | sudo dkp-pacman -S pkg-config 26 | ``` 27 | 28 | ## Further reading 29 | 30 | In addition to the detailed comments in `main.c` and the docs for [opusfile](https://www.opus-codec.org/docs/#developing-with-opusfile-api-reference) and [libctru](https://libctru.devkitpro.org/), see also [David Gow's OpenAL-based example](https://davidgow.net/hacks/opusal.html) which was indispensable when writing this code. 31 | 32 | ## Credits 33 | 34 | Originally written by [Lauren Kelly (thejsa)](https://github.com/thejsa), with lots of help from [mtheall](https://github.com/mtheall) who re-architected the decoding and buffer logic to be much more efficient as well as overall making the code half decent :) 35 | 36 | The sample audio included as `sample.opus` is a clip from [Paul Pitman's recording of Ludwig van Beethoven's Moonlight Sonata, Op. 27 No. 2 - I. Adagio sostenuto, sourced from Musopen](https://musopen.org/music/2547-piano-sonata-no-14-in-c-sharp-minor-moonlight-sonata-op-27-no-2/) and in the public domain (trimmed and amplified using Audacity for file size reasons, then transcoded to 96 kb/s Opus using ffmpeg). 37 | 38 | All links retrieved on 2020-05-16. 39 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/multiple-windows-text/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Multiple Windows Text example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/12/2014 23:50 UTC+1 4 | 5 | */ 6 | 7 | #include <3ds.h> 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | // Initialize services 13 | gfxInitDefault(); 14 | 15 | //In this example we need three PrintConsole, one for each window and one for the whole top screen 16 | PrintConsole leftWindow, rightWindow, topScreen; 17 | 18 | //Initialize console for each window 19 | consoleInit(GFX_TOP, &leftWindow); 20 | consoleInit(GFX_TOP, &rightWindow); 21 | consoleInit(GFX_TOP, &topScreen); 22 | 23 | //Now we specify the window position and dimension for each console window using consoleSetWindow(PrintConsole* console, int x, int y, int width, int height); 24 | //x, y, width and height are in terms of cells, not pixel, where each cell is composed by 8x8 pixels. 25 | consoleSetWindow(&leftWindow, 1, 1, 23, 28); 26 | consoleSetWindow(&rightWindow, 26, 1, 23, 28); 27 | 28 | //Before doing any text printing we should select the PrintConsole in which we are willing to write, otherwise the library will print on the last selected/initialized one 29 | //Let's start by printing something on the top screen 30 | consoleSelect(&leftWindow); 31 | printf("This text is in the left window!\n"); 32 | printf("3DS rocks!!!\n"); 33 | 34 | //Now write something else on the bottom screen 35 | consoleSelect(&rightWindow); 36 | printf("This text is in the right window!\n"); 37 | printf("This thing works pretty well!\n"); 38 | 39 | 40 | consoleSelect(&topScreen); 41 | printf("\x1b[30;16HPress Start to exit."); 42 | 43 | // Main loop 44 | while (aptMainLoop()) 45 | { 46 | //Scan all the inputs. This should be done once for each frame 47 | hidScanInput(); 48 | 49 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 50 | u32 kDown = hidKeysDown(); 51 | 52 | if (kDown & KEY_START) break; // break in order to return to hbmenu 53 | 54 | // Flush and swap framebuffers 55 | gfxFlushBuffers(); 56 | gfxSwapBuffers(); 57 | 58 | //Wait for VBlank 59 | gspWaitForVBlank(); 60 | } 61 | 62 | // Exit services 63 | gfxExit(); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /3ds-examples-master/sdmc/source/main.c: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////// 2 | // SDMC example // 3 | /////////////////////////////////////// 4 | 5 | //this example shows you how to load a binary image file from the SD card and display it on the lower screen 6 | //for this to work you should copy test.bin to same folder as your .3dsx 7 | //this file was generated with GIMP by saving a 240x320 image to raw RGB 8 | #include 9 | #include 10 | #include 11 | 12 | #include <3ds.h> 13 | #include "costable.h" 14 | 15 | //this will contain the data read from SDMC 16 | u8* buffer; 17 | 18 | //3DS has VFPs so we could just use cos 19 | //but we're old school so LUT4life 20 | s32 pcCos(u16 v) 21 | { 22 | return costable[v&0x1FF]; 23 | } 24 | 25 | void renderEffect() 26 | { 27 | static int cnt; 28 | u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 29 | 30 | int i, j; 31 | for(i=1;i<400;i++) 32 | { 33 | for(j=1;j<240;j++) 34 | { 35 | u32 v=(j+i*240)*3; 36 | bufAdr[v]=(pcCos(i+cnt)+4096)/32; 37 | bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64; 38 | bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32; 39 | } 40 | } 41 | 42 | cnt++; 43 | } 44 | 45 | int main(int argc, char** argv) 46 | { 47 | 48 | gfxInitDefault(); //makes displaying to screen easier 49 | 50 | FILE *file = fopen("test.bin","rb"); 51 | if (file == NULL) goto exit; 52 | 53 | // seek to end of file 54 | fseek(file,0,SEEK_END); 55 | 56 | // file pointer tells us the size 57 | off_t size = ftell(file); 58 | 59 | // seek back to start 60 | fseek(file,0,SEEK_SET); 61 | 62 | //allocate a buffer 63 | buffer=malloc(size); 64 | if(!buffer)goto exit; 65 | 66 | //read contents ! 67 | off_t bytesRead = fread(buffer,1,size,file); 68 | 69 | //close the file because we like being nice and tidy 70 | fclose(file); 71 | 72 | if(size!=bytesRead)goto exit; 73 | 74 | while(aptMainLoop()) 75 | { 76 | //exit when user hits B 77 | hidScanInput(); 78 | if(keysHeld()&KEY_B)break; 79 | 80 | //render rainbow 81 | renderEffect(); 82 | 83 | //copy buffer to lower screen (don't have to do it every frame) 84 | memcpy(gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL), buffer, size); 85 | 86 | //wait & swap 87 | gfxSwapBuffersGpu(); 88 | gspWaitForEvent(GSPGPU_EVENT_VBlank0, false); 89 | } 90 | 91 | //cleanup and return 92 | //returning from main() returns to hbmenu when run under ninjhax 93 | exit: 94 | 95 | //closing all services even more so 96 | gfxExit(); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/mipmap_fog/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | .fvec lightVec, lightHalfVec, lightClr, material[4] 6 | .alias mat_amb material[0] 7 | .alias mat_dif material[1] 8 | .alias mat_spe material[2] 9 | .alias mat_emi material[3] 10 | 11 | ; Constants 12 | .constf myconst(0.0, 1.0, -1.0, -0.5) 13 | .alias zeros myconst.xxxx ; Vector full of zeros 14 | .alias ones myconst.yyyy ; Vector full of ones 15 | 16 | ; Outputs 17 | .out outpos position 18 | .out outtc0 texcoord0 19 | .out outclr color 20 | 21 | ; Inputs (defined as aliases for convenience) 22 | .alias inpos v0 23 | .alias intex v1 24 | .alias innrm v2 25 | 26 | .proc main 27 | ; Force the w component of inpos to be 1.0 28 | mov r0.xyz, inpos 29 | mov r0.w, ones 30 | 31 | ; r1 = modelView * inpos 32 | dp4 r1.x, modelView[0], r0 33 | dp4 r1.y, modelView[1], r0 34 | dp4 r1.z, modelView[2], r0 35 | dp4 r1.w, modelView[3], r0 36 | 37 | ; outpos = projection * r1 38 | dp4 outpos.x, projection[0], r1 39 | dp4 outpos.y, projection[1], r1 40 | dp4 outpos.z, projection[2], r1 41 | dp4 outpos.w, projection[3], r1 42 | 43 | ; outtex = intex 44 | mov outtc0, intex 45 | 46 | ; Transform the normal vector with the modelView matrix 47 | ; r1 = normalize(modelView * innrm) 48 | mov r0.xyz, innrm 49 | mov r0.w, zeros 50 | dp4 r1.x, modelView[0], r0 51 | dp4 r1.y, modelView[1], r0 52 | dp4 r1.z, modelView[2], r0 53 | mov r1.w, zeros 54 | dp3 r2, r1, r1 ; r2 = x^2+y^2+z^2 for each component 55 | rsq r2, r2 ; r2 = 1/sqrt(r2) '' 56 | mul r1, r2, r1 ; r1 = r1*r2 57 | 58 | ; Calculate the diffuse level (r0.x) and the shininess level (r0.y) 59 | ; r0.x = max(0, -(lightVec * r1)) 60 | ; r0.y = max(0, (-lightHalfVec[i]) * r1) ^ 2 61 | dp3 r0.x, lightVec, r1 62 | add r0.x, zeros, -r0 63 | dp3 r0.y, -lightHalfVec, r1 64 | max r0, zeros, r0 65 | mul r0.y, r0, r0 66 | 67 | ; Accumulate the vertex color in r1, initializing it to the emission color 68 | mov r1, mat_emi 69 | 70 | ; r1 += specularColor * lightClr * shininessLevel 71 | mul r2, lightClr, r0.yyyy 72 | mad r1, r2, mat_spe, r1 73 | 74 | ; r1 += diffuseColor * lightClr * diffuseLevel 75 | mul r2, lightClr, r0.xxxx 76 | mad r1, r2, mat_dif, r1 77 | 78 | ; r1 += ambientColor * lightClr 79 | mov r2, lightClr 80 | mad r1, r2, mat_amb, r1 81 | 82 | ; outclr = clamp r1 to [0,1] 83 | min outclr, ones, r1 84 | 85 | ; We're finished 86 | end 87 | .end 88 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/textured_cube/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | .fvec lightVec, lightHalfVec, lightClr, material[4] 6 | .alias mat_amb material[0] 7 | .alias mat_dif material[1] 8 | .alias mat_spe material[2] 9 | .alias mat_emi material[3] 10 | 11 | ; Constants 12 | .constf myconst(0.0, 1.0, -1.0, -0.5) 13 | .alias zeros myconst.xxxx ; Vector full of zeros 14 | .alias ones myconst.yyyy ; Vector full of ones 15 | 16 | ; Outputs 17 | .out outpos position 18 | .out outtc0 texcoord0 19 | .out outclr color 20 | 21 | ; Inputs (defined as aliases for convenience) 22 | .alias inpos v0 23 | .alias intex v1 24 | .alias innrm v2 25 | 26 | .proc main 27 | ; Force the w component of inpos to be 1.0 28 | mov r0.xyz, inpos 29 | mov r0.w, ones 30 | 31 | ; r1 = modelView * inpos 32 | dp4 r1.x, modelView[0], r0 33 | dp4 r1.y, modelView[1], r0 34 | dp4 r1.z, modelView[2], r0 35 | dp4 r1.w, modelView[3], r0 36 | 37 | ; outpos = projection * r1 38 | dp4 outpos.x, projection[0], r1 39 | dp4 outpos.y, projection[1], r1 40 | dp4 outpos.z, projection[2], r1 41 | dp4 outpos.w, projection[3], r1 42 | 43 | ; outtex = intex 44 | mov outtc0, intex 45 | 46 | ; Transform the normal vector with the modelView matrix 47 | ; r1 = normalize(modelView * innrm) 48 | mov r0.xyz, innrm 49 | mov r0.w, zeros 50 | dp4 r1.x, modelView[0], r0 51 | dp4 r1.y, modelView[1], r0 52 | dp4 r1.z, modelView[2], r0 53 | mov r1.w, zeros 54 | dp3 r2, r1, r1 ; r2 = x^2+y^2+z^2 for each component 55 | rsq r2, r2 ; r2 = 1/sqrt(r2) '' 56 | mul r1, r2, r1 ; r1 = r1*r2 57 | 58 | ; Calculate the diffuse level (r0.x) and the shininess level (r0.y) 59 | ; r0.x = max(0, -(lightVec * r1)) 60 | ; r0.y = max(0, (-lightHalfVec[i]) * r1) ^ 2 61 | dp3 r0.x, lightVec, r1 62 | add r0.x, zeros, -r0 63 | dp3 r0.y, -lightHalfVec, r1 64 | max r0, zeros, r0 65 | mul r0.y, r0, r0 66 | 67 | ; Accumulate the vertex color in r1, initializing it to the emission color 68 | mov r1, mat_emi 69 | 70 | ; r1 += specularColor * lightClr * shininessLevel 71 | mul r2, lightClr, r0.yyyy 72 | mad r1, r2, mat_spe, r1 73 | 74 | ; r1 += diffuseColor * lightClr * diffuseLevel 75 | mul r2, lightClr, r0.xxxx 76 | mad r1, r2, mat_dif, r1 77 | 78 | ; r1 += ambientColor * lightClr 79 | mov r2, lightClr 80 | mad r1, r2, mat_amb, r1 81 | 82 | ; outclr = clamp r1 to [0,1] 83 | min outclr, ones, r1 84 | 85 | ; We're finished 86 | end 87 | .end 88 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/colored-text/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Colored Text example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/12/2014 23:00 UTC+1 4 | 5 | */ 6 | 7 | #include <3ds.h> 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | // Initialize services 13 | gfxInitDefault(); 14 | 15 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 16 | consoleInit(GFX_TOP, NULL); 17 | 18 | //Move the cursor to row 15 and column 19 and then prints "Hello World!" 19 | //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively 20 | //the row and column where you want your cursor to move 21 | //The top screen has 30 rows and 50 columns 22 | //The bottom screen has 30 rows and 40 columns 23 | printf("\x1b[16;20HHello World!"); 24 | 25 | //Move the cursor to the top left corner of the screen 26 | printf("\x1b[1;1H"); 27 | 28 | //Print a REALLY crappy poeam with colored text 29 | //\x1b[cm set a SGR (Select Graphic Rendition) parameter, where c is the parameter that you want to set 30 | //Please refer to http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes to see all the possible SGR parameters 31 | //As of now libctru support only these parameters: 32 | //Reset (0), Half bright colors (2), Reverse (7), Text color (30-37) and Background color (40-47) 33 | printf("Roses are \x1b[31mred\x1b[0m\n"); 34 | printf("Violets are \x1b[34mblue\x1b[0m\n"); 35 | printf("Lenny is our savior\n"); 36 | printf("Homebrew is his blessing\n\n"); 37 | 38 | //Black text on white background 39 | //In this example we set two parameter in a single escape sequence by separating them by a semicolon 40 | //\x1b[47;30m means that it will set a white background (47) and it will print white characters (30) 41 | //In this we also could have used the 42 | printf("\x1b[47;30mBlack text on white background\x1b[0m"); 43 | 44 | 45 | printf("\x1b[30;16HPress Start to exit."); 46 | // Main loop 47 | while (aptMainLoop()) 48 | { 49 | //Scan all the inputs. This should be done once for each frame 50 | hidScanInput(); 51 | 52 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 53 | u32 kDown = hidKeysDown(); 54 | 55 | if (kDown & KEY_START) break; // break in order to return to hbmenu 56 | 57 | // Flush and swap framebuffers 58 | gfxFlushBuffers(); 59 | gfxSwapBuffers(); 60 | 61 | //Wait for VBlank 62 | gspWaitForVBlank(); 63 | } 64 | 65 | // Exit services 66 | gfxExit(); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /3ds-examples-master/time/rtc/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | 5 | const char* const months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; 6 | 7 | const char* const weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 8 | 9 | const u16 daysAtStartOfMonthLUT[12] = 10 | { 11 | 0 % 7, //january 31 12 | 31 % 7, //february 28+1(leap year) 13 | 59 % 7, //march 31 14 | 90 % 7, //april 30 15 | 120 % 7, //may 31 16 | 151 % 7, //june 30 17 | 181 % 7, //july 31 18 | 212 % 7, //august 31 19 | 243 % 7, //september 30 20 | 273 % 7, //october 31 21 | 304 % 7, //november 30 22 | 334 % 7 //december 31 23 | }; 24 | 25 | static inline bool isLeapYear(int year) 26 | { 27 | return (year%4) == 0 && !((year%100) == 0 && (year%400) != 0); 28 | } 29 | 30 | static inline int getDayOfWeek(int day, int month, int year) 31 | { 32 | //http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week 33 | day += 2*(3-((year/100)%4)); 34 | year %= 100; 35 | day += year + (year/4); 36 | day += daysAtStartOfMonthLUT[month] - (isLeapYear(year) && (month <= 1)); 37 | return day % 7; 38 | } 39 | 40 | int main(int argc, char **argv) 41 | { 42 | // Initialize services 43 | gfxInitDefault(); 44 | 45 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 46 | consoleInit(GFX_TOP, NULL); 47 | 48 | printf("\x1b[30;16HPress Start to exit."); 49 | 50 | // Main loop 51 | while (aptMainLoop()) 52 | { 53 | //Scan all the inputs. This should be done once for each frame 54 | hidScanInput(); 55 | 56 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 57 | u32 kDown = hidKeysDown(); 58 | 59 | if (kDown & KEY_START) break; // break in order to return to hbmenu 60 | 61 | //Print current time 62 | time_t unixTime = time(NULL); 63 | struct tm* timeStruct = gmtime((const time_t *)&unixTime); 64 | 65 | int hours = timeStruct->tm_hour; 66 | int minutes = timeStruct->tm_min; 67 | int seconds = timeStruct->tm_sec; 68 | int day = timeStruct->tm_mday; 69 | int month = timeStruct->tm_mon; 70 | int year = timeStruct->tm_year +1900; 71 | 72 | printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds); 73 | printf("\n%s %s %i %i", weekDays[getDayOfWeek(day, month, year)], months[month], day, year); 74 | 75 | // Flush and swap framebuffers 76 | gfxFlushBuffers(); 77 | gfxSwapBuffers(); 78 | 79 | //Wait for VBlank 80 | gspWaitForVBlank(); 81 | } 82 | 83 | // Exit services 84 | gfxExit(); 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/custom-font/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include <3ds.h> 5 | #include 6 | 7 | C2D_TextBuf g_staticBuf; 8 | C2D_Text g_staticText[3]; 9 | C2D_Font font[3]; 10 | 11 | static void sceneInit(void) 12 | { 13 | g_staticBuf = C2D_TextBufNew(4096); // support up to 4096 glyphs in the buffer 14 | font[0] = C2D_FontLoadSystem(CFG_REGION_USA); 15 | font[1] = C2D_FontLoadSystem(CFG_REGION_KOR); 16 | font[2] = C2D_FontLoad("romfs:/liberationitalic.bcfnt"); 17 | 18 | // Parse the text strings 19 | // Loads system font 20 | C2D_TextFontParse(&g_staticText[0], font[0], g_staticBuf, "A boring system font."); 21 | // Uses loaded font 22 | C2D_TextFontParse(&g_staticText[1], font[1], g_staticBuf, "이 텍스트는 한국어입니다."); 23 | // Uses other loaded font 24 | C2D_TextFontParse(&g_staticText[2], font[2], g_staticBuf, "Wow, this is interesting."); 25 | 26 | // Optimize the text strings 27 | C2D_TextOptimize(&g_staticText[0]); 28 | C2D_TextOptimize(&g_staticText[1]); 29 | C2D_TextOptimize(&g_staticText[2]); 30 | } 31 | 32 | static void sceneRender(float size) 33 | { 34 | // Draw static text strings 35 | float text2PosX = 400.0f - 16.0f - g_staticText[2].width*0.75f; // right-justify 36 | C2D_DrawText(&g_staticText[0], 0, 8.0f, 8.0f, 0.5f, size, size); 37 | C2D_DrawText(&g_staticText[1], C2D_AtBaseline, 108.0f, 36.0f, 0.5f, size, size); 38 | C2D_DrawText(&g_staticText[2], C2D_AtBaseline, text2PosX, 210.0f, 0.5f, size, size); 39 | } 40 | 41 | static void sceneExit(void) 42 | { 43 | // Delete the text buffers 44 | C2D_TextBufDelete(g_staticBuf); 45 | C2D_FontFree(font[0]); 46 | C2D_FontFree(font[1]); 47 | C2D_FontFree(font[2]); 48 | } 49 | 50 | int main() 51 | { 52 | romfsInit(); 53 | cfguInit(); // Allow C2D_FontLoadSystem to work 54 | // Initialize the libs 55 | gfxInitDefault(); 56 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 57 | C2D_Init(C2D_DEFAULT_MAX_OBJECTS); 58 | C2D_Prepare(); 59 | 60 | // Create screen 61 | C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); 62 | 63 | // Initialize the scene 64 | sceneInit(); 65 | 66 | float size = 0.5f; 67 | 68 | // Main loop 69 | while (aptMainLoop()) 70 | { 71 | hidScanInput(); 72 | 73 | // Respond to user input 74 | u32 kDown = hidKeysDown(); 75 | if (kDown & KEY_START) 76 | break; // break in order to return to hbmenu 77 | 78 | // Render the scene 79 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 80 | C2D_TargetClear(top, C2D_Color32(0x68, 0xB0, 0xD8, 0xFF)); 81 | C2D_SceneBegin(top); 82 | sceneRender(size); 83 | C3D_FrameEnd(0); 84 | } 85 | 86 | // Deinitialize the scene 87 | sceneExit(); 88 | 89 | // Deinitialize the libs 90 | C2D_Fini(); 91 | C3D_Fini(); 92 | romfsExit(); 93 | cfguExit(); 94 | gfxExit(); 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/mic/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include <3ds.h> 6 | 7 | int main() 8 | { 9 | gfxInitDefault(); 10 | consoleInit(GFX_BOTTOM, NULL); 11 | 12 | bool initialized = true; 13 | 14 | u32 micbuf_size = 0x30000; 15 | u32 micbuf_pos = 0; 16 | u8* micbuf = memalign(0x1000, micbuf_size); 17 | 18 | printf("Initializing CSND...\n"); 19 | if(R_FAILED(csndInit())) 20 | { 21 | initialized = false; 22 | printf("Could not initialize CSND.\n"); 23 | } else printf("CSND initialized.\n"); 24 | 25 | printf("Initializing MIC...\n"); 26 | if(R_FAILED(micInit(micbuf, micbuf_size))) 27 | { 28 | initialized = false; 29 | printf("Could not initialize MIC.\n"); 30 | } else printf("MIC initialized.\n"); 31 | 32 | u32 micbuf_datasize = micGetSampleDataSize(); 33 | 34 | u32 audiobuf_size = 0x100000; 35 | u32 audiobuf_pos = 0; 36 | u8* audiobuf = linearAlloc(audiobuf_size); 37 | 38 | if(initialized) printf("Hold A to record, release to play.\n"); 39 | printf("Press START to exit.\n"); 40 | 41 | while(aptMainLoop()) 42 | { 43 | hidScanInput(); 44 | gspWaitForVBlank(); 45 | 46 | u32 kDown = hidKeysDown(); 47 | if (kDown & KEY_START) 48 | break; // break in order to return to hbmenu 49 | 50 | if(initialized) 51 | { 52 | if(kDown & KEY_A) 53 | { 54 | audiobuf_pos = 0; 55 | micbuf_pos = 0; 56 | 57 | printf("Stopping audio playback...\n"); 58 | CSND_SetPlayState(0x8, 0); 59 | if(R_FAILED(CSND_UpdateInfo(0))) printf("Failed to stop audio playback.\n"); 60 | 61 | printf("Starting sampling...\n"); 62 | if(R_SUCCEEDED(MICU_StartSampling(MICU_ENCODING_PCM16_SIGNED, MICU_SAMPLE_RATE_16360, 0, micbuf_datasize, true))) printf("Now recording.\n"); 63 | else printf("Failed to start sampling.\n"); 64 | } 65 | 66 | if((hidKeysHeld() & KEY_A) && audiobuf_pos < audiobuf_size) 67 | { 68 | u32 micbuf_readpos = micbuf_pos; 69 | micbuf_pos = micGetLastSampleOffset(); 70 | while(audiobuf_pos < audiobuf_size && micbuf_readpos != micbuf_pos) 71 | { 72 | audiobuf[audiobuf_pos] = micbuf[micbuf_readpos]; 73 | audiobuf_pos++; 74 | micbuf_readpos = (micbuf_readpos + 1) % micbuf_datasize; 75 | } 76 | } 77 | 78 | if(hidKeysUp() & KEY_A) 79 | { 80 | printf("Stoping sampling...\n"); 81 | if(R_FAILED(MICU_StopSampling())) printf("Failed to stop sampling.\n"); 82 | 83 | printf("Starting audio playback...\n"); 84 | if(R_SUCCEEDED(GSPGPU_FlushDataCache(audiobuf, audiobuf_pos)) && R_SUCCEEDED(csndPlaySound(0x8, SOUND_ONE_SHOT | SOUND_FORMAT_16BIT, 16360, 1.0, 0.0, (u32*)audiobuf, NULL, audiobuf_pos))) printf("Now playing.\n"); 85 | else printf("Failed to start playback.\n"); 86 | } 87 | } 88 | 89 | gfxFlushBuffers(); 90 | gfxSwapBuffers(); 91 | } 92 | 93 | linearFree(audiobuf); 94 | 95 | micExit(); 96 | free(micbuf); 97 | 98 | csndExit(); 99 | gfxExit(); 100 | return 0; 101 | } 102 | 103 | -------------------------------------------------------------------------------- /3ds-examples-master/network/3dslink-demo/source/3dslink-demo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include <3ds.h> 18 | 19 | #define SOC_ALIGN 0x1000 20 | #define SOC_BUFFERSIZE 0x100000 21 | 22 | static u32 *SOC_buffer = NULL; 23 | s32 sock = -1, csock = -1; 24 | 25 | __attribute__((format(printf,1,2))) 26 | void failExit(const char *fmt, ...); 27 | 28 | 29 | //--------------------------------------------------------------------------------- 30 | void socShutdown() { 31 | //--------------------------------------------------------------------------------- 32 | printf("waiting for socExit...\n"); 33 | socExit(); 34 | 35 | } 36 | 37 | //--------------------------------------------------------------------------------- 38 | int main(int argc, char **argv) { 39 | //--------------------------------------------------------------------------------- 40 | int ret; 41 | 42 | gfxInitDefault(); 43 | 44 | // register gfxExit to be run when app quits 45 | // this can help simplify error handling 46 | atexit(gfxExit); 47 | 48 | consoleInit(GFX_TOP, NULL); 49 | 50 | printf ("\nlibctru 3dslink demo\n\n"); 51 | 52 | printf ("\nstart 3dslink with -s to see printf output on host\n\n"); 53 | 54 | // allocate buffer for SOC service 55 | SOC_buffer = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE); 56 | 57 | if(SOC_buffer == NULL) { 58 | failExit("memalign: failed to allocate\n"); 59 | } 60 | 61 | // Now intialise soc:u service 62 | if ((ret = socInit(SOC_buffer, SOC_BUFFERSIZE)) != 0) { 63 | failExit("socInit: 0x%08X\n", (unsigned int)ret); 64 | } 65 | 66 | // register socShutdown to run at exit 67 | // atexit functions execute in reverse order so this runs before gfxExit 68 | atexit(socShutdown); 69 | 70 | 71 | link3dsStdio(); 72 | 73 | printf("Hello World!\n"); 74 | 75 | while (aptMainLoop()) { 76 | gspWaitForVBlank(); 77 | hidScanInput(); 78 | 79 | u32 kDown = hidKeysDown(); 80 | if (kDown & KEY_START) break; 81 | if (kDown & KEY_A) { 82 | printf("Pressed A!\n"); 83 | } 84 | if (kDown & KEY_B) { 85 | printf("Pressed B!\n"); 86 | } 87 | } 88 | 89 | close(sock); 90 | 91 | return 0; 92 | } 93 | 94 | //--------------------------------------------------------------------------------- 95 | void failExit(const char *fmt, ...) { 96 | //--------------------------------------------------------------------------------- 97 | 98 | if(sock>0) close(sock); 99 | if(csock>0) close(csock); 100 | 101 | va_list ap; 102 | 103 | printf(CONSOLE_RED); 104 | va_start(ap, fmt); 105 | vprintf(fmt, ap); 106 | va_end(ap); 107 | printf(CONSOLE_RESET); 108 | printf("\nPress B to exit\n"); 109 | 110 | while (aptMainLoop()) { 111 | gspWaitForVBlank(); 112 | hidScanInput(); 113 | 114 | u32 kDown = hidKeysDown(); 115 | if (kDown & KEY_B) exit(0); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /3ds-examples-master/mii_selector/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | gfxInitDefault(); 7 | consoleInit(GFX_TOP, NULL); 8 | 9 | printf("Mii selector demo.\n"); 10 | printf("Press A to bring up Mii selector with default settings.\n"); 11 | printf("Press B to bring up Mii selector with custom settings.\n"); 12 | printf("Press START to exit.\n"); 13 | 14 | while (aptMainLoop()) 15 | { 16 | hidScanInput(); 17 | 18 | u32 kDown = hidKeysDown(); 19 | 20 | if (kDown & KEY_START) 21 | break; 22 | 23 | bool didit = false; 24 | static MiiSelectorConf msConf; 25 | static MiiSelectorReturn msRet; 26 | static char miiname[36]; 27 | static char miiauthor[30]; 28 | 29 | if (kDown & KEY_A) 30 | { 31 | didit = true; 32 | // Ensure that the config is initalized and that all 33 | // defaults are set properly. (failing to do this to a new 34 | // MiiSelecorConf at least once before launching the miiSelector 35 | // can result in undefined behavior) 36 | miiSelectorInit(&msConf); 37 | miiSelectorLaunch(&msConf, &msRet); 38 | } 39 | 40 | if (kDown & KEY_B) 41 | { 42 | didit = true; 43 | miiSelectorInit(&msConf); 44 | // Sets title of Mii selector. 45 | miiSelectorSetTitle(&msConf, "This is a custom title!"); 46 | // Choose and option to enable. Any options not listed will be disabled. 47 | // 0 can be used to select no option. 48 | miiSelectorSetOptions(&msConf, MIISELECTOR_CANCEL|MIISELECTOR_GUESTS|MIISELECTOR_TOP|MIISELECTOR_GUESTSTART); 49 | // Start on the Mii with the database index of 1. 50 | // This is a guest Mii since the option MIISELECTOR_GUESTSTART is enabled. 51 | // If MIISELECTOR_GUESTSTART was not enabled, this would be a user Mii. 52 | miiSelectorSetInitialIndex(&msConf, 1); 53 | // Blacklist main user Mii 54 | miiSelectorBlacklistUserMii(&msConf, 0); 55 | miiSelectorLaunch(&msConf, &msRet); 56 | } 57 | 58 | if (didit) 59 | { 60 | // Check that the data in the miiSelector return buffer 61 | // is correct. 62 | if (miiSelectorChecksumIsValid(&msRet)) 63 | { 64 | if (!msRet.no_mii_selected) 65 | { 66 | printf("A Mii was selected.\n"); 67 | miiSelectorReturnGetName(&msRet, miiname, sizeof(miiname)); 68 | miiSelectorReturnGetAuthor(&msRet, miiauthor, sizeof(miiauthor)); 69 | printf("Name: %s\n", miiname); 70 | printf("Author: %s\n", miiauthor); 71 | printf("Birthday: Month-%d/Day-%d\n", msRet.mii.mii_details.bday_month, msRet.mii.mii_details.bday_day); 72 | printf("Sex: %d\n", msRet.mii.mii_details.sex); 73 | printf("Color: %d\n", msRet.mii.mii_details.shirt_color); 74 | printf("Favorite: %d\n", msRet.mii.mii_details.favorite); 75 | // Keep in mind that not all things align with their order in Mii Maker. 76 | // https://www.3dbrew.org/wiki/Mii#Mii_values 77 | printf("Eyebrow: %d\n", msRet.mii.eyebrow_details.style); 78 | printf("Eyebrow color: %d\n", msRet.mii.eyebrow_details.color); 79 | printf("Nose: %d\n", msRet.mii.nose_details.style); 80 | } else 81 | printf("No Mii was selected.\n"); 82 | } else 83 | printf("Return checksum invalid.\n"); 84 | } 85 | 86 | // Flush and swap framebuffers 87 | gfxFlushBuffers(); 88 | gfxSwapBuffers(); 89 | 90 | gspWaitForVBlank(); 91 | } 92 | 93 | gfxExit(); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/2d_shapes/source/main.c: -------------------------------------------------------------------------------- 1 | // Simple citro2d untextured shape example 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #define SCREEN_WIDTH 400 10 | #define SCREEN_HEIGHT 240 11 | 12 | //--------------------------------------------------------------------------------- 13 | int main(int argc, char* argv[]) { 14 | //--------------------------------------------------------------------------------- 15 | // Init libs 16 | gfxInitDefault(); 17 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 18 | C2D_Init(C2D_DEFAULT_MAX_OBJECTS); 19 | C2D_Prepare(); 20 | consoleInit(GFX_BOTTOM, NULL); 21 | 22 | // Create screens 23 | C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); 24 | 25 | // Create colors 26 | u32 clrWhite = C2D_Color32(0xFF, 0xFF, 0xFF, 0xFF); 27 | u32 clrGreen = C2D_Color32(0x00, 0xFF, 0x00, 0xFF); 28 | u32 clrRed = C2D_Color32(0xFF, 0x00, 0x00, 0xFF); 29 | u32 clrBlue = C2D_Color32(0x00, 0x00, 0xFF, 0xFF); 30 | 31 | u32 clrCircle1 = C2D_Color32(0xFF, 0x00, 0xFF, 0xFF); 32 | u32 clrCircle2 = C2D_Color32(0xFF, 0xFF, 0x00, 0xFF); 33 | u32 clrCircle3 = C2D_Color32(0x00, 0xFF, 0xFF, 0xFF); 34 | 35 | u32 clrSolidCircle = C2D_Color32(0x68, 0xB0, 0xD8, 0xFF); 36 | 37 | u32 clrTri1 = C2D_Color32(0xFF, 0x15, 0x00, 0xFF); 38 | u32 clrTri2 = C2D_Color32(0x27, 0x69, 0xE5, 0xFF); 39 | 40 | u32 clrRec1 = C2D_Color32(0x9A, 0x6C, 0xB9, 0xFF); 41 | u32 clrRec2 = C2D_Color32(0xFF, 0xFF, 0x2C, 0xFF); 42 | u32 clrRec3 = C2D_Color32(0xD8, 0xF6, 0x0F, 0xFF); 43 | u32 clrRec4 = C2D_Color32(0x40, 0xEA, 0x87, 0xFF); 44 | 45 | u32 clrClear = C2D_Color32(0xFF, 0xD8, 0xB0, 0x68); 46 | 47 | // Main loop 48 | while (aptMainLoop()) 49 | { 50 | hidScanInput(); 51 | 52 | // Respond to user input 53 | u32 kDown = hidKeysDown(); 54 | if (kDown & KEY_START) 55 | break; // break in order to return to hbmenu 56 | printf("\x1b[1;1HSimple citro2d shapes example"); 57 | printf("\x1b[2;1HCPU: %6.2f%%\x1b[K", C3D_GetProcessingTime()*6.0f); 58 | printf("\x1b[3;1HGPU: %6.2f%%\x1b[K", C3D_GetDrawingTime()*6.0f); 59 | printf("\x1b[4;1HCmdBuf: %6.2f%%\x1b[K", C3D_GetCmdBufUsage()*100.0f); 60 | 61 | // Render the scene 62 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 63 | C2D_TargetClear(top, clrClear); 64 | C2D_SceneBegin(top); 65 | 66 | C2D_DrawTriangle(50 / 2, SCREEN_HEIGHT - 50, clrWhite, 67 | 0, SCREEN_HEIGHT, clrTri1, 68 | 50, SCREEN_HEIGHT, clrTri2, 0); 69 | C2D_DrawRectangle(SCREEN_WIDTH - 50, 0, 0, 50, 50, clrRec1, clrRec2, clrRec3, clrRec4); 70 | 71 | // Circles require a state change (an expensive operation) within citro2d's internals, so draw them last. 72 | // Although it is possible to draw them in the middle of drawing non-circular objects 73 | // (sprites, images, triangles, rectangles, etc.) this is not recommended. They should either 74 | // be drawn before all non-circular objects, or afterwards. 75 | C2D_DrawEllipse(0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, clrCircle1, clrCircle2, clrCircle3, clrWhite); 76 | C2D_DrawCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0, 50, clrCircle3, clrWhite, clrCircle1, clrCircle2); 77 | C2D_DrawCircle(25, 25, 0, 25, 78 | clrRed, clrBlue, clrGreen, clrWhite); 79 | C2D_DrawCircleSolid(SCREEN_WIDTH - 25, SCREEN_HEIGHT - 25, 0, 25, clrSolidCircle); 80 | C3D_FrameEnd(0); 81 | } 82 | 83 | // Deinit libs 84 | C2D_Fini(); 85 | C3D_Fini(); 86 | gfxExit(); 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/streaming/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include <3ds.h> 7 | 8 | #define SAMPLERATE 22050 9 | #define SAMPLESPERBUF (SAMPLERATE / 30) 10 | #define BYTESPERSAMPLE 4 11 | 12 | //---------------------------------------------------------------------------- 13 | void fill_buffer(void *audioBuffer,size_t offset, size_t size, int frequency ) { 14 | //---------------------------------------------------------------------------- 15 | 16 | u32 *dest = (u32*)audioBuffer; 17 | 18 | for (int i=0; i (sizeof(notefreq)/sizeof(notefreq[0])-1)) note = 0; 108 | } 109 | 110 | if (waveBuf[fillBlock].status == NDSP_WBUF_DONE) { 111 | 112 | fill_buffer(waveBuf[fillBlock].data_pcm16, stream_offset, waveBuf[fillBlock].nsamples,notefreq[note]); 113 | 114 | ndspChnWaveBufAdd(0, &waveBuf[fillBlock]); 115 | stream_offset += waveBuf[fillBlock].nsamples; 116 | 117 | fillBlock = !fillBlock; 118 | } 119 | } 120 | 121 | ndspExit(); 122 | 123 | linearFree(audioBuffer); 124 | 125 | gfxExit(); 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /3ds-examples-master/sdmc/source/costable.c: -------------------------------------------------------------------------------- 1 | #include <3ds/types.h> 2 | 3 | s32 costable[] = { 4096, 4095, 4094, 4093, 4091, 4088, 4084, 4080, 4076, 4071, 4065, 4 | 4058, 4051, 4044, 4035, 4026, 4017, 4007, 3996, 3985, 3973, 3960, 5 | 3947, 3934, 3919, 3904, 3889, 3873, 3856, 3839, 3821, 3803, 3784, 6 | 3765, 3744, 3724, 3703, 3681, 3659, 3636, 3612, 3588, 3564, 3539, 7 | 3513, 3487, 3461, 3434, 3406, 3378, 3349, 3320, 3290, 3260, 3229, 8 | 3198, 3167, 3135, 3102, 3069, 3035, 3002, 2967, 2932, 2897, 2861, 9 | 2825, 2788, 2751, 2714, 2676, 2638, 2599, 2560, 2521, 2481, 2441, 10 | 2401, 2360, 2318, 2277, 2235, 2193, 2150, 2107, 2064, 2020, 1976, 11 | 1932, 1888, 1843, 1798, 1753, 1707, 1662, 1616, 1569, 1523, 1476, 12 | 1429, 1382, 1334, 1287, 1239, 1191, 1143, 1095, 1046, 997, 949, 13 | 900, 851, 801, 752, 703, 653, 603, 554, 504, 454, 404, 354, 304, 14 | 254, 204, 153, 103, 53, 3, -46, -97, -147, -197, -247, -297, -347, 15 | -398, -448, -497, -547, -597, -647, -696, -746, -795, -844, -893, 16 | -942, -991, -1040, -1088, -1137, -1185, -1233, -1281, -1328, -1376, 17 | -1423, -1470, -1517, -1563, -1610, -1656, -1701, -1747, -1792, -1837, 18 | -1882, -1927, -1971, -2015, -2058, -2102, -2144, -2187, -2229, -2271, 19 | -2313, -2354, -2395, -2436, -2476, -2516, -2555, -2594, -2633, -2671, 20 | -2709, -2747, -2784, -2820, -2857, -2892, -2928, -2963, -2997, -3031, 21 | -3065, -3098, -3130, -3163, -3194, -3225, -3256, -3286, -3316, -3345, 22 | -3374, -3402, -3430, -3457, -3484, -3510, -3536, -3561, -3585, -3609, 23 | -3633, -3656, -3678, -3700, -3721, -3742, -3762, -3782, -3801, -3819, 24 | -3837, -3854, -3871, -3887, -3902, -3917, -3932, -3946, -3959, -3971, 25 | -3983, -3995, -4005, -4016, -4025, -4034, -4042, -4050, -4057, -4064, 26 | -4070, -4075, -4080, -4084, -4087, -4090, -4092, -4094, -4095, -4095, 27 | -4095, -4094, -4093, -4091, -4088, -4085, -4081, -4076, -4071, -4066, 28 | -4059, -4052, -4045, -4036, -4028, -4018, -4008, -3997, -3986, -3974, 29 | -3962, -3949, -3935, -3921, -3906, -3891, -3875, -3858, -3841, -3824, 30 | -3805, -3787, -3767, -3747, -3727, -3705, -3684, -3662, -3639, -3615, 31 | -3592, -3567, -3542, -3517, -3491, -3464, -3437, -3409, -3381, -3353, 32 | -3324, -3294, -3264, -3233, -3202, -3171, -3139, -3106, -3073, -3040, 33 | -3006, -2972, -2937, -2902, -2866, -2830, -2793, -2756, -2719, -2681, 34 | -2643, -2604, -2565, -2526, -2486, -2446, -2406, -2365, -2324, -2282, 35 | -2240, -2198, -2156, -2113, -2069, -2026, -1982, -1938, -1894, -1849, 36 | -1804, -1759, -1713, -1668, -1622, -1575, -1529, -1482, -1435, -1388, 37 | -1341, -1293, -1245, -1197, -1149, -1101, -1052, -1004, -955, -906, 38 | -857, -808, -758, -709, -660, -610, -560, -510, -460, -411, -360, 39 | -310, -260, -210, -160, -110, -60, -9, 40, 90, 140, 191, 241, 291, 40 | 341, 391, 441, 491, 541, 591, 640, 690, 739, 789, 838, 887, 936, 41 | 985, 1033, 1082, 1130, 1179, 1227, 1274, 1322, 1370, 1417, 1464, 42 | 1511, 1557, 1604, 1650, 1695, 1741, 1786, 1831, 1876, 1921, 1965, 43 | 2009, 2053, 2096, 2139, 2182, 2224, 2266, 2308, 2349, 2390, 2431, 44 | 2471, 2511, 2550, 2589, 2628, 2666, 2704, 2742, 2779, 2816, 2852, 45 | 2888, 2923, 2958, 2993, 3027, 3060, 3093, 3126, 3158, 3190, 3221, 46 | 3252, 3282, 3312, 3342, 3370, 3399, 3426, 3454, 3480, 3507, 3532, 47 | 3557, 3582, 3606, 3630, 3653, 3675, 3697, 3718, 3739, 3759, 3779, 48 | 3798, 3817, 3835, 3852, 3869, 3885, 3900, 3915, 3930, 3944, 3957, 49 | 3970, 3982, 3993, 4004, 4014, 4024, 4033, 4041, 4049, 4056, 4063, 50 | 4069, 4074, 4079, 4083, 4087, 4090, 4092, 4094, 4095}; 51 | -------------------------------------------------------------------------------- /3ds-examples-master/input/read-controls/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Circle Pad example made by Aurelio Mannara for libctru 3 | Please refer to https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/hid.h for more information 4 | This code was modified for the last time on: 12/13/2014 2:20 UTC+1 5 | 6 | This wouldn't be possible without the amazing work done by: 7 | -Smealum 8 | -fincs 9 | -WinterMute 10 | -yellows8 11 | -plutoo 12 | -mtheall 13 | -Many others who worked on 3DS and I'm surely forgetting about 14 | */ 15 | 16 | #include <3ds.h> 17 | #include 18 | 19 | int main(int argc, char **argv) 20 | { 21 | //Matrix containing the name of each key. Useful for printing when a key is pressed 22 | char keysNames[32][32] = { 23 | "KEY_A", "KEY_B", "KEY_SELECT", "KEY_START", 24 | "KEY_DRIGHT", "KEY_DLEFT", "KEY_DUP", "KEY_DDOWN", 25 | "KEY_R", "KEY_L", "KEY_X", "KEY_Y", 26 | "", "", "KEY_ZL", "KEY_ZR", 27 | "", "", "", "", 28 | "KEY_TOUCH", "", "", "", 29 | "KEY_CSTICK_RIGHT", "KEY_CSTICK_LEFT", "KEY_CSTICK_UP", "KEY_CSTICK_DOWN", 30 | "KEY_CPAD_RIGHT", "KEY_CPAD_LEFT", "KEY_CPAD_UP", "KEY_CPAD_DOWN" 31 | }; 32 | 33 | // Initialize services 34 | gfxInitDefault(); 35 | 36 | //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one 37 | consoleInit(GFX_TOP, NULL); 38 | 39 | u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame 40 | 41 | printf("\x1b[1;1HPress Start to exit."); 42 | printf("\x1b[2;1HCirclePad position:"); 43 | 44 | // Main loop 45 | while (aptMainLoop()) 46 | { 47 | //Scan all the inputs. This should be done once for each frame 48 | hidScanInput(); 49 | 50 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 51 | u32 kDown = hidKeysDown(); 52 | //hidKeysHeld returns information about which buttons have are held down in this frame 53 | u32 kHeld = hidKeysHeld(); 54 | //hidKeysUp returns information about which buttons have been just released 55 | u32 kUp = hidKeysUp(); 56 | 57 | if (kDown & KEY_START) break; // break in order to return to hbmenu 58 | 59 | //Do the keys printing only if keys have changed 60 | if (kDown != kDownOld || kHeld != kHeldOld || kUp != kUpOld) 61 | { 62 | //Clear console 63 | consoleClear(); 64 | 65 | //These two lines must be rewritten because we cleared the whole console 66 | printf("\x1b[1;1HPress Start to exit."); 67 | printf("\x1b[2;1HCirclePad position:"); 68 | 69 | printf("\x1b[4;1H"); //Move the cursor to the fourth row because on the third one we'll write the circle pad position 70 | 71 | //Check if some of the keys are down, held or up 72 | int i; 73 | for (i = 0; i < 32; i++) 74 | { 75 | if (kDown & BIT(i)) printf("%s down\n", keysNames[i]); 76 | if (kHeld & BIT(i)) printf("%s held\n", keysNames[i]); 77 | if (kUp & BIT(i)) printf("%s up\n", keysNames[i]); 78 | } 79 | } 80 | 81 | //Set keys old values for the next frame 82 | kDownOld = kDown; 83 | kHeldOld = kHeld; 84 | kUpOld = kUp; 85 | 86 | circlePosition pos; 87 | 88 | //Read the CirclePad position 89 | hidCircleRead(&pos); 90 | 91 | //Print the CirclePad position 92 | printf("\x1b[3;1H%04d; %04d", pos.dx, pos.dy); 93 | 94 | // Flush and swap framebuffers 95 | gfxFlushBuffers(); 96 | gfxSwapBuffers(); 97 | 98 | //Wait for VBlank 99 | gspWaitForVBlank(); 100 | } 101 | 102 | // Exit services 103 | gfxExit(); 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/immediate/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "vshader_shbin.h" 5 | 6 | #define CLEAR_COLOR 0x68B0D8FF 7 | 8 | #define DISPLAY_TRANSFER_FLAGS \ 9 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 10 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 11 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 12 | 13 | static DVLB_s* vshader_dvlb; 14 | static shaderProgram_s program; 15 | static int uLoc_projection; 16 | static C3D_Mtx projection; 17 | 18 | static void sceneInit(void) 19 | { 20 | // Load the vertex shader, create a shader program and bind it 21 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 22 | shaderProgramInit(&program); 23 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 24 | C3D_BindProgram(&program); 25 | 26 | // Get the location of the uniforms 27 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 28 | 29 | // Configure attributes for use with the vertex shader 30 | // Attribute format and element count are ignored in immediate mode 31 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 32 | AttrInfo_Init(attrInfo); 33 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 34 | AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=color 35 | 36 | // Compute the projection matrix 37 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); 38 | 39 | // Configure the first fragment shading substage to just pass through the vertex color 40 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 41 | C3D_TexEnv* env = C3D_GetTexEnv(0); 42 | C3D_TexEnvInit(env); 43 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 44 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 45 | } 46 | 47 | static void sceneRender(void) 48 | { 49 | // Update the uniforms 50 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); 51 | 52 | // Draw the triangle directly 53 | C3D_ImmDrawBegin(GPU_TRIANGLES); 54 | C3D_ImmSendAttrib(200.0f, 200.0f, 0.5f, 0.0f); // v0=position 55 | C3D_ImmSendAttrib(1.0f, 0.0f, 0.0f, 1.0f); // v1=color 56 | 57 | C3D_ImmSendAttrib(100.0f, 40.0f, 0.5f, 0.0f); 58 | C3D_ImmSendAttrib(0.0f, 1.0f, 0.0f, 1.0f); 59 | 60 | C3D_ImmSendAttrib(300.0f, 40.0f, 0.5f, 0.0f); 61 | C3D_ImmSendAttrib(0.0f, 0.0f, 1.0f, 1.0f); 62 | C3D_ImmDrawEnd(); 63 | } 64 | 65 | static void sceneExit(void) 66 | { 67 | // Free the shader program 68 | shaderProgramFree(&program); 69 | DVLB_Free(vshader_dvlb); 70 | } 71 | 72 | int main() 73 | { 74 | // Initialize graphics 75 | gfxInitDefault(); 76 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 77 | 78 | // Initialize the render target 79 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 80 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 81 | 82 | // Initialize the scene 83 | sceneInit(); 84 | 85 | // Main loop 86 | while (aptMainLoop()) 87 | { 88 | hidScanInput(); 89 | 90 | // Respond to user input 91 | u32 kDown = hidKeysDown(); 92 | if (kDown & KEY_START) 93 | break; // break in order to return to hbmenu 94 | 95 | // Render the scene 96 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 97 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 98 | C3D_FrameDrawOn(target); 99 | sceneRender(); 100 | C3D_FrameEnd(0); 101 | } 102 | 103 | // Deinitialize the scene 104 | sceneExit(); 105 | 106 | // Deinitialize graphics 107 | C3D_Fini(); 108 | gfxExit(); 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/normal_mapping/source/vshader.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Uniforms 4 | .fvec projection[4], modelView[4] 5 | 6 | ; Constants 7 | .constf myconst(0.0, 1.0, 2.0, 0.5) 8 | .alias zeros myconst.xxxx ; Vector full of zeros 9 | .alias ones myconst.yyyy ; Vector full of ones 10 | .alias twos myconst.zzzz ; Vector full of twos 11 | .alias half myconst.wwww 12 | 13 | ; Outputs 14 | .out outpos position 15 | .out outtc0 texcoord0 16 | .out outtc1 texcoord1 17 | .out outclr color 18 | .out outview view 19 | .out outnq normalquat 20 | 21 | ; Inputs (defined as aliases for convenience) 22 | .alias inpos v0 23 | .alias intex v1 24 | .alias innrm v2 25 | .alias intng v3 26 | 27 | .proc main 28 | ; Force the w component of inpos to be 1.0 29 | mov r0.xyz, inpos 30 | mov r0.w, ones 31 | 32 | ; r1 = modelView * inpos 33 | dp4 r1.x, modelView[0], r0 34 | dp4 r1.y, modelView[1], r0 35 | dp4 r1.z, modelView[2], r0 36 | dp4 r1.w, modelView[3], r0 37 | 38 | ; outview = -r1 39 | mov outview, -r1 40 | 41 | ; outpos = projection * r1 42 | dp4 outpos.x, projection[0], r1 43 | dp4 outpos.y, projection[1], r1 44 | dp4 outpos.z, projection[2], r1 45 | dp4 outpos.w, projection[3], r1 46 | 47 | ; outtex = intex 48 | mov outtc0, intex 49 | mov outtc1, intex 50 | 51 | ; Transform the normal and tangent vector with the modelView matrix 52 | ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView 53 | ; Trick: Assuming N and T are both unitary when they come in, after transformation 54 | ; they will both have the same modulus. We can shave off one extra dp3/rsq 55 | dp3 r14.x, modelView[0], innrm 56 | dp3 r14.y, modelView[1], innrm 57 | dp3 r14.z, modelView[2], innrm 58 | dp3 r12.x, modelView[0], intng 59 | dp3 r12.y, modelView[1], intng 60 | dp3 r12.z, modelView[2], intng 61 | dp3 r6.x, r14, r14 62 | rsq r6.x, r6.x 63 | mul r14.xyz, r14.xyz, r6.x 64 | mul r12.xyz, r12.xyz, r6.x 65 | 66 | ; Cross N x T = B 67 | mul r13.xyz, r14.yzx, r12.zxy 68 | mad r13.xyz, -r12.yzx, r14.zxy, r13 69 | 70 | ; Cross B x N = T (for ensuring orthonormalization) 71 | mul r12.xyz, r13.yzx, r14.zxy 72 | mad r12.xyz, -r14.yzx, r13.zxy, r12 73 | 74 | ; Readjust vectors for easier calculation: 75 | ; r12 = (Tx, Ty, Tz, Bz) 76 | ; r13 = (Tx, By, Nz, 1 ) 77 | ; r14 = (Nx, Ny, Nz, Bx) 78 | mov r12.w, r13.z 79 | mov r14.w, r13.x 80 | mov r13.x, r12.x 81 | mov r13.z, r14.z 82 | mov r13.w, ones 83 | 84 | ; Perform case discrimination 85 | mov r11.z, zeros 86 | sge r10, zeros, r14.z 87 | mov r11.xyw, r13.zxzy 88 | add r10, r10, r10 89 | mad r11.y, r10, r11, -r11 90 | cmp r11.xy, le, ge, r11.zw 91 | 92 | ifc cmp.x 93 | ifc cmp.y 94 | ; X case 95 | ; x = 1 + Tx - By - Nz 96 | ; y = +Ty + Bx 97 | ; z = +Tz + Nx 98 | ; w = +Bz - Ny 99 | mov r13.yz, -r13 100 | mov r14.y, -r14 101 | dp4 r0.x, r13.w, r13 102 | add r0.yzw, r12.yyzw, r14.wwxy 103 | .else 104 | ; Y case 105 | ; x = +Ty + Bx 106 | ; y = 1 - Tx + By - Nz 107 | ; z = +Bz + Ny 108 | ; w = -Tz + Nx 109 | mov r13.xz, -r13 110 | mov r12.z, -r12 111 | dp4 r0.y, r13.w, r13 112 | add r0.xzw, r12.yywz, r14.wwyx 113 | .end 114 | .else 115 | ifc cmp.y 116 | ; Z case 117 | ; x = +Tz + Nx 118 | ; y = +Bz + Ny 119 | ; z = 1 - Tx - By + Nz 120 | ; w = +Ty - Bx 121 | mov r13.xy, -r13 122 | mov r14.w, -r14 123 | dp4 r0.z, r13.w, r13 124 | add r0.xyw, r12.zwwy, r14.xyyw 125 | .else 126 | ; W case 127 | ; x = +Bz - Ny 128 | ; y = -Tz + Nx 129 | ; z = +Ty - Bx 130 | ; w = 1 + Tx + By + Nz 131 | mov r12.z, -r12 132 | mov r14.yw, -r14 133 | dp4 r0.w, r13.w, r13 134 | add r0.xyz, r12.wzyy, r14.yxww 135 | .end 136 | .end 137 | 138 | ; Renormalize quaternion and output 139 | dp4 r1.x, r0, r0 140 | rsq r1.x, r1.x 141 | mul outnq, r0, r1.x 142 | 143 | ; Output color 144 | mov outclr, ones 145 | 146 | ; We're finished 147 | end 148 | .end 149 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/printing/system-font/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include <3ds.h> 5 | #include 6 | 7 | static const char teststring[] = 8 | "Hello World - now with citro2d!\n" 9 | "The quick brown fox jumps over the lazy dog.\n" 10 | "\n" 11 | "En français: Vous ne devez pas éteindre votre console.\n" 12 | "日本語文章を見せるのも出来ますよ。\n" 13 | "Un poco de texto en español nunca queda mal.\n" 14 | "Πού είναι η τουαλέτα;\n" 15 | "Я очень рад, ведь я, наконец, возвращаюсь домой\n"; 16 | 17 | C2D_TextBuf g_staticBuf, g_dynamicBuf; 18 | C2D_Text g_staticText[4]; 19 | 20 | static void sceneInit(void) 21 | { 22 | // Create two text buffers: one for static text, and another one for 23 | // dynamic text - the latter will be cleared at each frame. 24 | g_staticBuf = C2D_TextBufNew(4096); // support up to 4096 glyphs in the buffer 25 | g_dynamicBuf = C2D_TextBufNew(4096); 26 | 27 | // Parse the static text strings 28 | C2D_TextParse(&g_staticText[0], g_staticBuf, teststring); 29 | C2D_TextParse(&g_staticText[1], g_staticBuf, "I am red skinny text!"); 30 | C2D_TextParse(&g_staticText[2], g_staticBuf, "I am blue fat text!"); 31 | C2D_TextParse(&g_staticText[3], g_staticBuf, "I am justified text!"); 32 | 33 | // Optimize the static text strings 34 | C2D_TextOptimize(&g_staticText[0]); 35 | C2D_TextOptimize(&g_staticText[1]); 36 | C2D_TextOptimize(&g_staticText[2]); 37 | C2D_TextOptimize(&g_staticText[3]); 38 | } 39 | 40 | static void sceneRender(float size) 41 | { 42 | // Clear the dynamic text buffer 43 | C2D_TextBufClear(g_dynamicBuf); 44 | 45 | // Draw static text strings 46 | C2D_DrawText(&g_staticText[0], 0, 8.0f, 8.0f, 0.5f, size, size); 47 | C2D_DrawText(&g_staticText[1], C2D_AtBaseline | C2D_WithColor, 16.0f, 210.0f, 0.5f, 0.5f, 0.75f, C2D_Color32f(1.0f,0.0f,0.0f,1.0f)); 48 | C2D_DrawText(&g_staticText[2], C2D_AtBaseline | C2D_WithColor | C2D_AlignRight, 384.0f, 210.0f, 0.5f, 0.75f, 0.5f, C2D_Color32f(0.0f,0.0f,1.0f,0.625f)); 49 | C2D_DrawText(&g_staticText[3], C2D_AtBaseline | C2D_AlignJustified | C2D_WordWrap, 100.0f, 170.0f, 0.5f, 0.75f, 0.75f, 200.0f); 50 | 51 | // Generate and draw dynamic text 52 | char buf[160]; 53 | C2D_Text dynText; 54 | snprintf(buf, sizeof(buf), "Current text size: %f (Use  to change)", size); 55 | C2D_TextParse(&dynText, g_dynamicBuf, buf); 56 | C2D_TextOptimize(&dynText); 57 | C2D_DrawText(&dynText, C2D_AlignCenter, 200.0f, 220.0f, 0.5f, 0.5f, 0.5f); 58 | } 59 | 60 | static void sceneExit(void) 61 | { 62 | // Delete the text buffers 63 | C2D_TextBufDelete(g_dynamicBuf); 64 | C2D_TextBufDelete(g_staticBuf); 65 | } 66 | 67 | int main() 68 | { 69 | // Initialize the libs 70 | gfxInitDefault(); 71 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 72 | C2D_Init(C2D_DEFAULT_MAX_OBJECTS); 73 | C2D_Prepare(); 74 | 75 | // Create screen 76 | C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); 77 | 78 | // Initialize the scene 79 | sceneInit(); 80 | 81 | float size = 0.5f; 82 | 83 | // Main loop 84 | while (aptMainLoop()) 85 | { 86 | hidScanInput(); 87 | 88 | // Respond to user input 89 | u32 kDown = hidKeysDown(); 90 | u32 kHeld = hidKeysHeld(); 91 | if (kDown & KEY_START) 92 | break; // break in order to return to hbmenu 93 | 94 | if (kHeld & KEY_L) 95 | size -= 1.0f/128; 96 | else if (kHeld & KEY_R) 97 | size += 1.0f/128; 98 | else if (kHeld & KEY_X) 99 | size = 0.5f; 100 | else if (kHeld & KEY_Y) 101 | size = 1.0f; 102 | 103 | if (size < 0.25f) 104 | size = 0.25f; 105 | else if (size > 2.0f) 106 | size = 2.0f; 107 | 108 | // Render the scene 109 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 110 | C2D_TargetClear(top, C2D_Color32(0x68, 0xB0, 0xD8, 0xFF)); 111 | C2D_SceneBegin(top); 112 | sceneRender(size); 113 | C3D_FrameEnd(0); 114 | } 115 | 116 | // Deinitialize the scene 117 | sceneExit(); 118 | 119 | // Deinitialize the libs 120 | C2D_Fini(); 121 | C3D_Fini(); 122 | gfxExit(); 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/simple_tri/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "vshader_shbin.h" 5 | 6 | #define CLEAR_COLOR 0x68B0D8FF 7 | 8 | #define DISPLAY_TRANSFER_FLAGS \ 9 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 10 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 11 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 12 | 13 | typedef struct { float x, y, z; } vertex; 14 | 15 | static const vertex vertex_list[] = 16 | { 17 | { 200.0f, 200.0f, 0.5f }, 18 | { 100.0f, 40.0f, 0.5f }, 19 | { 300.0f, 40.0f, 0.5f }, 20 | }; 21 | 22 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 23 | 24 | static DVLB_s* vshader_dvlb; 25 | static shaderProgram_s program; 26 | static int uLoc_projection; 27 | static C3D_Mtx projection; 28 | 29 | static void* vbo_data; 30 | 31 | static void sceneInit(void) 32 | { 33 | // Load the vertex shader, create a shader program and bind it 34 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 35 | shaderProgramInit(&program); 36 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 37 | C3D_BindProgram(&program); 38 | 39 | // Get the location of the uniforms 40 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 41 | 42 | // Configure attributes for use with the vertex shader 43 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 44 | AttrInfo_Init(attrInfo); 45 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 46 | AttrInfo_AddFixed(attrInfo, 1); // v1=color 47 | 48 | // Set the fixed attribute (color) to solid white 49 | C3D_FixedAttribSet(1, 1.0, 1.0, 1.0, 1.0); 50 | 51 | // Compute the projection matrix 52 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); 53 | 54 | // Create the VBO (vertex buffer object) 55 | vbo_data = linearAlloc(sizeof(vertex_list)); 56 | memcpy(vbo_data, vertex_list, sizeof(vertex_list)); 57 | 58 | // Configure buffers 59 | C3D_BufInfo* bufInfo = C3D_GetBufInfo(); 60 | BufInfo_Init(bufInfo); 61 | BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 1, 0x0); 62 | 63 | // Configure the first fragment shading substage to just pass through the vertex color 64 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 65 | C3D_TexEnv* env = C3D_GetTexEnv(0); 66 | C3D_TexEnvInit(env); 67 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 68 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 69 | } 70 | 71 | static void sceneRender(void) 72 | { 73 | // Update the uniforms 74 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); 75 | 76 | // Draw the VBO 77 | C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); 78 | } 79 | 80 | static void sceneExit(void) 81 | { 82 | // Free the VBO 83 | linearFree(vbo_data); 84 | 85 | // Free the shader program 86 | shaderProgramFree(&program); 87 | DVLB_Free(vshader_dvlb); 88 | } 89 | 90 | int main() 91 | { 92 | // Initialize graphics 93 | gfxInitDefault(); 94 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 95 | 96 | // Initialize the render target 97 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 98 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 99 | 100 | // Initialize the scene 101 | sceneInit(); 102 | 103 | // Main loop 104 | while (aptMainLoop()) 105 | { 106 | hidScanInput(); 107 | 108 | // Respond to user input 109 | u32 kDown = hidKeysDown(); 110 | if (kDown & KEY_START) 111 | break; // break in order to return to hbmenu 112 | 113 | // Render the scene 114 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 115 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 116 | C3D_FrameDrawOn(target); 117 | sceneRender(); 118 | C3D_FrameEnd(0); 119 | } 120 | 121 | // Deinitialize the scene 122 | sceneExit(); 123 | 124 | // Deinitialize graphics 125 | C3D_Fini(); 126 | gfxExit(); 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/geoshader/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "program_shbin.h" 5 | 6 | #define CLEAR_COLOR 0x68B0D8FF 7 | 8 | #define DISPLAY_TRANSFER_FLAGS \ 9 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 10 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 11 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 12 | 13 | typedef struct { float position[3]; float color[4]; } vertex; 14 | 15 | static const vertex vertex_list[] = 16 | { 17 | { {200.0f, 200.0f, 0.5f}, {1.0f, 0.0f, 0.0f, 1.0f} }, 18 | { {100.0f, 40.0f, 0.5f}, {0.0f, 1.0f, 0.0f, 1.0f} }, 19 | { {300.0f, 40.0f, 0.5f}, {0.0f, 0.0f, 1.0f, 1.0f} }, 20 | }; 21 | 22 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 23 | 24 | static DVLB_s* program_dvlb; 25 | static shaderProgram_s program; 26 | static int uLoc_projection; 27 | static C3D_Mtx projection; 28 | 29 | static void* vbo_data; 30 | 31 | static void sceneInit(void) 32 | { 33 | // Load the shaders and create a shader program 34 | // The geoshader stride is set to 6 so that it processes a triangle at a time 35 | program_dvlb = DVLB_ParseFile((u32*)program_shbin, program_shbin_size); 36 | shaderProgramInit(&program); 37 | shaderProgramSetVsh(&program, &program_dvlb->DVLE[0]); 38 | shaderProgramSetGsh(&program, &program_dvlb->DVLE[1], 6); 39 | C3D_BindProgram(&program); 40 | 41 | // Get the location of the projection matrix uniform 42 | uLoc_projection = shaderInstanceGetUniformLocation(program.geometryShader, "projection"); 43 | 44 | // Configure attributes for use with the vertex shader 45 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 46 | AttrInfo_Init(attrInfo); 47 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 48 | AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 4); // v1=color 49 | 50 | // Compute the projection matrix 51 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); 52 | 53 | // Create the VBO (vertex buffer object) 54 | vbo_data = linearAlloc(sizeof(vertex_list)); 55 | memcpy(vbo_data, vertex_list, sizeof(vertex_list)); 56 | 57 | // Configure buffers 58 | C3D_BufInfo* bufInfo = C3D_GetBufInfo(); 59 | BufInfo_Init(bufInfo); 60 | BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 2, 0x10); 61 | 62 | // Configure the first fragment shading substage to just pass through the vertex color 63 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 64 | C3D_TexEnv* env = C3D_GetTexEnv(0); 65 | C3D_TexEnvInit(env); 66 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 67 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 68 | } 69 | 70 | static void sceneRender(void) 71 | { 72 | // Update the uniforms 73 | C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, uLoc_projection, &projection); 74 | 75 | // Draw the VBO - GPU_GEOMETRY_PRIM allows the geoshader to control primitive emission 76 | C3D_DrawArrays(GPU_GEOMETRY_PRIM, 0, vertex_list_count); 77 | } 78 | 79 | static void sceneExit(void) 80 | { 81 | // Free the VBO 82 | linearFree(vbo_data); 83 | 84 | // Free the shader program 85 | shaderProgramFree(&program); 86 | DVLB_Free(program_dvlb); 87 | } 88 | 89 | int main() 90 | { 91 | // Initialize graphics 92 | gfxInitDefault(); 93 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 94 | 95 | // Initialize the render target 96 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 97 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 98 | 99 | // Initialize the scene 100 | sceneInit(); 101 | 102 | // Main loop 103 | while (aptMainLoop()) 104 | { 105 | hidScanInput(); 106 | 107 | // Respond to user input 108 | u32 kDown = hidKeysDown(); 109 | if (kDown & KEY_START) 110 | break; // break in order to return to hbmenu 111 | 112 | // Render the scene 113 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 114 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 115 | C3D_FrameDrawOn(target); 116 | sceneRender(); 117 | C3D_FrameEnd(0); 118 | } 119 | 120 | // Deinitialize the scene 121 | sceneExit(); 122 | 123 | // Deinitialize graphics 124 | C3D_Fini(); 125 | gfxExit(); 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/multiple_buf/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "vshader_shbin.h" 5 | 6 | #define CLEAR_COLOR 0x68B0D8FF 7 | 8 | #define DISPLAY_TRANSFER_FLAGS \ 9 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 10 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 11 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 12 | 13 | typedef struct { float x, y, z; } position; 14 | typedef struct { float r, g, b, a; } color; 15 | 16 | static const position position_list[] = 17 | { 18 | { 200.0f, 200.0f, 0.5f }, 19 | { 100.0f, 40.0f, 0.5f }, 20 | { 300.0f, 40.0f, 0.5f }, 21 | }; 22 | 23 | static const color color_list[] = 24 | { 25 | { 1.0f, 0.0f, 0.0f, 1.0f }, 26 | { 0.0f, 1.0f, 0.0f, 1.0f }, 27 | { 0.0f, 0.0f, 1.0f, 1.0f }, 28 | }; 29 | 30 | #define vertex_count (sizeof(position_list)/sizeof(position_list[0])) 31 | 32 | static DVLB_s* vshader_dvlb; 33 | static shaderProgram_s program; 34 | static int uLoc_projection; 35 | static C3D_Mtx projection; 36 | 37 | static void *vbo_data_pos, *vbo_data_clr; 38 | 39 | static void sceneInit(void) 40 | { 41 | // Load the vertex shader, create a shader program and bind it 42 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 43 | shaderProgramInit(&program); 44 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 45 | C3D_BindProgram(&program); 46 | 47 | // Get the location of the uniforms 48 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 49 | 50 | // Configure attributes for use with the vertex shader 51 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 52 | AttrInfo_Init(attrInfo); 53 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 54 | AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 4); // v1=color 55 | 56 | // Compute the projection matrix 57 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); 58 | 59 | // Create the VBO (vertex buffer object) 60 | vbo_data_pos = linearAlloc(sizeof(position_list)); 61 | memcpy(vbo_data_pos, position_list, sizeof(position_list)); 62 | vbo_data_clr = linearAlloc(sizeof(color_list)); 63 | memcpy(vbo_data_clr, color_list, sizeof(color_list)); 64 | 65 | // Configure buffers 66 | C3D_BufInfo* bufInfo = C3D_GetBufInfo(); 67 | BufInfo_Init(bufInfo); 68 | BufInfo_Add(bufInfo, vbo_data_pos, sizeof(position), 1, 0x0); 69 | BufInfo_Add(bufInfo, vbo_data_clr, sizeof(color), 1, 0x1); 70 | 71 | // Configure the first fragment shading substage to just pass through the vertex color 72 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 73 | C3D_TexEnv* env = C3D_GetTexEnv(0); 74 | C3D_TexEnvInit(env); 75 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 76 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 77 | } 78 | 79 | static void sceneRender(void) 80 | { 81 | // Update the uniforms 82 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); 83 | 84 | // Draw the VBO 85 | C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_count); 86 | } 87 | 88 | static void sceneExit(void) 89 | { 90 | // Free the VBO 91 | linearFree(vbo_data_pos); 92 | linearFree(vbo_data_clr); 93 | 94 | // Free the shader program 95 | shaderProgramFree(&program); 96 | DVLB_Free(vshader_dvlb); 97 | } 98 | 99 | int main() 100 | { 101 | // Initialize graphics 102 | gfxInitDefault(); 103 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 104 | 105 | // Initialize the render target 106 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 107 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 108 | 109 | // Initialize the scene 110 | sceneInit(); 111 | 112 | // Main loop 113 | while (aptMainLoop()) 114 | { 115 | hidScanInput(); 116 | 117 | // Respond to user input 118 | u32 kDown = hidKeysDown(); 119 | if (kDown & KEY_START) 120 | break; // break in order to return to hbmenu 121 | 122 | // Render the scene 123 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 124 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 125 | C3D_FrameDrawOn(target); 126 | sceneRender(); 127 | C3D_FrameEnd(0); 128 | } 129 | 130 | // Deinitialize the scene 131 | sceneExit(); 132 | 133 | // Deinitialize graphics 134 | C3D_Fini(); 135 | gfxExit(); 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/gpusprites/source/main.c: -------------------------------------------------------------------------------- 1 | // Simple citro2d sprite drawing example 2 | // Images borrowed from: 3 | // https://kenney.nl/assets/space-shooter-redux 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define MAX_SPRITES 768 13 | #define SCREEN_WIDTH 400 14 | #define SCREEN_HEIGHT 240 15 | 16 | // Simple sprite struct 17 | typedef struct 18 | { 19 | C2D_Sprite spr; 20 | float dx, dy; // velocity 21 | } Sprite; 22 | 23 | static C2D_SpriteSheet spriteSheet; 24 | static Sprite sprites[MAX_SPRITES]; 25 | static size_t numSprites = MAX_SPRITES/2; 26 | 27 | //--------------------------------------------------------------------------------- 28 | static void initSprites() { 29 | //--------------------------------------------------------------------------------- 30 | size_t numImages = C2D_SpriteSheetCount(spriteSheet); 31 | srand(time(NULL)); 32 | 33 | for (size_t i = 0; i < MAX_SPRITES; i++) 34 | { 35 | Sprite* sprite = &sprites[i]; 36 | 37 | // Random image, position, rotation and speed 38 | C2D_SpriteFromSheet(&sprite->spr, spriteSheet, rand() % numImages); 39 | C2D_SpriteSetCenter(&sprite->spr, 0.5f, 0.5f); 40 | C2D_SpriteSetPos(&sprite->spr, rand() % SCREEN_WIDTH, rand() % SCREEN_HEIGHT); 41 | C2D_SpriteSetRotation(&sprite->spr, C3D_Angle(rand()/(float)RAND_MAX)); 42 | sprite->dx = rand()*4.0f/RAND_MAX - 2.0f; 43 | sprite->dy = rand()*4.0f/RAND_MAX - 2.0f; 44 | } 45 | } 46 | 47 | //--------------------------------------------------------------------------------- 48 | static void moveSprites() { 49 | //--------------------------------------------------------------------------------- 50 | for (size_t i = 0; i < numSprites; i++) 51 | { 52 | Sprite* sprite = &sprites[i]; 53 | C2D_SpriteMove(&sprite->spr, sprite->dx, sprite->dy); 54 | C2D_SpriteRotateDegrees(&sprite->spr, 1.0f); 55 | 56 | // Check for collision with the screen boundaries 57 | if ((sprite->spr.params.pos.x < sprite->spr.params.pos.w / 2.0f && sprite->dx < 0.0f) || 58 | (sprite->spr.params.pos.x > (SCREEN_WIDTH-(sprite->spr.params.pos.w / 2.0f)) && sprite->dx > 0.0f)) 59 | sprite->dx = -sprite->dx; 60 | 61 | if ((sprite->spr.params.pos.y < sprite->spr.params.pos.h / 2.0f && sprite->dy < 0.0f) || 62 | (sprite->spr.params.pos.y > (SCREEN_HEIGHT-(sprite->spr.params.pos.h / 2.0f)) && sprite->dy > 0.0f)) 63 | sprite->dy = -sprite->dy; 64 | } 65 | } 66 | 67 | //--------------------------------------------------------------------------------- 68 | int main(int argc, char* argv[]) { 69 | //--------------------------------------------------------------------------------- 70 | // Init libs 71 | romfsInit(); 72 | gfxInitDefault(); 73 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 74 | C2D_Init(C2D_DEFAULT_MAX_OBJECTS); 75 | C2D_Prepare(); 76 | consoleInit(GFX_BOTTOM, NULL); 77 | 78 | // Create screens 79 | C3D_RenderTarget* top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); 80 | 81 | // Load graphics 82 | spriteSheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x"); 83 | if (!spriteSheet) svcBreak(USERBREAK_PANIC); 84 | 85 | // Initialize sprites 86 | initSprites(); 87 | 88 | printf("\x1b[8;1HPress Up to increment sprites"); 89 | printf("\x1b[9;1HPress Down to decrement sprites"); 90 | 91 | // Main loop 92 | while (aptMainLoop()) 93 | { 94 | hidScanInput(); 95 | 96 | // Respond to user input 97 | u32 kDown = hidKeysDown(); 98 | if (kDown & KEY_START) 99 | break; // break in order to return to hbmenu 100 | 101 | u32 kHeld = hidKeysHeld(); 102 | if ((kHeld & KEY_UP) && numSprites < MAX_SPRITES) 103 | numSprites++; 104 | if ((kHeld & KEY_DOWN) && numSprites > 1) 105 | numSprites--; 106 | 107 | moveSprites(); 108 | 109 | printf("\x1b[1;1HSprites: %zu/%u\x1b[K", numSprites, MAX_SPRITES); 110 | printf("\x1b[2;1HCPU: %6.2f%%\x1b[K", C3D_GetProcessingTime()*6.0f); 111 | printf("\x1b[3;1HGPU: %6.2f%%\x1b[K", C3D_GetDrawingTime()*6.0f); 112 | printf("\x1b[4;1HCmdBuf: %6.2f%%\x1b[K", C3D_GetCmdBufUsage()*100.0f); 113 | 114 | // Render the scene 115 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 116 | C2D_TargetClear(top, C2D_Color32f(0.0f, 0.0f, 0.0f, 1.0f)); 117 | C2D_SceneBegin(top); 118 | for (size_t i = 0; i < numSprites; i ++) 119 | C2D_DrawSprite(&sprites[i].spr); 120 | C3D_FrameEnd(0); 121 | } 122 | 123 | // Delete graphics 124 | C2D_SpriteSheetFree(spriteSheet); 125 | 126 | // Deinit libs 127 | C2D_Fini(); 128 | C3D_Fini(); 129 | gfxExit(); 130 | romfsExit(); 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /3ds-examples-master/input/software-keyboard/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | 5 | static SwkbdCallbackResult MyCallback(void* user, const char** ppMessage, const char* text, size_t textlen) 6 | { 7 | if (strstr(text, "lenny")) 8 | { 9 | *ppMessage = "Nice try but I'm not letting you use that meme right now"; 10 | return SWKBD_CALLBACK_CONTINUE; 11 | } 12 | 13 | if (strstr(text, "brick")) 14 | { 15 | *ppMessage = "~Time to visit Brick City~"; 16 | return SWKBD_CALLBACK_CLOSE; 17 | } 18 | 19 | return SWKBD_CALLBACK_OK; 20 | } 21 | 22 | int main(int argc, char **argv) 23 | { 24 | gfxInitDefault(); 25 | consoleInit(GFX_TOP, NULL); 26 | 27 | printf("Software keyboard demo - by fincs\n"); 28 | printf("A: text input\n"); 29 | printf("B: numpad input\n"); 30 | printf("X: western input\n"); 31 | printf("Y: filtered input + HOME/POWER/reset handling\n"); 32 | printf("START: exit\n"); 33 | 34 | while (aptMainLoop()) 35 | { 36 | hidScanInput(); 37 | 38 | u32 kDown = hidKeysDown(); 39 | 40 | if (kDown & KEY_START) 41 | break; 42 | 43 | static SwkbdState swkbd; 44 | static char mybuf[60]; 45 | static SwkbdStatusData swkbdStatus; 46 | static SwkbdLearningData swkbdLearning; 47 | SwkbdButton button = SWKBD_BUTTON_NONE; 48 | bool didit = false; 49 | 50 | if (kDown & KEY_A) 51 | { 52 | didit = true; 53 | swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 3, -1); 54 | swkbdSetInitialText(&swkbd, mybuf); 55 | swkbdSetHintText(&swkbd, "Please enter dank memes"); 56 | swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Maybe Not", false); 57 | swkbdSetButton(&swkbd, SWKBD_BUTTON_MIDDLE, "~Middle~", true); 58 | swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Do It", true); 59 | swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT); 60 | SwkbdDictWord words[2]; 61 | swkbdSetDictWord(&words[0], "lenny", "( ͡° ͜ʖ ͡°)"); 62 | swkbdSetDictWord(&words[1], "shrug", "¯\\_(ツ)_/¯"); 63 | swkbdSetDictionary(&swkbd, words, sizeof(words)/sizeof(SwkbdDictWord)); 64 | static bool reload = false; 65 | swkbdSetStatusData(&swkbd, &swkbdStatus, reload, true); 66 | swkbdSetLearningData(&swkbd, &swkbdLearning, reload, true); 67 | reload = true; 68 | button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf)); 69 | } 70 | 71 | if (kDown & KEY_B) 72 | { 73 | didit = true; 74 | swkbdInit(&swkbd, SWKBD_TYPE_NUMPAD, 1, 8); 75 | swkbdSetPasswordMode(&swkbd, SWKBD_PASSWORD_HIDE_DELAY); 76 | swkbdSetValidation(&swkbd, SWKBD_ANYTHING, 0, 0); 77 | swkbdSetFeatures(&swkbd, SWKBD_FIXED_WIDTH); 78 | swkbdSetNumpadKeys(&swkbd, L'ツ', L'益'); 79 | button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf)); 80 | } 81 | 82 | if (kDown & KEY_X) 83 | { 84 | didit = true; 85 | swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 1, -1); 86 | swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, SWKBD_FILTER_DIGITS | SWKBD_FILTER_AT | SWKBD_FILTER_PERCENT | SWKBD_FILTER_BACKSLASH | SWKBD_FILTER_PROFANITY, 2); 87 | swkbdSetFeatures(&swkbd, SWKBD_MULTILINE); 88 | swkbdSetHintText(&swkbd, "No Japanese text allowed ¯\\_(ツ)_/¯"); 89 | button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf)); 90 | } 91 | 92 | if (kDown & KEY_Y) 93 | { 94 | didit = true; 95 | swkbdInit(&swkbd, SWKBD_TYPE_WESTERN, 2, -1); 96 | swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, 0, 0); 97 | swkbdSetFeatures(&swkbd, SWKBD_DARKEN_TOP_SCREEN | SWKBD_ALLOW_HOME | SWKBD_ALLOW_RESET | SWKBD_ALLOW_POWER); 98 | swkbdSetFilterCallback(&swkbd, MyCallback, NULL); 99 | 100 | bool shouldQuit = false; 101 | mybuf[0] = 0; 102 | do 103 | { 104 | swkbdSetInitialText(&swkbd, mybuf); 105 | button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf)); 106 | if (button != SWKBD_BUTTON_NONE) 107 | break; 108 | 109 | SwkbdResult res = swkbdGetResult(&swkbd); 110 | if (res == SWKBD_RESETPRESSED) 111 | { 112 | shouldQuit = true; 113 | aptSetChainloaderToSelf(); 114 | break; 115 | } 116 | else if (res != SWKBD_HOMEPRESSED && res != SWKBD_POWERPRESSED) 117 | break; // An actual error happened, display it 118 | 119 | shouldQuit = !aptMainLoop(); 120 | } while (!shouldQuit); 121 | 122 | if (shouldQuit) 123 | break; 124 | } 125 | 126 | if (didit) 127 | { 128 | if (button != SWKBD_BUTTON_NONE) 129 | { 130 | printf("You pressed button %d\n", button); 131 | printf("Text: %s\n", mybuf); 132 | } else 133 | printf("swkbd event: %d\n", swkbdGetResult(&swkbd)); 134 | } 135 | 136 | // Flush and swap framebuffers 137 | gfxFlushBuffers(); 138 | gfxSwapBuffers(); 139 | 140 | gspWaitForVBlank(); 141 | } 142 | 143 | gfxExit(); 144 | return 0; 145 | } 146 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/both_screens/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "vshader_shbin.h" 5 | 6 | #define CLEAR_COLOR 0x68B0D8FF 7 | 8 | #define DISPLAY_TRANSFER_FLAGS \ 9 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 10 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 11 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 12 | 13 | typedef struct { float x, y, z; } vertex; 14 | 15 | static const vertex vertex_list[] = 16 | { 17 | { 0.0f, 200.0f, 0.5f }, 18 | { -100.0f, 40.0f, 0.5f }, 19 | { +100.0f, 40.0f, 0.5f }, 20 | }; 21 | 22 | #define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) 23 | 24 | static DVLB_s* vshader_dvlb; 25 | static shaderProgram_s program; 26 | static int uLoc_projection; 27 | static C3D_Mtx projectionTop, projectionBot; 28 | 29 | static void* vbo_data; 30 | 31 | static void sceneInit(void) 32 | { 33 | // Load the vertex shader, create a shader program and bind it 34 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 35 | shaderProgramInit(&program); 36 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 37 | C3D_BindProgram(&program); 38 | 39 | // Get the location of the uniforms 40 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 41 | 42 | // Configure attributes for use with the vertex shader 43 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 44 | AttrInfo_Init(attrInfo); 45 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 46 | AttrInfo_AddFixed(attrInfo, 1); // v1=color 47 | 48 | // Set the fixed attribute (color) to solid white 49 | C3D_FixedAttribSet(1, 1.0, 1.0, 1.0, 1.0); 50 | 51 | // Compute the projection matrix 52 | Mtx_OrthoTilt(&projectionTop, -200.0f, 200.0f, 0.0f, 240.0f, 0.0f, 1.0f, true); 53 | Mtx_OrthoTilt(&projectionBot, -160.0f, 160.0f, 0.0f, 240.0f, 0.0f, 1.0f, true); 54 | 55 | // Create the VBO (vertex buffer object) 56 | vbo_data = linearAlloc(sizeof(vertex_list)); 57 | memcpy(vbo_data, vertex_list, sizeof(vertex_list)); 58 | 59 | // Configure buffers 60 | C3D_BufInfo* bufInfo = C3D_GetBufInfo(); 61 | BufInfo_Init(bufInfo); 62 | BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 1, 0x0); 63 | 64 | // Configure the first fragment shading substage to just pass through the vertex color 65 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 66 | C3D_TexEnv* env = C3D_GetTexEnv(0); 67 | C3D_TexEnvInit(env); 68 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 69 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 70 | } 71 | 72 | static void sceneRender(float a, bool top) 73 | { 74 | float b = (cosf(C3D_Angle(a)) + 1.0f) / 2.0f; 75 | if (!top) b = 1.0f - b; 76 | 77 | C3D_FixedAttribSet(1, b, b, b, 1.0); 78 | // Update the uniforms 79 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, top ? &projectionTop : &projectionBot); 80 | 81 | // Draw the VBO 82 | C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); 83 | } 84 | 85 | static void sceneExit(void) 86 | { 87 | // Free the VBO 88 | linearFree(vbo_data); 89 | 90 | // Free the shader program 91 | shaderProgramFree(&program); 92 | DVLB_Free(vshader_dvlb); 93 | } 94 | 95 | int main() 96 | { 97 | // Initialize graphics 98 | gfxInitDefault(); 99 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 100 | 101 | // Initialize the render target 102 | C3D_RenderTarget* top = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 103 | C3D_RenderTargetSetOutput(top, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 104 | C3D_RenderTarget* bot = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 105 | C3D_RenderTargetSetOutput(bot, GFX_BOTTOM, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 106 | 107 | // Initialize the scene 108 | sceneInit(); 109 | 110 | // Main loop 111 | float count = 0.0f; 112 | while (aptMainLoop()) 113 | { 114 | hidScanInput(); 115 | 116 | // Respond to user input 117 | u32 kDown = hidKeysDown(); 118 | if (kDown & KEY_START) 119 | break; // break in order to return to hbmenu 120 | 121 | // Render the scene 122 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 123 | C3D_RenderTargetClear(top, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 124 | C3D_FrameDrawOn(top); 125 | sceneRender(count, true); 126 | C3D_RenderTargetClear(bot, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 127 | C3D_FrameDrawOn(bot); 128 | sceneRender(count, false); 129 | C3D_FrameEnd(0); 130 | count += 1/128.0f; 131 | } 132 | 133 | // Deinitialize the scene 134 | sceneExit(); 135 | 136 | // Deinitialize graphics 137 | C3D_Fini(); 138 | gfxExit(); 139 | return 0; 140 | } 141 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/modplug-decoding/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | typedef struct 12 | { 13 | ModPlugFile *plug; 14 | ModPlug_Settings settings; 15 | } ModplugDecoder; 16 | 17 | typedef struct 18 | { 19 | void* data; 20 | size_t size; 21 | } StaticDataBuffer; 22 | 23 | void staticDataBufferInit(StaticDataBuffer* buffer, void* data, size_t size) 24 | { 25 | memset(buffer, 0, sizeof(StaticDataBuffer)); 26 | 27 | buffer->data = (int16_t*)linearAlloc(size); 28 | buffer->size = size; 29 | 30 | memcpy(buffer->data, data, size); 31 | } 32 | 33 | void staticDataBufferDestroy(StaticDataBuffer* buffer) 34 | { 35 | if (buffer) 36 | linearFree(buffer->data); 37 | } 38 | 39 | int main(int argc, char **argv) 40 | { 41 | gfxInitDefault(); 42 | 43 | consoleInit(GFX_TOP, NULL); 44 | 45 | ndspInit(); 46 | romfsInit(); 47 | 48 | ModplugDecoder decoder; 49 | 50 | /* set up ModPlug settings */ 51 | decoder.settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION; 52 | decoder.settings.mChannels = 2; 53 | decoder.settings.mBits = 16; 54 | decoder.settings.mFrequency = 44100; 55 | decoder.settings.mResamplingMode = MODPLUG_RESAMPLE_LINEAR; 56 | 57 | /* Fill with modplug defaults */ 58 | decoder.settings.mStereoSeparation = 128; 59 | decoder.settings.mMaxMixChannels = 32; 60 | decoder.settings.mReverbDepth = 0; 61 | decoder.settings.mReverbDelay = 0; 62 | decoder.settings.mBassAmount = 0; 63 | decoder.settings.mBassRange = 0; 64 | decoder.settings.mSurroundDepth = 0; 65 | decoder.settings.mSurroundDelay = 0; 66 | decoder.settings.mLoopCount = -1; 67 | 68 | ModPlug_SetSettings(&decoder.settings); 69 | 70 | /* Get the file size via stat */ 71 | 72 | struct stat fileStat; 73 | stat("romfs:/space_debris.mod", &fileStat); 74 | size_t bufferSize = fileStat.st_size; 75 | 76 | /* Open the file for reading */ 77 | 78 | FILE* file = fopen("romfs:/space_debris.mod", "rb"); 79 | 80 | /* Read the file into a buffer */ 81 | 82 | void* buffer = (void*)malloc(bufferSize); 83 | fread(buffer, bufferSize, 1, file); 84 | 85 | /* Load the ModPlug file from the buffer */ 86 | 87 | decoder.plug = ModPlug_Load(buffer, bufferSize); 88 | 89 | /* Free the useless buffer now and close the file handle */ 90 | 91 | free(buffer); 92 | fclose(file); 93 | 94 | if (decoder.plug == 0) 95 | printf("Well shit, could not load file!\n"); 96 | else 97 | ModPlug_SetMasterVolume(decoder.plug, 128); 98 | 99 | /* Create a new ndspWaveBuf */ 100 | 101 | ndspWaveBuf waveBuf; 102 | 103 | /* 104 | ** Create static buffer data and use 105 | ** a redundant size for the test. 106 | ** 107 | ** == WARNING == 108 | ** Do not actually do this. 109 | ** 110 | ** The decoder size should be looping 111 | ** through calls to ModPlug_Read until nothing 112 | ** can be read anymore. 113 | ** 114 | ** Memory *may* get exhausted if too much is allocated. 115 | ** Implement a way to check that, realloc, etc until a limit 116 | ** of streaming data is hit. 117 | */ 118 | size_t decoderSize = 524288 * 50; 119 | void* decodedBuffer = (void*)malloc(decoderSize); 120 | 121 | size_t decoded = ModPlug_Read(decoder.plug, decodedBuffer, decoderSize); 122 | 123 | StaticDataBuffer staticDataBuffer; 124 | staticDataBufferInit(&staticDataBuffer, decodedBuffer, decoded); 125 | 126 | printf("Decoded Size: %zu\n", decoded); 127 | 128 | waveBuf.nsamples = ((decoded / 2) / 16 / 8); 129 | waveBuf.looping = false; 130 | 131 | waveBuf.data_pcm16 = (int16_t*)staticDataBuffer.data; 132 | DSP_FlushDataCache(waveBuf.data_pcm16, decoded); 133 | 134 | ndspChnReset(0); 135 | ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); 136 | ndspChnSetRate(0, 44100); 137 | ndspChnSetInterp(0, NDSP_INTERP_POLYPHASE); 138 | 139 | printf("Playing modplug file!\n"); 140 | ndspChnWaveBufAdd(0, &waveBuf); 141 | 142 | // Main loop 143 | while (aptMainLoop()) 144 | { 145 | hidScanInput(); 146 | 147 | u32 kDown = hidKeysDown(); 148 | 149 | if (kDown & KEY_START) 150 | break; // break in order to return to hbmenu 151 | 152 | // Flush and swap framebuffers 153 | gfxFlushBuffers(); 154 | gfxSwapBuffers(); 155 | 156 | //Wait for VBlank 157 | gspWaitForVBlank(); 158 | } 159 | 160 | if (decoder.plug != 0) 161 | ModPlug_Unload(decoder.plug); 162 | 163 | staticDataBufferDestroy(&staticDataBuffer); 164 | 165 | romfsExit(); 166 | 167 | ndspExit(); 168 | 169 | gfxExit(); 170 | 171 | return 0; 172 | } 173 | -------------------------------------------------------------------------------- /3ds-examples-master/templates/library/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | include $(DEVKITARM)/3ds_rules 10 | 11 | #--------------------------------------------------------------------------------- 12 | # TARGET is the name of the output 13 | # BUILD is the directory where object files & intermediate files will be placed 14 | # SOURCES is a list of directories containing source code 15 | # DATA is a list of directories containing data files 16 | # INCLUDES is a list of directories containing header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := $(shell basename $(CURDIR)) 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := include 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft 28 | 29 | CFLAGS := -g -Wall -O2 -mword-relocations \ 30 | -ffunction-sections \ 31 | $(ARCH) 32 | 33 | CFLAGS += $(INCLUDE) -D__3DS__ 34 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 35 | 36 | ASFLAGS := -g $(ARCH) 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := $(CTRULIB) 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 59 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 60 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 61 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 62 | 63 | #--------------------------------------------------------------------------------- 64 | # use CXX for linking C++ projects, CC for standard C 65 | #--------------------------------------------------------------------------------- 66 | ifeq ($(strip $(CPPFILES)),) 67 | #--------------------------------------------------------------------------------- 68 | export LD := $(CC) 69 | #--------------------------------------------------------------------------------- 70 | else 71 | #--------------------------------------------------------------------------------- 72 | export LD := $(CXX) 73 | #--------------------------------------------------------------------------------- 74 | endif 75 | #--------------------------------------------------------------------------------- 76 | 77 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 78 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 79 | 80 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 81 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 82 | -I$(CURDIR)/$(BUILD) 83 | 84 | .PHONY: $(BUILD) clean all 85 | 86 | #--------------------------------------------------------------------------------- 87 | all: $(BUILD) 88 | 89 | lib: 90 | @[ -d $@ ] || mkdir -p $@ 91 | 92 | $(BUILD): lib 93 | @[ -d $@ ] || mkdir -p $@ 94 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 95 | 96 | #--------------------------------------------------------------------------------- 97 | clean: 98 | @echo clean ... 99 | @rm -fr $(BUILD) lib 100 | 101 | #--------------------------------------------------------------------------------- 102 | else 103 | 104 | DEPENDS := $(OFILES:.o=.d) 105 | 106 | #--------------------------------------------------------------------------------- 107 | # main targets 108 | #--------------------------------------------------------------------------------- 109 | $(OUTPUT) : $(OFILES) 110 | 111 | #--------------------------------------------------------------------------------- 112 | %.bin.o : %.bin 113 | #--------------------------------------------------------------------------------- 114 | @echo $(notdir $<) 115 | @$(bin2o) 116 | 117 | 118 | -include $(DEPENDS) 119 | 120 | #--------------------------------------------------------------------------------------- 121 | endif 122 | #--------------------------------------------------------------------------------------- 123 | -------------------------------------------------------------------------------- /3ds-examples-master/audio/filters/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include <3ds.h> 7 | 8 | #define SAMPLERATE 22050 9 | #define SAMPLESPERBUF (SAMPLERATE / 30) 10 | #define BYTESPERSAMPLE 4 11 | 12 | #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0])) 13 | 14 | // audioBuffer is stereo PCM16 15 | void fill_buffer(void* audioBuffer, size_t offset, size_t size, int frequency) { 16 | u32* dest = (u32*) audioBuffer; 17 | 18 | for (int i = 0; i < size; i++) { 19 | // This is a simple sine wave, with a frequency of `frequency` Hz, and an amplitude 30% of maximum. 20 | s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE); 21 | 22 | // Stereo samples are interleaved: left and right channels. 23 | dest[i] = (sample << 16) | (sample & 0xffff); 24 | } 25 | 26 | DSP_FlushDataCache(audioBuffer, size); 27 | } 28 | 29 | int main(int argc, char **argv) { 30 | gfxInitDefault(); 31 | 32 | PrintConsole topScreen; 33 | consoleInit(GFX_TOP, &topScreen); 34 | consoleSelect(&topScreen); 35 | 36 | printf("libctru filtered streamed audio\n"); 37 | 38 | u32* audioBuffer = (u32*) linearAlloc(SAMPLESPERBUF * BYTESPERSAMPLE * 2); 39 | 40 | bool fillBlock = false; 41 | 42 | ndspInit(); 43 | 44 | ndspSetOutputMode(NDSP_OUTPUT_STEREO); 45 | 46 | ndspChnSetInterp(0, NDSP_INTERP_LINEAR); 47 | ndspChnSetRate(0, SAMPLERATE); 48 | ndspChnSetFormat(0, NDSP_FORMAT_STEREO_PCM16); 49 | 50 | // Output at 100% on the first pair of left and right channels. 51 | 52 | float mix[12]; 53 | memset(mix, 0, sizeof(mix)); 54 | mix[0] = 1.0; 55 | mix[1] = 1.0; 56 | ndspChnSetMix(0, mix); 57 | 58 | // Note Frequencies 59 | 60 | int notefreq[] = { 61 | 220, 62 | 440, 880, 1760, 3520, 7040, 63 | 14080, 64 | 7040, 3520, 1760, 880, 440 65 | }; 66 | 67 | int note = 4; 68 | 69 | // Filters 70 | 71 | const char* filter_names[] = { 72 | "None", 73 | "Low-Pass", 74 | "High-Pass", 75 | "Band-Pass", 76 | "Notch", 77 | "Peaking" 78 | }; 79 | 80 | int filter = 0; 81 | 82 | // We set up two wave buffers and alternate between the two, 83 | // effectively streaming an infinitely long sine wave. 84 | 85 | ndspWaveBuf waveBuf[2]; 86 | memset(waveBuf,0,sizeof(waveBuf)); 87 | waveBuf[0].data_vaddr = &audioBuffer[0]; 88 | waveBuf[0].nsamples = SAMPLESPERBUF; 89 | waveBuf[1].data_vaddr = &audioBuffer[SAMPLESPERBUF]; 90 | waveBuf[1].nsamples = SAMPLESPERBUF; 91 | 92 | size_t stream_offset = 0; 93 | 94 | fill_buffer(audioBuffer,stream_offset, SAMPLESPERBUF * 2, notefreq[note]); 95 | 96 | stream_offset += SAMPLESPERBUF; 97 | 98 | ndspChnWaveBufAdd(0, &waveBuf[0]); 99 | ndspChnWaveBufAdd(0, &waveBuf[1]); 100 | 101 | printf("Press up/down to change tone frequency\n"); 102 | printf("Press left/right to change filter\n"); 103 | printf("\x1b[6;1Hnote = %i Hz ", notefreq[note]); 104 | printf("\x1b[7;1Hfilter = %s ", filter_names[filter]); 105 | 106 | while(aptMainLoop()) { 107 | 108 | gfxSwapBuffers(); 109 | gfxFlushBuffers(); 110 | gspWaitForVBlank(); 111 | 112 | hidScanInput(); 113 | u32 kDown = hidKeysDown(); 114 | 115 | if (kDown & KEY_START) 116 | break; // break in order to return to hbmenu 117 | 118 | if (kDown & KEY_DOWN) { 119 | note--; 120 | if (note < 0) { 121 | note = ARRAY_SIZE(notefreq) - 1; 122 | } 123 | printf("\x1b[6;1Hnote = %i Hz ", notefreq[note]); 124 | } else if (kDown & KEY_UP) { 125 | note++; 126 | if (note >= ARRAY_SIZE(notefreq)) { 127 | note = 0; 128 | } 129 | printf("\x1b[6;1Hnote = %i Hz ", notefreq[note]); 130 | } 131 | 132 | bool update_params = false; 133 | if (kDown & KEY_LEFT) { 134 | filter--; 135 | if (filter < 0) { 136 | filter = ARRAY_SIZE(filter_names) - 1; 137 | } 138 | update_params = true; 139 | } else if (kDown & KEY_RIGHT) { 140 | filter++; 141 | if (filter >= ARRAY_SIZE(filter_names)) { 142 | filter = 0; 143 | } 144 | update_params = true; 145 | } 146 | 147 | if (update_params) { 148 | printf("\x1b[7;1Hfilter = %s ", filter_names[filter]); 149 | switch (filter) { 150 | default: 151 | ndspChnIirBiquadSetEnable(0, false); 152 | break; 153 | case 1: 154 | ndspChnIirBiquadSetParamsLowPassFilter(0, 1760.f, 0.707f); 155 | break; 156 | case 2: 157 | ndspChnIirBiquadSetParamsHighPassFilter(0, 1760.f, 0.707f); 158 | break; 159 | case 3: 160 | ndspChnIirBiquadSetParamsBandPassFilter(0, 1760.f, 0.707f); 161 | break; 162 | case 4: 163 | ndspChnIirBiquadSetParamsNotchFilter(0, 1760.f, 0.707f); 164 | break; 165 | case 5: 166 | ndspChnIirBiquadSetParamsPeakingEqualizer(0, 1760.f, 0.707f, 3.0f); 167 | break; 168 | } 169 | } 170 | 171 | if (waveBuf[fillBlock].status == NDSP_WBUF_DONE) { 172 | fill_buffer(waveBuf[fillBlock].data_pcm16, stream_offset, waveBuf[fillBlock].nsamples, notefreq[note]); 173 | ndspChnWaveBufAdd(0, &waveBuf[fillBlock]); 174 | stream_offset += waveBuf[fillBlock].nsamples; 175 | fillBlock = !fillBlock; 176 | } 177 | } 178 | 179 | ndspExit(); 180 | 181 | linearFree(audioBuffer); 182 | 183 | gfxExit(); 184 | return 0; 185 | } 186 | -------------------------------------------------------------------------------- /3ds-examples-master/network/sockets/source/sockets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include <3ds.h> 18 | 19 | #define SOC_ALIGN 0x1000 20 | #define SOC_BUFFERSIZE 0x100000 21 | 22 | static u32 *SOC_buffer = NULL; 23 | s32 sock = -1, csock = -1; 24 | 25 | __attribute__((format(printf,1,2))) 26 | void failExit(const char *fmt, ...); 27 | 28 | const static char http_200[] = "HTTP/1.1 200 OK\r\n"; 29 | 30 | const static char indexdata[] = " \ 31 | A test page \ 32 | \ 33 | This small test page has had %d hits. \ 34 | \ 35 | "; 36 | 37 | const static char http_html_hdr[] = "Content-type: text/html\r\n\r\n"; 38 | const static char http_get_index[] = "GET / HTTP/1.1\r\n"; 39 | 40 | 41 | //--------------------------------------------------------------------------------- 42 | void socShutdown() { 43 | //--------------------------------------------------------------------------------- 44 | printf("waiting for socExit...\n"); 45 | socExit(); 46 | 47 | } 48 | 49 | //--------------------------------------------------------------------------------- 50 | int main(int argc, char **argv) { 51 | //--------------------------------------------------------------------------------- 52 | int ret; 53 | 54 | u32 clientlen; 55 | struct sockaddr_in client; 56 | struct sockaddr_in server; 57 | char temp[1026]; 58 | static int hits=0; 59 | 60 | gfxInitDefault(); 61 | 62 | // register gfxExit to be run when app quits 63 | // this can help simplify error handling 64 | atexit(gfxExit); 65 | 66 | consoleInit(GFX_TOP, NULL); 67 | 68 | printf ("\nlibctru sockets demo\n"); 69 | 70 | // allocate buffer for SOC service 71 | SOC_buffer = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE); 72 | 73 | if(SOC_buffer == NULL) { 74 | failExit("memalign: failed to allocate\n"); 75 | } 76 | 77 | // Now intialise soc:u service 78 | if ((ret = socInit(SOC_buffer, SOC_BUFFERSIZE)) != 0) { 79 | failExit("socInit: 0x%08X\n", (unsigned int)ret); 80 | } 81 | 82 | // register socShutdown to run at exit 83 | // atexit functions execute in reverse order so this runs before gfxExit 84 | atexit(socShutdown); 85 | 86 | // libctru provides BSD sockets so most code from here is standard 87 | clientlen = sizeof(client); 88 | 89 | sock = socket (AF_INET, SOCK_STREAM, IPPROTO_IP); 90 | 91 | if (sock < 0) { 92 | failExit("socket: %d %s\n", errno, strerror(errno)); 93 | } 94 | 95 | memset (&server, 0, sizeof (server)); 96 | memset (&client, 0, sizeof (client)); 97 | 98 | server.sin_family = AF_INET; 99 | server.sin_port = htons (80); 100 | server.sin_addr.s_addr = gethostid(); 101 | 102 | printf("Point your browser to http://%s/\n",inet_ntoa(server.sin_addr)); 103 | 104 | if ( (ret = bind (sock, (struct sockaddr *) &server, sizeof (server))) ) { 105 | close(sock); 106 | failExit("bind: %d %s\n", errno, strerror(errno)); 107 | } 108 | 109 | // Set socket non blocking so we can still read input to exit 110 | fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); 111 | 112 | if ( (ret = listen( sock, 5)) ) { 113 | failExit("listen: %d %s\n", errno, strerror(errno)); 114 | } 115 | 116 | while (aptMainLoop()) { 117 | gspWaitForVBlank(); 118 | hidScanInput(); 119 | 120 | csock = accept (sock, (struct sockaddr *) &client, &clientlen); 121 | 122 | if (csock<0) { 123 | if(errno != EAGAIN) { 124 | failExit("accept: %d %s\n", errno, strerror(errno)); 125 | } 126 | } else { 127 | // set client socket to blocking to simplify sending data back 128 | fcntl(csock, F_SETFL, fcntl(csock, F_GETFL, 0) & ~O_NONBLOCK); 129 | printf("Connecting port %d from %s\n", client.sin_port, inet_ntoa(client.sin_addr)); 130 | memset (temp, 0, 1026); 131 | 132 | ret = recv (csock, temp, 1024, 0); 133 | 134 | if ( !strncmp( temp, http_get_index, strlen(http_get_index) ) ) { 135 | hits++; 136 | 137 | send(csock, http_200, strlen(http_200),0); 138 | send(csock, http_html_hdr, strlen(http_html_hdr),0); 139 | sprintf(temp, indexdata, hits); 140 | send(csock, temp, strlen(temp),0); 141 | } 142 | 143 | close (csock); 144 | csock = -1; 145 | 146 | } 147 | 148 | u32 kDown = hidKeysDown(); 149 | if (kDown & KEY_START) break; 150 | } 151 | 152 | close(sock); 153 | 154 | return 0; 155 | } 156 | 157 | //--------------------------------------------------------------------------------- 158 | void failExit(const char *fmt, ...) { 159 | //--------------------------------------------------------------------------------- 160 | 161 | if(sock>0) close(sock); 162 | if(csock>0) close(csock); 163 | 164 | va_list ap; 165 | 166 | printf(CONSOLE_RED); 167 | va_start(ap, fmt); 168 | vprintf(fmt, ap); 169 | va_end(ap); 170 | printf(CONSOLE_RESET); 171 | printf("\nPress B to exit\n"); 172 | 173 | while (aptMainLoop()) { 174 | gspWaitForVBlank(); 175 | hidScanInput(); 176 | 177 | u32 kDown = hidKeysDown(); 178 | if (kDown & KEY_B) exit(0); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/wide_mode_3d/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include "vshader_shbin.h" 5 | #include "lenny.h" 6 | 7 | #define CLEAR_COLOR 0x68B0D8FF 8 | 9 | #define DISPLAY_TRANSFER_FLAGS \ 10 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 11 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 12 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 13 | 14 | static DVLB_s* vshader_dvlb; 15 | static shaderProgram_s program; 16 | static int uLoc_projection, uLoc_modelView; 17 | static C3D_Mtx projection; 18 | 19 | static C3D_LightEnv lightEnv; 20 | static C3D_Light light; 21 | static C3D_LightLut lut_Spec; 22 | 23 | static void* vbo_data; 24 | static float angleX = 0.0, angleY = 0.0; 25 | 26 | static void sceneInit(void) 27 | { 28 | // Load the vertex shader, create a shader program and bind it 29 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 30 | shaderProgramInit(&program); 31 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 32 | C3D_BindProgram(&program); 33 | 34 | // Get the location of the uniforms 35 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 36 | uLoc_modelView = shaderInstanceGetUniformLocation(program.vertexShader, "modelView"); 37 | 38 | // Configure attributes for use with the vertex shader 39 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 40 | AttrInfo_Init(attrInfo); 41 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 42 | AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=normal 43 | 44 | // Create the VBO (vertex buffer object) 45 | vbo_data = linearAlloc(sizeof(vertex_list)); 46 | memcpy(vbo_data, vertex_list, sizeof(vertex_list)); 47 | 48 | // Configure buffers 49 | C3D_BufInfo* bufInfo = C3D_GetBufInfo(); 50 | BufInfo_Init(bufInfo); 51 | BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 2, 0x10); 52 | 53 | // Configure the first fragment shading substage to blend the fragment primary color 54 | // with the fragment secondary color. 55 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 56 | C3D_TexEnv* env = C3D_GetTexEnv(0); 57 | C3D_TexEnvInit(env); 58 | C3D_TexEnvSrc(env, C3D_Both, GPU_FRAGMENT_PRIMARY_COLOR, GPU_FRAGMENT_SECONDARY_COLOR, 0); 59 | C3D_TexEnvFunc(env, C3D_Both, GPU_ADD); 60 | 61 | static const C3D_Material material = 62 | { 63 | { 0.1f, 0.1f, 0.1f }, //ambient 64 | { 0.4f, 0.4f, 0.4f }, //diffuse 65 | { 0.5f, 0.5f, 0.5f }, //specular0 66 | { 0.0f, 0.0f, 0.0f }, //specular1 67 | { 0.0f, 0.0f, 0.0f }, //emission 68 | }; 69 | 70 | C3D_LightEnvInit(&lightEnv); 71 | C3D_LightEnvBind(&lightEnv); 72 | C3D_LightEnvMaterial(&lightEnv, &material); 73 | 74 | LightLut_Phong(&lut_Spec, 20.0f); 75 | C3D_LightEnvLut(&lightEnv, GPU_LUT_D0, GPU_LUTINPUT_NH, false, &lut_Spec); 76 | 77 | C3D_LightInit(&light, &lightEnv); 78 | } 79 | 80 | static void sceneRender(void) 81 | { 82 | // Compute the projection matrix 83 | Mtx_PerspTilt(&projection, C3D_AngleFromDegrees(40.0f), C3D_AspectRatioTop, 0.01f, 1000.0f, false); 84 | 85 | C3D_FVec objPos = FVec4_New(0.0f, 0.0f, -3.0f, 1.0f); 86 | C3D_FVec lightPos = FVec4_New(0.0f, 0.0f, -0.5f, 1.0f); 87 | 88 | // Calculate the modelView matrix 89 | C3D_Mtx modelView; 90 | Mtx_Identity(&modelView); 91 | Mtx_Translate(&modelView, objPos.x, objPos.y, objPos.z, true); 92 | Mtx_RotateY(&modelView, C3D_Angle(angleY), true); 93 | Mtx_Scale(&modelView, 2.0f, 2.0f, 2.0f); 94 | 95 | C3D_LightPosition(&light, &lightPos); 96 | 97 | // Update the uniforms 98 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); 99 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_modelView, &modelView); 100 | 101 | // Draw the VBO 102 | C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); 103 | } 104 | 105 | static void sceneExit(void) 106 | { 107 | // Free the VBO 108 | linearFree(vbo_data); 109 | 110 | // Free the shader program 111 | shaderProgramFree(&program); 112 | DVLB_Free(vshader_dvlb); 113 | } 114 | 115 | int main() 116 | { 117 | // Initialize graphics 118 | gfxInitDefault(); 119 | gfxSetWide(true); // Enable wide mode 120 | consoleInit(GFX_BOTTOM, NULL); 121 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 122 | 123 | // Initialize the render targets 124 | C3D_RenderTarget* targetTop = C3D_RenderTargetCreate(240, 800, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 125 | C3D_RenderTargetSetOutput(targetTop, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 126 | 127 | // Initialize the scene 128 | sceneInit(); 129 | 130 | // Main loop 131 | while (aptMainLoop()) 132 | { 133 | hidScanInput(); 134 | 135 | // Respond to user input 136 | u32 kDown = hidKeysDown(); 137 | u32 kHeld = hidKeysHeld(); 138 | if (kDown & KEY_START) 139 | break; // break in order to return to hbmenu 140 | 141 | // Rotate the model 142 | if (!(kHeld & KEY_A)) 143 | { 144 | angleX += 1.0f/64; 145 | angleY += 1.0f/256; 146 | } 147 | 148 | // Render the scene 149 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 150 | { 151 | C3D_RenderTargetClear(targetTop, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 152 | C3D_FrameDrawOn(targetTop); 153 | sceneRender(); 154 | } 155 | C3D_FrameEnd(0); 156 | } 157 | 158 | // Deinitialize the scene 159 | sceneExit(); 160 | 161 | // Deinitialize graphics 162 | C3D_Fini(); 163 | gfxExit(); 164 | return 0; 165 | } 166 | -------------------------------------------------------------------------------- /3ds-examples-master/graphics/gpu/proctex/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include 5 | #include "vshader_shbin.h" 6 | 7 | #define CLEAR_COLOR 0x68B0D8FF 8 | 9 | #define DISPLAY_TRANSFER_FLAGS \ 10 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 11 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 12 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 13 | 14 | static DVLB_s* vshader_dvlb; 15 | static shaderProgram_s program; 16 | static int uLoc_projection; 17 | static C3D_Mtx projection; 18 | 19 | static C3D_ProcTex pt; 20 | static C3D_ProcTexLut pt_map; 21 | static C3D_ProcTexLut pt_noise; 22 | static C3D_ProcTexColorLut pt_clr; 23 | 24 | static void sceneInit(void) 25 | { 26 | // Load the vertex shader, create a shader program and bind it 27 | vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); 28 | shaderProgramInit(&program); 29 | shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); 30 | C3D_BindProgram(&program); 31 | 32 | // Get the location of the uniforms 33 | uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); 34 | 35 | // Configure attributes for use with the vertex shader 36 | // Attribute format and element count are ignored in immediate mode 37 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 38 | AttrInfo_Init(attrInfo); 39 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 40 | AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=texcoord0 41 | 42 | // Compute the projection matrix 43 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 240.0, 0.0, 0.0, 1.0, true); 44 | 45 | #define NUMCOLORS 2 46 | C3D_ProcTexInit(&pt, 0, NUMCOLORS); 47 | C3D_ProcTexClamp(&pt, GPU_PT_MIRRORED_REPEAT, GPU_PT_MIRRORED_REPEAT); 48 | C3D_ProcTexNoiseCoefs(&pt, C3D_ProcTex_UV, 0.1f, 0.3f, 0.1f); 49 | C3D_ProcTexCombiner(&pt, false, GPU_PT_SQRT2, GPU_PT_SQRT2); // <- for wood rings 50 | //C3D_ProcTexCombiner(&pt, false, GPU_PT_V, GPU_PT_V); // <- for wood stripes (or also _U) 51 | C3D_ProcTexFilter(&pt, GPU_PT_LINEAR); 52 | C3D_ProcTexBind(0, &pt); 53 | 54 | float data[129]; 55 | int i; 56 | for (i = 0; i <= 128; i ++) 57 | { 58 | float x = i/128.0f; 59 | data[i] = fabsf(sinf(C3D_Angle(6*(x+0.125f)))); // 6*2 = 12 stripes 60 | } 61 | ProcTexLut_FromArray(&pt_map, data); 62 | C3D_ProcTexLutBind(GPU_LUT_RGBMAP, &pt_map); 63 | 64 | // Noise smooth step equation 65 | for (i = 0; i <= 128; i ++) 66 | { 67 | float x = i/128.0f; 68 | data[i] = x*x*(3-2*x); 69 | } 70 | ProcTexLut_FromArray(&pt_noise, data); 71 | C3D_ProcTexLutBind(GPU_LUT_NOISE, &pt_noise); 72 | 73 | u32 colors[NUMCOLORS]; 74 | colors[0] = 0xFF1F1F4F; // dark brown 75 | colors[1] = 0xFF1F9ED1; // light brown 76 | 77 | ProcTexColorLut_Write(&pt_clr, colors, 0, NUMCOLORS); 78 | C3D_ProcTexColorLutBind(&pt_clr); 79 | 80 | // Configure the first fragment shading substage to just pass through the procedural texture color 81 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 82 | C3D_TexEnv* env = C3D_GetTexEnv(0); 83 | C3D_TexEnvInit(env); 84 | C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE3, 0, 0); 85 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 86 | } 87 | 88 | static void sceneRender(void) 89 | { 90 | // Update the uniforms 91 | C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); 92 | 93 | // Draw the triangle directly 94 | //float min = -1.0f; //<-- for (symmetrical) wood rings 95 | //float max = +1.0f; 96 | float min = 1.0f; //<-- for asymmetrical wood rings 97 | float max = 3.0f; 98 | //float min = 0.0f; //<-- for wood stripes 99 | //float max = +3.0f; // triplicate stripes 100 | float size = 200.0f/2; 101 | C3D_ImmDrawBegin(GPU_TRIANGLE_STRIP); 102 | C3D_ImmSendAttrib(200.0f-size, 120.0f+size, 0.5f, 0.0f); // v0=position 103 | C3D_ImmSendAttrib(min, min, 0.0f, 0.0f); // v1=texcoord0 104 | 105 | C3D_ImmSendAttrib(200.0f+size, 120.0f+size, 0.5f, 0.0f); 106 | C3D_ImmSendAttrib(max, min, 0.0f, 0.0f); 107 | 108 | C3D_ImmSendAttrib(200.0f-size, 120.0f-size, 0.5f, 0.0f); 109 | C3D_ImmSendAttrib(min, max, 0.0f, 0.0f); 110 | 111 | C3D_ImmSendAttrib(200.0f+size, 120.0f-size, 0.5f, 0.0f); 112 | C3D_ImmSendAttrib(max, max, 0.0f, 0.0f); 113 | C3D_ImmDrawEnd(); 114 | } 115 | 116 | static void sceneExit(void) 117 | { 118 | // Free the shader program 119 | shaderProgramFree(&program); 120 | DVLB_Free(vshader_dvlb); 121 | } 122 | 123 | int main() 124 | { 125 | // Initialize graphics 126 | gfxInitDefault(); 127 | consoleInit(GFX_BOTTOM, NULL); 128 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 129 | 130 | // Initialize the render target 131 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 132 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 133 | 134 | // Initialize the scene 135 | sceneInit(); 136 | 137 | // Main loop 138 | while (aptMainLoop()) 139 | { 140 | hidScanInput(); 141 | 142 | // Respond to user input 143 | u32 kDown = hidKeysDown(); 144 | if (kDown & KEY_START) 145 | break; // break in order to return to hbmenu 146 | 147 | printf("\x1b[29;1Hgpu: %5.2f%% cpu: %5.2f%% buf:%5.2f%%\n", C3D_GetDrawingTime()*3, C3D_GetProcessingTime()*3, C3D_GetCmdBufUsage()*100); 148 | 149 | // Render the scene 150 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 151 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 152 | C3D_FrameDrawOn(target); 153 | sceneRender(); 154 | C3D_FrameEnd(0); 155 | } 156 | 157 | // Deinitialize the scene 158 | sceneExit(); 159 | 160 | // Deinitialize graphics 161 | C3D_Fini(); 162 | gfxExit(); 163 | return 0; 164 | } 165 | -------------------------------------------------------------------------------- /3ds-examples-master/network/boss/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include <3ds.h> 5 | 6 | char regionids_table[7][4] = {//https://3dbrew.org/wiki/Nandrw/sys/SecureInfo_A 7 | "JPN", 8 | "USA", 9 | "EUR", 10 | "JPN", //"AUS" 11 | "CHN", 12 | "KOR", 13 | "TWN" 14 | }; 15 | 16 | Result setup_boss() 17 | { 18 | Result ret=0; 19 | u32 test_NsDataId = 0x57524248;//This can be anything. 20 | 21 | u8 region=0; 22 | 23 | bossContext ctx; 24 | u8 status=0; 25 | u32 tmp=0; 26 | u32 contentsize=0; 27 | 28 | char *taskID = "tmptask";//Should be unique per task(and unique per homebrew when running under *hax payload >=v2.8), unless the task is deleted afterwards. 29 | 30 | char tmpstr[256]; 31 | 32 | printf("Running BOSS setup...\n"); 33 | 34 | ret = cfguInit(); 35 | if(ret!=0) 36 | { 37 | printf("Failed to init cfg: 0x%08x.\n", (unsigned int)ret); 38 | return ret; 39 | } 40 | ret = CFGU_SecureInfoGetRegion(®ion); 41 | if(ret!=0) 42 | { 43 | printf("Failed to get region from cfg: 0x%08x.\n", (unsigned int)ret); 44 | return ret; 45 | } 46 | if(region>=7) 47 | { 48 | printf("Region value from cfg is invalid: 0x%02x.\n", (unsigned int)region); 49 | ret = -9; 50 | return ret; 51 | } 52 | cfguExit(); 53 | 54 | ret = bossInit(0, false); 55 | if(R_FAILED(ret))return ret; 56 | 57 | //If you're using background tasks you should check whether the task exists first, and skip task setup if so. 58 | 59 | bossDeleteTask(taskID, 0); 60 | bossDeleteNsData(test_NsDataId); 61 | 62 | //HTTP is used here since it's currently unknown how to setup a non-default rootCA cert for BOSS. 63 | //This uses a 60-second interval, with background tasks you will probably want to change that. 64 | //You can change the below URL to your own, the URL should include region info(see README). 65 | 66 | memset(tmpstr, 0, sizeof(tmpstr)); 67 | snprintf(tmpstr, sizeof(tmpstr)-1, "http://yls8.mtheall.com/boss/libctru_example/%s_bossdata0.bin", regionids_table[region]); 68 | 69 | bossSetupContextDefault(&ctx, 60, tmpstr); 70 | 71 | ret = bossSendContextConfig(&ctx); 72 | if(R_FAILED(ret))printf("bossSendContextConfig returned 0x%08x.\n", (unsigned int)ret); 73 | 74 | if(R_SUCCEEDED(ret)) 75 | { 76 | ret = bossRegisterTask(taskID, 0, 0); 77 | if(R_FAILED(ret))printf("bossRegisterTask returned 0x%08x.\n", (unsigned int)ret); 78 | 79 | if(R_SUCCEEDED(ret)) 80 | { 81 | ret = bossStartTaskImmediate(taskID); 82 | if(R_FAILED(ret))printf("bossStartTaskImmediate returned 0x%08x.\n", (unsigned int)ret); 83 | 84 | //The below is only needed if you want to process the content immediately. 85 | 86 | if(R_SUCCEEDED(ret)) 87 | { 88 | printf("Waiting for the task to finish running...\n"); 89 | 90 | while(1) 91 | { 92 | ret = bossGetTaskState(taskID, 0, &status, NULL, NULL); 93 | if(R_FAILED(ret)) 94 | { 95 | printf("bossGetTaskState returned 0x%08x.\n", (unsigned int)ret); 96 | break; 97 | } 98 | if(R_SUCCEEDED(ret)) 99 | { 100 | printf("...\n"); 101 | } 102 | 103 | if(status!=BOSSTASKSTATUS_STARTED)break; 104 | 105 | svcSleepThread(1000000000LL);//Delay 1s. 106 | } 107 | } 108 | 109 | if(R_SUCCEEDED(ret) && status==BOSSTASKSTATUS_ERROR) 110 | { 111 | printf("BOSS task failed. This usually indicates a network failure.\n"); 112 | ret = -9; 113 | } 114 | 115 | if(R_SUCCEEDED(ret)) 116 | { 117 | printf("Reading BOSS content...\n"); 118 | 119 | ret = bossGetNsDataHeaderInfo(test_NsDataId, bossNsDataHeaderInfoType_ContentSize, &contentsize, bossNsDataHeaderInfoTypeSize_ContentSize); 120 | if(R_FAILED(ret))printf("bossGetNsDataHeaderInfo returned 0x%08x.\n", (unsigned int)ret); 121 | 122 | if(R_SUCCEEDED(ret)) 123 | { 124 | printf("Content size: 0x%x.\n", (unsigned int)contentsize); 125 | if(contentsize > sizeof(tmpstr)-1)contentsize = sizeof(tmpstr)-1; 126 | 127 | tmp = 0; 128 | memset(tmpstr, 0, sizeof(tmpstr)); 129 | ret = bossReadNsData(test_NsDataId, 0, tmpstr, contentsize, &tmp, NULL); 130 | if(R_FAILED(ret))printf("bossReadNsData returned 0x%08x, transfer_total=0x%x.\n", (unsigned int)ret, (unsigned int)tmp); 131 | } 132 | 133 | if(R_SUCCEEDED(ret) && tmp!=contentsize)ret = -10; 134 | 135 | //This verifies that the first 4-bytes matches the expected data, but you can do whatever with the loaded content here. 136 | if(R_SUCCEEDED(ret) && strncmp(tmpstr, "Test", 4))ret = -11; 137 | 138 | if(R_SUCCEEDED(ret))printf("Content data at offset 0x4: %s\n", &tmpstr[4]); 139 | 140 | if(R_FAILED(ret))printf("BOSS data reading failed: 0x%08x.\n", (unsigned int)ret); 141 | } 142 | 143 | bossDeleteTask(taskID, 0);//Don't run this if you want a background task. 144 | bossDeleteNsData(test_NsDataId);//Don't run this if the SpotPass content will be used again later. 145 | } 146 | } 147 | 148 | if(R_SUCCEEDED(ret))printf("Done.\n"); 149 | 150 | bossExit(); 151 | 152 | return ret; 153 | } 154 | 155 | int main(int argc, char **argv) { 156 | 157 | Result ret = 0; 158 | 159 | gfxInitDefault(); 160 | consoleInit(GFX_TOP, NULL); 161 | 162 | ret = setup_boss(); 163 | if(R_FAILED(ret))printf("setup_boss() failed: 0x%08x.\n", (unsigned int)ret); 164 | 165 | printf("Press START to exit.\n"); 166 | 167 | // Main loop 168 | while (aptMainLoop()) { 169 | 170 | gspWaitForVBlank(); 171 | hidScanInput(); 172 | 173 | // Your code goes here 174 | 175 | u32 kDown = hidKeysDown(); 176 | if (kDown & KEY_START) 177 | break; // break in order to return to hbmenu 178 | 179 | // Flush and swap framebuffers 180 | gfxFlushBuffers(); 181 | gfxSwapBuffers(); 182 | } 183 | 184 | gfxExit(); 185 | return 0; 186 | } 187 | 188 | -------------------------------------------------------------------------------- /3ds-examples-master/network/http/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include <3ds.h> 7 | 8 | Result http_download(const char *url) 9 | { 10 | Result ret=0; 11 | httpcContext context; 12 | char *newurl=NULL; 13 | u8* framebuf_top; 14 | u32 statuscode=0; 15 | u32 contentsize=0, readsize=0, size=0; 16 | u8 *buf, *lastbuf; 17 | 18 | printf("Downloading %s\n",url); 19 | 20 | do { 21 | ret = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1); 22 | printf("return from httpcOpenContext: %" PRId32 "\n",ret); 23 | 24 | // This disables SSL cert verification, so https:// will be usable 25 | ret = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify); 26 | printf("return from httpcSetSSLOpt: %" PRId32 "\n",ret); 27 | 28 | // Enable Keep-Alive connections 29 | ret = httpcSetKeepAlive(&context, HTTPC_KEEPALIVE_ENABLED); 30 | printf("return from httpcSetKeepAlive: %" PRId32 "\n",ret); 31 | 32 | // Set a User-Agent header so websites can identify your application 33 | ret = httpcAddRequestHeaderField(&context, "User-Agent", "httpc-example/1.0.0"); 34 | printf("return from httpcAddRequestHeaderField: %" PRId32 "\n",ret); 35 | 36 | // Tell the server we can support Keep-Alive connections. 37 | // This will delay connection teardown momentarily (typically 5s) 38 | // in case there is another request made to the same server. 39 | ret = httpcAddRequestHeaderField(&context, "Connection", "Keep-Alive"); 40 | printf("return from httpcAddRequestHeaderField: %" PRId32 "\n",ret); 41 | 42 | ret = httpcBeginRequest(&context); 43 | if(ret!=0){ 44 | httpcCloseContext(&context); 45 | if(newurl!=NULL) free(newurl); 46 | return ret; 47 | } 48 | 49 | ret = httpcGetResponseStatusCode(&context, &statuscode); 50 | if(ret!=0){ 51 | httpcCloseContext(&context); 52 | if(newurl!=NULL) free(newurl); 53 | return ret; 54 | } 55 | 56 | if ((statuscode >= 301 && statuscode <= 303) || (statuscode >= 307 && statuscode <= 308)) { 57 | if(newurl==NULL) newurl = (char*)malloc(0x1000); // One 4K page for new URL 58 | if (newurl==NULL){ 59 | httpcCloseContext(&context); 60 | return -1; 61 | } 62 | ret = httpcGetResponseHeader(&context, "Location", newurl, 0x1000); 63 | url = newurl; // Change pointer to the url that we just learned 64 | printf("redirecting to url: %s\n",url); 65 | httpcCloseContext(&context); // Close this context before we try the next 66 | } 67 | } while ((statuscode >= 301 && statuscode <= 303) || (statuscode >= 307 && statuscode <= 308)); 68 | 69 | if(statuscode!=200){ 70 | printf("URL returned status: %" PRId32 "\n", statuscode); 71 | httpcCloseContext(&context); 72 | if(newurl!=NULL) free(newurl); 73 | return -2; 74 | } 75 | 76 | // This relies on an optional Content-Length header and may be 0 77 | ret=httpcGetDownloadSizeState(&context, NULL, &contentsize); 78 | if(ret!=0){ 79 | httpcCloseContext(&context); 80 | if(newurl!=NULL) free(newurl); 81 | return ret; 82 | } 83 | 84 | printf("reported size: %" PRId32 "\n",contentsize); 85 | 86 | // Start with a single page buffer 87 | buf = (u8*)malloc(0x1000); 88 | if(buf==NULL){ 89 | httpcCloseContext(&context); 90 | if(newurl!=NULL) free(newurl); 91 | return -1; 92 | } 93 | 94 | do { 95 | // This download loop resizes the buffer as data is read. 96 | ret = httpcDownloadData(&context, buf+size, 0x1000, &readsize); 97 | size += readsize; 98 | if (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING){ 99 | lastbuf = buf; // Save the old pointer, in case realloc() fails. 100 | buf = (u8*)realloc(buf, size + 0x1000); 101 | if(buf==NULL){ 102 | httpcCloseContext(&context); 103 | free(lastbuf); 104 | if(newurl!=NULL) free(newurl); 105 | return -1; 106 | } 107 | } 108 | } while (ret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING); 109 | 110 | if(ret!=0){ 111 | httpcCloseContext(&context); 112 | if(newurl!=NULL) free(newurl); 113 | free(buf); 114 | return -1; 115 | } 116 | 117 | // Resize the buffer back down to our actual final size 118 | lastbuf = buf; 119 | buf = (u8*)realloc(buf, size); 120 | if(buf==NULL){ // realloc() failed. 121 | httpcCloseContext(&context); 122 | free(lastbuf); 123 | if(newurl!=NULL) free(newurl); 124 | return -1; 125 | } 126 | 127 | printf("downloaded size: %" PRId32 "\n",size); 128 | 129 | if(size>(240*400*3*2))size = 240*400*3*2; 130 | 131 | framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 132 | memcpy(framebuf_top, buf, size); 133 | 134 | gfxFlushBuffers(); 135 | gfxSwapBuffers(); 136 | 137 | framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 138 | memcpy(framebuf_top, buf, size); 139 | 140 | gfxFlushBuffers(); 141 | gfxSwapBuffers(); 142 | gspWaitForVBlank(); 143 | 144 | httpcCloseContext(&context); 145 | free(buf); 146 | if (newurl!=NULL) free(newurl); 147 | 148 | return 0; 149 | } 150 | 151 | int main() 152 | { 153 | Result ret=0; 154 | gfxInitDefault(); 155 | httpcInit(0); // Buffer size when POST/PUT. 156 | 157 | consoleInit(GFX_BOTTOM,NULL); 158 | 159 | ret=http_download("http://devkitpro.org/misc/httpexample_rawimg.rgb"); 160 | // Try the following for redirection to the above URL. 161 | // ret=http_download("http://tinyurl.com/hd8jwqx"); 162 | printf("return from http_download: %" PRId32 "\n",ret); 163 | 164 | // Main loop 165 | while (aptMainLoop()) 166 | { 167 | gspWaitForVBlank(); 168 | hidScanInput(); 169 | 170 | // Your code goes here 171 | 172 | u32 kDown = hidKeysDown(); 173 | if (kDown & KEY_START) 174 | break; // break in order to return to hbmenu 175 | 176 | } 177 | 178 | // Exit services 179 | httpcExit(); 180 | gfxExit(); 181 | return 0; 182 | } 183 | 184 | -------------------------------------------------------------------------------- /3ds-examples-master/network/sslc/source/ssl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include <3ds.h> 19 | 20 | #include "builtin_rootca_der.h" 21 | 22 | static char http_netreq[] = "GET /testpage HTTP/1.1\r\nUser-Agent: 3ds-examples_sslc\r\nConnection: close\r\nHost: yls8.mtheall.com\r\n\r\n"; 23 | 24 | char readbuf[0x400]; 25 | 26 | void network_request(char *hostname) 27 | { 28 | Result ret=0; 29 | 30 | struct addrinfo hints; 31 | struct addrinfo *resaddr = NULL, *resaddr_cur; 32 | int sockfd; 33 | 34 | sslcContext sslc_context; 35 | u32 RootCertChain_contexthandle=0; 36 | 37 | sockfd = socket(AF_INET, SOCK_STREAM, 0); 38 | if(sockfd==-1) 39 | { 40 | printf("Failed to create the socket.\n"); 41 | return; 42 | } 43 | 44 | memset(&hints, 0, sizeof(struct addrinfo)); 45 | hints.ai_family = AF_INET; 46 | hints.ai_socktype = SOCK_STREAM; 47 | 48 | printf("Resolving hostname...\n"); 49 | 50 | if(getaddrinfo(hostname, "443", &hints, &resaddr)!=0) 51 | { 52 | printf("getaddrinfo() failed.\n"); 53 | closesocket(sockfd); 54 | return; 55 | } 56 | 57 | printf("Connecting to the server...\n"); 58 | 59 | for(resaddr_cur = resaddr; resaddr_cur!=NULL; resaddr_cur = resaddr_cur->ai_next) 60 | { 61 | if(connect(sockfd, resaddr_cur->ai_addr, resaddr_cur->ai_addrlen)==0)break; 62 | } 63 | 64 | freeaddrinfo(resaddr); 65 | 66 | if(resaddr_cur==NULL) 67 | { 68 | printf("Failed to connect.\n"); 69 | closesocket(sockfd); 70 | return; 71 | } 72 | 73 | printf("Running sslc setup...\n"); 74 | 75 | ret = sslcCreateRootCertChain(&RootCertChain_contexthandle); 76 | if(R_FAILED(ret)) 77 | { 78 | printf("sslcCreateRootCertChain() failed: 0x%08x.\n", (unsigned int)ret); 79 | closesocket(sockfd); 80 | return; 81 | } 82 | 83 | ret = sslcAddTrustedRootCA(RootCertChain_contexthandle, (u8*)builtin_rootca_der, builtin_rootca_der_size, NULL); 84 | if(R_FAILED(ret)) 85 | { 86 | printf("sslcAddTrustedRootCA() failed: 0x%08x.\n", (unsigned int)ret); 87 | closesocket(sockfd); 88 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 89 | return; 90 | } 91 | 92 | ret = sslcCreateContext(&sslc_context, sockfd, SSLCOPT_Default, hostname); 93 | if(R_FAILED(ret)) 94 | { 95 | printf("sslcCreateContext() failed: 0x%08x.\n", (unsigned int)ret); 96 | closesocket(sockfd); 97 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 98 | return; 99 | } 100 | 101 | ret = sslcContextSetRootCertChain(&sslc_context, RootCertChain_contexthandle); 102 | if(R_FAILED(ret)) 103 | { 104 | printf("sslcContextSetRootCertChain() failed: 0x%08x.\n", (unsigned int)ret); 105 | sslcDestroyContext(&sslc_context); 106 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 107 | closesocket(sockfd); 108 | return; 109 | } 110 | 111 | printf("Starting the TLS connection...\n"); 112 | 113 | ret = sslcStartConnection(&sslc_context, NULL, NULL); 114 | if(R_FAILED(ret)) 115 | { 116 | printf("sslcStartConnection() failed: 0x%08x.\n", (unsigned int)ret); 117 | sslcDestroyContext(&sslc_context); 118 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 119 | closesocket(sockfd); 120 | return; 121 | } 122 | 123 | printf("Sending request...\n"); 124 | 125 | ret = sslcWrite(&sslc_context, (u8*)http_netreq, strlen(http_netreq)); 126 | if(R_FAILED(ret)) 127 | { 128 | printf("sslcWrite() failed: 0x%08x.\n", (unsigned int)ret); 129 | sslcDestroyContext(&sslc_context); 130 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 131 | closesocket(sockfd); 132 | return; 133 | } 134 | 135 | printf("Total sent size: 0x%x.\n", (unsigned int)ret); 136 | 137 | memset(readbuf, 0, sizeof(readbuf)); 138 | 139 | ret = sslcRead(&sslc_context, readbuf, sizeof(readbuf)-1, false); 140 | if(R_FAILED(ret)) 141 | { 142 | printf("sslcWrite() failed: 0x%08x.\n", (unsigned int)ret); 143 | sslcDestroyContext(&sslc_context); 144 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 145 | closesocket(sockfd); 146 | return; 147 | } 148 | 149 | printf("Total received size: 0x%x.\n", (unsigned int)ret); 150 | 151 | printf("Reply:\n%s\n", readbuf); 152 | 153 | sslcDestroyContext(&sslc_context); 154 | sslcDestroyRootCertChain(RootCertChain_contexthandle); 155 | 156 | closesocket(sockfd); 157 | } 158 | 159 | int main() 160 | { 161 | Result ret=0; 162 | u32 *soc_sharedmem, soc_sharedmem_size = 0x100000; 163 | 164 | gfxInitDefault(); 165 | consoleInit(GFX_TOP, NULL); 166 | 167 | printf("libctru sslc demo.\n"); 168 | 169 | soc_sharedmem = memalign(0x1000, soc_sharedmem_size); 170 | if(soc_sharedmem==NULL) 171 | { 172 | printf("Failed to allocate SOC sharedmem.\n"); 173 | } 174 | else 175 | { 176 | ret = socInit(soc_sharedmem, soc_sharedmem_size); 177 | 178 | if(R_FAILED(ret)) 179 | { 180 | printf("socInit failed: 0x%08x.\n", (unsigned int)ret); 181 | } 182 | else 183 | { 184 | ret = sslcInit(0); 185 | if(R_FAILED(ret)) 186 | { 187 | printf("sslcInit failed: 0x%08x.\n", (unsigned int)ret); 188 | } 189 | else 190 | { 191 | network_request("yls8.mtheall.com"); 192 | sslcExit(); 193 | } 194 | 195 | socExit(); 196 | } 197 | } 198 | 199 | printf("Press START to exit.\n"); 200 | 201 | // Main loop 202 | while (aptMainLoop()) 203 | { 204 | gspWaitForVBlank(); 205 | hidScanInput(); 206 | 207 | u32 kDown = hidKeysDown(); 208 | if (kDown & KEY_START) 209 | break; // break in order to return to hbmenu 210 | 211 | // Flush and swap framebuffers 212 | gfxFlushBuffers(); 213 | gfxSwapBuffers(); 214 | } 215 | 216 | gfxExit(); 217 | return 0; 218 | } 219 | --------------------------------------------------------------------------------