├── .gitignore ├── LICENSE ├── README.md ├── clock ├── 3ds.ld ├── bin │ └── empty.txt ├── build.bat ├── build.py ├── include │ ├── ctr │ │ ├── AC.h │ │ ├── APT.h │ │ ├── CFGNOR.h │ │ ├── CSND.h │ │ ├── FS.h │ │ ├── GPU.h │ │ ├── GSP.h │ │ ├── GX.h │ │ ├── HID.h │ │ ├── HTTPC.h │ │ ├── IR.h │ │ ├── OS.h │ │ ├── SHDR.h │ │ ├── SOC.h │ │ ├── srv.h │ │ ├── svc.h │ │ └── types.h │ ├── libntrplg │ │ ├── 3dstypes.h │ │ ├── constants.h │ │ ├── func.h │ │ ├── global.h │ │ ├── integer.h │ │ ├── memory.h │ │ ├── netdb.h │ │ ├── ns │ │ │ └── ns.h │ │ ├── sharedfunc.h │ │ └── xprintf.h │ ├── main.h │ ├── netinet │ │ ├── in.h │ │ └── tcp.h │ └── sys │ │ └── socket.h ├── lib │ ├── libc.a │ └── libgcc.a ├── obj │ └── empty.txt ├── source │ ├── bootloader.s │ ├── entry.c │ ├── font.h │ ├── libctru │ │ ├── AC.c │ │ ├── FS.c │ │ ├── OS.c │ │ ├── SOC.c │ │ ├── srv.c │ │ └── svc.s │ ├── libntrplg │ │ ├── pm.c │ │ ├── rt.c │ │ ├── sharedfunc.c │ │ └── stub.s │ ├── main.c │ ├── misc.s │ ├── ov.c │ └── ov.h └── startenv.bat └── fps ├── 3ds.ld ├── bin └── empty.txt ├── build.bat ├── build.py ├── include ├── ctr │ ├── AC.h │ ├── APT.h │ ├── CFGNOR.h │ ├── CSND.h │ ├── FS.h │ ├── GPU.h │ ├── GSP.h │ ├── GX.h │ ├── HID.h │ ├── HTTPC.h │ ├── IR.h │ ├── OS.h │ ├── SHDR.h │ ├── SOC.h │ ├── srv.h │ ├── svc.h │ └── types.h ├── libntrplg │ ├── 3dstypes.h │ ├── constants.h │ ├── func.h │ ├── global.h │ ├── integer.h │ ├── memory.h │ ├── netdb.h │ ├── ns │ │ └── ns.h │ ├── sharedfunc.h │ └── xprintf.h ├── main.h ├── netinet │ ├── in.h │ └── tcp.h └── sys │ └── socket.h ├── lib ├── libc.a └── libgcc.a ├── obj └── empty.txt ├── source ├── bootloader.s ├── entry.c ├── font.h ├── libctru │ ├── AC.c │ ├── FS.c │ ├── OS.c │ ├── SOC.c │ ├── srv.c │ └── svc.s ├── libntrplg │ ├── pm.c │ ├── rt.c │ ├── sharedfunc.c │ └── stub.s ├── main.c ├── misc.s ├── ov.c └── ov.h └── startenv.bat /.gitignore: -------------------------------------------------------------------------------- 1 | exefs.bin 2 | *.plg 3 | payload.bin 4 | exefs/ 5 | autogen.h 6 | *.map 7 | 8 | Release 9 | *.elf 10 | 11 | ## Ignore Visual Studio temporary files, build results, and 12 | ## files generated by popular Visual Studio add-ons. 13 | 14 | 15 | # User-specific files 16 | *.suo 17 | *.user 18 | *.sln.docstates 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Dd]ebugPublic/ 23 | x64/ 24 | x86/ 25 | build/ 26 | bld/ 27 | 28 | # Roslyn cache directories 29 | *.ide/ 30 | 31 | # MSTest test Results 32 | [Tt]est[Rr]esult*/ 33 | [Bb]uild[Ll]og.* 34 | 35 | #NUNIT 36 | *.VisualState.xml 37 | TestResult.xml 38 | 39 | # Build Results of an ATL Project 40 | [Dd]ebugPS/ 41 | [Rr]eleasePS/ 42 | dlldata.c 43 | 44 | *_i.c 45 | *_p.c 46 | *_i.h 47 | *.ilk 48 | *.meta 49 | *.obj 50 | *.pch 51 | *.pdb 52 | *.pgc 53 | *.pgd 54 | *.rsp 55 | *.sbr 56 | *.tlb 57 | *.tli 58 | *.tlh 59 | *.tmp 60 | *.tmp_proj 61 | *.log 62 | *.vspscc 63 | *.vssscc 64 | .builds 65 | *.pidb 66 | *.svclog 67 | *.scc 68 | *.o 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding addin-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | # TODO: Comment the next line if you want to checkin your web deploy settings 137 | # but database connection strings (with potential passwords) will be unencrypted 138 | *.pubxml 139 | *.publishproj 140 | 141 | # NuGet Packages 142 | *.nupkg 143 | # The packages folder can be ignored because of Package Restore 144 | **/packages/* 145 | # except build/, which is used as an MSBuild target. 146 | !**/packages/build/ 147 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 148 | #!**/packages/repositories.config 149 | 150 | # Windows Azure Build Output 151 | csx/ 152 | *.build.csdef 153 | 154 | # Windows Store app package directory 155 | AppPackages/ 156 | 157 | # Others 158 | sql/ 159 | *.Cache 160 | ClientBin/ 161 | [Ss]tyle[Cc]op.* 162 | ~$* 163 | *~ 164 | *.dbmdl 165 | *.dbproj.schemaview 166 | *.pfx 167 | *.publishsettings 168 | node_modules/ 169 | 170 | # RIA/Silverlight projects 171 | Generated_Code/ 172 | 173 | # Backup & report files from converting an old project file 174 | # to a newer Visual Studio version. Backup files are not needed, 175 | # because we have git ;-) 176 | _UpgradeReport_Files/ 177 | Backup*/ 178 | UpgradeLog*.XML 179 | UpgradeLog*.htm 180 | 181 | # SQL Server files 182 | *.mdf 183 | *.ldf 184 | 185 | # Business Intelligence projects 186 | *.rdl.data 187 | *.bim.layout 188 | *.bim_*.settings 189 | 190 | # Microsoft Fakes 191 | FakesAssemblies/ 192 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ntr_overlay_samples 2 | Sample overlay plugins for NTR CFW. 3 | 4 | Overlay plugin is a plugin that has ability to "postprocess" the game's screen while playing games. For example, drawing a clock widget on the top of the game's screen. 5 | 6 | 7 | # Clock 8 | Draw a transparent widget to display time and battery status on the top screen. 9 | 10 | # FPS 11 | 12 | Display fps on both screens. 13 | 14 | # Usage 15 | Copy .plg files to **/plugin/game** folder in the sdcard. Then the overlay plugins be loaded in every games. 16 | 17 | Precompiled .plg files could be found at https://github.com/44670/ntr_overlay_samples/releases 18 | -------------------------------------------------------------------------------- /clock/3ds.ld: -------------------------------------------------------------------------------- 1 | 2 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 3 | OUTPUT_ARCH(arm) 4 | ENTRY(_Reset) 5 | SECTIONS 6 | { 7 | . = 0x00100100; 8 | . = ALIGN(4); 9 | .text : { 10 | __text_start = .; 11 | bootloader.o (.text*) 12 | *(.text*) 13 | } 14 | . = ALIGN(4); 15 | .data : { 16 | *(.data) 17 | } 18 | . = ALIGN(4); 19 | 20 | . = ALIGN(4); 21 | .rel.dyn : { 22 | *(.__rel_dyn_start) 23 | *(.rel*) 24 | *(.rel.*) 25 | *(.__rel_dyn_end) 26 | } 27 | 28 | __code_end = .; 29 | 30 | . = ALIGN(4); 31 | .bss : { 32 | *(.__bss_start) 33 | *(.bss COMMON) 34 | *(.__bss_end) 35 | } 36 | __end__ = .; 37 | } 38 | -------------------------------------------------------------------------------- /clock/bin/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/clock/bin/empty.txt -------------------------------------------------------------------------------- /clock/build.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | build.py -------------------------------------------------------------------------------- /clock/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys 3 | import os 4 | import ftplib 5 | import glob 6 | 7 | # the path plugin was copied to 8 | COPYTOPATH = 'clock.plg' 9 | 10 | CC = "arm-none-eabi-gcc" 11 | CP = "arm-none-eabi-g++" 12 | OC = "arm-none-eabi-objcopy" 13 | LD = "arm-none-eabi-ld" 14 | CTRULIB = '../libctru' 15 | DEVKITARM = 'c:/devkitPro/devkitARM' 16 | LIBPATH = '-L ./lib' 17 | 18 | def allFile(pattern): 19 | s = ""; 20 | for file in glob.glob(pattern): 21 | s += file + " "; 22 | return s; 23 | 24 | def run(cmd): 25 | os.system(cmd) 26 | 27 | cwd = os.getcwd() 28 | run("rm obj/*.o") 29 | run("rm bin/*.elf") 30 | run(CC+ " -s -g -I include -I include/libntrplg " + allFile('source/libntrplg/*.c') + allFile('source/ns/*.c') + allFile('source/*.c') + allFile('source/libctru/*.c') + " -c -march=armv6 -mlittle-endian "); 31 | run(CC+" -Os " + allFile('source/libntrplg/*.s') + allFile('source/ns/*.s') + allFile('source/*.s') + allFile('source/libctru/*.s') + " -c -s -march=armv6 -mlittle-endian "); 32 | 33 | run(LD + ' ' + LIBPATH + " -pie --print-gc-sections -T 3ds.ld -Map=homebrew.map " + allFile("*.o") + " -lc -lgcc --nostdlib" ) 34 | run("cp -r *.o obj/ ") 35 | run("cp a.out bin/homebrew.elf ") 36 | run(OC+" -O binary a.out payload.bin -S") 37 | run("rm *.o") 38 | run("rm *.out") 39 | run('copy payload.bin ' + COPYTOPATH); 40 | -------------------------------------------------------------------------------- /clock/include/ctr/AC.h: -------------------------------------------------------------------------------- 1 | #ifndef AC_H 2 | #define AC_H 3 | 4 | Result ACU_GetWifiStatus(Handle servhandle, u32 *out); 5 | Result ACU_WaitInternetConnection(); 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /clock/include/ctr/APT.h: -------------------------------------------------------------------------------- 1 | #ifndef APT_H 2 | #define APT_H 3 | 4 | typedef enum{ 5 | APPID_HOMEMENU = 0x101, // Home Menu 6 | APPID_CAMERA = 0x110, // Camera applet 7 | APPID_WEB = 0x114, // Internet Browser 8 | APPID_APPLICATION = 0x300, // Application 9 | }NS_APPID; // cf http://3dbrew.org/wiki/NS#AppIDs 10 | 11 | typedef enum{ 12 | APP_NOTINITIALIZED, 13 | APP_RUNNING, 14 | APP_SUSPENDED, 15 | APP_EXITING, 16 | APP_SUSPENDING, 17 | APP_SLEEPMODE, 18 | APP_PREPARE_SLEEPMODE 19 | }APP_STATUS; 20 | 21 | extern Handle aptEvents[3]; 22 | 23 | Result aptInit(NS_APPID appID); 24 | void aptExit(); 25 | void aptOpenSession(); 26 | void aptCloseSession(); 27 | void aptSetupEventHandler(); 28 | void aptSetStatus(APP_STATUS status); 29 | APP_STATUS aptGetStatus(); 30 | u32 aptGetStatusPower();//This can be used when the status is APP_SUSPEND* to check how the return-to-menu was triggered: 0 = home-button, 1 = power-button. 31 | void aptSetStatusPower(u32 status); 32 | void aptReturnToMenu();//This should be called by the user application when aptGetStatus() returns APP_SUSPENDING, not calling this will result in return-to-menu being disabled with the status left at APP_SUSPENDING. This function will not return until the system returns to the application, or when the status was changed to APP_EXITING. 33 | void aptWaitStatusEvent(); 34 | NS_APPID aptGetMenuAppID(); 35 | 36 | Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle); 37 | Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2); 38 | Result APT_Enable(Handle* handle, u32 a); 39 | Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid); 40 | Result APT_PrepareToJumpToHomeMenu(Handle* handle); 41 | Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c); 42 | Result APT_InquireNotification(Handle* handle, u32 appID, u8* signalType); 43 | Result APT_NotifyToWait(Handle* handle, NS_APPID appID); 44 | Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2); 45 | Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); 46 | Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); 47 | Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType); 48 | Result APT_SendCaptureBufferInfo(Handle* handle, u32 bufferSize, u32* buffer); 49 | Result APT_ReplySleepQuery(Handle* handle, NS_APPID appID, u32 a); 50 | Result APT_ReplySleepNotificationComplete(Handle* handle, NS_APPID appID); 51 | Result APT_PrepareToCloseApplication(Handle* handle, u8 a); 52 | Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /clock/include/ctr/CFGNOR.h: -------------------------------------------------------------------------------- 1 | #ifndef CFGNOR_H 2 | #define CFGNOR_H 3 | 4 | Result CFGNOR_Initialize(u8 value); 5 | Result CFGNOR_Shutdown(); 6 | Result CFGNOR_ReadData(u32 offset, u32 *buf, u32 size); 7 | Result CFGNOR_WriteData(u32 offset, u32 *buf, u32 size); 8 | Result CFGNOR_DumpFlash(u32 *buf, u32 size); 9 | Result CFGNOR_WriteFlash(u32 *buf, u32 size); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /clock/include/ctr/CSND.h: -------------------------------------------------------------------------------- 1 | #ifndef CSND_H 2 | #define CSND_H 3 | 4 | //See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory 5 | 6 | #define CSND_SHAREDMEM_DEFAULT 0x10004000 7 | 8 | typedef enum{ 9 | CSND_LOOP_DISABLE, 10 | CSND_LOOP_ENABLE 11 | } CSND_LOOPING; 12 | 13 | typedef enum{ 14 | CSND_ENCODING_PCM8, 15 | CSND_ENCODING_PCM16, 16 | CSND_ENCODING_IMA_ADPCM, 17 | CSND_ENCODING_PSG//"3 = PSG, similar to DS?" 18 | } CSND_ENCODING; 19 | 20 | Result CSND_initialize(u32* sharedMem); 21 | Result CSND_shutdown(); 22 | 23 | Result CSND_playsound(u32 channel, CSND_LOOPING looping, CSND_ENCODING encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1);//vaddr0 is the initial virtual-address of the audio-data. vaddr1 is the audio-data virtual-address used for looping, when playback is restarted for looping. 24 | void CSND_setchannel_playbackstate(u32 channel, u32 value);//value0 = pause playback, value1 = resume playback. 25 | void CSND_sharedmemtype0_cmd0(u32 channel, u32 value);//value1 = start playback. value0 = stop playback, and reset the CSND registers for this channel. 26 | void CSND_writesharedmem_cmdtype0(u16 cmdid, u8 *cmdparams);//This can be used to use arbitary CSND shared-memory commands. 27 | Result CSND_sharedmemtype0_cmdupdatestate(int waitdone);//This must be used after using CSND shared-memory commands in order for those commands to be processed. CSND_playsound() and CSND_getchannelstate() use this automatically. 28 | 29 | Result CSND_getchannelstate(u32 entryindex, u32 *out); 30 | Result CSND_getchannelstate_isplaying(u32 entryindex, u8 *status); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /clock/include/ctr/FS.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_H 2 | #define FS_H 3 | 4 | #define FS_OPEN_READ (1<<0) 5 | #define FS_OPEN_WRITE (1<<1) 6 | #define FS_OPEN_CREATE (1<<2) 7 | 8 | #define FS_ATTRIBUTE_NONE (0x00000000) 9 | #define FS_ATTRIBUTE_READONLY (0x00000001) 10 | #define FS_ATTRIBUTE_ARCHIVE (0x00000100) 11 | #define FS_ATTRIBUTE_HIDDEN (0x00010000) 12 | #define FS_ATTRIBUTE_DIRECTORY (0x01000000) 13 | 14 | typedef enum{ 15 | PATH_INVALID = 0, // Specifies an invalid path. 16 | PATH_EMPTY = 1, // Specifies an empty path. 17 | PATH_BINARY = 2, // Specifies a binary path, which is non-text based. 18 | PATH_CHAR = 3, // Specifies a text based path with a 8-bit byte per character. 19 | PATH_WCHAR = 4, // Specifies a text based path with a 16-bit short per character. 20 | }FS_pathType; 21 | 22 | typedef struct{ 23 | FS_pathType type; 24 | u32 size; 25 | u8* data; 26 | }FS_path; 27 | 28 | typedef struct{ 29 | u32 id; 30 | FS_path lowPath; 31 | Handle handleLow, handleHigh; 32 | }FS_archive; 33 | 34 | static inline FS_path FS_makePath(FS_pathType type, char* path) 35 | { 36 | return (FS_path){type, strlen(path)+1, (u8*)path}; 37 | } 38 | 39 | Result FSUSER_Initialize(Handle handle); 40 | Result FSUSER_OpenArchive(Handle handle, FS_archive* archive); 41 | Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath); 42 | Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); 43 | Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); 44 | Result FSUSER_CloseArchive(Handle handle, FS_archive* archive); 45 | 46 | Result FSFILE_Close(Handle handle); 47 | Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size); 48 | Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *buffer, u32 size, u32 flushFlags); 49 | Result FSFILE_GetSize(Handle handle, u64 *size); 50 | Result FSFILE_SetSize(Handle handle, u64 size); 51 | 52 | Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer); 53 | Result FSDIR_Close(Handle handle); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /clock/include/ctr/GPU.h: -------------------------------------------------------------------------------- 1 | #ifndef GPU_H 2 | #define GPU_H 3 | 4 | void GPU_Init(Handle *gsphandle); 5 | void GPU_Reset(u32* gxbuf, u32* gpuBuf, u32 gpuBufSize); 6 | 7 | void GPUCMD_SetBuffer(u32* adr, u32 size, u32 offset); 8 | void GPUCMD_Run(u32* gxbuf); 9 | void GPUCMD_Add(u32 cmd, u32* param, u32 paramlength); 10 | void GPUCMD_AddSingleParam(u32 cmd, u32 param); 11 | void GPUCMD_Finalize(); 12 | 13 | typedef enum{ 14 | GPU_RGBA8=0x0, 15 | GPU_RGB8=0x1, 16 | GPU_RGBA5551=0x2, 17 | GPU_RGB565=0x3, 18 | GPU_RGBA4=0x4, 19 | GPU_LA8=0x5, 20 | GPU_HILO8=0x6, 21 | GPU_L8=0x7, 22 | GPU_A8=0x8, 23 | GPU_LA4=0x9, 24 | GPU_L4=0xA, 25 | GPU_ETC1=0xB, 26 | GPU_ETC1A4=0xC 27 | }GPU_TEXCOLOR; 28 | 29 | typedef enum 30 | { 31 | GPU_NEVER = 0, 32 | GPU_ALWAYS = 1, 33 | GPU_EQUAL = 2, 34 | GPU_NOTEQUAL = 3, 35 | GPU_LESS = 4, 36 | GPU_LEQUAL = 5, 37 | GPU_GREATER = 6, 38 | GPU_GEQUAL = 7 39 | }GPU_TESTFUNC; 40 | 41 | typedef enum{ 42 | GPU_BYTE = 0, 43 | GPU_UNSIGNED_BYTE = 1, 44 | GPU_SHORT = 2, 45 | GPU_FLOAT = 3 46 | }GPU_FORMATS; 47 | 48 | //defines for CW ? 49 | typedef enum{ 50 | GPU_CULL_NONE = 0, 51 | GPU_CULL_FRONT_CCW = 1, 52 | GPU_CULL_BACK_CCW = 2 53 | }GPU_CULLMODE; 54 | 55 | #define GPU_ATTRIBFMT(i, n, f) (((((n)-1)<<2)|((f)&3))<<((i)*4)) 56 | 57 | typedef enum{ 58 | GPU_PRIMARY_COLOR = 0x00, 59 | GPU_TEXTURE0 = 0x03, 60 | GPU_TEXTURE1 = 0x04, 61 | GPU_TEXTURE2 = 0x05, 62 | GPU_TEXTURE3 = 0x06, 63 | GPU_CONSTANT = 0x0E, 64 | GPU_PREVIOUS = 0x0F, 65 | }GPU_TEVSRC; 66 | 67 | typedef enum{ 68 | GPU_REPLACE = 0x00, 69 | GPU_MODULATE = 0x01, 70 | GPU_ADD = 0x02, 71 | GPU_ADD_SIGNED = 0x03, 72 | GPU_INTERPOLATE = 0x04, 73 | GPU_SUBTRACT = 0x05, 74 | GPU_DOT3_RGB = 0x06 //RGB only 75 | }GPU_COMBINEFUNC; 76 | 77 | #define GPU_TEVSOURCES(a,b,c) (((a))|((b)<<4)|((c)<<8)) 78 | #define GPU_TEVOPERANDS(a,b,c) (((a))|((b)<<4)|((c)<<8)) 79 | 80 | void GPU_SetUniform(u32 startreg, u32* data, u32 numreg); 81 | void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h); 82 | void GPU_DepthRange(float nearVal, float farVal); 83 | void GPU_SetDepthTest(bool enable, GPU_TESTFUNC function, u8 ref); 84 | void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref); 85 | void GPU_SetFaceCulling(GPU_CULLMODE mode); 86 | void GPU_SetAttributeBuffers(u8 totalAttributes, u32* baseAddress, u64 attributeFormats, u16 attributeMask, u64 attributePermutation, u8 numBuffers, u32 bufferOffsets[], u64 bufferPermutations[], u8 bufferNumAttributes[]); 87 | void GPU_SetTexture(u32* data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType); 88 | void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /clock/include/ctr/GSP.h: -------------------------------------------------------------------------------- 1 | #ifndef GSP_H 2 | #define GSP_H 3 | 4 | #define GSP_REBASE_REG(r) ((r)-0x1EB00000) 5 | 6 | typedef struct 7 | { 8 | u32 active_framebuf;//"0=first, 1=second" 9 | u32 *framebuf0_vaddr;//"Framebuffer virtual address, for the main screen this is the 3D left framebuffer" 10 | u32 *framebuf1_vaddr;//"For the main screen: 3D right framebuffer address" 11 | u32 framebuf_widthbytesize;//"Value for 0x1EF00X90, controls framebuffer width" 12 | u32 format;//"Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70." 13 | u32 framebuf_dispselect;//"Value for 0x1EF00X78, controls which framebuffer is displayed" 14 | u32 unk;//"?" 15 | } GSP_FramebufferInfo; 16 | 17 | typedef struct//See this for GSP_CaptureInfoEntry and GSP_CaptureInfo: http://3dbrew.org/wiki/GSPGPU:ImportDisplayCaptureInfo 18 | { 19 | u32 *framebuf0_vaddr; 20 | u32 *framebuf1_vaddr; 21 | u32 format; 22 | u32 framebuf_widthbytesize; 23 | } GSP_CaptureInfoEntry; 24 | 25 | typedef struct 26 | { 27 | GSP_CaptureInfoEntry screencapture[2]; 28 | } GSP_CaptureInfo; 29 | 30 | Result gspInit(); 31 | void gspExit(); 32 | 33 | Result GSPGPU_AcquireRight(Handle *handle, u8 flags); 34 | Result GSPGPU_ReleaseRight(Handle *handle); 35 | Result GSPGPU_ImportDisplayCaptureInfo(Handle* handle, GSP_CaptureInfo *captureinfo); 36 | Result GSPGPU_SaveVramSysArea(Handle* handle); 37 | Result GSPGPU_RestoreVramSysArea(Handle* handle); 38 | Result GSPGPU_SetLcdForceBlack(Handle *handle, u8 flags); 39 | Result GSPGPU_SetBufferSwap(Handle* handle, u32 screenid, GSP_FramebufferInfo *framebufinfo); 40 | Result GSPGPU_FlushDataCache(Handle *handle, u8* adr, u32 size); 41 | Result GSPGPU_InvalidateDataCache(Handle* handle, u8* adr, u32 size); 42 | Result GSPGPU_WriteHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); 43 | Result GSPGPU_WriteHWRegsWithMask(Handle* handle, u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize); 44 | Result GSPGPU_ReadHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); 45 | Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID); 46 | Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle); 47 | Result GSPGPU_TriggerCmdReqQueue(Handle *handle); 48 | 49 | Result GSPGPU_submitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /clock/include/ctr/GX.h: -------------------------------------------------------------------------------- 1 | #ifndef GX_H 2 | #define GX_H 3 | 4 | #define GX_BUFFER_DIM(w, h) (((h)<<16)|((w)&0xFFFF)) 5 | 6 | Result GX_RequestDma(u32* gxbuf, u32* src, u32* dst, u32 length); 7 | Result GX_SetCommandList_Last(u32* gxbuf, u32* buf0a, u32 buf0s, u8 flags); 8 | Result GX_SetMemoryFill(u32* gxbuf, u32* buf0a, u32 buf0v, u32* buf0e, u16 width0, u32* buf1a, u32 buf1v, u32* buf1e, u16 width1); 9 | Result GX_SetDisplayTransfer(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 flags); 10 | Result GX_SetTextureCopy(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags); 11 | Result GX_SetCommandList_First(u32* gxbuf, u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /clock/include/ctr/HID.h: -------------------------------------------------------------------------------- 1 | #ifndef HID_H 2 | #define HID_H 3 | 4 | #define HID_SHAREDMEM_DEFAULT (0x10000000) 5 | 6 | #define CPAD_X(v) ((s16)((v)&0xFFFF)) 7 | #define CPAD_Y(v) ((s16)(((v>>16))&0xFFFF)) 8 | 9 | #define TOUCH_X(v) ((u16)((v)&0xFFFF)) 10 | #define TOUCH_Y(v) ((u16)(((v>>16))&0xFFFF)) 11 | 12 | typedef enum 13 | { 14 | PAD_A = (1<<0), 15 | PAD_B = (1<<1), 16 | PAD_SELECT = (1<<2), 17 | PAD_START = (1<<3), 18 | PAD_RIGHT = (1<<4), 19 | PAD_LEFT = (1<<5), 20 | PAD_UP = (1<<6), 21 | PAD_DOWN = (1<<7), 22 | PAD_R = (1<<8), 23 | PAD_L = (1<<9), 24 | PAD_X = (1<<10), 25 | PAD_Y = (1<<11) 26 | }PAD_KEY; 27 | 28 | extern Handle hidMemHandle; 29 | extern vu32* hidSharedMem; 30 | 31 | Result hidInit(u32* sharedMem); 32 | void hidExit(); 33 | 34 | Result HIDUSER_GetInfo(Handle* handle, Handle* outMemHandle); 35 | Result HIDUSER_EnableAccelerometer(Handle* handle); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /clock/include/ctr/HTTPC.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPC_H 2 | #define HTTPC_H 3 | 4 | Result HTTPC_Initialize(Handle handle); 5 | Result HTTPC_InitializeConnectionSession(Handle handle, Handle contextHandle); 6 | Result HTTPC_CreateContext(Handle handle, char* url, Handle* contextHandle); 7 | Result HTTPC_CloseContext(Handle handle, Handle contextHandle); 8 | Result HTTPC_SetProxyDefault(Handle handle, Handle contextHandle); 9 | Result HTTPC_AddRequestHeaderField(Handle handle, Handle contextHandle, char* name, char* value); 10 | Result HTTPC_BeginRequest(Handle handle, Handle contextHandle); 11 | Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /clock/include/ctr/IR.h: -------------------------------------------------------------------------------- 1 | #ifndef IR_H 2 | #define IR_H 3 | 4 | Result IRU_Initialize(u32 *sharedmem_addr, u32 sharedmem_size);//The permissions for the specified memory is set to RO. This memory must be already mapped. 5 | Result IRU_Shutdown(); 6 | Handle IRU_GetServHandle(); 7 | Result IRU_SendData(u8 *buf, u32 size, u32 wait); 8 | Result IRU_RecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, u32 wait); 9 | Result IRU_SetBitRate(u8 value); 10 | Result IRU_GetBitRate(u8 *out); 11 | Result IRU_SetIRLEDState(u32 value); 12 | Result IRU_GetIRLEDRecvState(u32 *out); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /clock/include/ctr/OS.h: -------------------------------------------------------------------------------- 1 | #ifndef OS_H 2 | #define OS_H 3 | 4 | u32 OS_ConvertVaddr2Physaddr(u32 vaddr); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /clock/include/ctr/SHDR.h: -------------------------------------------------------------------------------- 1 | #ifndef SHDR_H 2 | #define SHDR_H 3 | 4 | typedef enum{ 5 | VERTEX_SHDR=0x0, 6 | GEOMETRY_SHDR=0x1 7 | }SHDR_type; 8 | 9 | typedef enum{ 10 | RESULT_POSITION = 0x0, 11 | RESULT_COLOR = 0x2, 12 | RESULT_TEXCOORD0 = 0x3, 13 | RESULT_TEXCOORD1 = 0x5, 14 | RESULT_TEXCOORD2 = 0x6 15 | }SHDR_outType; 16 | 17 | typedef struct{ 18 | u32 codeSize; 19 | u32* codeData; 20 | u32 opdescSize; 21 | u32* opcdescData; 22 | }DVLP_s; 23 | 24 | typedef struct{ 25 | u32 header; 26 | u32 data[4]; 27 | }DVLE_constEntry_s; 28 | 29 | typedef struct{ 30 | u16 type; 31 | u16 regID; 32 | u32 header; 33 | }DVLE_outEntry_s; 34 | 35 | typedef struct{ 36 | u32 symbolOffset; 37 | u16 startReg; 38 | u16 endReg; 39 | }DVLE_uniformEntry_s; 40 | 41 | typedef struct{ 42 | SHDR_type type; 43 | u32 mainOffset, endmainOffset; 44 | u32 constTableSize; 45 | DVLE_constEntry_s* constTableData; 46 | u32 outTableSize; 47 | DVLE_outEntry_s* outTableData; 48 | u32 uniformTableSize; 49 | DVLE_uniformEntry_s* uniformTableData; 50 | char* symbolTableData; 51 | }DVLE_s; 52 | 53 | typedef struct{ 54 | u32 numDVLE; 55 | DVLP_s DVLP; 56 | DVLE_s* DVLE; 57 | }DVLB_s; 58 | 59 | 60 | DVLB_s* SHDR_ParseSHBIN(u32* shbinData, u32 shbinSize); 61 | void SHDR_UseProgram(DVLB_s* dvlb, u8 id); 62 | void SHDR_FreeDVLB(DVLB_s* dvlb); 63 | s8 SHDR_GetUniformRegister(DVLB_s* dvlb, char* name, u8 programID); 64 | 65 | void DVLP_SendCode(DVLP_s* dvlp); 66 | void DVLP_SendOpDesc(DVLP_s* dvlp); 67 | 68 | void DVLE_SendOutmap(DVLE_s* dvle); 69 | void DVLE_SendConstants(DVLE_s* dvle); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /clock/include/ctr/SOC.h: -------------------------------------------------------------------------------- 1 | #ifndef SOC_H 2 | #define SOC_H 3 | 4 | extern Handle SOCU_handle; 5 | 6 | Result SOC_Initialize(u32 *context_addr, u32 context_size);//Example context_size: 0x48000. The specified context buffer can no longer be accessed by the process which called this function, since the userland permissions for this block are set to no-access. 7 | Result SOC_Shutdown(); 8 | int SOC_GetErrno(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /clock/include/ctr/srv.h: -------------------------------------------------------------------------------- 1 | #ifndef SRV_H 2 | #define SRV_H 3 | 4 | Result initSrv(); 5 | Result exitSrv(); 6 | Result srv_RegisterClient(Handle* handleptr); 7 | Result srv_getServiceHandle(Handle* handleptr, Handle* out, char* server); 8 | 9 | extern Handle srvHandle; 10 | #endif 11 | -------------------------------------------------------------------------------- /clock/include/ctr/svc.h: -------------------------------------------------------------------------------- 1 | #ifndef SVC_H 2 | #define SVC_H 3 | 4 | typedef enum{ 5 | MEMOP_FREE = 1, 6 | MEMOP_RESERVE = 2, 7 | MEMOP_COMMIT = 3, 8 | MEMOP_MAP = 4, 9 | MEMOP_UNMAP = 5, 10 | MEMOP_PROTECT = 6, 11 | MEMOP_REGION_APP = 0x100, 12 | MEMOP_REGION_SYSTEM = 0x200, 13 | MEMOP_REGION_BASE = 0x300, 14 | MEMOP_LINEAR = 0x1000, 15 | }MEMORY_OPERATION; 16 | 17 | u32* getThreadCommandBuffer(void); 18 | 19 | Result svc_getDmaState(u32* state, Handle dma); 20 | Result svc_startInterProcessDma(Handle* hdma, Handle dstProcess, void* dst, Handle srcProcess, const void* src, u32 size, u32* config); 21 | 22 | Result svc_writeProcessMemory(Handle debug, void const* buffer, u32 addr, u32 size); 23 | Result svc_readProcessMemory(void* buffer, Handle debug, u32 addr, u32 size); 24 | Result svc_debugActiveProcess(s32* handle_out, u32 pid); 25 | Result svc_getProcessList(s32* processCount, u32* processIds, s32 processIdMaxCount); 26 | 27 | Result svc_controlProcessMemory(Handle hProcess, void* Addr0, void* Addr1, u32 size, u32 Type, u32 Permissions); 28 | 29 | Result svc_openProcess(Handle* process, u32 processId); 30 | Result svc_addCodeSegment(u32 addr, u32 size); 31 | Result svc_flushProcessDataCache(Handle handle, u32 addr, u32 size); 32 | Result svc_invalidateProcessDataCache(Handle handle, u32 addr, u32 size); 33 | Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0) 34 | void svc_exitProcess(void); 35 | Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid); 36 | void svc_exitThread(); 37 | void svc_sleepThread(s64 ns); 38 | Result svc_createMutex(Handle* mutex, bool initialLocked); 39 | Result svc_releaseMutex(Handle handle); 40 | Result svc_releaseSemaphore(s32* count, Handle semaphore, s32 releaseCount); 41 | Result svc_createEvent(Handle* event, u8 resettype); 42 | Result svc_signalEvent(Handle handle); 43 | Result svc_clearEvent(Handle handle); 44 | Result svc_createMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 mypermission, u32 otherpermission); 45 | Result svc_mapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherpermission); 46 | Result svc_unmapMemoryBlock(Handle memblock, u32 addr); 47 | Result svc_waitSynchronization1(Handle handle, s64 nanoseconds); 48 | Result svc_waitSynchronizationN(s32* out, Handle* handles, s32 handlecount, bool waitAll, s64 nanoseconds); 49 | Result svc_arbitrateAddress(Handle arbiter, u32 addr, u8 type, s32 value, s64 nanoseconds); 50 | Result svc_closeHandle(Handle handle); 51 | u64 svc_getSystemTick(); 52 | Result svc_getSystemInfo(s64* out, u32 type, s32 param); 53 | Result svc_connectToPort(volatile Handle* out, const char* portName); 54 | Result svc_sendSyncRequest(Handle session); 55 | Result svc_getProcessId(u32 *out, Handle handle); 56 | Result svc_getThreadId(u32 *out, Handle handle); 57 | Result svc_setThreadIdealProcessor(Handle handle, u32 processorid); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /clock/include/ctr/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | #include 6 | 7 | #define U64_MAX UINT64_MAX 8 | 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | 14 | typedef int8_t s8; 15 | typedef int16_t s16; 16 | typedef int32_t s32; 17 | typedef int64_t s64; 18 | 19 | typedef volatile u8 vu8; 20 | typedef volatile u16 vu16; 21 | typedef volatile u32 vu32; 22 | typedef volatile u64 vu64; 23 | 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | typedef u32 Handle; 30 | typedef s32 Result; 31 | typedef void (*ThreadFunc)(u32); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /clock/include/libntrplg/3dstypes.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | ndstypes.h -- Common types (and a few useful macros) 4 | 5 | Copyright (C) 2005 - 2008 6 | Michael Noland (joat) 7 | Jason Rogers (dovoto) 8 | Dave Murphy (WinterMute) 9 | Chris Double (doublec) 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any 13 | damages arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any 16 | purpose, including commercial applications, and to alter it and 17 | redistribute it freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you 20 | must not claim that you wrote the original software. If you use 21 | this software in a product, an acknowledgment in the product 22 | documentation would be appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and 24 | must not be misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source 26 | distribution. 27 | 28 | ---------------------------------------------------------------------------------*/ 29 | /*! \file ndstypes.h 30 | \brief Custom types employed by libnds 31 | */ 32 | 33 | /// Note by Kane49: I kept in stuff i dont use to not mess with stuff i dont understand, this provides some convenient stuff though ! 34 | 35 | #ifndef _3DSTYPES_INCLUDE 36 | #define _3DSTYPES_INCLUDE 37 | //--------------------------------------------------------------------------------- 38 | // define libnds types in terms of stdint 39 | #include 40 | #include 41 | 42 | 43 | 44 | //--------------------------------------------------------------------------------- 45 | // libgba compatible section macros 46 | //--------------------------------------------------------------------------------- 47 | #define ITCM_CODE __attribute__((section(".itcm"), long_call)) 48 | 49 | #define DTCM_DATA __attribute__((section(".dtcm"))) 50 | #define DTCM_BSS __attribute__((section(".sbss"))) 51 | 52 | //! aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. 53 | #define ALIGN(m) __attribute__((aligned (m))) 54 | 55 | //! packs a struct (and other types?) so it won't include padding bytes. 56 | #define PACKED __attribute__ ((packed)) 57 | #define packed_struct struct PACKED 58 | 59 | //--------------------------------------------------------------------------------- 60 | // These are linked to the bin2o macro in the Makefile 61 | //--------------------------------------------------------------------------------- 62 | #define GETRAW(name) (name) 63 | #define GETRAWSIZE(name) ((int)name##_size) 64 | #define GETRAWEND(name) ((int)name##_end) 65 | 66 | 67 | /*! 68 | \brief returns a number with the nth bit set. 69 | */ 70 | #define BIT(n) (1 << (n)) 71 | 72 | //! 8 bit unsigned integer. 73 | typedef uint8_t uint8; 74 | //! 16 bit unsigned integer. 75 | typedef uint16_t uint16; 76 | //! 32 bit unsigned integer. 77 | typedef uint32_t uint32; 78 | //! 64 bit unsigned integer. 79 | typedef uint64_t uint64; 80 | 81 | //! 8 bit signed integer. 82 | typedef int8_t int8; 83 | //! 16 bit signed integer. 84 | typedef int16_t int16; 85 | //! 32 bit signed integer. 86 | typedef int32_t int32; 87 | //! 64 bit signed integer. 88 | typedef int64_t int64; 89 | 90 | //! 32 bit signed floating point number. 91 | typedef float float32; 92 | //! 64 bit signed floating point number. 93 | typedef double float64; 94 | 95 | //! 8 bit volatile unsigned integer. 96 | typedef volatile uint8_t vuint8; 97 | //! 16 bit volatile unsigned integer. 98 | typedef volatile uint16_t vuint16; 99 | //! 32 bit volatile unsigned integer. 100 | typedef volatile uint32_t vuint32; 101 | //! 64 bit volatile unsigned integer. 102 | typedef volatile uint64_t vuint64; 103 | 104 | //! 8 bit volatile signed integer. 105 | typedef volatile int8_t vint8; 106 | //! 16 bit volatile signed integer. 107 | typedef volatile int16_t vint16; 108 | //! 32 bit volatile signed integer. 109 | typedef volatile int32_t vint32; 110 | //! 64 bit volatile signed integer. 111 | typedef volatile int64_t vint64; 112 | 113 | //! 32 bit volatile signed floating point number. 114 | typedef volatile float32 vfloat32; 115 | //! 64 bit volatile signed floating point number. 116 | typedef volatile float64 vfloat64; 117 | 118 | //! 8 bit unsigned integer. 119 | typedef uint8_t byte; 120 | 121 | //! 8 bit unsigned integer. 122 | typedef uint8_t u8; 123 | //! 16 bit unsigned integer. 124 | typedef uint16_t u16; 125 | //! 32 bit unsigned integer. 126 | typedef uint32_t u32; 127 | //! 64 bit unsigned integer. 128 | typedef uint64_t u64; 129 | 130 | //! 8 bit signed integer. 131 | typedef int8_t s8; 132 | //! 16 bit signed integer. 133 | typedef int16_t s16; 134 | //! 32 bit signed integer. 135 | typedef int32_t s32; 136 | //! 64 bit signed integer. 137 | typedef int64_t s64; 138 | 139 | //! 8 bit volatile unsigned integer. 140 | typedef volatile u8 vu8; 141 | //! 16 bit volatile unsigned integer. 142 | typedef volatile u16 vu16; 143 | //! 32 bit volatile unsigned integer. 144 | typedef volatile u32 vu32; 145 | //! 64 bit volatile unsigned integer. 146 | typedef volatile u64 vu64; 147 | 148 | //! 8 bit volatile signed integer. 149 | typedef volatile s8 vs8; 150 | //! 16 bit volatile signed integer. 151 | typedef volatile s16 vs16; 152 | //! 32 bit volatile signed integer. 153 | typedef volatile s32 vs32; 154 | //! 64 bit volatile signed integer. 155 | typedef volatile s64 vs64; 156 | 157 | struct RECT { 158 | int x, y, w, h; 159 | }; 160 | 161 | typedef struct RECT rect; 162 | 163 | struct POINT { 164 | int x, y; 165 | }; 166 | 167 | typedef struct POINT point; 168 | 169 | struct COLOR { 170 | u8 r, g, b; 171 | }; 172 | 173 | typedef struct COLOR color; 174 | 175 | 176 | #ifndef TRUE 177 | #define TRUE 1 178 | #define FALSE 0 179 | #endif 180 | 181 | 182 | // Handy function pointer typedefs 183 | //! a function pointer that takes no arguments and doesn't return anything. 184 | typedef void (* VoidFn)(void); 185 | 186 | typedef void (* IntFn)(void); 187 | typedef void (* fp)(void); 188 | 189 | //--------------------------------------------------------------------------------- 190 | #endif 191 | //--------------------------------------------------------------------------------- 192 | -------------------------------------------------------------------------------- /clock/include/libntrplg/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | #define BUTTON_A 0x00000001 5 | #define BUTTON_B 0x00000002 6 | #define BUTTON_SE 0x00000004 7 | #define BUTTON_ST 0x00000008 8 | #define BUTTON_DR 0x00000010 9 | #define BUTTON_DL 0x00000020 10 | #define BUTTON_DU 0x00000040 11 | #define BUTTON_DD 0x00000080 12 | #define BUTTON_R 0x00000100 13 | #define BUTTON_L 0x00000200 14 | #define BUTTON_X 0x00000400 15 | #define BUTTON_Y 0x00000800 16 | 17 | #endif -------------------------------------------------------------------------------- /clock/include/libntrplg/func.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNC_H 2 | #define FUNC_H 3 | 4 | #if IS_PLUGIN 5 | #define INIT_SHARED_FUNC(name,id) rtGenerateJumpCode(((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[id], (void*) name);rtFlushInstructionCache((void*) name, 8); 6 | #else 7 | #define INIT_SHARED_FUNC(name,id) (g_nsConfig->sharedFunc[id] = (u32) name) 8 | #endif 9 | 10 | 11 | u32 protectRemoteMemory(Handle hProcess, void* addr, u32 size); 12 | u32 protectMemory(void* addr, u32 size); 13 | 14 | 15 | 16 | extern Handle fsUserHandle; 17 | extern FS_archive sdmcArchive; 18 | 19 | 20 | 21 | #define MAX_PLUGIN_COUNT 32 22 | 23 | typedef struct _PLGLOADER_INFO { 24 | u32 plgCount; 25 | u32 plgBufferPtr[MAX_PLUGIN_COUNT]; 26 | u32 plgSize[MAX_PLUGIN_COUNT]; 27 | u32 arm11BinStart; 28 | u32 arm11BinSize; 29 | u32 tid[2]; 30 | } PLGLOADER_INFO; 31 | 32 | void updateScreen(); 33 | s32 showMenu(u8* title, u32 entryCount, u8* captions[]); 34 | int showMsg(u8* msg); 35 | void showDbg(u8* fmt, u32 v1, u32 v2); 36 | void kmemcpy(void* dst, void* src, u32 size) ; 37 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 38 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 39 | 40 | #define CURRENT_PROCESS_HANDLE 0xffff8001 41 | 42 | #endif -------------------------------------------------------------------------------- /clock/include/libntrplg/global.h: -------------------------------------------------------------------------------- 1 | #define IS_PLUGIN 1 2 | #define USE_SOCKET 0 3 | 4 | #include "main.h" 5 | #include "memory.h" 6 | #include "math.h" 7 | #include "3dstypes.h" 8 | #include "constants.h" 9 | #include "xprintf.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "func.h" 25 | #include "sharedfunc.h" 26 | #include "ns/ns.h" 27 | #include -------------------------------------------------------------------------------- /clock/include/libntrplg/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /clock/include/libntrplg/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMORY_H 2 | #define MEMORY_H 3 | #include "math.h" 4 | #include "3dstypes.h" 5 | 6 | 7 | void write_byte(u32 address, u8 byte); 8 | void write_word(u32 address, u32 word); 9 | void write_color(u32 address, u8 r, u8 g, u8 b); 10 | u32 read_word(u32 address); 11 | char nibble_to_readable(u8 nibble); 12 | u32 byte_to_string(u8 byte, char* ret, int max_len); 13 | u32 byte_to_bit_string(u8 byte, char* ret, int max_len); 14 | u32 u32_to_string(u32 byte, char* ret, int max_len); 15 | u32 u16_to_string(u16 sh, char* ret, int max_len); 16 | u32 u16_to_bit_string(u16 sh, char* ret, int max_len); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /clock/include/libntrplg/netdb.h: -------------------------------------------------------------------------------- 1 | #ifndef NETDB_H 2 | #define NETDB_H 3 | 4 | struct hostent { 5 | char * h_name; 6 | char ** h_aliases; 7 | int h_addrtype; 8 | int h_length; 9 | char ** h_addr_list; 10 | }; 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct hostent * gethostbyname(const char * name); 18 | 19 | #ifdef __cplusplus 20 | }; 21 | #endif 22 | 23 | 24 | #endif // NETDB_H 25 | -------------------------------------------------------------------------------- /clock/include/libntrplg/ns/ns.h: -------------------------------------------------------------------------------- 1 | #define NS_DEFAULT_MEM_REGION 0x300 2 | 3 | #define DEBUG_BUFFER_SIZE 0x4000 4 | #define GLOBAL_BUFFER_SIZE 0x4000 5 | #define MAX_BREAKPOINT 64 6 | 7 | typedef struct _RT_LOCK { 8 | vu32 value; 9 | } RT_LOCK; 10 | 11 | 12 | #define NS_CONFIGURE_ADDR 0x06000000 13 | 14 | typedef struct _RT_HOOK { 15 | u32 model; 16 | u32 isEnabled; 17 | u32 funcAddr; 18 | u32 bakCode[16]; 19 | u32 jmpCode[16]; 20 | u32 callCode[16]; 21 | } RT_HOOK; 22 | 23 | typedef struct _NS_BREAKPOINT { 24 | u32 type; 25 | u32 flag; 26 | u32 addr; 27 | RT_HOOK hook; 28 | u32 stubCode[32]; 29 | u32 isEnabled; 30 | } NS_BREAKPOINT; 31 | 32 | 33 | 34 | typedef struct _NS_CONFIG { 35 | u32 initMode; 36 | u32 startupCommand; 37 | u32 hSOCU; 38 | 39 | u8* debugBuf; 40 | u32 debugBufSize; 41 | u32 debugPtr; 42 | u32 debugReady; 43 | 44 | RT_LOCK debugBufferLock; 45 | 46 | u32 startupInfo[32]; 47 | u32 allowDirectScreenAccess; 48 | u32 exitFlag; 49 | 50 | u32 sharedFunc[100]; 51 | 52 | } NS_CONFIG; 53 | 54 | 55 | 56 | void nsDbgPrint (const char* fmt, ... ); 57 | 58 | void rtInitLock(RT_LOCK *lock) ; 59 | void rtAcquireLock(RT_LOCK *lock) ; 60 | void rtReleaseLock(RT_LOCK *lock) ; 61 | u32 rtAlignToPageSize(u32 size); 62 | u32 rtGetPageOfAddress(u32 addr) ; 63 | u32 rtCheckRemoteMemoryRegionSafeForWrite(Handle hProcess, u32 addr, u32 size) ; 64 | u32 rtSafeCopyMemory(u32 dst, u32 src, u32 size) ; 65 | int rtRecvSocket(u32 sockfd, u8 *buf, int size); 66 | int rtSendSocket(u32 sockfd, u8 *buf, int size); 67 | u16 rtIntToPortNumber(u16 x) ; 68 | u32 rtGetFileSize(u8* fileName); 69 | u32 rtLoadFileToBuffer(u8* fileName, u32* pBuf, u32 bufSize) ; 70 | u32 rtGetThreadReg(Handle hProcess, u32 tid, u32* ctx); 71 | u32 rtFlushInstructionCache(void* ptr, u32 size); 72 | void rtInitHook(RT_HOOK* hook, u32 funcAddr, u32 callbackAddr); 73 | void rtEnableHook(RT_HOOK* hook); 74 | void rtDisableHook(RT_HOOK* hook); 75 | u32 rtGenerateJumpCode(u32 dst, u32* buf); 76 | 77 | 78 | u32 nsAttachProcess(Handle hProcess, u32 remotePC, NS_CONFIG *cfg) ; 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /clock/include/libntrplg/sharedfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_FUNC_H 2 | #define SHARED_FUNC_H 3 | 4 | #if IS_PLUGIN 5 | #define INIT_SHARED_FUNC(name,id) rtGenerateJumpCode(((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[id], (void*) name);rtFlushInstructionCache((void*) name, 8); 6 | #else 7 | #define INIT_SHARED_FUNC(name,id) (g_nsConfig->sharedFunc[id] = (u32) name) 8 | #endif 9 | 10 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 11 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 12 | u32 plgRequestMemory(u32 size); 13 | u32 plgRegisterCallback(u32 type, void* callback, u32 param0); 14 | 15 | void showDbg(u8* fmt, u32 v1, u32 v2); 16 | void nsDbgPrint (const char* fmt, ... ); 17 | 18 | #endif -------------------------------------------------------------------------------- /clock/include/libntrplg/xprintf.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Universal string handler for user console interface (C)ChaN, 2011 */ 3 | /*------------------------------------------------------------------------*/ 4 | 5 | #ifndef _STRFUNC 6 | #define _STRFUNC 7 | 8 | #define _USE_XFUNC_OUT 1 /* 1: Use output functions */ 9 | #define _CR_CRLF 0 /* 1: Convert \n ==> \r\n in the output char */ 10 | 11 | #define _USE_XFUNC_IN 1 /* 1: Use input function */ 12 | #define _LINE_ECHO 1 /* 1: Echo back input chars in xgets function */ 13 | 14 | 15 | #if _USE_XFUNC_OUT 16 | #define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func) 17 | extern void (*xfunc_out)(unsigned char); 18 | void xputc (char c); 19 | void xputs (const char* str); 20 | void xfputs (void (*func)(unsigned char), const char* str); 21 | void xprintf (const char* fmt, ...); 22 | void xsprintf (char* buff, const char* fmt, ...); 23 | void xfprintf (void (*func)(unsigned char), const char* fmt, ...); 24 | void put_dump (const void* buff, unsigned long addr, int len, int width); 25 | #define DW_CHAR sizeof(char) 26 | #define DW_SHORT sizeof(short) 27 | #define DW_LONG sizeof(long) 28 | #endif 29 | 30 | #if _USE_XFUNC_IN 31 | #define xdev_in(func) xfunc_in = (unsigned char(*)(void))(func) 32 | extern unsigned char (*xfunc_in)(void); 33 | int xgets (char* buff, int len); 34 | int xfgets (unsigned char (*func)(void), char* buff, int len); 35 | int xatoi (char** str, long* res); 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /clock/include/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int main(); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /clock/include/netinet/in.h: -------------------------------------------------------------------------------- 1 | #ifndef NETINET_IN_H 2 | #define NETINET_IN_H 3 | 4 | #include "sys/socket.h" 5 | 6 | #define INADDR_ANY 0x00000000 7 | #define INADDR_BROADCAST 0xFFFFFFFF 8 | #define INADDR_NONE 0xFFFFFFFF 9 | 10 | struct in_addr { 11 | unsigned long s_addr; 12 | }; 13 | 14 | struct sockaddr_in { 15 | unsigned short sin_family; 16 | unsigned short sin_port; 17 | struct in_addr sin_addr; 18 | unsigned char sin_zero[8]; 19 | }; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | // actually from arpa/inet.h - but is included through netinet/in.h 26 | unsigned long inet_addr(const char *cp); 27 | int inet_aton(const char *cp, struct in_addr *inp); 28 | char *inet_ntoa(struct in_addr in); 29 | 30 | #ifdef __cplusplus 31 | }; 32 | #endif 33 | 34 | #endif // NETINET_IN_H 35 | -------------------------------------------------------------------------------- /clock/include/netinet/tcp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/clock/include/netinet/tcp.h -------------------------------------------------------------------------------- /clock/include/sys/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SYS_SOCKET_H 2 | #define SYS_SOCKET_H 3 | 4 | #include 5 | 6 | /* 7 | * Level number for (get/set)sockopt() to apply to socket itself. 8 | */ 9 | #define SOL_SOCKET 0xfff /* options for socket level */ 10 | # define SOL_TCP 6 /* TCP level */ 11 | 12 | #define PF_UNSPEC 0 13 | #define PF_INET 2 14 | #define PF_INET6 10 15 | 16 | #define AF_UNSPEC PF_UNSPEC 17 | #define AF_INET PF_INET 18 | #define AF_INET6 PF_INET6 19 | 20 | #define SOCK_STREAM 1 21 | #define SOCK_DGRAM 2 22 | 23 | // need to sync FIO* values with commonly accepted ones sometime 24 | #define FIONBIO 1 25 | #define FIONREAD 2 26 | 27 | #define SOCKET_ERROR -1 28 | 29 | // send()/recv()/etc flags 30 | // at present, only MSG_PEEK is implemented though. 31 | #define MSG_WAITALL 0x40000000 32 | #define MSG_TRUNC 0x20000000 33 | #define MSG_PEEK 0x10000000 34 | #define MSG_OOB 0x08000000 35 | #define MSG_EOR 0x04000000 36 | #define MSG_DONTROUTE 0x02000000 37 | #define MSG_CTRUNC 0x01000000 38 | 39 | // shutdown() flags: 40 | #define SHUT_RD 1 41 | #define SHUT_WR 2 42 | #define SHUT_RDWR 3 43 | 44 | /* 45 | * Option flags per-socket. 46 | */ 47 | #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 48 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 49 | #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 50 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 51 | #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 52 | #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 53 | #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 54 | #define SO_LINGER 0x0080 /* linger on close if data present */ 55 | #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 56 | #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 57 | 58 | #define SO_DONTLINGER (int)(~SO_LINGER) 59 | 60 | /* 61 | * Additional options, not kept in so_options. 62 | */ 63 | #define SO_SNDBUF 0x1001 /* send buffer size */ 64 | #define SO_RCVBUF 0x1002 /* receive buffer size */ 65 | #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 66 | #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 67 | #define SO_SNDTIMEO 0x1005 /* send timeout */ 68 | #define SO_RCVTIMEO 0x1006 /* receive timeout */ 69 | #define SO_ERROR 0x1007 /* get error status and clear */ 70 | #define SO_TYPE 0x1008 /* get socket type */ 71 | 72 | struct sockaddr { 73 | unsigned short sa_family; 74 | char sa_data[14]; 75 | }; 76 | 77 | #ifndef ntohs 78 | #define ntohs(num) htons(num) 79 | #define ntohl(num) htonl(num) 80 | #endif 81 | 82 | #ifdef __cplusplus 83 | extern "C" { 84 | #endif 85 | 86 | int socket(int domain, int type, int protocol); 87 | int bind(int socket, const struct sockaddr * addr, int addr_len); 88 | int connect(int socket, const struct sockaddr * addr, int addr_len); 89 | int send(int socket, const void * data, int sendlength, int flags); 90 | int recv(int socket, void * data, int recvlength, int flags); 91 | int sendto(int socket, const void * data, int sendlength, int flags, const struct sockaddr * addr, int addr_len); 92 | int recvfrom(int socket, void * data, int recvlength, int flags, struct sockaddr * addr, int * addr_len); 93 | int listen(int socket, int max_connections); 94 | int accept(int socket, struct sockaddr * addr, int * addr_len); 95 | int shutdown(int socket, int shutdown_type); 96 | int closesocket(int socket); 97 | 98 | int ioctl(int socket, long cmd, void * arg); 99 | 100 | int setsockopt(int socket, int level, int option_name, const void * data, int data_len); 101 | int getsockopt(int socket, int level, int option_name, void * data, int * data_len); 102 | 103 | int getpeername(int socket, struct sockaddr *addr, int * addr_len); 104 | int getsockname(int socket, struct sockaddr *addr, int * addr_len); 105 | 106 | int gethostname(char *name, size_t len); 107 | int sethostname(const char *name, size_t len); 108 | 109 | unsigned short htons(unsigned short num); 110 | unsigned long htonl(unsigned long num); 111 | 112 | extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout); 113 | 114 | #ifdef __cplusplus 115 | }; 116 | #endif 117 | 118 | 119 | #endif // SYS_SOCKET_H 120 | -------------------------------------------------------------------------------- /clock/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/clock/lib/libc.a -------------------------------------------------------------------------------- /clock/lib/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/clock/lib/libgcc.a -------------------------------------------------------------------------------- /clock/obj/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/clock/obj/empty.txt -------------------------------------------------------------------------------- /clock/source/bootloader.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align(4); 3 | .section .text 4 | .global _Reset 5 | _Reset: 6 | 7 | STMFD SP!, {R0-R12, LR}; 8 | MRS R0, CPSR 9 | STMFD SP!, {R0} 10 | 11 | LDR R6, =_Reset 12 | ADR R5, _Reset 13 | sub r5, r5, r6 /* r5 = realAddress - baseAddress */ 14 | ldr r6, = __rel_dyn_start 15 | ldr r7, = __rel_dyn_end 16 | add r6, r6, r5 17 | add r7, r7, r5 18 | relocNotFinished: 19 | ldmia r6!, {r3, r4} 20 | cmp r4, #0x17 21 | bne notRelativeEntry 22 | add r3, r3, r5 23 | ldr r4, [r3] 24 | add r4, r4, r5 25 | str r4, [r3] 26 | notRelativeEntry: 27 | cmp r6, r7 28 | bcc relocNotFinished 29 | ldr r0, =0xffff8001 30 | adr r1, _Reset 31 | ldr r2, =__rel_dyn_end 32 | sub r2, r2, r1 /* r2 = codesize */ 33 | svc 0x54 /* flush instruction cache */ 34 | nop 35 | nop 36 | 37 | mov r0, sp 38 | bl c_entry 39 | 40 | ldmfd sp!, {r0} 41 | msr cpsr, r0 42 | ldmfd SP!, {R0-R12, LR}; 43 | 44 | .global _ReturnToUser 45 | _ReturnToUser: 46 | bx lr 47 | nop 48 | nop 49 | nop 50 | msr cpsr, r0 51 | /* unused 52 | ldr PC, =c_entry 53 | */ 54 | 55 | .section .__rel_dyn_start 56 | __rel_dyn_start: 57 | 58 | .section .__rel_dyn_end 59 | __rel_dyn_end: 60 | 61 | .section .__bss_start 62 | .global __c_bss_start 63 | __c_bss_start: 64 | 65 | .section .__bss_end 66 | .global __c_bss_end 67 | __c_bss_end: 68 | 69 | -------------------------------------------------------------------------------- /clock/source/entry.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | extern u32 __c_bss_start; 4 | extern u32 __c_bss_end; 5 | 6 | void c_entry(u32* reg) { 7 | u32 i; 8 | 9 | for (i = __c_bss_start; i < __c_bss_end; i += 4){ 10 | *(vu32*)(i) = 0; 11 | } 12 | main(); 13 | } 14 | 15 | void IRQHandler (void) 16 | { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /clock/source/font.h: -------------------------------------------------------------------------------- 1 | 2 | static unsigned char font[] = 3 | { 4 | /*0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, // Char 000 (.) 5 | 0x7E, 0x81, 0xA5, 0x81, 0x9D, 0xB9, 0x81, 0x7E, // Char 001 (.) 6 | 0x7E, 0xFF, 0xDB, 0xFF, 0xE3, 0xC7, 0xFF, 0x7E, // Char 002 (.) 7 | 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, // Char 003 (.) 8 | 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, // Char 004 (.) 9 | 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x10, 0x10, 0x7C, // Char 005 (.) 10 | 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0x7E, 0x18, 0x7E, // Char 006 (.) 11 | 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, // Char 007 (.) 12 | 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, // Char 008 (.) 13 | 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, // Char 009 (.) 14 | 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, // Char 010 (.) 15 | 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, // Char 011 (.) 16 | 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, // Char 012 (.) 17 | 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, // Char 013 (.) 18 | 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, // Char 014 (.) 19 | 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, // Char 015 (.) 20 | 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, // Char 016 (.) 21 | 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, // Char 017 (.) 22 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, // Char 018 (.) 23 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, // Char 019 (.) 24 | 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, // Char 020 (.) 25 | 0x3F, 0x60, 0x7C, 0x66, 0x66, 0x3E, 0x06, 0xFC, // Char 021 (.) 26 | 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, // Char 022 (.) 27 | 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, // Char 023 (.) 28 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 024 (.) 29 | 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, // Char 025 (.) 30 | 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, // Char 026 (.) 31 | 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, // Char 027 (.) 32 | 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, // Char 028 (.) 33 | 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, // Char 029 (.) 34 | 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, // Char 030 (.) 35 | 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, // Char 031 (.)*/ 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 032 ( ) 37 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00, // Char 033 (!) 38 | 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 034 (") 39 | 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, // Char 035 (#) 40 | 0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, // Char 036 ($) 41 | 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, // Char 037 (%) 42 | 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, // Char 038 (&) 43 | 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 039 (') 44 | 0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00, // Char 040 (() 45 | 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00, // Char 041 ()) 46 | 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, // Char 042 (*) 47 | 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, // Char 043 (+) 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, // Char 044 (,) 49 | 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, // Char 045 (-) 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, // Char 046 (.) 51 | 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, // Char 047 (/) 52 | 0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, // Char 048 (0) 53 | 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, // Char 049 (1) 54 | 0x7C, 0xC6, 0x06, 0x7C, 0xC0, 0xC0, 0xFE, 0x00, // Char 050 (2) 55 | 0xFC, 0x06, 0x06, 0x3C, 0x06, 0x06, 0xFC, 0x00, // Char 051 (3) 56 | 0x0C, 0xCC, 0xCC, 0xCC, 0xFE, 0x0C, 0x0C, 0x00, // Char 052 (4) 57 | 0xFE, 0xC0, 0xFC, 0x06, 0x06, 0xC6, 0x7C, 0x00, // Char 053 (5) 58 | 0x7C, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0x7C, 0x00, // Char 054 (6) 59 | 0xFE, 0x06, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x00, // Char 055 (7) 60 | 0x7C, 0xC6, 0xC6, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, // Char 056 (8) 61 | 0x7C, 0xC6, 0xC6, 0x7E, 0x06, 0x06, 0x7C, 0x00, // Char 057 (9) 62 | 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, // Char 058 (:) 63 | 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, // Char 059 (;) 64 | 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00, // Char 060 (<) 65 | 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, // Char 061 (=) 66 | 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00, // Char 062 (>) 67 | 0x3C, 0x66, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x00, // Char 063 (?) 68 | 0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x7E, 0x00, // Char 064 (@) 69 | 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, // Char 065 (A) 70 | 0xFC, 0xC6, 0xC6, 0xFC, 0xC6, 0xC6, 0xFC, 0x00, // Char 066 (B) 71 | 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, // Char 067 (C) 72 | 0xF8, 0xCC, 0xC6, 0xC6, 0xC6, 0xCC, 0xF8, 0x00, // Char 068 (D) 73 | 0xFE, 0xC0, 0xC0, 0xF8, 0xC0, 0xC0, 0xFE, 0x00, // Char 069 (E) 74 | 0xFE, 0xC0, 0xC0, 0xF8, 0xC0, 0xC0, 0xC0, 0x00, // Char 070 (F) 75 | 0x7C, 0xC6, 0xC0, 0xC0, 0xCE, 0xC6, 0x7C, 0x00, // Char 071 (G) 76 | 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0x00, // Char 072 (H) 77 | 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, // Char 073 (I) 78 | 0x06, 0x06, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, // Char 074 (J) 79 | 0xC6, 0xCC, 0xD8, 0xF0, 0xD8, 0xCC, 0xC6, 0x00, // Char 075 (K) 80 | 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, // Char 076 (L) 81 | 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, // Char 077 (M) 82 | 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, // Char 078 (N) 83 | 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 079 (O) 84 | 0xFC, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, 0xC0, 0x00, // Char 080 (P) 85 | 0x7C, 0xC6, 0xC6, 0xC6, 0xD6, 0xDE, 0x7C, 0x06, // Char 081 (Q) 86 | 0xFC, 0xC6, 0xC6, 0xFC, 0xD8, 0xCC, 0xC6, 0x00, // Char 082 (R) 87 | 0x7C, 0xC6, 0xC0, 0x7C, 0x06, 0xC6, 0x7C, 0x00, // Char 083 (S) 88 | 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 084 (T) 89 | 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0x00, // Char 085 (U) 90 | 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x38, 0x00, // Char 086 (V) 91 | 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, // Char 087 (W) 92 | 0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, // Char 088 (X) 93 | 0xC6, 0xC6, 0xC6, 0x7C, 0x18, 0x30, 0xE0, 0x00, // Char 089 (Y) 94 | 0xFE, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFE, 0x00, // Char 090 (Z) 95 | 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x00, // Char 091 ([) 96 | 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, // Char 092 (\) 97 | 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x00, // Char 093 (]) 98 | 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, // Char 094 (^) 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // Char 095 (_) 100 | 0x18, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 096 (`) 101 | 0x00, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 097 (a) 102 | 0xC0, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xFC, 0x00, // Char 098 (b) 103 | 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, // Char 099 (c) 104 | 0x06, 0x06, 0x06, 0x7E, 0xC6, 0xC6, 0x7E, 0x00, // Char 100 (d) 105 | 0x00, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 101 (e) 106 | 0x1C, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x00, // Char 102 (f) 107 | 0x00, 0x00, 0x7E, 0xC6, 0xC6, 0x7E, 0x06, 0xFC, // Char 103 (g) 108 | 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, // Char 104 (h) 109 | 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 105 (i) 110 | 0x06, 0x00, 0x06, 0x06, 0x06, 0x06, 0xC6, 0x7C, // Char 106 (j) 111 | 0xC0, 0xC0, 0xCC, 0xD8, 0xF8, 0xCC, 0xC6, 0x00, // Char 107 (k) 112 | 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 108 (l) 113 | 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, // Char 109 (m) 114 | 0x00, 0x00, 0xFC, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, // Char 110 (n) 115 | 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 111 (o) 116 | 0x00, 0x00, 0xFC, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, // Char 112 (p) 117 | 0x00, 0x00, 0x7E, 0xC6, 0xC6, 0x7E, 0x06, 0x06, // Char 113 (q) 118 | 0x00, 0x00, 0xFC, 0xC6, 0xC0, 0xC0, 0xC0, 0x00, // Char 114 (r) 119 | 0x00, 0x00, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x00, // Char 115 (s) 120 | 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x0E, 0x00, // Char 116 (t) 121 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 117 (u) 122 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0x7C, 0x38, 0x00, // Char 118 (v) 123 | 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, // Char 119 (w) 124 | 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, // Char 120 (x) 125 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0xFC, // Char 121 (y) 126 | 0x00, 0x00, 0xFE, 0x0C, 0x38, 0x60, 0xFE, 0x00, // Char 122 (z) 127 | 0x0E, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0E, 0x00, // Char 123 ({) 128 | 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, // Char 124 (|) 129 | 0x70, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x70, 0x00, // Char 125 (}) 130 | 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 126 (~) 131 | /*0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, // Char 127 (.) 132 | 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xD6, 0x7C, 0x30, // Char 128 (.) 133 | 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 129 (.) 134 | 0x0E, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 130 (.) 135 | 0x7E, 0x81, 0x3C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 131 (.) 136 | 0x66, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 132 (.) 137 | 0xE0, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 133 (.) 138 | 0x18, 0x18, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 134 (.) 139 | 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xD6, 0x7C, 0x30, // Char 135 (.) 140 | 0x7E, 0x81, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 136 (.) 141 | 0x66, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 137 (.) 142 | 0xE0, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 138 (.) 143 | 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 139 (.) 144 | 0x7C, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 140 (.) 145 | 0x70, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 141 (.) 146 | 0xC6, 0x10, 0x7C, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, // Char 142 (.) 147 | 0x38, 0x38, 0x00, 0x7C, 0xC6, 0xFE, 0xC6, 0x00, // Char 143 (.) 148 | 0x0E, 0x00, 0xFE, 0xC0, 0xF8, 0xC0, 0xFE, 0x00, // Char 144 (.) 149 | 0x00, 0x00, 0x7F, 0x0C, 0x7F, 0xCC, 0x7F, 0x00, // Char 145 (.) 150 | 0x3F, 0x6C, 0xCC, 0xFF, 0xCC, 0xCC, 0xCF, 0x00, // Char 146 (.) 151 | 0x7C, 0x82, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 147 (.) 152 | 0x66, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 148 (.) 153 | 0xE0, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 149 (.) 154 | 0x7C, 0x82, 0x00, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 150 (.) 155 | 0xE0, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 151 (.) 156 | 0x66, 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x7C, // Char 152 (.) 157 | 0xC6, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 153 (.) 158 | 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0x00, // Char 154 (.) 159 | 0x18, 0x18, 0x7E, 0xD8, 0xD8, 0xD8, 0x7E, 0x18, // Char 155 (.) 160 | 0x38, 0x6C, 0x60, 0xF0, 0x60, 0x66, 0xFC, 0x00, // Char 156 (.) 161 | 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x7E, 0x18, // Char 157 (.) 162 | 0xF8, 0xCC, 0xCC, 0xFA, 0xC6, 0xCF, 0xC6, 0xC3, // Char 158 (.) 163 | 0x0E, 0x1B, 0x18, 0x3C, 0x18, 0x18, 0xD8, 0x70, // Char 159 (.) 164 | 0x0E, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 160 (.) 165 | 0x1C, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 161 (.) 166 | 0x0E, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 162 (.) 167 | 0x0E, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 163 (.) 168 | 0x00, 0xFE, 0x00, 0xFC, 0xC6, 0xC6, 0xC6, 0x00, // Char 164 (.) 169 | 0xFE, 0x00, 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0x00, // Char 165 (.) 170 | 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, // Char 166 (.) 171 | 0x3C, 0x66, 0x66, 0x3C, 0x00, 0x7E, 0x00, 0x00, // Char 167 (.) 172 | 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3C, 0x00, // Char 168 (.) 173 | 0x00, 0x00, 0x00, 0xFC, 0xC0, 0xC0, 0x00, 0x00, // Char 169 (.) 174 | 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x00, 0x00, // Char 170 (.) 175 | 0xC6, 0xCC, 0xD8, 0x3F, 0x63, 0xCF, 0x8C, 0x0F, // Char 171 (.) 176 | 0xC3, 0xC6, 0xCC, 0xDB, 0x37, 0x6D, 0xCF, 0x03, // Char 172 (.) 177 | 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 173 (.) 178 | 0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, // Char 174 (.) 179 | 0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, // Char 175 (.) 180 | 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, // Char 176 (.) 181 | 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, // Char 177 (.) 182 | 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, // Char 178 (.) 183 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, // Char 179 (.) 184 | 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 180 (.) 185 | 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 181 (.) 186 | 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, // Char 182 (.) 187 | 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, // Char 183 (.) 188 | 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 184 (.) 189 | 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, // Char 185 (.) 190 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, // Char 186 (.) 191 | 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, // Char 187 (.) 192 | 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, // Char 188 (.) 193 | 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, // Char 189 (.) 194 | 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, // Char 190 (.) 195 | 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, // Char 191 (.) 196 | 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, // Char 192 (.) 197 | 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, // Char 193 (.) 198 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, // Char 194 (.) 199 | 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 195 (.) 200 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 196 (.) 201 | 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, // Char 197 (.) 202 | 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 198 (.) 203 | 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, // Char 199 (.) 204 | 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, // Char 200 (.) 205 | 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, // Char 201 (.) 206 | 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 202 (.) 207 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, // Char 203 (.) 208 | 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, // Char 204 (.) 209 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 205 (.) 210 | 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, // Char 206 (.) 211 | 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 207 (.) 212 | 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, // Char 208 (.) 213 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, // Char 209 (.) 214 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, // Char 210 (.) 215 | 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, // Char 211 (.) 216 | 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, // Char 212 (.) 217 | 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 213 (.) 218 | 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, // Char 214 (.) 219 | 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, // Char 215 (.) 220 | 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, // Char 216 (.) 221 | 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, // Char 217 (.) 222 | 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, // Char 218 (.) 223 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Char 219 (.) 224 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, // Char 220 (.) 225 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, // Char 221 (.) 226 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // Char 222 (.) 227 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // Char 223 (.) 228 | 0x00, 0x00, 0x76, 0xDC, 0xC8, 0xDC, 0x76, 0x00, // Char 224 (.) 229 | 0x38, 0x6C, 0x6C, 0x78, 0x6C, 0x66, 0x6C, 0x60, // Char 225 (.) 230 | 0x00, 0xFE, 0xC6, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, // Char 226 (.) 231 | 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, // Char 227 (.) 232 | 0xFE, 0x60, 0x30, 0x18, 0x30, 0x60, 0xFE, 0x00, // Char 228 (.) 233 | 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0x70, 0x00, // Char 229 (.) 234 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0xC0, // Char 230 (.) 235 | 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 231 (.) 236 | 0x7E, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x7E, // Char 232 (.) 237 | 0x3C, 0x66, 0xC3, 0xFF, 0xC3, 0x66, 0x3C, 0x00, // Char 233 (.) 238 | 0x3C, 0x66, 0xC3, 0xC3, 0x66, 0x66, 0xE7, 0x00, // Char 234 (.) 239 | 0x0E, 0x18, 0x0C, 0x7E, 0xC6, 0xC6, 0x7C, 0x00, // Char 235 (.) 240 | 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x00, 0x00, // Char 236 (.) 241 | 0x06, 0x0C, 0x7E, 0xDB, 0xDB, 0x7E, 0x60, 0xC0, // Char 237 (.) 242 | 0x38, 0x60, 0xC0, 0xF8, 0xC0, 0x60, 0x38, 0x00, // Char 238 (.) 243 | 0x78, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, // Char 239 (.) 244 | 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, // Char 240 (.) 245 | 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x7E, 0x00, // Char 241 (.) 246 | 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xFC, 0x00, // Char 242 (.) 247 | 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xFC, 0x00, // Char 243 (.) 248 | 0x0E, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, // Char 244 (.) 249 | 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70, // Char 245 (.) 250 | 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, // Char 246 (.) 251 | 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, // Char 247 (.) 252 | 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, // Char 248 (.) 253 | 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, // Char 249 (.) 254 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, // Char 250 (.) 255 | 0x0F, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C, // Char 251 (.) 256 | 0x78, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, // Char 252 (.) 257 | 0x7C, 0x0C, 0x7C, 0x60, 0x7C, 0x00, 0x00, 0x00, // Char 253 (.) 258 | 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, // Char 254 (.) 259 | 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Char 255 (.)*/ 260 | }; -------------------------------------------------------------------------------- /clock/source/libctru/AC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | Result ACU_cmd1(Handle servhandle, u32 *ptr)//Unknown what this cmd does at the time of writing. (ptr=0x200-byte outbuf) 11 | { 12 | u32 tmp0, tmp1; 13 | Result ret=0; 14 | u32 *cmdbuf = getThreadCommandBuffer(); 15 | 16 | tmp0 = cmdbuf[0x100>>2]; 17 | tmp1 = cmdbuf[0x104>>2]; 18 | 19 | cmdbuf[0] = 0x00010000; 20 | cmdbuf[0x100>>2] = 0x00800002; 21 | cmdbuf[0x104>>2] = (u32)ptr; 22 | 23 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 24 | 25 | cmdbuf[0x100>>2] = tmp0; 26 | cmdbuf[0x104>>2] = tmp1; 27 | 28 | return (Result)cmdbuf[1]; 29 | } 30 | 31 | Result ACU_cmd26(Handle servhandle, u32 *ptr, u8 val)//Unknown what this cmd does at the time of writing. (ptr=0x200-byte inbuf/outbuf) 32 | { 33 | u32 tmp0, tmp1; 34 | Result ret=0; 35 | u32 *cmdbuf = getThreadCommandBuffer(); 36 | 37 | tmp0 = cmdbuf[0x100>>2]; 38 | tmp1 = cmdbuf[0x104>>2]; 39 | 40 | cmdbuf[0] = 0x00260042; 41 | cmdbuf[1] = (u32)val; 42 | cmdbuf[0x100>>2] = 0x00800002; 43 | cmdbuf[0x104>>2] = (u32)ptr; 44 | cmdbuf[2] = 0x00800002; 45 | cmdbuf[3] = (u32)ptr; 46 | 47 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 48 | 49 | cmdbuf[0x100>>2] = tmp0; 50 | cmdbuf[0x104>>2] = tmp1; 51 | 52 | return (Result)cmdbuf[1]; 53 | } 54 | 55 | Result ACU_GetWifiStatus(Handle servhandle, u32 *out) 56 | { 57 | Result ret=0; 58 | u32 *cmdbuf = getThreadCommandBuffer(); 59 | 60 | cmdbuf[0] = 0x000D0000; 61 | 62 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 63 | 64 | *out = cmdbuf[2]; 65 | 66 | return (Result)cmdbuf[1]; 67 | } 68 | 69 | Result ACU_WaitInternetConnection() 70 | { 71 | Handle servhandle = 0; 72 | Result ret=0; 73 | u32 outval=0; 74 | 75 | if((ret = srv_getServiceHandle(NULL, &servhandle, "ac:u"))!=0)return ret; 76 | 77 | while(1) 78 | { 79 | ret = ACU_GetWifiStatus(servhandle, &outval); 80 | if(ret==0 && outval==1)break; 81 | } 82 | 83 | svc_closeHandle(servhandle); 84 | 85 | return ret; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /clock/source/libctru/FS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Result FSUSER_Initialize(Handle handle) 9 | { 10 | u32* cmdbuf=getThreadCommandBuffer(); 11 | cmdbuf[0]=0x08010002; //request header code 12 | cmdbuf[1]=32; 13 | 14 | Result ret=0; 15 | if((ret=svc_sendSyncRequest(handle)))return ret; 16 | 17 | return cmdbuf[1]; 18 | } 19 | 20 | Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //archive needs to have been opened 21 | { 22 | u32* cmdbuf=getThreadCommandBuffer(); 23 | 24 | cmdbuf[0]=0x080201C2; 25 | cmdbuf[1]=0; 26 | cmdbuf[2]=archive.handleLow; 27 | cmdbuf[3]=archive.handleHigh; 28 | cmdbuf[4]=fileLowPath.type; 29 | cmdbuf[5]=fileLowPath.size; 30 | cmdbuf[6]=openflags; 31 | cmdbuf[7]=attributes; 32 | cmdbuf[8]=(fileLowPath.size<<14)|2; 33 | cmdbuf[9]=(u32)fileLowPath.data; 34 | 35 | Result ret=0; 36 | if((ret=svc_sendSyncRequest(handle)))return ret; 37 | 38 | if(out)*out=cmdbuf[3]; 39 | 40 | return cmdbuf[1]; 41 | } 42 | 43 | Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //no need to have archive opened 44 | { 45 | u32* cmdbuf=getThreadCommandBuffer(); 46 | 47 | cmdbuf[0]=0x08030204; 48 | cmdbuf[1]=0; 49 | cmdbuf[2]=archive.id; 50 | cmdbuf[3]=archive.lowPath.type; 51 | cmdbuf[4]=archive.lowPath.size; 52 | cmdbuf[5]=fileLowPath.type; 53 | cmdbuf[6]=fileLowPath.size; 54 | cmdbuf[7]=openflags; 55 | cmdbuf[8]=attributes; 56 | cmdbuf[9]=(archive.lowPath.size<<14)|0x802; 57 | cmdbuf[10]=(u32)archive.lowPath.data; 58 | cmdbuf[11]=(fileLowPath.size<<14)|2; 59 | cmdbuf[12]=(u32)fileLowPath.data; 60 | 61 | Result ret=0; 62 | if((ret=svc_sendSyncRequest(handle)))return ret; 63 | 64 | if(out)*out=cmdbuf[3]; 65 | 66 | return cmdbuf[1]; 67 | } 68 | 69 | Result FSUSER_OpenArchive(Handle handle, FS_archive* archive) 70 | { 71 | if(!archive)return -2; 72 | u32* cmdbuf=getThreadCommandBuffer(); 73 | 74 | cmdbuf[0]=0x080C00C2; 75 | cmdbuf[1]=archive->id; 76 | cmdbuf[2]=archive->lowPath.type; 77 | cmdbuf[3]=archive->lowPath.size; 78 | cmdbuf[4]=(archive->lowPath.size<<14)|0x2; 79 | cmdbuf[5]=(u32)archive->lowPath.data; 80 | 81 | Result ret=0; 82 | if((ret=svc_sendSyncRequest(handle)))return ret; 83 | 84 | archive->handleLow=cmdbuf[2]; 85 | archive->handleHigh=cmdbuf[3]; 86 | 87 | return cmdbuf[1]; 88 | } 89 | 90 | Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath) 91 | { 92 | u32* cmdbuf=getThreadCommandBuffer(); 93 | 94 | cmdbuf[0]=0x080B0102; 95 | cmdbuf[1]=archive.handleLow; 96 | cmdbuf[2]=archive.handleHigh; 97 | cmdbuf[3]=dirLowPath.type; 98 | cmdbuf[4]=dirLowPath.size; 99 | cmdbuf[5]=(dirLowPath.size<<14)|0x2; 100 | cmdbuf[6]=(u32)dirLowPath.data; 101 | 102 | Result ret=0; 103 | if((ret=svc_sendSyncRequest(handle)))return ret; 104 | 105 | if(out)*out=cmdbuf[3]; 106 | 107 | return cmdbuf[1]; 108 | } 109 | 110 | Result FSUSER_CloseArchive(Handle handle, FS_archive* archive) 111 | { 112 | if(!archive)return -2; 113 | u32* cmdbuf=getThreadCommandBuffer(); 114 | 115 | cmdbuf[0]=0x080E0080; 116 | cmdbuf[1]=archive->handleLow; 117 | cmdbuf[2]=archive->handleLow; 118 | 119 | Result ret=0; 120 | if((ret=svc_sendSyncRequest(handle)))return ret; 121 | 122 | return cmdbuf[1]; 123 | } 124 | 125 | Result FSFILE_Close(Handle handle) 126 | { 127 | u32* cmdbuf=getThreadCommandBuffer(); 128 | 129 | cmdbuf[0]=0x08080000; 130 | 131 | Result ret=0; 132 | if((ret=svc_sendSyncRequest(handle)))return ret; 133 | 134 | return cmdbuf[1]; 135 | } 136 | 137 | Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size) 138 | { 139 | u32 *cmdbuf=getThreadCommandBuffer(); 140 | 141 | cmdbuf[0]=0x080200C2; 142 | cmdbuf[1]=(u32)offset; 143 | cmdbuf[2]=(u32)(offset>>32); 144 | cmdbuf[3]=size; 145 | cmdbuf[4]=(size<<4)|12; 146 | cmdbuf[5]=(u32)buffer; 147 | 148 | Result ret=0; 149 | if((ret=svc_sendSyncRequest(handle)))return ret; 150 | 151 | if(bytesRead)*bytesRead=cmdbuf[2]; 152 | 153 | return cmdbuf[1]; 154 | } 155 | 156 | //WARNING : using wrong flushFlags CAN corrupt the archive you're writing to. 157 | //another warning : data should *not* be in RO memory 158 | Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *data, u32 size, u32 flushFlags) 159 | { 160 | u32 *cmdbuf=getThreadCommandBuffer(); 161 | 162 | cmdbuf[0]=0x08030102; 163 | cmdbuf[1]=(u32)offset; 164 | cmdbuf[2]=(u32)(offset>>32); 165 | cmdbuf[3]=size; 166 | cmdbuf[4]=flushFlags; 167 | cmdbuf[5]=(size<<4)|10; 168 | cmdbuf[6]=(u32)data; 169 | 170 | Result ret=0; 171 | if((ret=svc_sendSyncRequest(handle)))return ret; 172 | 173 | if(bytesWritten)*bytesWritten=cmdbuf[2]; 174 | 175 | return cmdbuf[1]; 176 | } 177 | 178 | Result FSFILE_GetSize(Handle handle, u64 *size) 179 | { 180 | u32 *cmdbuf=getThreadCommandBuffer(); 181 | 182 | cmdbuf[0] = 0x08040000; 183 | 184 | Result ret=0; 185 | if((ret=svc_sendSyncRequest(handle)))return ret; 186 | 187 | if(size)*size = *((u64*)&cmdbuf[2]); 188 | 189 | return cmdbuf[1]; 190 | } 191 | 192 | Result FSFILE_SetSize(Handle handle, u64 size) 193 | { 194 | u32 *cmdbuf = getThreadCommandBuffer(); 195 | 196 | cmdbuf[0] = 0x08050080; 197 | cmdbuf[1] = (u32)size; 198 | cmdbuf[2] = (u32)(size >> 32); 199 | 200 | Result ret = 0; 201 | if ((ret = svc_sendSyncRequest(handle)))return ret; 202 | 203 | 204 | return cmdbuf[1]; 205 | } 206 | 207 | Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer) 208 | { 209 | u32 *cmdbuf=getThreadCommandBuffer(); 210 | 211 | cmdbuf[0]=0x08010042; 212 | cmdbuf[1]=entrycount; 213 | cmdbuf[2]=((entrycount*0x228)<<4)|0xC; 214 | cmdbuf[3]=(u32)buffer; 215 | 216 | Result ret=0; 217 | if((ret=svc_sendSyncRequest(handle)))return ret; 218 | 219 | if(entriesRead)*entriesRead=cmdbuf[2]; 220 | 221 | return cmdbuf[1]; 222 | } 223 | 224 | Result FSDIR_Close(Handle handle) 225 | { 226 | u32* cmdbuf=getThreadCommandBuffer(); 227 | 228 | cmdbuf[0]=0x08020000; 229 | 230 | Result ret=0; 231 | if((ret=svc_sendSyncRequest(handle)))return ret; 232 | 233 | return cmdbuf[1]; 234 | } 235 | -------------------------------------------------------------------------------- /clock/source/libctru/OS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | u32 OS_ConvertVaddr2Physaddr(u32 vaddr) 9 | { 10 | if(vaddr >= 0x14000000 && vaddr<0x1c000000)return vaddr + 0x0c000000;//LINEAR memory 11 | if(vaddr >= 0x30000000 && vaddr<0x40000000)return vaddr - 0x10000000;//Only available under system-version v8.0 for certain processes, see here: http://3dbrew.org/wiki/SVC#enum_MemoryOperation 12 | if(vaddr >= 0x1F000000 && vaddr<0x1F600000)return vaddr - 0x07000000;//VRAM 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /clock/source/libctru/SOC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #if USE_SOCKET 18 | 19 | 20 | Handle SOCU_handle = 0; 21 | static int SOCU_errno = 0; 22 | 23 | #define NET_UNKNOWN_ERROR_OFFSET -10000//This is from libogc network_wii.c. 24 | 25 | static u8 _net_error_code_map[] = { //This is based on the array from libogc network_wii.c. 26 | 0, // 0 27 | E2BIG, 28 | EACCES, 29 | EADDRINUSE, 30 | EADDRNOTAVAIL, 31 | EAFNOSUPPORT, // 5 32 | EAGAIN, 33 | EALREADY, 34 | EBADF, 35 | EBADMSG, 36 | EBUSY, // 10 37 | ECANCELED, 38 | ECHILD, 39 | ECONNABORTED, 40 | ECONNREFUSED, 41 | ECONNRESET, // 15 42 | EDEADLK, 43 | EDESTADDRREQ, 44 | EDOM, 45 | EDQUOT, 46 | EEXIST, // 20 47 | EFAULT, 48 | EFBIG, 49 | EHOSTUNREACH, 50 | EIDRM, 51 | EILSEQ, // 25 52 | EINPROGRESS, 53 | EINTR, 54 | EINVAL, 55 | EIO, 56 | EISCONN, // 30 57 | EISDIR, 58 | ELOOP, 59 | EMFILE, 60 | EMLINK, 61 | EMSGSIZE, // 35 62 | EMULTIHOP, 63 | ENAMETOOLONG, 64 | ENETDOWN, 65 | ENETRESET, 66 | ENETUNREACH, // 40 67 | ENFILE, 68 | ENOBUFS, 69 | ENODATA, 70 | ENODEV, 71 | ENOENT, // 45 72 | ENOEXEC, 73 | ENOLCK, 74 | ENOLINK, 75 | ENOMEM, 76 | ENOMSG, // 50 77 | ENOPROTOOPT, 78 | ENOSPC, 79 | ENOSR, 80 | ENOSTR, 81 | ENOSYS, // 55 82 | ENOTCONN, 83 | ENOTDIR, 84 | ENOTEMPTY, 85 | ENOTSOCK, 86 | ENOTSUP, // 60 87 | ENOTTY, 88 | ENXIO, 89 | EOPNOTSUPP, 90 | EOVERFLOW, 91 | EPERM, // 65 92 | EPIPE, 93 | EPROTO, 94 | EPROTONOSUPPORT, 95 | EPROTOTYPE, 96 | ERANGE, // 70 97 | EROFS, 98 | ESPIPE, 99 | ESRCH, 100 | ESTALE, 101 | ETIME, // 75 102 | ETIMEDOUT, 103 | }; 104 | 105 | static s32 _net_convert_error(s32 sock_retval)//This is based on the function from libogc network_wii.c. 106 | { 107 | if (sock_retval >= 0) return sock_retval; 108 | if (sock_retval < -sizeof(_net_error_code_map) 109 | || !_net_error_code_map[-sock_retval]) 110 | return NET_UNKNOWN_ERROR_OFFSET + sock_retval; 111 | return -_net_error_code_map[-sock_retval]; 112 | } 113 | 114 | Result socu_cmd1(Handle memhandle, u32 memsize) 115 | { 116 | Result ret=0; 117 | u32 *cmdbuf = getThreadCommandBuffer(); 118 | 119 | cmdbuf[0] = 0x00010044; 120 | cmdbuf[1] = memsize; 121 | cmdbuf[2] = 0x20; 122 | cmdbuf[4] = 0; 123 | cmdbuf[5] = memhandle; 124 | 125 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 126 | 127 | return cmdbuf[1]; 128 | } 129 | 130 | Result SOC_Shutdown() 131 | { 132 | Result ret=0; 133 | u32 *cmdbuf = getThreadCommandBuffer(); 134 | 135 | cmdbuf[0] = 0x00190000; 136 | 137 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 138 | 139 | svc_closeHandle(SOCU_handle); 140 | 141 | return cmdbuf[1]; 142 | } 143 | 144 | Result SOC_Initialize(u32 *context_addr, u32 context_size) 145 | { 146 | Result ret=0; 147 | Handle memhandle = 0; 148 | 149 | ret = svc_createMemoryBlock(&memhandle, (u32)context_addr, context_size, 0, 3); 150 | if(ret!=0)return ret; 151 | 152 | if((ret = srv_getServiceHandle(NULL, &SOCU_handle, "soc:U"))!=0)return ret; 153 | return socu_cmd1(memhandle, context_size); 154 | } 155 | 156 | int SOC_GetErrno() 157 | { 158 | return SOCU_errno; 159 | } 160 | 161 | int socket(int domain, int type, int protocol) 162 | { 163 | int ret=0; 164 | u32 *cmdbuf = getThreadCommandBuffer(); 165 | 166 | cmdbuf[0] = 0x000200C2; 167 | cmdbuf[1] = domain; 168 | cmdbuf[2] = type; 169 | cmdbuf[3] = protocol; 170 | cmdbuf[4] = 0x20; 171 | 172 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 173 | 174 | ret = (int)cmdbuf[1]; 175 | SOCU_errno = ret; 176 | 177 | if(ret!=0)return -1; 178 | return _net_convert_error(cmdbuf[2]); 179 | } 180 | 181 | int closesocket(int sockfd) 182 | { 183 | int ret=0; 184 | u32 *cmdbuf = getThreadCommandBuffer(); 185 | 186 | cmdbuf[0] = 0x000B0042; 187 | cmdbuf[1] = (u32)sockfd; 188 | cmdbuf[2] = 0x20; 189 | 190 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 191 | 192 | ret = (int)cmdbuf[1]; 193 | if(ret==0)ret =_net_convert_error(cmdbuf[2]); 194 | SOCU_errno = ret; 195 | 196 | if(ret!=0)return -1; 197 | return 0; 198 | } 199 | 200 | int shutdown(int sockfd, int shutdown_type) 201 | { 202 | int ret=0; 203 | u32 *cmdbuf = getThreadCommandBuffer(); 204 | 205 | cmdbuf[0] = 0x000C0082; 206 | cmdbuf[1] = (u32)sockfd; 207 | cmdbuf[2] = (u32)shutdown_type; 208 | cmdbuf[3] = 0x20; 209 | 210 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 211 | 212 | ret = (int)cmdbuf[1]; 213 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 214 | SOCU_errno = ret; 215 | 216 | if(ret!=0)return -1; 217 | return 0; 218 | } 219 | 220 | int listen(int sockfd, int max_connections) 221 | { 222 | int ret=0; 223 | u32 *cmdbuf = getThreadCommandBuffer(); 224 | 225 | cmdbuf[0] = 0x00030082; 226 | cmdbuf[1] = (u32)sockfd; 227 | cmdbuf[2] = (u32)max_connections; 228 | cmdbuf[3] = 0x20; 229 | 230 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 231 | 232 | ret = (int)cmdbuf[1]; 233 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 234 | SOCU_errno = ret; 235 | 236 | if(ret!=0)return -1; 237 | return 0; 238 | } 239 | 240 | int accept(int sockfd, struct sockaddr *addr, int *addrlen) 241 | { 242 | int ret=0; 243 | int tmp_addrlen=0x1c; 244 | u32 *cmdbuf = getThreadCommandBuffer(); 245 | u8 tmpaddr[0x1c]; 246 | u32 saved_threadstorage[2]; 247 | 248 | memset(tmpaddr, 0, 0x1c); 249 | 250 | cmdbuf[0] = 0x00040082; 251 | cmdbuf[1] = (u32)sockfd; 252 | cmdbuf[2] = (u32)tmp_addrlen; 253 | cmdbuf[3] = 0x20; 254 | 255 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 256 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 257 | 258 | cmdbuf[0x100>>2] = (tmp_addrlen<<14) | 2; 259 | cmdbuf[0x104>>2] = (u32)tmpaddr; 260 | 261 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 262 | 263 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 264 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 265 | 266 | ret = (int)cmdbuf[1]; 267 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 268 | if(ret<0)SOCU_errno = ret; 269 | 270 | if(ret>=0 && addr!=NULL) 271 | { 272 | addr->sa_family = tmpaddr[1]; 273 | if(*addrlen > tmpaddr[0])*addrlen = tmpaddr[0]; 274 | memcpy(addr->sa_data, &tmpaddr[2], *addrlen - 2); 275 | } 276 | 277 | if(ret<0)return -1; 278 | return ret; 279 | } 280 | 281 | int bind(int sockfd, const struct sockaddr *addr, int addrlen) 282 | { 283 | int ret=0; 284 | int tmp_addrlen=0; 285 | u32 *cmdbuf = getThreadCommandBuffer(); 286 | u8 tmpaddr[0x1c]; 287 | 288 | memset(tmpaddr, 0, 0x1c); 289 | 290 | if(addr->sa_family == AF_INET) 291 | { 292 | tmp_addrlen = 8; 293 | } 294 | else 295 | { 296 | tmp_addrlen = 0x1c; 297 | } 298 | 299 | if(addrlen < tmp_addrlen) 300 | { 301 | SOCU_errno = -EINVAL; 302 | return -1; 303 | } 304 | 305 | tmpaddr[0] = tmp_addrlen; 306 | tmpaddr[1] = addr->sa_family; 307 | memcpy(&tmpaddr[2], &addr->sa_data, tmp_addrlen-2); 308 | 309 | cmdbuf[0] = 0x00050084; 310 | cmdbuf[1] = (u32)sockfd; 311 | cmdbuf[2] = (u32)tmp_addrlen; 312 | cmdbuf[3] = 0x20; 313 | cmdbuf[5] = (((u32)tmp_addrlen)<<14) | 2; 314 | cmdbuf[6] = (u32)tmpaddr; 315 | 316 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 317 | 318 | ret = (int)cmdbuf[1]; 319 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 320 | SOCU_errno = ret; 321 | 322 | if(ret<0)return -1; 323 | return 0; 324 | } 325 | 326 | int connect(int sockfd, const struct sockaddr *addr, int addrlen) 327 | { 328 | int ret=0; 329 | int tmp_addrlen=0; 330 | u32 *cmdbuf = getThreadCommandBuffer(); 331 | u8 tmpaddr[0x1c]; 332 | 333 | memset(tmpaddr, 0, 0x1c); 334 | 335 | if(addr->sa_family == AF_INET) 336 | { 337 | tmp_addrlen = 8; 338 | } 339 | else 340 | { 341 | tmp_addrlen = 0x1c; 342 | } 343 | 344 | if(addrlen < tmp_addrlen) 345 | { 346 | SOCU_errno = -EINVAL; 347 | return -1; 348 | } 349 | 350 | tmpaddr[0] = tmp_addrlen; 351 | tmpaddr[1] = addr->sa_family; 352 | memcpy(&tmpaddr[2], &addr->sa_data, tmp_addrlen-2); 353 | 354 | cmdbuf[0] = 0x00060084; 355 | cmdbuf[1] = (u32)sockfd; 356 | cmdbuf[2] = (u32)addrlen; 357 | cmdbuf[3] = 0x20; 358 | cmdbuf[5] = (((u32)tmp_addrlen)<<14) | 2; 359 | cmdbuf[6] = (u32)tmpaddr; 360 | 361 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 362 | 363 | ret = (int)cmdbuf[1]; 364 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 365 | SOCU_errno = ret; 366 | 367 | if(ret<0)return -1; 368 | return 0; 369 | } 370 | 371 | int socuipc_cmd7(int sockfd, void *buf, int len, int flags, struct sockaddr *src_addr, int *addrlen) 372 | { 373 | int ret=0; 374 | u32 *cmdbuf = getThreadCommandBuffer(); 375 | u32 tmp_addrlen=0; 376 | u8 tmpaddr[0x1c]; 377 | u32 saved_threadstorage[2]; 378 | 379 | memset(tmpaddr, 0, 0x1c); 380 | 381 | if(src_addr)tmp_addrlen = 0x1c; 382 | 383 | cmdbuf[0] = 0x00070104; 384 | cmdbuf[1] = (u32)sockfd; 385 | cmdbuf[2] = (u32)len; 386 | cmdbuf[3] = (u32)flags; 387 | cmdbuf[4] = (u32)tmp_addrlen; 388 | cmdbuf[5] = 0x20; 389 | cmdbuf[7] = (((u32)len)<<4) | 12; 390 | cmdbuf[8] = (u32)buf; 391 | 392 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 393 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 394 | 395 | cmdbuf[0x100>>2] = (tmp_addrlen<<14) | 2; 396 | cmdbuf[0x104>>2] = (u32)tmpaddr; 397 | 398 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 399 | 400 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 401 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 402 | 403 | ret = (int)cmdbuf[1]; 404 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 405 | if(ret<0)SOCU_errno = ret; 406 | 407 | if(ret>0 && src_addr!=NULL) 408 | { 409 | src_addr->sa_family = tmpaddr[1]; 410 | if(*addrlen > tmpaddr[0])*addrlen = tmpaddr[0]; 411 | memcpy(src_addr->sa_data, &tmpaddr[2], *addrlen - 2); 412 | } 413 | 414 | if(ret<0)return -1; 415 | return ret; 416 | } 417 | 418 | int socuipc_cmd8(int sockfd, void *buf, int len, int flags, struct sockaddr *src_addr, int *addrlen) 419 | { 420 | int ret=0; 421 | u32 *cmdbuf = getThreadCommandBuffer(); 422 | u32 tmp_addrlen=0; 423 | u8 tmpaddr[0x1c]; 424 | u32 saved_threadstorage[4]; 425 | 426 | if(src_addr)tmp_addrlen = 0x1c; 427 | 428 | memset(tmpaddr, 0, 0x1c); 429 | 430 | cmdbuf[0] = 0x00080102; 431 | cmdbuf[1] = (u32)sockfd; 432 | cmdbuf[2] = (u32)len; 433 | cmdbuf[3] = (u32)flags; 434 | cmdbuf[4] = (u32)tmp_addrlen; 435 | cmdbuf[5] = 0x20; 436 | 437 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 438 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 439 | saved_threadstorage[2] = cmdbuf[0x108>>2]; 440 | saved_threadstorage[3] = cmdbuf[0x10c>>2]; 441 | 442 | cmdbuf[0x100>>2] = (((u32)len)<<14) | 2; 443 | cmdbuf[0x104>>2] = (u32)buf; 444 | cmdbuf[0x108>>2] = (tmp_addrlen<<14) | 2; 445 | cmdbuf[0x10c>>2] = (u32)tmpaddr; 446 | 447 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 448 | 449 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 450 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 451 | cmdbuf[0x108>>2] = saved_threadstorage[2]; 452 | cmdbuf[0x10c>>2] = saved_threadstorage[3]; 453 | 454 | ret = (int)cmdbuf[1]; 455 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 456 | if(ret<0)SOCU_errno = ret; 457 | 458 | if(ret>0 && src_addr!=NULL) 459 | { 460 | src_addr->sa_family = tmpaddr[1]; 461 | if(*addrlen > tmpaddr[0])*addrlen = tmpaddr[0]; 462 | memcpy(src_addr->sa_data, &tmpaddr[2], *addrlen - 2); 463 | } 464 | 465 | if(ret<0)return -1; 466 | return ret; 467 | } 468 | 469 | int socuipc_cmd9(int sockfd, const void *buf, int len, int flags, const struct sockaddr *dest_addr, int addrlen) 470 | { 471 | int ret=0; 472 | u32 *cmdbuf = getThreadCommandBuffer(); 473 | u32 tmp_addrlen=0; 474 | u8 tmpaddr[0x1c]; 475 | 476 | memset(tmpaddr, 0, 0x1c); 477 | 478 | if(dest_addr) 479 | { 480 | if(dest_addr->sa_family == AF_INET) 481 | { 482 | tmp_addrlen = 8; 483 | } 484 | else 485 | { 486 | tmp_addrlen = 0x1c; 487 | } 488 | 489 | if(addrlen < tmp_addrlen) 490 | { 491 | SOCU_errno = -EINVAL; 492 | return -1; 493 | } 494 | 495 | tmpaddr[0] = tmp_addrlen; 496 | tmpaddr[1] = dest_addr->sa_family; 497 | memcpy(&tmpaddr[2], &dest_addr->sa_data, tmp_addrlen-2); 498 | } 499 | 500 | cmdbuf[0] = 0x00090106; 501 | cmdbuf[1] = (u32)sockfd; 502 | cmdbuf[2] = (u32)len; 503 | cmdbuf[3] = (u32)flags; 504 | cmdbuf[4] = (u32)tmp_addrlen; 505 | cmdbuf[5] = 0x20; 506 | cmdbuf[7] = (tmp_addrlen<<14) | 0x402; 507 | cmdbuf[8] = (u32)tmpaddr; 508 | cmdbuf[9] = (((u32)len)<<4) | 10; 509 | cmdbuf[10] = (u32)buf; 510 | 511 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 512 | 513 | ret = (int)cmdbuf[1]; 514 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 515 | if(ret<0)SOCU_errno = ret; 516 | 517 | if(ret<0)return -1; 518 | return ret; 519 | } 520 | 521 | int socuipc_cmda(int sockfd, const void *buf, int len, int flags, const struct sockaddr *dest_addr, int addrlen) 522 | { 523 | int ret=0; 524 | u32 *cmdbuf = getThreadCommandBuffer(); 525 | u32 tmp_addrlen=0; 526 | u8 tmpaddr[0x1c]; 527 | 528 | memset(tmpaddr, 0, 0x1c); 529 | 530 | if(dest_addr) 531 | { 532 | if(dest_addr->sa_family == AF_INET) 533 | { 534 | tmp_addrlen = 8; 535 | } 536 | else 537 | { 538 | tmp_addrlen = 0x1c; 539 | } 540 | 541 | if(addrlen < tmp_addrlen) 542 | { 543 | SOCU_errno = -EINVAL; 544 | return -1; 545 | } 546 | 547 | tmpaddr[0] = tmp_addrlen; 548 | tmpaddr[1] = dest_addr->sa_family; 549 | memcpy(&tmpaddr[2], &dest_addr->sa_data, tmp_addrlen-2); 550 | } 551 | 552 | cmdbuf[0] = 0x000A0106; 553 | cmdbuf[1] = (u32)sockfd; 554 | cmdbuf[2] = (u32)len; 555 | cmdbuf[3] = (u32)flags; 556 | cmdbuf[4] = (u32)tmp_addrlen; 557 | cmdbuf[5] = 0x20; 558 | cmdbuf[7] = (((u32)len)<<14) | 0x802; 559 | cmdbuf[8] = (u32)buf; 560 | cmdbuf[9] = (tmp_addrlen<<14) | 0x402; 561 | cmdbuf[10] = (u32)tmpaddr; 562 | 563 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 564 | 565 | ret = (int)cmdbuf[1]; 566 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 567 | if(ret<0)SOCU_errno = ret; 568 | 569 | if(ret<0)return -1; 570 | return ret; 571 | } 572 | 573 | int recvfrom(int sockfd, void *buf, int len, int flags, struct sockaddr *src_addr, int *addrlen) 574 | { 575 | if(len<0x2000)return socuipc_cmd8(sockfd, buf, len, flags, src_addr, addrlen); 576 | return socuipc_cmd7(sockfd, buf, len, flags, src_addr, addrlen); 577 | } 578 | 579 | int sendto(int sockfd, const void *buf, int len, int flags, const struct sockaddr *dest_addr, int addrlen) 580 | { 581 | if(len<0x2000)return socuipc_cmda(sockfd, buf, len, flags, dest_addr, addrlen); 582 | return socuipc_cmd9(sockfd, buf, len, flags, (struct sockaddr*)dest_addr, addrlen); 583 | } 584 | 585 | int recv(int sockfd, void *buf, int len, int flags) 586 | { 587 | return recvfrom(sockfd, buf, len, flags, NULL, 0); 588 | } 589 | 590 | int send(int sockfd, const void *buf, int len, int flags) 591 | { 592 | return sendto(sockfd, buf, len, flags, NULL, 0); 593 | } 594 | 595 | int getsockopt(int sockfd, int level, int option_name, void * data, int * data_len) 596 | { 597 | int ret=0; 598 | u32 *cmdbuf = getThreadCommandBuffer(); 599 | u32 saved_threadstorage[2]; 600 | 601 | cmdbuf[0] = 0x00110102; 602 | cmdbuf[1] = (u32)sockfd; 603 | cmdbuf[2] = (u32)level; 604 | cmdbuf[3] = (u32)option_name; 605 | cmdbuf[4] = (u32)*data_len; 606 | cmdbuf[5] = 0x20; 607 | 608 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 609 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 610 | 611 | cmdbuf[0x100>>2] = ((*data_len)<<14) | 2; 612 | cmdbuf[0x104>>2] = (u32)data; 613 | 614 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 615 | 616 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 617 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 618 | 619 | ret = (int)cmdbuf[1]; 620 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 621 | if(ret<0)SOCU_errno = ret; 622 | 623 | if(ret==0)*data_len = cmdbuf[3]; 624 | 625 | if(ret<0)return -1; 626 | return ret; 627 | } 628 | 629 | int setsockopt(int sockfd, int level, int option_name, const void * data, int data_len) 630 | { 631 | int ret=0; 632 | u32 *cmdbuf = getThreadCommandBuffer(); 633 | 634 | cmdbuf[0] = 0x00120104; 635 | cmdbuf[1] = (u32)sockfd; 636 | cmdbuf[2] = (u32)level; 637 | cmdbuf[3] = (u32)option_name; 638 | cmdbuf[4] = (u32)data_len; 639 | cmdbuf[5] = 0x20; 640 | cmdbuf[7] = (data_len<<14) | 0x2402; 641 | cmdbuf[8] = (u32)data; 642 | 643 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 644 | 645 | ret = (int)cmdbuf[1]; 646 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 647 | if(ret<0)SOCU_errno = ret; 648 | 649 | if(ret<0)return -1; 650 | return ret; 651 | } 652 | 653 | int fcntl(int sockfd, int cmd, ...) 654 | { 655 | int ret=0; 656 | int arg=0; 657 | u32 *cmdbuf = getThreadCommandBuffer(); 658 | 659 | va_list args; 660 | va_start(args, cmd); 661 | 662 | if(cmd!=F_GETFL && cmd!=F_SETFL) 663 | { 664 | SOCU_errno = -EINVAL; 665 | return -1; 666 | } 667 | 668 | if(cmd==F_SETFL) 669 | { 670 | arg = va_arg(args, int); 671 | 672 | if(arg && arg!=O_NONBLOCK) 673 | { 674 | SOCU_errno = -EINVAL; 675 | return -1; 676 | } 677 | 678 | if(arg==O_NONBLOCK)arg = 0x4; 679 | } 680 | 681 | cmdbuf[0] = 0x001300C2; 682 | cmdbuf[1] = (u32)sockfd; 683 | cmdbuf[2] = (u32)cmd; 684 | cmdbuf[3] = (u32)arg; 685 | cmdbuf[4] = 0x20; 686 | 687 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 688 | 689 | ret = (int)cmdbuf[1]; 690 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 691 | if(ret<0)SOCU_errno = ret; 692 | 693 | if(ret<0)return -1; 694 | return ret; 695 | } 696 | 697 | int sockatmark(int sockfd) 698 | { 699 | int ret=0; 700 | u32 *cmdbuf = getThreadCommandBuffer(); 701 | 702 | cmdbuf[0] = 0x00150042; 703 | cmdbuf[1] = (u32)sockfd; 704 | cmdbuf[2] = 0x20; 705 | 706 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 707 | 708 | ret = (int)cmdbuf[1]; 709 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 710 | if(ret<0)SOCU_errno = ret; 711 | 712 | if(ret<0)return -1; 713 | return ret; 714 | } 715 | 716 | long gethostid() 717 | { 718 | int ret=0; 719 | u32 *cmdbuf = getThreadCommandBuffer(); 720 | 721 | cmdbuf[0] = 0x00160000; 722 | 723 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 724 | 725 | ret = (int)cmdbuf[1]; 726 | if(ret==0)ret = cmdbuf[2]; 727 | 728 | return ret; 729 | } 730 | 731 | int getsockname(int sockfd, struct sockaddr *addr, int * addr_len) 732 | { 733 | int ret=0; 734 | u32 *cmdbuf = getThreadCommandBuffer(); 735 | u32 saved_threadstorage[2]; 736 | u8 tmpaddr[0x1c]; 737 | 738 | cmdbuf[0] = 0x00170082; 739 | cmdbuf[1] = (u32)sockfd; 740 | cmdbuf[2] = 0x1c; 741 | cmdbuf[3] = 0x20; 742 | 743 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 744 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 745 | 746 | cmdbuf[0x100>>2] = (0x1c<<14) | 2; 747 | cmdbuf[0x104>>2] = (u32)tmpaddr; 748 | 749 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 750 | 751 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 752 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 753 | 754 | ret = (int)cmdbuf[1]; 755 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 756 | if(ret<0)SOCU_errno = ret; 757 | 758 | if(ret==0) 759 | { 760 | addr->sa_family = tmpaddr[1]; 761 | if(*addr_len > tmpaddr[0])*addr_len = tmpaddr[0]; 762 | memset(addr, 0, sizeof(struct sockaddr)); 763 | memcpy(addr->sa_data, &tmpaddr[2], *addr_len - 2); 764 | } 765 | 766 | if(ret<0)return -1; 767 | return ret; 768 | } 769 | 770 | int getpeername(int sockfd, struct sockaddr *addr, int * addr_len) 771 | { 772 | int ret=0; 773 | u32 *cmdbuf = getThreadCommandBuffer(); 774 | u32 saved_threadstorage[2]; 775 | u8 tmpaddr[0x1c]; 776 | 777 | cmdbuf[0] = 0x00180082; 778 | cmdbuf[1] = (u32)sockfd; 779 | cmdbuf[2] = 0x1c; 780 | cmdbuf[3] = 0x20; 781 | 782 | saved_threadstorage[0] = cmdbuf[0x100>>2]; 783 | saved_threadstorage[1] = cmdbuf[0x104>>2]; 784 | 785 | cmdbuf[0x100>>2] = (0x1c<<14) | 2; 786 | cmdbuf[0x104>>2] = (u32)tmpaddr; 787 | 788 | if((ret = svc_sendSyncRequest(SOCU_handle))!=0)return ret; 789 | 790 | cmdbuf[0x100>>2] = saved_threadstorage[0]; 791 | cmdbuf[0x104>>2] = saved_threadstorage[1]; 792 | 793 | ret = (int)cmdbuf[1]; 794 | if(ret==0)ret = _net_convert_error(cmdbuf[2]); 795 | if(ret<0)SOCU_errno = ret; 796 | 797 | if(ret==0) 798 | { 799 | addr->sa_family = tmpaddr[1]; 800 | if(*addr_len > tmpaddr[0])*addr_len = tmpaddr[0]; 801 | memset(addr, 0, sizeof(struct sockaddr)); 802 | memcpy(addr->sa_data, &tmpaddr[2], *addr_len - 2); 803 | } 804 | 805 | if(ret<0)return -1; 806 | return ret; 807 | } 808 | 809 | #endif // USE_SOCKET 810 | -------------------------------------------------------------------------------- /clock/source/libctru/srv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Handle srvHandle=0; 9 | 10 | Result initSrv() 11 | { 12 | Result ret=0; 13 | if(svc_connectToPort(&srvHandle, "srv:"))return ret; 14 | return srv_RegisterClient(&srvHandle); 15 | } 16 | 17 | Result exitSrv() 18 | { 19 | if(srvHandle)svc_closeHandle(srvHandle); 20 | } 21 | 22 | Result srv_RegisterClient(Handle* handleptr) 23 | { 24 | if(!handleptr)handleptr=&srvHandle; 25 | u32* cmdbuf=getThreadCommandBuffer(); 26 | cmdbuf[0]=0x10002; //request header code 27 | cmdbuf[1]=0x20; 28 | 29 | Result ret=0; 30 | if((ret=svc_sendSyncRequest(*handleptr)))return ret; 31 | 32 | return cmdbuf[1]; 33 | } 34 | 35 | Result srv_getServiceHandle(Handle* handleptr, Handle* out, char* server) 36 | { 37 | if(!handleptr)handleptr=&srvHandle; 38 | u8 l=strlen(server); 39 | if(!out || !server || l>8)return -1; 40 | 41 | u32* cmdbuf=getThreadCommandBuffer(); 42 | 43 | cmdbuf[0]=0x50100; //request header code 44 | strcpy((char*)&cmdbuf[1], server); 45 | cmdbuf[3]=l; 46 | cmdbuf[4]=0x0; 47 | 48 | Result ret=0; 49 | if((ret=svc_sendSyncRequest(*handleptr)))return ret; 50 | 51 | *out=cmdbuf[3]; 52 | 53 | return cmdbuf[1]; 54 | } 55 | -------------------------------------------------------------------------------- /clock/source/libctru/svc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | .align 4 4 | 5 | .global getThreadCommandBuffer 6 | .type getThreadCommandBuffer, %function 7 | getThreadCommandBuffer: 8 | mrc p15, 0, r0, c13, c0, 3 9 | add r0, #0x80 10 | bx lr 11 | 12 | 13 | .global svc_controlMemory 14 | .type svc_controlMemory, %function 15 | svc_controlMemory: 16 | stmfd sp!, {r0, r4} 17 | ldr r0, [sp, #0x8] 18 | ldr r4, [sp, #0x8+0x4] 19 | svc 0x01 20 | ldr r2, [sp], #4 21 | str r1, [r2] 22 | ldr r4, [sp], #4 23 | bx lr 24 | 25 | .global svc_exitProcess 26 | .type svc_exitProcess, %function 27 | svc_exitProcess: 28 | svc 0x03 29 | bx lr 30 | 31 | .global svc_createThread 32 | .type svc_createThread, %function 33 | svc_createThread: 34 | stmfd sp!, {r0, r4} 35 | ldr r0, [sp, #0x8] 36 | ldr r4, [sp, #0x8+0x4] 37 | svc 0x08 38 | ldr r2, [sp], #4 39 | str r1, [r2] 40 | ldr r4, [sp], #4 41 | bx lr 42 | 43 | .global svc_exitThread 44 | .type svc_exitThread, %function 45 | svc_exitThread: 46 | svc 0x09 47 | bx lr 48 | 49 | .global svc_sleepThread 50 | .type svc_sleepThread, %function 51 | svc_sleepThread: 52 | svc 0x0A 53 | bx lr 54 | 55 | .global svc_createMutex 56 | .type svc_createMutex, %function 57 | svc_createMutex: 58 | str r0, [sp, #-4]! 59 | svc 0x13 60 | ldr r3, [sp], #4 61 | str r1, [r3] 62 | bx lr 63 | 64 | .global svc_releaseMutex 65 | .type svc_releaseMutex, %function 66 | svc_releaseMutex: 67 | svc 0x14 68 | bx lr 69 | 70 | .global svc_releaseSemaphore 71 | .type svc_releaseSemaphore, %function 72 | svc_releaseSemaphore: 73 | str r0, [sp,#-4]! 74 | svc 0x16 75 | ldr r2, [sp], #4 76 | str r1, [r2] 77 | bx lr 78 | 79 | .global svc_createEvent 80 | .type svc_createEvent, %function 81 | svc_createEvent: 82 | str r0, [sp,#-4]! 83 | svc 0x17 84 | ldr r2, [sp], #4 85 | str r1, [r2] 86 | bx lr 87 | 88 | .global svc_signalEvent 89 | .type svc_signalEvent, %function 90 | svc_signalEvent: 91 | svc 0x18 92 | bx lr 93 | 94 | .global svc_clearEvent 95 | .type svc_clearEvent, %function 96 | svc_clearEvent: 97 | svc 0x19 98 | bx lr 99 | 100 | .global svc_createMemoryBlock 101 | .type svc_createMemoryBlock, %function 102 | svc_createMemoryBlock: 103 | str r0, [sp, #-4]! 104 | ldr r0, [sp, #4] 105 | svc 0x1E 106 | ldr r2, [sp], #4 107 | str r1, [r2] 108 | bx lr 109 | 110 | .global svc_mapMemoryBlock 111 | .type svc_mapMemoryBlock, %function 112 | svc_mapMemoryBlock: 113 | svc 0x1F 114 | bx lr 115 | 116 | .global svc_unmapMemoryBlock 117 | .type svc_unmapMemoryBlock, %function 118 | svc_unmapMemoryBlock: 119 | svc 0x20 120 | bx lr 121 | 122 | .global svc_arbitrateAddress 123 | .type svc_arbitrateAddress, %function 124 | svc_arbitrateAddress: 125 | svc 0x22 126 | bx lr 127 | 128 | .global svc_closeHandle 129 | .type svc_closeHandle, %function 130 | svc_closeHandle: 131 | svc 0x23 132 | bx lr 133 | 134 | .global svc_waitSynchronization1 135 | .type svc_waitSynchronization1, %function 136 | svc_waitSynchronization1: 137 | svc 0x24 138 | bx lr 139 | 140 | .global svc_waitSynchronizationN 141 | .type svc_waitSynchronizationN, %function 142 | svc_waitSynchronizationN: 143 | str r5, [sp, #-4]! 144 | mov r5, r0 145 | ldr r0, [sp, #0x4] 146 | ldr r4, [sp, #0x4+0x4] 147 | svc 0x25 148 | str r1, [r5] 149 | ldr r5, [sp], #4 150 | bx lr 151 | 152 | .global svc_getSystemTick 153 | .type svc_getSystemTick, %function 154 | svc_getSystemTick: 155 | svc 0x28 156 | bx lr 157 | 158 | .global svc_getSystemInfo 159 | .type svc_getSystemInfo, %function 160 | svc_getSystemInfo: 161 | stmfd sp!, {r0, r4} 162 | svc 0x2A 163 | ldr r4, [sp], #4 164 | str r1, [r4] 165 | str r2, [r4, #4] 166 | # str r3, [r4, #8] # ? 167 | ldr r4, [sp], #4 168 | bx lr 169 | 170 | .global svc_getProcessInfo 171 | .type svc_getProcessInfo, %function 172 | svc_getProcessInfo: 173 | stmfd sp!, {r0, r4} 174 | svc 0x2B 175 | ldr r4, [sp], #4 176 | str r1, [r4] 177 | str r2, [r4, #4] 178 | ldr r4, [sp], #4 179 | bx lr 180 | 181 | .global svc_connectToPort 182 | .type svc_connectToPort, %function 183 | svc_connectToPort: 184 | str r0, [sp,#-0x4]! 185 | svc 0x2D 186 | ldr r3, [sp], #4 187 | str r1, [r3] 188 | bx lr 189 | 190 | .global svc_sendSyncRequest 191 | .type svc_sendSyncRequest, %function 192 | svc_sendSyncRequest: 193 | svc 0x32 194 | bx lr 195 | 196 | .global svc_getProcessId 197 | .type svc_getProcessId, %function 198 | svc_getProcessId: 199 | str r0, [sp,#-0x4]! 200 | svc 0x35 201 | ldr r3, [sp], #4 202 | str r1, [r3] 203 | bx lr 204 | 205 | .global svc_getThreadId 206 | .type svc_getThreadId, %function 207 | svc_getThreadId: 208 | str r0, [sp,#-0x4]! 209 | svc 0x37 210 | ldr r3, [sp], #4 211 | str r1, [r3] 212 | bx lr 213 | 214 | 215 | .global svc_setThreadIdealProcessor 216 | .type svc_setThreadIdealProcessor, %function 217 | svc_setThreadIdealProcessor: 218 | svc 0x10 219 | bx lr 220 | 221 | .global svc_openThread 222 | .type svc_openThread, %function 223 | svc_openThread: 224 | str r0, [sp,#-0x4]! 225 | svc 0x34 226 | ldr r3, [sp], #4 227 | str r1, [r3] 228 | bx lr 229 | 230 | .global svc_flushProcessDataCache 231 | .type svc_flushProcessDataCache, %function 232 | svc_flushProcessDataCache: 233 | svc 0x54 234 | bx lr 235 | 236 | .global svc_invalidateProcessDataCache 237 | .type svc_invalidateProcessDataCache, %function 238 | svc_invalidateProcessDataCache: 239 | svc 0x52 240 | bx lr 241 | 242 | .global svc_queryMemory 243 | .type svc_queryMemory, %function 244 | svc_queryMemory: 245 | svc 0x02 246 | bx lr 247 | 248 | .global svc_addCodeSegment 249 | .type svc_addCodeSegment, %function 250 | svc_addCodeSegment: 251 | svc 0x7a 252 | bx lr 253 | 254 | .global svc_openProcess 255 | .type svc_openProcess, %function 256 | svc_openProcess: 257 | str r0, [sp,#-0x4]! 258 | svc 0x33 259 | ldr r3, [sp], #4 260 | str r1, [r3] 261 | bx lr 262 | 263 | .global svc_controlProcessMemory 264 | .type svc_controlProcessMemory, %function 265 | svc_controlProcessMemory: 266 | 267 | stmfd sp!, {r0, r4, r5} 268 | ldr r4, [sp, #0xC+0x0] 269 | ldr r5, [sp, #0xC+0x4] 270 | svc 0x70 271 | ldmfd sp!, {r2, r4, r5} 272 | bx lr 273 | 274 | 275 | .global svc_mapProcessMemory 276 | .type svc_mapProcessMemory, %function 277 | svc_mapProcessMemory: 278 | 279 | svc 0x71 280 | bx lr 281 | 282 | .global svc_startInterProcessDma 283 | .type svc_startInterProcessDma, %function 284 | svc_startInterProcessDma: 285 | 286 | stmfd sp!, {r0, r4, r5} 287 | ldr r0, [sp, #0xC] 288 | ldr r4, [sp, #0xC+0x4] 289 | ldr r5, [sp, #0xC+0x8] 290 | svc 0x55 291 | ldmfd sp!, {r2, r4, r5} 292 | str r1, [r2] 293 | bx lr 294 | 295 | .global svc_getDmaState 296 | .type svc_getDmaState, %function 297 | svc_getDmaState: 298 | 299 | str r0, [sp,#-0x4]! 300 | svc 0x57 301 | ldr r3, [sp], #4 302 | str r1, [r3] 303 | bx lr 304 | 305 | 306 | .global svc_backDoor 307 | .type svc_backDoor, %function 308 | svc_backDoor: 309 | svc 0x7b 310 | bx lr 311 | 312 | 313 | .global svc_getProcessList 314 | .type svc_getProcessList, %function 315 | svc_getProcessList: 316 | str r0, [sp,#-0x4]! 317 | svc 0x65 318 | ldr r3, [sp], #4 319 | str r1, [r3] 320 | bx lr 321 | 322 | 323 | .global svc_getThreadList 324 | .type svc_getThreadList, %function 325 | svc_getThreadList: 326 | str r0, [sp,#-0x4]! 327 | svc 0x66 328 | ldr r3, [sp], #4 329 | str r1, [r3] 330 | bx lr 331 | 332 | .global svc_getThreadContext 333 | .type svc_getThreadContext, %function 334 | svc_getThreadContext: 335 | svc 0x3b 336 | bx lr 337 | 338 | 339 | 340 | .global svc_debugActiveProcess 341 | .type svc_debugActiveProcess, %function 342 | svc_debugActiveProcess: 343 | str r0, [sp,#-0x4]! 344 | svc 0x60 345 | ldr r3, [sp], #4 346 | str r1, [r3] 347 | bx lr 348 | 349 | .global svc_readProcessMemory 350 | .type svc_readProcessMemory, %function 351 | svc_readProcessMemory: 352 | svc 0x6a 353 | bx lr 354 | 355 | .global svc_writeProcessMemory 356 | .type svc_writeProcessMemory, %function 357 | svc_writeProcessMemory: 358 | svc 0x6b 359 | bx lr 360 | 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /clock/source/libntrplg/pm.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | void dumpKernel() { 4 | 5 | } 6 | 7 | Handle hCurrentProcess = 0; 8 | u32 currentPid = 0; 9 | 10 | u32 getCurrentProcessId() { 11 | svc_getProcessId(¤tPid, 0xffff8001); 12 | return currentPid; 13 | } 14 | 15 | u32 getCurrentProcessHandle() { 16 | u32 handle = 0; 17 | u32 ret; 18 | 19 | if (hCurrentProcess != 0) { 20 | return hCurrentProcess; 21 | } 22 | svc_getProcessId(¤tPid, 0xffff8001); 23 | ret = svc_openProcess(&handle, currentPid); 24 | if (ret != 0) { 25 | showDbg("openProcess failed, ret: %08x", ret, 0); 26 | return 0; 27 | } 28 | hCurrentProcess = handle; 29 | return hCurrentProcess; 30 | } 31 | 32 | 33 | 34 | u32 protectRemoteMemory(Handle hProcess, void* addr, u32 size) { 35 | u32 outAddr = 0; 36 | 37 | return svc_controlProcessMemory(hProcess, addr, addr, size, 6, 7); 38 | } 39 | 40 | u32 protectMemory(void* addr, u32 size) { 41 | return protectRemoteMemory(getCurrentProcessHandle(), addr, size); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /clock/source/libntrplg/rt.c: -------------------------------------------------------------------------------- 1 | 2 | #include "global.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void rtInitLock(RT_LOCK *lock) { 11 | lock->value = 0; 12 | } 13 | 14 | void rtAcquireLock(RT_LOCK *lock) { 15 | while(lock->value != 0) { 16 | svc_sleepThread(1000000); 17 | } 18 | lock->value = 1; 19 | } 20 | 21 | void rtReleaseLock(RT_LOCK *lock) { 22 | lock->value = 0; 23 | } 24 | 25 | u32 rtAlignToPageSize(u32 size) { 26 | return ((size / 0x1000) + 1) * 0x1000; 27 | } 28 | 29 | u32 rtGetPageOfAddress(u32 addr) { 30 | return (addr / 0x1000) * 0x1000; 31 | } 32 | 33 | 34 | u32 rtCheckRemoteMemoryRegionSafeForWrite(Handle hProcess, u32 addr, u32 size) { 35 | u32 ret; 36 | u32 startPage, endPage, page; 37 | 38 | startPage = rtGetPageOfAddress(addr); 39 | endPage = rtGetPageOfAddress(addr + size - 1); 40 | 41 | for (page = startPage; page <= endPage; page += 0x1000) { 42 | ret = protectRemoteMemory(hProcess, (void*) page, 0x1000); 43 | if (ret != 0) { 44 | return ret; 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | u32 rtSafeCopyMemory(u32 dst, u32 src, u32 size) { 51 | u32 ret; 52 | 53 | ret = rtCheckRemoteMemoryRegionSafeForWrite(0xffff8001, dst, size) ; 54 | if (ret != 0) { 55 | return ret; 56 | } 57 | ret = rtCheckRemoteMemoryRegionSafeForWrite(0xffff8001, src, size) ; 58 | if (ret != 0) { 59 | return ret; 60 | } 61 | memcpy((void*) dst, (void*) src, size); 62 | return 0; 63 | } 64 | 65 | #if USE_SOCKET 66 | 67 | 68 | int rtRecvSocket(u32 sockfd, u8 *buf, int size) 69 | { 70 | int ret, pos=0; 71 | int tmpsize=size; 72 | 73 | while(tmpsize) 74 | { 75 | if((ret = recv(sockfd, &buf[pos], tmpsize, 0))<=0) 76 | { 77 | if(ret<0)ret = SOC_GetErrno(); 78 | if(ret == -EWOULDBLOCK)continue; 79 | return ret; 80 | } 81 | pos+= ret; 82 | tmpsize-= ret; 83 | } 84 | 85 | return size; 86 | } 87 | 88 | int rtSendSocket(u32 sockfd, u8 *buf, int size) 89 | { 90 | int ret, pos=0; 91 | int tmpsize=size; 92 | 93 | while(tmpsize) 94 | { 95 | if((ret = send(sockfd, &buf[pos], tmpsize, 0))<0) 96 | { 97 | ret = SOC_GetErrno(); 98 | if(ret == -EWOULDBLOCK)continue; 99 | return ret; 100 | } 101 | pos+= ret; 102 | tmpsize-= ret; 103 | } 104 | 105 | return size; 106 | } 107 | 108 | u16 rtIntToPortNumber(u16 x) { 109 | u8* buf; 110 | u8 tmp; 111 | 112 | buf = (void*)&x; 113 | tmp = buf[0]; 114 | buf[0] = buf[1]; 115 | buf[1] = tmp; 116 | return *((u16*)buf); 117 | } 118 | 119 | #endif 120 | 121 | u32 rtGetFileSize(u8* fileName) { 122 | u32 hFile, size, ret; 123 | u64 size64 ; 124 | 125 | FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; 126 | ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); 127 | if (ret != 0) { 128 | nsDbgPrint("openFile failed: %08x\n", ret, 0); 129 | hFile = 0; 130 | goto final; 131 | } 132 | ret = FSFILE_GetSize(hFile, &size64); 133 | if (ret != 0) { 134 | nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); 135 | goto final; 136 | } 137 | size = size64; 138 | 139 | final: 140 | if (hFile != 0) { 141 | svc_closeHandle(hFile); 142 | } 143 | if (ret != 0) { 144 | return 0; 145 | } 146 | return size; 147 | } 148 | 149 | u32 rtLoadFileToBuffer(u8* fileName, u32* pBuf, u32 bufSize) { 150 | u32 ret; 151 | u32 hFile, size; 152 | u64 size64; 153 | u32 tmp; 154 | 155 | FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; 156 | ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); 157 | if (ret != 0) { 158 | nsDbgPrint("openFile failed: %08x\n", ret, 0); 159 | hFile = 0; 160 | goto final; 161 | } 162 | 163 | ret = FSFILE_GetSize(hFile, &size64); 164 | if (ret != 0) { 165 | nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); 166 | goto final; 167 | } 168 | 169 | size = size64; 170 | 171 | if (bufSize < size) { 172 | nsDbgPrint("rtLoadFileToBuffer: buffer too small\n"); 173 | ret = -1; 174 | goto final; 175 | } 176 | 177 | ret = FSFILE_Read(hFile, &tmp, 0, (u32*)pBuf, size); 178 | if(ret != 0) { 179 | nsDbgPrint("FSFILE_Read failed: %08x\n", ret, 0); 180 | goto final; 181 | } 182 | 183 | final: 184 | if (hFile != 0) { 185 | svc_closeHandle(hFile); 186 | } 187 | if (ret != 0) { 188 | return 0; 189 | } 190 | 191 | return size; 192 | } 193 | 194 | 195 | u32 rtGenerateJumpCode(u32 dst, u32* buf) { 196 | buf[0] = 0xe51ff004; 197 | buf[1] = dst; 198 | return 8; 199 | } 200 | 201 | void rtInitHook(RT_HOOK* hook, u32 funcAddr, u32 callbackAddr) { 202 | hook->model = 0; 203 | hook->isEnabled = 0; 204 | hook->funcAddr = funcAddr; 205 | 206 | rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), funcAddr, 8); 207 | memcpy(hook->bakCode, (void*) funcAddr, 8); 208 | rtGenerateJumpCode(callbackAddr, hook->jmpCode); 209 | memcpy(hook->callCode, (void*) funcAddr, 8); 210 | rtGenerateJumpCode(funcAddr + 8, &(hook->callCode[2])); 211 | rtFlushInstructionCache(hook->callCode, 16); 212 | } 213 | 214 | u32 rtFlushInstructionCache(void* ptr, u32 size) { 215 | return svc_flushProcessDataCache(0xffff8001, (u32)ptr, size); 216 | } 217 | 218 | void rtEnableHook(RT_HOOK* hook) { 219 | if (hook->isEnabled) { 220 | return; 221 | } 222 | memcpy((void*) hook->funcAddr, hook->jmpCode, 8); 223 | rtFlushInstructionCache((void*) hook->funcAddr, 8); 224 | hook->isEnabled = 1; 225 | } 226 | 227 | void rtDisableHook(RT_HOOK* hook) { 228 | if (!hook->isEnabled) { 229 | return; 230 | } 231 | memcpy((void*) hook->funcAddr, hook->bakCode, 8); 232 | rtFlushInstructionCache((void*) hook->funcAddr, 8); 233 | hook->isEnabled = 0; 234 | } -------------------------------------------------------------------------------- /clock/source/libntrplg/sharedfunc.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | 4 | 5 | void initSharedFunc() { 6 | 7 | INIT_SHARED_FUNC(showDbg, 0); 8 | INIT_SHARED_FUNC(nsDbgPrint, 1); 9 | INIT_SHARED_FUNC(plgRegisterMenuEntry, 2); 10 | INIT_SHARED_FUNC(plgGetSharedServiceHandle, 3); 11 | INIT_SHARED_FUNC(plgRequestMemory, 4); 12 | INIT_SHARED_FUNC(plgRegisterCallback, 5); 13 | INIT_SHARED_FUNC(xsprintf, 6); 14 | } 15 | -------------------------------------------------------------------------------- /clock/source/libntrplg/stub.s: -------------------------------------------------------------------------------- 1 | .global showDbg; 2 | .type showDbg, %function; 3 | showDbg: 4 | nop 5 | nop 6 | 7 | 8 | .global nsDbgPrint; 9 | .type nsDbgPrint, %function; 10 | nsDbgPrint: 11 | nop 12 | nop 13 | 14 | 15 | .global plgRegisterMenuEntry; 16 | .type plgRegisterMenuEntry, %function; 17 | plgRegisterMenuEntry: 18 | nop 19 | nop 20 | 21 | 22 | .global plgGetSharedServiceHandle; 23 | .type plgGetSharedServiceHandle, %function; 24 | plgGetSharedServiceHandle: 25 | nop 26 | nop 27 | 28 | 29 | .global plgRequestMemory; 30 | .type plgRequestMemory, %function; 31 | plgRequestMemory: 32 | nop 33 | nop 34 | 35 | .global plgRegisterCallback; 36 | .type plgRegisterCallback, %function; 37 | plgRegisterCallback: 38 | nop 39 | nop 40 | 41 | .global xsprintf; 42 | .type xsprintf, %function; 43 | xsprintf: 44 | nop 45 | nop 46 | 47 | 48 | -------------------------------------------------------------------------------- /clock/source/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "global.h" 3 | #include "ov.h" 4 | 5 | FS_archive sdmcArchive = { 0x9, (FS_path){ PATH_EMPTY, 1, (u8*)"" } }; 6 | Handle fsUserHandle = 0; 7 | 8 | #define CALLBACK_OVERLAY (101) 9 | 10 | #define __datetime_selector (*(vu32*)0x1FF81000) 11 | #define __datetime0 (*(volatile datetime_t*)0x1FF81020) 12 | #define __datetime1 (*(volatile datetime_t*)0x1FF81040) 13 | 14 | #define TICKS_PER_MSEC (268123.480) 15 | 16 | typedef struct { 17 | u64 date_time; 18 | u64 update_tick; 19 | //... 20 | } datetime_t; 21 | 22 | static Handle ptmuHandle; 23 | 24 | Result ptmuInit(void) 25 | { 26 | Result res = srv_getServiceHandle(NULL, &ptmuHandle, "ptm:u"); 27 | return res; 28 | } 29 | 30 | static datetime_t getSysTime(void) { 31 | u32 s1, s2 = __datetime_selector & 1; 32 | datetime_t dt; 33 | 34 | do { 35 | s1 = s2; 36 | if(!s1) 37 | dt = __datetime0; 38 | else 39 | dt = __datetime1; 40 | s2 = __datetime_selector & 1; 41 | } while(s2 != s1); 42 | 43 | return dt; 44 | } 45 | 46 | u64 osGetTime(void) { 47 | datetime_t dt = getSysTime(); 48 | 49 | u64 delta = svc_getSystemTick() - dt.update_tick; 50 | 51 | return dt.date_time + (u64)(((double)(delta))/TICKS_PER_MSEC); 52 | } 53 | 54 | 55 | 56 | static inline u32 IPC_MakeHeader(u16 command_id, unsigned normal_params, unsigned translate_params) 57 | { 58 | return ((u32) command_id << 16) | (((u32) normal_params & 0x3F) << 6) | (((u32) translate_params & 0x3F) << 0); 59 | } 60 | 61 | Result PTMU_GetBatteryLevel(u8 *out) 62 | { 63 | Result ret=0; 64 | u32 *cmdbuf = getThreadCommandBuffer(); 65 | 66 | cmdbuf[0] = IPC_MakeHeader(0x7,0,0); // 0x70000 67 | 68 | if((ret = svc_sendSyncRequest(ptmuHandle)))return ret; 69 | 70 | *out = (u8)cmdbuf[2] & 0xFF; 71 | 72 | return (Result)cmdbuf[1]; 73 | } 74 | 75 | 76 | 77 | 78 | #define SECONDS_IN_DAY 86400 79 | #define SECONDS_IN_HOUR 3600 80 | #define SECONDS_IN_MINUTE 60 81 | 82 | 83 | void drawWidget(int batteryLevel, u32 addr, u32 stride, u32 format, u8 hour, u8 min, int colOffset) { 84 | 85 | char buf[30]; 86 | 87 | 88 | 89 | 90 | 91 | int batval = 0; 92 | if (batteryLevel == 1) { 93 | batval = 2; 94 | } else if (batteryLevel == 2) { 95 | batval = 5; 96 | } else if (batteryLevel == 3) { 97 | batval = 8; 98 | } else if (batteryLevel == 4) { 99 | batval = 11; 100 | } else if (batteryLevel == 5) { 101 | batval = 16; 102 | } 103 | 104 | 105 | ovDrawTranspartBlackRect(addr, stride, format, 9, colOffset, 12, 62 + 4, 1); 106 | ovDrawRect(addr, stride, format, 11, colOffset + 46, 1, 16, 255, 255, 255); 107 | ovDrawRect(addr, stride, format, 17, colOffset + 46, 1, 16, 255, 255, 255); 108 | ovDrawRect(addr, stride, format, 11, colOffset + 46, 7, 1, 255, 255, 255); 109 | ovDrawRect(addr, stride, format, 11, colOffset + 61, 7, 1, 255, 255, 255); 110 | ovDrawRect(addr, stride, format, 11, colOffset + 46, 7, batval, 255, 255, 255); 111 | ovDrawRect(addr, stride, format, 13, colOffset + 62, 3, 1, 255, 255, 255); 112 | 113 | xsprintf(buf, "%02d:%02d", hour, min); 114 | ovDrawString(addr, stride, format, 400, 11, colOffset + 4, 255, 255, 255, buf); 115 | } 116 | 117 | 118 | /* 119 | Overlay Callback. 120 | isBottom: 1 for bottom screen, 0 for top screen. 121 | addr: writable cached framebuffer virtual address. 122 | addrB: right-eye framebuffer for top screen, undefined for bottom screen. 123 | stride: framebuffer stride(pitch) in bytes, at least 240*bytes_per_pixel. 124 | format: framebuffer format, see https://www.3dbrew.org/wiki/GPU/External_Registers for details. 125 | 126 | NTR will invalidate data cache of the framebuffer before calling overlay callbacks. NTR will flush data cache after the callbacks were called and at least one overlay callback returns zero. 127 | 128 | return 0 when the framebuffer was modified. return 1 when nothing in the framebuffer was modified. 129 | */ 130 | 131 | u32 overlayCallback(u32 isBottom, u32 addr, u32 addrB, u32 stride, u32 format) { 132 | static u32 count = 0; 133 | static u8 batteryLevel = 0; 134 | 135 | u32 height = isBottom ? 320 : 400; 136 | if (isBottom == 0) { 137 | if (count == 0) { 138 | PTMU_GetBatteryLevel(&batteryLevel); 139 | } 140 | count ++; 141 | if (count > 100) { 142 | count = 0; 143 | } 144 | 145 | u64 timeInSeconds = osGetTime() / 1000; 146 | u64 dayTime = timeInSeconds % SECONDS_IN_DAY; 147 | u8 hour = dayTime / SECONDS_IN_HOUR; 148 | u8 min = (dayTime % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE; 149 | u8 seconds = dayTime % SECONDS_IN_MINUTE; 150 | 151 | drawWidget(batteryLevel, addr, stride, format, hour, min, 332); 152 | // In 2D mode, top screen's addrB might be invalid or equal to addr, do not draw on addrB in either situations 153 | if ((addrB) && (addrB != addr)) { 154 | drawWidget(batteryLevel, addrB, stride, format, hour, min, 328); 155 | } 156 | return 0; 157 | } 158 | return 1; 159 | } 160 | 161 | int main() { 162 | u32 retv; 163 | 164 | initSharedFunc(); 165 | // Init srv client and ptmu client for monitoring battery status. 166 | initSrv(); 167 | ptmuInit(); 168 | // Register overlay callback. 169 | plgRegisterCallback(CALLBACK_OVERLAY, (void*) overlayCallback, 0); 170 | return 0; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /clock/source/misc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align(4); 3 | 4 | .global sleep 5 | .type sleep, %function 6 | sleep: 7 | SVC 0xA 8 | BX LR 9 | 10 | -------------------------------------------------------------------------------- /clock/source/ov.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "font.h" 3 | #include "ov.h" 4 | 5 | void ovDrawTranspartBlackRect(u32 addr, u32 stride, u32 format, int r, int c, int h, int w, u8 level) { 6 | format &= 0x0f; 7 | int posC; 8 | for (posC = c; posC < c + w; posC ++ ) { 9 | if (format == 2) { 10 | u16* sp = (u16*)(addr + stride * posC + 240 * 2 - 2 * (r + h - 1)); 11 | u16* spEnd = sp + h; 12 | while (sp < spEnd) { 13 | u16 pix = *sp; 14 | u16 r = (pix >> 11) & 0x1f; 15 | u16 g = (pix >> 5) & 0x3f; 16 | u16 b = (pix & 0x1f); 17 | pix = ((r >> level) << 11) | ((g >> level) << 5) | (b >> level); 18 | *sp = pix; 19 | sp++; 20 | } 21 | } else if (format == 1) { 22 | u8* sp = (u8*)(addr + stride * posC + 240 * 3 - 3 * (r + h - 1)); 23 | u8* spEnd = sp + 3 * h; 24 | while (sp < spEnd) { 25 | sp[0] >>= level; 26 | sp[1] >>= level; 27 | sp[2] >>= level; 28 | sp += 3; 29 | } 30 | } 31 | } 32 | } 33 | 34 | void ovDrawPixel(u32 addr, u32 stride, u32 format, int posR, int posC, u32 r, u32 g, u32 b) { 35 | format &= 0x0f; 36 | if (format == 2) { 37 | u16 pix = ((r ) << 11) | ((g ) << 5) | (b ); 38 | *(u16*)(addr + stride * posC + 240 * 2 -2 * posR) = pix; 39 | } else { 40 | u8* sp = (u8*)(addr + stride * posC + 240 * 3 - 3 * posR); 41 | sp[0] = b; 42 | sp[1] = g; 43 | sp[2] = r; 44 | } 45 | } 46 | 47 | void ovDrawRect(u32 addr, u32 stride, u32 format, int posR, int posC, int h, int w, u32 r, u32 g, u32 b) { 48 | int r_, c_; 49 | for (c_ = posC; c_ < posC + w; c_ ++) { 50 | for (r_ = posR; r_ < posR + h; r_ ++) { 51 | ovDrawPixel(addr, stride, format, r_, c_, r, g, b); 52 | } 53 | } 54 | } 55 | 56 | void ovDrawChar(u32 addr, u32 stride, u32 format, u8 letter,int y, int x, u32 r, u32 g, u32 b){ 57 | 58 | int i; 59 | int k; 60 | int c; 61 | unsigned char mask; 62 | unsigned char* _letter; 63 | unsigned char l; 64 | 65 | if ((letter < 32) || (letter > 127)) { 66 | letter = '?'; 67 | } 68 | 69 | c=(letter-32)*8; 70 | 71 | for (i = 0; i < 8; i++){ 72 | mask = 0b10000000; 73 | l = font[i+c]; 74 | for (k = 0; k < 8; k++){ 75 | if ((mask >> k) & l){ 76 | ovDrawPixel(addr, stride, format, i+y, k+x ,r,g,b); 77 | } 78 | } 79 | } 80 | } 81 | 82 | void ovDrawString(u32 addr, u32 stride, u32 format, u32 scrnWidth, int posR, int posC, u32 r, u32 g, u32 b, u8* buf) { 83 | while(*buf) { 84 | if ((posR + 8 > 240) || (posC + 8 > scrnWidth)) { 85 | return; 86 | } 87 | ovDrawChar(addr, stride, format, *buf, posR, posC, r, g, b); 88 | buf++; 89 | posC += 8; 90 | 91 | } 92 | } -------------------------------------------------------------------------------- /clock/source/ov.h: -------------------------------------------------------------------------------- 1 | void ovDrawTranspartBlackRect(u32 addr, u32 stride, u32 format, int r, int c, int h, int w, u8 level) ; 2 | void ovDrawPixel(u32 addr, u32 stride, u32 format, int posR, int posC, u32 r, u32 g, u32 b); 3 | void ovDrawRect(u32 addr, u32 stride, u32 format, int posR, int posC, int h, int w, u32 r, u32 g, u32 b); 4 | void ovDrawChar(u32 addr, u32 stride, u32 format, u8 letter,int y, int x, u32 r, u32 g, u32 b); 5 | void ovDrawString(u32 addr, u32 stride, u32 format, u32 scrnWidth, int posR, int posC, u32 r, u32 g, u32 b, u8* buf); 6 | 7 | -------------------------------------------------------------------------------- /clock/startenv.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | cmd -------------------------------------------------------------------------------- /fps/3ds.ld: -------------------------------------------------------------------------------- 1 | 2 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 3 | OUTPUT_ARCH(arm) 4 | ENTRY(_Reset) 5 | SECTIONS 6 | { 7 | . = 0x00100100; 8 | . = ALIGN(4); 9 | .text : { 10 | __text_start = .; 11 | bootloader.o (.text*) 12 | *(.text*) 13 | } 14 | . = ALIGN(4); 15 | .data : { 16 | *(.data) 17 | } 18 | . = ALIGN(4); 19 | 20 | . = ALIGN(4); 21 | .rel.dyn : { 22 | *(.__rel_dyn_start) 23 | *(.rel*) 24 | *(.rel.*) 25 | *(.__rel_dyn_end) 26 | } 27 | 28 | __code_end = .; 29 | 30 | . = ALIGN(4); 31 | .bss : { 32 | *(.__bss_start) 33 | *(.bss COMMON) 34 | *(.__bss_end) 35 | } 36 | __end__ = .; 37 | } 38 | -------------------------------------------------------------------------------- /fps/bin/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/fps/bin/empty.txt -------------------------------------------------------------------------------- /fps/build.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | build.py -------------------------------------------------------------------------------- /fps/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys 3 | import os 4 | import ftplib 5 | import glob 6 | 7 | # the path plugin was copied to 8 | COPYTOPATH = 'fps.plg' 9 | 10 | CC = "arm-none-eabi-gcc" 11 | CP = "arm-none-eabi-g++" 12 | OC = "arm-none-eabi-objcopy" 13 | LD = "arm-none-eabi-ld" 14 | CTRULIB = '../libctru' 15 | DEVKITARM = 'c:/devkitPro/devkitARM' 16 | LIBPATH = '-L ./lib' 17 | 18 | def allFile(pattern): 19 | s = ""; 20 | for file in glob.glob(pattern): 21 | s += file + " "; 22 | return s; 23 | 24 | def run(cmd): 25 | os.system(cmd) 26 | 27 | cwd = os.getcwd() 28 | run("rm obj/*.o") 29 | run("rm bin/*.elf") 30 | run(CC+ " -s -g -I include -I include/libntrplg " + allFile('source/libntrplg/*.c') + allFile('source/ns/*.c') + allFile('source/*.c') + allFile('source/libctru/*.c') + " -c -march=armv6 -mlittle-endian "); 31 | run(CC+" -Os " + allFile('source/libntrplg/*.s') + allFile('source/ns/*.s') + allFile('source/*.s') + allFile('source/libctru/*.s') + " -c -s -march=armv6 -mlittle-endian "); 32 | 33 | run(LD + ' ' + LIBPATH + " -pie --print-gc-sections -T 3ds.ld -Map=homebrew.map " + allFile("*.o") + " -lc -lgcc --nostdlib" ) 34 | run("cp -r *.o obj/ ") 35 | run("cp a.out bin/homebrew.elf ") 36 | run(OC+" -O binary a.out payload.bin -S") 37 | run("rm *.o") 38 | run("rm *.out") 39 | run('copy payload.bin ' + COPYTOPATH); 40 | -------------------------------------------------------------------------------- /fps/include/ctr/AC.h: -------------------------------------------------------------------------------- 1 | #ifndef AC_H 2 | #define AC_H 3 | 4 | Result ACU_GetWifiStatus(Handle servhandle, u32 *out); 5 | Result ACU_WaitInternetConnection(); 6 | 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /fps/include/ctr/APT.h: -------------------------------------------------------------------------------- 1 | #ifndef APT_H 2 | #define APT_H 3 | 4 | typedef enum{ 5 | APPID_HOMEMENU = 0x101, // Home Menu 6 | APPID_CAMERA = 0x110, // Camera applet 7 | APPID_WEB = 0x114, // Internet Browser 8 | APPID_APPLICATION = 0x300, // Application 9 | }NS_APPID; // cf http://3dbrew.org/wiki/NS#AppIDs 10 | 11 | typedef enum{ 12 | APP_NOTINITIALIZED, 13 | APP_RUNNING, 14 | APP_SUSPENDED, 15 | APP_EXITING, 16 | APP_SUSPENDING, 17 | APP_SLEEPMODE, 18 | APP_PREPARE_SLEEPMODE 19 | }APP_STATUS; 20 | 21 | extern Handle aptEvents[3]; 22 | 23 | Result aptInit(NS_APPID appID); 24 | void aptExit(); 25 | void aptOpenSession(); 26 | void aptCloseSession(); 27 | void aptSetupEventHandler(); 28 | void aptSetStatus(APP_STATUS status); 29 | APP_STATUS aptGetStatus(); 30 | u32 aptGetStatusPower();//This can be used when the status is APP_SUSPEND* to check how the return-to-menu was triggered: 0 = home-button, 1 = power-button. 31 | void aptSetStatusPower(u32 status); 32 | void aptReturnToMenu();//This should be called by the user application when aptGetStatus() returns APP_SUSPENDING, not calling this will result in return-to-menu being disabled with the status left at APP_SUSPENDING. This function will not return until the system returns to the application, or when the status was changed to APP_EXITING. 33 | void aptWaitStatusEvent(); 34 | NS_APPID aptGetMenuAppID(); 35 | 36 | Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle); 37 | Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2); 38 | Result APT_Enable(Handle* handle, u32 a); 39 | Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid); 40 | Result APT_PrepareToJumpToHomeMenu(Handle* handle); 41 | Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c); 42 | Result APT_InquireNotification(Handle* handle, u32 appID, u8* signalType); 43 | Result APT_NotifyToWait(Handle* handle, NS_APPID appID); 44 | Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2); 45 | Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); 46 | Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); 47 | Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType); 48 | Result APT_SendCaptureBufferInfo(Handle* handle, u32 bufferSize, u32* buffer); 49 | Result APT_ReplySleepQuery(Handle* handle, NS_APPID appID, u32 a); 50 | Result APT_ReplySleepNotificationComplete(Handle* handle, NS_APPID appID); 51 | Result APT_PrepareToCloseApplication(Handle* handle, u8 a); 52 | Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /fps/include/ctr/CFGNOR.h: -------------------------------------------------------------------------------- 1 | #ifndef CFGNOR_H 2 | #define CFGNOR_H 3 | 4 | Result CFGNOR_Initialize(u8 value); 5 | Result CFGNOR_Shutdown(); 6 | Result CFGNOR_ReadData(u32 offset, u32 *buf, u32 size); 7 | Result CFGNOR_WriteData(u32 offset, u32 *buf, u32 size); 8 | Result CFGNOR_DumpFlash(u32 *buf, u32 size); 9 | Result CFGNOR_WriteFlash(u32 *buf, u32 size); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /fps/include/ctr/CSND.h: -------------------------------------------------------------------------------- 1 | #ifndef CSND_H 2 | #define CSND_H 3 | 4 | //See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory 5 | 6 | #define CSND_SHAREDMEM_DEFAULT 0x10004000 7 | 8 | typedef enum{ 9 | CSND_LOOP_DISABLE, 10 | CSND_LOOP_ENABLE 11 | } CSND_LOOPING; 12 | 13 | typedef enum{ 14 | CSND_ENCODING_PCM8, 15 | CSND_ENCODING_PCM16, 16 | CSND_ENCODING_IMA_ADPCM, 17 | CSND_ENCODING_PSG//"3 = PSG, similar to DS?" 18 | } CSND_ENCODING; 19 | 20 | Result CSND_initialize(u32* sharedMem); 21 | Result CSND_shutdown(); 22 | 23 | Result CSND_playsound(u32 channel, CSND_LOOPING looping, CSND_ENCODING encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1);//vaddr0 is the initial virtual-address of the audio-data. vaddr1 is the audio-data virtual-address used for looping, when playback is restarted for looping. 24 | void CSND_setchannel_playbackstate(u32 channel, u32 value);//value0 = pause playback, value1 = resume playback. 25 | void CSND_sharedmemtype0_cmd0(u32 channel, u32 value);//value1 = start playback. value0 = stop playback, and reset the CSND registers for this channel. 26 | void CSND_writesharedmem_cmdtype0(u16 cmdid, u8 *cmdparams);//This can be used to use arbitary CSND shared-memory commands. 27 | Result CSND_sharedmemtype0_cmdupdatestate(int waitdone);//This must be used after using CSND shared-memory commands in order for those commands to be processed. CSND_playsound() and CSND_getchannelstate() use this automatically. 28 | 29 | Result CSND_getchannelstate(u32 entryindex, u32 *out); 30 | Result CSND_getchannelstate_isplaying(u32 entryindex, u8 *status); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /fps/include/ctr/FS.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_H 2 | #define FS_H 3 | 4 | #define FS_OPEN_READ (1<<0) 5 | #define FS_OPEN_WRITE (1<<1) 6 | #define FS_OPEN_CREATE (1<<2) 7 | 8 | #define FS_ATTRIBUTE_NONE (0x00000000) 9 | #define FS_ATTRIBUTE_READONLY (0x00000001) 10 | #define FS_ATTRIBUTE_ARCHIVE (0x00000100) 11 | #define FS_ATTRIBUTE_HIDDEN (0x00010000) 12 | #define FS_ATTRIBUTE_DIRECTORY (0x01000000) 13 | 14 | typedef enum{ 15 | PATH_INVALID = 0, // Specifies an invalid path. 16 | PATH_EMPTY = 1, // Specifies an empty path. 17 | PATH_BINARY = 2, // Specifies a binary path, which is non-text based. 18 | PATH_CHAR = 3, // Specifies a text based path with a 8-bit byte per character. 19 | PATH_WCHAR = 4, // Specifies a text based path with a 16-bit short per character. 20 | }FS_pathType; 21 | 22 | typedef struct{ 23 | FS_pathType type; 24 | u32 size; 25 | u8* data; 26 | }FS_path; 27 | 28 | typedef struct{ 29 | u32 id; 30 | FS_path lowPath; 31 | Handle handleLow, handleHigh; 32 | }FS_archive; 33 | 34 | static inline FS_path FS_makePath(FS_pathType type, char* path) 35 | { 36 | return (FS_path){type, strlen(path)+1, (u8*)path}; 37 | } 38 | 39 | Result FSUSER_Initialize(Handle handle); 40 | Result FSUSER_OpenArchive(Handle handle, FS_archive* archive); 41 | Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath); 42 | Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); 43 | Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes); 44 | Result FSUSER_CloseArchive(Handle handle, FS_archive* archive); 45 | 46 | Result FSFILE_Close(Handle handle); 47 | Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size); 48 | Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *buffer, u32 size, u32 flushFlags); 49 | Result FSFILE_GetSize(Handle handle, u64 *size); 50 | Result FSFILE_SetSize(Handle handle, u64 size); 51 | 52 | Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer); 53 | Result FSDIR_Close(Handle handle); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /fps/include/ctr/GPU.h: -------------------------------------------------------------------------------- 1 | #ifndef GPU_H 2 | #define GPU_H 3 | 4 | void GPU_Init(Handle *gsphandle); 5 | void GPU_Reset(u32* gxbuf, u32* gpuBuf, u32 gpuBufSize); 6 | 7 | void GPUCMD_SetBuffer(u32* adr, u32 size, u32 offset); 8 | void GPUCMD_Run(u32* gxbuf); 9 | void GPUCMD_Add(u32 cmd, u32* param, u32 paramlength); 10 | void GPUCMD_AddSingleParam(u32 cmd, u32 param); 11 | void GPUCMD_Finalize(); 12 | 13 | typedef enum{ 14 | GPU_RGBA8=0x0, 15 | GPU_RGB8=0x1, 16 | GPU_RGBA5551=0x2, 17 | GPU_RGB565=0x3, 18 | GPU_RGBA4=0x4, 19 | GPU_LA8=0x5, 20 | GPU_HILO8=0x6, 21 | GPU_L8=0x7, 22 | GPU_A8=0x8, 23 | GPU_LA4=0x9, 24 | GPU_L4=0xA, 25 | GPU_ETC1=0xB, 26 | GPU_ETC1A4=0xC 27 | }GPU_TEXCOLOR; 28 | 29 | typedef enum 30 | { 31 | GPU_NEVER = 0, 32 | GPU_ALWAYS = 1, 33 | GPU_EQUAL = 2, 34 | GPU_NOTEQUAL = 3, 35 | GPU_LESS = 4, 36 | GPU_LEQUAL = 5, 37 | GPU_GREATER = 6, 38 | GPU_GEQUAL = 7 39 | }GPU_TESTFUNC; 40 | 41 | typedef enum{ 42 | GPU_BYTE = 0, 43 | GPU_UNSIGNED_BYTE = 1, 44 | GPU_SHORT = 2, 45 | GPU_FLOAT = 3 46 | }GPU_FORMATS; 47 | 48 | //defines for CW ? 49 | typedef enum{ 50 | GPU_CULL_NONE = 0, 51 | GPU_CULL_FRONT_CCW = 1, 52 | GPU_CULL_BACK_CCW = 2 53 | }GPU_CULLMODE; 54 | 55 | #define GPU_ATTRIBFMT(i, n, f) (((((n)-1)<<2)|((f)&3))<<((i)*4)) 56 | 57 | typedef enum{ 58 | GPU_PRIMARY_COLOR = 0x00, 59 | GPU_TEXTURE0 = 0x03, 60 | GPU_TEXTURE1 = 0x04, 61 | GPU_TEXTURE2 = 0x05, 62 | GPU_TEXTURE3 = 0x06, 63 | GPU_CONSTANT = 0x0E, 64 | GPU_PREVIOUS = 0x0F, 65 | }GPU_TEVSRC; 66 | 67 | typedef enum{ 68 | GPU_REPLACE = 0x00, 69 | GPU_MODULATE = 0x01, 70 | GPU_ADD = 0x02, 71 | GPU_ADD_SIGNED = 0x03, 72 | GPU_INTERPOLATE = 0x04, 73 | GPU_SUBTRACT = 0x05, 74 | GPU_DOT3_RGB = 0x06 //RGB only 75 | }GPU_COMBINEFUNC; 76 | 77 | #define GPU_TEVSOURCES(a,b,c) (((a))|((b)<<4)|((c)<<8)) 78 | #define GPU_TEVOPERANDS(a,b,c) (((a))|((b)<<4)|((c)<<8)) 79 | 80 | void GPU_SetUniform(u32 startreg, u32* data, u32 numreg); 81 | void GPU_SetViewport(u32* depthBuffer, u32* colorBuffer, u32 x, u32 y, u32 w, u32 h); 82 | void GPU_DepthRange(float nearVal, float farVal); 83 | void GPU_SetDepthTest(bool enable, GPU_TESTFUNC function, u8 ref); 84 | void GPU_SetStencilTest(bool enable, GPU_TESTFUNC function, u8 ref); 85 | void GPU_SetFaceCulling(GPU_CULLMODE mode); 86 | void GPU_SetAttributeBuffers(u8 totalAttributes, u32* baseAddress, u64 attributeFormats, u16 attributeMask, u64 attributePermutation, u8 numBuffers, u32 bufferOffsets[], u64 bufferPermutations[], u8 bufferNumAttributes[]); 87 | void GPU_SetTexture(u32* data, u16 width, u16 height, u32 param, GPU_TEXCOLOR colorType); 88 | void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor); 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /fps/include/ctr/GSP.h: -------------------------------------------------------------------------------- 1 | #ifndef GSP_H 2 | #define GSP_H 3 | 4 | #define GSP_REBASE_REG(r) ((r)-0x1EB00000) 5 | 6 | typedef struct 7 | { 8 | u32 active_framebuf;//"0=first, 1=second" 9 | u32 *framebuf0_vaddr;//"Framebuffer virtual address, for the main screen this is the 3D left framebuffer" 10 | u32 *framebuf1_vaddr;//"For the main screen: 3D right framebuffer address" 11 | u32 framebuf_widthbytesize;//"Value for 0x1EF00X90, controls framebuffer width" 12 | u32 format;//"Framebuffer format, this u16 is written to the low u16 for LCD register 0x1EF00X70." 13 | u32 framebuf_dispselect;//"Value for 0x1EF00X78, controls which framebuffer is displayed" 14 | u32 unk;//"?" 15 | } GSP_FramebufferInfo; 16 | 17 | typedef struct//See this for GSP_CaptureInfoEntry and GSP_CaptureInfo: http://3dbrew.org/wiki/GSPGPU:ImportDisplayCaptureInfo 18 | { 19 | u32 *framebuf0_vaddr; 20 | u32 *framebuf1_vaddr; 21 | u32 format; 22 | u32 framebuf_widthbytesize; 23 | } GSP_CaptureInfoEntry; 24 | 25 | typedef struct 26 | { 27 | GSP_CaptureInfoEntry screencapture[2]; 28 | } GSP_CaptureInfo; 29 | 30 | Result gspInit(); 31 | void gspExit(); 32 | 33 | Result GSPGPU_AcquireRight(Handle *handle, u8 flags); 34 | Result GSPGPU_ReleaseRight(Handle *handle); 35 | Result GSPGPU_ImportDisplayCaptureInfo(Handle* handle, GSP_CaptureInfo *captureinfo); 36 | Result GSPGPU_SaveVramSysArea(Handle* handle); 37 | Result GSPGPU_RestoreVramSysArea(Handle* handle); 38 | Result GSPGPU_SetLcdForceBlack(Handle *handle, u8 flags); 39 | Result GSPGPU_SetBufferSwap(Handle* handle, u32 screenid, GSP_FramebufferInfo *framebufinfo); 40 | Result GSPGPU_FlushDataCache(Handle *handle, u8* adr, u32 size); 41 | Result GSPGPU_InvalidateDataCache(Handle* handle, u8* adr, u32 size); 42 | Result GSPGPU_WriteHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); 43 | Result GSPGPU_WriteHWRegsWithMask(Handle* handle, u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize); 44 | Result GSPGPU_ReadHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); 45 | Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID); 46 | Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle); 47 | Result GSPGPU_TriggerCmdReqQueue(Handle *handle); 48 | 49 | Result GSPGPU_submitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /fps/include/ctr/GX.h: -------------------------------------------------------------------------------- 1 | #ifndef GX_H 2 | #define GX_H 3 | 4 | #define GX_BUFFER_DIM(w, h) (((h)<<16)|((w)&0xFFFF)) 5 | 6 | Result GX_RequestDma(u32* gxbuf, u32* src, u32* dst, u32 length); 7 | Result GX_SetCommandList_Last(u32* gxbuf, u32* buf0a, u32 buf0s, u8 flags); 8 | Result GX_SetMemoryFill(u32* gxbuf, u32* buf0a, u32 buf0v, u32* buf0e, u16 width0, u32* buf1a, u32 buf1v, u32* buf1e, u16 width1); 9 | Result GX_SetDisplayTransfer(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 flags); 10 | Result GX_SetTextureCopy(u32* gxbuf, u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags); 11 | Result GX_SetCommandList_First(u32* gxbuf, u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fps/include/ctr/HID.h: -------------------------------------------------------------------------------- 1 | #ifndef HID_H 2 | #define HID_H 3 | 4 | #define HID_SHAREDMEM_DEFAULT (0x10000000) 5 | 6 | #define CPAD_X(v) ((s16)((v)&0xFFFF)) 7 | #define CPAD_Y(v) ((s16)(((v>>16))&0xFFFF)) 8 | 9 | #define TOUCH_X(v) ((u16)((v)&0xFFFF)) 10 | #define TOUCH_Y(v) ((u16)(((v>>16))&0xFFFF)) 11 | 12 | typedef enum 13 | { 14 | PAD_A = (1<<0), 15 | PAD_B = (1<<1), 16 | PAD_SELECT = (1<<2), 17 | PAD_START = (1<<3), 18 | PAD_RIGHT = (1<<4), 19 | PAD_LEFT = (1<<5), 20 | PAD_UP = (1<<6), 21 | PAD_DOWN = (1<<7), 22 | PAD_R = (1<<8), 23 | PAD_L = (1<<9), 24 | PAD_X = (1<<10), 25 | PAD_Y = (1<<11) 26 | }PAD_KEY; 27 | 28 | extern Handle hidMemHandle; 29 | extern vu32* hidSharedMem; 30 | 31 | Result hidInit(u32* sharedMem); 32 | void hidExit(); 33 | 34 | Result HIDUSER_GetInfo(Handle* handle, Handle* outMemHandle); 35 | Result HIDUSER_EnableAccelerometer(Handle* handle); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /fps/include/ctr/HTTPC.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPC_H 2 | #define HTTPC_H 3 | 4 | Result HTTPC_Initialize(Handle handle); 5 | Result HTTPC_InitializeConnectionSession(Handle handle, Handle contextHandle); 6 | Result HTTPC_CreateContext(Handle handle, char* url, Handle* contextHandle); 7 | Result HTTPC_CloseContext(Handle handle, Handle contextHandle); 8 | Result HTTPC_SetProxyDefault(Handle handle, Handle contextHandle); 9 | Result HTTPC_AddRequestHeaderField(Handle handle, Handle contextHandle, char* name, char* value); 10 | Result HTTPC_BeginRequest(Handle handle, Handle contextHandle); 11 | Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fps/include/ctr/IR.h: -------------------------------------------------------------------------------- 1 | #ifndef IR_H 2 | #define IR_H 3 | 4 | Result IRU_Initialize(u32 *sharedmem_addr, u32 sharedmem_size);//The permissions for the specified memory is set to RO. This memory must be already mapped. 5 | Result IRU_Shutdown(); 6 | Handle IRU_GetServHandle(); 7 | Result IRU_SendData(u8 *buf, u32 size, u32 wait); 8 | Result IRU_RecvData(u8 *buf, u32 size, u8 flag, u32 *transfercount, u32 wait); 9 | Result IRU_SetBitRate(u8 value); 10 | Result IRU_GetBitRate(u8 *out); 11 | Result IRU_SetIRLEDState(u32 value); 12 | Result IRU_GetIRLEDRecvState(u32 *out); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /fps/include/ctr/OS.h: -------------------------------------------------------------------------------- 1 | #ifndef OS_H 2 | #define OS_H 3 | 4 | u32 OS_ConvertVaddr2Physaddr(u32 vaddr); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /fps/include/ctr/SHDR.h: -------------------------------------------------------------------------------- 1 | #ifndef SHDR_H 2 | #define SHDR_H 3 | 4 | typedef enum{ 5 | VERTEX_SHDR=0x0, 6 | GEOMETRY_SHDR=0x1 7 | }SHDR_type; 8 | 9 | typedef enum{ 10 | RESULT_POSITION = 0x0, 11 | RESULT_COLOR = 0x2, 12 | RESULT_TEXCOORD0 = 0x3, 13 | RESULT_TEXCOORD1 = 0x5, 14 | RESULT_TEXCOORD2 = 0x6 15 | }SHDR_outType; 16 | 17 | typedef struct{ 18 | u32 codeSize; 19 | u32* codeData; 20 | u32 opdescSize; 21 | u32* opcdescData; 22 | }DVLP_s; 23 | 24 | typedef struct{ 25 | u32 header; 26 | u32 data[4]; 27 | }DVLE_constEntry_s; 28 | 29 | typedef struct{ 30 | u16 type; 31 | u16 regID; 32 | u32 header; 33 | }DVLE_outEntry_s; 34 | 35 | typedef struct{ 36 | u32 symbolOffset; 37 | u16 startReg; 38 | u16 endReg; 39 | }DVLE_uniformEntry_s; 40 | 41 | typedef struct{ 42 | SHDR_type type; 43 | u32 mainOffset, endmainOffset; 44 | u32 constTableSize; 45 | DVLE_constEntry_s* constTableData; 46 | u32 outTableSize; 47 | DVLE_outEntry_s* outTableData; 48 | u32 uniformTableSize; 49 | DVLE_uniformEntry_s* uniformTableData; 50 | char* symbolTableData; 51 | }DVLE_s; 52 | 53 | typedef struct{ 54 | u32 numDVLE; 55 | DVLP_s DVLP; 56 | DVLE_s* DVLE; 57 | }DVLB_s; 58 | 59 | 60 | DVLB_s* SHDR_ParseSHBIN(u32* shbinData, u32 shbinSize); 61 | void SHDR_UseProgram(DVLB_s* dvlb, u8 id); 62 | void SHDR_FreeDVLB(DVLB_s* dvlb); 63 | s8 SHDR_GetUniformRegister(DVLB_s* dvlb, char* name, u8 programID); 64 | 65 | void DVLP_SendCode(DVLP_s* dvlp); 66 | void DVLP_SendOpDesc(DVLP_s* dvlp); 67 | 68 | void DVLE_SendOutmap(DVLE_s* dvle); 69 | void DVLE_SendConstants(DVLE_s* dvle); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /fps/include/ctr/SOC.h: -------------------------------------------------------------------------------- 1 | #ifndef SOC_H 2 | #define SOC_H 3 | 4 | extern Handle SOCU_handle; 5 | 6 | Result SOC_Initialize(u32 *context_addr, u32 context_size);//Example context_size: 0x48000. The specified context buffer can no longer be accessed by the process which called this function, since the userland permissions for this block are set to no-access. 7 | Result SOC_Shutdown(); 8 | int SOC_GetErrno(); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /fps/include/ctr/srv.h: -------------------------------------------------------------------------------- 1 | #ifndef SRV_H 2 | #define SRV_H 3 | 4 | Result initSrv(); 5 | Result exitSrv(); 6 | Result srv_RegisterClient(Handle* handleptr); 7 | Result srv_getServiceHandle(Handle* handleptr, Handle* out, char* server); 8 | 9 | extern Handle srvHandle; 10 | #endif 11 | -------------------------------------------------------------------------------- /fps/include/ctr/svc.h: -------------------------------------------------------------------------------- 1 | #ifndef SVC_H 2 | #define SVC_H 3 | 4 | typedef enum{ 5 | MEMOP_FREE = 1, 6 | MEMOP_RESERVE = 2, 7 | MEMOP_COMMIT = 3, 8 | MEMOP_MAP = 4, 9 | MEMOP_UNMAP = 5, 10 | MEMOP_PROTECT = 6, 11 | MEMOP_REGION_APP = 0x100, 12 | MEMOP_REGION_SYSTEM = 0x200, 13 | MEMOP_REGION_BASE = 0x300, 14 | MEMOP_LINEAR = 0x1000, 15 | }MEMORY_OPERATION; 16 | 17 | u32* getThreadCommandBuffer(void); 18 | 19 | Result svc_getDmaState(u32* state, Handle dma); 20 | Result svc_startInterProcessDma(Handle* hdma, Handle dstProcess, void* dst, Handle srcProcess, const void* src, u32 size, u32* config); 21 | 22 | Result svc_writeProcessMemory(Handle debug, void const* buffer, u32 addr, u32 size); 23 | Result svc_readProcessMemory(void* buffer, Handle debug, u32 addr, u32 size); 24 | Result svc_debugActiveProcess(s32* handle_out, u32 pid); 25 | Result svc_getProcessList(s32* processCount, u32* processIds, s32 processIdMaxCount); 26 | 27 | Result svc_controlProcessMemory(Handle hProcess, void* Addr0, void* Addr1, u32 size, u32 Type, u32 Permissions); 28 | 29 | Result svc_openProcess(Handle* process, u32 processId); 30 | Result svc_addCodeSegment(u32 addr, u32 size); 31 | Result svc_flushProcessDataCache(Handle handle, u32 addr, u32 size); 32 | Result svc_invalidateProcessDataCache(Handle handle, u32 addr, u32 size); 33 | Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0) 34 | void svc_exitProcess(void); 35 | Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid); 36 | void svc_exitThread(); 37 | void svc_sleepThread(s64 ns); 38 | Result svc_createMutex(Handle* mutex, bool initialLocked); 39 | Result svc_releaseMutex(Handle handle); 40 | Result svc_releaseSemaphore(s32* count, Handle semaphore, s32 releaseCount); 41 | Result svc_createEvent(Handle* event, u8 resettype); 42 | Result svc_signalEvent(Handle handle); 43 | Result svc_clearEvent(Handle handle); 44 | Result svc_createMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 mypermission, u32 otherpermission); 45 | Result svc_mapMemoryBlock(Handle memblock, u32 addr, u32 mypermissions, u32 otherpermission); 46 | Result svc_unmapMemoryBlock(Handle memblock, u32 addr); 47 | Result svc_waitSynchronization1(Handle handle, s64 nanoseconds); 48 | Result svc_waitSynchronizationN(s32* out, Handle* handles, s32 handlecount, bool waitAll, s64 nanoseconds); 49 | Result svc_arbitrateAddress(Handle arbiter, u32 addr, u8 type, s32 value, s64 nanoseconds); 50 | Result svc_closeHandle(Handle handle); 51 | u64 svc_getSystemTick(); 52 | Result svc_getSystemInfo(s64* out, u32 type, s32 param); 53 | Result svc_connectToPort(volatile Handle* out, const char* portName); 54 | Result svc_sendSyncRequest(Handle session); 55 | Result svc_getProcessId(u32 *out, Handle handle); 56 | Result svc_getThreadId(u32 *out, Handle handle); 57 | Result svc_setThreadIdealProcessor(Handle handle, u32 processorid); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /fps/include/ctr/types.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPES_H 2 | #define TYPES_H 3 | 4 | #include 5 | #include 6 | 7 | #define U64_MAX UINT64_MAX 8 | 9 | typedef uint8_t u8; 10 | typedef uint16_t u16; 11 | typedef uint32_t u32; 12 | typedef uint64_t u64; 13 | 14 | typedef int8_t s8; 15 | typedef int16_t s16; 16 | typedef int32_t s32; 17 | typedef int64_t s64; 18 | 19 | typedef volatile u8 vu8; 20 | typedef volatile u16 vu16; 21 | typedef volatile u32 vu32; 22 | typedef volatile u64 vu64; 23 | 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | typedef u32 Handle; 30 | typedef s32 Result; 31 | typedef void (*ThreadFunc)(u32); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /fps/include/libntrplg/3dstypes.h: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------- 2 | 3 | ndstypes.h -- Common types (and a few useful macros) 4 | 5 | Copyright (C) 2005 - 2008 6 | Michael Noland (joat) 7 | Jason Rogers (dovoto) 8 | Dave Murphy (WinterMute) 9 | Chris Double (doublec) 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any 13 | damages arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any 16 | purpose, including commercial applications, and to alter it and 17 | redistribute it freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you 20 | must not claim that you wrote the original software. If you use 21 | this software in a product, an acknowledgment in the product 22 | documentation would be appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and 24 | must not be misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source 26 | distribution. 27 | 28 | ---------------------------------------------------------------------------------*/ 29 | /*! \file ndstypes.h 30 | \brief Custom types employed by libnds 31 | */ 32 | 33 | /// Note by Kane49: I kept in stuff i dont use to not mess with stuff i dont understand, this provides some convenient stuff though ! 34 | 35 | #ifndef _3DSTYPES_INCLUDE 36 | #define _3DSTYPES_INCLUDE 37 | //--------------------------------------------------------------------------------- 38 | // define libnds types in terms of stdint 39 | #include 40 | #include 41 | 42 | 43 | 44 | //--------------------------------------------------------------------------------- 45 | // libgba compatible section macros 46 | //--------------------------------------------------------------------------------- 47 | #define ITCM_CODE __attribute__((section(".itcm"), long_call)) 48 | 49 | #define DTCM_DATA __attribute__((section(".dtcm"))) 50 | #define DTCM_BSS __attribute__((section(".sbss"))) 51 | 52 | //! aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. 53 | #define ALIGN(m) __attribute__((aligned (m))) 54 | 55 | //! packs a struct (and other types?) so it won't include padding bytes. 56 | #define PACKED __attribute__ ((packed)) 57 | #define packed_struct struct PACKED 58 | 59 | //--------------------------------------------------------------------------------- 60 | // These are linked to the bin2o macro in the Makefile 61 | //--------------------------------------------------------------------------------- 62 | #define GETRAW(name) (name) 63 | #define GETRAWSIZE(name) ((int)name##_size) 64 | #define GETRAWEND(name) ((int)name##_end) 65 | 66 | 67 | /*! 68 | \brief returns a number with the nth bit set. 69 | */ 70 | #define BIT(n) (1 << (n)) 71 | 72 | //! 8 bit unsigned integer. 73 | typedef uint8_t uint8; 74 | //! 16 bit unsigned integer. 75 | typedef uint16_t uint16; 76 | //! 32 bit unsigned integer. 77 | typedef uint32_t uint32; 78 | //! 64 bit unsigned integer. 79 | typedef uint64_t uint64; 80 | 81 | //! 8 bit signed integer. 82 | typedef int8_t int8; 83 | //! 16 bit signed integer. 84 | typedef int16_t int16; 85 | //! 32 bit signed integer. 86 | typedef int32_t int32; 87 | //! 64 bit signed integer. 88 | typedef int64_t int64; 89 | 90 | //! 32 bit signed floating point number. 91 | typedef float float32; 92 | //! 64 bit signed floating point number. 93 | typedef double float64; 94 | 95 | //! 8 bit volatile unsigned integer. 96 | typedef volatile uint8_t vuint8; 97 | //! 16 bit volatile unsigned integer. 98 | typedef volatile uint16_t vuint16; 99 | //! 32 bit volatile unsigned integer. 100 | typedef volatile uint32_t vuint32; 101 | //! 64 bit volatile unsigned integer. 102 | typedef volatile uint64_t vuint64; 103 | 104 | //! 8 bit volatile signed integer. 105 | typedef volatile int8_t vint8; 106 | //! 16 bit volatile signed integer. 107 | typedef volatile int16_t vint16; 108 | //! 32 bit volatile signed integer. 109 | typedef volatile int32_t vint32; 110 | //! 64 bit volatile signed integer. 111 | typedef volatile int64_t vint64; 112 | 113 | //! 32 bit volatile signed floating point number. 114 | typedef volatile float32 vfloat32; 115 | //! 64 bit volatile signed floating point number. 116 | typedef volatile float64 vfloat64; 117 | 118 | //! 8 bit unsigned integer. 119 | typedef uint8_t byte; 120 | 121 | //! 8 bit unsigned integer. 122 | typedef uint8_t u8; 123 | //! 16 bit unsigned integer. 124 | typedef uint16_t u16; 125 | //! 32 bit unsigned integer. 126 | typedef uint32_t u32; 127 | //! 64 bit unsigned integer. 128 | typedef uint64_t u64; 129 | 130 | //! 8 bit signed integer. 131 | typedef int8_t s8; 132 | //! 16 bit signed integer. 133 | typedef int16_t s16; 134 | //! 32 bit signed integer. 135 | typedef int32_t s32; 136 | //! 64 bit signed integer. 137 | typedef int64_t s64; 138 | 139 | //! 8 bit volatile unsigned integer. 140 | typedef volatile u8 vu8; 141 | //! 16 bit volatile unsigned integer. 142 | typedef volatile u16 vu16; 143 | //! 32 bit volatile unsigned integer. 144 | typedef volatile u32 vu32; 145 | //! 64 bit volatile unsigned integer. 146 | typedef volatile u64 vu64; 147 | 148 | //! 8 bit volatile signed integer. 149 | typedef volatile s8 vs8; 150 | //! 16 bit volatile signed integer. 151 | typedef volatile s16 vs16; 152 | //! 32 bit volatile signed integer. 153 | typedef volatile s32 vs32; 154 | //! 64 bit volatile signed integer. 155 | typedef volatile s64 vs64; 156 | 157 | struct RECT { 158 | int x, y, w, h; 159 | }; 160 | 161 | typedef struct RECT rect; 162 | 163 | struct POINT { 164 | int x, y; 165 | }; 166 | 167 | typedef struct POINT point; 168 | 169 | struct COLOR { 170 | u8 r, g, b; 171 | }; 172 | 173 | typedef struct COLOR color; 174 | 175 | 176 | #ifndef TRUE 177 | #define TRUE 1 178 | #define FALSE 0 179 | #endif 180 | 181 | 182 | // Handy function pointer typedefs 183 | //! a function pointer that takes no arguments and doesn't return anything. 184 | typedef void (* VoidFn)(void); 185 | 186 | typedef void (* IntFn)(void); 187 | typedef void (* fp)(void); 188 | 189 | //--------------------------------------------------------------------------------- 190 | #endif 191 | //--------------------------------------------------------------------------------- 192 | -------------------------------------------------------------------------------- /fps/include/libntrplg/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSTANTS_H 2 | #define CONSTANTS_H 3 | 4 | #define BUTTON_A 0x00000001 5 | #define BUTTON_B 0x00000002 6 | #define BUTTON_SE 0x00000004 7 | #define BUTTON_ST 0x00000008 8 | #define BUTTON_DR 0x00000010 9 | #define BUTTON_DL 0x00000020 10 | #define BUTTON_DU 0x00000040 11 | #define BUTTON_DD 0x00000080 12 | #define BUTTON_R 0x00000100 13 | #define BUTTON_L 0x00000200 14 | #define BUTTON_X 0x00000400 15 | #define BUTTON_Y 0x00000800 16 | 17 | #endif -------------------------------------------------------------------------------- /fps/include/libntrplg/func.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNC_H 2 | #define FUNC_H 3 | 4 | #if IS_PLUGIN 5 | #define INIT_SHARED_FUNC(name,id) rtGenerateJumpCode(((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[id], (void*) name);rtFlushInstructionCache((void*) name, 8); 6 | #else 7 | #define INIT_SHARED_FUNC(name,id) (g_nsConfig->sharedFunc[id] = (u32) name) 8 | #endif 9 | 10 | 11 | u32 protectRemoteMemory(Handle hProcess, void* addr, u32 size); 12 | u32 protectMemory(void* addr, u32 size); 13 | 14 | 15 | 16 | extern Handle fsUserHandle; 17 | extern FS_archive sdmcArchive; 18 | 19 | 20 | 21 | #define MAX_PLUGIN_COUNT 32 22 | 23 | typedef struct _PLGLOADER_INFO { 24 | u32 plgCount; 25 | u32 plgBufferPtr[MAX_PLUGIN_COUNT]; 26 | u32 plgSize[MAX_PLUGIN_COUNT]; 27 | u32 arm11BinStart; 28 | u32 arm11BinSize; 29 | u32 tid[2]; 30 | } PLGLOADER_INFO; 31 | 32 | void updateScreen(); 33 | s32 showMenu(u8* title, u32 entryCount, u8* captions[]); 34 | int showMsg(u8* msg); 35 | void showDbg(u8* fmt, u32 v1, u32 v2); 36 | void kmemcpy(void* dst, void* src, u32 size) ; 37 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 38 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 39 | 40 | #define CURRENT_PROCESS_HANDLE 0xffff8001 41 | 42 | #endif -------------------------------------------------------------------------------- /fps/include/libntrplg/global.h: -------------------------------------------------------------------------------- 1 | #define IS_PLUGIN 1 2 | #define USE_SOCKET 0 3 | 4 | #include "main.h" 5 | #include "memory.h" 6 | #include "math.h" 7 | #include "3dstypes.h" 8 | #include "constants.h" 9 | #include "xprintf.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "func.h" 25 | #include "sharedfunc.h" 26 | #include "ns/ns.h" 27 | #include -------------------------------------------------------------------------------- /fps/include/libntrplg/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /fps/include/libntrplg/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMORY_H 2 | #define MEMORY_H 3 | #include "math.h" 4 | #include "3dstypes.h" 5 | 6 | 7 | void write_byte(u32 address, u8 byte); 8 | void write_word(u32 address, u32 word); 9 | void write_color(u32 address, u8 r, u8 g, u8 b); 10 | u32 read_word(u32 address); 11 | char nibble_to_readable(u8 nibble); 12 | u32 byte_to_string(u8 byte, char* ret, int max_len); 13 | u32 byte_to_bit_string(u8 byte, char* ret, int max_len); 14 | u32 u32_to_string(u32 byte, char* ret, int max_len); 15 | u32 u16_to_string(u16 sh, char* ret, int max_len); 16 | u32 u16_to_bit_string(u16 sh, char* ret, int max_len); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /fps/include/libntrplg/netdb.h: -------------------------------------------------------------------------------- 1 | #ifndef NETDB_H 2 | #define NETDB_H 3 | 4 | struct hostent { 5 | char * h_name; 6 | char ** h_aliases; 7 | int h_addrtype; 8 | int h_length; 9 | char ** h_addr_list; 10 | }; 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct hostent * gethostbyname(const char * name); 18 | 19 | #ifdef __cplusplus 20 | }; 21 | #endif 22 | 23 | 24 | #endif // NETDB_H 25 | -------------------------------------------------------------------------------- /fps/include/libntrplg/ns/ns.h: -------------------------------------------------------------------------------- 1 | #define NS_DEFAULT_MEM_REGION 0x300 2 | 3 | #define DEBUG_BUFFER_SIZE 0x4000 4 | #define GLOBAL_BUFFER_SIZE 0x4000 5 | #define MAX_BREAKPOINT 64 6 | 7 | typedef struct _RT_LOCK { 8 | vu32 value; 9 | } RT_LOCK; 10 | 11 | 12 | #define NS_CONFIGURE_ADDR 0x06000000 13 | 14 | typedef struct _RT_HOOK { 15 | u32 model; 16 | u32 isEnabled; 17 | u32 funcAddr; 18 | u32 bakCode[16]; 19 | u32 jmpCode[16]; 20 | u32 callCode[16]; 21 | } RT_HOOK; 22 | 23 | typedef struct _NS_BREAKPOINT { 24 | u32 type; 25 | u32 flag; 26 | u32 addr; 27 | RT_HOOK hook; 28 | u32 stubCode[32]; 29 | u32 isEnabled; 30 | } NS_BREAKPOINT; 31 | 32 | 33 | 34 | typedef struct _NS_CONFIG { 35 | u32 initMode; 36 | u32 startupCommand; 37 | u32 hSOCU; 38 | 39 | u8* debugBuf; 40 | u32 debugBufSize; 41 | u32 debugPtr; 42 | u32 debugReady; 43 | 44 | RT_LOCK debugBufferLock; 45 | 46 | u32 startupInfo[32]; 47 | u32 allowDirectScreenAccess; 48 | u32 exitFlag; 49 | 50 | u32 sharedFunc[100]; 51 | 52 | } NS_CONFIG; 53 | 54 | 55 | 56 | void nsDbgPrint (const char* fmt, ... ); 57 | 58 | void rtInitLock(RT_LOCK *lock) ; 59 | void rtAcquireLock(RT_LOCK *lock) ; 60 | void rtReleaseLock(RT_LOCK *lock) ; 61 | u32 rtAlignToPageSize(u32 size); 62 | u32 rtGetPageOfAddress(u32 addr) ; 63 | u32 rtCheckRemoteMemoryRegionSafeForWrite(Handle hProcess, u32 addr, u32 size) ; 64 | u32 rtSafeCopyMemory(u32 dst, u32 src, u32 size) ; 65 | int rtRecvSocket(u32 sockfd, u8 *buf, int size); 66 | int rtSendSocket(u32 sockfd, u8 *buf, int size); 67 | u16 rtIntToPortNumber(u16 x) ; 68 | u32 rtGetFileSize(u8* fileName); 69 | u32 rtLoadFileToBuffer(u8* fileName, u32* pBuf, u32 bufSize) ; 70 | u32 rtGetThreadReg(Handle hProcess, u32 tid, u32* ctx); 71 | u32 rtFlushInstructionCache(void* ptr, u32 size); 72 | void rtInitHook(RT_HOOK* hook, u32 funcAddr, u32 callbackAddr); 73 | void rtEnableHook(RT_HOOK* hook); 74 | void rtDisableHook(RT_HOOK* hook); 75 | u32 rtGenerateJumpCode(u32 dst, u32* buf); 76 | 77 | 78 | u32 nsAttachProcess(Handle hProcess, u32 remotePC, NS_CONFIG *cfg) ; 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /fps/include/libntrplg/sharedfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_FUNC_H 2 | #define SHARED_FUNC_H 3 | 4 | #if IS_PLUGIN 5 | #define INIT_SHARED_FUNC(name,id) rtGenerateJumpCode(((NS_CONFIG*)(NS_CONFIGURE_ADDR))->sharedFunc[id], (void*) name);rtFlushInstructionCache((void*) name, 8); 6 | #else 7 | #define INIT_SHARED_FUNC(name,id) (g_nsConfig->sharedFunc[id] = (u32) name) 8 | #endif 9 | 10 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 11 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 12 | u32 plgRequestMemory(u32 size); 13 | u32 plgRegisterCallback(u32 type, void* callback, u32 param0); 14 | 15 | void showDbg(u8* fmt, u32 v1, u32 v2); 16 | void nsDbgPrint (const char* fmt, ... ); 17 | 18 | #endif -------------------------------------------------------------------------------- /fps/include/libntrplg/xprintf.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Universal string handler for user console interface (C)ChaN, 2011 */ 3 | /*------------------------------------------------------------------------*/ 4 | 5 | #ifndef _STRFUNC 6 | #define _STRFUNC 7 | 8 | #define _USE_XFUNC_OUT 1 /* 1: Use output functions */ 9 | #define _CR_CRLF 0 /* 1: Convert \n ==> \r\n in the output char */ 10 | 11 | #define _USE_XFUNC_IN 1 /* 1: Use input function */ 12 | #define _LINE_ECHO 1 /* 1: Echo back input chars in xgets function */ 13 | 14 | 15 | #if _USE_XFUNC_OUT 16 | #define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func) 17 | extern void (*xfunc_out)(unsigned char); 18 | void xputc (char c); 19 | void xputs (const char* str); 20 | void xfputs (void (*func)(unsigned char), const char* str); 21 | void xprintf (const char* fmt, ...); 22 | void xsprintf (char* buff, const char* fmt, ...); 23 | void xfprintf (void (*func)(unsigned char), const char* fmt, ...); 24 | void put_dump (const void* buff, unsigned long addr, int len, int width); 25 | #define DW_CHAR sizeof(char) 26 | #define DW_SHORT sizeof(short) 27 | #define DW_LONG sizeof(long) 28 | #endif 29 | 30 | #if _USE_XFUNC_IN 31 | #define xdev_in(func) xfunc_in = (unsigned char(*)(void))(func) 32 | extern unsigned char (*xfunc_in)(void); 33 | int xgets (char* buff, int len); 34 | int xfgets (unsigned char (*func)(void), char* buff, int len); 35 | int xatoi (char** str, long* res); 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /fps/include/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int main(); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /fps/include/netinet/in.h: -------------------------------------------------------------------------------- 1 | #ifndef NETINET_IN_H 2 | #define NETINET_IN_H 3 | 4 | #include "sys/socket.h" 5 | 6 | #define INADDR_ANY 0x00000000 7 | #define INADDR_BROADCAST 0xFFFFFFFF 8 | #define INADDR_NONE 0xFFFFFFFF 9 | 10 | struct in_addr { 11 | unsigned long s_addr; 12 | }; 13 | 14 | struct sockaddr_in { 15 | unsigned short sin_family; 16 | unsigned short sin_port; 17 | struct in_addr sin_addr; 18 | unsigned char sin_zero[8]; 19 | }; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | // actually from arpa/inet.h - but is included through netinet/in.h 26 | unsigned long inet_addr(const char *cp); 27 | int inet_aton(const char *cp, struct in_addr *inp); 28 | char *inet_ntoa(struct in_addr in); 29 | 30 | #ifdef __cplusplus 31 | }; 32 | #endif 33 | 34 | #endif // NETINET_IN_H 35 | -------------------------------------------------------------------------------- /fps/include/netinet/tcp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/fps/include/netinet/tcp.h -------------------------------------------------------------------------------- /fps/include/sys/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef SYS_SOCKET_H 2 | #define SYS_SOCKET_H 3 | 4 | #include 5 | 6 | /* 7 | * Level number for (get/set)sockopt() to apply to socket itself. 8 | */ 9 | #define SOL_SOCKET 0xfff /* options for socket level */ 10 | # define SOL_TCP 6 /* TCP level */ 11 | 12 | #define PF_UNSPEC 0 13 | #define PF_INET 2 14 | #define PF_INET6 10 15 | 16 | #define AF_UNSPEC PF_UNSPEC 17 | #define AF_INET PF_INET 18 | #define AF_INET6 PF_INET6 19 | 20 | #define SOCK_STREAM 1 21 | #define SOCK_DGRAM 2 22 | 23 | // need to sync FIO* values with commonly accepted ones sometime 24 | #define FIONBIO 1 25 | #define FIONREAD 2 26 | 27 | #define SOCKET_ERROR -1 28 | 29 | // send()/recv()/etc flags 30 | // at present, only MSG_PEEK is implemented though. 31 | #define MSG_WAITALL 0x40000000 32 | #define MSG_TRUNC 0x20000000 33 | #define MSG_PEEK 0x10000000 34 | #define MSG_OOB 0x08000000 35 | #define MSG_EOR 0x04000000 36 | #define MSG_DONTROUTE 0x02000000 37 | #define MSG_CTRUNC 0x01000000 38 | 39 | // shutdown() flags: 40 | #define SHUT_RD 1 41 | #define SHUT_WR 2 42 | #define SHUT_RDWR 3 43 | 44 | /* 45 | * Option flags per-socket. 46 | */ 47 | #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 48 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 49 | #define SO_REUSEADDR 0x0004 /* allow local address reuse */ 50 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 51 | #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 52 | #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 53 | #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 54 | #define SO_LINGER 0x0080 /* linger on close if data present */ 55 | #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 56 | #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 57 | 58 | #define SO_DONTLINGER (int)(~SO_LINGER) 59 | 60 | /* 61 | * Additional options, not kept in so_options. 62 | */ 63 | #define SO_SNDBUF 0x1001 /* send buffer size */ 64 | #define SO_RCVBUF 0x1002 /* receive buffer size */ 65 | #define SO_SNDLOWAT 0x1003 /* send low-water mark */ 66 | #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 67 | #define SO_SNDTIMEO 0x1005 /* send timeout */ 68 | #define SO_RCVTIMEO 0x1006 /* receive timeout */ 69 | #define SO_ERROR 0x1007 /* get error status and clear */ 70 | #define SO_TYPE 0x1008 /* get socket type */ 71 | 72 | struct sockaddr { 73 | unsigned short sa_family; 74 | char sa_data[14]; 75 | }; 76 | 77 | #ifndef ntohs 78 | #define ntohs(num) htons(num) 79 | #define ntohl(num) htonl(num) 80 | #endif 81 | 82 | #ifdef __cplusplus 83 | extern "C" { 84 | #endif 85 | 86 | int socket(int domain, int type, int protocol); 87 | int bind(int socket, const struct sockaddr * addr, int addr_len); 88 | int connect(int socket, const struct sockaddr * addr, int addr_len); 89 | int send(int socket, const void * data, int sendlength, int flags); 90 | int recv(int socket, void * data, int recvlength, int flags); 91 | int sendto(int socket, const void * data, int sendlength, int flags, const struct sockaddr * addr, int addr_len); 92 | int recvfrom(int socket, void * data, int recvlength, int flags, struct sockaddr * addr, int * addr_len); 93 | int listen(int socket, int max_connections); 94 | int accept(int socket, struct sockaddr * addr, int * addr_len); 95 | int shutdown(int socket, int shutdown_type); 96 | int closesocket(int socket); 97 | 98 | int ioctl(int socket, long cmd, void * arg); 99 | 100 | int setsockopt(int socket, int level, int option_name, const void * data, int data_len); 101 | int getsockopt(int socket, int level, int option_name, void * data, int * data_len); 102 | 103 | int getpeername(int socket, struct sockaddr *addr, int * addr_len); 104 | int getsockname(int socket, struct sockaddr *addr, int * addr_len); 105 | 106 | int gethostname(char *name, size_t len); 107 | int sethostname(const char *name, size_t len); 108 | 109 | unsigned short htons(unsigned short num); 110 | unsigned long htonl(unsigned long num); 111 | 112 | extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout); 113 | 114 | #ifdef __cplusplus 115 | }; 116 | #endif 117 | 118 | 119 | #endif // SYS_SOCKET_H 120 | -------------------------------------------------------------------------------- /fps/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/fps/lib/libc.a -------------------------------------------------------------------------------- /fps/lib/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/fps/lib/libgcc.a -------------------------------------------------------------------------------- /fps/obj/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/44670/ntr_overlay_samples/afb39efad58354b0d5e50027e84b59d0f9c61f9f/fps/obj/empty.txt -------------------------------------------------------------------------------- /fps/source/bootloader.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align(4); 3 | .section .text 4 | .global _Reset 5 | _Reset: 6 | 7 | STMFD SP!, {R0-R12, LR}; 8 | MRS R0, CPSR 9 | STMFD SP!, {R0} 10 | 11 | LDR R6, =_Reset 12 | ADR R5, _Reset 13 | sub r5, r5, r6 /* r5 = realAddress - baseAddress */ 14 | ldr r6, = __rel_dyn_start 15 | ldr r7, = __rel_dyn_end 16 | add r6, r6, r5 17 | add r7, r7, r5 18 | relocNotFinished: 19 | ldmia r6!, {r3, r4} 20 | cmp r4, #0x17 21 | bne notRelativeEntry 22 | add r3, r3, r5 23 | ldr r4, [r3] 24 | add r4, r4, r5 25 | str r4, [r3] 26 | notRelativeEntry: 27 | cmp r6, r7 28 | bcc relocNotFinished 29 | ldr r0, =0xffff8001 30 | adr r1, _Reset 31 | ldr r2, =__rel_dyn_end 32 | sub r2, r2, r1 /* r2 = codesize */ 33 | svc 0x54 /* flush instruction cache */ 34 | nop 35 | nop 36 | 37 | mov r0, sp 38 | bl c_entry 39 | 40 | ldmfd sp!, {r0} 41 | msr cpsr, r0 42 | ldmfd SP!, {R0-R12, LR}; 43 | 44 | .global _ReturnToUser 45 | _ReturnToUser: 46 | bx lr 47 | nop 48 | nop 49 | nop 50 | msr cpsr, r0 51 | /* unused 52 | ldr PC, =c_entry 53 | */ 54 | 55 | .section .__rel_dyn_start 56 | __rel_dyn_start: 57 | 58 | .section .__rel_dyn_end 59 | __rel_dyn_end: 60 | 61 | .section .__bss_start 62 | .global __c_bss_start 63 | __c_bss_start: 64 | 65 | .section .__bss_end 66 | .global __c_bss_end 67 | __c_bss_end: 68 | 69 | -------------------------------------------------------------------------------- /fps/source/entry.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | extern u32 __c_bss_start; 4 | extern u32 __c_bss_end; 5 | 6 | void c_entry(u32* reg) { 7 | u32 i; 8 | 9 | for (i = __c_bss_start; i < __c_bss_end; i += 4){ 10 | *(vu32*)(i) = 0; 11 | } 12 | main(); 13 | } 14 | 15 | void IRQHandler (void) 16 | { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /fps/source/font.h: -------------------------------------------------------------------------------- 1 | 2 | static unsigned char font[] = 3 | { 4 | /*0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, // Char 000 (.) 5 | 0x7E, 0x81, 0xA5, 0x81, 0x9D, 0xB9, 0x81, 0x7E, // Char 001 (.) 6 | 0x7E, 0xFF, 0xDB, 0xFF, 0xE3, 0xC7, 0xFF, 0x7E, // Char 002 (.) 7 | 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, // Char 003 (.) 8 | 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, // Char 004 (.) 9 | 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x10, 0x10, 0x7C, // Char 005 (.) 10 | 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0x7E, 0x18, 0x7E, // Char 006 (.) 11 | 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, // Char 007 (.) 12 | 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, // Char 008 (.) 13 | 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, // Char 009 (.) 14 | 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, // Char 010 (.) 15 | 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, // Char 011 (.) 16 | 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, // Char 012 (.) 17 | 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, // Char 013 (.) 18 | 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, // Char 014 (.) 19 | 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, // Char 015 (.) 20 | 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, // Char 016 (.) 21 | 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, // Char 017 (.) 22 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, // Char 018 (.) 23 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, // Char 019 (.) 24 | 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, // Char 020 (.) 25 | 0x3F, 0x60, 0x7C, 0x66, 0x66, 0x3E, 0x06, 0xFC, // Char 021 (.) 26 | 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, // Char 022 (.) 27 | 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, // Char 023 (.) 28 | 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 024 (.) 29 | 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, // Char 025 (.) 30 | 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, // Char 026 (.) 31 | 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, // Char 027 (.) 32 | 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, // Char 028 (.) 33 | 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, // Char 029 (.) 34 | 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, // Char 030 (.) 35 | 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, // Char 031 (.)*/ 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 032 ( ) 37 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00, // Char 033 (!) 38 | 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 034 (") 39 | 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, // Char 035 (#) 40 | 0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, // Char 036 ($) 41 | 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, // Char 037 (%) 42 | 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, // Char 038 (&) 43 | 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 039 (') 44 | 0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0x00, // Char 040 (() 45 | 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0x00, // Char 041 ()) 46 | 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, // Char 042 (*) 47 | 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, // Char 043 (+) 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, // Char 044 (,) 49 | 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, // Char 045 (-) 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, // Char 046 (.) 51 | 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, // Char 047 (/) 52 | 0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, // Char 048 (0) 53 | 0x18, 0x38, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, // Char 049 (1) 54 | 0x7C, 0xC6, 0x06, 0x7C, 0xC0, 0xC0, 0xFE, 0x00, // Char 050 (2) 55 | 0xFC, 0x06, 0x06, 0x3C, 0x06, 0x06, 0xFC, 0x00, // Char 051 (3) 56 | 0x0C, 0xCC, 0xCC, 0xCC, 0xFE, 0x0C, 0x0C, 0x00, // Char 052 (4) 57 | 0xFE, 0xC0, 0xFC, 0x06, 0x06, 0xC6, 0x7C, 0x00, // Char 053 (5) 58 | 0x7C, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0x7C, 0x00, // Char 054 (6) 59 | 0xFE, 0x06, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x00, // Char 055 (7) 60 | 0x7C, 0xC6, 0xC6, 0x7C, 0xC6, 0xC6, 0x7C, 0x00, // Char 056 (8) 61 | 0x7C, 0xC6, 0xC6, 0x7E, 0x06, 0x06, 0x7C, 0x00, // Char 057 (9) 62 | 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, // Char 058 (:) 63 | 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, // Char 059 (;) 64 | 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0x00, // Char 060 (<) 65 | 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, // Char 061 (=) 66 | 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0x00, // Char 062 (>) 67 | 0x3C, 0x66, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x00, // Char 063 (?) 68 | 0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x7E, 0x00, // Char 064 (@) 69 | 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, // Char 065 (A) 70 | 0xFC, 0xC6, 0xC6, 0xFC, 0xC6, 0xC6, 0xFC, 0x00, // Char 066 (B) 71 | 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xC6, 0x7C, 0x00, // Char 067 (C) 72 | 0xF8, 0xCC, 0xC6, 0xC6, 0xC6, 0xCC, 0xF8, 0x00, // Char 068 (D) 73 | 0xFE, 0xC0, 0xC0, 0xF8, 0xC0, 0xC0, 0xFE, 0x00, // Char 069 (E) 74 | 0xFE, 0xC0, 0xC0, 0xF8, 0xC0, 0xC0, 0xC0, 0x00, // Char 070 (F) 75 | 0x7C, 0xC6, 0xC0, 0xC0, 0xCE, 0xC6, 0x7C, 0x00, // Char 071 (G) 76 | 0xC6, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0x00, // Char 072 (H) 77 | 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x00, // Char 073 (I) 78 | 0x06, 0x06, 0x06, 0x06, 0x06, 0xC6, 0x7C, 0x00, // Char 074 (J) 79 | 0xC6, 0xCC, 0xD8, 0xF0, 0xD8, 0xCC, 0xC6, 0x00, // Char 075 (K) 80 | 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, // Char 076 (L) 81 | 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, // Char 077 (M) 82 | 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, // Char 078 (N) 83 | 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 079 (O) 84 | 0xFC, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, 0xC0, 0x00, // Char 080 (P) 85 | 0x7C, 0xC6, 0xC6, 0xC6, 0xD6, 0xDE, 0x7C, 0x06, // Char 081 (Q) 86 | 0xFC, 0xC6, 0xC6, 0xFC, 0xD8, 0xCC, 0xC6, 0x00, // Char 082 (R) 87 | 0x7C, 0xC6, 0xC0, 0x7C, 0x06, 0xC6, 0x7C, 0x00, // Char 083 (S) 88 | 0xFF, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 084 (T) 89 | 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0x00, // Char 085 (U) 90 | 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x38, 0x00, // Char 086 (V) 91 | 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, // Char 087 (W) 92 | 0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, // Char 088 (X) 93 | 0xC6, 0xC6, 0xC6, 0x7C, 0x18, 0x30, 0xE0, 0x00, // Char 089 (Y) 94 | 0xFE, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFE, 0x00, // Char 090 (Z) 95 | 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x00, // Char 091 ([) 96 | 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, // Char 092 (\) 97 | 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0x00, // Char 093 (]) 98 | 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, // Char 094 (^) 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // Char 095 (_) 100 | 0x18, 0x18, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 096 (`) 101 | 0x00, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 097 (a) 102 | 0xC0, 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xFC, 0x00, // Char 098 (b) 103 | 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x00, // Char 099 (c) 104 | 0x06, 0x06, 0x06, 0x7E, 0xC6, 0xC6, 0x7E, 0x00, // Char 100 (d) 105 | 0x00, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 101 (e) 106 | 0x1C, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0x00, // Char 102 (f) 107 | 0x00, 0x00, 0x7E, 0xC6, 0xC6, 0x7E, 0x06, 0xFC, // Char 103 (g) 108 | 0xC0, 0xC0, 0xFC, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, // Char 104 (h) 109 | 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 105 (i) 110 | 0x06, 0x00, 0x06, 0x06, 0x06, 0x06, 0xC6, 0x7C, // Char 106 (j) 111 | 0xC0, 0xC0, 0xCC, 0xD8, 0xF8, 0xCC, 0xC6, 0x00, // Char 107 (k) 112 | 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 108 (l) 113 | 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, // Char 109 (m) 114 | 0x00, 0x00, 0xFC, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, // Char 110 (n) 115 | 0x00, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 111 (o) 116 | 0x00, 0x00, 0xFC, 0xC6, 0xC6, 0xFC, 0xC0, 0xC0, // Char 112 (p) 117 | 0x00, 0x00, 0x7E, 0xC6, 0xC6, 0x7E, 0x06, 0x06, // Char 113 (q) 118 | 0x00, 0x00, 0xFC, 0xC6, 0xC0, 0xC0, 0xC0, 0x00, // Char 114 (r) 119 | 0x00, 0x00, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x00, // Char 115 (s) 120 | 0x18, 0x18, 0x7E, 0x18, 0x18, 0x18, 0x0E, 0x00, // Char 116 (t) 121 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 117 (u) 122 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0x7C, 0x38, 0x00, // Char 118 (v) 123 | 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, // Char 119 (w) 124 | 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, // Char 120 (x) 125 | 0x00, 0x00, 0xC6, 0xC6, 0xC6, 0x7E, 0x06, 0xFC, // Char 121 (y) 126 | 0x00, 0x00, 0xFE, 0x0C, 0x38, 0x60, 0xFE, 0x00, // Char 122 (z) 127 | 0x0E, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0E, 0x00, // Char 123 ({) 128 | 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, // Char 124 (|) 129 | 0x70, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x70, 0x00, // Char 125 (}) 130 | 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Char 126 (~) 131 | /*0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, // Char 127 (.) 132 | 0x7C, 0xC6, 0xC0, 0xC0, 0xC0, 0xD6, 0x7C, 0x30, // Char 128 (.) 133 | 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 129 (.) 134 | 0x0E, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 130 (.) 135 | 0x7E, 0x81, 0x3C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 131 (.) 136 | 0x66, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 132 (.) 137 | 0xE0, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 133 (.) 138 | 0x18, 0x18, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 134 (.) 139 | 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0xD6, 0x7C, 0x30, // Char 135 (.) 140 | 0x7E, 0x81, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 136 (.) 141 | 0x66, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 137 (.) 142 | 0xE0, 0x00, 0x7C, 0xC6, 0xFE, 0xC0, 0x7C, 0x00, // Char 138 (.) 143 | 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 139 (.) 144 | 0x7C, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 140 (.) 145 | 0x70, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 141 (.) 146 | 0xC6, 0x10, 0x7C, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, // Char 142 (.) 147 | 0x38, 0x38, 0x00, 0x7C, 0xC6, 0xFE, 0xC6, 0x00, // Char 143 (.) 148 | 0x0E, 0x00, 0xFE, 0xC0, 0xF8, 0xC0, 0xFE, 0x00, // Char 144 (.) 149 | 0x00, 0x00, 0x7F, 0x0C, 0x7F, 0xCC, 0x7F, 0x00, // Char 145 (.) 150 | 0x3F, 0x6C, 0xCC, 0xFF, 0xCC, 0xCC, 0xCF, 0x00, // Char 146 (.) 151 | 0x7C, 0x82, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 147 (.) 152 | 0x66, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 148 (.) 153 | 0xE0, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 149 (.) 154 | 0x7C, 0x82, 0x00, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 150 (.) 155 | 0xE0, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 151 (.) 156 | 0x66, 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x7C, // Char 152 (.) 157 | 0xC6, 0x7C, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 153 (.) 158 | 0xC6, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0xFE, 0x00, // Char 154 (.) 159 | 0x18, 0x18, 0x7E, 0xD8, 0xD8, 0xD8, 0x7E, 0x18, // Char 155 (.) 160 | 0x38, 0x6C, 0x60, 0xF0, 0x60, 0x66, 0xFC, 0x00, // Char 156 (.) 161 | 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, 0x7E, 0x18, // Char 157 (.) 162 | 0xF8, 0xCC, 0xCC, 0xFA, 0xC6, 0xCF, 0xC6, 0xC3, // Char 158 (.) 163 | 0x0E, 0x1B, 0x18, 0x3C, 0x18, 0x18, 0xD8, 0x70, // Char 159 (.) 164 | 0x0E, 0x00, 0x7C, 0x06, 0x7E, 0xC6, 0x7E, 0x00, // Char 160 (.) 165 | 0x1C, 0x00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, // Char 161 (.) 166 | 0x0E, 0x00, 0x7C, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // Char 162 (.) 167 | 0x0E, 0x00, 0xC6, 0xC6, 0xC6, 0xC6, 0x7E, 0x00, // Char 163 (.) 168 | 0x00, 0xFE, 0x00, 0xFC, 0xC6, 0xC6, 0xC6, 0x00, // Char 164 (.) 169 | 0xFE, 0x00, 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0x00, // Char 165 (.) 170 | 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, // Char 166 (.) 171 | 0x3C, 0x66, 0x66, 0x3C, 0x00, 0x7E, 0x00, 0x00, // Char 167 (.) 172 | 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3C, 0x00, // Char 168 (.) 173 | 0x00, 0x00, 0x00, 0xFC, 0xC0, 0xC0, 0x00, 0x00, // Char 169 (.) 174 | 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x00, 0x00, // Char 170 (.) 175 | 0xC6, 0xCC, 0xD8, 0x3F, 0x63, 0xCF, 0x8C, 0x0F, // Char 171 (.) 176 | 0xC3, 0xC6, 0xCC, 0xDB, 0x37, 0x6D, 0xCF, 0x03, // Char 172 (.) 177 | 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 173 (.) 178 | 0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, // Char 174 (.) 179 | 0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, // Char 175 (.) 180 | 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, // Char 176 (.) 181 | 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, // Char 177 (.) 182 | 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, // Char 178 (.) 183 | 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, // Char 179 (.) 184 | 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 180 (.) 185 | 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 181 (.) 186 | 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, // Char 182 (.) 187 | 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, // Char 183 (.) 188 | 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, // Char 184 (.) 189 | 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, // Char 185 (.) 190 | 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, // Char 186 (.) 191 | 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, // Char 187 (.) 192 | 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, // Char 188 (.) 193 | 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, // Char 189 (.) 194 | 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, // Char 190 (.) 195 | 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, // Char 191 (.) 196 | 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, // Char 192 (.) 197 | 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, // Char 193 (.) 198 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, // Char 194 (.) 199 | 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 195 (.) 200 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 196 (.) 201 | 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, // Char 197 (.) 202 | 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 198 (.) 203 | 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, // Char 199 (.) 204 | 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, // Char 200 (.) 205 | 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, // Char 201 (.) 206 | 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 202 (.) 207 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, // Char 203 (.) 208 | 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, // Char 204 (.) 209 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 205 (.) 210 | 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, // Char 206 (.) 211 | 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, // Char 207 (.) 212 | 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, // Char 208 (.) 213 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, // Char 209 (.) 214 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, // Char 210 (.) 215 | 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, // Char 211 (.) 216 | 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, // Char 212 (.) 217 | 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, // Char 213 (.) 218 | 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, // Char 214 (.) 219 | 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, // Char 215 (.) 220 | 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, // Char 216 (.) 221 | 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, // Char 217 (.) 222 | 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, // Char 218 (.) 223 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Char 219 (.) 224 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, // Char 220 (.) 225 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, // Char 221 (.) 226 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // Char 222 (.) 227 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // Char 223 (.) 228 | 0x00, 0x00, 0x76, 0xDC, 0xC8, 0xDC, 0x76, 0x00, // Char 224 (.) 229 | 0x38, 0x6C, 0x6C, 0x78, 0x6C, 0x66, 0x6C, 0x60, // Char 225 (.) 230 | 0x00, 0xFE, 0xC6, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, // Char 226 (.) 231 | 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, // Char 227 (.) 232 | 0xFE, 0x60, 0x30, 0x18, 0x30, 0x60, 0xFE, 0x00, // Char 228 (.) 233 | 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0x70, 0x00, // Char 229 (.) 234 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0xC0, // Char 230 (.) 235 | 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x00, // Char 231 (.) 236 | 0x7E, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x7E, // Char 232 (.) 237 | 0x3C, 0x66, 0xC3, 0xFF, 0xC3, 0x66, 0x3C, 0x00, // Char 233 (.) 238 | 0x3C, 0x66, 0xC3, 0xC3, 0x66, 0x66, 0xE7, 0x00, // Char 234 (.) 239 | 0x0E, 0x18, 0x0C, 0x7E, 0xC6, 0xC6, 0x7C, 0x00, // Char 235 (.) 240 | 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x00, 0x00, // Char 236 (.) 241 | 0x06, 0x0C, 0x7E, 0xDB, 0xDB, 0x7E, 0x60, 0xC0, // Char 237 (.) 242 | 0x38, 0x60, 0xC0, 0xF8, 0xC0, 0x60, 0x38, 0x00, // Char 238 (.) 243 | 0x78, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, // Char 239 (.) 244 | 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, // Char 240 (.) 245 | 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x7E, 0x00, // Char 241 (.) 246 | 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xFC, 0x00, // Char 242 (.) 247 | 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xFC, 0x00, // Char 243 (.) 248 | 0x0E, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, // Char 244 (.) 249 | 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70, // Char 245 (.) 250 | 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, // Char 246 (.) 251 | 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, // Char 247 (.) 252 | 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, // Char 248 (.) 253 | 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, // Char 249 (.) 254 | 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, // Char 250 (.) 255 | 0x0F, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C, // Char 251 (.) 256 | 0x78, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, // Char 252 (.) 257 | 0x7C, 0x0C, 0x7C, 0x60, 0x7C, 0x00, 0x00, 0x00, // Char 253 (.) 258 | 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, // Char 254 (.) 259 | 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Char 255 (.)*/ 260 | }; -------------------------------------------------------------------------------- /fps/source/libctru/AC.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | Result ACU_cmd1(Handle servhandle, u32 *ptr)//Unknown what this cmd does at the time of writing. (ptr=0x200-byte outbuf) 11 | { 12 | u32 tmp0, tmp1; 13 | Result ret=0; 14 | u32 *cmdbuf = getThreadCommandBuffer(); 15 | 16 | tmp0 = cmdbuf[0x100>>2]; 17 | tmp1 = cmdbuf[0x104>>2]; 18 | 19 | cmdbuf[0] = 0x00010000; 20 | cmdbuf[0x100>>2] = 0x00800002; 21 | cmdbuf[0x104>>2] = (u32)ptr; 22 | 23 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 24 | 25 | cmdbuf[0x100>>2] = tmp0; 26 | cmdbuf[0x104>>2] = tmp1; 27 | 28 | return (Result)cmdbuf[1]; 29 | } 30 | 31 | Result ACU_cmd26(Handle servhandle, u32 *ptr, u8 val)//Unknown what this cmd does at the time of writing. (ptr=0x200-byte inbuf/outbuf) 32 | { 33 | u32 tmp0, tmp1; 34 | Result ret=0; 35 | u32 *cmdbuf = getThreadCommandBuffer(); 36 | 37 | tmp0 = cmdbuf[0x100>>2]; 38 | tmp1 = cmdbuf[0x104>>2]; 39 | 40 | cmdbuf[0] = 0x00260042; 41 | cmdbuf[1] = (u32)val; 42 | cmdbuf[0x100>>2] = 0x00800002; 43 | cmdbuf[0x104>>2] = (u32)ptr; 44 | cmdbuf[2] = 0x00800002; 45 | cmdbuf[3] = (u32)ptr; 46 | 47 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 48 | 49 | cmdbuf[0x100>>2] = tmp0; 50 | cmdbuf[0x104>>2] = tmp1; 51 | 52 | return (Result)cmdbuf[1]; 53 | } 54 | 55 | Result ACU_GetWifiStatus(Handle servhandle, u32 *out) 56 | { 57 | Result ret=0; 58 | u32 *cmdbuf = getThreadCommandBuffer(); 59 | 60 | cmdbuf[0] = 0x000D0000; 61 | 62 | if((ret = svc_sendSyncRequest(servhandle))!=0)return ret; 63 | 64 | *out = cmdbuf[2]; 65 | 66 | return (Result)cmdbuf[1]; 67 | } 68 | 69 | Result ACU_WaitInternetConnection() 70 | { 71 | Handle servhandle = 0; 72 | Result ret=0; 73 | u32 outval=0; 74 | 75 | if((ret = srv_getServiceHandle(NULL, &servhandle, "ac:u"))!=0)return ret; 76 | 77 | while(1) 78 | { 79 | ret = ACU_GetWifiStatus(servhandle, &outval); 80 | if(ret==0 && outval==1)break; 81 | } 82 | 83 | svc_closeHandle(servhandle); 84 | 85 | return ret; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /fps/source/libctru/FS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Result FSUSER_Initialize(Handle handle) 9 | { 10 | u32* cmdbuf=getThreadCommandBuffer(); 11 | cmdbuf[0]=0x08010002; //request header code 12 | cmdbuf[1]=32; 13 | 14 | Result ret=0; 15 | if((ret=svc_sendSyncRequest(handle)))return ret; 16 | 17 | return cmdbuf[1]; 18 | } 19 | 20 | Result FSUSER_OpenFile(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //archive needs to have been opened 21 | { 22 | u32* cmdbuf=getThreadCommandBuffer(); 23 | 24 | cmdbuf[0]=0x080201C2; 25 | cmdbuf[1]=0; 26 | cmdbuf[2]=archive.handleLow; 27 | cmdbuf[3]=archive.handleHigh; 28 | cmdbuf[4]=fileLowPath.type; 29 | cmdbuf[5]=fileLowPath.size; 30 | cmdbuf[6]=openflags; 31 | cmdbuf[7]=attributes; 32 | cmdbuf[8]=(fileLowPath.size<<14)|2; 33 | cmdbuf[9]=(u32)fileLowPath.data; 34 | 35 | Result ret=0; 36 | if((ret=svc_sendSyncRequest(handle)))return ret; 37 | 38 | if(out)*out=cmdbuf[3]; 39 | 40 | return cmdbuf[1]; 41 | } 42 | 43 | Result FSUSER_OpenFileDirectly(Handle handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes) //no need to have archive opened 44 | { 45 | u32* cmdbuf=getThreadCommandBuffer(); 46 | 47 | cmdbuf[0]=0x08030204; 48 | cmdbuf[1]=0; 49 | cmdbuf[2]=archive.id; 50 | cmdbuf[3]=archive.lowPath.type; 51 | cmdbuf[4]=archive.lowPath.size; 52 | cmdbuf[5]=fileLowPath.type; 53 | cmdbuf[6]=fileLowPath.size; 54 | cmdbuf[7]=openflags; 55 | cmdbuf[8]=attributes; 56 | cmdbuf[9]=(archive.lowPath.size<<14)|0x802; 57 | cmdbuf[10]=(u32)archive.lowPath.data; 58 | cmdbuf[11]=(fileLowPath.size<<14)|2; 59 | cmdbuf[12]=(u32)fileLowPath.data; 60 | 61 | Result ret=0; 62 | if((ret=svc_sendSyncRequest(handle)))return ret; 63 | 64 | if(out)*out=cmdbuf[3]; 65 | 66 | return cmdbuf[1]; 67 | } 68 | 69 | Result FSUSER_OpenArchive(Handle handle, FS_archive* archive) 70 | { 71 | if(!archive)return -2; 72 | u32* cmdbuf=getThreadCommandBuffer(); 73 | 74 | cmdbuf[0]=0x080C00C2; 75 | cmdbuf[1]=archive->id; 76 | cmdbuf[2]=archive->lowPath.type; 77 | cmdbuf[3]=archive->lowPath.size; 78 | cmdbuf[4]=(archive->lowPath.size<<14)|0x2; 79 | cmdbuf[5]=(u32)archive->lowPath.data; 80 | 81 | Result ret=0; 82 | if((ret=svc_sendSyncRequest(handle)))return ret; 83 | 84 | archive->handleLow=cmdbuf[2]; 85 | archive->handleHigh=cmdbuf[3]; 86 | 87 | return cmdbuf[1]; 88 | } 89 | 90 | Result FSUSER_OpenDirectory(Handle handle, Handle* out, FS_archive archive, FS_path dirLowPath) 91 | { 92 | u32* cmdbuf=getThreadCommandBuffer(); 93 | 94 | cmdbuf[0]=0x080B0102; 95 | cmdbuf[1]=archive.handleLow; 96 | cmdbuf[2]=archive.handleHigh; 97 | cmdbuf[3]=dirLowPath.type; 98 | cmdbuf[4]=dirLowPath.size; 99 | cmdbuf[5]=(dirLowPath.size<<14)|0x2; 100 | cmdbuf[6]=(u32)dirLowPath.data; 101 | 102 | Result ret=0; 103 | if((ret=svc_sendSyncRequest(handle)))return ret; 104 | 105 | if(out)*out=cmdbuf[3]; 106 | 107 | return cmdbuf[1]; 108 | } 109 | 110 | Result FSUSER_CloseArchive(Handle handle, FS_archive* archive) 111 | { 112 | if(!archive)return -2; 113 | u32* cmdbuf=getThreadCommandBuffer(); 114 | 115 | cmdbuf[0]=0x080E0080; 116 | cmdbuf[1]=archive->handleLow; 117 | cmdbuf[2]=archive->handleLow; 118 | 119 | Result ret=0; 120 | if((ret=svc_sendSyncRequest(handle)))return ret; 121 | 122 | return cmdbuf[1]; 123 | } 124 | 125 | Result FSFILE_Close(Handle handle) 126 | { 127 | u32* cmdbuf=getThreadCommandBuffer(); 128 | 129 | cmdbuf[0]=0x08080000; 130 | 131 | Result ret=0; 132 | if((ret=svc_sendSyncRequest(handle)))return ret; 133 | 134 | return cmdbuf[1]; 135 | } 136 | 137 | Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, u32 *buffer, u32 size) 138 | { 139 | u32 *cmdbuf=getThreadCommandBuffer(); 140 | 141 | cmdbuf[0]=0x080200C2; 142 | cmdbuf[1]=(u32)offset; 143 | cmdbuf[2]=(u32)(offset>>32); 144 | cmdbuf[3]=size; 145 | cmdbuf[4]=(size<<4)|12; 146 | cmdbuf[5]=(u32)buffer; 147 | 148 | Result ret=0; 149 | if((ret=svc_sendSyncRequest(handle)))return ret; 150 | 151 | if(bytesRead)*bytesRead=cmdbuf[2]; 152 | 153 | return cmdbuf[1]; 154 | } 155 | 156 | //WARNING : using wrong flushFlags CAN corrupt the archive you're writing to. 157 | //another warning : data should *not* be in RO memory 158 | Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, u32 *data, u32 size, u32 flushFlags) 159 | { 160 | u32 *cmdbuf=getThreadCommandBuffer(); 161 | 162 | cmdbuf[0]=0x08030102; 163 | cmdbuf[1]=(u32)offset; 164 | cmdbuf[2]=(u32)(offset>>32); 165 | cmdbuf[3]=size; 166 | cmdbuf[4]=flushFlags; 167 | cmdbuf[5]=(size<<4)|10; 168 | cmdbuf[6]=(u32)data; 169 | 170 | Result ret=0; 171 | if((ret=svc_sendSyncRequest(handle)))return ret; 172 | 173 | if(bytesWritten)*bytesWritten=cmdbuf[2]; 174 | 175 | return cmdbuf[1]; 176 | } 177 | 178 | Result FSFILE_GetSize(Handle handle, u64 *size) 179 | { 180 | u32 *cmdbuf=getThreadCommandBuffer(); 181 | 182 | cmdbuf[0] = 0x08040000; 183 | 184 | Result ret=0; 185 | if((ret=svc_sendSyncRequest(handle)))return ret; 186 | 187 | if(size)*size = *((u64*)&cmdbuf[2]); 188 | 189 | return cmdbuf[1]; 190 | } 191 | 192 | Result FSFILE_SetSize(Handle handle, u64 size) 193 | { 194 | u32 *cmdbuf = getThreadCommandBuffer(); 195 | 196 | cmdbuf[0] = 0x08050080; 197 | cmdbuf[1] = (u32)size; 198 | cmdbuf[2] = (u32)(size >> 32); 199 | 200 | Result ret = 0; 201 | if ((ret = svc_sendSyncRequest(handle)))return ret; 202 | 203 | 204 | return cmdbuf[1]; 205 | } 206 | 207 | Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, u16 *buffer) 208 | { 209 | u32 *cmdbuf=getThreadCommandBuffer(); 210 | 211 | cmdbuf[0]=0x08010042; 212 | cmdbuf[1]=entrycount; 213 | cmdbuf[2]=((entrycount*0x228)<<4)|0xC; 214 | cmdbuf[3]=(u32)buffer; 215 | 216 | Result ret=0; 217 | if((ret=svc_sendSyncRequest(handle)))return ret; 218 | 219 | if(entriesRead)*entriesRead=cmdbuf[2]; 220 | 221 | return cmdbuf[1]; 222 | } 223 | 224 | Result FSDIR_Close(Handle handle) 225 | { 226 | u32* cmdbuf=getThreadCommandBuffer(); 227 | 228 | cmdbuf[0]=0x08020000; 229 | 230 | Result ret=0; 231 | if((ret=svc_sendSyncRequest(handle)))return ret; 232 | 233 | return cmdbuf[1]; 234 | } 235 | -------------------------------------------------------------------------------- /fps/source/libctru/OS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | u32 OS_ConvertVaddr2Physaddr(u32 vaddr) 9 | { 10 | if(vaddr >= 0x14000000 && vaddr<0x1c000000)return vaddr + 0x0c000000;//LINEAR memory 11 | if(vaddr >= 0x30000000 && vaddr<0x40000000)return vaddr - 0x10000000;//Only available under system-version v8.0 for certain processes, see here: http://3dbrew.org/wiki/SVC#enum_MemoryOperation 12 | if(vaddr >= 0x1F000000 && vaddr<0x1F600000)return vaddr - 0x07000000;//VRAM 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /fps/source/libctru/srv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Handle srvHandle=0; 9 | 10 | Result initSrv() 11 | { 12 | Result ret=0; 13 | if(svc_connectToPort(&srvHandle, "srv:"))return ret; 14 | return srv_RegisterClient(&srvHandle); 15 | } 16 | 17 | Result exitSrv() 18 | { 19 | if(srvHandle)svc_closeHandle(srvHandle); 20 | } 21 | 22 | Result srv_RegisterClient(Handle* handleptr) 23 | { 24 | if(!handleptr)handleptr=&srvHandle; 25 | u32* cmdbuf=getThreadCommandBuffer(); 26 | cmdbuf[0]=0x10002; //request header code 27 | cmdbuf[1]=0x20; 28 | 29 | Result ret=0; 30 | if((ret=svc_sendSyncRequest(*handleptr)))return ret; 31 | 32 | return cmdbuf[1]; 33 | } 34 | 35 | Result srv_getServiceHandle(Handle* handleptr, Handle* out, char* server) 36 | { 37 | if(!handleptr)handleptr=&srvHandle; 38 | u8 l=strlen(server); 39 | if(!out || !server || l>8)return -1; 40 | 41 | u32* cmdbuf=getThreadCommandBuffer(); 42 | 43 | cmdbuf[0]=0x50100; //request header code 44 | strcpy((char*)&cmdbuf[1], server); 45 | cmdbuf[3]=l; 46 | cmdbuf[4]=0x0; 47 | 48 | Result ret=0; 49 | if((ret=svc_sendSyncRequest(*handleptr)))return ret; 50 | 51 | *out=cmdbuf[3]; 52 | 53 | return cmdbuf[1]; 54 | } 55 | -------------------------------------------------------------------------------- /fps/source/libctru/svc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | 3 | .align 4 4 | 5 | .global getThreadCommandBuffer 6 | .type getThreadCommandBuffer, %function 7 | getThreadCommandBuffer: 8 | mrc p15, 0, r0, c13, c0, 3 9 | add r0, #0x80 10 | bx lr 11 | 12 | 13 | .global svc_controlMemory 14 | .type svc_controlMemory, %function 15 | svc_controlMemory: 16 | stmfd sp!, {r0, r4} 17 | ldr r0, [sp, #0x8] 18 | ldr r4, [sp, #0x8+0x4] 19 | svc 0x01 20 | ldr r2, [sp], #4 21 | str r1, [r2] 22 | ldr r4, [sp], #4 23 | bx lr 24 | 25 | .global svc_exitProcess 26 | .type svc_exitProcess, %function 27 | svc_exitProcess: 28 | svc 0x03 29 | bx lr 30 | 31 | .global svc_createThread 32 | .type svc_createThread, %function 33 | svc_createThread: 34 | stmfd sp!, {r0, r4} 35 | ldr r0, [sp, #0x8] 36 | ldr r4, [sp, #0x8+0x4] 37 | svc 0x08 38 | ldr r2, [sp], #4 39 | str r1, [r2] 40 | ldr r4, [sp], #4 41 | bx lr 42 | 43 | .global svc_exitThread 44 | .type svc_exitThread, %function 45 | svc_exitThread: 46 | svc 0x09 47 | bx lr 48 | 49 | .global svc_sleepThread 50 | .type svc_sleepThread, %function 51 | svc_sleepThread: 52 | svc 0x0A 53 | bx lr 54 | 55 | .global svc_createMutex 56 | .type svc_createMutex, %function 57 | svc_createMutex: 58 | str r0, [sp, #-4]! 59 | svc 0x13 60 | ldr r3, [sp], #4 61 | str r1, [r3] 62 | bx lr 63 | 64 | .global svc_releaseMutex 65 | .type svc_releaseMutex, %function 66 | svc_releaseMutex: 67 | svc 0x14 68 | bx lr 69 | 70 | .global svc_releaseSemaphore 71 | .type svc_releaseSemaphore, %function 72 | svc_releaseSemaphore: 73 | str r0, [sp,#-4]! 74 | svc 0x16 75 | ldr r2, [sp], #4 76 | str r1, [r2] 77 | bx lr 78 | 79 | .global svc_createEvent 80 | .type svc_createEvent, %function 81 | svc_createEvent: 82 | str r0, [sp,#-4]! 83 | svc 0x17 84 | ldr r2, [sp], #4 85 | str r1, [r2] 86 | bx lr 87 | 88 | .global svc_signalEvent 89 | .type svc_signalEvent, %function 90 | svc_signalEvent: 91 | svc 0x18 92 | bx lr 93 | 94 | .global svc_clearEvent 95 | .type svc_clearEvent, %function 96 | svc_clearEvent: 97 | svc 0x19 98 | bx lr 99 | 100 | .global svc_createMemoryBlock 101 | .type svc_createMemoryBlock, %function 102 | svc_createMemoryBlock: 103 | str r0, [sp, #-4]! 104 | ldr r0, [sp, #4] 105 | svc 0x1E 106 | ldr r2, [sp], #4 107 | str r1, [r2] 108 | bx lr 109 | 110 | .global svc_mapMemoryBlock 111 | .type svc_mapMemoryBlock, %function 112 | svc_mapMemoryBlock: 113 | svc 0x1F 114 | bx lr 115 | 116 | .global svc_unmapMemoryBlock 117 | .type svc_unmapMemoryBlock, %function 118 | svc_unmapMemoryBlock: 119 | svc 0x20 120 | bx lr 121 | 122 | .global svc_arbitrateAddress 123 | .type svc_arbitrateAddress, %function 124 | svc_arbitrateAddress: 125 | svc 0x22 126 | bx lr 127 | 128 | .global svc_closeHandle 129 | .type svc_closeHandle, %function 130 | svc_closeHandle: 131 | svc 0x23 132 | bx lr 133 | 134 | .global svc_waitSynchronization1 135 | .type svc_waitSynchronization1, %function 136 | svc_waitSynchronization1: 137 | svc 0x24 138 | bx lr 139 | 140 | .global svc_waitSynchronizationN 141 | .type svc_waitSynchronizationN, %function 142 | svc_waitSynchronizationN: 143 | str r5, [sp, #-4]! 144 | mov r5, r0 145 | ldr r0, [sp, #0x4] 146 | ldr r4, [sp, #0x4+0x4] 147 | svc 0x25 148 | str r1, [r5] 149 | ldr r5, [sp], #4 150 | bx lr 151 | 152 | .global svc_getSystemTick 153 | .type svc_getSystemTick, %function 154 | svc_getSystemTick: 155 | svc 0x28 156 | bx lr 157 | 158 | .global svc_getSystemInfo 159 | .type svc_getSystemInfo, %function 160 | svc_getSystemInfo: 161 | stmfd sp!, {r0, r4} 162 | svc 0x2A 163 | ldr r4, [sp], #4 164 | str r1, [r4] 165 | str r2, [r4, #4] 166 | # str r3, [r4, #8] # ? 167 | ldr r4, [sp], #4 168 | bx lr 169 | 170 | .global svc_getProcessInfo 171 | .type svc_getProcessInfo, %function 172 | svc_getProcessInfo: 173 | stmfd sp!, {r0, r4} 174 | svc 0x2B 175 | ldr r4, [sp], #4 176 | str r1, [r4] 177 | str r2, [r4, #4] 178 | ldr r4, [sp], #4 179 | bx lr 180 | 181 | .global svc_connectToPort 182 | .type svc_connectToPort, %function 183 | svc_connectToPort: 184 | str r0, [sp,#-0x4]! 185 | svc 0x2D 186 | ldr r3, [sp], #4 187 | str r1, [r3] 188 | bx lr 189 | 190 | .global svc_sendSyncRequest 191 | .type svc_sendSyncRequest, %function 192 | svc_sendSyncRequest: 193 | svc 0x32 194 | bx lr 195 | 196 | .global svc_getProcessId 197 | .type svc_getProcessId, %function 198 | svc_getProcessId: 199 | str r0, [sp,#-0x4]! 200 | svc 0x35 201 | ldr r3, [sp], #4 202 | str r1, [r3] 203 | bx lr 204 | 205 | .global svc_getThreadId 206 | .type svc_getThreadId, %function 207 | svc_getThreadId: 208 | str r0, [sp,#-0x4]! 209 | svc 0x37 210 | ldr r3, [sp], #4 211 | str r1, [r3] 212 | bx lr 213 | 214 | 215 | .global svc_setThreadIdealProcessor 216 | .type svc_setThreadIdealProcessor, %function 217 | svc_setThreadIdealProcessor: 218 | svc 0x10 219 | bx lr 220 | 221 | .global svc_openThread 222 | .type svc_openThread, %function 223 | svc_openThread: 224 | str r0, [sp,#-0x4]! 225 | svc 0x34 226 | ldr r3, [sp], #4 227 | str r1, [r3] 228 | bx lr 229 | 230 | .global svc_flushProcessDataCache 231 | .type svc_flushProcessDataCache, %function 232 | svc_flushProcessDataCache: 233 | svc 0x54 234 | bx lr 235 | 236 | .global svc_invalidateProcessDataCache 237 | .type svc_invalidateProcessDataCache, %function 238 | svc_invalidateProcessDataCache: 239 | svc 0x52 240 | bx lr 241 | 242 | .global svc_queryMemory 243 | .type svc_queryMemory, %function 244 | svc_queryMemory: 245 | svc 0x02 246 | bx lr 247 | 248 | .global svc_addCodeSegment 249 | .type svc_addCodeSegment, %function 250 | svc_addCodeSegment: 251 | svc 0x7a 252 | bx lr 253 | 254 | .global svc_openProcess 255 | .type svc_openProcess, %function 256 | svc_openProcess: 257 | str r0, [sp,#-0x4]! 258 | svc 0x33 259 | ldr r3, [sp], #4 260 | str r1, [r3] 261 | bx lr 262 | 263 | .global svc_controlProcessMemory 264 | .type svc_controlProcessMemory, %function 265 | svc_controlProcessMemory: 266 | 267 | stmfd sp!, {r0, r4, r5} 268 | ldr r4, [sp, #0xC+0x0] 269 | ldr r5, [sp, #0xC+0x4] 270 | svc 0x70 271 | ldmfd sp!, {r2, r4, r5} 272 | bx lr 273 | 274 | 275 | .global svc_mapProcessMemory 276 | .type svc_mapProcessMemory, %function 277 | svc_mapProcessMemory: 278 | 279 | svc 0x71 280 | bx lr 281 | 282 | .global svc_startInterProcessDma 283 | .type svc_startInterProcessDma, %function 284 | svc_startInterProcessDma: 285 | 286 | stmfd sp!, {r0, r4, r5} 287 | ldr r0, [sp, #0xC] 288 | ldr r4, [sp, #0xC+0x4] 289 | ldr r5, [sp, #0xC+0x8] 290 | svc 0x55 291 | ldmfd sp!, {r2, r4, r5} 292 | str r1, [r2] 293 | bx lr 294 | 295 | .global svc_getDmaState 296 | .type svc_getDmaState, %function 297 | svc_getDmaState: 298 | 299 | str r0, [sp,#-0x4]! 300 | svc 0x57 301 | ldr r3, [sp], #4 302 | str r1, [r3] 303 | bx lr 304 | 305 | 306 | .global svc_backDoor 307 | .type svc_backDoor, %function 308 | svc_backDoor: 309 | svc 0x7b 310 | bx lr 311 | 312 | 313 | .global svc_getProcessList 314 | .type svc_getProcessList, %function 315 | svc_getProcessList: 316 | str r0, [sp,#-0x4]! 317 | svc 0x65 318 | ldr r3, [sp], #4 319 | str r1, [r3] 320 | bx lr 321 | 322 | 323 | .global svc_getThreadList 324 | .type svc_getThreadList, %function 325 | svc_getThreadList: 326 | str r0, [sp,#-0x4]! 327 | svc 0x66 328 | ldr r3, [sp], #4 329 | str r1, [r3] 330 | bx lr 331 | 332 | .global svc_getThreadContext 333 | .type svc_getThreadContext, %function 334 | svc_getThreadContext: 335 | svc 0x3b 336 | bx lr 337 | 338 | 339 | 340 | .global svc_debugActiveProcess 341 | .type svc_debugActiveProcess, %function 342 | svc_debugActiveProcess: 343 | str r0, [sp,#-0x4]! 344 | svc 0x60 345 | ldr r3, [sp], #4 346 | str r1, [r3] 347 | bx lr 348 | 349 | .global svc_readProcessMemory 350 | .type svc_readProcessMemory, %function 351 | svc_readProcessMemory: 352 | svc 0x6a 353 | bx lr 354 | 355 | .global svc_writeProcessMemory 356 | .type svc_writeProcessMemory, %function 357 | svc_writeProcessMemory: 358 | svc 0x6b 359 | bx lr 360 | 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /fps/source/libntrplg/pm.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | void dumpKernel() { 4 | 5 | } 6 | 7 | Handle hCurrentProcess = 0; 8 | u32 currentPid = 0; 9 | 10 | u32 getCurrentProcessId() { 11 | svc_getProcessId(¤tPid, 0xffff8001); 12 | return currentPid; 13 | } 14 | 15 | u32 getCurrentProcessHandle() { 16 | u32 handle = 0; 17 | u32 ret; 18 | 19 | if (hCurrentProcess != 0) { 20 | return hCurrentProcess; 21 | } 22 | svc_getProcessId(¤tPid, 0xffff8001); 23 | ret = svc_openProcess(&handle, currentPid); 24 | if (ret != 0) { 25 | showDbg("openProcess failed, ret: %08x", ret, 0); 26 | return 0; 27 | } 28 | hCurrentProcess = handle; 29 | return hCurrentProcess; 30 | } 31 | 32 | 33 | 34 | u32 protectRemoteMemory(Handle hProcess, void* addr, u32 size) { 35 | u32 outAddr = 0; 36 | 37 | return svc_controlProcessMemory(hProcess, addr, addr, size, 6, 7); 38 | } 39 | 40 | u32 protectMemory(void* addr, u32 size) { 41 | return protectRemoteMemory(getCurrentProcessHandle(), addr, size); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /fps/source/libntrplg/rt.c: -------------------------------------------------------------------------------- 1 | 2 | #include "global.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void rtInitLock(RT_LOCK *lock) { 11 | lock->value = 0; 12 | } 13 | 14 | void rtAcquireLock(RT_LOCK *lock) { 15 | while(lock->value != 0) { 16 | svc_sleepThread(1000000); 17 | } 18 | lock->value = 1; 19 | } 20 | 21 | void rtReleaseLock(RT_LOCK *lock) { 22 | lock->value = 0; 23 | } 24 | 25 | u32 rtAlignToPageSize(u32 size) { 26 | return ((size / 0x1000) + 1) * 0x1000; 27 | } 28 | 29 | u32 rtGetPageOfAddress(u32 addr) { 30 | return (addr / 0x1000) * 0x1000; 31 | } 32 | 33 | 34 | u32 rtCheckRemoteMemoryRegionSafeForWrite(Handle hProcess, u32 addr, u32 size) { 35 | u32 ret; 36 | u32 startPage, endPage, page; 37 | 38 | startPage = rtGetPageOfAddress(addr); 39 | endPage = rtGetPageOfAddress(addr + size - 1); 40 | 41 | for (page = startPage; page <= endPage; page += 0x1000) { 42 | ret = protectRemoteMemory(hProcess, (void*) page, 0x1000); 43 | if (ret != 0) { 44 | return ret; 45 | } 46 | } 47 | return 0; 48 | } 49 | 50 | u32 rtSafeCopyMemory(u32 dst, u32 src, u32 size) { 51 | u32 ret; 52 | 53 | ret = rtCheckRemoteMemoryRegionSafeForWrite(0xffff8001, dst, size) ; 54 | if (ret != 0) { 55 | return ret; 56 | } 57 | ret = rtCheckRemoteMemoryRegionSafeForWrite(0xffff8001, src, size) ; 58 | if (ret != 0) { 59 | return ret; 60 | } 61 | memcpy((void*) dst, (void*) src, size); 62 | return 0; 63 | } 64 | 65 | #if USE_SOCKET 66 | 67 | 68 | int rtRecvSocket(u32 sockfd, u8 *buf, int size) 69 | { 70 | int ret, pos=0; 71 | int tmpsize=size; 72 | 73 | while(tmpsize) 74 | { 75 | if((ret = recv(sockfd, &buf[pos], tmpsize, 0))<=0) 76 | { 77 | if(ret<0)ret = SOC_GetErrno(); 78 | if(ret == -EWOULDBLOCK)continue; 79 | return ret; 80 | } 81 | pos+= ret; 82 | tmpsize-= ret; 83 | } 84 | 85 | return size; 86 | } 87 | 88 | int rtSendSocket(u32 sockfd, u8 *buf, int size) 89 | { 90 | int ret, pos=0; 91 | int tmpsize=size; 92 | 93 | while(tmpsize) 94 | { 95 | if((ret = send(sockfd, &buf[pos], tmpsize, 0))<0) 96 | { 97 | ret = SOC_GetErrno(); 98 | if(ret == -EWOULDBLOCK)continue; 99 | return ret; 100 | } 101 | pos+= ret; 102 | tmpsize-= ret; 103 | } 104 | 105 | return size; 106 | } 107 | 108 | u16 rtIntToPortNumber(u16 x) { 109 | u8* buf; 110 | u8 tmp; 111 | 112 | buf = (void*)&x; 113 | tmp = buf[0]; 114 | buf[0] = buf[1]; 115 | buf[1] = tmp; 116 | return *((u16*)buf); 117 | } 118 | 119 | #endif 120 | 121 | u32 rtGetFileSize(u8* fileName) { 122 | u32 hFile, size, ret; 123 | u64 size64 ; 124 | 125 | FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; 126 | ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); 127 | if (ret != 0) { 128 | nsDbgPrint("openFile failed: %08x\n", ret, 0); 129 | hFile = 0; 130 | goto final; 131 | } 132 | ret = FSFILE_GetSize(hFile, &size64); 133 | if (ret != 0) { 134 | nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); 135 | goto final; 136 | } 137 | size = size64; 138 | 139 | final: 140 | if (hFile != 0) { 141 | svc_closeHandle(hFile); 142 | } 143 | if (ret != 0) { 144 | return 0; 145 | } 146 | return size; 147 | } 148 | 149 | u32 rtLoadFileToBuffer(u8* fileName, u32* pBuf, u32 bufSize) { 150 | u32 ret; 151 | u32 hFile, size; 152 | u64 size64; 153 | u32 tmp; 154 | 155 | FS_path testPath = (FS_path){PATH_CHAR, strlen(fileName) + 1, fileName}; 156 | ret = FSUSER_OpenFileDirectly(fsUserHandle, &hFile, sdmcArchive, testPath, 7, 0); 157 | if (ret != 0) { 158 | nsDbgPrint("openFile failed: %08x\n", ret, 0); 159 | hFile = 0; 160 | goto final; 161 | } 162 | 163 | ret = FSFILE_GetSize(hFile, &size64); 164 | if (ret != 0) { 165 | nsDbgPrint("FSFILE_GetSize failed: %08x\n", ret, 0); 166 | goto final; 167 | } 168 | 169 | size = size64; 170 | 171 | if (bufSize < size) { 172 | nsDbgPrint("rtLoadFileToBuffer: buffer too small\n"); 173 | ret = -1; 174 | goto final; 175 | } 176 | 177 | ret = FSFILE_Read(hFile, &tmp, 0, (u32*)pBuf, size); 178 | if(ret != 0) { 179 | nsDbgPrint("FSFILE_Read failed: %08x\n", ret, 0); 180 | goto final; 181 | } 182 | 183 | final: 184 | if (hFile != 0) { 185 | svc_closeHandle(hFile); 186 | } 187 | if (ret != 0) { 188 | return 0; 189 | } 190 | 191 | return size; 192 | } 193 | 194 | 195 | u32 rtGenerateJumpCode(u32 dst, u32* buf) { 196 | buf[0] = 0xe51ff004; 197 | buf[1] = dst; 198 | return 8; 199 | } 200 | 201 | void rtInitHook(RT_HOOK* hook, u32 funcAddr, u32 callbackAddr) { 202 | hook->model = 0; 203 | hook->isEnabled = 0; 204 | hook->funcAddr = funcAddr; 205 | 206 | rtCheckRemoteMemoryRegionSafeForWrite(getCurrentProcessHandle(), funcAddr, 8); 207 | memcpy(hook->bakCode, (void*) funcAddr, 8); 208 | rtGenerateJumpCode(callbackAddr, hook->jmpCode); 209 | memcpy(hook->callCode, (void*) funcAddr, 8); 210 | rtGenerateJumpCode(funcAddr + 8, &(hook->callCode[2])); 211 | rtFlushInstructionCache(hook->callCode, 16); 212 | } 213 | 214 | u32 rtFlushInstructionCache(void* ptr, u32 size) { 215 | return svc_flushProcessDataCache(0xffff8001, (u32)ptr, size); 216 | } 217 | 218 | void rtEnableHook(RT_HOOK* hook) { 219 | if (hook->isEnabled) { 220 | return; 221 | } 222 | memcpy((void*) hook->funcAddr, hook->jmpCode, 8); 223 | rtFlushInstructionCache((void*) hook->funcAddr, 8); 224 | hook->isEnabled = 1; 225 | } 226 | 227 | void rtDisableHook(RT_HOOK* hook) { 228 | if (!hook->isEnabled) { 229 | return; 230 | } 231 | memcpy((void*) hook->funcAddr, hook->bakCode, 8); 232 | rtFlushInstructionCache((void*) hook->funcAddr, 8); 233 | hook->isEnabled = 0; 234 | } -------------------------------------------------------------------------------- /fps/source/libntrplg/sharedfunc.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | 4 | 5 | void initSharedFunc() { 6 | 7 | INIT_SHARED_FUNC(showDbg, 0); 8 | INIT_SHARED_FUNC(nsDbgPrint, 1); 9 | INIT_SHARED_FUNC(plgRegisterMenuEntry, 2); 10 | INIT_SHARED_FUNC(plgGetSharedServiceHandle, 3); 11 | INIT_SHARED_FUNC(plgRequestMemory, 4); 12 | INIT_SHARED_FUNC(plgRegisterCallback, 5); 13 | INIT_SHARED_FUNC(xsprintf, 6); 14 | } 15 | -------------------------------------------------------------------------------- /fps/source/libntrplg/stub.s: -------------------------------------------------------------------------------- 1 | .global showDbg; 2 | .type showDbg, %function; 3 | showDbg: 4 | nop 5 | nop 6 | 7 | 8 | .global nsDbgPrint; 9 | .type nsDbgPrint, %function; 10 | nsDbgPrint: 11 | nop 12 | nop 13 | 14 | 15 | .global plgRegisterMenuEntry; 16 | .type plgRegisterMenuEntry, %function; 17 | plgRegisterMenuEntry: 18 | nop 19 | nop 20 | 21 | 22 | .global plgGetSharedServiceHandle; 23 | .type plgGetSharedServiceHandle, %function; 24 | plgGetSharedServiceHandle: 25 | nop 26 | nop 27 | 28 | 29 | .global plgRequestMemory; 30 | .type plgRequestMemory, %function; 31 | plgRequestMemory: 32 | nop 33 | nop 34 | 35 | .global plgRegisterCallback; 36 | .type plgRegisterCallback, %function; 37 | plgRegisterCallback: 38 | nop 39 | nop 40 | 41 | .global xsprintf; 42 | .type xsprintf, %function; 43 | xsprintf: 44 | nop 45 | nop 46 | 47 | 48 | -------------------------------------------------------------------------------- /fps/source/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "global.h" 3 | #include "ov.h" 4 | 5 | FS_archive sdmcArchive = { 0x9, (FS_path){ PATH_EMPTY, 1, (u8*)"" } }; 6 | Handle fsUserHandle = 0; 7 | 8 | #define CALLBACK_OVERLAY (101) 9 | 10 | 11 | 12 | #define TICKS_PER_MSEC (268123.480) 13 | 14 | 15 | int frameCount[2]; 16 | u64 lastUpdatedTick[2]; 17 | int fps[2]; 18 | 19 | 20 | void drawWidget(int calculateFps, int isBottom, u32 addr, u32 stride, u32 format, u32 colOffset) { 21 | u32 height = isBottom ? 320 : 400; 22 | char buf[30]; 23 | if (calculateFps) { 24 | frameCount[isBottom] ++; 25 | if (frameCount[isBottom] >= 64) { 26 | frameCount[isBottom] = 0; 27 | u64 tickNow = svc_getSystemTick(); 28 | u64 diff = tickNow - lastUpdatedTick[isBottom] ; 29 | lastUpdatedTick[isBottom] = tickNow; 30 | fps[isBottom] = 64.0 / ((double) (diff) / TICKS_PER_MSEC / 1000.0) * 10.0; 31 | } 32 | } 33 | 34 | 35 | ovDrawTranspartBlackRect(addr, stride, format, 9, colOffset, 12, 80 + 4, 1); 36 | xsprintf(buf, "fps: %d.%d", fps[isBottom] / 10, fps[isBottom] % 10); 37 | ovDrawString(addr, stride, format, height, 11, colOffset + 4, 255, 255, 255, buf); 38 | } 39 | 40 | 41 | /* 42 | Overlay Callback. 43 | isBottom: 1 for bottom screen, 0 for top screen. 44 | addr: writable cached framebuffer virtual address. 45 | addrB: right-eye framebuffer for top screen, undefined for bottom screen. 46 | stride: framebuffer stride(pitch) in bytes, at least 240*bytes_per_pixel. 47 | format: framebuffer format, see https://www.3dbrew.org/wiki/GPU/External_Registers for details. 48 | 49 | NTR will invalidate data cache of the framebuffer before calling overlay callbacks. NTR will flush data cache after the callbacks were called and at least one overlay callback returns zero. 50 | 51 | return 0 when the framebuffer was modified. return 1 when nothing in the framebuffer was modified. 52 | */ 53 | 54 | u32 overlayCallback(u32 isBottom, u32 addr, u32 addrB, u32 stride, u32 format) { 55 | drawWidget(1, isBottom, addr, stride, format, 14); 56 | // In 2D mode, top screen's addrB might be invalid or equal to addr, do not draw on addrB in either situations 57 | if ((isBottom == 0) && (addrB) && (addrB != addr)) { 58 | drawWidget(0, isBottom, addrB, stride, format, 10); 59 | } 60 | return 0; 61 | } 62 | 63 | int main() { 64 | u32 retv; 65 | 66 | initSharedFunc(); 67 | plgRegisterCallback(CALLBACK_OVERLAY, (void*) overlayCallback, 0); 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /fps/source/misc.s: -------------------------------------------------------------------------------- 1 | .arm 2 | .align(4); 3 | 4 | .global sleep 5 | .type sleep, %function 6 | sleep: 7 | SVC 0xA 8 | BX LR 9 | 10 | -------------------------------------------------------------------------------- /fps/source/ov.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "font.h" 3 | #include "ov.h" 4 | 5 | void ovDrawTranspartBlackRect(u32 addr, u32 stride, u32 format, int r, int c, int h, int w, u8 level) { 6 | format &= 0x0f; 7 | int posC; 8 | for (posC = c; posC < c + w; posC ++ ) { 9 | if (format == 2) { 10 | u16* sp = (u16*)(addr + stride * posC + 240 * 2 - 2 * (r + h - 1)); 11 | u16* spEnd = sp + h; 12 | while (sp < spEnd) { 13 | u16 pix = *sp; 14 | u16 r = (pix >> 11) & 0x1f; 15 | u16 g = (pix >> 5) & 0x3f; 16 | u16 b = (pix & 0x1f); 17 | pix = ((r >> level) << 11) | ((g >> level) << 5) | (b >> level); 18 | *sp = pix; 19 | sp++; 20 | } 21 | } else if (format == 1) { 22 | u8* sp = (u8*)(addr + stride * posC + 240 * 3 - 3 * (r + h - 1)); 23 | u8* spEnd = sp + 3 * h; 24 | while (sp < spEnd) { 25 | sp[0] >>= level; 26 | sp[1] >>= level; 27 | sp[2] >>= level; 28 | sp += 3; 29 | } 30 | } 31 | } 32 | } 33 | 34 | void ovDrawPixel(u32 addr, u32 stride, u32 format, int posR, int posC, u32 r, u32 g, u32 b) { 35 | format &= 0x0f; 36 | if (format == 2) { 37 | u16 pix = ((r ) << 11) | ((g ) << 5) | (b ); 38 | *(u16*)(addr + stride * posC + 240 * 2 -2 * posR) = pix; 39 | } else { 40 | u8* sp = (u8*)(addr + stride * posC + 240 * 3 - 3 * posR); 41 | sp[0] = b; 42 | sp[1] = g; 43 | sp[2] = r; 44 | } 45 | } 46 | 47 | void ovDrawRect(u32 addr, u32 stride, u32 format, int posR, int posC, int h, int w, u32 r, u32 g, u32 b) { 48 | int r_, c_; 49 | for (c_ = posC; c_ < posC + w; c_ ++) { 50 | for (r_ = posR; r_ < posR + h; r_ ++) { 51 | ovDrawPixel(addr, stride, format, r_, c_, r, g, b); 52 | } 53 | } 54 | } 55 | 56 | void ovDrawChar(u32 addr, u32 stride, u32 format, u8 letter,int y, int x, u32 r, u32 g, u32 b){ 57 | 58 | int i; 59 | int k; 60 | int c; 61 | unsigned char mask; 62 | unsigned char* _letter; 63 | unsigned char l; 64 | 65 | if ((letter < 32) || (letter > 127)) { 66 | letter = '?'; 67 | } 68 | 69 | c=(letter-32)*8; 70 | 71 | for (i = 0; i < 8; i++){ 72 | mask = 0b10000000; 73 | l = font[i+c]; 74 | for (k = 0; k < 8; k++){ 75 | if ((mask >> k) & l){ 76 | ovDrawPixel(addr, stride, format, i+y, k+x ,r,g,b); 77 | } 78 | } 79 | } 80 | } 81 | 82 | void ovDrawString(u32 addr, u32 stride, u32 format, u32 scrnWidth, int posR, int posC, u32 r, u32 g, u32 b, u8* buf) { 83 | while(*buf) { 84 | if ((posR + 8 > 240) || (posC + 8 > scrnWidth)) { 85 | return; 86 | } 87 | ovDrawChar(addr, stride, format, *buf, posR, posC, r, g, b); 88 | buf++; 89 | posC += 8; 90 | 91 | } 92 | } -------------------------------------------------------------------------------- /fps/source/ov.h: -------------------------------------------------------------------------------- 1 | void ovDrawTranspartBlackRect(u32 addr, u32 stride, u32 format, int r, int c, int h, int w, u8 level) ; 2 | void ovDrawPixel(u32 addr, u32 stride, u32 format, int posR, int posC, u32 r, u32 g, u32 b); 3 | void ovDrawRect(u32 addr, u32 stride, u32 format, int posR, int posC, int h, int w, u32 r, u32 g, u32 b); 4 | void ovDrawChar(u32 addr, u32 stride, u32 format, u8 letter,int y, int x, u32 r, u32 g, u32 b); 5 | void ovDrawString(u32 addr, u32 stride, u32 format, u32 scrnWidth, int posR, int posC, u32 r, u32 g, u32 b, u8* buf); 6 | 7 | -------------------------------------------------------------------------------- /fps/startenv.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | cmd --------------------------------------------------------------------------------