├── .github └── workflows │ └── deploy_pages.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── README_kr.md ├── Source ├── Atmosphere │ └── stratosphere │ │ └── loader │ │ └── source │ │ ├── oc │ │ ├── Makefile │ │ ├── customize.cpp │ │ ├── customize.hpp │ │ ├── mtc_timing_table.hpp │ │ ├── mtc_timing_value.hpp │ │ ├── oc_common.hpp │ │ ├── oc_loader.hpp │ │ ├── oc_test.cpp │ │ ├── oc_test.hpp │ │ ├── pcv │ │ │ ├── pcv.cpp │ │ │ ├── pcv.hpp │ │ │ ├── pcv_common.hpp │ │ │ ├── pcv_erista.cpp │ │ │ └── pcv_mariko.cpp │ │ └── ptm │ │ │ ├── ptm.cpp │ │ │ └── ptm.hpp │ │ └── patch.py ├── MemTesterNX │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ └── source │ │ ├── main.c │ │ ├── memtester.h │ │ ├── sizes.h │ │ ├── tests.c │ │ ├── tests.h │ │ └── types.h ├── ReverseNX-RT.diff(deprecated) ├── TinyMemBenchNX │ ├── .gitignore │ ├── LICENSE.txt │ ├── Makefile │ ├── readme.txt │ └── source │ │ ├── aarch64-asm.h │ │ ├── aarch64-asm.s │ │ └── main.c ├── clkrst_query.cpp ├── sys-clk-OC(deprecated) │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── build.sh │ ├── common │ │ ├── include │ │ │ ├── cpp_util.hpp │ │ │ ├── sysclk.h │ │ │ └── sysclk │ │ │ │ ├── apm.h │ │ │ │ ├── client │ │ │ │ ├── ipc.h │ │ │ │ └── types.h │ │ │ │ ├── clocks.h │ │ │ │ ├── config.h │ │ │ │ ├── errors.h │ │ │ │ ├── i2c.h │ │ │ │ ├── ipc.h │ │ │ │ └── psm_ext.h │ │ └── src │ │ │ ├── apm_profile_table.c │ │ │ ├── client │ │ │ └── ipc.c │ │ │ ├── i2c.c │ │ │ └── psm_ext.c │ ├── config.ini.template │ ├── overlay │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── lib │ │ │ └── tesla │ │ │ │ ├── .github │ │ │ │ └── FUNDING.yml │ │ │ │ ├── .gitignore │ │ │ │ ├── .gitrepo │ │ │ │ ├── LICENSE │ │ │ │ ├── README.md │ │ │ │ ├── example │ │ │ │ ├── Makefile │ │ │ │ └── source │ │ │ │ │ └── main.cpp │ │ │ │ └── include │ │ │ │ ├── stb_truetype.h │ │ │ │ └── tesla.hpp │ │ ├── scripts │ │ │ └── make_logo.sh │ │ └── src │ │ │ ├── ipc.h │ │ │ ├── main.cpp │ │ │ └── ui │ │ │ ├── elements │ │ │ └── base_frame.h │ │ │ ├── format.h │ │ │ ├── gui │ │ │ ├── app_profile_gui.cpp │ │ │ ├── app_profile_gui.h │ │ │ ├── base_gui.cpp │ │ │ ├── base_gui.h │ │ │ ├── base_menu_gui.cpp │ │ │ ├── base_menu_gui.h │ │ │ ├── fatal_gui.cpp │ │ │ ├── fatal_gui.h │ │ │ ├── freq_choice_gui.cpp │ │ │ ├── freq_choice_gui.h │ │ │ ├── global_override_gui.cpp │ │ │ ├── global_override_gui.h │ │ │ ├── main_gui.cpp │ │ │ ├── main_gui.h │ │ │ ├── misc_gui.cpp │ │ │ └── misc_gui.h │ │ │ └── style.h │ └── sysmodule │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── lib │ │ ├── minIni │ │ │ ├── .gitignore │ │ │ ├── .gitrepo │ │ │ ├── LICENSE │ │ │ ├── Makefile │ │ │ ├── NOTICE │ │ │ ├── README.md │ │ │ ├── dev │ │ │ │ ├── minGlue-FatFs.h │ │ │ │ ├── minGlue-ccs.h │ │ │ │ ├── minGlue-efsl.h │ │ │ │ ├── minGlue-ffs.h │ │ │ │ ├── minGlue-mdd.h │ │ │ │ ├── minGlue-stdio.h │ │ │ │ ├── minGlue.h │ │ │ │ ├── minIni.c │ │ │ │ ├── minIni.h │ │ │ │ ├── test.c │ │ │ │ ├── test.ini │ │ │ │ ├── test2.cc │ │ │ │ ├── testplain.ini │ │ │ │ └── wxMinIni.h │ │ │ ├── doc │ │ │ │ └── minIni.pdf │ │ │ └── include │ │ │ │ └── minIni.h │ │ └── nxExt │ │ │ ├── .gitignore │ │ │ ├── Makefile │ │ │ ├── include │ │ │ ├── nxExt.h │ │ │ └── nxExt │ │ │ │ ├── apm_ext.h │ │ │ │ ├── cpp │ │ │ │ └── lockable_mutex.h │ │ │ │ └── ipc_server.h │ │ │ └── src │ │ │ ├── apm_ext.c │ │ │ └── ipc_server.c │ │ ├── perms.json │ │ └── src │ │ ├── clock_manager.cpp │ │ ├── clock_manager.h │ │ ├── clocks.cpp │ │ ├── clocks.h │ │ ├── config.cpp │ │ ├── config.h │ │ ├── errors.cpp │ │ ├── errors.h │ │ ├── file_utils.cpp │ │ ├── file_utils.h │ │ ├── ipc_service.cpp │ │ ├── ipc_service.h │ │ ├── main.cpp │ │ ├── oc_extra.cpp │ │ ├── oc_extra.h │ │ ├── process_management.cpp │ │ └── process_management.h └── sys-clk-OC │ └── README.md ├── gpu_volt.py ├── pages ├── build.sh ├── dist │ ├── index.html │ └── main.js └── src │ ├── index.html │ └── main.ts ├── system_settings.md ├── system_settings_parser.py └── test_patch.sh /.github/workflows/deploy_pages.yml: -------------------------------------------------------------------------------- 1 | # Simple workflow for deploying static content to GitHub Pages 2 | name: Deploy static content to Pages 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["master"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow one concurrent deployment 19 | concurrency: 20 | group: "pages" 21 | cancel-in-progress: true 22 | 23 | jobs: 24 | # Single deploy job since we're just deploying 25 | deploy: 26 | environment: 27 | name: github-pages 28 | url: ${{ steps.deployment.outputs.page_url }} 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v3 33 | - name: Setup Pages 34 | uses: actions/configure-pages@v2 35 | - name: Upload artifact 36 | uses: actions/upload-pages-artifact@v1 37 | with: 38 | # Upload entire repository 39 | path: './pages/dist' 40 | - name: Deploy to GitHub Pages 41 | id: deployment 42 | uses: actions/deploy-pages@v1 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | .vscode/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanai3Bi/Switch-OC-Suite/822556e6e4e627e5b9a444a934a82cc7f4a48db2/.gitmodules -------------------------------------------------------------------------------- /README_kr.md: -------------------------------------------------------------------------------- 1 | # Switch OC Suite 2 | 3 | [![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) 4 | [![Downloads](https://img.shields.io/github/downloads/hanai3Bi/Switch-OC-Suite/total)](https://github.com/hanai3Bi/Switch-OC-Suite/releases) 5 | 6 | 이 프로젝트는 매우 위험하며 콘솔을 손상시킬 수 있습니다. 따라서 이 프로젝트를 사용하는걸 권장하지 않습니다. 사용할 경우 모든 책임은 본인에게 있습니다. 7 | 8 | 닌텐도 스위치 Atmosphere 커스텀 펌웨어 용 오버클럭 스위트 9 | 10 | [프로젝트 홈페이지](https://hanai3Bi.github.io/Switch-OC-Suite) 11 | 12 | **주의 사항: 사용시 모든 책임은 본인에게 있습니다!** 13 | 14 | - 일반적으로 오버클럭 시 일부 하드웨어 구성 요소들의 수명이 단축됩니다. sys-clk-oc 에서 안전하지 않은 주파수 활성화 시 **문제나 고장에 대한 모든 책임은 본인에게 있습니다** . 제한 해제에 관한 이슈 등은 무시되거나 답글 없이 닫힐 수 있습니다. 15 | 16 | - HorizonOS 의 구조 때문에, 안전하지 않은 RAM 주파수는 파일시스템 손상을 일으킬 수 있습니다. **메모리 오버클럭을 하기 전 반드시 백업을 하세요** 17 | 18 | ## 기능 19 | 20 | - 구형 스위치 (HAC-001) 21 | - CPU / GPU 오버클럭 (안전한 클럭: 1785 / 921 MHz) 22 | - 안전하지 않은 클럭 23 | - 보드 전력 소모 한계나 전원부 IC 때문 24 | - 2091 / 998 MHz 까지 클럭 해제 가능 25 | - [README for sys-clk-OC](https://github.com/hanai3Bi/Switch-OC-Suite/blob/master/Source/sys-clk-OC/README.md) 참조 26 | 27 | - 메모리 오버클럭 (안전한 클럭: 1862.4 MHz) 28 | 29 | - 신형 스위치 (HAC-001-01, HDH-001, HEG-001) 30 | - CPU / GPU 오버클럭 (안전한 클럭: 1963 / 998 MHz) 31 | - 안전하지 않은 클럭 32 | - 보드 전력 소모 한계나 전원부 IC 때문 33 | - 2295 / 1267 MHz 까지 클럭 해제 가능 34 | - [README for sys-clk-OC](https://github.com/hanai3Bi/Switch-OC-Suite/blob/master/Source/sys-clk-OC/README.md) 참조 35 | 36 | - 메모리 오버클럭 (안전한 클럭: 1996.8 MHz) 37 | 38 | - 수정된 sys-clk 와 ReverseNX-RT 39 | - 자동 CPU 부스트 40 | - 게임 로딩 속도 향상 목적 41 | - CPU 코어#3 (시스템 코어)가 과부하시 CPU 부스트 (1785 MHz) 활성화 (주로 I/O 작업). 42 | - 충전기 연결시나 거버너 활성화 했을때만 가능 43 | - 이 기능은 구형 스위치에서, 특히 높은 GPU 주파수나 거버너랑 같이 사용시, 안전하지 않음. 44 | 45 | - CPU & GPU 주파수 거버너 (실험적 기능) 46 | - 부하에 따라 주파수를 조정함. 전력 소비를 줄일 수 있지만 렉을 유발할 수 있음. 타이틀 별로 끌 수 있음. 47 | - 신형 스위치에서 프로필의 CPU 주파수를 1020Mhz 보다 높은 값으로 설정 시, 최소 스케일링 주파수는 1020Mhz로 설정됨. 48 | - 충전 전류 (100 mA - 2000 mA) 와 충전 제한 (20% - 100%) 설정 49 | - 충전 제한을 장기간 사용시 배터리 수치가 부정확해 질 수 있음. 완충, 완방 시 재보정에 도움이 될 수 있음. 또는 [battery_desync_fix_nx](https://github.com/CTCaer/battery_desync_fix_nx) 를 사용. 50 | 51 | - 글로벌 프로필 52 | - 더미 타이틀 아이디 지정 `0xA111111111111111`. 53 | - 우선 순위: "Temp overrides" > "Application profile" > "Global profile" > "System default". 54 | 55 | - ReverseNX 모드 동기화 56 | - ReverseNX (-RT) 에서 모드 변경 후 클럭 변경 불필요 57 | 58 | - **[System Settings (옵션)](https://github.com/hanai3Bi/Switch-OC-Suite/blob/master/system_settings.md)** 59 | 60 | 61 | ## 설치 방법 62 | 63 | 1. 최신 [릴리즈](https://github.com/hanai3Bi/Switch-OC-Suite/releases) 파일을 다운로드 한다. 64 | 65 | 2. `SdOut` 폴더 안의 모든 파일들을 SD카드의 최상단에 복사한다. 66 | 67 | 3. Atmosphere 버전에 맞는 `x.x.x_loader.kip` 파일을 `loader.kip` 으로 이름을 변경한 후, `/atmosphere/kips/` 로 이동 시킨다. 68 | 69 | 4. 맞춤 설정 [온라인 loader configurator](https://hanai3Bi.github.io/Switch-OC-Suite/#config): 70 |
71 | 72 | | Defaults | Mariko | Erista | 73 | | ---------- | ------------- | ------------- | 74 | | CPU OC | 2295 MHz Max | 2091 MHz Max | 75 | | CPU Boost | 1785 MHz | N/A | 76 | | CPU Volt | 1235 mV Max | 1235 mV Max | 77 | | GPU OC | 1267 MHz Max | N/A | 78 | | RAM OC | 1996 MHz Max | 1862 MHz Max | 79 | | RAM Volt | Disabled | Disabled | 80 | | RAM Timing | Auto-Adjusted | Auto-Adjusted | 81 | | CPU UV | Disabled | N/A | 82 | | GPU UV | Disabled | N/A | 83 | 84 |
85 | 86 | 5. Hekate 부트로더 전용 87 | - `bootloader/hekate_ipl.ini`을 연 후, boot entry 항목에 `kip1=atmosphere/kips/loader.kip` 를 추가한다. 88 | 89 | ## AIO 를 통해 업데이트 하기 90 | 91 | 1. custom_packs.json 파일을 다운로드 한 후 /config/aio-switch-updater/custom_packs.json 에 복사한다. 92 | 93 | 2. AIO Switch Updater 를 실행한 후 커스텀 다운로드 탭으로 이동한다. 94 | 95 | 3. Switch-OC-Suite 를 선택한 후 계속하기를 누른다. 96 | 97 | 98 | ## 빌드 방법 99 | 100 |
101 | 102 | Grab necessary patches from the repo, then compile sys-clk, ReverseNX-RT and Atmosphere loader with devkitpro. 103 | 104 | Before compiling Atmosphere loader, run `patch.py` in `Atmosphere/stratosphere/loader/source/` to insert oc module into loader sysmodule. 105 | 106 | When compilation is done, uncompress the kip to make it work with configurator: `hactool -t kip1 Atmosphere/stratosphere/loader/out/nintendo_nx_arm64_armv8a/release/loader.kip --uncompress=./loader.kip` 107 | 108 |
109 | 110 | 111 | ## 크레딧 112 | 113 | - CTCaer for [Hekate-ipl](https://github.com/CTCaer/hekate) bootloader, RE and hardware research 114 | - [devkitPro](https://devkitpro.org/) for All-In-One homebrew toolchains 115 | - masagrator for [ReverseNX-RT](https://github.com/masagrator/ReverseNX-RT) and info on BatteryChargeInfoFields in psm module 116 | - Nvidia for [Tegra X1 Technical Reference Manual](https://developer.nvidia.com/embedded/dlc/tegra-x1-technical-reference-manual) 117 | - RetroNX team for [sys-clk](https://github.com/retronx-team/sys-clk) 118 | - SciresM and Reswitched Team for the state-of-the-art [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) CFW of Switch 119 | - Switchbrew [wiki](http://switchbrew.org/wiki/) for Switch in-depth info 120 | - Switchroot for their [modified L4T kernel and device tree](https://gitlab.com/switchroot/kernel) 121 | - ZatchyCatGames for RE and original OC loader patches for Atmosphere 122 | - KazushiMe for [Switch-OC-Suite](https://github.com/KazushiMe/Switch-OC-Suite) 123 | -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/Makefile: -------------------------------------------------------------------------------- 1 | TARGET_EXEC := test 2 | 3 | BUILD_DIR := ./build 4 | SRC_DIRS := ./ 5 | 6 | # CXX := clang++ g++-12 7 | 8 | # Find all the C and C++ files we want to compile 9 | # Note the single quotes around the * expressions. Make will incorrectly expand these otherwise. 10 | SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s') 11 | 12 | # String substitution for every C/C++ file. 13 | # As an example, hello.cpp turns into ./build/hello.cpp.o 14 | OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) 15 | 16 | # String substitution (suffix version without %). 17 | # As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d 18 | DEPS := $(OBJS:.o=.d) 19 | 20 | # Every folder in ./src will need to be passed to GCC so that it can find header files 21 | INC_DIRS := $(shell find $(SRC_DIRS) -type d) 22 | # Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag 23 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) 24 | 25 | CPPFLAGS := $(INC_FLAGS) -Wall -Werror -Wno-unused-result -std=c++20 -Og -g 26 | 27 | # The final build step. 28 | $(TARGET_EXEC): $(OBJS) 29 | @echo "Linking $@" 30 | @$(CXX) $(OBJS) -o $@ $(LDFLAGS) 31 | 32 | # Build step for C source 33 | $(BUILD_DIR)/%.c.o: %.c 34 | @mkdir -p $(dir $@) 35 | @echo "$<" 36 | @$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 37 | 38 | # Build step for C++ source 39 | $(BUILD_DIR)/%.cpp.o: %.cpp 40 | @mkdir -p $(dir $@) 41 | @echo "$<" 42 | @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ 43 | 44 | .PHONY: clean 45 | clean: 46 | @rm -r $(BUILD_DIR) $(TARGET_EXEC) 47 | 48 | # Include the .d makefiles. The - at the front suppresses the errors of missing 49 | # Makefiles. Initially, all the .d files will be missing, and we don't want those 50 | # errors to show up. 51 | -include $(DEPS) -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/customize.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * Copyright (c) 2023 hanai3Bi 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #define CUST_REV 11 22 | 23 | #include "oc_common.hpp" 24 | #include "pcv/pcv_common.hpp" 25 | 26 | namespace ams::ldr::oc { 27 | 28 | #include "mtc_timing_table.hpp" 29 | 30 | enum MtcConfig: u32 { 31 | AUTO_ADJ_ALL = 0, 32 | CUSTOM_ADJ_ALL = 1, 33 | NO_ADJ_ALL = 2, 34 | 35 | CUSTOMIZED_ALL = 4, 36 | }; 37 | 38 | using CustomizeCpuDvfsTable = pcv::cvb_entry_t[pcv::DvfsTableEntryLimit]; 39 | using CustomizeGpuDvfsTable = pcv::cvb_entry_t[pcv::DvfsTableEntryLimit]; 40 | static_assert(sizeof(CustomizeCpuDvfsTable) == sizeof(CustomizeGpuDvfsTable)); 41 | static_assert(sizeof(CustomizeCpuDvfsTable) == sizeof(pcv::cvb_entry_t) * pcv::DvfsTableEntryLimit); 42 | 43 | constexpr uint32_t ERISTA_MTC_MAGIC = 0x43544D45; // EMTC 44 | constexpr uint32_t MARIKO_MTC_MAGIC = 0x43544D4D; // MMTC 45 | 46 | typedef struct CustomizeTable { 47 | u8 cust[4] = {'C', 'U', 'S', 'T'}; 48 | u32 custRev = CUST_REV; 49 | u32 mtcConf; 50 | u32 commonCpuBoostClock; 51 | u32 commonEmcMemVolt; 52 | u32 eristaCpuMaxVolt; 53 | u32 eristaEmcMaxClock; 54 | u32 marikoCpuMaxVolt; 55 | u32 marikoEmcMaxClock; 56 | u32 marikoEmcVddqVolt; 57 | u32 marikoCpuUV; 58 | u32 marikoGpuUV; 59 | u32 commonGpuVoltOffset; 60 | // advanced config 61 | u32 marikoEmcDvbShift; 62 | u32 ramTimingPresetOne; 63 | u32 ramTimingPresetTwo; 64 | u32 ramTimingPresetThree; 65 | u32 ramTimingPresetFour; 66 | u32 ramTimingPresetFive; 67 | u32 ramTimingPresetSix; 68 | u32 ramTimingPresetSeven; 69 | // 70 | u32 marikoGpuVoltArray[17]; 71 | CustomizeCpuDvfsTable eristaCpuDvfsTable; 72 | CustomizeCpuDvfsTable marikoCpuDvfsTable; 73 | CustomizeCpuDvfsTable marikoCpuDvfsTableSLT; 74 | CustomizeGpuDvfsTable eristaGpuDvfsTable; 75 | CustomizeGpuDvfsTable marikoGpuDvfsTable; 76 | CustomizeGpuDvfsTable marikoGpuDvfsTableSLT; 77 | CustomizeGpuDvfsTable marikoGpuDvfsTableHiOPT; 78 | //EristaMtcTable* eristaMtcTable; 79 | //MarikoMtcTable* marikoMtcTable; 80 | } CustomizeTable; 81 | //static_assert(sizeof(CustomizeTable) == sizeof(u8) * 4 + sizeof(u32) * 10 + sizeof(CustomizeCpuDvfsTable) * 5 + sizeof(void*) * 2); 82 | //static_assert(sizeof(CustomizeTable) == 7000); 83 | 84 | extern volatile CustomizeTable C; 85 | 86 | //extern volatile EristaMtcTable EristaMtcTablePlaceholder; 87 | //extern volatile MarikoMtcTable MarikoMtcTablePlaceholder; 88 | 89 | } -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #pragma once 18 | 19 | #ifdef ATMOSPHERE_IS_STRATOSPHERE 20 | #include 21 | #include 22 | #define LOGGING(fmt, ...) ((void)0) 23 | #define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); } 24 | #else 25 | #include "oc_test.hpp" 26 | #endif 27 | 28 | #include "customize.hpp" 29 | 30 | #define PATCH_OFFSET(offset, value) \ 31 | static_assert(sizeof(__typeof__(offset)) <= sizeof(u64)); \ 32 | *(offset) = value; 33 | 34 | namespace ams::ldr { 35 | R_DEFINE_ERROR_RESULT(OutOfRange, 1000); 36 | R_DEFINE_ERROR_RESULT(InvalidMemPllmEntry, 1001); 37 | R_DEFINE_ERROR_RESULT(InvalidMtcMagic, 1002); 38 | R_DEFINE_ERROR_RESULT(InvalidMtcTable, 1003); 39 | R_DEFINE_ERROR_RESULT(InvalidDvbTable, 1004); 40 | R_DEFINE_ERROR_RESULT(InvalidCpuFreqVddEntry, 1005); 41 | R_DEFINE_ERROR_RESULT(InvalidCpuVoltDfllEntry, 1006); 42 | R_DEFINE_ERROR_RESULT(InvalidCpuDvfs, 1007); 43 | R_DEFINE_ERROR_RESULT(InvalidCpuMinVolt, 1008); 44 | R_DEFINE_ERROR_RESULT(InvalidGpuDvfs, 1009); 45 | R_DEFINE_ERROR_RESULT(InvalidGpuFreqMaxPattern, 1010); 46 | R_DEFINE_ERROR_RESULT(InvalidGpuPllEntry, 1011); 47 | R_DEFINE_ERROR_RESULT(InvalidRegulatorEntry, 1012); 48 | R_DEFINE_ERROR_RESULT(UninitializedPatcher, 1013); 49 | R_DEFINE_ERROR_RESULT(UnsuccessfulPatcher, 1014); 50 | R_DEFINE_ERROR_RESULT(SafetyCheckFailure, 1015); 51 | } 52 | 53 | namespace ams::ldr::oc { 54 | template 55 | struct PatcherEntry { 56 | using patternFn = bool(*)(Pointer* ptr); 57 | using patcherFn = Result(*)(Pointer* ptr); 58 | 59 | const char* description; 60 | patcherFn patcher_fn = nullptr; 61 | size_t maximum_patched_count = 0; 62 | patternFn pattern_search_fn = nullptr; 63 | Pointer value_search; 64 | 65 | size_t patched_count = 0; 66 | 67 | Result Apply(Pointer* ptr) { 68 | Result res = patcher_fn(ptr); 69 | if (R_SUCCEEDED(res)) 70 | patched_count++; 71 | 72 | return res; 73 | } 74 | 75 | Result SearchAndApply(Pointer* ptr) { 76 | bool searchOk = false; 77 | if (pattern_search_fn) { 78 | if (pattern_search_fn(ptr)) searchOk = true; 79 | } else { 80 | if (value_search == *(ptr)) searchOk = true; 81 | } 82 | 83 | if (searchOk) 84 | return Apply(ptr); 85 | 86 | R_THROW(ldr::ResultUnsuccessfulPatcher()); 87 | } 88 | 89 | Result CheckResult() { 90 | #ifndef ATMOSPHERE_IS_STRATOSPHERE 91 | R_UNLESS(patched_count > 0, ldr::ResultUnsuccessfulPatcher()); 92 | #endif 93 | 94 | if (maximum_patched_count) 95 | R_UNLESS(patched_count <= maximum_patched_count, ldr::ResultUnsuccessfulPatcher()); 96 | 97 | R_SUCCEED(); 98 | } 99 | }; 100 | } 101 | -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/oc_loader.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "oc_common.hpp" 20 | #include "pcv/pcv.hpp" 21 | #include "ptm/ptm.hpp" 22 | -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/oc_test.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #pragma once 18 | 19 | #ifndef ATMOSPHERE_IS_STRATOSPHERE 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | typedef uint8_t u8; 31 | typedef uint16_t u16; 32 | typedef uint32_t u32; 33 | typedef int32_t s32; 34 | typedef uint64_t u64; 35 | typedef int Result; 36 | 37 | #define R_SUCCEEDED(arg) (arg == 0) 38 | #define R_FAILED(arg) (arg != 0) 39 | #define LOGGING(fmt, ...) { printf(fmt "\n", ##__VA_ARGS__); } 40 | #define CRASH(msg, ...) { fprintf(stderr, "%s\nFailed in %s!\n", msg, __PRETTY_FUNCTION__); exit(-1); } 41 | #define R_SUCCEED() { return 0; } 42 | #define R_THROW(err) { return err; } 43 | #define R_TRY(expr) { Result _rc = (expr); if (R_FAILED(_rc)) { return _rc; } } 44 | #define R_UNLESS(expr, rc) { if (!(expr)) { return rc; } } 45 | 46 | #define R_DEFINE_ERROR_RESULT(name, rc) \ 47 | inline Result Result##name() { return rc; } 48 | 49 | #define HEXDUMP(ptr, len) \ 50 | { \ 51 | const uint8_t* p = reinterpret_cast(ptr); \ 52 | size_t i, j; \ 53 | for (i = 0; i < len; i += 16) { \ 54 | printf("%06zx: ", i); \ 55 | for (j = 0; j < 16 && i + j < len; j++) \ 56 | printf("%02x ", p[i + j]); \ 57 | for (; j < 16; j++) \ 58 | printf(" "); \ 59 | for (j = 0; j < 16 && i + j < len; j++) \ 60 | printf("%c", isprint(p[i + j]) ? p[i + j] : '.'); \ 61 | printf("\n"); \ 62 | } \ 63 | } \ 64 | 65 | typedef struct UnitTest { 66 | using Func = Result(*)(); 67 | 68 | const char* description; 69 | Func fun = nullptr; 70 | 71 | void Test() { 72 | Result res = fun(); 73 | if (R_FAILED(res)) { 74 | CRASH(description); 75 | } 76 | } 77 | } UnitTest; 78 | 79 | #endif -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * Copyright (c) 2023 hanai3Bi 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "pcv.hpp" 20 | 21 | namespace ams::ldr::oc::pcv { 22 | 23 | Result MemFreqPllmLimit(u32* ptr) { 24 | clk_pll_param* entry = reinterpret_cast(ptr); 25 | R_UNLESS(entry->freq == entry->vco_max, ldr::ResultInvalidMemPllmEntry()); 26 | 27 | // Double the max clk simply 28 | u32 max_clk = entry->freq * 2; 29 | entry->freq = max_clk; 30 | entry->vco_max = max_clk; 31 | R_SUCCEED(); 32 | } 33 | 34 | Result MemVoltHandler(u32* ptr) { 35 | // ptr value might be default_uv or max_uv 36 | regulator* entries[2] = { 37 | reinterpret_cast(reinterpret_cast(ptr) - offsetof(regulator, type_1.default_uv)), 38 | reinterpret_cast(reinterpret_cast(ptr) - offsetof(regulator, type_1.max_uv)), 39 | }; 40 | 41 | constexpr u32 uv_step = 12'500; 42 | constexpr u32 uv_min = 600'000; 43 | 44 | auto validator = [](regulator* entry) { 45 | R_UNLESS(entry->id == 1, ldr::ResultInvalidRegulatorEntry()); 46 | R_UNLESS(entry->type == 1, ldr::ResultInvalidRegulatorEntry()); 47 | R_UNLESS(entry->type_1.volt_reg == 0x17, ldr::ResultInvalidRegulatorEntry()); 48 | R_UNLESS(entry->type_1.step_uv == uv_step, ldr::ResultInvalidRegulatorEntry()); 49 | R_UNLESS(entry->type_1.min_uv == uv_min, ldr::ResultInvalidRegulatorEntry()); 50 | R_SUCCEED(); 51 | }; 52 | 53 | regulator* entry = nullptr; 54 | for (auto& i : entries) { 55 | if (R_SUCCEEDED(validator(i))) 56 | entry = i; 57 | } 58 | 59 | R_UNLESS(entry, ldr::ResultInvalidRegulatorEntry()); 60 | 61 | u32 emc_uv = C.commonEmcMemVolt; 62 | if (!emc_uv) 63 | R_SKIP(); 64 | 65 | if (emc_uv % uv_step) 66 | emc_uv = emc_uv / uv_step * uv_step; // rounding 67 | 68 | PATCH_OFFSET(ptr, emc_uv); 69 | 70 | R_SUCCEED(); 71 | } 72 | 73 | void SafetyCheck() { 74 | if (C.custRev != CUST_REV) 75 | CRASH("Triggered"); 76 | 77 | struct sValidator { 78 | volatile u32 value; 79 | u32 min; 80 | u32 max; 81 | bool value_required = false; 82 | 83 | Result check() { 84 | if (!value_required && !value) 85 | R_SUCCEED(); 86 | 87 | if (min && value < min) 88 | R_THROW(ldr::ResultSafetyCheckFailure()); 89 | if (max && value > max) 90 | R_THROW(ldr::ResultSafetyCheckFailure()); 91 | 92 | R_SUCCEED(); 93 | } 94 | }; 95 | 96 | u32 eristaCpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.eristaCpuDvfsTable)->freq); 97 | u32 marikoCpuDvfsMaxFreq = static_cast(C.marikoCpuUV ? GetDvfsTableLastEntry(C.marikoCpuDvfsTableSLT)->freq : GetDvfsTableLastEntry(C.marikoCpuDvfsTable)->freq); 98 | u32 eristaGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.eristaGpuDvfsTable)->freq); 99 | u32 marikoGpuDvfsMaxFreq; 100 | switch (C.marikoGpuUV) { 101 | case 0: 102 | marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq); 103 | break; 104 | case 1: 105 | marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTableSLT)->freq); 106 | break; 107 | case 2: 108 | marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTableHiOPT)->freq); 109 | break; 110 | default: 111 | marikoGpuDvfsMaxFreq = static_cast(GetDvfsTableLastEntry(C.marikoGpuDvfsTable)->freq); 112 | break; 113 | } 114 | 115 | sValidator validators[] = { 116 | { C.commonCpuBoostClock, 1020'000, 3000'000, true }, 117 | { C.commonEmcMemVolt, 1100'000, 1250'000 }, 118 | { C.eristaCpuMaxVolt, 1100, 1300 }, 119 | { C.eristaEmcMaxClock, 1600'000, 2131'200 }, 120 | { C.marikoCpuMaxVolt, 1100, 1300 }, 121 | { C.marikoEmcMaxClock, 1600'000, 2800'000 }, 122 | { C.marikoEmcVddqVolt, 550'000, 650'000 }, 123 | { eristaCpuDvfsMaxFreq, 1785'000, 3000'000 }, 124 | { marikoCpuDvfsMaxFreq, 1785'000, 3000'000 }, 125 | { eristaGpuDvfsMaxFreq, 768'000, 1536'000 }, 126 | { marikoGpuDvfsMaxFreq, 768'000, 1536'000 }, 127 | }; 128 | 129 | for (auto& i : validators) { 130 | if (R_FAILED(i.check())) 131 | CRASH("Triggered"); 132 | } 133 | } 134 | 135 | void Patch(uintptr_t mapped_nso, size_t nso_size) { 136 | #ifdef ATMOSPHERE_IS_STRATOSPHERE 137 | SafetyCheck(); 138 | bool isMariko = (spl::GetSocType() == spl::SocType_Mariko); 139 | if (isMariko) 140 | mariko::Patch(mapped_nso, nso_size); 141 | else 142 | erista::Patch(mapped_nso, nso_size); 143 | #endif 144 | } 145 | 146 | } -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_common.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #pragma once 18 | 19 | namespace ams::ldr::oc::pcv { 20 | 21 | typedef struct cvb_coefficients { 22 | s32 c0 = 0; 23 | s32 c1 = 0; 24 | s32 c2 = 0; 25 | s32 c3 = 0; 26 | s32 c4 = 0; 27 | s32 c5 = 0; 28 | } cvb_coefficients; 29 | 30 | typedef struct cvb_entry_t { 31 | u64 freq; 32 | cvb_coefficients cvb_dfll_param; 33 | cvb_coefficients cvb_pll_param; 34 | } cvb_entry_t; 35 | static_assert(sizeof(cvb_entry_t) == 0x38); 36 | 37 | typedef struct cvb_cpu_dfll_data { 38 | u32 tune0_low; 39 | u32 tune0_high; 40 | u32 tune1_low; 41 | u32 tune1_high; 42 | unsigned int tune_high_min_millivolts; 43 | unsigned int tune_high_margin_millivolts; 44 | unsigned long dvco_calibration_max; 45 | } cvb_cpu_dfll_data; 46 | 47 | typedef struct emc_dvb_dvfs_table_t { 48 | u64 freq; 49 | s32 volt[4] = {0}; 50 | } emc_dvb_dvfs_table_t; 51 | 52 | typedef struct __attribute__((packed)) div_nmp { 53 | u8 divn_shift; 54 | u8 divn_width; 55 | u8 divm_shift; 56 | u8 divm_width; 57 | u8 divp_shift; 58 | u8 divp_width; 59 | u8 override_divn_shift; 60 | u8 override_divm_shift; 61 | u8 override_divp_shift; 62 | } div_nmp; 63 | 64 | typedef struct __attribute__((packed)) clk_pll_param { 65 | u32 freq; 66 | u32 input_min; 67 | u32 input_max; 68 | u32 cf_min; 69 | u32 cf_max; 70 | u32 vco_min; 71 | u32 vco_max; 72 | s32 lock_delay; 73 | u32 fixed_rate; 74 | u32 unk_0; 75 | struct div_nmp *div_nmp; 76 | u32 unk_1[4]; 77 | void (*unk_fn)(u64* unk_struct); // set_defaults? 78 | } clk_pll_param; 79 | 80 | typedef struct __attribute__((packed)) dvfs_rail { 81 | u32 id; 82 | u32 unk_0[5]; 83 | u32 freq; 84 | u32 unk_1[8]; 85 | u32 unk_flag; 86 | u32 min_mv; 87 | u32 step_mv; 88 | u32 max_mv; 89 | u32 unk_2[11]; 90 | } dvfs_rail; 91 | 92 | typedef struct __attribute__((packed)) regulator { 93 | u64 id; 94 | const char* name; 95 | u32 type; 96 | union { 97 | struct { 98 | u32 volt_reg; 99 | u32 step_uv; 100 | u32 min_uv; 101 | u32 default_uv; 102 | u32 max_uv; 103 | u32 unk_0[2]; 104 | } type_1; 105 | struct { 106 | u32 unk_0; 107 | u32 step_uv; 108 | u32 unk_1; 109 | u32 min_uv; 110 | u32 max_uv; 111 | u32 unk_2; 112 | u32 default_uv; 113 | } type_2_3; 114 | }; 115 | u32 unk_x[60]; 116 | } regulator; 117 | static_assert(sizeof(regulator) == 0x120); 118 | 119 | constexpr u32 CpuClkOSLimit = 1785'000; 120 | 121 | constexpr u32 EmcClkOSLimit = 1600'000; 122 | 123 | #define R_SKIP() R_SUCCEED() 124 | 125 | // Count 32 / Index 31 is reserved to be empty 126 | constexpr size_t DvfsTableEntryCount = 32; 127 | constexpr size_t DvfsTableEntryLimit = DvfsTableEntryCount - 1; 128 | 129 | template 130 | size_t GetDvfsTableEntryCount(T* table_head) { 131 | using NT = std::remove_const_t>; 132 | 133 | auto is_empty = [](NT* entry) { 134 | uint8_t* m = reinterpret_cast(entry); 135 | for (size_t i = 0; i < sizeof(NT); i++) { 136 | if (*(m + i)) 137 | return false; 138 | } 139 | return true; 140 | }; 141 | 142 | NT* table = const_cast(table_head); 143 | size_t count = 0; 144 | while (count < DvfsTableEntryLimit) { 145 | if (is_empty(table++)) { 146 | return count; 147 | } 148 | count++; 149 | } 150 | return DvfsTableEntryLimit; 151 | } 152 | 153 | template 154 | T* GetDvfsTableLastEntry(T* table_head) { 155 | using NT = std::remove_const_t>; 156 | 157 | NT* table = const_cast(table_head); 158 | size_t count = GetDvfsTableEntryCount(table_head); 159 | if (!count) { 160 | return nullptr; 161 | } 162 | size_t index = count - 1; 163 | return table + index; 164 | } 165 | 166 | } -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include "ptm.hpp" 18 | 19 | namespace ams::ldr::oc::ptm { 20 | 21 | Result CpuPtmBoost(perf_conf_entry* entry) { 22 | if (!C.commonCpuBoostClock) 23 | R_SUCCEED(); 24 | 25 | u32 cpuPtmBoostNew = C.commonCpuBoostClock * 1000; 26 | 27 | PATCH_OFFSET(&(entry->cpu_freq_1), cpuPtmBoostNew); 28 | PATCH_OFFSET(&(entry->cpu_freq_2), cpuPtmBoostNew); 29 | 30 | R_SUCCEED(); 31 | } 32 | 33 | Result MemPtm(perf_conf_entry* entry) { 34 | PATCH_OFFSET(&(entry->emc_freq_1), memPtmLimit); 35 | PATCH_OFFSET(&(entry->emc_freq_2), memPtmLimit); 36 | 37 | R_SUCCEED(); 38 | } 39 | 40 | bool PtmEntryIsValid(perf_conf_entry* entry) { 41 | return (entry->cpu_freq_1 == entry->cpu_freq_2 && 42 | entry->gpu_freq_1 == entry->gpu_freq_2 && 43 | entry->emc_freq_1 == entry->emc_freq_2); 44 | } 45 | 46 | bool PtmTablePatternFn(u32* ptr) { 47 | perf_conf_entry* entry = reinterpret_cast(ptr); 48 | if (!PtmEntryIsValid(entry)) 49 | return false; 50 | 51 | return entry->cpu_freq_1 == cpuPtmDefault; 52 | } 53 | 54 | void Patch(uintptr_t mapped_nso, size_t nso_size) { 55 | perf_conf_entry* confTable = nullptr; 56 | for (uintptr_t ptr = mapped_nso; 57 | ptr <= mapped_nso + nso_size - sizeof(perf_conf_entry) * entryCnt; 58 | ptr += sizeof(u32)) 59 | { 60 | u32* ptr32 = reinterpret_cast(ptr); 61 | if (PtmTablePatternFn(ptr32)) { 62 | confTable = reinterpret_cast(ptr); 63 | break; 64 | } 65 | } 66 | 67 | if (!confTable) { 68 | CRASH("confTable not found!"); 69 | } 70 | 71 | PatcherEntry cpuPtmBoostPatch = { "CPU Ptm Boost", &CpuPtmBoost, 2, }; 72 | PatcherEntry memPtmPatch = { "MEM Ptm", &MemPtm, 16, }; 73 | 74 | #ifdef ATMOSPHERE_IS_STRATOSPHERE 75 | bool isMariko = (spl::GetSocType() == spl::SocType_Mariko); 76 | #else 77 | bool isMariko = true; 78 | #endif 79 | 80 | 81 | for (u32 i = 0; i < entryCnt; i++) { 82 | perf_conf_entry* entry = confTable + i; 83 | 84 | if (!PtmEntryIsValid(entry)) { 85 | LOGGING("@%p", &entry); 86 | CRASH("Invalid ptm confTable entry"); 87 | } 88 | 89 | switch (entry->cpu_freq_1) { 90 | case cpuPtmBoost: 91 | cpuPtmBoostPatch.Apply(entry); 92 | break; 93 | case cpuPtmDefault: 94 | case cpuPtmDevOC: 95 | break; 96 | default: 97 | LOGGING("%u (0x%08x) @%p", entry->cpu_freq_1, entry->conf_id, &(entry->cpu_freq_1)); 98 | CRASH("Unknown CPU Freq"); 99 | } 100 | 101 | switch (entry->emc_freq_1) { 102 | case memPtmLimit: 103 | case memPtmAlt: 104 | case memPtmClamp: 105 | if (isMariko) { 106 | memPtmPatch.Apply(entry); 107 | } 108 | break; 109 | default: 110 | LOGGING("%u (0x%08x) @%p", entry->emc_freq_1, entry->conf_id, &(entry->emc_freq_2)); 111 | CRASH("Unknown MEM Freq"); 112 | } 113 | } 114 | 115 | LOGGING("%s Count: %zu", cpuPtmBoostPatch.description, cpuPtmBoostPatch.patched_count); 116 | if (R_FAILED(cpuPtmBoostPatch.CheckResult())) 117 | CRASH(cpuPtmBoostPatch.description); 118 | 119 | if (isMariko) { 120 | LOGGING("%s Count: %zu", memPtmPatch.description, memPtmPatch.patched_count); 121 | if (R_FAILED(memPtmPatch.CheckResult())) 122 | CRASH(memPtmPatch.description); 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Switch-OC-Suite 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #pragma once 18 | 19 | #include "../oc_common.hpp" 20 | 21 | namespace ams::ldr::oc::ptm { 22 | 23 | typedef struct { 24 | u32 conf_id; 25 | u32 cpu_freq_1; // min-max pair? 26 | u32 cpu_freq_2; 27 | u32 gpu_freq_1; 28 | u32 gpu_freq_2; 29 | u32 emc_freq_1; 30 | u32 emc_freq_2; 31 | u32 padding; 32 | } perf_conf_entry; 33 | 34 | constexpr u32 entryCnt = 16; 35 | constexpr u32 cpuPtmDefault = 1020'000'000; 36 | constexpr u32 cpuPtmDevOC = 1224'000'000; 37 | constexpr u32 cpuPtmBoost = 1785'000'000; 38 | 39 | constexpr u32 memPtmLimit = 1600'000'000; 40 | constexpr u32 memPtmAlt = 1331'200'000; 41 | constexpr u32 memPtmClamp = 1065'600'000; 42 | 43 | void Patch(uintptr_t mapped_nso, size_t nso_size); 44 | 45 | } -------------------------------------------------------------------------------- /Source/Atmosphere/stratosphere/loader/source/patch.py: -------------------------------------------------------------------------------- 1 | #!python3 2 | 3 | import sys 4 | import os 5 | 6 | def file_replace_str(file_path, search_replace_list): 7 | assert file_path 8 | assert search_replace_list 9 | with open(file_path, "r") as f: 10 | content = f.read() 11 | 12 | for entry in search_replace_list: 13 | (search, replace) = entry 14 | if search in content: 15 | content = content.replace(search, replace) 16 | else: 17 | assert replace in content, f"Pattern \"{search}\" not found" 18 | 19 | with open(file_path, "w") as f: 20 | f.write(content) 21 | 22 | 23 | dir_path = os.path.dirname(__file__) 24 | 25 | os.chdir(dir_path) 26 | os.system("git reset --hard") 27 | 28 | ldr_process_creation = os.path.join(dir_path, "ldr_process_creation.cpp") 29 | file_replace_str(ldr_process_creation, 30 | [("""#include "ldr_ro_manager.hpp" 31 | 32 | namespace ams::ldr {""", 33 | """#include "ldr_ro_manager.hpp" 34 | #include "oc/oc_loader.hpp" 35 | 36 | namespace ams::ldr {"""), 37 | (""" NsoHeader g_nso_headers[Nso_Count]; 38 | 39 | Result ValidateProgramVersion(ncm::ProgramId program_id, u32 version) {""", 40 | """ NsoHeader g_nso_headers[Nso_Count]; 41 | 42 | /* Pcv/Ptm check cache. */ 43 | bool g_is_pcv; 44 | bool g_is_ptm; 45 | 46 | Result ValidateProgramVersion(ncm::ProgramId program_id, u32 version) {"""), 47 | (""" R_UNLESS(meta->aci->program_id <= meta->acid->program_id_max, ldr::ResultInvalidProgramId()); 48 | 49 | /* Validate the kernel capabilities. */""", 50 | """ R_UNLESS(meta->aci->program_id <= meta->acid->program_id_max, ldr::ResultInvalidProgramId()); 51 | 52 | /* Check if nca is pcv or ptm */ 53 | g_is_pcv = meta->aci->program_id == ncm::SystemProgramId::Pcv; 54 | g_is_ptm = meta->aci->program_id == ncm::SystemProgramId::Ptm; 55 | 56 | /* Validate the kernel capabilities. */"""), 57 | (""" LocateAndApplyIpsPatchesToModule(nso_header->module_id, map_address, nso_size); 58 | }""", 59 | """ LocateAndApplyIpsPatchesToModule(nso_header->module_id, map_address, nso_size); 60 | 61 | /* Apply pcv and ptm patches. */ 62 | if (g_is_pcv) 63 | oc::pcv::Patch(map_address, nso_size); 64 | if (g_is_ptm) 65 | oc::ptm::Patch(map_address, nso_size); 66 | }""")]) 67 | 68 | ldr_meta = os.path.join(dir_path, "ldr_meta.cpp") 69 | file_replace_str(ldr_meta, 70 | [(""" Result ValidateAcidSignature(Meta *meta) { 71 | /* Loader did not check signatures prior to 10.0.0. */""", 72 | """ Result ValidateAcidSignature(Meta *meta) { 73 | R_SUCCEED(); 74 | /* Loader did not check signatures prior to 10.0.0. */""")]) 75 | -------------------------------------------------------------------------------- /Source/MemTesterNX/.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | build/ 3 | *.elf 4 | *.nacp 5 | *.nro -------------------------------------------------------------------------------- /Source/MemTesterNX/source/memtester.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Very simple (yet, for some reason, very effective) memory tester. 3 | * Originally by Simon Kirby 4 | * Version 2 by Charles Cazabon 5 | * Version 3 not publicly released. 6 | * Version 4 rewrite: 7 | * Copyright (C) 2004-2020 Charles Cazabon 8 | * Licensed under the terms of the GNU General Public License version 2 (only). 9 | * See the file COPYING for details. 10 | * 11 | * This file contains the declarations for external variables from the main file. 12 | * See other comments in that file. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | /* extern declarations. */ 19 | 20 | extern int use_phys; 21 | extern off_t physaddrbase; 22 | 23 | -------------------------------------------------------------------------------- /Source/MemTesterNX/source/sizes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Very simple but very effective user-space memory tester. 3 | * Originally by Simon Kirby 4 | * Version 2 by Charles Cazabon 5 | * Version 3 not publicly released. 6 | * Version 4 rewrite: 7 | * Copyright (C) 2004-2012 Charles Cazabon 8 | * Licensed under the terms of the GNU General Public License version 2 (only). 9 | * See the file COPYING for details. 10 | * 11 | * This file contains some macro definitions for handling 32/64 bit platforms. 12 | * 13 | */ 14 | 15 | #include 16 | 17 | #define rand32() ((unsigned int) rand() | ( (unsigned int) rand() << 16)) 18 | 19 | #if (ULONG_MAX == 4294967295UL) 20 | #define rand_ul() rand32() 21 | #define UL_ONEBITS 0xffffffff 22 | #define UL_LEN 32 23 | #define CHECKERBOARD1 0x55555555 24 | #define CHECKERBOARD2 0xaaaaaaaa 25 | #define UL_BYTE(x) ((x | x << 8 | x << 16 | x << 24)) 26 | #elif (ULONG_MAX == 18446744073709551615ULL) 27 | #define rand64() (((ul) rand32()) << 32 | ((ul) rand32())) 28 | #define rand_ul() rand64() 29 | #define UL_ONEBITS 0xffffffffffffffffUL 30 | #define UL_LEN 64 31 | #define CHECKERBOARD1 0x5555555555555555 32 | #define CHECKERBOARD2 0xaaaaaaaaaaaaaaaa 33 | #define UL_BYTE(x) (((ul)x | (ul)x<<8 | (ul)x<<16 | (ul)x<<24 | (ul)x<<32 | (ul)x<<40 | (ul)x<<48 | (ul)x<<56)) 34 | #else 35 | #error long on this platform is not 32 or 64 bits 36 | #endif 37 | 38 | 39 | -------------------------------------------------------------------------------- /Source/MemTesterNX/source/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Very simple yet very effective memory tester. 3 | * Originally by Simon Kirby 4 | * Version 2 by Charles Cazabon 5 | * Version 3 not publicly released. 6 | * Version 4 rewrite: 7 | * Copyright (C) 2004-2020 Charles Cazabon 8 | * Licensed under the terms of the GNU General Public License version 2 (only). 9 | * See the file COPYING for details. 10 | * 11 | * This file contains the declarations for the functions for the actual tests, 12 | * called from the main routine in memtester.c. See other comments in that 13 | * file. 14 | * 15 | */ 16 | 17 | /* Function declaration. */ 18 | 19 | int test_stuck_address(unsigned long volatile *bufa, size_t count); 20 | int test_random_value(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 21 | int test_xor_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 22 | int test_sub_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 23 | int test_mul_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 24 | int test_div_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 25 | int test_or_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 26 | int test_and_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 27 | int test_seqinc_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 28 | int test_solidbits_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 29 | int test_checkerboard_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 30 | int test_blockseq_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 31 | int test_walkbits0_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 32 | int test_walkbits1_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 33 | int test_bitspread_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 34 | int test_bitflip_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 35 | #ifdef TEST_NARROW_WRITES 36 | int test_8bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 37 | int test_16bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 38 | #endif 39 | 40 | int test_stress_memcpy(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 41 | int test_stress_memset(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); 42 | int test_stress_memcmp(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); -------------------------------------------------------------------------------- /Source/MemTesterNX/source/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Very simple but very effective user-space memory tester. 3 | * Originally by Simon Kirby 4 | * Version 2 by Charles Cazabon 5 | * Version 3 not publicly released. 6 | * Version 4 rewrite: 7 | * Copyright (C) 2004-2020 Charles Cazabon 8 | * Licensed under the terms of the GNU General Public License version 2 (only). 9 | * See the file COPYING for details. 10 | * 11 | * This file contains typedefs, structure, and union definitions. 12 | * 13 | */ 14 | 15 | #include "sizes.h" 16 | 17 | typedef unsigned long ul; 18 | typedef unsigned long long ull; 19 | typedef unsigned long volatile ulv; 20 | typedef unsigned char volatile u8v; 21 | typedef unsigned short volatile u16v; 22 | 23 | struct test { 24 | char *name; 25 | int (*fp)(); 26 | }; 27 | -------------------------------------------------------------------------------- /Source/TinyMemBenchNX/.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | build/ 3 | *.elf 4 | *.nacp 5 | *.nro -------------------------------------------------------------------------------- /Source/TinyMemBenchNX/LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2011-2016 Siarhei Siamashka 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice (including the next 12 | * paragraph) shall be included in all copies or substantial portions of the 13 | * 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 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | -------------------------------------------------------------------------------- /Source/TinyMemBenchNX/readme.txt: -------------------------------------------------------------------------------- 1 | This is a simple memory benchmark program, which tries to measure the peak 2 | bandwidth of sequential memory accesses and the latency of random memory 3 | accesses. Bandwidth is measured by running different assembly code for 4 | the aligned memory blocks and attempting different prefetch strategies. 5 | 6 | The benchmark results for some hardware can be found in the wiki page: 7 | https://github.com/ssvb/tinymembench/wiki 8 | 9 | This program can be compiled in either linux or windows (via mingw32 and msys) 10 | by simply running make: 11 | $ make 12 | 13 | Adding extra optimization options is possible (in linux): 14 | $ CFLAGS="-O2 -march=atom -mtune=atom" make 15 | 16 | Example of crosscompiling for ARM (also in linux): 17 | $ CC=arm-linux-gnueabihf-gcc CFLAGS="-O2 -mcpu=cortex-a9" make 18 | 19 | Example of crosscompiling and running the benchmark on android device: 20 | $ CC=arm-linux-gnueabihf-gcc CFLAGS="-O2 -mcpu=cortex-a8 -static" make 21 | $ adb push tinymembench /data/local/tmp/tinymembench 22 | $ adb shell /data/local/tmp/tinymembench 23 | -------------------------------------------------------------------------------- /Source/TinyMemBenchNX/source/aarch64-asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2016 Siarhei Siamashka 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice (including the next 12 | * paragraph) shall be included in all copies or substantial portions of the 13 | * 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 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef __AARCH64_ASM_H__ 25 | #define __AARCH64_ASM_H__ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | void aligned_block_read_ldp_x_aarch64(int64_t * __restrict dst, 34 | int64_t * __restrict src, 35 | int size); 36 | void aligned_block_read_ldp_q_aarch64(int64_t * __restrict dst, 37 | int64_t * __restrict src, 38 | int size); 39 | void aligned_block_copy_ldpstp_x_aarch64(int64_t * __restrict dst, 40 | int64_t * __restrict src, 41 | int size); 42 | void aligned_block_copy_ldpstp_q_aarch64(int64_t * __restrict dst, 43 | int64_t * __restrict src, 44 | int size); 45 | void aligned_block_copy_ld1st1_aarch64(int64_t * __restrict dst, 46 | int64_t * __restrict src, 47 | int size); 48 | 49 | void aligned_block_copy_ldpstp_q_pf32_l2strm_aarch64(int64_t * __restrict dst, 50 | int64_t * __restrict src, 51 | int size); 52 | void aligned_block_copy_ldpstp_q_pf64_l2strm_aarch64(int64_t * __restrict dst, 53 | int64_t * __restrict src, 54 | int size); 55 | void aligned_block_copy_ldpstp_q_pf32_l1keep_aarch64(int64_t * __restrict dst, 56 | int64_t * __restrict src, 57 | int size); 58 | void aligned_block_copy_ldpstp_q_pf64_l1keep_aarch64(int64_t * __restrict dst, 59 | int64_t * __restrict src, 60 | int size); 61 | 62 | void aligned_block_fill_stp_x_aarch64(int64_t * __restrict dst, 63 | int64_t * __restrict src, 64 | int size); 65 | void aligned_block_fill_stp_q_aarch64(int64_t * __restrict dst, 66 | int64_t * __restrict src, 67 | int size); 68 | 69 | void aligned_block_fill_stnp_x_aarch64(int64_t * __restrict dst, 70 | int64_t * __restrict src, 71 | int size); 72 | void aligned_block_fill_stnp_q_aarch64(int64_t * __restrict dst, 73 | int64_t * __restrict src, 74 | int size); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/.gitignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/LICENSE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------- 2 | "THE BEER-WARE LICENSE" (Revision 42): 3 | , , 4 | wrote this file. As long as you retain this notice you can do whatever you 5 | want with this stuff. If you meet any of us some day, and you think this 6 | stuff is worth it, you can buy us a beer in return. - The sys-clk authors 7 | -------------------------------------------------------------------------- 8 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | DIST_DIR="$ROOT_DIR/dist" 6 | CORES=$(nproc --all) 7 | 8 | if [[ -n "$1" ]]; then 9 | DIST_DIR="$1" 10 | fi 11 | 12 | echo "DIST_DIR: $DIST_DIR" 13 | echo "CORES: $CORES" 14 | 15 | echo "*** sysmodule ***" 16 | TITLE_ID="00FF0000636C6BFF" 17 | 18 | pushd "$ROOT_DIR/sysmodule" 19 | make -j$CORES 20 | popd > /dev/null 21 | 22 | mkdir -p "$DIST_DIR/atmosphere/contents/$TITLE_ID/flags" 23 | cp -vf "$ROOT_DIR/sysmodule/out/sys-clk-OC.nsp" "$DIST_DIR/atmosphere/contents/$TITLE_ID/exefs.nsp" 24 | >"$DIST_DIR/atmosphere/contents/$TITLE_ID/flags/boot2.flag" 25 | 26 | echo "*** overlay ***" 27 | pushd "$ROOT_DIR/overlay" 28 | make -j$CORES 29 | popd > /dev/null 30 | 31 | mkdir -p "$DIST_DIR/switch/.overlays" 32 | cp -vf "$ROOT_DIR/overlay/out/sys-clk-overlay.ovl" "$DIST_DIR/switch/.overlays/sys-clk-overlay.ovl" 33 | 34 | echo "*** assets ***" 35 | mkdir -p "$DIST_DIR/config/sys-clk-oc" 36 | cp -vf "$ROOT_DIR/config.ini.template" "$DIST_DIR/config/sys-clk-oc/config.ini.template" 37 | >"$DIST_DIR/config/sys-clk-oc/log.flag" 38 | cp -vf "$ROOT_DIR/README.md" "$DIST_DIR/README.md" 39 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/cpp_util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class ScopeGuard { 7 | public: 8 | ScopeGuard(F&& f) 9 | : f(f), engaged(true) {}; 10 | 11 | ~ScopeGuard() { 12 | if (engaged) 13 | f(); 14 | }; 15 | 16 | ScopeGuard(ScopeGuard&& rhs) 17 | : f(std::move(rhs.f)) {}; 18 | 19 | void dismiss() { engaged = false; } 20 | 21 | private: 22 | F f; 23 | bool engaged; 24 | }; 25 | 26 | struct MakeScopeExit { 27 | template 28 | ScopeGuard operator+=(F&& f) { 29 | return ScopeGuard(std::move(f)); 30 | }; 31 | }; 32 | 33 | #define STRING_CAT2(x, y) x##y 34 | #define STRING_CAT(x, y) STRING_CAT2(x, y) 35 | #define SCOPE_GUARD MakeScopeExit() += [&]() __attribute__((always_inline)) 36 | #define SCOPE_EXIT auto STRING_CAT(scope_exit_, __LINE__) = SCOPE_GUARD -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | #include "cpp_util.hpp" 15 | extern "C" { 16 | #endif 17 | 18 | #include "sysclk/ipc.h" 19 | #include "sysclk/clocks.h" 20 | #include "sysclk/apm.h" 21 | #include "sysclk/config.h" 22 | #include "sysclk/errors.h" 23 | #include "sysclk/i2c.h" 24 | #include "sysclk/psm_ext.h" 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/apm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "clocks.h" 14 | 15 | typedef struct { 16 | uint32_t id; 17 | uint32_t cpu_hz; 18 | uint32_t gpu_hz; 19 | uint32_t mem_hz; 20 | } SysClkApmConfiguration; 21 | 22 | extern SysClkApmConfiguration sysclk_g_apm_configurations[]; -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/client/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include "types.h" 18 | #include "../config.h" 19 | #include "../clocks.h" 20 | #include "../ipc.h" 21 | 22 | bool sysclkIpcRunning(); 23 | Result sysclkIpcInitialize(void); 24 | void sysclkIpcExit(void); 25 | 26 | Result sysclkIpcGetAPIVersion(u32* out_ver); 27 | Result sysclkIpcGetVersionString(char* out, size_t len); 28 | Result sysclkIpcGetCurrentContext(SysClkContext* out_context); 29 | Result sysclkIpcGetProfileCount(u64 tid, u8* out_count); 30 | Result sysclkIpcSetEnabled(bool enabled); 31 | Result sysclkIpcExitCmd(); 32 | Result sysclkIpcSetOverride(SysClkModule module, u32 hz); 33 | Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles); 34 | Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles); 35 | Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues); 36 | Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues); 37 | Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode); 38 | Result sysclkIpcGetFrequencyTable(SysClkModule module, SysClkProfile profile, SysClkFrequencyTable* out_table); 39 | Result sysclkIpcGetIsMariko(bool* out_is_mariko); 40 | Result sysclkIpcGetBatteryChargingDisabledOverride(bool* out_is_true); 41 | Result sysclkIpcSetBatteryChargingDisabledOverride(bool toggle_true); 42 | 43 | static inline Result sysclkIpcRemoveOverride(SysClkModule module) 44 | { 45 | return sysclkIpcSetOverride(module, 0); 46 | } 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/client/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __SWITCH__ 14 | 15 | #include 16 | #include 17 | 18 | #else 19 | 20 | #define R_FAILED(res) ((res) != 0) 21 | #define R_SUCCEEDED(res) ((res) == 0) 22 | 23 | typedef std::uint32_t Result; 24 | typedef std::uint32_t u32; 25 | typedef std::int32_t s32; 26 | typedef std::uint64_t u64; 27 | typedef std::uint8_t u8; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | const uint32_t CHARGING_CURRENT_MA_LIMIT = 2000; 17 | 18 | typedef enum { 19 | SysClkConfigValue_PollingIntervalMs = 0, 20 | SysClkConfigValue_TempLogIntervalMs, 21 | SysClkConfigValue_CsvWriteIntervalMs, 22 | SysClkConfigValue_AutoCPUBoost, 23 | SysClkConfigValue_SyncReverseNXMode, 24 | SysClkConfigValue_AllowUnsafeFrequencies, 25 | SysClkConfigValue_ChargingCurrentLimit, 26 | SysClkConfigValue_ChargingLimitPercentage, 27 | SysClkConfigValue_GovernorExperimental, 28 | SysClkConfigValue_GovernorHandheldOnly, 29 | SysClkConfigValue_EnumMax, 30 | } SysClkConfigValue; 31 | 32 | typedef struct { 33 | uint64_t values[SysClkConfigValue_EnumMax]; 34 | } SysClkConfigValueList; 35 | 36 | static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pretty) 37 | { 38 | switch(val) 39 | { 40 | case SysClkConfigValue_PollingIntervalMs: 41 | return pretty ? "Polling Interval (ms)" : "poll_interval_ms"; 42 | case SysClkConfigValue_TempLogIntervalMs: 43 | return pretty ? "Temperature logging interval (ms)" : "temp_log_interval_ms"; 44 | case SysClkConfigValue_CsvWriteIntervalMs: 45 | return pretty ? "CSV write interval (ms)" : "csv_write_interval_ms"; 46 | case SysClkConfigValue_AutoCPUBoost: 47 | return pretty ? "Auto CPU Boost" : "auto_cpu_boost"; 48 | case SysClkConfigValue_SyncReverseNXMode: 49 | return pretty ? "Sync ReverseNX Mode Sync" : "sync_reversenx_mode"; 50 | case SysClkConfigValue_AllowUnsafeFrequencies: 51 | return pretty ? "Allow Unsafe Frequencies" : "allow_unsafe_freq"; 52 | case SysClkConfigValue_ChargingCurrentLimit: 53 | return pretty ? "Charging Current Limit (mA)" : "charging_current"; 54 | case SysClkConfigValue_ChargingLimitPercentage: 55 | return pretty ? "Charging Limit (%%)" : "charging_limit_perc"; 56 | case SysClkConfigValue_GovernorExperimental: 57 | return pretty ? "Frequency Governor (Experimental)" : "governor_experimental"; 58 | case SysClkConfigValue_GovernorHandheldOnly: 59 | return pretty ? "Frequency Governor Handheld Only" : "governor_handheld_only"; 60 | default: 61 | return NULL; 62 | } 63 | } 64 | 65 | static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val) 66 | { 67 | switch(val) 68 | { 69 | case SysClkConfigValue_PollingIntervalMs: 70 | return 500ULL; 71 | case SysClkConfigValue_TempLogIntervalMs: 72 | case SysClkConfigValue_CsvWriteIntervalMs: 73 | case SysClkConfigValue_AllowUnsafeFrequencies: 74 | case SysClkConfigValue_GovernorExperimental: 75 | case SysClkConfigValue_GovernorHandheldOnly: 76 | case SysClkConfigValue_AutoCPUBoost: 77 | return 0ULL; 78 | case SysClkConfigValue_SyncReverseNXMode: 79 | return 1ULL; 80 | case SysClkConfigValue_ChargingCurrentLimit: 81 | return 2000ULL; 82 | case SysClkConfigValue_ChargingLimitPercentage: 83 | return 100ULL; 84 | default: 85 | return 0ULL; 86 | } 87 | } 88 | 89 | static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t input) 90 | { 91 | switch(val) 92 | { 93 | case SysClkConfigValue_PollingIntervalMs: 94 | return input > 0; 95 | case SysClkConfigValue_TempLogIntervalMs: 96 | case SysClkConfigValue_CsvWriteIntervalMs: 97 | return true; 98 | case SysClkConfigValue_AutoCPUBoost: 99 | case SysClkConfigValue_SyncReverseNXMode: 100 | case SysClkConfigValue_AllowUnsafeFrequencies: 101 | case SysClkConfigValue_GovernorExperimental: 102 | case SysClkConfigValue_GovernorHandheldOnly: 103 | return (input & 0x1) == input; 104 | case SysClkConfigValue_ChargingCurrentLimit: 105 | return (input >= 100 && input <= CHARGING_CURRENT_MA_LIMIT && input % 100 == 0); 106 | case SysClkConfigValue_ChargingLimitPercentage: 107 | return (input <= 100 && input >= 20); 108 | default: 109 | return false; 110 | } 111 | } -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #define SYSCLK_ERROR_MODULE 388 14 | #define SYSCLK_ERROR(desc) ((SYSCLK_ERROR_MODULE & 0x1FF) | (SysClkError_##desc & 0x1FFF)<<9) 15 | 16 | typedef enum 17 | { 18 | SysClkError_Generic = 0, 19 | SysClkError_ConfigNotLoaded = 1, 20 | SysClkError_ConfigSaveFailed = 2, 21 | SysClkError_InternalFrequencyTableError = 3, 22 | } SysClkError; 23 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/i2c.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // To use i2c service, sm and i2c should be intialized via smInitialize() and i2cInitialize(). 6 | 7 | Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val); 8 | 9 | Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out); 10 | Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out); 11 | 12 | // Max17050 fuel gauge 13 | float I2c_Max17050_GetBatteryCurrent(); 14 | 15 | const u8 MAX17050_CURRENT_REG = 0x0A; 16 | 17 | // Buck Converter 18 | typedef enum I2c_BuckConverter_Reg { 19 | I2c_Max77620_SD1VOLT_REG = 0x17, // Used for Erista DDR VDDQ+VDD2 / Mariko VDD2 20 | I2c_Max77621_VOLT_REG = 0x00, 21 | I2c_Max77812_CPUVOLT_REG = 0x26, 22 | I2c_Max77812_GPUVOLT_REG = 0x23, 23 | I2c_Max77812_MEMVOLT_REG = 0x25, // Master 3 (GPU 1 + 2, DRAM 3, CPU 4), used for Mariko VDDQ 24 | } I2c_BuckConverter_Reg; 25 | 26 | typedef struct I2c_BuckConverter_Domain { 27 | I2cDevice device; 28 | I2c_BuckConverter_Reg reg; 29 | u8 volt_mask; 30 | u32 uv_step; 31 | u32 uv_min; 32 | u32 uv_max; 33 | u8 por_val; 34 | } I2c_BuckConverter_Domain; 35 | 36 | const I2c_BuckConverter_Domain I2c_Erista_CPU = { I2cDevice_Max77621Cpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, }; 37 | const I2c_BuckConverter_Domain I2c_Erista_GPU = { I2cDevice_Max77621Gpu, I2c_Max77621_VOLT_REG, 0x7F, 6250, 606250, 1400000, }; 38 | const I2c_BuckConverter_Domain I2c_Erista_DRAM = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1250000, }; 39 | const I2c_BuckConverter_Domain I2c_Mariko_CPU = { I2cDevice_Max77812_2, I2c_Max77812_CPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 }; 40 | const I2c_BuckConverter_Domain I2c_Mariko_GPU = { I2cDevice_Max77812_2, I2c_Max77812_GPUVOLT_REG, 0xFF, 5000, 250000, 1525000, 0x78 }; 41 | const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDDQ = { I2cDevice_Max77812_2, I2c_Max77812_MEMVOLT_REG, 0xFF, 5000, 250000, 650000, 0x78 }; 42 | const I2c_BuckConverter_Domain I2c_Mariko_DRAM_VDD2 = { I2cDevice_Max77620Pmic, I2c_Max77620_SD1VOLT_REG, 0x7F, 12500, 600000, 1250000, }; 43 | 44 | u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain); 45 | Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt); 46 | 47 | // Bq24193 Battery management 48 | u32 I2c_Bq24193_Convert_Raw_mA(u8 raw); 49 | u8 I2c_Bq24193_Convert_mA_Raw(u32 ma); 50 | 51 | Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma); 52 | Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma); 53 | 54 | const u32 MA_RANGE_MIN = 512; 55 | const u32 MA_RANGE_MAX = 4544; 56 | 57 | const u8 BQ24193_CHARGE_CURRENT_CONTROL_REG = 0x2; -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include "clocks.h" 15 | 16 | #define SYSCLK_IPC_API_VERSION 2 17 | #define SYSCLK_IPC_SERVICE_NAME "sysclkOC" 18 | 19 | enum SysClkIpcCmd 20 | { 21 | SysClkIpcCmd_GetApiVersion = 0, 22 | SysClkIpcCmd_GetVersionString = 1, 23 | SysClkIpcCmd_GetCurrentContext = 2, 24 | SysClkIpcCmd_Exit = 3, 25 | SysClkIpcCmd_GetProfileCount = 4, 26 | SysClkIpcCmd_GetProfiles = 5, 27 | SysClkIpcCmd_SetProfiles = 6, 28 | SysClkIpcCmd_SetEnabled = 7, 29 | SysClkIpcCmd_SetOverride = 8, 30 | SysClkIpcCmd_GetConfigValues = 9, 31 | SysClkIpcCmd_SetConfigValues = 10, 32 | SysClkIpcCmd_SetReverseNXRTMode = 11, 33 | SysClkIpcCmd_GetFrequencyTable = 12, 34 | SysClkIpcCmd_GetIsMariko = 13, 35 | SysClkIpcCmd_GetBatteryChargingDisabledOverride = 14, 36 | SysClkIpcCmd_SetBatteryChargingDisabledOverride = 15, 37 | }; 38 | 39 | typedef struct 40 | { 41 | uint64_t tid; 42 | SysClkTitleProfileList profiles; 43 | } SysClkIpc_SetProfiles_Args; 44 | 45 | typedef struct 46 | { 47 | SysClkModule module; 48 | uint32_t hz; 49 | } SysClkIpc_SetOverride_Args; 50 | 51 | typedef struct 52 | { 53 | SysClkModule module; 54 | SysClkProfile profile; 55 | } SysClkIpc_GetFrequencyTable_Args; 56 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/include/sysclk/psm_ext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | typedef enum { 6 | PsmPDC_NewPDO = 1, //Received new Power Data Object 7 | PsmPDC_NoPD = 2, //No Power Delivery source is detected 8 | PsmPDC_AcceptedRDO = 3 //Received and accepted Request Data Object 9 | } PsmChargeInfoPDC; //BM92T series 10 | 11 | typedef enum { 12 | PsmPowerRole_Sink = 1, 13 | PsmPowerRole_Source = 2 14 | } PsmPowerRole; 15 | 16 | const char* PsmPowerRoleToStr(PsmPowerRole role); 17 | 18 | typedef enum { 19 | PsmInfoChargerType_None = 0, 20 | PsmInfoChargerType_PD = 1, 21 | PsmInfoChargerType_TypeC_1500mA = 2, 22 | PsmInfoChargerType_TypeC_3000mA = 3, 23 | PsmInfoChargerType_DCP = 4, 24 | PsmInfoChargerType_CDP = 5, 25 | PsmInfoChargerType_SDP = 6, 26 | PsmInfoChargerType_Apple_500mA = 7, 27 | PsmInfoChargerType_Apple_1000mA = 8, 28 | PsmInfoChargerType_Apple_2000mA = 9 29 | } PsmInfoChargerType; 30 | 31 | const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type); 32 | 33 | typedef enum { 34 | PsmFlags_NoHub = BIT(0), //If hub is disconnected 35 | PsmFlags_Rail = BIT(8), //At least one Joy-con is charging from rail 36 | PsmFlags_SPDSRC = BIT(12), //OTG 37 | PsmFlags_ACC = BIT(16) //Accessory 38 | } PsmChargeInfoFlags; 39 | 40 | typedef struct { 41 | int32_t InputCurrentLimit; //Input (Sink) current limit in mA 42 | int32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA 43 | int32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C) 44 | int32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C) 45 | int32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases 46 | int32_t unk_x14; //Possibly flags 47 | PsmChargeInfoPDC PDCState; //Power Delivery Controller State 48 | int32_t BatteryTemperature; //Battery temperature in milli C 49 | int32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm) 50 | int32_t VoltageAvg; //Voltage avg in mV (more in Notes) 51 | int32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm) 52 | PsmPowerRole PowerRole; 53 | PsmInfoChargerType ChargerType; 54 | int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV 55 | int32_t ChargerCurrentLimit; //Charger and external device current limit in mA 56 | PsmChargeInfoFlags Flags; //Unknown flags 57 | } PsmChargeInfo; 58 | 59 | typedef enum { 60 | Psm_EnableBatteryCharging = 2, 61 | Psm_DisableBatteryCharging = 3, 62 | Psm_EnableFastBatteryCharging = 10, 63 | Psm_DisableFastBatteryCharging = 11, 64 | Psm_GetBatteryChargeInfoFields = 17, 65 | } IPsmServerCmd; 66 | 67 | bool PsmIsChargerConnected(const PsmChargeInfo* info); 68 | bool PsmIsCharging(const PsmChargeInfo* info); 69 | 70 | typedef enum { 71 | PsmBatteryState_Discharging, 72 | PsmBatteryState_ChargingPaused, 73 | PsmBatteryState_FastCharging 74 | } PsmBatteryState; 75 | 76 | PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info); 77 | const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info); -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/src/apm_profile_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include 12 | 13 | SysClkApmConfiguration sysclk_g_apm_configurations[] = { 14 | {0x00010000, 1020000000, 384000000, 1600000000}, 15 | {0x00010001, 1020000000, 768000000, 1600000000}, 16 | {0x00010002, 1224000000, 691200000, 1600000000}, 17 | {0x00020000, 1020000000, 230400000, 1600000000}, 18 | {0x00020001, 1020000000, 307200000, 1600000000}, 19 | {0x00020002, 1224000000, 230400000, 1600000000}, 20 | {0x00020003, 1020000000, 307000000, 1331200000}, 21 | {0x00020004, 1020000000, 384000000, 1331200000}, 22 | {0x00020005, 1020000000, 307200000, 1065600000}, 23 | {0x00020006, 1020000000, 384000000, 1065600000}, 24 | {0x92220007, 1020000000, 460800000, 1600000000}, 25 | {0x92220008, 1020000000, 460800000, 1331200000}, 26 | {0x92220009, 1785000000, 76800000, 1600000000}, 27 | {0x9222000A, 1785000000, 76800000, 1331200000}, 28 | {0x9222000B, 1020000000, 76800000, 1600000000}, 29 | {0x9222000C, 1020000000, 76800000, 1331200000}, 30 | {0, 0, 0, 0}, 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/src/client/ipc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #define NX_SERVICE_ASSUME_NON_DOMAIN 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | static Service g_sysclkSrv; 18 | static atomic_size_t g_refCnt; 19 | 20 | bool sysclkIpcRunning() 21 | { 22 | Handle handle; 23 | bool running = R_FAILED(smRegisterService(&handle, smEncodeName(SYSCLK_IPC_SERVICE_NAME), false, 1)); 24 | 25 | if (!running) 26 | { 27 | smUnregisterService(smEncodeName(SYSCLK_IPC_SERVICE_NAME)); 28 | } 29 | 30 | return running; 31 | } 32 | 33 | Result sysclkIpcInitialize(void) 34 | { 35 | Result rc = 0; 36 | 37 | g_refCnt++; 38 | 39 | if (serviceIsActive(&g_sysclkSrv)) 40 | return 0; 41 | 42 | rc = smGetService(&g_sysclkSrv, SYSCLK_IPC_SERVICE_NAME); 43 | 44 | if (R_FAILED(rc)) sysclkIpcExit(); 45 | 46 | return rc; 47 | } 48 | 49 | void sysclkIpcExit(void) 50 | { 51 | if (--g_refCnt == 0) 52 | { 53 | serviceClose(&g_sysclkSrv); 54 | } 55 | } 56 | 57 | Result sysclkIpcGetAPIVersion(u32* out_ver) 58 | { 59 | return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetApiVersion, *out_ver); 60 | } 61 | 62 | Result sysclkIpcGetVersionString(char* out, size_t len) 63 | { 64 | return serviceDispatch(&g_sysclkSrv, SysClkIpcCmd_GetVersionString, 65 | .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, 66 | .buffers = {{out, len}}, 67 | ); 68 | } 69 | 70 | Result sysclkIpcGetCurrentContext(SysClkContext* out_context) 71 | { 72 | return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetCurrentContext, *out_context); 73 | } 74 | 75 | Result sysclkIpcGetProfileCount(u64 tid, u8* out_count) 76 | { 77 | return serviceDispatchInOut(&g_sysclkSrv, SysClkIpcCmd_GetProfileCount, tid, *out_count); 78 | } 79 | 80 | Result sysclkIpcSetEnabled(bool enabled) 81 | { 82 | u8 enabledRaw = (u8)enabled; 83 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetEnabled, enabledRaw); 84 | } 85 | 86 | Result sysclkIpcSetOverride(SysClkModule module, u32 hz) 87 | { 88 | SysClkIpc_SetOverride_Args args = { 89 | .module = module, 90 | .hz = hz 91 | }; 92 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetOverride, args); 93 | } 94 | 95 | Result sysclkIpcGetProfiles(u64 tid, SysClkTitleProfileList* out_profiles) 96 | { 97 | return serviceDispatchInOut(&g_sysclkSrv, SysClkIpcCmd_GetProfiles, tid, *out_profiles); 98 | } 99 | 100 | Result sysclkIpcSetProfiles(u64 tid, SysClkTitleProfileList* profiles) 101 | { 102 | SysClkIpc_SetProfiles_Args args; 103 | args.tid = tid; 104 | memcpy(&args.profiles, profiles, sizeof(SysClkTitleProfileList)); 105 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetProfiles, args); 106 | } 107 | 108 | Result sysclkIpcGetConfigValues(SysClkConfigValueList* out_configValues) 109 | { 110 | return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetConfigValues, *out_configValues); 111 | } 112 | 113 | Result sysclkIpcSetConfigValues(SysClkConfigValueList* configValues) 114 | { 115 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetConfigValues, *configValues); 116 | } 117 | 118 | Result sysclkIpcSetReverseNXRTMode(ReverseNXMode mode) 119 | { 120 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetReverseNXRTMode, mode); 121 | } 122 | 123 | Result sysclkIpcGetFrequencyTable(SysClkModule module, SysClkProfile profile, SysClkFrequencyTable* out_table) 124 | { 125 | SysClkIpc_GetFrequencyTable_Args args = { 126 | .module = module, 127 | .profile = profile, 128 | }; 129 | return serviceDispatchInOut(&g_sysclkSrv, SysClkIpcCmd_GetFrequencyTable, args, *out_table); 130 | } 131 | 132 | Result sysclkIpcGetIsMariko(bool* out_is_mariko) 133 | { 134 | return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetIsMariko, *out_is_mariko); 135 | } 136 | 137 | Result sysclkIpcGetBatteryChargingDisabledOverride(bool* out_is_true) 138 | { 139 | return serviceDispatchOut(&g_sysclkSrv, SysClkIpcCmd_GetBatteryChargingDisabledOverride, *out_is_true); 140 | } 141 | 142 | Result sysclkIpcSetBatteryChargingDisabledOverride(bool toggle_true) 143 | { 144 | return serviceDispatchIn(&g_sysclkSrv, SysClkIpcCmd_SetBatteryChargingDisabledOverride, toggle_true); 145 | } 146 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/src/i2c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) { 4 | // ams::fatal::srv::StopSoundTask::StopSound() 5 | // I2C Bus Communication Reference: https://www.ti.com/lit/an/slva704/slva704.pdf 6 | struct { 7 | u8 reg; 8 | u8 val; 9 | } __attribute__((packed)) cmd; 10 | 11 | I2cSession _session; 12 | Result res = i2cOpenSession(&_session, dev); 13 | if (res) 14 | return res; 15 | 16 | cmd.reg = reg; 17 | cmd.val = val; 18 | res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All); 19 | i2csessionClose(&_session); 20 | return res; 21 | } 22 | 23 | Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) { 24 | struct { u8 reg; } __attribute__((packed)) cmd; 25 | struct { u8 val; } __attribute__((packed)) rec; 26 | 27 | I2cSession _session; 28 | Result res = i2cOpenSession(&_session, dev); 29 | if (res) 30 | return res; 31 | 32 | cmd.reg = reg; 33 | res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All); 34 | if (res) { 35 | i2csessionClose(&_session); 36 | return res; 37 | } 38 | 39 | res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All); 40 | i2csessionClose(&_session); 41 | if (res) { 42 | return res; 43 | } 44 | 45 | *out = rec.val; 46 | return 0; 47 | } 48 | 49 | Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) { 50 | struct { u8 reg; } __attribute__((packed)) cmd; 51 | struct { u16 val; } __attribute__((packed)) rec; 52 | 53 | I2cSession _session; 54 | Result res = i2cOpenSession(&_session, dev); 55 | if (res) 56 | return res; 57 | 58 | cmd.reg = reg; 59 | res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All); 60 | if (res) { 61 | i2csessionClose(&_session); 62 | return res; 63 | } 64 | 65 | res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All); 66 | i2csessionClose(&_session); 67 | if (res) { 68 | return res; 69 | } 70 | 71 | *out = rec.val; 72 | return 0; 73 | } 74 | 75 | float I2c_Max17050_GetBatteryCurrent() { 76 | u16 val; 77 | Result res = I2cRead_OutU16(I2cDevice_Max17050, MAX17050_CURRENT_REG, &val); 78 | if (res) 79 | return 0.f; 80 | 81 | const float SenseResistor = 5.; // in uOhm 82 | const float CGain = 1.99993; 83 | return (s16)val * (1.5625 / (SenseResistor * CGain)); 84 | } 85 | 86 | u32 I2c_BuckConverter_MultiplierToMvOut(const I2c_BuckConverter_Domain* domain, u8 multiplier) { 87 | return (domain->uv_min + domain->uv_step * multiplier) / 1000; 88 | } 89 | 90 | u8 I2c_BuckConverter_MvOutToMultiplier(const I2c_BuckConverter_Domain* domain, u32 mvolt) { 91 | u32 uvolt = mvolt * 1000; 92 | if (uvolt < domain->uv_min) 93 | uvolt = domain->uv_min; 94 | if (uvolt > domain->uv_max) 95 | uvolt = domain->uv_max; 96 | 97 | return (uvolt - domain->uv_min) / domain->uv_step; 98 | } 99 | 100 | u32 I2c_BuckConverter_GetMvOut(const I2c_BuckConverter_Domain* domain) { 101 | u8 val; 102 | // Retry 5 times if received POR value 103 | for (int i = 0; i < 5; i++) { 104 | if (R_FAILED(I2cRead_OutU8(domain->device, domain->reg, &val))) 105 | return 0u; 106 | 107 | // Wait 1us 108 | svcSleepThread(1E3); 109 | 110 | if (!domain->por_val || val != domain->por_val) 111 | break; 112 | } 113 | return I2c_BuckConverter_MultiplierToMvOut(domain, val & domain->volt_mask); 114 | } 115 | 116 | Result I2c_BuckConverter_SetMvOut(const I2c_BuckConverter_Domain* domain, u32 mvolt) { 117 | u8 val; 118 | Result res = I2cRead_OutU8(domain->device, domain->reg, &val); 119 | if (R_FAILED(res)) 120 | return res; 121 | 122 | u8 multiplier = I2c_BuckConverter_MvOutToMultiplier(domain, mvolt); 123 | val &= ~domain->volt_mask; 124 | val |= multiplier & domain->volt_mask; 125 | 126 | res = I2cSet_U8(domain->device, domain->reg, val); 127 | if (R_FAILED(res)) 128 | return res; 129 | 130 | // 5ms Ramp delay 131 | svcSleepThread(5E6); 132 | u8 new_val; 133 | res = I2cRead_OutU8(domain->device, domain->reg, &new_val); 134 | if (R_FAILED(res)) 135 | return res; 136 | if (new_val != val) 137 | return -1; 138 | 139 | return 0; 140 | } 141 | 142 | u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) { 143 | // Adjustment is required 144 | u8 raw = 0; 145 | 146 | if (ma > MA_RANGE_MAX) // capping 147 | ma = MA_RANGE_MAX; 148 | 149 | bool pct20 = ma <= (MA_RANGE_MIN - 64); 150 | if (pct20) { 151 | ma = ma * 5; 152 | raw |= 0x1; 153 | } 154 | 155 | ma -= ma % 100; // round to 100 156 | ma -= (MA_RANGE_MIN - 64); // ceiling 157 | raw |= (ma >> 6) << 2; 158 | 159 | return raw; 160 | }; 161 | 162 | u32 I2c_Bq24193_Convert_Raw_mA(u8 raw) { 163 | // No adjustment is allowed 164 | u32 ma = (((raw >> 2)) << 6) + MA_RANGE_MIN; 165 | 166 | bool pct20 = raw & 1; 167 | if (pct20) 168 | ma = ma * 20 / 100; 169 | 170 | return ma; 171 | }; 172 | 173 | Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma) { 174 | u8 raw; 175 | Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, &raw); 176 | if (res) 177 | return res; 178 | 179 | *ma = I2c_Bq24193_Convert_Raw_mA(raw); 180 | return 0; 181 | } 182 | 183 | Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) { 184 | u8 raw = I2c_Bq24193_Convert_mA_Raw(ma); 185 | return I2cSet_U8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, raw); 186 | } -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/common/src/psm_ext.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char* PsmPowerRoleToStr(PsmPowerRole role) { 4 | switch (role) { 5 | case PsmPowerRole_Sink: return "Sink"; 6 | case PsmPowerRole_Source: return "Source"; 7 | default: return "Unknown"; 8 | } 9 | } 10 | 11 | const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type) { 12 | switch (type) { 13 | case PsmInfoChargerType_None: return "None"; 14 | case PsmInfoChargerType_PD: return "USB-C PD"; 15 | case PsmInfoChargerType_TypeC_1500mA: 16 | case PsmInfoChargerType_TypeC_3000mA: return "USB-C"; 17 | case PsmInfoChargerType_DCP: return "USB DCP"; 18 | case PsmInfoChargerType_CDP: return "USB CDP"; 19 | case PsmInfoChargerType_SDP: return "USB SDP"; 20 | case PsmInfoChargerType_Apple_500mA: 21 | case PsmInfoChargerType_Apple_1000mA: 22 | case PsmInfoChargerType_Apple_2000mA: return "Apple"; 23 | default: return "Unknown"; 24 | } 25 | } 26 | 27 | bool PsmIsChargerConnected(const PsmChargeInfo* info) { 28 | return info->ChargerType != PsmInfoChargerType_None; 29 | } 30 | 31 | bool PsmIsCharging(const PsmChargeInfo* info) { 32 | return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1); 33 | } 34 | 35 | PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) { 36 | if (!PsmIsChargerConnected(info)) 37 | return PsmBatteryState_Discharging; 38 | if (!PsmIsCharging(info)) 39 | return PsmBatteryState_ChargingPaused; 40 | return PsmBatteryState_FastCharging; 41 | } 42 | 43 | const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) { 44 | switch (PsmGetBatteryState(info)) { 45 | case PsmBatteryState_Discharging: return "\u25c0"; // ◀ 46 | case PsmBatteryState_ChargingPaused:return "| |"; 47 | case PsmBatteryState_FastCharging: return "\u25b6"; // ▶ 48 | default: return "?"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/config.ini.template: -------------------------------------------------------------------------------- 1 | [values] 2 | ; Defines how often sys-clk log temperatures, in milliseconds (set 0 to disable) 3 | temp_log_interval_ms=0 4 | ; Defines how often sys-clk writes to the CSV, in milliseconds (set 0 to disable) 5 | csv_write_interval_ms=0 6 | 7 | ; Example #1: BOTW 8 | ; Overclock CPU when docked 9 | ;[01007EF00011E000] 10 | ;docked_cpu=1224 11 | 12 | ; Example #2: Picross 13 | ; Underclock to save battery 14 | ;[0100BA0003EEA000] 15 | ;handheld_cpu=816 16 | ;handheld_gpu=153 -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /build 3 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/lib/tesla/.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: werwolv 4 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KP7XRJAND9KWU&source=url 5 | github: WerWolv 6 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/lib/tesla/.gitignore: -------------------------------------------------------------------------------- 1 | debug 2 | release 3 | lib 4 | *.bz2 5 | 6 | example/build/ 7 | 8 | *.elf 9 | 10 | *.nacp 11 | 12 | *.ovl 13 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/lib/tesla/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/WerWolv/libtesla 8 | branch = master 9 | commit = 779b4ead7df6b277b947a535544aa519785c437e 10 | parent = 3b9fed9f6b06581a0748fcfbcf992929919c01b5 11 | method = merge 12 | cmdver = 0.4.5 13 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/lib/tesla/README.md: -------------------------------------------------------------------------------- 1 | # libtesla 2 | 3 |

