├── fps ├── bin │ └── empty.txt ├── obj │ └── empty.txt ├── include │ ├── netinet │ │ ├── tcp.h │ │ └── in.h │ ├── main.h │ ├── ctr │ │ ├── OS.h │ │ ├── AC.h │ │ ├── srv.h │ │ ├── CFGNOR.h │ │ ├── SOC.h │ │ ├── IR.h │ │ ├── HTTPC.h │ │ ├── GX.h │ │ ├── types.h │ │ ├── HID.h │ │ ├── SHDR.h │ │ ├── CSND.h │ │ ├── FS.h │ │ ├── GSP.h │ │ ├── GPU.h │ │ ├── APT.h │ │ └── svc.h │ ├── libntrplg │ │ ├── netdb.h │ │ ├── constants.h │ │ ├── memory.h │ │ ├── global.h │ │ ├── sharedfunc.h │ │ ├── integer.h │ │ ├── func.h │ │ ├── xprintf.h │ │ └── ns │ │ │ └── ns.h │ └── sys │ │ └── socket.h ├── build.bat ├── startenv.bat ├── lib │ ├── libc.a │ └── libgcc.a ├── source │ ├── misc.s │ ├── entry.c │ ├── libntrplg │ │ ├── sharedfunc.c │ │ ├── stub.s │ │ ├── pm.c │ │ └── rt.c │ ├── ov.h │ ├── libctru │ │ ├── OS.c │ │ ├── srv.c │ │ └── AC.c │ ├── bootloader.s │ ├── main.c │ └── ov.c ├── 3ds.ld └── build.py ├── clock ├── bin │ └── empty.txt ├── obj │ └── empty.txt ├── include │ ├── netinet │ │ ├── tcp.h │ │ └── in.h │ ├── main.h │ ├── ctr │ │ ├── OS.h │ │ ├── AC.h │ │ ├── srv.h │ │ ├── CFGNOR.h │ │ ├── SOC.h │ │ ├── IR.h │ │ ├── HTTPC.h │ │ ├── GX.h │ │ ├── types.h │ │ ├── HID.h │ │ ├── SHDR.h │ │ ├── CSND.h │ │ ├── FS.h │ │ ├── GSP.h │ │ ├── GPU.h │ │ ├── APT.h │ │ └── svc.h │ ├── libntrplg │ │ ├── netdb.h │ │ ├── constants.h │ │ ├── memory.h │ │ ├── global.h │ │ ├── sharedfunc.h │ │ ├── integer.h │ │ ├── func.h │ │ ├── xprintf.h │ │ └── ns │ │ │ └── ns.h │ └── sys │ │ └── socket.h ├── startenv.bat ├── build.bat ├── lib │ ├── libc.a │ └── libgcc.a ├── source │ ├── misc.s │ ├── entry.c │ ├── libntrplg │ │ ├── sharedfunc.c │ │ ├── stub.s │ │ ├── pm.c │ │ └── rt.c │ ├── ov.h │ ├── libctru │ │ ├── OS.c │ │ ├── srv.c │ │ └── AC.c │ ├── bootloader.s │ ├── ov.c │ └── main.c ├── 3ds.ld └── build.py ├── clock_fps_with_menu ├── bin │ └── empty.txt ├── obj │ └── empty.txt ├── include │ ├── netinet │ │ ├── tcp.h │ │ └── in.h │ ├── main.h │ ├── ctr │ │ ├── OS.h │ │ ├── AC.h │ │ ├── srv.h │ │ ├── CFGNOR.h │ │ ├── SOC.h │ │ ├── IR.h │ │ ├── HTTPC.h │ │ ├── GX.h │ │ ├── HID.h │ │ ├── types.h │ │ ├── SHDR.h │ │ ├── CSND.h │ │ ├── FS.h │ │ ├── GSP.h │ │ ├── GPU.h │ │ ├── APT.h │ │ └── svc.h │ ├── libntrplg │ │ ├── ui.h │ │ ├── netdb.h │ │ ├── constants.h │ │ ├── memory.h │ │ ├── global.h │ │ ├── integer.h │ │ ├── sharedfunc.h │ │ ├── xprintf.h │ │ ├── func.h │ │ └── ns │ │ │ └── ns.h │ └── sys │ │ └── socket.h ├── startenv.bat ├── build.bat ├── lib │ ├── libc.a │ └── libgcc.a ├── source │ ├── misc.s │ ├── entry.c │ ├── libntrplg │ │ ├── sharedfunc.c │ │ ├── pm.c │ │ ├── stub.s │ │ └── rt.c │ ├── ov.h │ ├── libctru │ │ ├── OS.c │ │ ├── srv.c │ │ └── AC.c │ ├── bootloader.s │ ├── fspCounter.c │ ├── ui.c │ ├── main.c │ ├── services.c │ ├── batteryWidget.c │ ├── ov.c │ └── OverlayMenu.c ├── 3ds.ld └── build.py ├── README.md ├── LICENSE └── .gitignore /fps/bin/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fps/obj/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock/bin/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock/obj/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock/include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fps/include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock_fps_with_menu/bin/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock_fps_with_menu/obj/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock_fps_with_menu/include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /clock/startenv.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | cmd -------------------------------------------------------------------------------- /fps/build.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | build.py -------------------------------------------------------------------------------- /fps/startenv.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | cmd -------------------------------------------------------------------------------- /clock/build.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | build.py -------------------------------------------------------------------------------- /clock_fps_with_menu/startenv.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | cmd -------------------------------------------------------------------------------- /clock_fps_with_menu/build.bat: -------------------------------------------------------------------------------- 1 | set PATH=%PATH%;C:\devkitPro\devkitARM\bin 2 | build.py -------------------------------------------------------------------------------- /fps/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/fps/lib/libc.a -------------------------------------------------------------------------------- /clock/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/clock/lib/libc.a -------------------------------------------------------------------------------- /fps/lib/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/fps/lib/libgcc.a -------------------------------------------------------------------------------- /clock/include/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int main(); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /clock/lib/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/clock/lib/libgcc.a -------------------------------------------------------------------------------- /fps/include/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int main(); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /clock_fps_with_menu/include/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int main(); 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /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_fps_with_menu/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/clock_fps_with_menu/lib/libc.a -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/lib/libgcc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nanquitas/ntr_overlay_samples/HEAD/clock_fps_with_menu/lib/libgcc.a -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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/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_fps_with_menu/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/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/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_fps_with_menu/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/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/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_fps_with_menu/include/libntrplg/ui.h: -------------------------------------------------------------------------------- 1 | #ifndef UI_H 2 | #define UI_H 3 | 4 | void acquireVideo(); 5 | void releaseVideo(); 6 | void updateScreen(); 7 | 8 | u32 waitKey() ; 9 | u32 getKey() ; 10 | void waitKeyRelease(void); 11 | void updateScreen() ; 12 | 13 | #endif -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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/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_fps_with_menu/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/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/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_fps_with_menu/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/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/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/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/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_fps_with_menu/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/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/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_fps_with_menu/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_fps_with_menu/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/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/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/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/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_fps_with_menu/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_fps_with_menu/source/ov.h: -------------------------------------------------------------------------------- 1 | #ifndef OV_H 2 | #define OV_H 3 | 4 | void OvSettings(u32 addr, u32 addrB, u32 stride, u32 format, int isTop); 5 | void OvDrawTranspartBlackRect(int posX, int posY, int width, int height, u8 level); 6 | void OvDrawRect(int posX, int posY, int width, int height, u32 r, u32 g, u32 b); 7 | void OvDrawChar(char letter, int posX, int posY, u32 r, u32 g, u32 b); 8 | int OvDrawString(char *str, int posX, int posY, u32 r, u32 g, u32 b); 9 | int OvDrawStringTiny(char *str, int posX, int posY, u32 r, u32 g, u32 b); 10 | 11 | #endif -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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/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_fps_with_menu/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/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/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/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/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_fps_with_menu/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/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/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/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/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_fps_with_menu/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_fps_with_menu/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/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/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/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/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/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/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_fps_with_menu/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_fps_with_menu/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 28 | #include "ui.h" 29 | 30 | enum 31 | { 32 | CLOCK_ONLY = 1, 33 | CLOCK_BATTERY = 1 << 2, 34 | CLOCK_BOTTOM = 1 << 3, 35 | }; -------------------------------------------------------------------------------- /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 | # Clock & FPS with menu 15 | A configurable overlay plugin, with an ingame menu 16 | 17 | Press L + X + Y to open the menu, A to select an option, B to exit the menu 18 | 19 | # Usage 20 | Copy .plg files to **/plugin/game** folder in the sdcard. Then the overlay plugins be loaded in every games. 21 | 22 | Precompiled .plg files could be found at https://github.com/44670/ntr_overlay_samples/releases 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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/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/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_fps_with_menu/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/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 | .global copyRemoteMemory; 49 | .type controlVideo, %function; 50 | controlVideo: 51 | nop 52 | nop -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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/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_fps_with_menu/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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 | .global plgGetIoBase; 49 | .type plgGetIoBase, %function; 50 | plgGetIoBase: 51 | nop 52 | nop 53 | 54 | .global controlVideo; 55 | .type controlVideo, %function; 56 | controlVideo: 57 | nop 58 | nop 59 | 60 | .global copyRemoteMemory; 61 | .type copyRemoteMemory, %function; 62 | copyRemoteMemory: 63 | nop 64 | nop 65 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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_fps_with_menu/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 | #define CALLBACK_OVERLAY (101) 11 | 12 | u32 getCurrentProcessHandle(void); 13 | void initSharedFunc(void); 14 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 15 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 16 | u32 plgRequestMemory(u32 size); 17 | u32 plgRegisterCallback(u32 type, void* callback, u32 param0); 18 | u32 plgGetIoBase(u32 IoType); 19 | 20 | void showDbg(u8* fmt, u32 v1, u32 v2); 21 | void nsDbgPrint (const char* fmt, ... ); 22 | 23 | u32 controlVideo(u32 cmd, u32 arg1, u32 arg2, u32 arg3); 24 | #define CONTROLVIDEO_ACQUIREVIDEO 1 25 | #define CONTROLVIDEO_RELEASEVIDEO 2 26 | #define CONTROLVIDEO_GETFRAMEBUFFER 3 27 | #define CONTROLVIDEO_SETFRAMEBUFFER 4 28 | #define CONTROLVIDEO_UPDATESCREEN 5 29 | 30 | #define IO_BASE_PAD 1 31 | #define IO_BASE_LCD 2 32 | #define IO_BASE_PDC 3 33 | #define IO_BASE_GSPHEAP 4 34 | 35 | #endif -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_fps_with_menu/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/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/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_fps_with_menu/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_fps_with_menu/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 | 34 | /// Checks whether a result code indicates success. 35 | #define R_SUCCEEDED(res) ((res)>=0) 36 | /// Checks whether a result code indicates failure. 37 | #define R_FAILED(res) ((res)<0) 38 | /// Returns the level of a result code. 39 | #define R_LEVEL(res) (((res)>>27)&0x1F) 40 | /// Returns the summary of a result code. 41 | #define R_SUMMARY(res) (((res)>>21)&0x3F) 42 | /// Returns the module ID of a result code. 43 | #define R_MODULE(res) (((res)>>10)&0xFF) 44 | /// Returns the description of a result code. 45 | #define R_DESCRIPTION(res) ((res)&0x3FF) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_fps_with_menu/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 = 'fpsclockmenu.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/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/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_fps_with_menu/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/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/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_fps_with_menu/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_fps_with_menu/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 | u32 gamePluginPid; 31 | u32 gamePluginMenuAddr; 32 | } PLGLOADER_INFO; 33 | 34 | #define MAX_GAME_PLUGIN_MENU_ENTRY 64 35 | 36 | typedef struct _GAME_PLUGIN_MENU { 37 | u8 state[MAX_GAME_PLUGIN_MENU_ENTRY]; 38 | u16 offsetInBuffer[MAX_GAME_PLUGIN_MENU_ENTRY]; 39 | u16 bufOffset, count; 40 | u8 buf[3000]; 41 | } GAME_PLUGIN_MENU; 42 | 43 | void updateScreen(); 44 | s32 showMenu(u8* title, u32 entryCount, u8* captions[], int *selector); 45 | int showMsg(u8* msg); 46 | void showDbg(u8* fmt, u32 v1, u32 v2); 47 | void kmemcpy(void* dst, void* src, u32 size) ; 48 | u32 plgRegisterMenuEntry(u32 catalog, char* title, void* callback) ; 49 | u32 plgGetSharedServiceHandle(char* servName, u32* handle); 50 | 51 | #define CURRENT_PROCESS_HANDLE 0xffff8001 52 | 53 | #endif -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_fps_with_menu/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/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/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_fps_with_menu/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/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/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_fps_with_menu/source/fspCounter.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "ov.h" 3 | 4 | #define TICKS_PER_MSEC (268123.480) 5 | 6 | static int frameCount[2]; 7 | static u64 lastUpdatedTick[2]; 8 | static int fps[2]; 9 | 10 | int DrawFPSCounter(u32 isBottom) 11 | { 12 | char buf[30]; 13 | 14 | frameCount[isBottom]++; 15 | if (frameCount[isBottom] >= 64) 16 | { 17 | frameCount[isBottom] = 0; 18 | u64 tickNow = svc_getSystemTick(); 19 | u64 diff = tickNow - lastUpdatedTick[isBottom]; 20 | lastUpdatedTick[isBottom] = tickNow; 21 | fps[isBottom] = 64.0 / ((double)(diff) / TICKS_PER_MSEC / 1000.0) * 10.0; 22 | } 23 | 24 | OvDrawTranspartBlackRect(14, 9, 64, 12, 1); 25 | 26 | 27 | xsprintf(buf, "FPS: %02d.%02d", fps[isBottom] / 10, fps[isBottom] % 10); 28 | OvDrawString(buf, 16, 11, 255, 255, 255); 29 | return (1); 30 | } 31 | 32 | int DrawFPSCounterBottom(u32 isBottom, int mode)// 0 = disabled, 1 = both screen, 2 = top screen only, 3 = bottom screen only 33 | { 34 | char buf[30]; 35 | 36 | frameCount[isBottom]++; 37 | if (frameCount[isBottom] >= 64) 38 | { 39 | frameCount[isBottom] = 0; 40 | u64 tickNow = svc_getSystemTick(); 41 | u64 diff = tickNow - lastUpdatedTick[isBottom]; 42 | lastUpdatedTick[isBottom] = tickNow; 43 | fps[isBottom] = 64.0 / ((double)(diff) / TICKS_PER_MSEC / 1000.0) * 10.0; 44 | } 45 | 46 | if (isBottom) 47 | { 48 | int i = 0; 49 | if (mode == 1 || mode == 2) 50 | { 51 | OvDrawTranspartBlackRect(14, 9, 64, 12, 1); 52 | 53 | xsprintf(buf, "Top: %02d.%02d", fps[0] / 10, fps[0] % 10); 54 | OvDrawString(buf, 16, 11, 255, 255, 255); 55 | i = 12; 56 | } 57 | if (mode == 1 || mode == 3) 58 | { 59 | OvDrawTranspartBlackRect(14, 9 + i, 64, 12, 1); 60 | 61 | xsprintf(buf, "Bot: %02d.%02d", fps[0] / 10, fps[0] % 10); 62 | OvDrawString(buf, 16, 11 + i, 255, 255, 255); 63 | } 64 | } 65 | 66 | return (1); 67 | } -------------------------------------------------------------------------------- /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_fps_with_menu/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/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_fps_with_menu/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_fps_with_menu/source/ui.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "ov.h" 3 | 4 | extern u32 IoBasePad; 5 | 6 | void debounceKey() 7 | { 8 | vu32 t; 9 | for (t = 0; t < 0x200000; t++) { 10 | } 11 | } 12 | 13 | void black(int x, int y, int xs, int ys) 14 | { 15 | OvDrawTranspartBlackRect(x, y, xs, ys, 3); 16 | } 17 | 18 | u32 getKeyDebounced(void) 19 | { 20 | u32 key = *(vu32*)(IoBasePad) ^ 0xFFF & 0xFFF; 21 | if (key != 0) 22 | { 23 | debounceKey(); 24 | } 25 | return (key); 26 | } 27 | 28 | s32 showMenu(u8* title, u32 entryCount, u8* captions[], int *selector) 29 | { 30 | u32 maxCaptions = 12; 31 | u32 i; 32 | u8 buf[200]; 33 | u32 pos = 40; 34 | u32 x = 75, key = 0; 35 | u32 drawStart, drawEnd; 36 | int select = *selector; 37 | 38 | 39 | 40 | black(65, 30, 270, 190); 41 | OvDrawString(title, x, pos, 0, 255, 0); 42 | pos += 20; 43 | drawStart = (select / maxCaptions) * maxCaptions; 44 | drawEnd = drawStart + maxCaptions; 45 | 46 | if (drawEnd > entryCount) 47 | { 48 | drawEnd = entryCount; 49 | } 50 | for (i = drawStart; i < drawEnd; i++) 51 | { 52 | strcpy(buf, (i == select) ? "* " : " "); 53 | strcat(buf, captions[i]); 54 | OvDrawString(buf, x, pos, 255, 255, 255); 55 | pos += 12; 56 | } 57 | 58 | key = getKeyDebounced(); 59 | 60 | if (key == BUTTON_DD) 61 | { 62 | *selector += 1; 63 | if (*selector >= entryCount) 64 | { 65 | *selector = 0; 66 | } 67 | } 68 | if (key == BUTTON_DU) 69 | { 70 | *selector -= 1; 71 | if (*selector < 0) { 72 | *selector = entryCount - 1; 73 | } 74 | } 75 | if (key == BUTTON_A) 76 | { 77 | return select; 78 | } 79 | if (key == BUTTON_B) 80 | { 81 | return (-1); 82 | } 83 | 84 | return (-2); 85 | } 86 | 87 | u32 getKey() 88 | { 89 | return (*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF; 90 | } 91 | 92 | void waitKeyRelease(void) 93 | { 94 | while (getKey() != 0); 95 | } 96 | 97 | u32 waitKey() 98 | { 99 | u32 key; 100 | // wait key to be released 101 | while (getKey() != 0); 102 | while (1) { 103 | key = getKey(); 104 | if (key != 0) { 105 | break; 106 | } 107 | } 108 | debounceKey(); 109 | return key; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_fps_with_menu/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/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/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.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/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/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_fps_with_menu/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/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/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_fps_with_menu/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/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/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_fps_with_menu/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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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 | u32 IoBasePad; 8 | 9 | u32 g_slowLevel = 0; 10 | u32 g_percentage = 0; 11 | u32 g_clockScreen = 1; 12 | u32 g_clockType = 0; // 0 = 24 Hour, 1 = 12 Hour 13 | u32 g_clockMode = 2; // 0 = none, 1 = Clock Only, 2 = Clock + Battery, 3 = OnBottom 14 | u32 g_fpsScreen = 0; 15 | u32 g_fpsCounter = 1; // 0 = disabled, 1 = both screen, 2 = top screen only, 3 = bottom screen only 16 | 17 | Result ptmuInit(void); 18 | Result mcuInit(void); 19 | Result APT_CheckNew3DS(bool* out); 20 | int DrawClockAndBattery(int isBottom, u32 percentage, u32 clockType); 21 | int DrawClockOnly(int isBottom, u32 clockType); 22 | int DrawFPSCounter(u32 isBottom); 23 | int DrawFPSCounterBottom(u32 isBottom, int mode); 24 | int OverlayMenu(void); 25 | 26 | /* 27 | Overlay Callback. 28 | isBottom: 1 for bottom screen, 0 for top screen. 29 | addr: writable cached framebuffer virtual address. 30 | addrB: right-eye framebuffer for top screen, undefined for bottom screen. 31 | stride: framebuffer stride(pitch) in bytes, at least 240*bytes_per_pixel. 32 | format: framebuffer format, see https://www.3dbrew.org/wiki/GPU/External_Registers for details. 33 | 34 | 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. 35 | 36 | return 0 when the framebuffer was modified. return 1 when nothing in the framebuffer was modified. 37 | */ 38 | 39 | #define TICKS_PER_SEC 0xFFB3D58 40 | 41 | void SlowMode(void) 42 | { 43 | static u64 lastTick = 0; 44 | 45 | u64 framelimit = TICKS_PER_SEC / g_slowLevel; 46 | 47 | while (svc_getSystemTick() - lastTick < framelimit); 48 | lastTick = svc_getSystemTick(); 49 | } 50 | 51 | u32 OverlayCallback(u32 isBottom, u32 addr, u32 addrB, u32 stride, u32 format) 52 | { 53 | if (!addr) 54 | (1); 55 | // Set settings for draw functions 56 | OvSettings(addr, addrB, stride, format, !isBottom); 57 | 58 | int framebufWasModified = 0; 59 | 60 | // SlowMode ? 61 | if (g_slowLevel != 0) 62 | { 63 | SlowMode(); 64 | } 65 | 66 | // Check for menu 67 | if (!isBottom) 68 | framebufWasModified |= OverlayMenu(); 69 | 70 | if (g_clockMode != 0 && (isBottom == !g_clockScreen)) 71 | { 72 | if (g_clockMode == 1) 73 | framebufWasModified |= DrawClockOnly(isBottom, g_clockType); 74 | else if (g_clockMode == 2) 75 | framebufWasModified |= DrawClockAndBattery(isBottom, g_percentage, g_clockType); 76 | } 77 | 78 | if (g_fpsScreen == 0) 79 | { 80 | if (g_fpsCounter == 1 || (g_fpsCounter == 2 && !isBottom) || (g_fpsCounter == 3 && isBottom)) 81 | framebufWasModified |= DrawFPSCounter(isBottom); 82 | } 83 | else if (g_fpsScreen && g_fpsCounter) 84 | { 85 | framebufWasModified |= DrawFPSCounterBottom(isBottom, g_fpsCounter); 86 | } 87 | 88 | 89 | return (!framebufWasModified); 90 | } 91 | 92 | int main() 93 | { 94 | bool isNew3DS = false; 95 | 96 | initSharedFunc(); 97 | 98 | // Init srv client and ptmu client for monitoring battery status. 99 | initSrv(); 100 | ptmuInit(); 101 | mcuInit(); 102 | 103 | APT_CheckNew3DS(&isNew3DS); 104 | 105 | // Init pad 106 | if (isNew3DS) 107 | IoBasePad = 0xfffc2000; 108 | else 109 | IoBasePad = 0xfffc6000; 110 | 111 | // Register overlay callback. 112 | plgRegisterCallback(CALLBACK_OVERLAY, (void *)OverlayCallback, 0); 113 | 114 | return 0; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /clock_fps_with_menu/source/services.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | #define __datetime_selector (*(vu32*)0x1FF81000) 4 | #define __datetime0 (*(volatile datetime_t*)0x1FF81020) 5 | #define __datetime1 (*(volatile datetime_t*)0x1FF81040) 6 | 7 | #define TICKS_PER_MSEC (268123.480) 8 | 9 | typedef struct { 10 | u64 date_time; 11 | u64 update_tick; 12 | //... 13 | } datetime_t; 14 | 15 | static Handle ptmuHandle; 16 | static Handle mcuHandle; 17 | 18 | Result ptmuInit(void) 19 | { 20 | Result res = srv_getServiceHandle(NULL, &ptmuHandle, "ptm:u"); 21 | return res; 22 | } 23 | 24 | static datetime_t getSysTime(void) { 25 | u32 s1, s2 = __datetime_selector & 1; 26 | datetime_t dt; 27 | 28 | do { 29 | s1 = s2; 30 | if(!s1) 31 | dt = __datetime0; 32 | else 33 | dt = __datetime1; 34 | s2 = __datetime_selector & 1; 35 | } while(s2 != s1); 36 | 37 | return dt; 38 | } 39 | 40 | u64 osGetTime(void) { 41 | datetime_t dt = getSysTime(); 42 | 43 | u64 delta = svc_getSystemTick() - dt.update_tick; 44 | 45 | return dt.date_time + (u64)(((double)(delta))/TICKS_PER_MSEC); 46 | } 47 | 48 | 49 | 50 | static inline u32 IPC_MakeHeader(u16 command_id, unsigned normal_params, unsigned translate_params) 51 | { 52 | return ((u32) command_id << 16) | (((u32) normal_params & 0x3F) << 6) | (((u32) translate_params & 0x3F) << 0); 53 | } 54 | 55 | Result PTMU_GetBatteryLevel(u8 *out) 56 | { 57 | Result ret=0; 58 | u32 *cmdbuf = getThreadCommandBuffer(); 59 | 60 | cmdbuf[0] = IPC_MakeHeader(0x7,0,0); // 0x70000 61 | 62 | if((ret = svc_sendSyncRequest(ptmuHandle)))return ret; 63 | 64 | *out = (u8)cmdbuf[2] & 0xFF; 65 | 66 | return (Result)cmdbuf[1]; 67 | } 68 | 69 | 70 | 71 | static Result aptGetServiceHandle(Handle* aptuHandle) 72 | { 73 | static const char* serviceName; 74 | static const char* const serviceNameTable[3] = {"APT:S", "APT:A", "APT:U"}; 75 | 76 | if (serviceName) 77 | return srv_getServiceHandle(NULL, aptuHandle, (char *)serviceName); 78 | 79 | Result ret; 80 | int i; 81 | for (i = 0; i < 3; i ++) 82 | { 83 | ret = srv_getServiceHandle(NULL, aptuHandle, (char *)serviceNameTable[i]); 84 | if (R_SUCCEEDED(ret)) 85 | { 86 | serviceName = serviceNameTable[i]; 87 | break; 88 | } 89 | } 90 | 91 | return ret; 92 | } 93 | 94 | 95 | static inline int countPrmWords(u32 hdr) 96 | { 97 | return 1 + (hdr&0x3F) + ((hdr>>6)&0x3F); 98 | } 99 | 100 | Result aptSendCommand(u32* aptcmdbuf) 101 | { 102 | Handle aptuHandle; 103 | 104 | Result res = aptGetServiceHandle(&aptuHandle); 105 | if (R_SUCCEEDED(res)) 106 | { 107 | u32* cmdbuf = getThreadCommandBuffer(); 108 | memcpy(cmdbuf, aptcmdbuf, 4*countPrmWords(aptcmdbuf[0])); 109 | res = svc_sendSyncRequest(aptuHandle); 110 | if (R_SUCCEEDED(res)) 111 | { 112 | memcpy(aptcmdbuf, cmdbuf, 4*16);//4*countPrmWords(cmdbuf[0])); // Workaround for Citra failing to emulate response cmdheaders 113 | res = aptcmdbuf[1]; 114 | } 115 | svc_closeHandle(aptuHandle); 116 | } 117 | return res; 118 | } 119 | 120 | static Result APT_CheckNew3DS_System(bool* out) 121 | { 122 | u32 cmdbuf[16]; 123 | cmdbuf[0]=IPC_MakeHeader(0x102,0,0); // 0x1020000 124 | 125 | Result ret = aptSendCommand(cmdbuf); 126 | if (R_SUCCEEDED(ret)) 127 | *out = cmdbuf[2] & 0xFF; 128 | 129 | return ret; 130 | } 131 | 132 | Result APT_CheckNew3DS(bool* out) 133 | { 134 | static bool flagInit, flagValue; 135 | if (!flagInit) 136 | { 137 | *out = false; 138 | Result ret = APT_CheckNew3DS_System(&flagValue); 139 | if (R_FAILED(ret)) return ret; 140 | flagInit = true; 141 | } 142 | 143 | *out = flagValue; 144 | return 0; 145 | } 146 | 147 | 148 | Result mcuInit(void) 149 | { 150 | return (srv_getServiceHandle(NULL, &mcuHandle, "mcu::HWC")); 151 | } 152 | 153 | Result MCU_GetBatteryLevel(u8* out) 154 | { 155 | u32* ipc = getThreadCommandBuffer(); 156 | ipc[0] = IPC_MakeHeader(0x5,0,0); // 0x50000 157 | Result ret = svc_sendSyncRequest(mcuHandle); 158 | if(ret < 0) 159 | return ret; 160 | *out = ipc[2]; 161 | return ipc[1]; 162 | } 163 | -------------------------------------------------------------------------------- /clock_fps_with_menu/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/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_fps_with_menu/source/batteryWidget.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "ov.h" 3 | 4 | 5 | #define SECONDS_IN_DAY 86400 6 | #define SECONDS_IN_HOUR 3600 7 | #define SECONDS_IN_MINUTE 60 8 | 9 | #define TICKS_PER_SEC 0xFFB3D58 10 | #define TICKS_PER_MIN 0x3BEE260A0UL 11 | #define TICKS_IN_5_MIN 0x12BA6BE320UL 12 | 13 | #define ADJ(posX, isBottom) (posX >= 320 - g_clockWidth && isBottom ? posX - 80 : posX) 14 | 15 | u64 osGetTime(void); 16 | Result PTMU_GetBatteryLevel(u8 *out); 17 | Result MCU_GetBatteryLevel(u8* out); 18 | 19 | #define LIMEGREEN 50,205,50 20 | #define ORANGE 255,140,0 21 | #define RED 255,0,0 22 | #define BLANK 255,255,255 23 | 24 | static char * g_speriod[] = { "AM", "PM"}; 25 | 26 | int g_clockWidgetPosX = 338; 27 | int g_clockWidgetPosY = 11; 28 | int g_clockWidth = 0; 29 | 30 | int GetTimeString(char *output, u32 clockType) 31 | { 32 | u64 timeInSeconds = osGetTime() / 1000; 33 | u64 dayTime = timeInSeconds % SECONDS_IN_DAY; 34 | 35 | u8 hour = dayTime / SECONDS_IN_HOUR; 36 | u8 min = (dayTime % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE; 37 | u8 seconds = dayTime % SECONDS_IN_MINUTE; 38 | 39 | int period = 0; 40 | 41 | if (clockType == 1) 42 | { 43 | // Handle AM/PM 44 | if (hour == 0 || hour >= 12) 45 | { 46 | period = 1; 47 | } 48 | 49 | // 12 Hour Clock because 'merica 50 | if (hour==0) 51 | { 52 | hour = 12; 53 | } 54 | else if (hour > 12) 55 | { 56 | hour = hour - 12; 57 | } 58 | } 59 | 60 | xsprintf(output, "%02d:%02d", hour, min); 61 | 62 | return (period); 63 | 64 | } 65 | 66 | int DrawClockAndBattery(int isBottom, u32 percent, u32 clockType) 67 | { 68 | static u32 batval = 0; 69 | static u8 batPercent = 0; 70 | static u64 tick = 0; 71 | 72 | if (svc_getSystemTick() >= tick) 73 | { 74 | u8 batteryLevel = 0; 75 | PTMU_GetBatteryLevel(&batteryLevel); 76 | MCU_GetBatteryLevel(&batPercent); 77 | tick = svc_getSystemTick() + TICKS_IN_5_MIN; 78 | 79 | if (batteryLevel == 1) 80 | { 81 | batval = 2; 82 | } 83 | else if (batteryLevel == 2) 84 | { 85 | batval = 5; 86 | } 87 | else if (batteryLevel == 3) 88 | { 89 | batval = 8; 90 | } 91 | else if (batteryLevel == 4) 92 | { 93 | batval = 11; 94 | } 95 | else if (batteryLevel == 5) 96 | { 97 | batval = 16; 98 | } 99 | } 100 | 101 | char buf[30] = {0}; 102 | 103 | u32 xPos = g_clockWidgetPosX; 104 | u32 batteryX = xPos; 105 | u32 width = g_clockWidth = 57; 106 | u32 posY = g_clockWidgetPosY; 107 | 108 | // If it is a 12 hour clock, adjust things slightly 109 | if (clockType == 1) 110 | { 111 | xPos = g_clockWidgetPosX - 12; 112 | width = g_clockWidth = 69; 113 | } 114 | 115 | //DrawBackground 116 | OvDrawTranspartBlackRect(ADJ(xPos, isBottom), posY - 2, width, 12, 1); 117 | xPos += 3; 118 | 119 | // Draw battery 120 | OvDrawRect(ADJ(batteryX + 36, isBottom), posY, 18, 1, BLANK); 121 | OvDrawRect(ADJ(batteryX + 36, isBottom), posY + 7, 18, 1, BLANK); 122 | OvDrawRect(ADJ(batteryX + 36, isBottom), posY, 1, 8, BLANK); 123 | OvDrawRect(ADJ(batteryX + 53, isBottom), posY, 1, 8, BLANK); 124 | 125 | if (batval >= 11) 126 | OvDrawRect(ADJ(batteryX + 37, isBottom), posY + 1, batval, 6, LIMEGREEN); 127 | else if (batval >= 5 && batval <= 8) 128 | OvDrawRect(ADJ(batteryX + 37, isBottom), posY + 1, batval, 6, ORANGE); 129 | 130 | else 131 | OvDrawRect(ADJ(batteryX + 37, isBottom), posY + 1, batval, 6, RED); 132 | 133 | OvDrawRect(ADJ(batteryX + 54, isBottom), posY + 2, 1, 4, BLANK); 134 | 135 | if (percent) 136 | { 137 | xsprintf(buf, "%d%%", batPercent); 138 | int percentageX = ADJ(batteryX + 43, isBottom); 139 | int len = strlen(buf) - 1; 140 | percentageX -= (len) * 2; 141 | OvDrawStringTiny(buf, percentageX, posY + 1, BLANK); 142 | } 143 | 144 | 145 | 146 | // Draw clock 147 | int period = GetTimeString(buf, clockType); 148 | OvDrawString(buf, ADJ(xPos, isBottom), posY, BLANK); 149 | xPos += 31; 150 | if (clockType == 1) 151 | OvDrawString(g_speriod[period], ADJ(xPos, isBottom), posY, BLANK); 152 | 153 | return (1); 154 | } 155 | 156 | int DrawClockOnly(int isBottom, u32 clockType) 157 | { 158 | 159 | char buf[30] = {0}; 160 | 161 | int period = GetTimeString(buf, clockType); 162 | 163 | u32 xPos = g_clockWidgetPosX - 14; 164 | u32 width = g_clockWidth = 33; 165 | u32 posY = g_clockWidgetPosY; 166 | 167 | // If it is a 12 hour clock, adjust things slightly 168 | if ( clockType == 1 ) 169 | { 170 | xPos = g_clockWidgetPosX + 1; 171 | width = g_clockWidth = 46; 172 | } 173 | 174 | //DrawBackground 175 | OvDrawTranspartBlackRect(ADJ(xPos, isBottom), posY - 2, width, 12, 1); 176 | // Draw clock 177 | OvDrawString(buf, ADJ(xPos + 2, isBottom), posY, 255, 255, 255); 178 | if (clockType == 1) 179 | OvDrawString(g_speriod[period], ADJ(xPos + 33, isBottom), posY, BLANK); 180 | return (1); 181 | } 182 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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_fps_with_menu/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_fps_with_menu/source/ov.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "font_mini_4x6.h" 3 | #include "font6x10Linux.h" 4 | #include "ov.h" 5 | 6 | static u32 g_lframebuf; 7 | static u32 g_rframebuf; 8 | static u32 g_stride; 9 | static u32 g_format; 10 | static u32 g_isTop; 11 | static u32 g_maxWidth; 12 | static u32 g_is3DEnabled; 13 | 14 | void OvSettings(u32 addr, u32 addrB, u32 stride, u32 format, int isTop) 15 | { 16 | g_lframebuf = addr; 17 | g_rframebuf = addrB; 18 | g_stride = stride; 19 | g_format = format & 0xF; 20 | g_isTop = isTop; 21 | g_maxWidth = isTop ? 400 : 320; 22 | g_is3DEnabled = *(float *)(0x1FF81080) > 0.f && isTop && addr != addrB && addrB; 23 | } 24 | 25 | void OvDrawTranspartBlackRect(int posX, int posY, int width, int height, u8 level) 26 | { 27 | static int mode3D = 0; 28 | 29 | if (g_is3DEnabled && mode3D == 0) 30 | { 31 | mode3D = 1; 32 | OvDrawTranspartBlackRect(posX - 5, posY, width, height, level); 33 | mode3D = 0; 34 | } 35 | 36 | u32 addr = mode3D ? g_rframebuf : g_lframebuf; 37 | 38 | for (int posC = posX; posC < posX + width; posC++) 39 | { 40 | if (g_format == 2) 41 | { 42 | u16* sp = (u16*)(addr + g_stride * posC + 240 * 2 - 2 * (posY + height - 1)); 43 | u16* spEnd = sp + height; 44 | while (sp < spEnd) 45 | { 46 | u16 pix = *sp; 47 | u16 r = (pix >> 11) & 0x1f; 48 | u16 g = (pix >> 5) & 0x3f; 49 | u16 b = (pix & 0x1f); 50 | pix = ((r >> level) << 11) | ((g >> level) << 5) | (b >> level); 51 | *sp = pix; 52 | sp++; 53 | } 54 | } 55 | else if (g_format == 1) 56 | { 57 | u8* sp = (u8*)(addr + g_stride * posC + 240 * 3 - 3 * (posY + height - 1)); 58 | u8* spEnd = sp + 3 * height; 59 | while (sp < spEnd) 60 | { 61 | sp[0] >>= level; 62 | sp[1] >>= level; 63 | sp[2] >>= level; 64 | sp += 3; 65 | } 66 | } 67 | } 68 | } 69 | 70 | static inline void OvDrawPixel(u32 addr, int posX, int posY, u32 r, u32 g, u32 b) 71 | { 72 | if (g_format == 2) 73 | { 74 | u16 pix = ((r ) << 11) | ((g ) << 5) | (b ); 75 | *(u16*)(addr + g_stride * posX + 240 * 2 -2 * posY) = pix; 76 | } 77 | else 78 | { 79 | u8* sp = (u8*)(addr + g_stride * posX + 240 * 3 - 3 * posY); 80 | sp[0] = b; 81 | sp[1] = g; 82 | sp[2] = r; 83 | } 84 | } 85 | 86 | void OvDrawRect(int posX, int posY, int width, int height, u32 r, u32 g, u32 b) 87 | { 88 | static int mode3D = 0; 89 | 90 | if (g_is3DEnabled && mode3D == 0) 91 | { 92 | mode3D = 1; 93 | OvDrawRect(posX - 5, posY, width, height, r, g, b); 94 | mode3D = 0; 95 | } 96 | 97 | u32 addr = mode3D ? g_rframebuf : g_lframebuf; 98 | 99 | for (int x = posX; x < posX + width; x++) 100 | { 101 | for (int y = posY; y < posY + height; y++) 102 | { 103 | OvDrawPixel(addr, x, y, r, g, b); 104 | } 105 | } 106 | } 107 | 108 | void OvDrawChar(char letter, int posX, int posY, u32 r, u32 g, u32 b) 109 | { 110 | 111 | static int mode3D = 0; 112 | 113 | if (g_is3DEnabled && mode3D == 0) 114 | { 115 | mode3D = 1; 116 | OvDrawChar(letter, posX - 5, posY, r, g, b); 117 | mode3D = 0; 118 | } 119 | 120 | u32 addr = mode3D ? g_rframebuf : g_lframebuf; 121 | 122 | if ((letter < 32) || (letter > 127)) 123 | { 124 | letter = '?'; 125 | } 126 | 127 | int c = letter * 10; 128 | 129 | for (int y = 0; y < 10; y++) 130 | { 131 | u8 l = font[y + c]; 132 | int xx = posX; 133 | for (int x = 6; x > 0; x--, xx++) 134 | { 135 | if ((l >> x) & 1) 136 | OvDrawPixel(addr, xx, posY + y, r, g, b); 137 | } 138 | } 139 | } 140 | 141 | int OvDrawString(char *str, int posX, int posY, u32 r, u32 g, u32 b) 142 | { 143 | while(*str) 144 | { 145 | if ((posY + 6 > 240) || (posX + 6 > g_maxWidth)) 146 | { 147 | return (posY + 12); 148 | } 149 | 150 | OvDrawChar(*str, posX, posY, r, g, b); 151 | str++; 152 | posX += 6; 153 | } 154 | return (posY + 12); 155 | } 156 | 157 | void OvDrawCharTiny(char letter, int posX, int posY, u32 r, u32 g, u32 b) 158 | { 159 | 160 | static int mode3D = 0; 161 | 162 | if (g_is3DEnabled && mode3D == 0) 163 | { 164 | mode3D = 1; 165 | OvDrawCharTiny(letter, posX - 5, posY, r, g, b); 166 | mode3D = 0; 167 | } 168 | 169 | u32 addr = mode3D ? g_rframebuf : g_lframebuf; 170 | 171 | if ((letter < 32) || (letter > 127)) 172 | { 173 | letter = '?'; 174 | } 175 | 176 | int c = (letter) * 6; 177 | 178 | for (int y = 0; y < 6; y++) 179 | { 180 | u8 l = fontdata_mini_4x6[y + c]; 181 | int xx = posX; 182 | for (int x = 3; x >= 0; x--, xx++) 183 | { 184 | if ((l >> x) & 1) 185 | OvDrawPixel(addr, xx, posY + y, r, g, b); 186 | } 187 | } 188 | } 189 | 190 | int OvDrawStringTiny(char *str, int posX, int posY, u32 r, u32 g, u32 b) 191 | { 192 | while(*str) 193 | { 194 | if ((posY + 4 > 240) || (posX + 4 > g_maxWidth)) 195 | { 196 | return (posY + 6); 197 | } 198 | 199 | OvDrawCharTiny(*str, posX, posY, r, g, b); 200 | str++; 201 | posX += 4; 202 | } 203 | return (posY + 6); 204 | } 205 | -------------------------------------------------------------------------------- /clock_fps_with_menu/source/OverlayMenu.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "ov.h" 3 | 4 | #define LIMEGREEN 50,205,50 5 | #define ORANGE 255,140,0 6 | #define RED 255,0,0 7 | #define GREEN 0,255,0 8 | #define BLANK 255,255,255 9 | 10 | static u8 *menuEntries[12] = 11 | { 12 | "Disable Clock", 13 | "Display Clock only", 14 | "Display Clock + Battery", 15 | "12 Hour Clock", 16 | "Enable/Disable Battery percentage", 17 | "Change Clock widget's screen", 18 | "Move the Clock widget on the screen", 19 | "Disable FPS Counter", 20 | "Display FPS of both screens", 21 | "Display FPS of Top Screen", 22 | "Display FPS of Bottom Screen", 23 | "Display FPS on Bottom screen" 24 | }; 25 | 26 | static u8 *menuSlowMode[6] = 27 | { 28 | "Disable", 29 | "Slow Mode Level 1", 30 | "Slow Mode Level 2", 31 | "Slow Mode Level 3", 32 | "Slow Mode Level 4", 33 | "Slow Mode Level 5" 34 | }; 35 | 36 | extern int g_clockWidgetPosX; 37 | extern int g_clockWidgetPosY; 38 | extern int g_clockWidth; 39 | 40 | extern u32 g_slowLevel; 41 | extern u32 g_percentage; 42 | extern u32 g_clockScreen; 43 | extern u32 g_clockType; // 0 = 24 Hour, 1 = 12 Hour 44 | extern u32 g_clockMode; // 0 = none, 1 = Clock Only, 2 = Clock + Battery 45 | extern u32 g_fpsScreen; 46 | extern u32 g_fpsCounter; // 0 = disabled, 1 = both screen, 2 = top screen only, 3 = bottom screen only 47 | 48 | u32 getKeyDebounced(void); 49 | void black(int x, int y, int xs, int ys); 50 | 51 | int ClockMoveMenu(void) 52 | { 53 | static int isChanging = 0; 54 | static u32 widgetPosX = 0; 55 | static u32 widgetPosY = 0; 56 | 57 | u32 key = getKeyDebounced(); 58 | u32 posX = 75; 59 | u32 posY = 40; 60 | 61 | if (isChanging == 0) 62 | { 63 | if (key & BUTTON_A) 64 | return (0); 65 | widgetPosX = g_clockWidgetPosX; 66 | widgetPosY = g_clockWidgetPosY; 67 | isChanging = 1; 68 | } 69 | 70 | // Draw "menu" 71 | 72 | // Background 73 | black(65, 30, 270, 180); 74 | // Title 75 | posY = OvDrawString("Widget location", posX, posY, GREEN); 76 | posY += 12; 77 | posX += 12; 78 | // Content 79 | posY = OvDrawString("Use DPAD to move the widget", posX, posY, BLANK); 80 | posY = OvDrawString("Use L to move faster", posX, posY, BLANK); 81 | posY = OvDrawString("Use A to apply the change", posX, posY, BLANK); 82 | posY = OvDrawString("Use B to cancel", posX, posY, BLANK); 83 | 84 | if (key == BUTTON_B) 85 | { 86 | isChanging = 0; 87 | g_clockWidgetPosX = widgetPosX; 88 | g_clockWidgetPosY = widgetPosY; 89 | return (-1); 90 | } 91 | 92 | if (key == BUTTON_A) 93 | { 94 | isChanging = 0; 95 | return (-1); 96 | } 97 | 98 | if (key & BUTTON_L) 99 | { 100 | if (key & BUTTON_DL) 101 | g_clockWidgetPosX -= 10; 102 | if (key & BUTTON_DR) 103 | g_clockWidgetPosX += 10; 104 | if (key & BUTTON_DU) 105 | g_clockWidgetPosY -= 10; 106 | if (key & BUTTON_DD) 107 | g_clockWidgetPosY += 10; 108 | } 109 | else 110 | { 111 | if (key & BUTTON_DL) 112 | g_clockWidgetPosX--; 113 | if (key & BUTTON_DR) 114 | g_clockWidgetPosX++; 115 | if (key & BUTTON_DU) 116 | g_clockWidgetPosY--; 117 | if (key & BUTTON_DD) 118 | g_clockWidgetPosY++; 119 | } 120 | 121 | if (g_clockWidgetPosY - 2 < 0) 122 | g_clockWidgetPosY = 2; 123 | if (g_clockWidgetPosY > 230) 124 | g_clockWidgetPosY = 230; 125 | 126 | if (g_clockWidgetPosX < 0) 127 | g_clockWidgetPosX = 0; 128 | if (g_clockWidgetPosX + g_clockWidth > 400) 129 | g_clockWidgetPosX = 400 - g_clockWidth; 130 | return (0); 131 | } 132 | 133 | int OverlayMenu(void) 134 | { 135 | static int displayMenu = 0; 136 | static int selector = 0; 137 | static int mode = 0; 138 | 139 | u8 buf[200]; 140 | int res = 0; 141 | 142 | u32 key = getKey(); 143 | if (key == (BUTTON_L | BUTTON_X | BUTTON_Y)) 144 | { 145 | waitKeyRelease(); 146 | displayMenu = 1; 147 | } 148 | 149 | if (!displayMenu) 150 | return (0); 151 | 152 | int posX = 95; 153 | int posY = 205; 154 | 155 | if (displayMenu && key == BUTTON_R) 156 | { 157 | mode = !mode; 158 | selector = 0; 159 | for (int i = 0x200000; i > 0; i--); 160 | } 161 | 162 | // Normal mode 163 | if (mode == 0) 164 | { 165 | res = showMenu("Overlay Tools Menu", 12, menuEntries, &selector); 166 | if (res >= 0 && res <= 2) 167 | g_clockMode = res; 168 | else if (res == 3) 169 | g_clockType = !g_clockType; 170 | else if (res == 4) 171 | g_percentage = !g_percentage; 172 | else if (res == 5) 173 | g_clockScreen = !g_clockScreen; 174 | else if (res == 6) 175 | mode = 2; 176 | else if (res >= 7 && res <= 10) 177 | g_fpsCounter = res - 7; 178 | else if (res == 11) 179 | g_fpsScreen = !g_fpsScreen; 180 | 181 | OvDrawString("Press R to open Slow Mode Menu", posX, posY, 0, 0, 255); 182 | } 183 | else if (mode == 2) 184 | { 185 | res = ClockMoveMenu(); 186 | if (res == -1) 187 | mode = 0; 188 | } 189 | // Slow down mode 190 | else 191 | { 192 | res = showMenu("Slow Mode Menu", 6, menuSlowMode, &selector); 193 | 194 | if (res == 0) g_slowLevel = 0; 195 | else if (res == 1) g_slowLevel = 30; 196 | else if (res == 2) g_slowLevel = 20; 197 | else if (res == 3) g_slowLevel = 15; 198 | else if (res == 4) g_slowLevel = 10; 199 | else if (res == 5) g_slowLevel = 5; 200 | 201 | OvDrawString("Press R to open Overlay Tools Menu", posX, posY, 0, 0, 255); 202 | } 203 | 204 | 205 | if (res == -1) 206 | { 207 | displayMenu = 0; 208 | } 209 | return (1); 210 | } 211 | --------------------------------------------------------------------------------