4 | 5 |

6 | 7 | libtesla is the interface between the Tesla overlay loader and user-made Overlays. It handles all layer creation, UI creation, drawing and input management. 8 | It's main goal is to make sure all overlays look and feel similar and don't differenciate themselves from the switch's native overlays. 9 | 10 | ## Screenshots 11 | 12 |
13 | 14 | 15 |
16 | 17 | `Overlays do NOT show up on Screenshots. These pictures were taken using a capture card` 18 | 19 | ## Example 20 | 21 | An example for how to use libtesla can be found here: https://github.com/WerWolv/libtesla/tree/master/example 22 | To create your own Overlay, please consider creating a new repository using the official Tesla overlay template: https://github.com/WerWolv/Tesla-Template 23 | 24 | **Please Note:** While it is possible to create overlays without libtesla, it's highly recommended to not do so. libtesla handles showing and hiding of overlays, button combo detection, layer creation and a lot more. Not using it will lead to an inconsistent user experience when using multiple different overlays ultimately making it worse for the end user. If something's missing, please consider opening a PR here. 25 | 26 | ## Credits 27 | 28 | - **switchbrew** for nx-hbloader which is used as basis for overlay loading 29 | - **kardch** for the amazing icon 30 | - **All the devs on AtlasNX, RetroNX and Switchbrew** for their feedback 31 | - **All overlay devs** for making something awesome out of this :) 32 | 33 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/lib/tesla/example/source/main.cpp: -------------------------------------------------------------------------------- 1 | #define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one 2 | #include // The Tesla Header 3 | 4 | 5 | class GuiSecondary : public tsl::Gui { 6 | public: 7 | GuiSecondary() {} 8 | 9 | virtual tsl::elm::Element* createUI() override { 10 | auto *rootFrame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2 - Secondary Gui"); 11 | 12 | rootFrame->setContent(new tsl::elm::DebugRectangle(tsl::Color{ 0x8, 0x3, 0x8, 0xF })); 13 | 14 | return rootFrame; 15 | } 16 | }; 17 | 18 | class GuiTest : public tsl::Gui { 19 | public: 20 | GuiTest(u8 arg1, u8 arg2, bool arg3) { } 21 | 22 | // Called when this Gui gets loaded to create the UI 23 | // Allocate all elements on the heap. libtesla will make sure to clean them up when not needed anymore 24 | virtual tsl::elm::Element* createUI() override { 25 | // A OverlayFrame is the base element every overlay consists of. This will draw the default Title and Subtitle. 26 | // If you need more information in the header or want to change it's look, use a HeaderOverlayFrame. 27 | auto frame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2"); 28 | 29 | // A list that can contain sub elements and handles scrolling 30 | auto list = new tsl::elm::List(); 31 | 32 | // List Items 33 | list->addItem(new tsl::elm::CategoryHeader("List items")); 34 | 35 | auto *clickableListItem = new tsl::elm::ListItem("Clickable List Item", "..."); 36 | clickableListItem->setClickListener([](u64 keys) { 37 | if (keys & HidNpadButton_A) { 38 | tsl::changeTo(); 39 | return true; 40 | } 41 | 42 | return false; 43 | }); 44 | 45 | list->addItem(clickableListItem); 46 | list->addItem(new tsl::elm::ListItem("Default List Item")); 47 | list->addItem(new tsl::elm::ListItem("Default List Item with an extra long name to trigger truncation and scrolling")); 48 | list->addItem(new tsl::elm::ToggleListItem("Toggle List Item", true)); 49 | 50 | // Custom Drawer, a element that gives direct access to the renderer 51 | list->addItem(new tsl::elm::CategoryHeader("Custom Drawer", true)); 52 | list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { 53 | renderer->drawCircle(x + 40, y + 40, 20, true, renderer->a(0xF00F)); 54 | renderer->drawCircle(x + 50, y + 50, 20, true, renderer->a(0xF0F0)); 55 | renderer->drawRect(x + 130, y + 30, 60, 40, renderer->a(0xFF00)); 56 | renderer->drawString("Hello :)", false, x + 250, y + 70, 20, renderer->a(0xFF0F)); 57 | renderer->drawRect(x + 40, y + 90, 300, 10, renderer->a(0xF0FF)); 58 | }), 100); 59 | 60 | // Track bars 61 | list->addItem(new tsl::elm::CategoryHeader("Track bars")); 62 | list->addItem(new tsl::elm::TrackBar("\u2600")); 63 | list->addItem(new tsl::elm::StepTrackBar("\uE13C", 20)); 64 | list->addItem(new tsl::elm::NamedStepTrackBar("\uE132", { "Selection 1", "Selection 2", "Selection 3" })); 65 | 66 | // Add the list to the frame for it to be drawn 67 | frame->setContent(list); 68 | 69 | // Return the frame to have it become the top level element of this Gui 70 | return frame; 71 | } 72 | 73 | // Called once every frame to update values 74 | virtual void update() override { 75 | 76 | } 77 | 78 | // Called once every frame to handle inputs not handled by other UI elements 79 | virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override { 80 | return false; // Return true here to signal the inputs have been consumed 81 | } 82 | }; 83 | 84 | class OverlayTest : public tsl::Overlay { 85 | public: 86 | // libtesla already initialized fs, hid, pl, pmdmnt, hid:sys and set:sys 87 | virtual void initServices() override {} // Called at the start to initialize all services necessary for this Overlay 88 | virtual void exitServices() override {} // Called at the end to clean up all services previously initialized 89 | 90 | virtual void onShow() override {} // Called before overlay wants to change from invisible to visible state 91 | virtual void onHide() override {} // Called before overlay wants to change from visible to invisible state 92 | 93 | virtual std::unique_ptr loadInitialGui() override { 94 | return initially(1, 2, true); // Initial Gui to load. It's possible to pass arguments to it's constructor like this 95 | } 96 | }; 97 | 98 | int main(int argc, char **argv) { 99 | return tsl::loop(argc, argv); 100 | } 101 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/scripts/make_logo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | 6 | DEST="$CURRENT_DIR/../data/logo_rgba.bin" 7 | FONT="$CURRENT_DIR/../../manager/resources/fira/FiraSans-Medium-rnx.ttf" 8 | FONT_SIZE="30.5" 9 | TEXT="sys-clk" 10 | 11 | function render() { 12 | convert -background transparent -colorspace RGB -depth 8 -fill white -font "$1" -pointsize "$2" "label:$3" "$4" 13 | } 14 | 15 | render "$FONT" "$FONT_SIZE" "$TEXT" info: 16 | render "$FONT" "$FONT_SIZE" "$TEXT" "RGBA:$DEST" -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #define TESLA_INIT_IMPL 12 | #include 13 | 14 | #include "ui/gui/fatal_gui.h" 15 | #include "ui/gui/main_gui.h" 16 | 17 | class AppOverlay : public tsl::Overlay 18 | { 19 | public: 20 | AppOverlay() {} 21 | ~AppOverlay() {} 22 | 23 | virtual void exitServices() override { 24 | sysclkIpcExit(); 25 | } 26 | 27 | virtual std::unique_ptr loadInitialGui() override 28 | { 29 | uint32_t apiVersion; 30 | smInitialize(); 31 | 32 | tsl::hlp::ScopeGuard smGuard([] { smExit(); }); 33 | 34 | if(!sysclkIpcRunning()) 35 | { 36 | return initially( 37 | "sys-clk is not running.\n\n" 38 | "\n" 39 | "Please make sure it is correctly\n\n" 40 | "installed and enabled.\n\n" 41 | "\n" 42 | "Loader.kip is required to\n\n" 43 | "use this version of sys-clk.", 44 | "" 45 | ); 46 | } 47 | 48 | if(R_FAILED(sysclkIpcInitialize()) || R_FAILED(sysclkIpcGetAPIVersion(&apiVersion))) 49 | { 50 | return initially( 51 | "Could not connect to sys-clk.\n\n" 52 | "\n" 53 | "Please make sure it is correctly\n\n" 54 | "installed and enabled.", 55 | "" 56 | ); 57 | } 58 | 59 | if(SYSCLK_IPC_API_VERSION != apiVersion) 60 | { 61 | return initially( 62 | "Overlay not compatible with\n\n" 63 | "the running sys-clk version.\n\n" 64 | "\n" 65 | "Please make sure everything is\n\n" 66 | "installed and up to date.", 67 | "" 68 | ); 69 | } 70 | 71 | return initially(); 72 | } 73 | }; 74 | 75 | int main(int argc, char **argv) 76 | { 77 | return tsl::loop(argc, argv); 78 | } 79 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/elements/base_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include "../gui/base_gui.h" 15 | 16 | class BaseFrame : public tsl::elm::HeaderOverlayFrame 17 | { 18 | public: 19 | BaseFrame(BaseGui* gui) : tsl::elm::HeaderOverlayFrame(130) { // headerHeight 20 | this->gui = gui; 21 | } 22 | 23 | void draw(tsl::gfx::Renderer* renderer) override 24 | { 25 | tsl::elm::HeaderOverlayFrame::draw(renderer); 26 | this->gui->preDraw(renderer); 27 | } 28 | 29 | protected: 30 | BaseGui* gui; 31 | }; 32 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/format.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #define FREQ_DEFAULT_TEXT "Do not override" 16 | 17 | static inline std::string formatListFreqMhz(std::uint32_t mhz) 18 | { 19 | if(mhz == 0) 20 | return FREQ_DEFAULT_TEXT; 21 | 22 | char buf[10]; 23 | return std::string(buf, snprintf(buf, sizeof(buf), "%u MHz", mhz)); 24 | } 25 | 26 | static inline std::string formatListFreqHz(std::uint32_t hz) { return formatListFreqMhz(hz / 1000000); } 27 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/app_profile_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "../../ipc.h" 14 | #include "base_menu_gui.h" 15 | #include "freq_choice_gui.h" 16 | 17 | class AppProfileGui : public BaseMenuGui 18 | { 19 | protected: 20 | std::uint64_t applicationId; 21 | SysClkTitleProfileList* profileList; 22 | 23 | void openFreqChoiceGui(tsl::elm::ListItem* listItem, SysClkProfile profile, SysClkModule module); 24 | void addModuleListItem(SysClkProfile profile, SysClkModule module); 25 | void addProfileUI(SysClkProfile profile); 26 | 27 | public: 28 | AppProfileGui(std::uint64_t applicationId, SysClkTitleProfileList* profileList); 29 | ~AppProfileGui(); 30 | void listUI() override; 31 | static void changeTo(std::uint64_t applicationId); 32 | void update() override; 33 | }; 34 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/base_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "base_gui.h" 12 | 13 | #include "../elements/base_frame.h" 14 | // #include "logo_rgba_bin.h" 15 | 16 | #define LOGO_LABEL_X 40 17 | #define LOGO_LABEL_Y 35 18 | #define LOGO_LABEL_FONT_SIZE 20 19 | 20 | #define VERSION_X 266 21 | #define VERSION_Y LOGO_LABEL_Y 22 | #define VERSION_FONT_SIZE SMALL_TEXT_SIZE 23 | 24 | void BaseGui::preDraw(tsl::gfx::Renderer* renderer) 25 | { 26 | renderer->drawString("Sys-clk-OC overlay", false, LOGO_LABEL_X, LOGO_LABEL_Y, LOGO_LABEL_FONT_SIZE, TEXT_COLOR); 27 | renderer->drawString(TARGET_VERSION, false, VERSION_X, VERSION_Y, VERSION_FONT_SIZE, DESC_COLOR); 28 | } 29 | 30 | tsl::elm::Element* BaseGui::createUI() 31 | { 32 | BaseFrame* rootFrame = new BaseFrame(this); 33 | rootFrame->setContent(this->baseUI()); 34 | return rootFrame; 35 | } 36 | 37 | void BaseGui::update() 38 | { 39 | this->refresh(); 40 | } 41 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/base_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include "../style.h" 16 | 17 | class BaseGui : public tsl::Gui 18 | { 19 | public: 20 | BaseGui() {} 21 | ~BaseGui() {} 22 | virtual void preDraw(tsl::gfx::Renderer* renderer); 23 | void update() override; 24 | tsl::elm::Element* createUI() override; 25 | virtual tsl::elm::Element* baseUI() = 0; 26 | virtual void refresh() {} 27 | }; 28 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/base_menu_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "base_menu_gui.h" 12 | 13 | #include "fatal_gui.h" 14 | 15 | BaseMenuGui::BaseMenuGui() 16 | { 17 | this->context = nullptr; 18 | this->lastContextUpdate = 0; 19 | this->listElement = nullptr; 20 | } 21 | 22 | BaseMenuGui::~BaseMenuGui() 23 | { 24 | if(this->context) 25 | { 26 | delete this->context; 27 | } 28 | } 29 | 30 | void BaseMenuGui::preDraw(tsl::gfx::Renderer* renderer) 31 | { 32 | BaseGui::preDraw(renderer); 33 | if(this->context) 34 | { 35 | char buf[32]; 36 | 37 | renderer->drawString("App ID: ", false, 40, 60, SMALL_TEXT_SIZE, DESC_COLOR); 38 | snprintf(buf, sizeof(buf), "%016lX", context->applicationId); 39 | renderer->drawString(buf, false, 100, 60, SMALL_TEXT_SIZE, VALUE_COLOR); 40 | 41 | renderer->drawString("Profile: ", false, 266, 60, SMALL_TEXT_SIZE, DESC_COLOR); 42 | renderer->drawString(sysclkFormatProfile(context->profile, true), false, 322, 60, SMALL_TEXT_SIZE, VALUE_COLOR); 43 | 44 | static struct 45 | { 46 | SysClkModule m; 47 | std::uint32_t x; 48 | } freqOffsets[SysClkModule_EnumMax] = { 49 | { SysClkModule_CPU, 80 }, 50 | { SysClkModule_GPU, 200 }, 51 | { SysClkModule_MEM, 320 }, 52 | }; 53 | 54 | for(unsigned int i = 0; i < SysClkModule_EnumMax; i++) 55 | { 56 | std::uint32_t hz = this->context->freqs[freqOffsets[i].m]; 57 | snprintf(buf, sizeof(buf), "%u MHz", hz / 1000000); 58 | renderer->drawString(buf, false, freqOffsets[i].x, 85, SMALL_TEXT_SIZE, VALUE_COLOR); 59 | } 60 | renderer->drawString("CPU:", false, 40, 85, SMALL_TEXT_SIZE, DESC_COLOR); 61 | renderer->drawString("GPU:", false, 160, 85, SMALL_TEXT_SIZE, DESC_COLOR); 62 | renderer->drawString("MEM:", false, 270, 85, SMALL_TEXT_SIZE, DESC_COLOR); 63 | 64 | static struct 65 | { 66 | SysClkThermalSensor s; 67 | std::uint32_t x; 68 | } tempOffsets[SysClkModule_EnumMax] = { 69 | { SysClkThermalSensor_SOC, 80 }, 70 | { SysClkThermalSensor_PCB, 200 }, 71 | { SysClkThermalSensor_Skin, 320 }, 72 | }; 73 | 74 | renderer->drawString("SOC:", false, 40, 110, SMALL_TEXT_SIZE, DESC_COLOR); 75 | renderer->drawString("PCB:", false, 160, 110, SMALL_TEXT_SIZE, DESC_COLOR); 76 | renderer->drawString("Skin:", false, 270, 110, SMALL_TEXT_SIZE, DESC_COLOR); 77 | for(unsigned int i = 0; i < SysClkModule_EnumMax; i++) 78 | { 79 | std::uint32_t millis = this->context->temps[tempOffsets[i].s]; 80 | snprintf(buf, sizeof(buf), "%u.%u °C", millis / 1000, (millis - millis / 1000 * 1000) / 100); 81 | renderer->drawString(buf, false, tempOffsets[i].x, 110, SMALL_TEXT_SIZE, VALUE_COLOR); 82 | } 83 | } 84 | } 85 | 86 | void BaseMenuGui::refresh() 87 | { 88 | std::uint64_t ticks = armGetSystemTick(); 89 | 90 | if(armTicksToNs(ticks - this->lastContextUpdate) > 500000000UL) 91 | { 92 | this->lastContextUpdate = ticks; 93 | if(!this->context) 94 | { 95 | this->context = new SysClkContext; 96 | } 97 | 98 | Result rc = sysclkIpcGetCurrentContext(this->context); 99 | if(R_FAILED(rc)) 100 | { 101 | FatalGui::openWithResultCode("sysclkIpcGetCurrentContext", rc); 102 | return; 103 | } 104 | } 105 | } 106 | 107 | tsl::elm::Element* BaseMenuGui::baseUI() 108 | { 109 | tsl::elm::List* list = new tsl::elm::List(); 110 | this->listElement = list; 111 | this->listUI(); 112 | 113 | return list; 114 | } 115 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/base_menu_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "../../ipc.h" 14 | #include "base_gui.h" 15 | 16 | class BaseMenuGui : public BaseGui 17 | { 18 | protected: 19 | SysClkContext* context; 20 | std::uint64_t lastContextUpdate; 21 | tsl::elm::List* listElement; 22 | 23 | public: 24 | BaseMenuGui(); 25 | ~BaseMenuGui(); 26 | void preDraw(tsl::gfx::Renderer* renderer) override; 27 | tsl::elm::Element* baseUI() override; 28 | void refresh() override; 29 | virtual void listUI() = 0; 30 | }; 31 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/fatal_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "fatal_gui.h" 12 | 13 | FatalGui::FatalGui(const std::string message, const std::string info) 14 | { 15 | this->message = message; 16 | this->info = info; 17 | } 18 | 19 | void FatalGui::openWithResultCode(std::string tag, Result rc) 20 | { 21 | char rcStr[32]; 22 | std::string info = tag; 23 | info.append(rcStr, snprintf(rcStr, sizeof(rcStr), "\n\n[0x%x] %04d-%04d", rc, R_MODULE(rc), R_DESCRIPTION(rc))); 24 | 25 | tsl::changeTo( 26 | "Could not connect to sys-clk.\n\n" 27 | "\n" 28 | "Please make sure everything is\n\n" 29 | "correctly installed and enabled.", 30 | info 31 | ); 32 | } 33 | 34 | tsl::elm::Element* FatalGui::baseUI() 35 | { 36 | tsl::elm::CustomDrawer* drawer = new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer* renderer, u16 x, u16 y, u16 w, u16 h) { 37 | renderer->drawString("\uE150", false, 40, 210, 40, TEXT_COLOR); 38 | renderer->drawString("Fatal error", false, 100, 210, 30, TEXT_COLOR); 39 | 40 | std::uint32_t txtY = 255; 41 | if(!this->message.empty()) 42 | { 43 | txtY += renderer->drawString(this->message.c_str(), false, 40, txtY, 23, TEXT_COLOR).second; 44 | txtY += 55; 45 | } 46 | 47 | if(!this->info.empty()) 48 | { 49 | renderer->drawString(this->info.c_str(), false, 40, txtY, 18, DESC_COLOR); 50 | } 51 | }); 52 | 53 | return drawer; 54 | } 55 | 56 | bool FatalGui::handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) 57 | { 58 | if((keysDown & HidNpadButton_A) == HidNpadButton_A || (keysDown & HidNpadButton_B) == HidNpadButton_B) 59 | { 60 | while(tsl::Overlay::get()->getCurrentGui() != nullptr) { 61 | tsl::goBack(); 62 | } 63 | return true; 64 | } 65 | 66 | return false; 67 | } 68 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/fatal_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include "base_gui.h" 16 | 17 | class FatalGui : public BaseGui 18 | { 19 | protected: 20 | std::string message; 21 | std::string info; 22 | 23 | public: 24 | FatalGui(const std::string message, const std::string info); 25 | ~FatalGui() {} 26 | tsl::elm::Element* baseUI() override; 27 | bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight); 28 | static void openWithResultCode(std::string tag, Result rc); 29 | }; 30 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/freq_choice_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "freq_choice_gui.h" 12 | 13 | #include "../format.h" 14 | #include "fatal_gui.h" 15 | 16 | FreqChoiceGui::FreqChoiceGui(std::uint32_t selectedMHz, SysClkModule module, SysClkProfile profile, FreqChoiceListener listener) 17 | { 18 | this->hzTable = new SysClkFrequencyTable; 19 | Result rc = sysclkIpcGetFrequencyTable(module, profile, hzTable); 20 | if (R_FAILED(rc)) { 21 | FatalGui::openWithResultCode("sysclkIpcGetFrequencyTable", rc); 22 | } 23 | 24 | this->selectedMHz = selectedMHz; 25 | this->listener = listener; 26 | } 27 | 28 | FreqChoiceGui::~FreqChoiceGui() { 29 | delete this->hzTable; 30 | } 31 | 32 | tsl::elm::ListItem* FreqChoiceGui::createFreqListItem(std::uint32_t mhz, bool selected) 33 | { 34 | tsl::elm::ListItem* listItem = new tsl::elm::ListItem(formatListFreqMhz(mhz)); 35 | listItem->setValue(selected ? "\uE14B" : ""); 36 | 37 | listItem->setClickListener([this, mhz](u64 keys) { 38 | if((keys & HidNpadButton_A) == HidNpadButton_A && this->listener) 39 | { 40 | if(this->listener(mhz)) 41 | { 42 | tsl::goBack(); 43 | } 44 | return true; 45 | } 46 | 47 | return false; 48 | }); 49 | 50 | return listItem; 51 | } 52 | 53 | void FreqChoiceGui::listUI() 54 | { 55 | this->listElement->addItem(this->createFreqListItem(0, this->selectedMHz == 0)); 56 | 57 | size_t idx = 0; 58 | uint32_t freq; 59 | while(idx < FREQ_TABLE_MAX_ENTRY_COUNT && (freq = this->hzTable->freq[idx])) 60 | { 61 | uint32_t mhz = freq / 1000'000; 62 | this->listElement->addItem(this->createFreqListItem(mhz, mhz == this->selectedMHz)); 63 | idx++; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/freq_choice_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #include "base_menu_gui.h" 16 | 17 | using FreqChoiceListener = std::function; 18 | 19 | #define FREQ_DEFAULT_TEXT "Do not override" 20 | 21 | class FreqChoiceGui : public BaseMenuGui 22 | { 23 | protected: 24 | std::uint32_t selectedMHz; 25 | SysClkFrequencyTable* hzTable; 26 | FreqChoiceListener listener; 27 | tsl::elm::ListItem* createFreqListItem(std::uint32_t mhz, bool selected); 28 | 29 | public: 30 | FreqChoiceGui(std::uint32_t selectedMHz, SysClkModule module, SysClkProfile profile, FreqChoiceListener listener); 31 | ~FreqChoiceGui(); 32 | void listUI() override; 33 | }; 34 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/global_override_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "global_override_gui.h" 12 | 13 | #include "fatal_gui.h" 14 | #include "../format.h" 15 | 16 | GlobalOverrideGui::GlobalOverrideGui() 17 | { 18 | for(std::uint16_t m = 0; m < SysClkModule_EnumMax; m++) 19 | { 20 | this->listItems[m] = nullptr; 21 | this->listHz[m] = 0; 22 | } 23 | } 24 | 25 | void GlobalOverrideGui::openFreqChoiceGui(SysClkModule module) 26 | { 27 | tsl::changeTo(this->context->overrideFreqs[module] / 1000'000, module, this->context->profile, [this, module](std::uint32_t mhz) { 28 | Result rc = sysclkIpcSetOverride(module, mhz * 1000'000); 29 | if(R_FAILED(rc)) 30 | { 31 | FatalGui::openWithResultCode("sysclkIpcSetOverride", rc); 32 | return false; 33 | } 34 | 35 | this->lastContextUpdate = armGetSystemTick(); 36 | this->context->overrideFreqs[module] = mhz * 1000'000; 37 | 38 | return true; 39 | }); 40 | } 41 | 42 | void GlobalOverrideGui::addModuleListItem(SysClkModule module) 43 | { 44 | tsl::elm::ListItem* listItem = new tsl::elm::ListItem(sysclkFormatModule(module, true)); 45 | listItem->setValue(formatListFreqMhz(0)); 46 | 47 | listItem->setClickListener([this, module](u64 keys) { 48 | if((keys & HidNpadButton_A) == HidNpadButton_A) 49 | { 50 | this->openFreqChoiceGui(module); 51 | return true; 52 | } 53 | 54 | return false; 55 | }); 56 | 57 | this->listElement->addItem(listItem); 58 | this->listItems[module] = listItem; 59 | } 60 | 61 | void GlobalOverrideGui::listUI() 62 | { 63 | this->addModuleListItem(SysClkModule_CPU); 64 | this->addModuleListItem(SysClkModule_GPU); 65 | this->addModuleListItem(SysClkModule_MEM); 66 | } 67 | 68 | void GlobalOverrideGui::refresh() 69 | { 70 | BaseMenuGui::refresh(); 71 | 72 | if(this->context) 73 | { 74 | for(std::uint16_t m = 0; m < SysClkModule_EnumMax; m++) 75 | { 76 | if(this->listItems[m] != nullptr && this->listHz[m] != this->context->overrideFreqs[m]) 77 | { 78 | this->listItems[m]->setValue(formatListFreqHz(this->context->overrideFreqs[m])); 79 | this->listHz[m] = this->context->overrideFreqs[m]; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/global_override_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "../../ipc.h" 14 | #include "base_menu_gui.h" 15 | #include "freq_choice_gui.h" 16 | 17 | class GlobalOverrideGui : public BaseMenuGui 18 | { 19 | protected: 20 | tsl::elm::ListItem* listItems[SysClkModule_EnumMax]; 21 | std::uint32_t listHz[SysClkModule_EnumMax]; 22 | 23 | void openFreqChoiceGui(SysClkModule module); 24 | void addModuleListItem(SysClkModule module); 25 | 26 | public: 27 | GlobalOverrideGui(); 28 | ~GlobalOverrideGui() {} 29 | void listUI() override; 30 | void refresh() override; 31 | }; 32 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/main_gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "main_gui.h" 12 | 13 | #include "fatal_gui.h" 14 | #include "app_profile_gui.h" 15 | #include "global_override_gui.h" 16 | #include "misc_gui.h" 17 | 18 | void MainGui::listUI() 19 | { 20 | this->enabledToggle = new tsl::elm::ToggleListItem("Enable", false); 21 | enabledToggle->setStateChangedListener([this](bool state) { 22 | Result rc = sysclkIpcSetEnabled(state); 23 | if(R_FAILED(rc)) 24 | { 25 | FatalGui::openWithResultCode("sysclkIpcSetEnabled", rc); 26 | } 27 | 28 | this->lastContextUpdate = armGetSystemTick(); 29 | this->context->enabled = state; 30 | }); 31 | this->listElement->addItem(this->enabledToggle); 32 | 33 | tsl::elm::ListItem* appProfileItem = new tsl::elm::ListItem("Edit app profile"); 34 | appProfileItem->setClickListener([this](u64 keys) { 35 | if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) 36 | { 37 | AppProfileGui::changeTo(this->context->applicationId); 38 | return true; 39 | } 40 | 41 | return false; 42 | }); 43 | this->listElement->addItem(appProfileItem); 44 | 45 | this->listElement->addItem(new tsl::elm::CategoryHeader("Advanced")); 46 | 47 | tsl::elm::ListItem* globalOverrideItem = new tsl::elm::ListItem("Temporary overrides"); 48 | globalOverrideItem->setClickListener([this](u64 keys) { 49 | if((keys & HidNpadButton_A) == HidNpadButton_A) 50 | { 51 | tsl::changeTo(); 52 | return true; 53 | } 54 | 55 | return false; 56 | }); 57 | this->listElement->addItem(globalOverrideItem); 58 | 59 | tsl::elm::ListItem* globalProfileItem = new tsl::elm::ListItem("Global profile"); 60 | globalProfileItem->setClickListener([this](u64 keys) { 61 | if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) 62 | { 63 | AppProfileGui::changeTo(SYSCLK_GLOBAL_PROFILE_TID); 64 | return true; 65 | } 66 | 67 | return false; 68 | }); 69 | this->listElement->addItem(globalProfileItem); 70 | 71 | tsl::elm::ListItem* miscItem = new tsl::elm::ListItem("Miscellaneous"); 72 | miscItem->setClickListener([this](u64 keys) { 73 | if((keys & HidNpadButton_A) == HidNpadButton_A && this->context) 74 | { 75 | tsl::changeTo(); 76 | return true; 77 | } 78 | 79 | return false; 80 | }); 81 | this->listElement->addItem(miscItem); 82 | } 83 | 84 | void MainGui::refresh() 85 | { 86 | BaseMenuGui::refresh(); 87 | 88 | if(this->context) 89 | { 90 | this->enabledToggle->setState(this->context->enabled); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/gui/main_gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "base_menu_gui.h" 14 | 15 | class MainGui : public BaseMenuGui 16 | { 17 | protected: 18 | tsl::elm::ToggleListItem* enabledToggle; 19 | 20 | public: 21 | MainGui() {} 22 | ~MainGui() {} 23 | void listUI() override; 24 | void refresh() override; 25 | }; 26 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/overlay/src/ui/style.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | 15 | #define TEXT_COLOR tsl::gfx::Renderer::a(0xFFFF) 16 | #define DESC_COLOR tsl::gfx::Renderer::a({ 0xC, 0xC, 0xC, 0xF }) 17 | #define VALUE_COLOR tsl::gfx::Renderer::a({ 0x5, 0xC, 0xA, 0xF }) 18 | #define SMALL_TEXT_SIZE 15 19 | #define LABEL_SPACING 7 20 | #define LABEL_FONT_SIZE 15 21 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/.gitignore: -------------------------------------------------------------------------------- 1 | /out 2 | /build 3 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/.gitignore: -------------------------------------------------------------------------------- 1 | # Editor files 2 | *.swp 3 | *~ 4 | 5 | # Objects 6 | *.o 7 | *.a 8 | *.so 9 | 10 | # Lib 11 | lib 12 | release 13 | debug -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/.gitrepo: -------------------------------------------------------------------------------- 1 | ; DO NOT EDIT (unless you know what you are doing) 2 | ; 3 | ; This subdirectory is a git "subrepo", and this file is maintained by the 4 | ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme 5 | ; 6 | [subrepo] 7 | remote = https://github.com/compuphase/minIni 8 | branch = master 9 | commit = 8ce144c3c287fa4e59f8ed4c405cd8b7e29f189b 10 | parent = f32c0b1bca87a6d7e55fb341f8db9ef33b13819f 11 | method = merge 12 | cmdver = 0.4.0 13 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | include $(DEVKITPRO)/libnx/switch_rules 10 | 11 | #--------------------------------------------------------------------------------- 12 | # TARGET is the name of the output 13 | # SOURCES is a list of directories containing source code 14 | # DATA is a list of directories containing data files 15 | # INCLUDES is a list of directories containing header files 16 | #--------------------------------------------------------------------------------- 17 | TARGET := $(notdir $(CURDIR)) 18 | SOURCES := dev 19 | DATA := data 20 | INCLUDES := dev 21 | SRC_H_FILES := 22 | 23 | #--------------------------------------------------------------------------------- 24 | # options for code generation 25 | #--------------------------------------------------------------------------------- 26 | ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec 27 | 28 | CFLAGS := -g -Wall -Werror \ 29 | -ffunction-sections \ 30 | -fdata-sections \ 31 | $(ARCH) \ 32 | $(BUILD_CFLAGS) 33 | 34 | CFLAGS += $(INCLUDE) 35 | 36 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 37 | 38 | ASFLAGS := -g $(ARCH) 39 | 40 | #--------------------------------------------------------------------------------- 41 | # list of directories containing libraries, this must be the top level containing 42 | # include and lib 43 | #--------------------------------------------------------------------------------- 44 | LIBDIRS := $(PORTLIBS) $(LIBNX) 45 | 46 | #--------------------------------------------------------------------------------- 47 | # no real need to edit anything past this point unless you need to add additional 48 | # rules for different file extensions 49 | #--------------------------------------------------------------------------------- 50 | ifneq ($(BUILD),$(notdir $(CURDIR))) 51 | #--------------------------------------------------------------------------------- 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | CFILES := minIni.c 57 | CPPFILES := 58 | SFILES := 59 | BINFILES := 60 | 61 | #--------------------------------------------------------------------------------- 62 | # use CXX for linking C++ projects, CC for standard C 63 | #--------------------------------------------------------------------------------- 64 | ifeq ($(strip $(CPPFILES)),) 65 | #--------------------------------------------------------------------------------- 66 | export LD := $(CC) 67 | #--------------------------------------------------------------------------------- 68 | else 69 | #--------------------------------------------------------------------------------- 70 | export LD := $(CXX) 71 | #--------------------------------------------------------------------------------- 72 | endif 73 | #--------------------------------------------------------------------------------- 74 | 75 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 76 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 77 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 78 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 79 | 80 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 81 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 82 | -I$(CURDIR)/$(BUILD) 83 | 84 | .PHONY: clean all lib/lib$(TARGET).a 85 | 86 | #--------------------------------------------------------------------------------- 87 | all: lib/lib$(TARGET).a 88 | 89 | lib: 90 | @[ -d $@ ] || mkdir -p $@ 91 | 92 | release: 93 | @[ -d $@ ] || mkdir -p $@ 94 | 95 | debug: 96 | @[ -d $@ ] || mkdir -p $@ 97 | 98 | lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES) 99 | @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ 100 | BUILD_CFLAGS="-DNDEBUG=1 -O2" \ 101 | DEPSDIR=$(CURDIR)/release \ 102 | --no-print-directory -C release \ 103 | -f $(CURDIR)/Makefile 104 | 105 | #--------------------------------------------------------------------------------- 106 | clean: 107 | @echo clean ... 108 | @rm -fr release debug lib 109 | 110 | #--------------------------------------------------------------------------------- 111 | else 112 | 113 | DEPENDS := $(OFILES:.o=.d) 114 | 115 | #--------------------------------------------------------------------------------- 116 | # main targets 117 | #--------------------------------------------------------------------------------- 118 | $(OUTPUT) : $(OFILES) 119 | 120 | $(OFILES_SRC) : $(HFILES) 121 | 122 | #--------------------------------------------------------------------------------- 123 | %_bin.h %.bin.o : %.bin 124 | #--------------------------------------------------------------------------------- 125 | @echo $(notdir $<) 126 | @$(bin2o) 127 | 128 | 129 | -include $(DEPENDS) 130 | 131 | #--------------------------------------------------------------------------------------- 132 | endif 133 | #--------------------------------------------------------------------------------------- 134 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/NOTICE: -------------------------------------------------------------------------------- 1 | minIni is a programmer's library to read and write "INI" files in embedded 2 | systems. The library takes little resources and can be configured for various 3 | kinds of file I/O libraries. 4 | 5 | The method for portable INI file management in minIni is, in part based, on the 6 | article "Multiplatform .INI Files" by Joseph J. Graf in the March 1994 issue of 7 | Dr. Dobb's Journal. 8 | 9 | The C++ class in minIni.h was contributed by Steven Van Ingelgem. 10 | 11 | The option to compile minIni as a read-only library was contributed by Luca 12 | Bassanello. 13 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-FatFs.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the FatFs and Petit-FatFs 2 | * libraries, see http://elm-chan.org/fsw/ff/00index_e.html 3 | * 4 | * By CompuPhase, 2008-2012 5 | * This "glue file" is in the public domain. It is distributed without 6 | * warranties or conditions of any kind, either express or implied. 7 | * 8 | * (The FatFs and Petit-FatFs libraries are copyright by ChaN and licensed at 9 | * its own terms.) 10 | */ 11 | 12 | #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ 13 | 14 | /* You must set _USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h) 15 | * to enable the "string functions" fgets() and fputs(). 16 | */ 17 | #include "ff.h" /* include tff.h for Tiny-FatFs */ 18 | 19 | #define INI_FILETYPE FIL 20 | #define ini_openread(filename,file) (f_open((file), (filename), FA_READ+FA_OPEN_EXISTING) == FR_OK) 21 | #define ini_openwrite(filename,file) (f_open((file), (filename), FA_WRITE+FA_CREATE_ALWAYS) == FR_OK) 22 | #define ini_close(file) (f_close(file) == FR_OK) 23 | #define ini_read(buffer,size,file) f_gets((buffer), (size),(file)) 24 | #define ini_write(buffer,file) f_puts((buffer), (file)) 25 | #define ini_remove(filename) (f_unlink(filename) == FR_OK) 26 | 27 | #define INI_FILEPOS DWORD 28 | #define ini_tell(file,pos) (*(pos) = f_tell((file))) 29 | #define ini_seek(file,pos) (f_lseek((file), *(pos)) == FR_OK) 30 | 31 | static int ini_rename(TCHAR *source, const TCHAR *dest) 32 | { 33 | /* Function f_rename() does not allow drive letters in the destination file */ 34 | char *drive = strchr(dest, ':'); 35 | drive = (drive == NULL) ? dest : drive + 1; 36 | return (f_rename(source, drive) == FR_OK); 37 | } 38 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-ccs.h: -------------------------------------------------------------------------------- 1 | /* minIni glue functions for FAT library by CCS, Inc. (as provided with their 2 | * PIC MCU compiler) 3 | * 4 | * By CompuPhase, 2011-2012 5 | * This "glue file" is in the public domain. It is distributed without 6 | * warranties or conditions of any kind, either express or implied. 7 | * 8 | * (The FAT library is copyright (c) 2007 Custom Computer Services, and 9 | * licensed at its own terms.) 10 | */ 11 | 12 | #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ 13 | 14 | #ifndef FAT_PIC_C 15 | #error FAT library must be included before this module 16 | #endif 17 | #define const /* keyword not supported by CCS */ 18 | 19 | #define INI_FILETYPE FILE 20 | #define ini_openread(filename,file) (fatopen((filename), "r", (file)) == GOODEC) 21 | #define ini_openwrite(filename,file) (fatopen((filename), "w", (file)) == GOODEC) 22 | #define ini_close(file) (fatclose((file)) == 0) 23 | #define ini_read(buffer,size,file) (fatgets((buffer), (size), (file)) != NULL) 24 | #define ini_write(buffer,file) (fatputs((buffer), (file)) == GOODEC) 25 | #define ini_remove(filename) (rm_file((filename)) == 0) 26 | 27 | #define INI_FILEPOS fatpos_t 28 | #define ini_tell(file,pos) (fatgetpos((file), (pos)) == 0) 29 | #define ini_seek(file,pos) (fatsetpos((file), (pos)) == 0) 30 | 31 | #ifndef INI_READONLY 32 | /* CCS FAT library lacks a rename function, so instead we copy the file to the 33 | * new name and delete the old file 34 | */ 35 | static int ini_rename(char *source, char *dest) 36 | { 37 | FILE fr, fw; 38 | int n; 39 | 40 | if (fatopen(source, "r", &fr) != GOODEC) 41 | return 0; 42 | if (rm_file(dest) != 0) 43 | return 0; 44 | if (fatopen(dest, "w", &fw) != GOODEC) 45 | return 0; 46 | 47 | /* With some "insider knowledge", we can save some memory: the "source" 48 | * parameter holds a filename that was built from the "dest" parameter. It 49 | * was built in a local buffer with the size INI_BUFFERSIZE. We can reuse 50 | * this buffer for copying the file. 51 | */ 52 | while (n=fatread(source, 1, INI_BUFFERSIZE, &fr)) 53 | fatwrite(source, 1, n, &fw); 54 | 55 | fatclose(&fr); 56 | fatclose(&fw); 57 | 58 | /* Now we need to delete the source file. However, we have garbled the buffer 59 | * that held the filename of the source. So we need to build it again. 60 | */ 61 | ini_tempname(source, dest, INI_BUFFERSIZE); 62 | return rm_file(source) == 0; 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-efsl.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the EFS Library, see 2 | * http://www.efsl.be/ 3 | * 4 | * By CompuPhase, 2008-2012 5 | * This "glue file" is in the public domain. It is distributed without 6 | * warranties or conditions of any kind, either express or implied. 7 | * 8 | * (EFSL is copyright 2005-2006 Lennart Ysboodt and Michael De Nil, and 9 | * licensed under the GPL with an exception clause for static linking.) 10 | */ 11 | 12 | #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ 13 | #define INI_LINETERM "\r\n" /* set line termination explicitly */ 14 | 15 | #include "efs.h" 16 | extern EmbeddedFileSystem g_efs; 17 | 18 | #define INI_FILETYPE EmbeddedFile 19 | #define ini_openread(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'r') == 0) 20 | #define ini_openwrite(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'w') == 0) 21 | #define ini_close(file) file_fclose(file) 22 | #define ini_read(buffer,size,file) (file_read((file), (size), (buffer)) > 0) 23 | #define ini_write(buffer,file) (file_write((file), strlen(buffer), (char*)(buffer)) > 0) 24 | #define ini_remove(filename) rmfile(&g_efs.myFs, (char*)(filename)) 25 | 26 | #define INI_FILEPOS euint32 27 | #define ini_tell(file,pos) (*(pos) = (file)->FilePtr)) 28 | #define ini_seek(file,pos) file_setpos((file), (*pos)) 29 | 30 | #if ! defined INI_READONLY 31 | /* EFSL lacks a rename function, so instead we copy the file to the new name 32 | * and delete the old file 33 | */ 34 | static int ini_rename(char *source, const char *dest) 35 | { 36 | EmbeddedFile fr, fw; 37 | int n; 38 | 39 | if (file_fopen(&fr, &g_efs.myFs, source, 'r') != 0) 40 | return 0; 41 | if (rmfile(&g_efs.myFs, (char*)dest) != 0) 42 | return 0; 43 | if (file_fopen(&fw, &g_efs.myFs, (char*)dest, 'w') != 0) 44 | return 0; 45 | 46 | /* With some "insider knowledge", we can save some memory: the "source" 47 | * parameter holds a filename that was built from the "dest" parameter. It 48 | * was built in buffer and this buffer has the size INI_BUFFERSIZE. We can 49 | * reuse this buffer for copying the file. 50 | */ 51 | while (n=file_read(&fr, INI_BUFFERSIZE, source)) 52 | file_write(&fw, n, source); 53 | 54 | file_fclose(&fr); 55 | file_fclose(&fw); 56 | 57 | /* Now we need to delete the source file. However, we have garbled the buffer 58 | * that held the filename of the source. So we need to build it again. 59 | */ 60 | ini_tempname(source, dest, INI_BUFFERSIZE); 61 | return rmfile(&g_efs.myFs, source) == 0; 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-ffs.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the "FAT Filing System" 2 | * library by embedded-code.com 3 | * 4 | * By CompuPhase, 2008-2012 5 | * This "glue file" is in the public domain. It is distributed without 6 | * warranties or conditions of any kind, either express or implied. 7 | * 8 | * (The "FAT Filing System" library itself is copyright embedded-code.com, and 9 | * licensed at its own terms.) 10 | */ 11 | 12 | #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ 13 | #include 14 | 15 | #define INI_FILETYPE FFS_FILE* 16 | #define ini_openread(filename,file) ((*(file) = ffs_fopen((filename),"r")) != NULL) 17 | #define ini_openwrite(filename,file) ((*(file) = ffs_fopen((filename),"w")) != NULL) 18 | #define ini_close(file) (ffs_fclose(*(file)) == 0) 19 | #define ini_read(buffer,size,file) (ffs_fgets((buffer),(size),*(file)) != NULL) 20 | #define ini_write(buffer,file) (ffs_fputs((buffer),*(file)) >= 0) 21 | #define ini_rename(source,dest) (ffs_rename((source), (dest)) == 0) 22 | #define ini_remove(filename) (ffs_remove(filename) == 0) 23 | 24 | #define INI_FILEPOS long 25 | #define ini_tell(file,pos) (ffs_fgetpos(*(file), (pos)) == 0) 26 | #define ini_seek(file,pos) (ffs_fsetpos(*(file), (pos)) == 0) 27 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-mdd.h: -------------------------------------------------------------------------------- 1 | /* minIni glue functions for Microchip's "Memory Disk Drive" file system 2 | * library, as presented in Microchip application note AN1045. 3 | * 4 | * By CompuPhase, 2011-2014 5 | * This "glue file" is in the public domain. It is distributed without 6 | * warranties or conditions of any kind, either express or implied. 7 | * 8 | * (The "Microchip Memory Disk Drive File System" is copyright (c) Microchip 9 | * Technology Incorporated, and licensed at its own terms.) 10 | */ 11 | 12 | #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ 13 | 14 | #include "MDD File System\fsio.h" 15 | #include 16 | 17 | #define INI_FILETYPE FSFILE* 18 | #define ini_openread(filename,file) ((*(file) = FSfopen((filename),FS_READ)) != NULL) 19 | #define ini_openwrite(filename,file) ((*(file) = FSfopen((filename),FS_WRITE)) != NULL) 20 | #define ini_openrewrite(filename,file) ((*(file) = fopen((filename),FS_READPLUS)) != NULL) 21 | #define ini_close(file) (FSfclose(*(file)) == 0) 22 | #define ini_write(buffer,file) (FSfwrite((buffer), 1, strlen(buffer), (*file)) > 0) 23 | #define ini_remove(filename) (FSremove((filename)) == 0) 24 | 25 | #define INI_FILEPOS long int 26 | #define ini_tell(file,pos) (*(pos) = FSftell(*(file))) 27 | #define ini_seek(file,pos) (FSfseek(*(file), *(pos), SEEK_SET) == 0) 28 | 29 | /* Since the Memory Disk Drive file system library reads only blocks of files, 30 | * the function to read a text line does so by "over-reading" a block of the 31 | * of the maximum size and truncating it behind the end-of-line. 32 | */ 33 | static int ini_read(char *buffer, int size, INI_FILETYPE *file) 34 | { 35 | size_t numread = size; 36 | char *eol; 37 | 38 | if ((numread = FSfread(buffer, 1, size, *file)) == 0) 39 | return 0; /* at EOF */ 40 | if ((eol = strchr(buffer, '\n')) == NULL) 41 | eol = strchr(buffer, '\r'); 42 | if (eol != NULL) { 43 | /* terminate the buffer */ 44 | *++eol = '\0'; 45 | /* "unread" the data that was read too much */ 46 | FSfseek(*file, - (int)(numread - (size_t)(eol - buffer)), SEEK_CUR); 47 | } /* if */ 48 | return 1; 49 | } 50 | 51 | #ifndef INI_READONLY 52 | static int ini_rename(const char *source, const char *dest) 53 | { 54 | FSFILE* ftmp = FSfopen((source), FS_READ); 55 | FSrename((dest), ftmp); 56 | return FSfclose(ftmp) == 0; 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue-stdio.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the C/C++ stdio library 2 | * 3 | * Or better said: this file contains macros that maps the function interface 4 | * used by minIni to the standard C/C++ file I/O functions. 5 | * 6 | * By CompuPhase, 2008-2014 7 | * This "glue file" is in the public domain. It is distributed without 8 | * warranties or conditions of any kind, either express or implied. 9 | */ 10 | 11 | /* map required file I/O types and functions to the standard C library */ 12 | #include 13 | 14 | #define INI_FILETYPE FILE* 15 | #define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL) 16 | #define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL) 17 | #define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL) 18 | #define ini_close(file) (fclose(*(file)) == 0) 19 | #define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL) 20 | #define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0) 21 | #define ini_rename(source,dest) (rename((source), (dest)) == 0) 22 | #define ini_remove(filename) (remove(filename) == 0) 23 | 24 | #define INI_FILEPOS long int 25 | #define ini_tell(file,pos) (*(pos) = ftell(*(file))) 26 | #define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0) 27 | 28 | /* for floating-point support, define additional types and functions */ 29 | #define INI_REAL float 30 | #define ini_ftoa(string,value) sprintf((string),"%f",(value)) 31 | #define ini_atof(string) (INI_REAL)strtod((string),NULL) 32 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/minGlue.h: -------------------------------------------------------------------------------- 1 | /* Glue functions for the minIni library, based on the C/C++ stdio library 2 | * 3 | * Or better said: this file contains macros that maps the function interface 4 | * used by minIni to the standard C/C++ file I/O functions. 5 | * 6 | * By CompuPhase, 2008-2014 7 | * This "glue file" is in the public domain. It is distributed without 8 | * warranties or conditions of any kind, either express or implied. 9 | */ 10 | 11 | /* map required file I/O types and functions to the standard C library */ 12 | #include 13 | 14 | #define INI_FILETYPE FILE* 15 | #define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL) 16 | #define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL) 17 | #define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL) 18 | #define ini_close(file) (fclose(*(file)) == 0) 19 | #define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL) 20 | #define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0) 21 | #define ini_rename(source,dest) (rename((source), (dest)) == 0) 22 | #define ini_remove(filename) (remove(filename) == 0) 23 | 24 | #define INI_FILEPOS long int 25 | #define ini_tell(file,pos) (*(pos) = ftell(*(file))) 26 | #define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0) 27 | 28 | /* for floating-point support, define additional types and functions */ 29 | //#define INI_REAL float 30 | //#define ini_ftoa(string,value) sprintf((string),"%f",(value)) 31 | //#define ini_atof(string) (INI_REAL)strtod((string),NULL) 32 | 33 | #define INI_ANSIONLY 34 | #define INI_LINETERM "\n" 35 | #define PORTABLE_STRNICMP -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/test.c: -------------------------------------------------------------------------------- 1 | /* Simple test program 2 | * 3 | * gcc -o test test.c minIni.c 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include "minIni.h" 9 | 10 | #define sizearray(a) (sizeof(a) / sizeof((a)[0])) 11 | 12 | const char inifile[] = "test.ini"; 13 | const char inifile2[] = "testplain.ini"; 14 | 15 | int Callback(const char *section, const char *key, const char *value, void *userdata) 16 | { 17 | (void)userdata; /* this parameter is not used in this example */ 18 | printf(" [%s]\t%s=%s\n", section, key, value); 19 | return 1; 20 | } 21 | 22 | int main(void) 23 | { 24 | char str[100]; 25 | long n; 26 | int s, k; 27 | char section[50]; 28 | 29 | /* string reading */ 30 | n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile); 31 | assert(n==4 && strcmp(str,"noot")==0); 32 | n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile); 33 | assert(n==4 && strcmp(str,"mies")==0); 34 | n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile); 35 | assert(n==5 && strcmp(str,"dummy")==0); 36 | /* ----- */ 37 | n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2); 38 | assert(n==4 && strcmp(str,"noot")==0); 39 | n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2); 40 | assert(n==4 && strcmp(str,"noot")==0); 41 | /* ----- */ 42 | printf("1. String reading tests passed\n"); 43 | 44 | /* value reading */ 45 | n = ini_getl("first", "val", -1, inifile); 46 | assert(n==1); 47 | n = ini_getl("second", "val", -1, inifile); 48 | assert(n==2); 49 | n = ini_getl("first", "undefined", -1, inifile); 50 | assert(n==-1); 51 | /* ----- */ 52 | n = ini_getl(NULL, "val", -1, inifile2); 53 | assert(n==1); 54 | /* ----- */ 55 | printf("2. Value reading tests passed\n"); 56 | 57 | /* string writing */ 58 | n = ini_puts("first", "alt", "flagged as \"correct\"", inifile); 59 | assert(n==1); 60 | n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile); 61 | assert(n==20 && strcmp(str,"flagged as \"correct\"")==0); 62 | /* ----- */ 63 | n = ini_puts("second", "alt", "correct", inifile); 64 | assert(n==1); 65 | n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); 66 | assert(n==7 && strcmp(str,"correct")==0); 67 | /* ----- */ 68 | n = ini_puts("third", "test", "correct", inifile); 69 | assert(n==1); 70 | n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile); 71 | assert(n==7 && strcmp(str,"correct")==0); 72 | /* ----- */ 73 | n = ini_puts("second", "alt", "overwrite", inifile); 74 | assert(n==1); 75 | n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); 76 | assert(n==9 && strcmp(str,"overwrite")==0); 77 | /* ----- */ 78 | n = ini_puts("second", "alt", "123456789", inifile); 79 | assert(n==1); 80 | n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile); 81 | assert(n==9 && strcmp(str,"123456789")==0); 82 | /* ----- */ 83 | n = ini_puts(NULL, "alt", "correct", inifile2); 84 | assert(n==1); 85 | n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2); 86 | assert(n==7 && strcmp(str,"correct")==0); 87 | /* ----- */ 88 | printf("3. String writing tests passed\n"); 89 | 90 | /* section/key enumeration */ 91 | printf("4. Section/key enumeration, file structure follows\n"); 92 | for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) { 93 | printf(" [%s]\n", section); 94 | for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) { 95 | printf("\t%s\n", str); 96 | } /* for */ 97 | } /* for */ 98 | 99 | /* browsing through the file */ 100 | printf("5. browse through all settings, file field list follows\n"); 101 | ini_browse(Callback, NULL, inifile); 102 | 103 | /* string deletion */ 104 | n = ini_puts("first", "alt", NULL, inifile); 105 | assert(n==1); 106 | n = ini_puts("second", "alt", NULL, inifile); 107 | assert(n==1); 108 | n = ini_puts("third", NULL, NULL, inifile); 109 | assert(n==1); 110 | /* ----- */ 111 | n = ini_puts(NULL, "alt", NULL, inifile2); 112 | assert(n==1); 113 | printf("6. String deletion tests passed\n"); 114 | 115 | return 0; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/test.ini: -------------------------------------------------------------------------------- 1 | [First] 2 | String=noot # trailing commment 3 | Val=1 4 | 5 | [Second] 6 | Val = 2 7 | #comment=3 8 | String = mies 9 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/test2.cc: -------------------------------------------------------------------------------- 1 | /* 2 | gcc -o minIni.o -c minIni.c 3 | g++ -o test2.o -c test2.cc 4 | g++ -o test2 test2.o minIni.o 5 | ./test2 6 | */ 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | using namespace std ; 13 | 14 | #include "minIni.h" 15 | 16 | int main(void) 17 | { 18 | minIni ini("test.ini"); 19 | string s; 20 | 21 | /* string reading */ 22 | s = ini.gets( "first", "string" , "aap" ); 23 | assert(s == "noot"); 24 | s = ini.gets( "second", "string" , "aap" ); 25 | assert(s == "mies"); 26 | s = ini.gets( "first", "dummy" , "aap" ); 27 | assert(s == "aap"); 28 | cout << "1. String reading tests passed" << endl ; 29 | 30 | 31 | /* value reading */ 32 | long n; 33 | n = ini.getl("first", "val", -1 ); 34 | assert(n==1); 35 | n = ini.getl("second", "val", -1); 36 | assert(n==2); 37 | n = ini.getl("first", "dummy", -1); 38 | assert(n==-1); 39 | cout << "2. Value reading tests passed" << endl ; 40 | 41 | 42 | /* string writing */ 43 | bool b; 44 | b = ini.put("first", "alt", "flagged as \"correct\""); 45 | assert(b); 46 | s = ini.gets("first", "alt", "aap"); 47 | assert(s=="flagged as \"correct\""); 48 | 49 | b = ini.put("second", "alt", "correct"); 50 | assert(b); 51 | s = ini.gets("second", "alt", "aap"); 52 | assert(s=="correct"); 53 | 54 | b = ini.put("third", "alt", "correct"); 55 | assert(b); 56 | s = ini.gets("third", "alt", "aap" ); 57 | assert(s=="correct"); 58 | cout << "3. String writing tests passed" << endl; 59 | 60 | /* section/key enumeration */ 61 | cout << "4. section/key enumeration; file contents follows" << endl; 62 | string section; 63 | for (int is = 0; section = ini.getsection(is), section.length() > 0; is++) { 64 | cout << " [" << section.c_str() << "]" << endl; 65 | for (int ik = 0; s = ini.getkey(section, ik), s.length() > 0; ik++) { 66 | cout << "\t" << s.c_str() << endl; 67 | } 68 | } 69 | 70 | /* string deletion */ 71 | b = ini.del("first", "alt"); 72 | assert(b); 73 | b = ini.del("second", "alt"); 74 | assert(b); 75 | b = ini.del("third"); 76 | assert(b); 77 | cout << "5. string deletion passed " << endl; 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/testplain.ini: -------------------------------------------------------------------------------- 1 | String=noot # trailing commment 2 | #comment=3 3 | Val=1 4 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/dev/wxMinIni.h: -------------------------------------------------------------------------------- 1 | /* minIni - Multi-Platform INI file parser, wxWidgets interface 2 | * 3 | * Copyright (c) CompuPhase, 2008-2012 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | * use this file except in compliance with the License. You may obtain a copy 7 | * of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations 15 | * under the License. 16 | * 17 | * Version: $Id: wxMinIni.h 44 2012-01-04 15:52:56Z thiadmer.riemersma@gmail.com $ 18 | */ 19 | #ifndef WXMININI_H 20 | #define WXMININI_H 21 | 22 | #include 23 | #include "minIni.h" 24 | 25 | class minIni 26 | { 27 | public: 28 | minIni(const wxString& filename) : iniFilename(filename) 29 | { } 30 | 31 | bool getbool(const wxString& Section, const wxString& Key, bool DefValue=false) const 32 | { return ini_getbool(Section.utf8_str(), Key.utf8_str(), int(DefValue), iniFilename.utf8_str()) != 0; } 33 | 34 | long getl(const wxString& Section, const wxString& Key, long DefValue=0) const 35 | { return ini_getl(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); } 36 | 37 | int geti(const wxString& Section, const wxString& Key, int DefValue=0) const 38 | { return static_cast(ini_getl(Section.utf8_str(), Key.utf8_str(), (long)DefValue, iniFilename.utf8_str())); } 39 | 40 | wxString gets(const wxString& Section, const wxString& Key, const wxString& DefValue=wxT("")) const 41 | { 42 | char buffer[INI_BUFFERSIZE]; 43 | ini_gets(Section.utf8_str(), Key.utf8_str(), DefValue.utf8_str(), buffer, INI_BUFFERSIZE, iniFilename.utf8_str()); 44 | wxString result = wxString::FromUTF8(buffer); 45 | return result; 46 | } 47 | 48 | wxString getsection(int idx) const 49 | { 50 | char buffer[INI_BUFFERSIZE]; 51 | ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str()); 52 | wxString result = wxString::FromUTF8(buffer); 53 | return result; 54 | } 55 | 56 | wxString getkey(const wxString& Section, int idx) const 57 | { 58 | char buffer[INI_BUFFERSIZE]; 59 | ini_getkey(Section.utf8_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str()); 60 | wxString result = wxString::FromUTF8(buffer); 61 | return result; 62 | } 63 | 64 | #if defined INI_REAL 65 | INI_REAL getf(const wxString& Section, wxString& Key, INI_REAL DefValue=0) const 66 | { return ini_getf(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); } 67 | #endif 68 | 69 | #if ! defined INI_READONLY 70 | bool put(const wxString& Section, const wxString& Key, long Value) const 71 | { return ini_putl(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; } 72 | 73 | bool put(const wxString& Section, const wxString& Key, int Value) const 74 | { return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; } 75 | 76 | bool put(const wxString& Section, const wxString& Key, bool Value) const 77 | { return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; } 78 | 79 | bool put(const wxString& Section, const wxString& Key, const wxString& Value) const 80 | { return ini_puts(Section.utf8_str(), Key.utf8_str(), Value.utf8_str(), iniFilename.utf8_str()) != 0; } 81 | 82 | bool put(const wxString& Section, const wxString& Key, const char* Value) const 83 | { return ini_puts(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; } 84 | 85 | #if defined INI_REAL 86 | bool put(const wxString& Section, const wxString& Key, INI_REAL Value) const 87 | { return ini_putf(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; } 88 | #endif 89 | 90 | bool del(const wxString& Section, const wxString& Key) const 91 | { return ini_puts(Section.utf8_str(), Key.utf8_str(), 0, iniFilename.utf8_str()) != 0; } 92 | 93 | bool del(const wxString& Section) const 94 | { return ini_puts(Section.utf8_str(), 0, 0, iniFilename.utf8_str()) != 0; } 95 | #endif 96 | 97 | private: 98 | wxString iniFilename; 99 | }; 100 | 101 | #endif /* WXMININI_H */ 102 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/doc/minIni.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hanai3Bi/Switch-OC-Suite/822556e6e4e627e5b9a444a934a82cc7f4a48db2/Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/doc/minIni.pdf -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/minIni/include/minIni.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | #pragma once 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | #include "../dev/minIni.h" 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/.gitignore: -------------------------------------------------------------------------------- 1 | # Editor files 2 | *.swp 3 | *~ 4 | 5 | # Objects 6 | *.o 7 | *.a 8 | *.so 9 | 10 | # Lib 11 | lib 12 | release 13 | debug -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | include $(DEVKITPRO)/libnx/switch_rules 10 | 11 | #--------------------------------------------------------------------------------- 12 | # TARGET is the name of the output 13 | # SOURCES is a list of directories containing source code 14 | # DATA is a list of directories containing data files 15 | # INCLUDES is a list of directories containing header files 16 | #--------------------------------------------------------------------------------- 17 | TARGET := $(notdir $(CURDIR)) 18 | SOURCES := src 19 | DATA := data 20 | INCLUDES := include 21 | 22 | #--------------------------------------------------------------------------------- 23 | # options for code generation 24 | #--------------------------------------------------------------------------------- 25 | ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec 26 | 27 | CFLAGS := -g -Wall -Werror \ 28 | -ffunction-sections \ 29 | -fdata-sections \ 30 | $(ARCH) \ 31 | $(BUILD_CFLAGS) 32 | 33 | CFLAGS += $(INCLUDE) 34 | 35 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 36 | 37 | ASFLAGS := -g $(ARCH) 38 | 39 | #--------------------------------------------------------------------------------- 40 | # list of directories containing libraries, this must be the top level containing 41 | # include and lib 42 | #--------------------------------------------------------------------------------- 43 | LIBDIRS := $(PORTLIBS) $(LIBNX) 44 | 45 | #--------------------------------------------------------------------------------- 46 | # no real need to edit anything past this point unless you need to add additional 47 | # rules for different file extensions 48 | #--------------------------------------------------------------------------------- 49 | ifneq ($(BUILD),$(notdir $(CURDIR))) 50 | #--------------------------------------------------------------------------------- 51 | 52 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 53 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 54 | 55 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 56 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 57 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 58 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 59 | 60 | #--------------------------------------------------------------------------------- 61 | # use CXX for linking C++ projects, CC for standard C 62 | #--------------------------------------------------------------------------------- 63 | ifeq ($(strip $(CPPFILES)),) 64 | #--------------------------------------------------------------------------------- 65 | export LD := $(CC) 66 | #--------------------------------------------------------------------------------- 67 | else 68 | #--------------------------------------------------------------------------------- 69 | export LD := $(CXX) 70 | #--------------------------------------------------------------------------------- 71 | endif 72 | #--------------------------------------------------------------------------------- 73 | 74 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 75 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 76 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 77 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 78 | 79 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 80 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 81 | -I$(CURDIR)/$(BUILD) 82 | 83 | .PHONY: clean all lib/lib$(TARGET).a lib/lib$(TARGET)d.a 84 | 85 | #--------------------------------------------------------------------------------- 86 | all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a 87 | 88 | lib: 89 | @[ -d $@ ] || mkdir -p $@ 90 | 91 | release: 92 | @[ -d $@ ] || mkdir -p $@ 93 | 94 | debug: 95 | @[ -d $@ ] || mkdir -p $@ 96 | 97 | lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES) 98 | @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ 99 | BUILD_CFLAGS="-DNDEBUG=1 -O2" \ 100 | DEPSDIR=$(CURDIR)/release \ 101 | --no-print-directory -C release \ 102 | -f $(CURDIR)/Makefile 103 | 104 | #--------------------------------------------------------------------------------- 105 | clean: 106 | @echo clean ... 107 | @rm -fr release debug lib 108 | 109 | #--------------------------------------------------------------------------------- 110 | else 111 | 112 | DEPENDS := $(OFILES:.o=.d) 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | $(OUTPUT) : $(OFILES) 118 | 119 | $(OFILES_SRC) : $(HFILES) 120 | 121 | #--------------------------------------------------------------------------------- 122 | %_bin.h %.bin.o : %.bin 123 | #--------------------------------------------------------------------------------- 124 | @echo $(notdir $<) 125 | @$(bin2o) 126 | 127 | 128 | -include $(DEPENDS) 129 | 130 | #--------------------------------------------------------------------------------------- 131 | endif 132 | #--------------------------------------------------------------------------------------- 133 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/include/nxExt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "nxExt/apm_ext.h" 14 | #include "nxExt/ipc_server.h" 15 | #include "nxExt/cpp/lockable_mutex.h" 16 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/include/nxExt/apm_ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | #include 19 | 20 | Result apmExtInitialize(void); 21 | void apmExtExit(void); 22 | 23 | // Silently fail 24 | Result apmExtSysRequestPerformanceMode(u32 mode); 25 | Result apmExtSysSetCpuBoostMode(u32 mode); 26 | 27 | Result apmExtGetPerformanceMode(u32 *out_mode); 28 | Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf); 29 | 30 | inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz 31 | return (conf_id == 0x92220009 || conf_id == 0x9222000A); 32 | }; 33 | inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz 34 | return (conf_id >= 0x92220009 && conf_id <= 0x9222000C); 35 | }; 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/include/nxExt/cpp/lockable_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | 15 | #include 16 | #include 17 | 18 | class LockableMutex 19 | { 20 | public: 21 | LockableMutex() 22 | { 23 | mutexInit(&this->m); 24 | } 25 | 26 | virtual ~LockableMutex() {} 27 | 28 | void Lock() 29 | { 30 | mutexLock(&this->m); 31 | } 32 | 33 | bool TryLock() 34 | { 35 | return mutexTryLock(&this->m); 36 | } 37 | 38 | void Unlock() 39 | { 40 | mutexUnlock(&this->m); 41 | } 42 | 43 | // snake_case aliases in order to implement Lockable 44 | 45 | void lock() 46 | { 47 | this->Lock(); 48 | } 49 | 50 | bool try_lock() 51 | { 52 | return this->TryLock(); 53 | } 54 | 55 | void unlock() 56 | { 57 | this->Unlock(); 58 | } 59 | 60 | private: 61 | Mutex m; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/include/nxExt/ipc_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #define IPC_SERVER_EXT_RESPONSE_MAX_DATA_SIZE (0x100 - 0x10 - sizeof(IpcServerRawHeader)) 23 | 24 | typedef struct 25 | { 26 | u64 magic; 27 | union 28 | { 29 | u64 cmdId; 30 | u64 result; 31 | }; 32 | } IpcServerRawHeader; 33 | 34 | typedef struct 35 | { 36 | SmServiceName srvName; 37 | Handle handles[MAX_WAIT_OBJECTS]; 38 | u32 max; 39 | u32 count; 40 | } IpcServer; 41 | 42 | typedef struct 43 | { 44 | u64 cmdId; 45 | void* ptr; 46 | size_t size; 47 | } IpcServerRequestData; 48 | 49 | typedef struct 50 | { 51 | HipcParsedRequest hipc; 52 | IpcServerRequestData data; 53 | } IpcServerRequest; 54 | 55 | typedef Result (*IpcServerRequestHandler)(void* userdata, const IpcServerRequest* r, u8* out_data, size_t* out_dataSize); 56 | 57 | Result ipcServerInit(IpcServer* server, const char* name, u32 max_sessions); 58 | Result ipcServerExit(IpcServer* server); 59 | Result ipcServerProcess(IpcServer* server, IpcServerRequestHandler handler, void* userdata); 60 | Result ipcServerParseCommand(const IpcServerRequest* r, size_t *out_datasize, void** out_data, u64* out_cmd); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/lib/nxExt/src/apm_ext.c: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "nxExt/apm_ext.h" 12 | 13 | #include 14 | 15 | static Service g_apmSrv; 16 | static Service g_apmSysSrv; 17 | static atomic_size_t g_refCnt; 18 | 19 | Result apmExtInitialize(void) 20 | { 21 | g_refCnt++; 22 | 23 | if (serviceIsActive(&g_apmSrv)) 24 | return 0; 25 | 26 | Result rc = smGetService(&g_apmSrv, "apm"); 27 | 28 | if(R_SUCCEEDED(rc)) 29 | rc = smGetService(&g_apmSysSrv, "apm:sys"); 30 | 31 | if (R_FAILED(rc)) 32 | apmExtExit(); 33 | 34 | return rc; 35 | } 36 | 37 | void apmExtExit(void) 38 | { 39 | if (--g_refCnt == 0) 40 | { 41 | serviceClose(&g_apmSrv); 42 | serviceClose(&g_apmSysSrv); 43 | } 44 | } 45 | 46 | Result apmExtSysSetCpuBoostMode(u32 mode) 47 | { 48 | return serviceDispatchIn(&g_apmSysSrv, 6, mode); 49 | } 50 | 51 | Result apmExtGetPerformanceMode(u32 *out_mode) 52 | { 53 | return serviceDispatchOut(&g_apmSrv, 1, *out_mode); 54 | } 55 | 56 | Result apmExtSysRequestPerformanceMode(u32 mode) 57 | { 58 | return serviceDispatchIn(&g_apmSysSrv, 0, mode); 59 | } 60 | 61 | Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf) 62 | { 63 | return serviceDispatchOut(&g_apmSysSrv, 7, *out_conf); 64 | } 65 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/perms.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sysclkOC", 3 | "title_id": "0x00FF0000636C6BFF", 4 | "title_id_range_min": "0x00FF0000636C6BFF", 5 | "title_id_range_max": "0x00FF0000636C6BFF", 6 | "main_thread_stack_size": "0x00004000", 7 | "main_thread_priority": 49, 8 | "default_cpu_id": 3, 9 | "process_category": 0, 10 | "is_retail": true, 11 | "pool_partition": 2, 12 | "is_64_bit": true, 13 | "address_space_type": 3, 14 | "filesystem_access": { 15 | "permissions": "0xFFFFFFFFFFFFFFFF" 16 | }, 17 | "service_access": [ 18 | "*" 19 | ], 20 | "service_host": [ 21 | "sysclkOC" 22 | ], 23 | "kernel_capabilities": [ 24 | { 25 | "type": "kernel_flags", 26 | "value": { 27 | "highest_thread_priority": 63, 28 | "lowest_thread_priority": 24, 29 | "lowest_cpu_id": 0, 30 | "highest_cpu_id": 3 31 | } 32 | }, 33 | { 34 | "type": "syscalls", 35 | "value": { 36 | "svcSetHeapSize": "0x01", 37 | "svcSetMemoryPermission": "0x02", 38 | "svcSetMemoryAttribute": "0x03", 39 | "svcMapMemory": "0x04", 40 | "svcUnmapMemory": "0x05", 41 | "svcQueryMemory": "0x06", 42 | "svcExitProcess": "0x07", 43 | "svcCreateThread": "0x08", 44 | "svcStartThread": "0x09", 45 | "svcExitThread": "0x0a", 46 | "svcSleepThread": "0x0b", 47 | "svcGetThreadPriority": "0x0c", 48 | "svcSetThreadPriority": "0x0d", 49 | "svcGetThreadCoreMask": "0x0e", 50 | "svcSetThreadCoreMask": "0x0f", 51 | "svcGetCurrentProcessorNumber": "0x10", 52 | "svcSignalEvent": "0x11", 53 | "svcClearEvent": "0x12", 54 | "svcMapSharedMemory": "0x13", 55 | "svcUnmapSharedMemory": "0x14", 56 | "svcCreateTransferMemory": "0x15", 57 | "svcCloseHandle": "0x16", 58 | "svcResetSignal": "0x17", 59 | "svcWaitSynchronization": "0x18", 60 | "svcCancelSynchronization": "0x19", 61 | "svcArbitrateLock": "0x1a", 62 | "svcArbitrateUnlock": "0x1b", 63 | "svcWaitProcessWideKeyAtomic": "0x1c", 64 | "svcSignalProcessWideKey": "0x1d", 65 | "svcGetSystemTick": "0x1e", 66 | "svcConnectToNamedPort": "0x1f", 67 | "svcSendSyncRequestLight": "0x20", 68 | "svcSendSyncRequest": "0x21", 69 | "svcSendSyncRequestWithUserBuffer": "0x22", 70 | "svcSendAsyncRequestWithUserBuffer": "0x23", 71 | "svcGetProcessId": "0x24", 72 | "svcGetThreadId": "0x25", 73 | "svcBreak": "0x26", 74 | "svcOutputDebugString": "0x27", 75 | "svcReturnFromException": "0x28", 76 | "svcGetInfo": "0x29", 77 | "svcSetThreadActivity": "0x32", 78 | "svcWaitForAddress": "0x34", 79 | "svcSignalToAddress": "0x35", 80 | "svcCreateSession": "0x40", 81 | "svcAcceptSession": "0x41", 82 | "svcReplyAndReceiveLight": "0x42", 83 | "svcReplyAndReceive": "0x43", 84 | "svcReplyAndReceiveWithUserBuffer": "0x44", 85 | "svcCreateEvent": "0x45", 86 | "svcCreateInterruptEvent": "0x53", 87 | "svcReadWriteRegister": "0x4E", 88 | "svcQueryIoMapping": "0x55", 89 | "svcCreateDeviceAddressSpace": "0x56", 90 | "svcAttachDeviceAddressSpace": "0x57", 91 | "svcDetachDeviceAddressSpace": "0x58", 92 | "svcMapDeviceAddressSpaceAligned": "0x5a", 93 | "svcUnmapDeviceAddressSpace": "0x5c", 94 | "svcGetSystemInfo": "0x6f", 95 | "svcCallSecureMonitor": "0x7f" 96 | } 97 | }, 98 | { 99 | "type": "min_kernel_version", 100 | "value": "0x0060" 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/clock_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #include "config.h" 17 | #include "clocks.h" 18 | #include 19 | 20 | #include "oc_extra.h" 21 | 22 | // Forward declaration 23 | class ReverseNXSync; 24 | class Governor; 25 | 26 | class ClockManager 27 | { 28 | public: 29 | static ClockManager* GetInstance(); 30 | static void Initialize(); 31 | static void Exit(); 32 | 33 | void SetRunning(bool running); 34 | bool Running(); 35 | void Tick(); 36 | void WaitForNextTick(); 37 | void SetRNXRTMode(ReverseNXMode mode); 38 | SysClkContext GetCurrentContext(); 39 | Config* GetConfig(); 40 | bool GetBatteryChargingDisabledOverride(); 41 | Result SetBatteryChargingDisabledOverride(bool toggle_true); 42 | 43 | protected: 44 | ClockManager(); 45 | virtual ~ClockManager(); 46 | 47 | bool RefreshContext(); 48 | uint32_t GetHz(SysClkModule); 49 | 50 | static ClockManager *instance; 51 | std::atomic_bool running; 52 | LockableMutex contextMutex; 53 | Config *config; 54 | SysClkContext *context; 55 | std::uint64_t lastTempLogNs; 56 | std::uint64_t lastCsvWriteNs; 57 | 58 | SysClkOcExtra *oc; 59 | ReverseNXSync *rnxSync; 60 | Governor *governor; 61 | }; 62 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/clocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | #include 13 | #include 14 | #include 15 | 16 | #define MAX_MEM_CLOCK 1862'400'000 17 | #define MEM_CLOCK_MARIKO_MIN 1600'000'000 18 | #define MEM_CLOCK_DOCK 1600'000'000 19 | #define BOOST_THRESHOLD 95'0 20 | 21 | class Clocks 22 | { 23 | public: 24 | static inline uint32_t boostCpuFreq = 1785000000; 25 | static inline uint32_t maxMemFreq = 0; 26 | 27 | static inline uint32_t* GetNearestHzPtr(uint32_t* hzListStart, uint32_t* hzListEnd, uint32_t freq) { 28 | uint32_t* p = hzListStart; 29 | while (p < hzListEnd) { 30 | if (freq <= *p) 31 | return p; 32 | p++; 33 | } 34 | return hzListEnd; 35 | } 36 | 37 | static inline SysClkFrequencyTable freqTable[SysClkModule_EnumMax] = { 38 | {}, // CPU 39 | {}, // GPU 40 | { // MEM 41 | 665600000, 42 | 800000000, 43 | 1065600000, 44 | 1331200000, 45 | 1600000000, 46 | }, 47 | }; 48 | 49 | typedef struct FreqRange { 50 | uint32_t* first; 51 | uint32_t* last; 52 | uint32_t* min; 53 | uint32_t* max[SysClkProfile_EnumMax]; 54 | 55 | void InitDefault(SysClkModule module) { 56 | SysClkFrequencyTable* table_head = &freqTable[module]; 57 | uint32_t* p = this->first = this->min = &table_head->freq[0]; 58 | 59 | // Get pointer to last value 60 | for (int i = 0; i < FREQ_TABLE_MAX_ENTRY_COUNT; i++) { 61 | if (!*(++p)) { 62 | --p; 63 | break; 64 | } 65 | } 66 | 67 | this->last = p; 68 | for (auto& m: this->max) { 69 | m = p; 70 | } 71 | }; 72 | 73 | uint32_t* FindFreq(uint32_t freq, SysClkProfile profile = SysClkProfile_Docked) { 74 | return GetNearestHzPtr(this->min, this->max[profile], freq); 75 | }; 76 | } FreqRange; 77 | 78 | static inline FreqRange freqRange[SysClkModule_EnumMax]; 79 | static void UpdateFreqRange(); 80 | 81 | static Result GetRange(SysClkModule module, SysClkProfile profile, uint32_t** min, uint32_t** max); 82 | static Result GetTable(SysClkModule module, SysClkProfile profile, SysClkFrequencyTable* out_table); 83 | static void SetAllowUnsafe(bool allow); 84 | static bool GetIsMariko() { return isMariko; }; 85 | static void Exit(); 86 | static void Initialize(); 87 | static SysClkApmConfiguration* GetEmbeddedApmConfig(uint32_t confId); 88 | static uint32_t GetStockClock(SysClkApmConfiguration* apm, SysClkModule module); 89 | static void ResetToStock(unsigned int module = SysClkModule_EnumMax); 90 | static SysClkProfile GetCurrentProfile(); 91 | static std::uint32_t GetCurrentHz(SysClkModule module); 92 | static void SetHz(SysClkModule module, std::uint32_t hz); 93 | static const char* GetProfileName(SysClkProfile profile, bool pretty); 94 | static const char* GetModuleName(SysClkModule module, bool pretty); 95 | static const char* GetThermalSensorName(SysClkThermalSensor sensor, bool pretty); 96 | static std::uint32_t GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz); 97 | static std::uint32_t GetTemperatureMilli(SysClkThermalSensor sensor); 98 | 99 | protected: 100 | static inline bool allowUnsafe; 101 | static inline bool isMariko; 102 | static std::int32_t GetTsTemperatureMilli(TsLocation location); 103 | static PcvModule GetPcvModule(SysClkModule sysclkModule); 104 | static PcvModuleId GetPcvModuleId(SysClkModule sysclkModule); 105 | static std::uint32_t GetMaxAllowedHz(SysClkModule module, SysClkProfile profile); 106 | }; 107 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "clocks.h" 21 | 22 | #define CONFIG_VAL_SECTION "values" 23 | 24 | #define CONFIG_KEY_TITLE_GOVERNOR_CONFIG "governor_config" 25 | 26 | class Config 27 | { 28 | public: 29 | Config(std::string path); 30 | virtual ~Config(); 31 | 32 | static Config *CreateDefault(); 33 | 34 | bool Refresh(); 35 | 36 | bool HasProfilesLoaded(); 37 | 38 | std::uint8_t GetProfileCount(std::uint64_t tid); 39 | void GetProfiles(std::uint64_t tid, SysClkTitleProfileList* out_profiles); 40 | bool SetProfiles(std::uint64_t tid, SysClkTitleProfileList* profiles, bool immediate); 41 | std::uint32_t GetAutoClockHz(std::uint64_t tid, SysClkModule module, SysClkProfile profile); 42 | SysClkOcGovernorConfig GetTitleGovernorConfig(std::uint64_t tid); 43 | 44 | void SetEnabled(bool enabled); 45 | bool Enabled(); 46 | void SetOverrideHz(SysClkModule module, std::uint32_t hz); 47 | std::uint32_t GetOverrideHz(SysClkModule module); 48 | 49 | std::uint64_t GetConfigValue(SysClkConfigValue val); 50 | const char* GetConfigValueName(SysClkConfigValue val, bool pretty); 51 | void GetConfigValues(SysClkConfigValueList* out_configValues); 52 | bool SetConfigValues(SysClkConfigValueList* configValues, bool immediate); 53 | protected: 54 | void Load(); 55 | void Close(); 56 | 57 | time_t CheckModificationTime(); 58 | std::uint32_t FindClockMhz(std::uint64_t tid, SysClkModule module, SysClkProfile profile); 59 | std::uint32_t FindClockHzFromProfiles(std::uint64_t tid, SysClkModule module, std::initializer_list profiles); 60 | static int BrowseIniFunc(const char* section, const char* key, const char* value, void *userdata); 61 | 62 | std::map, std::uint32_t> profileMhzMap; 63 | std::map profileCountMap; 64 | std::map profileGovernorMap; 65 | bool loaded; 66 | std::string path; 67 | time_t mtime; 68 | LockableMutex configMutex; 69 | LockableMutex overrideMutex; 70 | std::atomic_bool enabled; 71 | std::uint32_t overrideFreqs[SysClkModule_EnumMax]; 72 | std::uint64_t configValues[SysClkConfigValue_EnumMax]; 73 | }; 74 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/errors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "errors.h" 12 | #include 13 | #include 14 | 15 | void Errors::ThrowException(const char *format, ...) 16 | { 17 | va_list args; 18 | va_start(args, format); 19 | const char *msg = Errors::FormatMessage(format, args); 20 | va_end(args); 21 | 22 | throw std::runtime_error(msg); 23 | } 24 | 25 | const char *Errors::FormatMessage(const char *format, va_list args) 26 | { 27 | size_t len = vsnprintf(NULL, 0, format, args) * sizeof(char); 28 | char *buf = (char *)malloc(len + 1); 29 | if (buf == NULL) 30 | { 31 | return format; 32 | } 33 | 34 | vsnprintf(buf, len + 1, format, args); 35 | 36 | return buf; 37 | } 38 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | #ifdef DEBUG 17 | #define ERROR_THROW(format, ...) Errors::ThrowException(format "\n in %s:%u", ##__VA_ARGS__, __FILE__, __LINE__) 18 | #else 19 | #define ERROR_THROW(format, ...) Errors::ThrowException(format, ##__VA_ARGS__) 20 | #endif 21 | 22 | #define ERROR_RESULT_THROW(rc, format, ...) ERROR_THROW(format "\n RC: [0x%x] %04d-%04d", ##__VA_ARGS__, rc, R_MODULE(rc), R_DESCRIPTION(rc)) 23 | #define ASSERT_RESULT_OK(rc, format, ...) \ 24 | if (R_FAILED(rc)) \ 25 | { \ 26 | ERROR_RESULT_THROW(rc, "ASSERT_RESULT_OK: " format, ##__VA_ARGS__); \ 27 | } 28 | 29 | class Errors 30 | { 31 | public: 32 | static void ThrowException(const char *format, ...); 33 | 34 | protected: 35 | static const char *FormatMessage(const char *format, va_list args); 36 | }; 37 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/file_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define FILE_CONFIG_DIR "/config/sys-clk-oc" 22 | #define FILE_FLAG_CHECK_INTERVAL_NS 5000000000ULL 23 | #define FILE_CONTEXT_CSV_PATH FILE_CONFIG_DIR "/context.csv" 24 | #define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag" 25 | #define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt" 26 | 27 | typedef struct cvb_coefficients { 28 | s32 c0 = 0; 29 | s32 c1 = 0; 30 | s32 c2 = 0; 31 | s32 c3 = 0; 32 | s32 c4 = 0; 33 | s32 c5 = 0; 34 | } cvb_coefficients; 35 | 36 | typedef struct cvb_entry_t { 37 | u64 freq; 38 | cvb_coefficients cvb_dfll_param; 39 | cvb_coefficients cvb_pll_param; 40 | } cvb_entry_t; 41 | static_assert(sizeof(cvb_entry_t) == 0x38); 42 | 43 | using CustomizeCpuDvfsTable = cvb_entry_t[FREQ_TABLE_MAX_ENTRY_COUNT]; 44 | using CustomizeGpuDvfsTable = cvb_entry_t[FREQ_TABLE_MAX_ENTRY_COUNT]; 45 | 46 | constexpr uint32_t CUST_REV = 10; 47 | 48 | typedef struct CustTable { 49 | u8 cust[4] = {'C', 'U', 'S', 'T'}; 50 | u32 custRev; 51 | u32 mtcConf; 52 | u32 commonCpuBoostClock; 53 | u32 commonEmcMemVolt; 54 | u32 eristaCpuMaxVolt; 55 | u32 eristaEmcMaxClock; 56 | u32 marikoCpuMaxVolt; 57 | u32 marikoEmcMaxClock; 58 | u32 marikoEmcVddqVolt; 59 | u32 marikoCpuUV; 60 | u32 marikoGpuUV; 61 | u32 marikoEmcDvbShift; 62 | u32 ramTimingPresetOne; 63 | u32 ramTimingPresetTwo; 64 | u32 ramTimingPresetThree; 65 | u32 ramTimingPresetFour; 66 | u32 ramTimingPresetFive; 67 | u32 ramTimingPresetSix; 68 | u32 ramTimingPresetSeven; 69 | u32 marikoGpuVoltArray[17]; 70 | CustomizeCpuDvfsTable eristaCpuDvfsTable; 71 | CustomizeCpuDvfsTable marikoCpuDvfsTable; 72 | CustomizeCpuDvfsTable marikoCpuDvfsTableSLT; 73 | CustomizeGpuDvfsTable eristaGpuDvfsTable; 74 | CustomizeGpuDvfsTable marikoGpuDvfsTable; 75 | CustomizeGpuDvfsTable marikoGpuDvfsTableSLT; 76 | CustomizeGpuDvfsTable marikoGpuDvfsTableHiOPT; 77 | //void* eristaMtcTable; 78 | //void* marikoMtcTable; 79 | } CustTable; 80 | //static_assert(sizeof(CustTable) == sizeof(u8) * 4 + sizeof(u32) * 9 + sizeof(CustomizeCpuDvfsTable) * 4 + sizeof(void*) * 2); 81 | //static_assert(sizeof(CustTable) == 7000); 82 | 83 | class FileUtils 84 | { 85 | public: 86 | static void Exit(); 87 | static Result Initialize(); 88 | static bool IsInitialized(); 89 | static void InitializeAsync(); 90 | static void LogLine(const char *format, ...); 91 | static void WriteContextToCsv(const SysClkContext* context); 92 | static void ParseLoaderKip(); 93 | static Result mkdir_p(const char* dirpath); 94 | protected: 95 | static void RefreshFlags(bool force); 96 | static Result CustParser(const char* path, size_t filesize); 97 | }; 98 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/ipc_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | class IpcService 18 | { 19 | public: 20 | IpcService(); 21 | virtual ~IpcService(); 22 | void SetRunning(bool running); 23 | 24 | protected: 25 | static void ProcessThreadFunc(void *arg); 26 | static Result ServiceHandlerFunc(void* arg, const IpcServerRequest* r, std::uint8_t* out_data, size_t* out_dataSize); 27 | 28 | Result GetApiVersion(u32* out_version); 29 | Result GetVersionString(char* out_buf, size_t bufSize); 30 | Result GetCurrentContext(SysClkContext* out_ctx); 31 | Result Exit(); 32 | Result GetProfileCount(std::uint64_t* tid, std::uint8_t* out_count); 33 | Result GetProfiles(std::uint64_t* tid, SysClkTitleProfileList* out_profiles); 34 | Result SetProfiles(SysClkIpc_SetProfiles_Args* args); 35 | Result SetEnabled(std::uint8_t* enabled); 36 | Result SetOverride(SysClkIpc_SetOverride_Args* args); 37 | Result GetConfigValues(SysClkConfigValueList* out_configValues); 38 | Result SetConfigValues(SysClkConfigValueList* configValues); 39 | Result SetReverseNXRTMode(ReverseNXMode mode); 40 | Result GetFrequencyTable(SysClkIpc_GetFrequencyTable_Args* args, SysClkFrequencyTable* out_table); 41 | Result GetIsMariko(bool* out_is_mariko); 42 | Result GetBatteryChargingDisabledOverride(bool* out_is_true); 43 | Result SetBatteryChargingDisabledOverride(bool toggle_true); 44 | 45 | bool running; 46 | Thread thread; 47 | LockableMutex threadMutex; 48 | IpcServer server; 49 | }; 50 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "errors.h" 18 | #include "file_utils.h" 19 | #include "clocks.h" 20 | #include "process_management.h" 21 | #include "clock_manager.h" 22 | #include "ipc_service.h" 23 | #include "oc_extra.h" 24 | 25 | #define INNER_HEAP_SIZE 0x50000 26 | 27 | extern "C" 28 | { 29 | extern std::uint32_t __start__; 30 | 31 | //set applet type to use nvdrv* service 32 | std::uint32_t __nx_applet_type = AppletType_SystemApplication; 33 | TimeServiceType __nx_time_service_type = TimeServiceType_System; 34 | std::uint32_t __nx_fs_num_sessions = 1; 35 | 36 | size_t nx_inner_heap_size = INNER_HEAP_SIZE; 37 | char nx_inner_heap[INNER_HEAP_SIZE]; 38 | 39 | // set transfermem size to 32kib as [Fizeau](https://github.com/averne/Fizeau/) 40 | // or LibnxError_OutOfMemory 41 | u32 __nx_nv_transfermem_size = 0x8000; 42 | 43 | void __libnx_initheap(void) 44 | { 45 | void *addr = nx_inner_heap; 46 | size_t size = nx_inner_heap_size; 47 | 48 | /* Newlib Heap Management */ 49 | extern char *fake_heap_start; 50 | extern char *fake_heap_end; 51 | 52 | fake_heap_start = (char *)addr; 53 | fake_heap_end = (char *)addr + size; 54 | } 55 | 56 | void __appInit(void) 57 | { 58 | if (R_FAILED(smInitialize())) 59 | { 60 | fatalThrow(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM)); 61 | } 62 | 63 | Result rc = setsysInitialize(); 64 | if (R_SUCCEEDED(rc)) 65 | { 66 | SetSysFirmwareVersion fw; 67 | rc = setsysGetFirmwareVersion(&fw); 68 | if (R_SUCCEEDED(rc)) 69 | hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro)); 70 | setsysExit(); 71 | } 72 | 73 | rc = i2cInitialize(); 74 | if (R_FAILED(rc)) 75 | fatalThrow(rc); 76 | } 77 | 78 | void __appExit(void) 79 | { 80 | i2cExit(); 81 | smExit(); 82 | } 83 | } 84 | 85 | int main(int argc, char **argv) 86 | { 87 | Result rc = FileUtils::Initialize(); 88 | if (R_FAILED(rc)) 89 | { 90 | fatalThrow(rc); 91 | return 1; 92 | } 93 | 94 | try 95 | { 96 | Clocks::Initialize(); 97 | ProcessManagement::Initialize(); 98 | 99 | ProcessManagement::WaitForQLaunch(); 100 | ClockManager::Initialize(); 101 | FileUtils::LogLine("Ready"); 102 | 103 | ClockManager *clockMgr = ClockManager::GetInstance(); 104 | IpcService *ipcSrv = new IpcService(); 105 | clockMgr->SetRunning(true); 106 | clockMgr->GetConfig()->SetEnabled(true); 107 | ipcSrv->SetRunning(true); 108 | 109 | while (clockMgr->Running()) 110 | { 111 | clockMgr->Tick(); 112 | clockMgr->WaitForNextTick(); 113 | } 114 | 115 | ipcSrv->SetRunning(false); 116 | delete ipcSrv; 117 | ClockManager::Exit(); 118 | ProcessManagement::Exit(); 119 | Clocks::Exit(); 120 | } 121 | catch (const std::exception &ex) 122 | { 123 | FileUtils::LogLine("[!] %s", ex.what()); 124 | } 125 | catch (...) 126 | { 127 | std::exception_ptr p = std::current_exception(); 128 | FileUtils::LogLine("[!?] %s", p ? p.__cxa_exception_type()->name() : "..."); 129 | } 130 | 131 | FileUtils::LogLine("Exit"); 132 | svcSleepThread(1000000ULL); 133 | FileUtils::Exit(); 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/process_management.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #include "process_management.h" 12 | #include "file_utils.h" 13 | #include "errors.h" 14 | 15 | void ProcessManagement::Initialize() 16 | { 17 | Result rc = 0; 18 | 19 | rc = pmdmntInitialize(); 20 | ASSERT_RESULT_OK(rc, "pmdmntInitialize"); 21 | 22 | rc = pminfoInitialize(); 23 | ASSERT_RESULT_OK(rc, "pminfoInitialize"); 24 | } 25 | 26 | void ProcessManagement::WaitForQLaunch() 27 | { 28 | Result rc = 0; 29 | std::uint64_t pid = 0; 30 | do 31 | { 32 | rc = pmdmntGetProcessId(&pid, PROCESS_MANAGEMENT_QLAUNCH_TID); 33 | svcSleepThread(500000000ULL); 34 | } while (R_FAILED(rc)); 35 | } 36 | 37 | std::uint64_t ProcessManagement::GetCurrentApplicationId() 38 | { 39 | Result rc = 0; 40 | std::uint64_t pid = 0; 41 | std::uint64_t tid = 0; 42 | rc = pmdmntGetApplicationProcessId(&pid); 43 | 44 | if (rc == 0x20f) 45 | { 46 | return PROCESS_MANAGEMENT_QLAUNCH_TID; 47 | } 48 | 49 | ASSERT_RESULT_OK(rc, "pmdmntGetApplicationProcessId"); 50 | 51 | rc = pminfoGetProgramId(&tid, pid); 52 | 53 | if (rc == 0x20f) 54 | { 55 | return PROCESS_MANAGEMENT_QLAUNCH_TID; 56 | } 57 | 58 | ASSERT_RESULT_OK(rc, "pminfoGetProgramId"); 59 | 60 | return tid; 61 | } 62 | 63 | void ProcessManagement::Exit() 64 | { 65 | pmdmntExit(); 66 | pminfoExit(); 67 | } 68 | -------------------------------------------------------------------------------- /Source/sys-clk-OC(deprecated)/sysmodule/src/process_management.h: -------------------------------------------------------------------------------- 1 | /* 2 | * -------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * , , 5 | * wrote this file. As long as you retain this notice you can do whatever you 6 | * want with this stuff. If you meet any of us some day, and you think this 7 | * stuff is worth it, you can buy us a beer in return. - The sys-clk authors 8 | * -------------------------------------------------------------------------- 9 | */ 10 | 11 | #pragma once 12 | #include 13 | #include 14 | 15 | #define PROCESS_MANAGEMENT_QLAUNCH_TID 0x0100000000001000ULL 16 | 17 | class ProcessManagement 18 | { 19 | public: 20 | static void Initialize(); 21 | static void WaitForQLaunch(); 22 | static std::uint64_t GetCurrentApplicationId(); 23 | static void Exit(); 24 | }; 25 | -------------------------------------------------------------------------------- /gpu_volt.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 hanai3Bi 2 | 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms and conditions of the GNU General Public License, 5 | # version 2, as published by the Free Software Foundation. 6 | 7 | # This program is distributed in the hope it will be useful, but WITHOUT 8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 10 | # more details. 11 | 12 | # You should have received a copy of the GNU General Public License 13 | # along with this program. If not, see . 14 | 15 | import math 16 | 17 | gpu_dvfs_table_0 = [ 18 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 19 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 20 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 21 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 22 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 23 | [ 610000, 0 , 0 , 0 , 0 , 0 ], 24 | [ 801688, -10900, -163, 298, -10599, 162 ], 25 | [ 824214, -5743, -452, 238, -6325, 81 ], 26 | [ 848830, -3903, -552, 119, -4030, -2 ], 27 | [ 891575, -4409, -584, 0, -2849, 39 ], 28 | [ 940071, -5367, -602, -60, -63, -93 ], 29 | [ 986765, -6637, -614, -179, 1905, -13 ], 30 | [ 1098475, -13529, -497, -179, 3626, 9 ], 31 | [ 1163644, -12688, -648, 0, 1077, 40 ], 32 | [ 1204812, -9908, -830, 0, 1469, 110 ], 33 | [ 1277303, -11675, -859, 0, 3722, 313 ], 34 | [ 1335531, -12567, -867, 0, 3681, 559 ] 35 | ] 36 | 37 | gpu_dvfs_table_1 = [ 38 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 39 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 40 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 41 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 42 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 43 | [ 795089, -11096, -163, 298, -10421, 162 ], 44 | [ 795089, -11096, -163, 298, -10421, 162 ], 45 | [ 820606, -6285, -452, 238, -6182, 81 ], 46 | [ 846289, -4565, -552, 119, -3958, -2 ], 47 | [ 888720, -5110, -584, 0, -2849, 39 ], 48 | [ 936634, -6089, -602, -60, -99, -93 ], 49 | [ 982562, -7373, -614, -179, 1797, -13 ], 50 | [ 1090179, -14125, -497, -179, 3518, 9 ], 51 | [ 1155798, -13465, -648, 0, 1077, 40 ], 52 | [ 1198568, -10904, -830, 0, 1469, 110 ], 53 | [ 1269988, -12707, -859, 0, 3722, 313 ], 54 | [ 1308155, -13694, -867, 0, 3681, 559 ] 55 | ] 56 | gpu_dvfs_table_2 = [ 57 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 58 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 59 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 60 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 61 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 62 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 63 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 64 | [ 590000, 0 , 0 , 0 , 0 , 0 ], 65 | [ 838712, -7304, -552, 119, -3750, -2 ], 66 | [ 880210, -7955, -584, 0, -2849, 39 ], 67 | [ 926398, -8892, -602, -60, -384, -93 ], 68 | [ 970060, -10108, -614, -179, 1508, -13 ], 69 | [ 1065665, -16075, -497, -179, 3213, 9 ], 70 | [ 1132576, -16093, -648, 0, 1077, 40 ], 71 | [ 1180029, -14534, -830, 0, 1469, 110 ], 72 | [ 1248293, -16383, -859, 0, 3722, 313 ], 73 | [ 1286399, -17475, -867, 0, 3681, 559 ] 74 | ] 75 | 76 | gpu_freq_table = [76800, 153600, 230400, 307200, 384000, 460800, 537600, 614400, 691200, 768000, 844800, 921600, 998400, 1075200, 1152000, 1228800, 1267200] 77 | 78 | temp_list = [20, 30, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90] 79 | 80 | def round_closest(value, scale): 81 | if (value > 0): 82 | return (((value) + ((scale) / 2)) / (scale)) 83 | else: 84 | return (((value) - ((scale) / 2)) / (scale)) 85 | 86 | def round5(number): 87 | return int(math.ceil(number / 5.0)) * 5 88 | 89 | speedo = int(input("Enter gpu speedo: ")) 90 | 91 | table = int(input("Enter gpu table (0~2): ")) 92 | if (table == 0): 93 | gpu_dvfs_table = gpu_dvfs_table_0 94 | elif (table == 1): 95 | gpu_dvfs_table = gpu_dvfs_table_1 96 | else: 97 | gpu_dvfs_table = gpu_dvfs_table_2 98 | 99 | offset = int(input("Enter gpu offset: ")) 100 | for i in range(17): 101 | gpu_dvfs_table[i][0] -= offset*1000 102 | 103 | print("\t\t", end="") 104 | 105 | for temp in temp_list: 106 | print(temp, "°C\t", end="") 107 | print() 108 | 109 | for entry in range(17): 110 | print(float(gpu_freq_table[entry]/1000),end="") 111 | print("\t\t", end="") 112 | 113 | mv = round_closest(gpu_dvfs_table[entry][2] * speedo , 100) 114 | mv = round_closest( (mv + gpu_dvfs_table[entry][1]) * speedo , 100) + gpu_dvfs_table[entry][0] 115 | #mv = round5(mv/1000) 116 | 117 | for temp in temp_list: 118 | mvt = round_closest(gpu_dvfs_table[entry][3] * speedo , 100) + gpu_dvfs_table[entry][4] + round_closest(gpu_dvfs_table[entry][5] * temp , 10) 119 | mvt = round_closest(mvt * temp , 10) 120 | #mvt = round5(mvt/1000) 121 | final_volt = math.ceil ((mv + mvt) / 1000) 122 | vmin = 610 if table == 0 else 590 123 | final_volt = max(final_volt, vmin) 124 | final_volt = round5(final_volt) 125 | print(final_volt, "\t", end="") 126 | print() 127 | 128 | #input("Press enter to exit") 129 | 130 | -------------------------------------------------------------------------------- /pages/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -d "./tmp" ] || mkdir ./tmp 4 | [ -d "./dist" ] || mkdir ./dist 5 | 6 | # README_HTML=`pandoc -f gfm -t html5 ../README.md` 7 | 8 | cp -Rf ./src/*.html ./tmp/ 9 | tsc ./src/main.ts --outDir ./tmp/ -lib es2019,dom -t es2015 10 | 11 | for FILE in ./tmp/*; do 12 | minify "${FILE}" > "./dist/${FILE/.\/tmp\/}" 13 | done 14 | 15 | rm -fr ./tmp -------------------------------------------------------------------------------- /system_settings.md: -------------------------------------------------------------------------------- 1 | ## `/atmosphere/config/system_settings.ini` 2 | 3 | - Default Fan Control Parameters 4 | - [Info on tskin coefficients](https://github.com/masagrator/Status-Monitor-Overlay/blob/master/docs/modes.md#additional-info) 5 | - If (tskin > holdable_tskin and handheld mode) or (tskin > touchable_tskin and dock mode), then fan speed is set to 100% regardlessly. 6 | - https://switchbrew.org/wiki/System_Settings#tc 7 | 8 | - Disable background services (For power saving in standby mode) 9 | - For power saving in standby mode 10 | - Do NOT add this if online service is in use. 11 | ```ini 12 | [bgtc] 13 | enable_halfawake = u32!0x0 14 | minimum_interval_normal = u32!0x7FFFFFFF 15 | minimum_interval_save = u32!0x7FFFFFFF 16 | battery_threshold_save = u32!0x64 17 | battery_threshold_stop = u32!0x64 18 | 19 | [npns] 20 | background_processing = u8!0x0 21 | sleep_periodic_interval = u32!0x7FFFFFFF 22 | sleep_processing_timeout = u32!0x0 23 | sleep_max_try_count = u32!0x0 24 | 25 | [ns.notification] 26 | enable_download_task_list = u8!0x0 27 | enable_download_ticket = u8!0x0 28 | enable_network_update = u8!0x0 29 | enable_random_wait = u8!0x0 30 | enable_request_on_cold_boot = u8!0x0 31 | enable_send_rights_usage_status_request = u8!0x0 32 | enable_sync_elicense_request = u8!0x0 33 | enable_version_list = u8!0x0 34 | retry_interval_min = u32!0x7FFFFFFF 35 | retry_interval_max = u32!0x7FFFFFFF 36 | version_list_waiting_limit_bias = u32!0x7FFFFFFF 37 | version_list_waiting_limit_min = u32!0x7FFFFFFF 38 | 39 | [account] 40 | na_required_for_network_service = u8!0x0 41 | na_license_verification_enabled = u8!0x0 42 | 43 | [account.daemon] 44 | background_awaking_periodicity = u32!0x7FFFFFFF 45 | initial_schedule_delay = u32!0x7FFFFFFF 46 | profile_sync_interval = u32!0x7FFFFFFF 47 | na_info_refresh_interval = u32!0x7FFFFFFF 48 | 49 | [capsrv] 50 | enable_album_screenshot_filedata_verification = u8!0x0 51 | enable_album_movie_filehash_verification = u8!0x0 52 | enable_album_movie_filesign_verification = u8!0x0 53 | 54 | [friends] 55 | background_processing = u8!0x0 56 | 57 | [notification.presenter] 58 | snooze_interval_in_seconds = u32!0x7FFFFFFF 59 | connection_retry_count = u32!0x0 60 | alarm_pattern_total_repeat_count = u32!0x0 61 | alarm_pattern_with_vibration_repeat_count = u32!0x0 62 | 63 | [prepo] 64 | ;background_processing = u8!0x0 (shutdown directly when entering sleep mode) 65 | transmission_interval_min = u32!0x7FFFFFFF 66 | transmission_retry_interval_min = u32!0x7FFFFFFF 67 | transmission_retry_interval_max = u32!0x7FFFFFFF 68 | transmission_interval_in_sleep = u32!0x7FFFFFFF 69 | statistics_save_interval_min = u32!0x7FFFFFFF 70 | statistics_post_interval = u32!0x7FFFFFFF 71 | save_system_report = u8!0x0 72 | 73 | [olsc] 74 | default_auto_upload_global_setting = u8!0x0 75 | default_auto_download_global_setting = u8!0x0 76 | autonomy_registration_interval_seconds = u32!0x7FFFFFFF 77 | network_service_license_info_cache_expiration_seconds = u32!0x7FFFFFFF 78 | postponed_transfer_task_processing_interval_seconds = u32!0x7FFFFFFF 79 | retry_offset_seconds = u32!0x7FFFFFFF 80 | network_trouble_detection_span_seconds = u32!0x7FFFFFFF 81 | network_connection_polling_interval_seconds = u32!0x7FFFFFFF 82 | is_save_data_backup_policy_check_required = u8!0x0 83 | is_global_transfer_task_autonomy_registration_enabled = u8!0x0 84 | is_on_event_transfer_task_registration_enabled = u8!0x0 85 | is_periodic_transfer_task_registration_enabled = u8!0x0 86 | 87 | [ntc] 88 | is_autonomic_correction_enabled = u8!0x0 89 | autonomic_correction_interval_seconds = u32!0x7FFFFFFF 90 | autonomic_correction_failed_retry_interval_seconds = u32!0x7FFFFFFF 91 | autonomic_correction_immediate_try_count_max = u32!0x0 92 | autonomic_correction_immediate_try_interval_milliseconds = u32!0x7FFFFFFF 93 | 94 | [systemupdate] 95 | bgnup_retry_seconds = u32!0x7FFFFFFF 96 | 97 | [ns.rights] 98 | skip_account_validation_on_rights_check = u8!0x1 99 | next_available_time_of_unexpected_error = u32!0x7FFFFFFF 100 | 101 | [pctl] 102 | intermittent_task_interval_seconds = u32!0x7FFFFFFF 103 | 104 | [sprofile] 105 | adjust_polling_interval_by_profile = u8!0x0 106 | polling_interval_sec_max = u32!0x7FFFFFFF 107 | polling_interval_sec_min = u32!0x7FFFFFFF 108 | ``` 109 | 110 | - Parameters of game recording and streaming 111 | - ```ini 112 | [am.debug] 113 | continuous_recording_fps = u32!60 ; 30 or 60 FPS, default: 30 114 | continuous_recording_video_bit_rate = u32!0x780000 ; 7.5Mbps(0x780000 = 7,864,320), default: ~5Mbps(0x4C4B40), VBR(Variable Bitrate) 115 | continuous_recording_key_frame_count = u32!15 ; One I-frame in 15 frames (with other 14 P-frames), default: 15 116 | ``` 117 | - Recommended: [dvr-patches](https://github.com/exelix11/dvr-patches): Allow screenshot/recording in any games and remove overlay image (copyright notice or logo). 118 | - For optimal streaming experience, SysDVR via USB interface is recommended. 119 | - Known Issues (won't fix) 120 | - Game recordings may be less than 30 seconds if higher bitrate is used. 121 | - It has noticeable performance impacts in demanding games. 122 | - Video duration shown in album will be doubled, while the playback speed or mp4 file itself are not affected. 123 | 124 | - Charging 125 | - https://switchbrew.org/wiki/System_Settings#psm 126 | - `enough_power_threshold_mw` 127 | - `cdp_dcp_input_current_limit_in_ma`: 5V CDP/DCP (BC1.2/QC?) Charger Current Limit -------------------------------------------------------------------------------- /system_settings_parser.py: -------------------------------------------------------------------------------- 1 | #!python3 2 | 3 | import os 4 | import struct 5 | import sys 6 | 7 | try: 8 | fpath = sys.argv[1] 9 | except IndexError: 10 | raise SystemExit(f"Usage: {sys.argv[0]} ") 11 | 12 | file = open(fpath, "rb") 13 | file.seek(0) 14 | file_size = int.from_bytes(file.read(4), byteorder="little") 15 | 16 | domain_key_value = {} 17 | 18 | while file.tell() != file_size: 19 | domain_key_len = int.from_bytes(file.read(4), byteorder="little") 20 | domain_key = file.read(domain_key_len).decode().rstrip('\x00') 21 | domain, key = domain_key.split("!") 22 | 23 | if not domain_key_value.get(domain): 24 | domain_key_value[domain] = {} 25 | 26 | val_types = {1: "str", 2: "u8", 3: "u32"} 27 | val_type = val_types.get(int.from_bytes(file.read(1), byteorder="little"), "unknown") 28 | val_len = int.from_bytes(file.read(4), byteorder="little") 29 | val = file.read(val_len) 30 | 31 | if val_type == "str": 32 | value = '"' + val.decode().rstrip('\x00') + '"' 33 | else: 34 | val_dec = int.from_bytes(val, byteorder="little") 35 | value = "0x" + format(val_dec, 'X') 36 | if val_type == "u32" and val_dec >= 10: 37 | val_dec = int.from_bytes(val, byteorder="little", signed=True) 38 | value += f" ; {val_dec}" 39 | 40 | domain_key_value[domain][key] = f"{val_type}!{value}" 41 | 42 | for domain in sorted(domain_key_value.keys()): 43 | print(f"[{domain}]") 44 | for key in sorted(domain_key_value[domain].keys()): 45 | print(f"{key} = {domain_key_value[domain][key]}") 46 | print() 47 | -------------------------------------------------------------------------------- /test_patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fw_dir="/Volumes/RAMDISK/NX-15.0.0/" 4 | tmp_dir="/Volumes/RAMDISK/" 5 | repack_out_dir="/Volumes/RAMDISK/out/" 6 | oc_test_dir="$HOME/Source/Switch-OC-Suite/Source/Atmosphere/stratosphere/loader/source/oc" 7 | prodkeys="$HOME/.switch/prod.keys" 8 | hactool_exe="$HOME/Source/hactool/hactool" 9 | nx2elf_exe="$HOME/Source/nx2elf/nx2elf" 10 | elf2nso_exe="$HOME/Source/switch-tools/elf2nso" 11 | hacpack_exe="$HOME/Source/hacPack/hacpack" 12 | 13 | should_remove_tmp="Y" 14 | should_save_repack="Y" 15 | option_Mariko_Erista="M" 16 | 17 | echo -e "\nExtracting nca..." 18 | out_pcv="${tmp_dir}pcv/" 19 | out_ptm="${tmp_dir}ptm/" 20 | mkdir -p "${out_pcv}" 21 | mkdir -p "${out_ptm}" 22 | cd $fw_dir 23 | 24 | pcv_nca_name="" 25 | ptm_nca_name="" 26 | for file_00 in ./*.nca/00 27 | do 28 | if [ -e "${file_00}" ]; then 29 | echo "Processing \"*.nca/00\" files..." 30 | find "${fw_dir}" -type f -name "00" -exec sh -c 'DIR=$(dirname "{}"); FW_DIR=$(dirname "${DIR}"); mv "{}" "${FW_DIR}/00"; rm -r "${DIR}"; mv "${FW_DIR}/00" "${DIR}"' \; 31 | fi 32 | break 33 | done 34 | 35 | for nca_file in ./*.nca 36 | do 37 | file_size=`wc -c "$nca_file" | awk '{print $1}'` 38 | if [[ "$nca_file" == *".cnmt."* || file_size -lt 16384 ]]; then 39 | continue 40 | fi 41 | 42 | titleid=`$hactool_exe -k $prodkeys --disablekeywarns -t nca $nca_file | grep 'Title ID'` 43 | 44 | if [[ $titleid == *"010000000000001a"* ]]; then 45 | pcv_nca_name="$(basename $nca_file)" 46 | echo "$pcv_nca_name (pcv) -> $out_pcv" 47 | $hactool_exe -k $prodkeys --disablekeywarns -t nca $nca_file --exefsdir "$out_pcv" 1> /dev/null 48 | fi 49 | 50 | if [[ $titleid == *"0100000000000010"* ]]; then 51 | ptm_nca_name="$(basename $nca_file)" 52 | echo "$ptm_nca_name (ptm) -> $out_ptm" 53 | $hactool_exe -k $prodkeys --disablekeywarns -t nca $nca_file --exefsdir "$out_ptm" 1> /dev/null 54 | fi 55 | done 56 | 57 | echo -e "\nConverting nca to elf..." 58 | $nx2elf_exe "${out_pcv}main" 1> /dev/null 59 | $nx2elf_exe "${out_ptm}main" 1> /dev/null 60 | 61 | echo -e "\nBuilding..." 62 | cd $oc_test_dir 63 | make test 1> /dev/null 64 | 65 | echo -e "\nPatching..." 66 | 67 | [ -z "$should_save_repack" ] && read -p "Save and repack to nca (y/N)? " should_save_repack 68 | SAVE_OPT=" " 69 | case $should_save_repack in 70 | Y|y ) SAVE_OPT="-s ";; 71 | esac 72 | 73 | ./test pcv $SAVE_OPT "${out_pcv}main.elf" 74 | ./test ptm $SAVE_OPT "${out_ptm}main.elf" 75 | make clean 1> /dev/null 76 | 77 | if [ ! -z $SAVE_OPT ]; then 78 | case $should_save_repack in 79 | Y|y ) 80 | patched_ext=".mariko" 81 | [ -z "$option_Mariko_Erista" ] && read -p "[M]ariko (Default) | [E]rista ? " option_Mariko_Erista 82 | case $option_Mariko_Erista in 83 | E|e ) patched_ext=".erista";; 84 | esac 85 | mkdir -p "${repack_out_dir}" 86 | cd "${tmp_dir}" 87 | echo -e "\nRepacking pcv to ${repack_out_dir}${pcv_nca_name}..." 88 | TMP="${out_pcv}temp/" 89 | mkdir -p "${TMP}" 90 | $elf2nso_exe "${out_pcv}main.elf${patched_ext}" "${TMP}main" 1> /dev/null 91 | cp "${out_pcv}main.npdm" "${TMP}main.npdm" 92 | $hacpack_exe -k $prodkeys -o "${TMP}nca" --type nca --ncatype program --titleid 010000000000001A --exefsdir "${TMP}" 1> /dev/null 93 | find "${TMP}nca" -name "*.nca" -exec mv {} "${repack_out_dir}${pcv_nca_name}" \; 94 | 95 | if [[ $patched_ext == ".mariko" ]]; then 96 | echo -e "\nRepacking ptm (Mariko Only) to ${repack_out_dir}${ptm_nca_name}..." 97 | TMP="${out_ptm}temp/" 98 | mkdir -p "${TMP}" 99 | $elf2nso_exe "${out_ptm}main.elf${patched_ext}" "${TMP}main" 1> /dev/null 100 | cp "${out_ptm}main.npdm" "${TMP}main.npdm" 101 | $hacpack_exe -k $prodkeys -o "${TMP}nca" --type nca --ncatype program --titleid 0100000000000010 --exefsdir "${TMP}" 1> /dev/null 102 | find "${TMP}nca" -name "*.nca" -exec mv {} "${repack_out_dir}${ptm_nca_name}" \; 103 | fi 104 | ;; 105 | esac 106 | fi 107 | 108 | [ -z "$should_remove_tmp" ] && read -p "Remove temp files (Y/n)? " should_remove_tmp 109 | case $should_remove_tmp in 110 | N|n ) 111 | exit;; 112 | esac 113 | 114 | rm -fr $out_pcv 115 | rm -fr $out_ptm 116 | rm -fr "${tmp_dir}hacpack_backup" 117 | 118 | echo -e "\nDone!" 119 | --------------------------------------------------------------------------------